KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > jbi > transport > JoramAgentTest


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: JoramAgentTest.java 10:37:37 AM ddesjardins $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.jbi.transport;
23
24 import java.io.File JavaDoc;
25 import java.io.IOException JavaDoc;
26 import java.lang.reflect.Method JavaDoc;
27 import java.util.ArrayList JavaDoc;
28 import java.util.List JavaDoc;
29
30 import junit.framework.TestCase;
31
32 import org.easymock.classextension.EasyMock;
33 import org.objectweb.fractal.api.control.IllegalLifeCycleException;
34
35 import org.objectweb.petals.PetalsException;
36 import org.objectweb.petals.kernel.admin.ContainerInformation;
37 import org.objectweb.petals.util.LoggingUtil;
38 import org.objectweb.petals.util.SystemUtil;
39
40 /**
41  * Tests of the JoramAgent
42  *
43  * @author ddesjardins - eBMWebsourcing
44  */

45 public class JoramAgentTest extends TestCase {
46
47     protected JoramAgent agentImpl;
48
49     protected String JavaDoc baseDir;
50
51     public void setUp() {
52         agentImpl = new JoramAgent(new LoggingUtil(null));
53         baseDir = this.getClass().getResource(".").toString();
54         baseDir = baseDir.substring(0, baseDir.indexOf("target"));
55         baseDir = baseDir.substring(baseDir.indexOf(":") + 1);
56         new File JavaDoc(baseDir + "target" + File.separator + "lib").mkdir();
57         new File JavaDoc(baseDir + "target" + File.separator + "lib" + File.separator
58             + "petals-1.0-SNAPSHOT.jar").mkdir();
59         System.setProperty("petals.home", baseDir + "target");
60     }
61
62     public void testInitConfiguration() throws IOException JavaDoc {
63         agentImpl.initConfiguration();
64         assertNotNull(agentImpl.factory);
65     }
66
67     /*
68      * public void testStart() throws Exception { JoramAgent agentImpl =
69      * EasyMock.createMock(JoramAgent.class, new Method[] {
70      * JoramAgent.class.getDeclaredMethod("initJoramAgentServer", new Class[]
71      * {}), JoramAgent.class.getDeclaredMethod("startJoramAgentServer", new
72      * Class[] {})}); agentImpl.log = EasyMock.createMock(LoggingUtil.class);
73      *
74      * agentImpl.startJoramAgentServer(); agentImpl.initJoramAgentServer();
75      *
76      * EasyMock.replay(agentImpl);
77      *
78      * agentImpl.startServer(); }
79      */

80     public void testStop() throws IllegalLifeCycleException, SecurityException JavaDoc,
81         NoSuchMethodException JavaDoc {
82         JoramAgent agentImpl = EasyMock.createMock(JoramAgent.class,
83             new Method JavaDoc[] {
84                 JoramAgent.class.getDeclaredMethod("initJoramAgentServer",
85                     new Class JavaDoc[] {}),
86                 JoramAgent.class.getDeclaredMethod("startJoramAgentServer",
87                     new Class JavaDoc[] {})});
88         agentImpl.log = EasyMock.createMock(LoggingUtil.class);
89         agentImpl.stopServer();
90     }
91
92     /*
93      * public void testStartServerDistributed() throws Exception {
94      * SystemUtil.setJoramId("0"); SystemUtil.setHost("127.0.0.1");
95      * SystemUtil.setJoramTCPPort("16200");
96      * SystemUtil.setJoramDomainPort("16300");
97      *
98      * String conf = FileUtils.readFileToString(new File(baseDir + "src" +
99      * File.separator + "test-data" + File.separator + "joram" + File.separator +
100      * "joram-conf.xml"), "UTF-8"); agentImpl =
101      * EasyMock.createMock(JoramAgent.class, new Method[] {
102      * JoramAgent.class.getDeclaredMethod( "retrieveDistributedConfiguration",
103      * new Class[0]), JoramAgent.class.getDeclaredMethod("updateContainerState",
104      * new Class[] {String.class, ContainerState.class}),
105      * JoramAgent.class.getDeclaredMethod("initJoramAgentServer", new Class[]
106      * {}), JoramAgent.class.getDeclaredMethod("startJoramAgentServer", new
107      * Class[] {})}); LoggingUtil log =
108      * EasyMock.createNiceMock(LoggingUtil.class);
109      *
110      * EasyMock.expect(agentImpl.retrieveDistributedConfiguration())
111      * .andReturn(conf);
112      *
113      * agentImpl.initJoramAgentServer(); agentImpl.startJoramAgentServer();
114      *
115      * EasyMock.replay(log); EasyMock.replay(agentImpl);
116      *
117      * agentImpl.log = log;
118      *
119      * agentImpl.startServer(); }
120      */

121     public void testStartServerException() throws SecurityException JavaDoc,
122         NoSuchMethodException JavaDoc, IOException JavaDoc {
123         SystemUtil.setJoramId("0");
124         SystemUtil.setHost("127.0.0.1");
125         SystemUtil.setJoramTCPPort("16200");
126         SystemUtil.setJoramDomainPort("16300");
127
128         agentImpl = EasyMock.createMock(JoramAgent.class, new Method JavaDoc[] {
129             JoramAgent.class.getDeclaredMethod(
130                 "retrieveDistributedConfiguration", new Class JavaDoc[0]),
131             JoramAgent.class.getDeclaredMethod(
132                 "retrieveAllContainersInformation", new Class JavaDoc[0])});
133         LoggingUtil log = EasyMock.createNiceMock(LoggingUtil.class);
134
135         RuntimeException JavaDoc runtimeException = new RuntimeException JavaDoc();
136
137         EasyMock.expect(agentImpl.retrieveDistributedConfiguration()).andThrow(
138             runtimeException).anyTimes();
139         log.error("Problem while starting the Joram server", runtimeException);
140         List JavaDoc<ContainerInformation> conts = new ArrayList JavaDoc<ContainerInformation>();
141         conts.add(null);
142         conts.add(null);
143         EasyMock.expect(agentImpl.retrieveAllContainersInformation())
144             .andReturn(conts);
145
146         EasyMock.replay(log);
147         EasyMock.replay(agentImpl);
148
149         agentImpl.log = log;
150
151         agentImpl.startServer();
152     }
153
154     public void testRetrieveContainerInformation() throws PetalsException {
155         SystemUtil.setJmxPort("8081");
156         ContainerInformation containerInformation = agentImpl
157             .createContainerInformation();
158         assertEquals(containerInformation.getJmxPort(), "8081");
159     }
160
161 }
162
Popular Tags