PageRenderTime 23ms CodeModel.GetById 1ms app.highlight 16ms RepoModel.GetById 1ms app.codeStats 0ms

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