Search in sources :

Example 41 with SimpleServiceImpl

use of org.apache.felix.scr.integration.components.SimpleServiceImpl in project felix by apache.

the class ServiceChangedTest method test_required_single_dynamic.

@Test
public void test_required_single_dynamic() throws Exception {
    final SimpleServiceImpl srv1 = SimpleServiceImpl.create(bundleContext, "srv1");
    String name = "test_required_single_dynamic_target";
    getDisabledConfigurationAndEnable(name, 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 a service property
    srv1.update("srv1-modified");
    // no changes in bindings expected
    TestCase.assertEquals(srv1, comp10.m_singleRef);
    TestCase.assertTrue(comp10.m_multiRef.isEmpty());
    TestCase.assertEquals(1, comp10.m_singleRefBind);
    TestCase.assertEquals(0, comp10.m_singleRefUnbind);
    // set target to not match any more -> deactivate this component
    srv1.setFilterProperty("don't match");
    findComponentConfigurationByName(name, ComponentConfigurationDTO.UNSATISFIED_REFERENCE);
    TestCase.assertNull(SimpleComponent.INSTANCE);
    TestCase.assertNull(comp10.m_singleRef);
    TestCase.assertTrue(comp10.m_multiRef.isEmpty());
    TestCase.assertEquals(1, comp10.m_singleRefBind);
    TestCase.assertEquals(1, comp10.m_singleRefUnbind);
    final SimpleServiceImpl srv2 = SimpleServiceImpl.create(bundleContext, "srv2");
    // async binding
    delay();
    findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
    final SimpleComponent comp12 = SimpleComponent.INSTANCE;
    TestCase.assertNotSame(comp10, comp12);
    TestCase.assertEquals(srv2, comp12.m_singleRef);
    TestCase.assertTrue(comp12.m_multiRef.isEmpty());
    TestCase.assertEquals(1, comp12.m_singleRefBind);
    TestCase.assertEquals(0, comp12.m_singleRefUnbind);
    // make srv1 match again, expect not changes in bindings
    srv1.setFilterProperty("match");
    TestCase.assertEquals(srv2, comp12.m_singleRef);
    TestCase.assertTrue(comp12.m_multiRef.isEmpty());
    TestCase.assertEquals(1, comp12.m_singleRefBind);
    TestCase.assertEquals(0, comp12.m_singleRefUnbind);
    // make srv2 to not match, expect binding to srv1
    srv2.setFilterProperty("don't match");
    TestCase.assertEquals(srv1, comp12.m_singleRef);
    TestCase.assertTrue(comp12.m_multiRef.isEmpty());
    TestCase.assertEquals(2, comp12.m_singleRefBind);
    TestCase.assertEquals(1, comp12.m_singleRefUnbind);
}
Also used : SimpleComponent(org.apache.felix.scr.integration.components.SimpleComponent) SimpleServiceImpl(org.apache.felix.scr.integration.components.SimpleServiceImpl) Test(org.junit.Test)

Example 42 with SimpleServiceImpl

use of org.apache.felix.scr.integration.components.SimpleServiceImpl in project felix by apache.

the class TargetPropertyTest method singleTest.

private void singleTest(String pid, String expected) throws Exception {
    final SimpleServiceImpl srv1 = SimpleServiceImpl.create(bundleContext, expected);
    final SimpleServiceImpl srv2 = SimpleServiceImpl.create(bundleContext, "baz");
    getDisabledConfigurationAndEnable(pid, ComponentConfigurationDTO.ACTIVE);
    checkTarget(expected, srv1);
    // configuration not setting target property does not change it
    configure(pid);
    // all cm event to complete
    delay();
    checkTarget(expected, srv1);
    // update configuration to target srv2
    theConfig.put("one.target", "(value=baz)");
    configure(pid);
    delay();
    checkTarget("baz", srv2);
    // update configuration removing target property
    theConfig.remove("one.target");
    configure(pid);
    // all cm event to complete
    delay();
    checkTarget(expected, srv1);
}
Also used : SimpleServiceImpl(org.apache.felix.scr.integration.components.SimpleServiceImpl)

Aggregations

SimpleServiceImpl (org.apache.felix.scr.integration.components.SimpleServiceImpl)42 Test (org.junit.Test)36 SimpleComponent (org.apache.felix.scr.integration.components.SimpleComponent)32 ComponentConfigurationDTO (org.osgi.service.component.runtime.dto.ComponentConfigurationDTO)22 Hashtable (java.util.Hashtable)7 ComponentInstance (org.osgi.service.component.ComponentInstance)7 ComponentFactory (org.osgi.service.component.ComponentFactory)5 ServiceReference (org.osgi.framework.ServiceReference)4 SimpleComponent2 (org.apache.felix.scr.integration.components.SimpleComponent2)2 SimpleService2Impl (org.apache.felix.scr.integration.components.SimpleService2Impl)2 ArrayList (java.util.ArrayList)1 ActivatorComponent (org.apache.felix.scr.integration.components.ActivatorComponent)1 MutatingService (org.apache.felix.scr.integration.components.MutatingService)1 ComponentException (org.osgi.service.component.ComponentException)1