use of org.apache.felix.scr.integration.components.MutatingService in project felix by apache.
the class MutablePropertiesTest method test_mutable_properties_returned.
@Test
public void test_mutable_properties_returned() throws InvalidSyntaxException {
String componentName = "components.mutable.properties.return";
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"));
// update theValue
MutatingService s = (MutatingService) bundleContext.getService(serviceReference);
Assert.assertNotNull(s);
Assert.assertEquals("anotherValue1", serviceReference.getProperty(PROP_NAME));
Assert.assertEquals("p1", serviceReference.getProperty("p1"));
Assert.assertEquals("p2", serviceReference.getProperty("p2"));
findComponentConfigurationByName(componentName, ComponentConfigurationDTO.ACTIVE);
Dictionary d = new Hashtable(Collections.singletonMap(PROP_NAME, "anotherValue"));
s.updateProperties(d);
Assert.assertEquals("anotherValue", serviceReference.getProperty(PROP_NAME));
checkPropertiesNotPresent(serviceReference, "p1", "p2");
// configure with configAdmin
configure(componentName);
delay();
delay();
// no change
Assert.assertEquals("anotherValue2", serviceReference.getProperty(PROP_NAME));
Assert.assertEquals("p1", serviceReference.getProperty("p1"));
Assert.assertEquals("p2", serviceReference.getProperty("p2"));
// check that removing config switches back to defaults modified by config admin
s.updateProperties(null);
Assert.assertEquals("theValue", serviceReference.getProperty(PROP_NAME));
Assert.assertEquals("p1", serviceReference.getProperty("p1"));
Assert.assertEquals("p2", serviceReference.getProperty("p2"));
bundleContext.ungetService(serviceReference);
}
use of org.apache.felix.scr.integration.components.MutatingService in project felix by apache.
the class MutablePropertiesTest method test_mutable_properties_returned_public.
@Test
public void test_mutable_properties_returned_public() throws InvalidSyntaxException {
String componentName = "components.mutable.properties.return.public";
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"));
// update theValue
MutatingService s = (MutatingService) bundleContext.getService(serviceReference);
Assert.assertNotNull(s);
Assert.assertEquals("anotherValue1", serviceReference.getProperty(PROP_NAME));
Assert.assertEquals("p1", serviceReference.getProperty("p1"));
Assert.assertEquals("p2", serviceReference.getProperty("p2"));
findComponentConfigurationByName(componentName, ComponentConfigurationDTO.ACTIVE);
Dictionary d = new Hashtable(Collections.singletonMap(PROP_NAME, "anotherValue"));
s.updateProperties(d);
Assert.assertEquals("anotherValue", serviceReference.getProperty(PROP_NAME));
checkPropertiesNotPresent(serviceReference, "p1", "p2");
// configure with configAdmin
configure(componentName);
delay();
delay();
// no change
Assert.assertEquals("anotherValue2", serviceReference.getProperty(PROP_NAME));
Assert.assertEquals("p1", serviceReference.getProperty("p1"));
Assert.assertEquals("p2", serviceReference.getProperty("p2"));
// check that removing config switches back to defaults modified by config admin
s.updateProperties(null);
Assert.assertEquals("theValue", serviceReference.getProperty(PROP_NAME));
Assert.assertEquals("p1", serviceReference.getProperty("p1"));
Assert.assertEquals("p2", serviceReference.getProperty("p2"));
bundleContext.ungetService(serviceReference);
}
use of org.apache.felix.scr.integration.components.MutatingService in project felix by apache.
the class MutablePropertiesTest method test_mutable_properties.
@Test
public void test_mutable_properties() throws InvalidSyntaxException {
String componentName = "components.mutable.properties";
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"));
// update theValue
MutatingService s = (MutatingService) bundleContext.getService(serviceReference);
Assert.assertNotNull(s);
findComponentConfigurationByName(componentName, ComponentConfigurationDTO.ACTIVE);
Dictionary d = new Hashtable(Collections.singletonMap(PROP_NAME, "anotherValue"));
s.updateProperties(d);
Assert.assertEquals("anotherValue", serviceReference.getProperty(PROP_NAME));
checkPropertiesNotPresent(serviceReference, "p1", "p2");
// configure with configAdmin
configure(componentName);
delay();
// no change
Assert.assertEquals("anotherValue", serviceReference.getProperty(PROP_NAME));
checkPropertiesNotPresent(serviceReference, "p1", "p2");
// check that removing config switches back to defaults modified by config admin
s.updateProperties(null);
Assert.assertEquals("theValue", serviceReference.getProperty(PROP_NAME));
Assert.assertEquals("p1", serviceReference.getProperty("p1"));
Assert.assertEquals("p2", serviceReference.getProperty("p2"));
bundleContext.ungetService(serviceReference);
}
use of org.apache.felix.scr.integration.components.MutatingService 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