use of org.easymock.MockControl in project felix by apache.
the class ServiceRegistryTest method testRegisterPlainService.
public void testRegisterPlainService() {
MockControl control = MockControl.createNiceControl(Bundle.class);
Bundle b = (Bundle) control.getMock();
control.replay();
MockControl controlContext = MockControl.createNiceControl(BundleContext.class);
BundleContext c = (BundleContext) controlContext.getMock();
controlContext.expectAndReturn(c.getBundle(), b);
controlContext.replay();
ServiceRegistry sr = new ServiceRegistry(new Logger(), null);
String svcObj = "hello";
assertEquals("Precondition failed", 0, sr.getHookRegistry().getHooks(EventHook.class).size());
assertEquals("Precondition failed", 0, sr.getHookRegistry().getHooks(FindHook.class).size());
assertEquals("Precondition failed", 0, sr.getHookRegistry().getHooks(ListenerHook.class).size());
ServiceRegistration reg = sr.registerService(c.getBundle(), new String[] { String.class.getName() }, svcObj, new Hashtable());
assertEquals("Postcondition failed", 0, sr.getHookRegistry().getHooks(EventHook.class).size());
assertEquals("Postcondition failed", 0, sr.getHookRegistry().getHooks(FindHook.class).size());
assertEquals("Postcondition failed", 0, sr.getHookRegistry().getHooks(ListenerHook.class).size());
sr.unregisterService(b, reg);
assertEquals("Unregistration should have no effect", 0, sr.getHookRegistry().getHooks(EventHook.class).size());
assertEquals("Unregistration should have no effect", 0, sr.getHookRegistry().getHooks(FindHook.class).size());
assertEquals("Unregistration should have no effect", 0, sr.getHookRegistry().getHooks(ListenerHook.class).size());
}
use of org.easymock.MockControl in project felix by apache.
the class ServiceRegistryTest method testRegisterListenerHookService.
public void testRegisterListenerHookService() {
MockControl control = MockControl.createNiceControl(Bundle.class);
Bundle b = (Bundle) control.getMock();
control.replay();
MockControl controlContext = MockControl.createNiceControl(BundleContext.class);
BundleContext c = (BundleContext) controlContext.getMock();
controlContext.expectAndReturn(c.getBundle(), b);
controlContext.replay();
ServiceRegistry sr = new ServiceRegistry(new Logger(), null);
ListenerHook hook = new ListenerHook() {
@Override
public void added(Collection listeners) {
}
@Override
public void removed(Collection listener) {
}
};
assertEquals("Precondition failed", 0, sr.getHookRegistry().getHooks(EventHook.class).size());
assertEquals("Precondition failed", 0, sr.getHookRegistry().getHooks(FindHook.class).size());
assertEquals("Precondition failed", 0, sr.getHookRegistry().getHooks(ListenerHook.class).size());
ServiceRegistration reg = sr.registerService(c.getBundle(), new String[] { ListenerHook.class.getName() }, hook, new Hashtable());
assertEquals(1, sr.getHookRegistry().getHooks(ListenerHook.class).size());
assertSame(reg.getReference(), sr.getHookRegistry().getHooks(ListenerHook.class).iterator().next());
assertSame(hook, ((ServiceRegistrationImpl) reg).getService());
assertEquals("Postcondition failed", 0, sr.getHookRegistry().getHooks(EventHook.class).size());
assertEquals("Postcondition failed", 0, sr.getHookRegistry().getHooks(FindHook.class).size());
sr.unregisterService(b, reg);
assertEquals("Should be no hooks left after unregistration", 0, sr.getHookRegistry().getHooks(EventHook.class).size());
assertEquals("Should be no hooks left after unregistration", 0, sr.getHookRegistry().getHooks(FindHook.class).size());
assertEquals("Should be no hooks left after unregistration", 0, sr.getHookRegistry().getHooks(ListenerHook.class).size());
}
use of org.easymock.MockControl in project felix by apache.
the class ServiceRegistryTest method testRegisterListenerHookServiceFactory.
public void testRegisterListenerHookServiceFactory() {
MockControl control = MockControl.createNiceControl(Bundle.class);
Bundle b = (Bundle) control.getMock();
control.replay();
MockControl controlContext = MockControl.createNiceControl(BundleContext.class);
BundleContext c = (BundleContext) controlContext.getMock();
controlContext.expectAndReturn(c.getBundle(), b);
controlContext.replay();
ServiceRegistry sr = new ServiceRegistry(new Logger(), null);
MockControl sfControl = MockControl.createNiceControl(ServiceFactory.class);
sfControl.replay();
ServiceFactory sf = (ServiceFactory) sfControl.getMock();
assertEquals("Precondition failed", 0, sr.getHookRegistry().getHooks(EventHook.class).size());
assertEquals("Precondition failed", 0, sr.getHookRegistry().getHooks(FindHook.class).size());
assertEquals("Precondition failed", 0, sr.getHookRegistry().getHooks(ListenerHook.class).size());
ServiceRegistration reg = sr.registerService(c.getBundle(), new String[] { ListenerHook.class.getName() }, sf, new Hashtable());
assertEquals(1, sr.getHookRegistry().getHooks(ListenerHook.class).size());
assertSame(reg.getReference(), sr.getHookRegistry().getHooks(ListenerHook.class).iterator().next());
assertSame(sf, ((ServiceRegistrationImpl) reg).getService());
assertEquals("Postcondition failed", 0, sr.getHookRegistry().getHooks(EventHook.class).size());
assertEquals("Postcondition failed", 0, sr.getHookRegistry().getHooks(FindHook.class).size());
sr.unregisterService(b, reg);
assertEquals("Should be no hooks left after unregistration", 0, sr.getHookRegistry().getHooks(EventHook.class).size());
assertEquals("Should be no hooks left after unregistration", 0, sr.getHookRegistry().getHooks(FindHook.class).size());
assertEquals("Should be no hooks left after unregistration", 0, sr.getHookRegistry().getHooks(ListenerHook.class).size());
}
use of org.easymock.MockControl in project felix by apache.
the class ServiceRegistryTest method testRegisterEventHookServiceFactory.
public void testRegisterEventHookServiceFactory() {
MockControl control = MockControl.createNiceControl(Bundle.class);
Bundle b = (Bundle) control.getMock();
control.replay();
MockControl controlContext = MockControl.createNiceControl(BundleContext.class);
BundleContext c = (BundleContext) controlContext.getMock();
controlContext.expectAndReturn(c.getBundle(), b);
controlContext.replay();
ServiceRegistry sr = new ServiceRegistry(new Logger(), null);
MockControl sfControl = MockControl.createNiceControl(ServiceFactory.class);
sfControl.replay();
ServiceFactory sf = (ServiceFactory) sfControl.getMock();
assertEquals("Precondition failed", 0, sr.getHookRegistry().getHooks(EventHook.class).size());
assertEquals("Precondition failed", 0, sr.getHookRegistry().getHooks(FindHook.class).size());
assertEquals("Precondition failed", 0, sr.getHookRegistry().getHooks(ListenerHook.class).size());
ServiceRegistration reg = sr.registerService(c.getBundle(), new String[] { EventHook.class.getName() }, sf, new Hashtable());
assertEquals(1, sr.getHookRegistry().getHooks(EventHook.class).size());
assertSame(reg.getReference(), sr.getHookRegistry().getHooks(EventHook.class).iterator().next());
assertSame(sf, ((ServiceRegistrationImpl) reg).getService());
assertEquals("Postcondition failed", 0, sr.getHookRegistry().getHooks(FindHook.class).size());
assertEquals("Postcondition failed", 0, sr.getHookRegistry().getHooks(ListenerHook.class).size());
sr.unregisterService(b, reg);
assertEquals("Should be no hooks left after unregistration", 0, sr.getHookRegistry().getHooks(EventHook.class).size());
assertEquals("Should be no hooks left after unregistration", 0, sr.getHookRegistry().getHooks(FindHook.class).size());
assertEquals("Should be no hooks left after unregistration", 0, sr.getHookRegistry().getHooks(ListenerHook.class).size());
}
use of org.easymock.MockControl in project maven-archetype by apache.
the class DefaultArchetypeGenerationConfiguratorTest method setUp.
public void setUp() throws Exception {
super.setUp();
configurator = (DefaultArchetypeGenerationConfigurator) lookup(ArchetypeGenerationConfigurator.ROLE);
ProjectBuildingRequest buildingRequest = null;
MockControl control = MockControl.createControl(ArchetypeArtifactManager.class);
control.setDefaultMatcher(MockControl.ALWAYS_MATCHER);
ArchetypeArtifactManager manager = (ArchetypeArtifactManager) control.getMock();
manager.exists("archetypeGroupId", "archetypeArtifactId", "archetypeVersion", null, null, null, buildingRequest);
control.setReturnValue(true);
manager.isFileSetArchetype("archetypeGroupId", "archetypeArtifactId", "archetypeVersion", null, null, null, buildingRequest);
control.setReturnValue(false);
manager.isOldArchetype("archetypeGroupId", "archetypeArtifactId", "archetypeVersion", null, null, null, buildingRequest);
control.setReturnValue(true);
manager.getOldArchetypeDescriptor("archetypeGroupId", "archetypeArtifactId", "archetypeVersion", null, null, null, buildingRequest);
control.setReturnValue(new ArchetypeDescriptor());
control.replay();
configurator.setArchetypeArtifactManager(manager);
}
Aggregations