Search in sources :

Example 11 with ComponentConfigurationDTO

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

the class InfoProvider method getBundleInfo.

/**
 * @see org.apache.felix.webconsole.bundleinfo.BundleInfoProvider#getBundleInfo(org.osgi.framework.Bundle,
 *      java.lang.String, java.util.Locale)
 */
public BundleInfo[] getBundleInfo(Bundle bundle, String webConsoleRoot, Locale locale) {
    final List<ComponentDescriptionDTO> disabled = new ArrayList<ComponentDescriptionDTO>();
    final List<ComponentConfigurationDTO> configurations = new ArrayList<ComponentConfigurationDTO>();
    final Collection<ComponentDescriptionDTO> descs = scrService.getComponentDescriptionDTOs(bundle);
    for (final ComponentDescriptionDTO d : descs) {
        if (!scrService.isComponentEnabled(d)) {
            disabled.add(d);
        } else {
            final Collection<ComponentConfigurationDTO> configs = scrService.getComponentConfigurationDTOs(d);
            if (configs.isEmpty()) {
                disabled.add(d);
            } else {
                configurations.addAll(configs);
            }
        }
    }
    Collections.sort(configurations, Util.COMPONENT_COMPARATOR);
    if (configurations.isEmpty()) {
        return NO_INFO;
    }
    BundleInfo[] ret = new BundleInfo[configurations.size() + disabled.size()];
    int i = 0;
    for (final ComponentDescriptionDTO cfg : disabled) {
        ret[i] = toInfo(cfg, webConsoleRoot, locale);
        i++;
    }
    for (final ComponentConfigurationDTO cfg : configurations) {
        ret[i] = toInfo(cfg, webConsoleRoot, locale);
        i++;
    }
    return ret;
}
Also used : BundleInfo(org.apache.felix.webconsole.bundleinfo.BundleInfo) ComponentDescriptionDTO(org.osgi.service.component.runtime.dto.ComponentDescriptionDTO) ArrayList(java.util.ArrayList) ComponentConfigurationDTO(org.osgi.service.component.runtime.dto.ComponentConfigurationDTO)

Example 12 with ComponentConfigurationDTO

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

the class ComponentActivationTest method test_deactivate_fail.

@Test
public void test_deactivate_fail() throws Exception {
    final String componentname = "ActivatorComponent.deactivate.fail";
    ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(componentname, ComponentConfigurationDTO.ACTIVE);
    disableAndCheck(cc);
}
Also used : ComponentConfigurationDTO(org.osgi.service.component.runtime.dto.ComponentConfigurationDTO) Test(org.junit.Test)

Example 13 with ComponentConfigurationDTO

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

the class ComponentActivationTest method test_activate_service_factory_register_service.

@Test
public void test_activate_service_factory_register_service() throws Exception {
    final String componentname = "ActivatorComponent.activate.service.factory.with.bind";
    ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(componentname, ComponentConfigurationDTO.SATISFIED);
    getServiceFromConfiguration(cc, ActivatorComponent.class);
    findComponentConfigurationByName(componentname, ComponentConfigurationDTO.ACTIVE);
    disableAndCheck(cc);
}
Also used : ComponentConfigurationDTO(org.osgi.service.component.runtime.dto.ComponentConfigurationDTO) Test(org.junit.Test)

Example 14 with ComponentConfigurationDTO

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

the class ComponentActivationTest method test_activator_not_declared.

@Test
public void test_activator_not_declared() throws Exception {
    final String componentname = "ActivatorComponent.no.decl";
    ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(componentname, ComponentConfigurationDTO.ACTIVE);
    disableAndCheck(cc);
}
Also used : ComponentConfigurationDTO(org.osgi.service.component.runtime.dto.ComponentConfigurationDTO) Test(org.junit.Test)

Example 15 with ComponentConfigurationDTO

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

the class ComponentConfigurationTest method test_SimpleComponent_dynamic_optional_configuration_with_required_service.

@Test
public void test_SimpleComponent_dynamic_optional_configuration_with_required_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 = "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=" + filterProp + ")");
        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();
        // 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 --> unsatisifed
        theConfig.remove(targetProp);
        configure(pid);
        delay();
        // mandatory ref missing --> component unsatisfied
        findComponentConfigurationByName(pid, ComponentConfigurationDTO.UNSATISFIED_REFERENCE);
        deleteConfig(pid);
        delay();
        // mandatory ref missing --> component unsatisfied
        findComponentConfigurationByName(pid, ComponentConfigurationDTO.UNSATISFIED_REFERENCE);
        disableAndCheck(cc);
        TestCase.assertNull(SimpleComponent.INSTANCE);
    } finally {
        theConfig.remove(targetProp);
        if (service != null) {
            service.drop();
        }
    }
}
Also used : SimpleComponent(org.apache.felix.scr.integration.components.SimpleComponent) ComponentConfigurationDTO(org.osgi.service.component.runtime.dto.ComponentConfigurationDTO) SimpleServiceImpl(org.apache.felix.scr.integration.components.SimpleServiceImpl) Test(org.junit.Test)

Aggregations

ComponentConfigurationDTO (org.osgi.service.component.runtime.dto.ComponentConfigurationDTO)87 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)19 A (org.apache.felix.scr.integration.components.circular.A)9 B (org.apache.felix.scr.integration.components.circular.B)9 ArrayList (java.util.ArrayList)6 Configuration (org.osgi.service.cm.Configuration)6 Bundle (org.osgi.framework.Bundle)5 ServiceReference (org.osgi.framework.ServiceReference)5 ServiceComponentRuntime (org.osgi.service.component.runtime.ServiceComponentRuntime)4 Hashtable (java.util.Hashtable)3 ConstructorComponent (org.apache.felix.scr.integration.components.ConstructorComponent)3 FieldActivatorComponent (org.apache.felix.scr.integration.components.FieldActivatorComponent)3 ReferenceDTO (org.osgi.service.component.runtime.dto.ReferenceDTO)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