Search in sources :

Example 16 with ComponentConfigurationDTO

use of org.osgi.service.component.runtime.dto.ComponentConfigurationDTO in project felix by apache.

the class ComponentConfigurationTest method test_SimpleComponent_configuration_ignore.

@Test
public void test_SimpleComponent_configuration_ignore() throws Exception {
    final String pid = "SimpleComponent.configuration.ignore";
    TestCase.assertNull(SimpleComponent.INSTANCE);
    deleteConfig(pid);
    delay();
    ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(pid, ComponentConfigurationDTO.ACTIVE);
    TestCase.assertNotNull(SimpleComponent.INSTANCE);
    TestCase.assertNull(SimpleComponent.INSTANCE.getProperty(PROP_NAME));
    configure(pid);
    delay();
    findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
    TestCase.assertNotNull(SimpleComponent.INSTANCE);
    TestCase.assertNull(SimpleComponent.INSTANCE.getProperty(PROP_NAME));
    deleteConfig(pid);
    delay();
    findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
    TestCase.assertNotNull(SimpleComponent.INSTANCE);
    TestCase.assertNull(SimpleComponent.INSTANCE.getProperty(PROP_NAME));
    disableAndCheck(cc);
    TestCase.assertNull(SimpleComponent.INSTANCE);
}
Also used : ComponentConfigurationDTO(org.osgi.service.component.runtime.dto.ComponentConfigurationDTO) Test(org.junit.Test)

Example 17 with ComponentConfigurationDTO

use of org.osgi.service.component.runtime.dto.ComponentConfigurationDTO in project felix by apache.

the class ComponentConfigurationTest method test_SimpleComponent_configuration_require.

@Test
public void test_SimpleComponent_configuration_require() throws Exception {
    final String pid = "SimpleComponent.configuration.require";
    deleteConfig(pid);
    delay();
    TestCase.assertNull(SimpleComponent.INSTANCE);
    getConfigurationsDisabledThenEnable(pid, 0, ComponentConfigurationDTO.UNSATISFIED_REFERENCE);
    TestCase.assertNull(SimpleComponent.INSTANCE);
    configure(pid);
    delay();
    ComponentConfigurationDTO cc = findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
    TestCase.assertNotNull(SimpleComponent.INSTANCE);
    TestCase.assertEquals(PROP_NAME, SimpleComponent.INSTANCE.getProperty(PROP_NAME));
    deleteConfig(pid);
    delay();
    checkConfigurationCount(pid, 0, -1);
    TestCase.assertNull(SimpleComponent.INSTANCE);
    disableAndCheck(cc);
    TestCase.assertNull(SimpleComponent.INSTANCE);
}
Also used : ComponentConfigurationDTO(org.osgi.service.component.runtime.dto.ComponentConfigurationDTO) Test(org.junit.Test)

Example 18 with ComponentConfigurationDTO

use of org.osgi.service.component.runtime.dto.ComponentConfigurationDTO in project felix by apache.

the class ComponentConfigurationTest method test_SimpleComponent_configuration_optional.

@Test
public void test_SimpleComponent_configuration_optional() throws Exception {
    final String pid = "SimpleComponent.configuration.optional";
    ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(pid, ComponentConfigurationDTO.ACTIVE);
    final SimpleComponent firstInstance = SimpleComponent.INSTANCE;
    TestCase.assertNotNull(firstInstance);
    TestCase.assertNull(firstInstance.getProperty(PROP_NAME));
    configure(pid);
    delay();
    final SimpleComponent secondInstance = SimpleComponent.INSTANCE;
    findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
    TestCase.assertNotNull(secondInstance);
    TestCase.assertEquals(PROP_NAME, secondInstance.getProperty(PROP_NAME));
    deleteConfig(pid);
    delay();
    final SimpleComponent thirdInstance = SimpleComponent.INSTANCE;
    findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
    TestCase.assertNotNull(thirdInstance);
    TestCase.assertNull(thirdInstance.getProperty(PROP_NAME));
    TestCase.assertNotSame("Expect new instance object after reconfiguration", firstInstance, secondInstance);
    TestCase.assertNotSame("Expect new instance object after configuration deletion (1)", firstInstance, thirdInstance);
    TestCase.assertNotSame("Expect new instance object after configuration deletion (2)", secondInstance, thirdInstance);
    disableAndCheck(cc);
    TestCase.assertNull(SimpleComponent.INSTANCE);
}
Also used : SimpleComponent(org.apache.felix.scr.integration.components.SimpleComponent) ComponentConfigurationDTO(org.osgi.service.component.runtime.dto.ComponentConfigurationDTO) Test(org.junit.Test)

