1 15 package hivemind.test.services; 16 17 import hivemind.test.FrameworkTestCase; 18 import hivemind.test.services.impl.StartupRunnableFixtureImpl; 19 20 import java.util.ArrayList ; 21 import java.util.List ; 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 37 public class TestStartup extends FrameworkTestCase 38 { 39 40 public void testStartupImpl() 41 { 42 StartupRunnableFixture fixture = new StartupRunnableFixtureImpl(); 43 44 List l = new ArrayList (); 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 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 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 helper.addContributionDefinition("hivemind.Startup", new Contribution() 81 { 82 public void contribute(ContributionContext context) 83 { 84 List contribution = new ArrayList (); 85 contribution.add(context.getService(StartupRunnableFixture.class)); 86 context.mergeContribution(contribution); 87 } 88 }); 89 90 return buildFrameworkRegistry(module); 91 } 92 93 } 94 | Popular Tags |