KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hivemind > test > services > TestStartup


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.services;
16
17 import hivemind.test.FrameworkTestCase;
18 import hivemind.test.services.impl.StartupRunnableFixtureImpl;
19
20 import java.util.ArrayList JavaDoc;
21 import java.util.List JavaDoc;
22
23 import org.apache.hivemind.Registry;
24 import org.apache.hivemind.definition.Contribution;
25 import org.apache.hivemind.definition.ContributionContext;
26 import org.apache.hivemind.definition.ServicePointDefinition;
27 import org.apache.hivemind.definition.impl.ModuleDefinitionHelper;
28 import org.apache.hivemind.definition.impl.ModuleDefinitionImpl;
29 import org.apache.hivemind.impl.StartupImpl;
30 import org.apache.hivemind.internal.ServiceModel;
31
32 /**
33  * Tests Registry startup.
34  *
35  * @author Howard Lewis Ship
36  */

37 public class TestStartup extends FrameworkTestCase
38 {
39
40     public void testStartupImpl()
41     {
42         StartupRunnableFixture fixture = new StartupRunnableFixtureImpl();
43
44         List JavaDoc l = new ArrayList JavaDoc();
45         l.add(fixture);
46
47         StartupImpl s = new StartupImpl();
48
49         s.setRunnables(l);
50         s.run();
51
52         assertEquals(true, fixture.getDidRun());
53     }
54
55     public void testStartupContribution() throws Exception JavaDoc
56     {
57         Registry r = createRegistry();
58
59         StartupRunnableFixture fixture =
60             (StartupRunnableFixture) r.getService(
61                 "hivemind.test.services.StartupRunnableFixture",
62                 StartupRunnableFixture.class);
63
64         assertEquals(true, fixture.getDidRun());
65     }
66     
67     /**
68      * Creates a Registry with one module, that defines a Service "Loud" added to the EagerLoad
69      * configuration.
70      */

71     private Registry createRegistry()
72     {
73         ModuleDefinitionImpl module = createModuleDefinition("hivemind.test.services");
74         ModuleDefinitionHelper helper = new ModuleDefinitionHelper(module);
75
76         ServicePointDefinition sp1 = helper.addServicePoint("StartupRunnableFixture", StartupRunnableFixture.class.getName());
77         helper.addSimpleServiceImplementation(sp1, StartupRunnableFixtureImpl.class.getName(), ServiceModel.SINGLETON);
78
79         // Add service point "StartupRunnableFixture" to Startup configuration point
80
helper.addContributionDefinition("hivemind.Startup", new Contribution()
81         {
82             public void contribute(ContributionContext context)
83             {
84                 List JavaDoc contribution = new ArrayList JavaDoc();
85                 contribution.add(context.getService(StartupRunnableFixture.class));
86                 context.mergeContribution(contribution);
87             }
88         });
89
90         return buildFrameworkRegistry(module);
91     }
92
93 }
94
Popular Tags