use of org.apache.felix.scr.integration.components.SimpleServiceImpl in project felix by apache.
the class ComponentActivationTest method testRequiredDependency.
private void testRequiredDependency(final String componentname) throws Exception {
ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(componentname, ComponentConfigurationDTO.UNSATISFIED_REFERENCE);
SimpleServiceImpl ss = SimpleServiceImpl.create(bundleContext, "foo");
findComponentConfigurationByName(componentname, ComponentConfigurationDTO.SATISFIED);
ServiceReference<ActivatorComponent> ref = bundleContext.getServiceReference(ActivatorComponent.class);
ss.drop();
findComponentConfigurationByName(componentname, ComponentConfigurationDTO.UNSATISFIED_REFERENCE);
TestCase.assertNull(bundleContext.getServiceReference(ActivatorComponent.class));
ss = SimpleServiceImpl.create(bundleContext, "foo");
ref = bundleContext.getServiceReference(ActivatorComponent.class);
ActivatorComponent ac = bundleContext.getService(ref);
TestCase.assertNotNull(ac.getSimpleService());
findComponentConfigurationByName(componentname, ComponentConfigurationDTO.ACTIVE);
disableAndCheck(cc);
}
use of org.apache.felix.scr.integration.components.SimpleServiceImpl in project felix by apache.
the class ComponentConfigurationTest method test_SimpleComponent_dynamic_optional_configuration_with_optional_service.
@Test
public void test_SimpleComponent_dynamic_optional_configuration_with_optional_service() throws Exception {
final String targetProp = "ref.target";
final String filterProp = "required";
final SimpleServiceImpl service = SimpleServiceImpl.create(bundleContext, "sample").setFilterProperty(filterProp);
try {
final String pid = "DynamicConfigurationComponentWithOptionalReference";
deleteConfig(pid);
delay();
// optional ref missing --> component active
ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(pid, ComponentConfigurationDTO.ACTIVE);
TestCase.assertNotNull(SimpleComponent.INSTANCE);
final SimpleComponent instance = SimpleComponent.INSTANCE;
// dynamically configure without the correct target
configure(pid);
delay();
// optional ref missing --> component active
findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
TestCase.assertEquals(instance, SimpleComponent.INSTANCE);
TestCase.assertNull(SimpleComponent.INSTANCE.m_singleRef);
// dynamically configure with correct target
theConfig.put(targetProp, "(filterprop=" + filterProp + ")");
configure(pid);
delay();
findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
TestCase.assertEquals(instance, SimpleComponent.INSTANCE);
TestCase.assertEquals(PROP_NAME, SimpleComponent.INSTANCE.getProperty(PROP_NAME));
TestCase.assertEquals(pid, SimpleComponent.INSTANCE.getProperty(Constants.SERVICE_PID));
TestCase.assertNotNull(SimpleComponent.INSTANCE.m_singleRef);
configure(pid);
delay();
// same instance after reconfiguration
findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
TestCase.assertEquals(instance, SimpleComponent.INSTANCE);
TestCase.assertEquals(PROP_NAME, SimpleComponent.INSTANCE.getProperty(PROP_NAME));
TestCase.assertEquals(pid, SimpleComponent.INSTANCE.getProperty(Constants.SERVICE_PID));
TestCase.assertNotNull(SimpleComponent.INSTANCE.m_singleRef);
// reconfigure without target --> active
theConfig.remove(targetProp);
configure(pid);
delay();
// optional ref missing --> component active
findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
TestCase.assertEquals(instance, SimpleComponent.INSTANCE);
TestCase.assertNull(SimpleComponent.INSTANCE.m_singleRef);
deleteConfig(pid);
delay();
// optional ref missing --> component active
findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
TestCase.assertNotSame(instance, SimpleComponent.INSTANCE);
TestCase.assertNull(SimpleComponent.INSTANCE.m_singleRef);
disableAndCheck(cc);
TestCase.assertNull(SimpleComponent.INSTANCE);
} finally {
// Thread.sleep( 60000 );
theConfig.remove(targetProp);
if (service != null) {
service.drop();
}
}
}
use of org.apache.felix.scr.integration.components.SimpleServiceImpl in project felix by apache.
the class ComponentConfigurationTest method test_SimpleComponent_dynamic_optional_configuration_with_required_service2.
/**
* FELIX-3902. Start with filter matching two services, remove one, then change the filter
* to (still) match the other one. 2nd service should remain bound.
*/
@Test
public void test_SimpleComponent_dynamic_optional_configuration_with_required_service2() throws Exception {
final String targetProp = "ref.target";
final String filterProp1 = "one";
final String filterProp2 = "two";
final SimpleServiceImpl service1 = SimpleServiceImpl.create(bundleContext, "one", 1).setFilterProperty(filterProp1);
final SimpleServiceImpl service2 = SimpleServiceImpl.create(bundleContext, "two", 2).setFilterProperty(filterProp2);
try {
final String pid = "DynamicConfigurationComponentWithRequiredReference";
deleteConfig(pid);
delay();
// mandatory ref missing --> component unsatisfied
ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(pid, ComponentConfigurationDTO.UNSATISFIED_REFERENCE);
// dynamically configure without the correct target
configure(pid);
delay();
// mandatory ref missing --> component unsatisfied
findComponentConfigurationByName(pid, ComponentConfigurationDTO.UNSATISFIED_REFERENCE);
// dynamically configure with correct target
theConfig.put(targetProp, "(|(filterprop=" + filterProp1 + ")(filterprop=" + filterProp2 + "))");
configure(pid);
delay();
findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
TestCase.assertNotNull(SimpleComponent.INSTANCE);
TestCase.assertEquals(PROP_NAME, SimpleComponent.INSTANCE.getProperty(PROP_NAME));
TestCase.assertEquals(pid, SimpleComponent.INSTANCE.getProperty(Constants.SERVICE_PID));
final SimpleComponent instance = SimpleComponent.INSTANCE;
configure(pid);
delay();
// remove higher ranked service
if (service2 != null) {
service2.drop();
}
// same instance after reconfiguration
findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
TestCase.assertEquals(instance, SimpleComponent.INSTANCE);
TestCase.assertEquals(PROP_NAME, SimpleComponent.INSTANCE.getProperty(PROP_NAME));
TestCase.assertEquals(pid, SimpleComponent.INSTANCE.getProperty(Constants.SERVICE_PID));
TestCase.assertNotNull(SimpleComponent.INSTANCE.m_singleRef);
// reconfigure with new filter --> active
theConfig.put(targetProp, "(filterprop=" + filterProp1 + ")");
configure(pid);
delay();
// same instance after reconfiguration
findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
TestCase.assertEquals(instance, SimpleComponent.INSTANCE);
TestCase.assertEquals(PROP_NAME, SimpleComponent.INSTANCE.getProperty(PROP_NAME));
TestCase.assertEquals(pid, SimpleComponent.INSTANCE.getProperty(Constants.SERVICE_PID));
TestCase.assertNotNull(SimpleComponent.INSTANCE.m_singleRef);
deleteConfig(pid);
delay();
// mandatory ref missing --> component unsatisfied
findComponentConfigurationByName(pid, ComponentConfigurationDTO.UNSATISFIED_REFERENCE);
disableAndCheck(cc);
TestCase.assertNull(SimpleComponent.INSTANCE);
} finally {
theConfig.remove(targetProp);
if (service1 != null) {
service1.drop();
}
}
}
use of org.apache.felix.scr.integration.components.SimpleServiceImpl in project felix by apache.
the class ConfigurationChangeTest method singleTest.
private void singleTest(String pid, boolean dynamic) throws Exception {
final SimpleServiceImpl srv1 = SimpleServiceImpl.create(bundleContext, "srv1");
final SimpleServiceImpl srv2 = SimpleServiceImpl.create(bundleContext, "srv2");
theConfig.put("ref.target", "(value=srv1)");
configure(pid);
// all cm event to complete
delay();
getDisabledConfigurationAndEnable(pid, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp10 = SimpleComponent.INSTANCE;
TestCase.assertNotNull(comp10);
TestCase.assertEquals(srv1, comp10.m_singleRef);
TestCase.assertTrue(comp10.m_multiRef.isEmpty());
TestCase.assertEquals(1, comp10.m_singleRefBind);
TestCase.assertEquals(0, comp10.m_singleRefUnbind);
// update configuration to target srv2
theConfig.put("ref.target", "(value=srv2)");
configure(pid);
delay();
// should bind to srv2
SimpleComponent comp20;
if (dynamic) {
TestCase.assertEquals(1, comp10.m_modified);
comp20 = comp10;
TestCase.assertEquals(2, comp20.m_singleRefBind);
TestCase.assertEquals(1, comp20.m_singleRefUnbind);
} else {
TestCase.assertEquals(0, comp10.m_modified);
comp20 = SimpleComponent.INSTANCE;
TestCase.assertNotSame(comp10, comp20);
TestCase.assertEquals(0, comp20.m_modified);
TestCase.assertEquals(1, comp20.m_singleRefBind);
TestCase.assertEquals(0, comp20.m_singleRefUnbind);
TestCase.assertEquals(1, comp10.m_singleRefUnbind);
}
findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
TestCase.assertEquals(srv2, comp20.m_singleRef);
TestCase.assertTrue(comp20.m_multiRef.isEmpty());
}
use of org.apache.felix.scr.integration.components.SimpleServiceImpl in project felix by apache.
the class MutablePropertiesTest method test_mutable_properties_bind_returned.
@Test
public void test_mutable_properties_bind_returned() throws InvalidSyntaxException {
String componentName = "components.mutable.properties.bind";
findComponentConfigurationByName(componentName, ComponentConfigurationDTO.SATISFIED);
ServiceReference[] serviceReferences = bundleContext.getServiceReferences(MutatingService.class.getName(), "(service.pid=" + componentName + ")");
TestCase.assertEquals(1, serviceReferences.length);
ServiceReference serviceReference = serviceReferences[0];
Assert.assertEquals("otherValue", serviceReference.getProperty(PROP_NAME));
Assert.assertEquals("p1", serviceReference.getProperty("p1"));
Assert.assertEquals("p2", serviceReference.getProperty("p2"));
MutatingService s = (MutatingService) bundleContext.getService(serviceReference);
SimpleServiceImpl srv1 = SimpleServiceImpl.create(bundleContext, "srv1");
checkPropertiesNotPresent(serviceReference, "p1", "p2");
Assert.assertEquals("bound", serviceReference.getProperty("SimpleService"));
srv1.update("foo");
checkPropertiesNotPresent(serviceReference, "p1", "p2");
Assert.assertEquals("updated", serviceReference.getProperty("SimpleService"));
srv1.drop();
checkPropertiesNotPresent(serviceReference, "p1", "p2");
Assert.assertEquals("unbound", serviceReference.getProperty("SimpleService"));
bundleContext.ungetService(serviceReference);
}
Aggregations