KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > TestBeanService


1 // Copyright 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 org.apache.hivemind;
16
17 import hivemind.test.FrameworkTestCase;
18
19 import org.apache.hivemind.definition.ServicePointDefinition;
20 import org.apache.hivemind.definition.impl.ModuleDefinitionHelper;
21 import org.apache.hivemind.definition.impl.ModuleDefinitionImpl;
22 import org.apache.hivemind.internal.ServiceModel;
23
24 /**
25  * Integration tests to prove that HiveMind supports JavaBeans classes as the "interface" of a
26  * service point.
27  *
28  * @author Howard M. Lewis Ship
29  * @since 1.1
30  */

31 public class TestBeanService extends FrameworkTestCase
32 {
33
34     private void attempt(String JavaDoc serviceModel) throws Exception JavaDoc
35     {
36         Registry reg = createRegistryWithPojo(serviceModel);
37
38         Reverser r = (Reverser) reg.getService("bean.Reverser", Reverser.class);
39
40         assertEquals("DNIMEVIH", r.reverse("HIVEMIND"));
41         // Call reverse a second time to check for HIVEMIND-118
42
r.reverse("HIVEMIND");
43         reg.shutdown();
44
45         try
46         {
47             r.reverse("SHUTDOWN");
48             unreachable();
49         }
50         catch (ApplicationRuntimeException ex)
51         {
52         }
53     }
54
55     public void testSimple() throws Exception JavaDoc
56     {
57         attempt(ServiceModel.SINGLETON);
58     }
59
60     public void testThreaded() throws Exception JavaDoc
61     {
62         attempt(ServiceModel.THREADED);
63     }
64     
65     public void testPooled() throws Exception JavaDoc
66     {
67         attempt(ServiceModel.POOLED);
68     }
69     
70     /**
71      * Creates a Registry with one module, that defines a Service "Reverser" which is a POJO
72      */

73     private Registry createRegistryWithPojo(final String JavaDoc serviceModel)
74     {
75         ModuleDefinitionImpl module = createModuleDefinition("bean");
76         ModuleDefinitionHelper helper = new ModuleDefinitionHelper(module);
77
78         ServicePointDefinition sp1 = helper.addServicePoint("Reverser", Reverser.class.getName());
79         helper.addSimpleServiceImplementation(sp1, Reverser.class.getName(), serviceModel);
80
81         return buildFrameworkRegistry(module);
82     }
83 }
Popular Tags