KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > system > launch > LauncherTest


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: LauncherTest.java 11:45:12 AM ddesjardins $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.system.launch;
23
24 import java.io.File JavaDoc;
25 import java.io.IOException JavaDoc;
26
27 import junit.framework.TestCase;
28
29 import org.easymock.classextension.EasyMock;
30 import org.objectweb.fractal.api.Component;
31 import org.objectweb.fractal.api.NoSuchInterfaceException;
32 import org.objectweb.fractal.api.control.ContentController;
33 import org.objectweb.fractal.api.control.NameController;
34 import org.objectweb.util.monolog.Monolog;
35
36 import org.objectweb.petals.util.SystemUtil;
37
38 /**
39  * Test of the launcher
40  *
41  * @author ddesjardins - eBMWebsourcing
42  */

43 public class LauncherTest extends TestCase {
44
45     
46     public void testInitializeKernel() throws Exception JavaDoc {
47         Launcher launcher = new Launcher();
48         launcher.initializeFractal();
49         assertNotNull(launcher.petalsComposite);
50     }
51
52     public void testInitializeMonolog() throws IOException JavaDoc {
53         Launcher launcher = new Launcher();
54         String JavaDoc classDir = this.getClass().getResource(".").toString();
55         String JavaDoc targetDir = classDir.substring(0, classDir
56             .indexOf("test-classes"));
57         targetDir = targetDir.substring(targetDir.indexOf(":") + 1);
58         File JavaDoc tmpPH = new File JavaDoc(targetDir);
59         new File JavaDoc(targetDir + File.separator + "logs").mkdir();
60         SystemUtil.setPetalsInstallDirectory(tmpPH);
61         launcher.initializeMonolog();
62         assertEquals(Monolog.monologFactory.getClass().getName(),
63             "org.objectweb.petals.util.monolog.wrapper.javalog.LoggerFactory");
64     }
65
66     
67
68     public void testGetComponentByName() throws NoSuchInterfaceException {
69         ContentController contentController = EasyMock
70             .createMock(ContentController.class);
71         Component component = EasyMock.createMock(Component.class);
72         NameController nameController = EasyMock
73             .createMock(NameController.class);
74
75         Component[] compos = new Component[] {component};
76
77         EasyMock.expect(contentController.getFcSubComponents()).andReturn(
78             compos).anyTimes();
79         EasyMock.expect(component.getFcInterface("name-controller")).andReturn(
80             nameController).anyTimes();
81         EasyMock.expect(nameController.getFcName()).andReturn("test")
82             .anyTimes();
83
84         EasyMock.replay(contentController);
85         EasyMock.replay(component);
86         EasyMock.replay(nameController);
87
88         assertEquals(component, FractalHelper.getComponentByName(contentController,
89             "test"));
90     }
91
92     public void testGetComponentByNameException()
93         throws NoSuchInterfaceException {
94         ContentController contentController = EasyMock
95             .createMock(ContentController.class);
96         Component component = EasyMock.createMock(Component.class);
97
98         Component[] compos = new Component[] {component};
99
100         EasyMock.expect(contentController.getFcSubComponents()).andReturn(
101             compos).anyTimes();
102         EasyMock.expect(component.getFcInterface("name-controller")).andThrow(
103             new NoSuchInterfaceException("name-controller"));
104
105         EasyMock.replay(contentController);
106         EasyMock.replay(component);
107
108         assertNull(FractalHelper.getComponentByName(contentController, "test"));
109     }
110
111     
112     public void testRun() throws Exception JavaDoc {
113       /*
114        * TODO fix crashing test
115        * Launcher launcher = EasyMock.createMock(Launcher.class, new Method[] {
116             Launcher.class.getDeclaredMethod("initializeMonolog",
117                 new Class[] {}),
118             Launcher.class.getDeclaredMethod("getComponentByName", new Class[] {
119                 ContentController.class, String.class})});
120         Component component = EasyMock.createMock(Component.class);
121         ContentController contentController = EasyMock
122             .createMock(ContentController.class);
123         Component[] compos = new Component[] {component};
124         NameController nameController = EasyMock
125             .createMock(NameController.class);
126         Component agent = EasyMock.createMock(Component.class);
127         Admin admin = EasyMock.createMock(Admin.class);
128         LifeCycleController lifeCycleController = EasyMock
129             .createMock(LifeCycleController.class);
130         AttributeController attributeController = EasyMock
131             .createMock(AttributeController.class);
132         AdminAttributes adminAttributes = EasyMock
133             .createMock(AdminAttributes.class);
134         MBeanServer mBeanServer = EasyMock.createMock(MBeanServer.class);
135         Component jbi = EasyMock.createMock(Component.class);
136         Component system = EasyMock.createMock(Component.class);
137         SystemState systemState = EasyMock.createMock(SystemState.class);
138
139         EasyMock.expect(component.getFcInterface("content-controller"))
140             .andReturn(contentController).anyTimes();
141         EasyMock.expect(component.getFcInterface("name-controller")).andReturn(
142             nameController).anyTimes();
143         EasyMock.expect(component.getFcInterface("lifecycle-controller"))
144             .andReturn(lifeCycleController).anyTimes();
145
146         EasyMock.expect(contentController.getFcSubComponents()).andReturn(
147             compos).anyTimes();
148         launcher.initializeMonolog();
149         launcher.initializeFractal();
150         EasyMock.expect(
151             launcher.getComponentByName(contentController, "agent-jmx"))
152             .andReturn(agent).anyTimes();
153         EasyMock.expect(agent.getFcInterface("admin")).andReturn(admin);
154         admin.expose();
155         EasyMock.expect(agent.getFcInterface("attribute-controller"))
156             .andReturn(adminAttributes);
157         EasyMock.expect(adminAttributes.getRawMBeanServer()).andReturn(
158             mBeanServer);
159         EasyMock.expect(launcher.getComponentByName(contentController, "jbi"))
160             .andReturn(jbi);
161         EasyMock.expect(jbi.getFcInterface("content-controller")).andReturn(
162             contentController);
163         EasyMock.expect(
164             launcher.getComponentByName(contentController, "systemstate-impl"))
165             .andReturn(system);
166         EasyMock.expect(system.getFcInterface("service"))
167             .andReturn(systemState);
168         EasyMock.expect(systemState.recoverAllEntities()).andReturn(
169             Boolean.TRUE);
170         EasyMock.expect(lifeCycleController.getFcState()).andReturn(
171             LifeCycleController.STARTED).anyTimes();
172         lifeCycleController.stopFc();
173
174         EasyMock.replay(jbi);
175         EasyMock.replay(systemState);
176         EasyMock.replay(system);
177         EasyMock.replay(adminAttributes);
178         EasyMock.replay(lifeCycleController);
179         EasyMock.replay(attributeController);
180         EasyMock.replay(launcher);
181         EasyMock.replay(agent);
182         EasyMock.replay(admin);
183         EasyMock.replay(nameController);
184         EasyMock.replay(contentController);
185         EasyMock.replay(component);
186
187         launcher.petalsComposite = component;
188         launcher.run(new String[0]);*/

189     }
190
191 }
192
Popular Tags