/protocols/smpp/src/test/java/org/mobicents/protocols/smpp/util/APIConfigFactoryTest.java

http://mobicents.googlecode.com/ · Java · 95 lines · 65 code · 9 blank · 21 comment · 0 complexity · 067e873b5debeec0036b568e11017589 MD5 · raw file

  1. /*
  2. * JBoss, Home of Professional Open Source
  3. * Copyright 2011, Red Hat, Inc. and individual contributors
  4. * by the @authors tag. See the copyright.txt in the distribution for a
  5. * full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.mobicents.protocols.smpp.util;
  23. import static org.testng.Assert.assertEquals;
  24. import static org.testng.Assert.assertNotNull;
  25. import static org.testng.Assert.assertNotSame;
  26. import static org.testng.Assert.assertSame;
  27. import org.mobicents.protocols.smpp.util.APIConfig;
  28. import org.mobicents.protocols.smpp.util.APIConfigFactory;
  29. import org.mobicents.protocols.smpp.util.InvalidConfigurationException;
  30. import org.mobicents.protocols.smpp.util.PropertiesAPIConfig;
  31. import org.testng.annotations.Test;
  32. @Test
  33. public class APIConfigFactoryTest {
  34. public void testPropertiesAPIConfigIsTheDefault() {
  35. APIConfigFactory.reset();
  36. APIConfig config = APIConfigFactory.getConfig();
  37. assertNotNull(config);
  38. assertEquals(config.getClass(), PropertiesAPIConfig.class);
  39. }
  40. public void testGetConfigReturnsACachedClass() {
  41. APIConfigFactory.reset();
  42. APIConfig config1 = APIConfigFactory.getConfig();
  43. APIConfig config2 = APIConfigFactory.getConfig();
  44. assertNotNull(config1);
  45. assertNotNull(config2);
  46. assertSame(config1, config2);
  47. }
  48. public void testNewInstanceIsInstantiatedWhenCachingIsDisabled() {
  49. try {
  50. System.setProperty(APIConfigFactory.CACHE_CONFIG_PROP, "false");
  51. APIConfigFactory.reset();
  52. APIConfig config1 = APIConfigFactory.getConfig();
  53. APIConfig config2 = APIConfigFactory.getConfig();
  54. assertNotNull(config1);
  55. assertNotNull(config2);
  56. assertNotSame(config1, config2);
  57. } finally {
  58. System.clearProperty(APIConfigFactory.CACHE_CONFIG_PROP);
  59. }
  60. }
  61. public void testLoadConfigLoadsSpecifiedConfigClass() throws Exception {
  62. try {
  63. System.setProperty(
  64. APIConfigFactory.CONFIG_CLASS_PROP,
  65. "org.mobicents.protocols.smpp.util.NullAPIConfig");
  66. APIConfigFactory.reset();
  67. APIConfig config = APIConfigFactory.loadConfig();
  68. assertNotNull(config);
  69. assertEquals(config.getClass(), NullAPIConfig.class);
  70. } finally {
  71. System.clearProperty(APIConfigFactory.CONFIG_CLASS_PROP);
  72. }
  73. }
  74. @Test(expectedExceptions = {InvalidConfigurationException.class})
  75. public void testLoadConfigThrowsExceptionWhenConfigClassDoesNotExist() {
  76. try {
  77. System.setProperty(
  78. APIConfigFactory.CONFIG_CLASS_PROP,
  79. "org.mobicents.smpp.util.NonExistentAPIConfig");
  80. APIConfigFactory.reset();
  81. APIConfigFactory.loadConfig();
  82. } finally {
  83. System.clearProperty(APIConfigFactory.CONFIG_CLASS_PROP);
  84. }
  85. }
  86. }