KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > kernel > configuration > ConfigurationServiceTest


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2005 EBM Websourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id: ConfigurationServiceTest.java 11:28:52 AM ddesjardins $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.kernel.configuration;
23
24 import java.lang.reflect.Method JavaDoc;
25 import java.util.ArrayList JavaDoc;
26 import java.util.List JavaDoc;
27
28 import junit.framework.TestCase;
29
30 import org.easymock.classextension.EasyMock;
31 import org.objectweb.petals.kernel.admin.ContainerInformation;
32 import org.objectweb.petals.util.LoggingUtil;
33
34 /**
35  * Tests of the ConfigurationService
36  *
37  * @author ddesjardins - eBMWebsourcing
38  */

39 public class ConfigurationServiceTest extends TestCase {
40
41     public void testFindNotTaken() {
42         List JavaDoc<String JavaDoc> taken = new ArrayList JavaDoc<String JavaDoc>();
43         taken.add("0");
44         taken.add("1");
45         ConfigurationService configurationService = new ConfigurationService(
46             EasyMock.createMock(LoggingUtil.class));
47         configurationService.id = "0";
48         assertEquals(configurationService.findNotTaken(taken, 0, 255), "2");
49     }
50
51     public void testFindNotTakenValues() {
52         List JavaDoc<String JavaDoc> taken = new ArrayList JavaDoc<String JavaDoc>();
53         taken.add("0");
54         taken.add("1");
55         ConfigurationService configurationService = new ConfigurationService(
56             EasyMock.createMock(LoggingUtil.class));
57         configurationService.id = "0";
58
59         List JavaDoc<String JavaDoc> ports = new ArrayList JavaDoc<String JavaDoc>();
60         ports.add("16400");
61         ports.add("16200");
62         ports.add("16300");
63         ports.add("8081");
64         ports.add("8082");
65         configurationService.jndiPort = "16400";
66         configurationService.tcpPort = "16200";
67         configurationService.htmlPort = "8081";
68         configurationService.jmxPort = "8081";
69         configurationService.domainPort = "16300";
70
71         configurationService.findNotTakenValues(taken, ports);
72
73         assertEquals(configurationService.id, "2");
74         assertEquals(configurationService.jndiPort, "16401");
75         assertEquals(configurationService.tcpPort, "16201");
76     }
77
78     public void testIsInitialized() {
79         ConfigurationService configurationService = new ConfigurationService(
80             EasyMock.createMock(LoggingUtil.class));
81         assertFalse(configurationService.isInitialized());
82     }
83
84     public void testSetUpConfiguration() throws SecurityException JavaDoc,
85         NoSuchMethodException JavaDoc {
86         ConfigurationService configurationService = EasyMock.createMock(
87             ConfigurationService.class,
88             new Method JavaDoc[] {ConfigurationService.class.getDeclaredMethod(
89                 "findNotTakenValues", new Class JavaDoc[] {List JavaDoc.class, List JavaDoc.class})});
90         LoggingUtil loggingUtil = EasyMock.createNiceMock(LoggingUtil.class);
91
92         List JavaDoc<ContainerInformation> containers = new ArrayList JavaDoc<ContainerInformation>();
93         ContainerInformation containerInformation = new ContainerInformation();
94         containerInformation.setHost("127.0.0.1");
95         containerInformation.setUid(10);
96         containers.add(containerInformation);
97         List JavaDoc<String JavaDoc> ids = new ArrayList JavaDoc<String JavaDoc>();
98         ids.add(null);
99         List JavaDoc<String JavaDoc> takenPorts = new ArrayList JavaDoc<String JavaDoc>();
100         takenPorts.add(null);
101         takenPorts.add(null);
102         takenPorts.add(null);
103         takenPorts.add(null);
104         takenPorts.add(null);
105         configurationService.findNotTakenValues(ids, takenPorts);
106         
107         EasyMock.replay(configurationService);
108
109         configurationService.host = "127.0.0.1";
110         configurationService.log = loggingUtil;
111         configurationService.setContainers(containers);
112
113         configurationService.setUpConfiguration();
114     }
115 }
116
Popular Tags