1 15 package hivemind.test.services; 16 17 import hivemind.test.FrameworkTestCase; 18 import hivemind.test.services.impl.LoudRunner; 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.internal.ServiceModel; 30 import org.apache.hivemind.internal.ServicePoint; 31 import org.apache.hivemind.service.impl.EagerLoader; 32 33 38 public class TestEagerLoader extends FrameworkTestCase 39 { 40 public void testEagerLoaderImpl() 41 { 42 EagerLoader el = new EagerLoader(); 43 List l = new ArrayList (); 44 45 ServicePoint sp = (ServicePoint) newMock(ServicePoint.class); 46 47 sp.forceServiceInstantiation(); 48 49 replayControls(); 50 51 l.add(sp); 52 53 el.setServicePoints(l); 54 55 el.run(); 56 57 verifyControls(); 58 } 59 60 public void testEagerLoadSingleton() throws Exception 61 { 62 interceptLogging("hivemind.test.services.Loud"); 63 64 createEagerLoadModule(ServiceModel.SINGLETON); 65 66 assertLoggedMessage("Instantiated."); 67 } 68 69 public void testEagerLoadPrimitive() throws Exception 70 { 71 interceptLogging("hivemind.test.services.Loud"); 72 73 createEagerLoadModule(ServiceModel.PRIMITIVE); 74 75 assertLoggedMessage("Instantiated."); 76 } 77 78 public void testEagerLoadThreaded() throws Exception 79 { 80 interceptLogging("hivemind.test.services.Loud"); 81 82 createEagerLoadModule(ServiceModel.THREADED); 83 84 assertLoggedMessage("Instantiated."); 85 } 86 87 public void testEagerLoadPooled() throws Exception 88 { 89 interceptLogging("hivemind.test.services.Loud"); 90 91 createEagerLoadModule(ServiceModel.POOLED); 92 93 assertLoggedMessage("Instantiated."); 94 } 95 96 100 private Registry createEagerLoadModule(final String serviceModel) 101 { 102 ModuleDefinitionImpl module = createModuleDefinition("hivemind.test.services"); 103 ModuleDefinitionHelper helper = new ModuleDefinitionHelper(module); 104 105 ServicePointDefinition sp1 = helper.addServicePoint("Loud", Runnable .class.getName()); 106 helper.addSimpleServiceImplementation(sp1, LoudRunner.class.getName(), serviceModel); 107 108 helper.addContributionDefinition("hivemind.EagerLoad", new Contribution() 110 { 111 public void contribute(ContributionContext context) 112 { 113 List contribution = new ArrayList (); 114 contribution.add(context.getDefiningModule().getServicePoint("hivemind.test.services.Loud")); 115 context.mergeContribution(contribution); 116 } 117 }); 118 119 return buildFrameworkRegistry(module); 120 } 121 122 } 123 | Popular Tags |