KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hivemind > test > TestMisc


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package hivemind.test;
16
17 import java.util.HashMap JavaDoc;
18
19 import org.apache.hivemind.ApplicationRuntimeException;
20 import org.apache.hivemind.definition.ImplementationConstructionContext;
21 import org.apache.hivemind.impl.CreateClassServiceConstructor;
22 import org.apache.hivemind.impl.ModuleImpl;
23 import org.apache.hivemind.impl.ServicePointImpl;
24 import org.apache.hivemind.internal.ImplementationConstructionContextImpl;
25 import org.apache.hivemind.internal.Module;
26 import org.apache.hivemind.internal.ServicePoint;
27
28 /**
29  * Additional tests to fill in minor code coverage gaps.
30  *
31  * @author Howard Lewis Ship
32  */

33 public class TestMisc extends FrameworkTestCase
34 {
35     private Module newModule()
36     {
37         ModuleImpl result = new ModuleImpl();
38         result.setClassResolver(getClassResolver());
39
40         return result;
41     }
42
43     public void testApplicationRuntimeExceptionGetComponent()
44     {
45         ApplicationRuntimeException ex = new ApplicationRuntimeException("My Message", this, null,
46                 null);
47
48         assertSame(this, ex.getComponent());
49     }
50
51     public void testApplicationRuntimeExceptionThrowableConstructor()
52     {
53         RuntimeException JavaDoc re = new RuntimeException JavaDoc("Now it can be told.");
54         ApplicationRuntimeException ex = new ApplicationRuntimeException(re);
55
56         assertEquals("Now it can be told.", ex.getMessage());
57         assertSame(re, ex.getRootCause());
58     }
59
60     public void testCreateClassServiceConstructorAccessors()
61     {
62         replayControls();
63
64         CreateClassServiceConstructor c = new CreateClassServiceConstructor(newLocation(),
65                 "java.util.HashMap");
66
67         c.setInstanceClassName("java.util.HashMap");
68
69         assertEquals("java.util.HashMap", c.getInstanceClassName());
70
71         verifyControls();
72     }
73
74     public void testCreateClassServiceConstructorTwice()
75     {
76         Module m = newModule();
77
78         ServicePoint sp = new ServicePointImpl(m, null);
79         
80         replayControls();
81
82         CreateClassServiceConstructor c = new CreateClassServiceConstructor(newLocation(),
83                 "java.util.HashMap");
84
85         ImplementationConstructionContext context = new ImplementationConstructionContextImpl(m, sp);
86         Object JavaDoc o1 = c.constructCoreServiceImplementation(context);
87         Object JavaDoc o2 = c.constructCoreServiceImplementation(context);
88
89         assertNotSame(o1, o2);
90
91         assertTrue(o1 instanceof HashMap JavaDoc);
92         assertTrue(o2 instanceof HashMap JavaDoc);
93     }
94
95     /** @since 1.1 */
96
97     public void testCreateInstanceWithInitializer()
98     {
99         Module m = newModule();
100         
101         ServicePoint sp = new ServicePointImpl(m, null);
102
103         CreateClassServiceConstructor c = new CreateClassServiceConstructor(newLocation(),
104                 SimpleBean.class.getName() + ",value=HiveMind");
105
106         ImplementationConstructionContext context = new ImplementationConstructionContextImpl(m, sp);
107         SimpleBean b = (SimpleBean) c.constructCoreServiceImplementation(context);
108
109         assertEquals("HiveMind", b.getValue());
110     }
111
112     public void testCreateClassServiceConstructorFailure()
113     {
114         Module m = newModule();
115         
116         ServicePoint sp = new ServicePointImpl(m, null);
117
118         CreateClassServiceConstructor c = new CreateClassServiceConstructor(newLocation(),
119                 PrivateBean.class.getName());
120
121         try
122         {
123             ImplementationConstructionContext context = new ImplementationConstructionContextImpl(m, sp);
124             c.constructCoreServiceImplementation(context);
125             unreachable();
126         }
127         catch (Exception JavaDoc ex)
128         {
129             assertExceptionSubstring(
130                     ex,
131                     "Unable to instantiate instance of class hivemind.test.PrivateBean");
132         }
133
134     }
135 }
Popular Tags