Search in sources :

Example 1 with ComponentException

use of org.osgi.service.component.ComponentException in project felix by apache.

the class ComponentFactoryTest method test_component_factory_reference.

@Test
public void test_component_factory_reference() throws Exception {
    final String componentname = "factory.component.reference";
    final String componentfactory = "factory.component.factory.reference";
    SimpleServiceImpl.create(bundleContext, "ignored").setFilterProperty("ignored");
    getConfigurationsDisabledThenEnable(componentname, 0, -1);
    TestCase.assertNull(SimpleComponent.INSTANCE);
    // register a service : filterprop=match
    SimpleServiceImpl match = SimpleServiceImpl.create(bundleContext, "required").setFilterProperty("required");
    delay();
    TestCase.assertNull(SimpleComponent.INSTANCE);
    final ComponentInstance instance = createFactoryComponentInstance(componentfactory);
    TestCase.assertEquals(1, SimpleComponent.INSTANCE.m_multiRef.size());
    TestCase.assertTrue(SimpleComponent.INSTANCE.m_multiRef.contains(match));
    // check registered components
    checkConfigurationCount(componentname, 1, ComponentConfigurationDTO.ACTIVE);
    instance.dispose();
    TestCase.assertNull(SimpleComponent.INSTANCE);
    // SCR 112.12.6.2
    TestCase.assertNull(instance.getInstance());
    checkConfigurationCount(componentname, 0, ComponentConfigurationDTO.ACTIVE);
    // overwritten filterprop
    Hashtable<String, String> propsNonMatch = new Hashtable<String, String>();
    propsNonMatch.put(PROP_NAME_FACTORY, PROP_NAME_FACTORY);
    propsNonMatch.put("ref.target", "(filterprop=nomatch)");
    ComponentFactory factory = getComponentFactory(componentfactory);
    try {
        factory.newInstance(propsNonMatch);
        TestCase.fail("Missing reference must fail instance creation");
    } catch (ComponentException ce) {
    // expected
    }
    final SimpleServiceImpl noMatch = SimpleServiceImpl.create(bundleContext, "nomatch").setFilterProperty("nomatch");
    delay();
    final ComponentInstance instanceNonMatch = factory.newInstance(propsNonMatch);
    TestCase.assertNotNull(instanceNonMatch);
    TestCase.assertNotNull(instanceNonMatch.getInstance());
    TestCase.assertEquals(SimpleComponent.INSTANCE, instanceNonMatch.getInstance());
    TestCase.assertEquals(PROP_NAME_FACTORY, SimpleComponent.INSTANCE.getProperty(PROP_NAME_FACTORY));
    TestCase.assertEquals(1, SimpleComponent.INSTANCE.m_multiRef.size());
    TestCase.assertTrue(SimpleComponent.INSTANCE.m_multiRef.contains(noMatch));
    // check registered components
    checkConfigurationCount(componentname, 1, ComponentConfigurationDTO.ACTIVE);
    match.getRegistration().unregister();
    delay();
    // check registered components (ComponentFactory aint no longer)
    checkConfigurationCount(componentname, 1, ComponentConfigurationDTO.ACTIVE);
    // it has already been deactivated.... this should cause an exception?
    noMatch.getRegistration().unregister();
    delay();
    // check registered components (ComponentFactory aint no longer)
    checkConfigurationCount(componentname, 0, ComponentConfigurationDTO.ACTIVE);
    // deactivated due to unsatisfied reference
    TestCase.assertNull(instanceNonMatch.getInstance());
    TestCase.assertNull(SimpleComponent.INSTANCE);
    // Check that calling dispose on a deactivated instance has no effect
    instanceNonMatch.dispose();
    TestCase.assertNull(SimpleComponent.INSTANCE);
    // SCR 112.12.6.2
    TestCase.assertNull(instanceNonMatch.getInstance());
}
Also used : Hashtable(java.util.Hashtable) ComponentFactory(org.osgi.service.component.ComponentFactory) ComponentInstance(org.osgi.service.component.ComponentInstance) ComponentException(org.osgi.service.component.ComponentException) SimpleServiceImpl(org.apache.felix.scr.integration.components.SimpleServiceImpl) Test(org.junit.Test)

Example 2 with ComponentException

use of org.osgi.service.component.ComponentException in project felix by apache.

the class XmlHandlerTest method test_duplicate_implementation_class_11.

