Search in sources :

Example 1 with MutatingService

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);
}
Also used : Dictionary(java.util.Dictionary) Hashtable(java.util.Hashtable) MutatingService(org.apache.felix.scr.integration.components.MutatingService) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 2 with MutatingService

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);
}
Also used : Dictionary(java.util.Dictionary) Hashtable(java.util.Hashtable) MutatingService(org.apache.felix.scr.integration.components.MutatingService) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 3 with MutatingService

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);
}
Also used : Dictionary(java.util.Dictionary) Hashtable(java.util.Hashtable) MutatingService(org.apache.felix.scr.integration.components.MutatingService) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 4 with MutatingService

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);
}
Also used : MutatingService(org.apache.felix.scr.integration.components.MutatingService) ServiceReference(org.osgi.framework.ServiceReference) SimpleServiceImpl(org.apache.felix.scr.integration.components.SimpleServiceImpl) Test(org.junit.Test)

Aggregations

MutatingService (org.apache.felix.scr.integration.components.MutatingService)4 Test (org.junit.Test)4 ServiceReference (org.osgi.framework.ServiceReference)4 Dictionary (java.util.Dictionary)3 Hashtable (java.util.Hashtable)3 SimpleServiceImpl (org.apache.felix.scr.integration.components.SimpleServiceImpl)1