use of org.apache.felix.ipojo.runtime.core.services.CheckService in project felix by apache.
the class TestServiceController method testArchitecture.
@Test
public void testArchitecture() {
ComponentInstance ci = ipojoHelper.createComponentInstance("PS-Controller-1-default");
// Controller set to true.
osgiHelper.waitForService(FooService.class.getName(), null, 5000);
osgiHelper.waitForService(CheckService.class.getName(), null, 5000);
ProvidedServiceHandlerDescription pshd = null;
pshd = (ProvidedServiceHandlerDescription) ci.getInstanceDescription().getHandlerDescription("org.apache.felix.ipojo:provides");
ProvidedServiceDescription ps = getPS(FooService.class.getName(), pshd.getProvidedServices());
assertEquals("true", ps.getController());
CheckService check = (CheckService) osgiHelper.getServiceObject(CheckService.class.getName(), null);
assertNotNull(check);
assertFalse(check.check());
ps = getPS(FooService.class.getName(), pshd.getProvidedServices());
assertEquals("false", ps.getController());
assertTrue(check.check());
ps = getPS(FooService.class.getName(), pshd.getProvidedServices());
assertEquals("true", ps.getController());
}
use of org.apache.felix.ipojo.runtime.core.services.CheckService in project felix by apache.
the class TestServiceController method testComponentWithTwoControllersSetToTrue.
@Test
public void testComponentWithTwoControllersSetToTrue() {
ComponentInstance ci = ipojoHelper.createComponentInstance("PS-Controller-2-truetrue");
osgiHelper.waitForService(CheckService.class.getName(), null, 5000);
osgiHelper.waitForService(FooService.class.getName(), null, 5000);
CheckService check = (CheckService) osgiHelper.getServiceObject(CheckService.class.getName(), null);
assertNotNull(check);
check.check();
assertNull(osgiHelper.getServiceReference(CheckService.class.getName()));
assertNotNull(osgiHelper.getServiceReference(FooService.class.getName()));
FooService fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), null);
fs.foo();
assertNull(osgiHelper.getServiceReference(CheckService.class.getName()));
assertNull(osgiHelper.getServiceReference(FooService.class.getName()));
ci.dispose();
}
use of org.apache.felix.ipojo.runtime.core.services.CheckService in project felix by apache.
the class TestServiceController method testComponentWithAController.
@Test
public void testComponentWithAController() {
ComponentInstance ci = ipojoHelper.createComponentInstance("PS-Controller-1-default");
// Controller set to true.
osgiHelper.waitForService(FooService.class.getName(), null, 5000);
osgiHelper.waitForService(CheckService.class.getName(), null, 5000);
CheckService check = (CheckService) osgiHelper.getServiceObject(CheckService.class.getName(), null);
assertNotNull(check);
assertFalse(check.check());
// FooService should not be there anymore
assertNull(osgiHelper.getServiceReference(FooService.class.getName()));
assertTrue(check.check());
assertNotNull(osgiHelper.getServiceReference(FooService.class.getName()));
ci.dispose();
}
use of org.apache.felix.ipojo.runtime.core.services.CheckService in project felix by apache.
the class TestServiceController method testComponentWithTwoControllersUsingSpecificationAndAllTrueFalse.
@Test
public void testComponentWithTwoControllersUsingSpecificationAndAllTrueFalse() {
ComponentInstance ci = ipojoHelper.createComponentInstance("PS-Controller-2-spec4");
osgiHelper.waitForService(CheckService.class.getName(), null, 5000);
assertFalse(osgiHelper.isServiceAvailable(FooService.class.getName()));
CheckService check = (CheckService) osgiHelper.getServiceObject(CheckService.class.getName(), null);
assertNotNull(check);
check.getProps();
assertFalse(osgiHelper.isServiceAvailable(CheckService.class.getName()));
assertTrue(osgiHelper.isServiceAvailable(FooService.class.getName()));
FooService fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), null);
fs.fooProps();
assertTrue(osgiHelper.isServiceAvailable(CheckService.class.getName()));
assertTrue(osgiHelper.isServiceAvailable(FooService.class.getName()));
ci.dispose();
}
use of org.apache.felix.ipojo.runtime.core.services.CheckService in project felix by apache.
the class CustomStrategy2Test method testObjectCreation.
@Test
public void testObjectCreation() {
prov.start();
// The two consumers are started and use their own objects.
ServiceReference refcons1 = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), cons1.getInstanceName());
assertNotNull("Cons1 Service available", refcons1);
CheckService cs_cons1 = (CheckService) osgiHelper.getRawServiceObject(refcons1);
Properties props = cs_cons1.getProps();
FooService fscons1 = (FooService) props.get("object");
ServiceReference refcons2 = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), cons2.getInstanceName());
assertNotNull("Cons2 Service available", refcons2);
CheckService cs_cons2 = (CheckService) osgiHelper.getRawServiceObject(refcons2);
Properties props2 = cs_cons2.getProps();
FooService fscons2 = (FooService) props2.get("object");
checkCreatedObjects(prov, 2);
assertNotSame("Two objects", fscons1, fscons2);
// Stop the provider
prov.stop();
// Cons1 and 2 are invalid.
assertEquals("Cons1 invalidity", ComponentInstance.INVALID, cons1.getState());
assertEquals("Cons2 invalidity", ComponentInstance.INVALID, cons2.getState());
// No object created in prov
checkCreatedObjects(prov, 0);
// Restart the provider
prov.start();
// Consumers are valid.
assertEquals("Cons1 validity", ComponentInstance.VALID, cons1.getState());
assertEquals("Cons2 validity", ComponentInstance.VALID, cons2.getState());
// Check objects
refcons1 = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), cons1.getInstanceName());
assertNotNull("Cons1 Service available", refcons1);
cs_cons1 = (CheckService) osgiHelper.getRawServiceObject(refcons1);
props = cs_cons1.getProps();
Object fscons3 = (FooService) props.get("object");
refcons2 = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), cons2.getInstanceName());
assertNotNull("Cons2 Service available", refcons2);
cs_cons2 = (CheckService) osgiHelper.getRawServiceObject(refcons2);
props2 = cs_cons2.getProps();
Object fscons4 = (FooService) props2.get("object");
checkCreatedObjects(prov, 2);
assertNotSame("Two objects", fscons3, fscons4);
assertNotSame("Two new objects - 1", fscons3, fscons1);
assertNotSame("Two new objects - 2", fscons4, fscons2);
}
Aggregations