public void test_duplicate_implementation_class_11() throws Exception {
    final List metadataList11 = readMetadata("/components_duplicate_implementation_11.xml");
    assertEquals("Component Descriptors", 1, metadataList11.size());
    final ComponentMetadata cm11 = (ComponentMetadata) metadataList11.get(0);
    try {
        cm11.validate(logger);
        fail("Expect validation failure for duplicate implementation element");
    } catch (ComponentException ce) {
    // expected
    }
}
Also used : ComponentException(org.osgi.service.component.ComponentException) List(java.util.List)

Example 3 with ComponentException

use of org.osgi.service.component.ComponentException in project felix by apache.

the class XmlHandlerTest method test_reference_no_name.

public void test_reference_no_name() throws Exception {
    final List metadataList10 = readMetadata("/components_anonymous_10.xml");
    assertEquals("Component Descriptors", 1, metadataList10.size());
    final ComponentMetadata cm10 = (ComponentMetadata) metadataList10.get(0);
    try {
        cm10.validate(logger);
        fail("Expected validation failure for component without name");
    } catch (ComponentException ce) {
    // expected !!
    }
    final List metadataList11 = readMetadata("/components_anonymous_11.xml");
    assertEquals("Component Descriptors", 1, metadataList11.size());
    final ComponentMetadata cm11 = (ComponentMetadata) metadataList11.get(0);
    cm11.validate(logger);
    assertEquals("Expected name equals class", cm11.getImplementationClassName(), cm11.getName());
}
Also used : ComponentException(org.osgi.service.component.ComponentException) List(java.util.List)

Example 4 with ComponentException

use of org.osgi.service.component.ComponentException in project opencast by opencast.

the class AbstractElasticsearchIndex method activate.

/**
 * OSGi callback to activate this component instance.
 *
 * @param ctx
 *          the component context
 * @throws ComponentException
 *           if the search index cannot be initialized
 */
public void activate(ComponentContext ctx) throws ComponentException {
    Option<String> indexSettingsPathOption = OsgiUtil.getOptContextProperty(ctx, ELASTICSEARCH_CONFIG_DIR_KEY);
    if (indexSettingsPathOption.isNone())
        throw new ComponentException("Configuration for key '" + ELASTICSEARCH_CONFIG_DIR_KEY + "' missing");
    indexSettingsPath = indexSettingsPathOption.get();
}
Also used : ComponentException(org.osgi.service.component.ComponentException)

Example 5 with ComponentException

use of org.osgi.service.component.ComponentException in project felix by apache.

the class XmlHandlerTest method test_duplicate_service_10.

public void test_duplicate_service_10() throws Exception {
    final List metadataList10 = readMetadata("/components_duplicate_service_10.xml");
    assertEquals("Component Descriptors", 1, metadataList10.size());
    final ComponentMetadata cm10 = (ComponentMetadata) metadataList10.get(0);
    try {
        cm10.validate(logger);
        fail("Expect validation failure for duplicate service element");
    } catch (ComponentException ce) {
    // expected
    }
}
Also used : ComponentException(org.osgi.service.component.ComponentException) List(java.util.List)

Aggregations

ComponentException (org.osgi.service.component.ComponentException)16 List (java.util.List)7 IOException (java.io.IOException)4 InputStream (java.io.InputStream)3 Properties (java.util.Properties)3 ArrayList (java.util.ArrayList)2 CommonEventCatalogUIAdapter (org.opencastproject.index.service.catalog.adapter.events.CommonEventCatalogUIAdapter)2 ComponentInstance (org.osgi.service.component.ComponentInstance)2 Listener (com.google.common.util.concurrent.Service.Listener)1 State (com.google.common.util.concurrent.Service.State)1 ShutdownException (io.fabric8.common.util.ShutdownTracker.ShutdownException)1 VertxService (io.fabric8.gateway.fabric.support.vertx.VertxService)1 DetectingGateway (io.fabric8.gateway.handlers.detecting.DetectingGateway)1 Protocol (io.fabric8.gateway.handlers.detecting.Protocol)1 AmqpProtocol (io.fabric8.gateway.handlers.detecting.protocol.amqp.AmqpProtocol)1 HttpProtocol (io.fabric8.gateway.handlers.detecting.protocol.http.HttpProtocol)1 MqttProtocol (io.fabric8.gateway.handlers.detecting.protocol.mqtt.MqttProtocol)1 OpenwireProtocol (io.fabric8.gateway.handlers.detecting.protocol.openwire.OpenwireProtocol)1 SslConfig (io.fabric8.gateway.handlers.detecting.protocol.ssl.SslConfig)1 SslProtocol (io.fabric8.gateway.handlers.detecting.protocol.ssl.SslProtocol)1