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

http://mobicents.googlecode.com/ · Java · 87 lines · 54 code · 10 blank · 23 comment · 0 complexity · acc01a3f5e7fabb634dbdf9020746cce 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.assertFalse;
  25. import static org.testng.Assert.assertNotNull;
  26. import static org.testng.Assert.assertTrue;
  27. import java.net.URL;
  28. import org.testng.annotations.Test;
  29. import org.mobicents.protocols.smpp.encoding.ASCIIEncoding;
  30. import org.mobicents.protocols.smpp.util.APIConfig;
  31. import org.mobicents.protocols.smpp.util.PropertiesAPIConfig;
  32. @Test
  33. public class PropertiesAPIConfigTest {
  34. public void testPropertiesAreLoadedFromDefaultLocation() throws Exception {
  35. PropertiesAPIConfig config = new PropertiesAPIConfig();
  36. config.initialise();
  37. // The following properties are set in
  38. // src/main/resources/smppapi.properties.
  39. assertTrue(config.getBoolean(APIConfig.LINK_AUTO_FLUSH));
  40. assertEquals(config.getInt(APIConfig.LINK_TIMEOUT), 120000);
  41. assertEquals(config.getInt(APIConfig.TOO_MANY_IO_EXCEPTIONS), 3);
  42. assertEquals(config.getInt(APIConfig.BIND_TIMEOUT), 180000);
  43. }
  44. public void testPropertiesAreLoadedFromSpecifiedURL() throws Exception {
  45. URL url = getClass().getResource("/propertiesapiconfigtest.properties");
  46. assertNotNull(url);
  47. PropertiesAPIConfig config = new PropertiesAPIConfig(url);
  48. config.initialise();
  49. assertTrue(config.getBoolean(APIConfig.LAX_VERSIONS));
  50. assertEquals(config.getInt(APIConfig.LINK_TIMEOUT), 90);
  51. assertEquals(config.getInt(APIConfig.BIND_TIMEOUT), 91);
  52. assertEquals(config.getProperty(APIConfig.DEFAULT_ALPHABET), ASCIIEncoding.class.getName());
  53. }
  54. public void testReloadConfigCorrectlyReloadsFromURL() throws Exception {
  55. URL url = getClass().getResource("/propertiesapiconfigtest.properties");
  56. assertNotNull(url);
  57. PropertiesAPIConfig config = new PropertiesAPIConfig(url);
  58. config.initialise();
  59. assertFalse(config.isSet(APIConfig.EVENT_DISPATCHER_CLASS));
  60. config.setProperty(APIConfig.EVENT_DISPATCHER_CLASS, "RandomClass");
  61. config.setProperty(APIConfig.LINK_TIMEOUT, "78");
  62. assertTrue(config.isSet(APIConfig.EVENT_DISPATCHER_CLASS));
  63. assertEquals(config.getInt(APIConfig.LINK_TIMEOUT), 78);
  64. config.reloadAPIConfig();
  65. assertFalse(config.isSet(APIConfig.EVENT_DISPATCHER_CLASS));
  66. assertEquals(config.getInt(APIConfig.LINK_TIMEOUT), 90);
  67. }
  68. public void testReconfigureReloadsPropertiesFromNewLocation() throws Exception {
  69. PropertiesAPIConfig config = new PropertiesAPIConfig();
  70. config.initialise();
  71. URL url = getClass().getResource("/propertiesapiconfigtest.properties");
  72. assertNotNull(url);
  73. assertEquals(config.getInt(APIConfig.LINK_TIMEOUT), 120000);
  74. config.reconfigure(url);
  75. assertEquals(config.getInt(APIConfig.LINK_TIMEOUT), 90);
  76. }
  77. }