use of org.apache.felix.scr.impl.metadata.ComponentMetadata in project felix by apache.
the class ActivateMethodTest method newMetadata.
private ComponentMetadata newMetadata() {
ComponentMetadata metadata = new ComponentMetadata(DSVersion.DS11);
metadata.setName("foo");
metadata.setImplementationClassName(Object.class.getName());
metadata.validate(null);
return metadata;
}
use of org.apache.felix.scr.impl.metadata.ComponentMetadata in project felix by apache.
the class ActivateMethodTest method newContainer.
private ComponentContainer newContainer() {
final ComponentMetadata metadata = newMetadata();
ComponentContainer container = new ComponentContainer() {
public BundleComponentActivator getActivator() {
return null;
}
public ComponentMetadata getComponentMetadata() {
return metadata;
}
public void disposed(SingleComponentManager component) {
}
public boolean isEnabled() {
return false;
}
};
return container;
}
use of org.apache.felix.scr.impl.metadata.ComponentMetadata in project felix by apache.
the class BindMethodTest method newContainer.
private ComponentContainer newContainer() {
final ComponentMetadata metadata = newMetadata();
ComponentContainer container = new ComponentContainer() {
public BundleComponentActivator getActivator() {
return null;
}
public ComponentMetadata getComponentMetadata() {
return metadata;
}
public void disposed(SingleComponentManager component) {
}
public boolean isEnabled() {
return false;
}
};
return container;
}
use of org.apache.felix.scr.impl.metadata.ComponentMetadata in project felix by apache.
the class ConfiguredComponentHolderTest method test_factory.
public void test_factory() {
// setup a holder
final String name = "test.factory";
final ComponentMetadata cm = createComponentMetadata(name);
final TestingConfiguredComponentHolder holder = new TestingConfiguredComponentHolder(cm);
holder.enableComponents(false);
// assert single component and no map
final SingleComponentManager cmgr = getSingleManager(holder);
assertNotNull("Expect single component manager", cmgr);
assertEquals("Expect no other component manager list", 1, getComponentManagers(holder).size());
// configure with configuration
final String pid1 = "test.factory.0001";
final Dictionary config1 = new Hashtable();
config1.put("value", pid1);
TargetedPID targetedFactoryPid = new TargetedPID(name);
TargetedPID targetedPid1 = new TargetedPID(pid1);
holder.configurationUpdated(targetedPid1, targetedFactoryPid, config1, 0);
// assert single component and single-entry map
final SingleComponentManager cmgrAfterConfig = getSingleManager(holder);
final List<SingleComponentManager> cmgrsAfterConfig = getComponentManagers(holder);
assertNotNull("Expect single component manager", cmgrAfterConfig);
assertNotNull("Expect component manager list", cmgrsAfterConfig);
assertEquals("Expect one component manager in list", 1, cmgrsAfterConfig.size());
// add another configuration
final String pid2 = "test.factory.0002";
final Dictionary config2 = new Hashtable();
config1.put("value", pid2);
TargetedPID targetedPid2 = new TargetedPID(pid2);
holder.configurationUpdated(targetedPid2, targetedFactoryPid, config2, 1);
final List<SingleComponentManager> cmgrsAfterConfig2 = getComponentManagers(holder);
assertNotNull("Expect component manager list", cmgrsAfterConfig2);
assertEquals("Expect two component manager in list", 2, cmgrsAfterConfig2.size());
// remove second configuration
holder.configurationDeleted(targetedPid2, targetedFactoryPid);
final List<SingleComponentManager> cmgrsAfterUnConfig2 = getComponentManagers(holder);
assertNotNull("Expect component manager list", cmgrsAfterUnConfig2);
// TODO Multipids fix correct assertion assertEquals( "Expect one component manager in list", 1, cmgrsAfterUnConfig2.size() );
// add second config again and remove first config -> replace singleton component
holder.configurationUpdated(targetedPid2, targetedFactoryPid, config2, 2);
holder.configurationDeleted(targetedPid1, targetedFactoryPid);
// assert single component and single-entry map
final List<SingleComponentManager> cmgrsAfterConfigUnconfig = getComponentManagers(holder);
assertNotNull("Expect component manager list", cmgrsAfterConfigUnconfig);
// TODO Multipids fix correct assertion assertEquals( "Expect one component manager in list", 1, cmgrsAfterConfigUnconfig.size() );
// remove second configuration (leaving no configurations)
holder.configurationDeleted(targetedPid2, targetedFactoryPid);
// assert single component and single-entry map
final List<SingleComponentManager> cmgrsAfterAllUnconfig = getComponentManagers(holder);
assertNotNull("Expect single component manager", cmgrsAfterAllUnconfig);
// TODO Multipids fix correct assertion assertEquals( "Expect no component manager list", 1, cmgrsAfterAllUnconfig.size() );
}
use of org.apache.felix.scr.impl.metadata.ComponentMetadata in project felix by apache.
the class SingleComponentManagerTest method testGetService.
@Test
public void testGetService() throws Exception {
ComponentMetadata cm = new ComponentMetadata(DSVersion.DS13);
cm.setImplementationClassName("foo.bar.SomeClass");
cm.validate(null);
@SuppressWarnings("unchecked") ComponentContainer<Object> cc = Mockito.mock(ComponentContainer.class);
Mockito.when(cc.getComponentMetadata()).thenReturn(cm);
Mockito.when(cc.getActivator()).thenReturn(componentActivator);
SingleComponentManager<Object> scm = new SingleComponentManager<Object>(cc, new ComponentMethodsImpl()) {
@Override
boolean getServiceInternal(ServiceRegistration<Object> serviceRegistration) {
return true;
}
};
BundleContext bc = Mockito.mock(BundleContext.class);
Bundle b = Mockito.mock(Bundle.class);
Mockito.when(b.getBundleContext()).thenReturn(bc);
ComponentContextImpl<Object> cci = new ComponentContextImpl<Object>(scm, b, null);
Object implObj = new Object();
cci.setImplementationObject(implObj);
cci.setImplementationAccessible(true);
Field f = SingleComponentManager.class.getDeclaredField("m_componentContext");
f.setAccessible(true);
f.set(scm, cci);
scm.setState(scm.getState(), State.unsatisfiedReference);
assertSame(implObj, scm.getService(b, serviceRegistration));
Field u = SingleComponentManager.class.getDeclaredField("m_useCount");
u.setAccessible(true);
AtomicInteger use = (AtomicInteger) u.get(scm);
assertEquals(1, use.get());
}
Aggregations