use of org.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.
the class CustomStrategyTest method testOneService.
@Test
public void testOneService() {
prov.start();
cons2.stop();
cons1.stop();
assertEquals("Prov valid", ComponentInstance.VALID, prov.getState());
ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), prov.getInstanceName());
assertNotNull("Service available", ref);
checkCreatedObjects(prov, 0);
// Step 1 : create start one consumer
cons1.start();
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();
Long id = (Long) props.get("id");
FooService fscons1 = (FooService) props.get("object");
assertEquals("id 1", 1, id.intValue());
checkCreatedObjects(prov, 1);
// Step 2 : create a second consumer
cons2.start();
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();
Long id2 = (Long) props2.get("id");
FooService fscons2 = (FooService) props2.get("object");
assertEquals("id 2", 2, id2.intValue());
checkCreatedObjects(prov, 2);
assertNotSame("Two objects", fscons1, fscons2);
// Step 3 : stop the second provider
System.out.println("cons2 stopping");
cons2.stop();
System.out.println("cons2 stopped");
checkCreatedObjects(prov, 1);
// Step 4 : stop the first consumer
cons1.stop();
checkCreatedObjects(prov, 0);
}
use of org.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.
the class PerInstanceStrategyTest method testOneService.
@Test
public void testOneService() {
prov.start();
cons2.stop();
cons1.stop();
assertEquals("Prov valid", ComponentInstance.VALID, prov.getState());
ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), prov.getInstanceName());
assertNotNull("Service available", ref);
checkCreatedObjects(prov, 0);
// Step 1 : create start one consumer
cons1.start();
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();
Long id = (Long) props.get("id");
FooService fscons1 = (FooService) props.get("object");
assertEquals("id 1", 1, id.intValue());
checkCreatedObjects(prov, 1);
// Step 2 : create a second consumer
cons2.start();
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();
Long id2 = (Long) props2.get("id");
FooService fscons2 = (FooService) props2.get("object");
assertEquals("id 2", 2, id2.intValue());
checkCreatedObjects(prov, 2);
assertNotSame("Two objects", fscons1, fscons2);
// Step 3 : stop the second provider
System.out.println("cons2 stopping");
cons2.stop();
System.out.println("cons2 stopped");
checkCreatedObjects(prov, 1);
// Step 4 : stop the first consumer
cons1.stop();
checkCreatedObjects(prov, 0);
}
use of org.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.
the class TestTypedList method getProps.
public Properties getProps() {
Properties props = new Properties();
if (list != null) {
props.put("list", list);
int i = 0;
for (FooService fs : list) {
props.put(i, fs.foo());
i++;
}
}
return props;
}
use of org.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.
the class TestExceptionHandling method testTry.
/**
* Check that the exception is correctly catch by the POJO.
*/
@Test
public void testTry() {
ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), ci_lazzy.getInstanceName());
assertNotNull("Check that a FooService from " + ci_lazzy.getInstanceName() + " is available", ref);
FooProviderType1 fs = (FooProviderType1) osgiHelper.getServiceObject(ref);
try {
fs.testTry();
} catch (Exception e) {
fail("The method has returned an exception");
}
}
use of org.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.
the class TestManagedServiceFactoryTestForImmediate method testCreationAndReconfiguration2.
@Test
public void testCreationAndReconfiguration2() {
// The reconfiguration happens before the service invocation
Configuration configuration = null;
try {
configuration = admin.createFactoryConfiguration("CA-ImmConfigurableProvider", "?");
} catch (IOException e) {
fail(e.getMessage());
}
Dictionary props = configuration.getProperties();
if (props == null) {
props = new Properties();
}
props.put("message", "message");
try {
configuration.update(props);
} catch (IOException e) {
fail(e.getMessage());
}
String pid = configuration.getPid();
System.out.println("PID : " + pid);
// Wait for the processing of the first configuration.
grace();
// The instance should be created, wait for the architecture service
osgiHelper.waitForService(Architecture.class.getName(), "(architecture.instance=" + pid + ")", 1000);
Architecture architecture = (Architecture) osgiHelper.getServiceObject(Architecture.class.getName(), "(architecture.instance=" + pid + ")");
assertEquals("Check object", 1, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
props.put("message", "message2");
try {
configuration.update(props);
// Update the configuration ...
grace();
} catch (Exception e) {
fail(e.getMessage());
}
// architecture = (Architecture) osgiHelper.getServiceObject( Architecture.class.getName(), "(architecture.instance="+pid+")");
assertEquals("Check object -2", 1, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
// Invoke
FooService fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), "(instance.name=" + pid + ")");
Properties p = fs.fooProps();
String mes = p.getProperty("message");
int count = ((Integer) p.get("count")).intValue();
// architecture = (Architecture) osgiHelper.getServiceObject( Architecture.class.getName(), "(architecture.instance="+pid+")");
assertEquals("Assert Message", "message2", mes);
assertEquals("Assert count", 2, count);
assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
try {
configuration.delete();
grace();
} catch (Exception e) {
fail(e.getMessage());
}
ServiceReference ref = osgiHelper.getServiceReference(FooService.class.getName(), "(instance.name=" + pid + ")");
assertNull("Check unavailability", ref);
}
Aggregations