KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > jbi > component > context > InstallationContextImplTest


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: InstallationContextImplTest.java 1:55:33 PM ddesjardins $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.jbi.component.context;
23
24 import java.util.ArrayList JavaDoc;
25 import java.util.List JavaDoc;
26
27 import javax.jbi.component.ComponentContext;
28
29 import junit.framework.TestCase;
30
31 import org.easymock.classextension.EasyMock;
32 import org.objectweb.petals.jbi.component.context.ComponentContextImpl;
33 import org.objectweb.petals.jbi.component.context.InstallationContextImpl;
34 import org.objectweb.petals.tools.jbicommon.descriptor.ComponentDescription;
35 import org.objectweb.petals.tools.jbicommon.descriptor.Identification;
36
37 /**
38  * Test of the InstallationContextImpl
39  *
40  * @author ddesjardins - eBMWebsourcing
41  * @author wjoseph - eBM-Websourcing
42  */

43 public class InstallationContextImplTest extends TestCase {
44
45     private InstallationContextImpl installationContextImpl;
46
47     private ComponentContextImpl componentContextImpl;
48
49     public void setUp() {
50         ComponentDescription componentDescription = EasyMock
51             .createMock(ComponentDescription.class);
52         EasyMock.expect(componentDescription.getComponentClassName())
53             .andReturn("testClassName").anyTimes();
54         List JavaDoc<String JavaDoc> classpaths = new ArrayList JavaDoc<String JavaDoc>();
55         classpaths.add("server.jar");
56         EasyMock.expect(componentDescription.getComponentClassPath())
57             .andReturn(classpaths).anyTimes();
58
59         Identification identification = EasyMock
60             .createMock(Identification.class);
61         EasyMock.expect(identification.getName()).andReturn("compoName")
62             .anyTimes();
63         EasyMock.replay(identification);
64
65         EasyMock.expect(componentDescription.getIdentification()).andReturn(
66             identification).anyTimes();
67         EasyMock.replay(componentDescription);
68
69         componentContextImpl = new ComponentContextImpl();
70         componentContextImpl.installationRoot = "install";
71
72         installationContextImpl = new InstallationContextImpl(
73             componentDescription, componentContextImpl, true);
74     }
75
76     public void testGetClassPathElements() {
77         List JavaDoc result = installationContextImpl.getClassPathElements();
78         assertNotNull("The result of getClassPathElements must not be null",result);
79         assertFalse("The list of classpath elements must not be empty",result.isEmpty());
80         assertEquals(result.get(0),
81             "server.jar");
82     }
83
84     public void testGetComponentClassName() {
85         String JavaDoc result = installationContextImpl.getComponentClassName();
86         assertNotNull("The result of getComponentClassName must not be null",result);
87         assertFalse("The result of getComponentClassName must not be empty",result.length() == 0);
88         assertEquals(result,"testClassName");
89     }
90
91     public void testGetComponentName() {
92         String JavaDoc result = installationContextImpl.getComponentName();
93         assertNotNull("The result of getComponentName must not be null",result);
94         assertFalse("The result of getComponentName must not be empty",result.length() == 0);
95         assertEquals(result, "compoName");
96     }
97
98     public void testGetContext() {
99         ComponentContext result = installationContextImpl.getContext();
100         assertNotNull("The result of getContext must not be null",result);
101         assertEquals(result.getInstallRoot(),
102             componentContextImpl.getInstallRoot());
103     }
104
105     public void testGetInstallationDescriptorExtension() {
106         assertNull(installationContextImpl.getInstallationDescriptorExtension());
107     }
108
109     public void testGetInstallRoot() {
110         String JavaDoc result = installationContextImpl.getInstallRoot();
111         assertNotNull("The result of getInstallRoot must not be null",result);
112         assertFalse("The result of getInstallRoot must not be empty",result.length() == 0);
113         assertEquals(result, "install");
114     }
115
116     public void testIsInstall() {
117         assertTrue(installationContextImpl.isInstall());
118     }
119     
120     public void testSetClassPathElements() {
121         /*
122          * Test Case 1
123          * The classPathElements parameter is null
124          */

125         List JavaDoc<String JavaDoc> classPathElements = null;
126         /*
127          * Run Test Case 1
128          */

129         try {
130         installationContextImpl.setClassPathElements(classPathElements);
131         fail("No exception was raised");
132         } catch (Exception JavaDoc e) {
133             // Do nothing
134
}
135         /*
136          * Test Case 2
137          * The classPathElements parameter is empty
138          */

139         classPathElements = new ArrayList JavaDoc<String JavaDoc>();
140         /*
141          * Run Test Case 2
142          */

143         try {
144         installationContextImpl.setClassPathElements(classPathElements);
145         fail("No exception was raised");
146         } catch (Exception JavaDoc e) {
147             // Do nothing
148
}
149         /*
150          * Test Case 2
151          * The classPathElements parameter is fine
152          */

153         classPathElements.add("some class path");
154         /*
155          * Run Test Case 2
156          */

157         try {
158         installationContextImpl.setClassPathElements(classPathElements);
159         } catch (Exception JavaDoc e) {
160             e.printStackTrace();
161             fail("Error during method invokation");
162         }
163         assertEquals("The classPathElements ware not properly set",installationContextImpl.getClassPathElements(), classPathElements);
164     }
165
166 }
167
Popular Tags