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());
}
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
}
}
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());
}
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();
}
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
}
}
Aggregations