Example 19 with ComponentConfigurationDTO

use of org.osgi.service.component.runtime.dto.ComponentConfigurationDTO in project felix by apache.

the class ComponentConfigurationTest method test_SimpleComponent_configuration_require_initialize.

/**
 * same as test_SimpleComponent_configuration_require except configuration is present when component is enabled.
 */
@Test
public void test_SimpleComponent_configuration_require_initialize() throws Exception {
    final String pid = "SimpleComponent.configuration.require";
    deleteConfig(pid);
    configure(pid);
    delay();
    TestCase.assertNull(SimpleComponent.INSTANCE);
    ComponentConfigurationDTO cc = getConfigurationsDisabledThenEnable(pid, 1, ComponentConfigurationDTO.ACTIVE).iterator().next();
    TestCase.assertNotNull(SimpleComponent.INSTANCE);
    TestCase.assertEquals(PROP_NAME, SimpleComponent.INSTANCE.getProperty(PROP_NAME));
    deleteConfig(pid);
    delay();
    checkConfigurationCount(pid, 0, -1);
    TestCase.assertNull(SimpleComponent.INSTANCE);
    disableAndCheck(cc);
    TestCase.assertNull(SimpleComponent.INSTANCE);
}
Also used : ComponentConfigurationDTO(org.osgi.service.component.runtime.dto.ComponentConfigurationDTO) Test(org.junit.Test)

Example 20 with ComponentConfigurationDTO

use of org.osgi.service.component.runtime.dto.ComponentConfigurationDTO in project felix by apache.

the class ComponentEnableTest method test_Component_Enable.

@Test
public void test_Component_Enable() throws Exception {
    final String enable = "org.apache.felix.scr.integration.components.enable";
    final String name = "org.apache.felix.scr.integration.components.SimpleComponent";
    ComponentConfigurationDTO dto = findComponentConfigurationByName(enable, ComponentConfigurationDTO.SATISFIED);
    EnableComponent ec = getServiceFromConfiguration(dto, EnableComponent.class);
    TestCase.assertEquals(0, SimpleComponent.INSTANCES.size());
    ec.enable(name);
    delay();
    TestCase.assertEquals(1, SimpleComponent.INSTANCES.size());
    ec.enable(name);
    delay();
    TestCase.assertEquals(1, SimpleComponent.INSTANCES.size());
}
Also used : EnableComponent(org.apache.felix.scr.integration.components.EnableComponent) ComponentConfigurationDTO(org.osgi.service.component.runtime.dto.ComponentConfigurationDTO) Test(org.junit.Test)

Aggregations

ComponentConfigurationDTO (org.osgi.service.component.runtime.dto.ComponentConfigurationDTO)91 Test (org.junit.Test)63 SimpleComponent (org.apache.felix.scr.integration.components.SimpleComponent)23 SimpleServiceImpl (org.apache.felix.scr.integration.components.SimpleServiceImpl)22 ComponentDescriptionDTO (org.osgi.service.component.runtime.dto.ComponentDescriptionDTO)21 A (org.apache.felix.scr.integration.components.circular.A)9 B (org.apache.felix.scr.integration.components.circular.B)9 ArrayList (java.util.ArrayList)7 Bundle (org.osgi.framework.Bundle)6 Configuration (org.osgi.service.cm.Configuration)6 ServiceReference (org.osgi.framework.ServiceReference)5 ServiceComponentRuntime (org.osgi.service.component.runtime.ServiceComponentRuntime)5 ReferenceDTO (org.osgi.service.component.runtime.dto.ReferenceDTO)4 Hashtable (java.util.Hashtable)3 ConstructorComponent (org.apache.felix.scr.integration.components.ConstructorComponent)3 FieldActivatorComponent (org.apache.felix.scr.integration.components.FieldActivatorComponent)3 UnsatisfiedReferenceDTO (org.osgi.service.component.runtime.dto.UnsatisfiedReferenceDTO)3 TreeMap (java.util.TreeMap)2 Component (org.apache.felix.scr.Component)2 ActivatorComponent (org.apache.felix.scr.integration.components.ActivatorComponent)2