use of org.apache.felix.scr.impl.inject.ComponentMethodsImpl in project felix by apache.
the class ActivateMethodTest method checkMethod.
/**
* Checks whether a method with the given name can be found for the
* activate/deactivate method parameter list and whether the method returns
* the expected description when called.
*
* @param obj
* @param methodName
* @param methodDesc
* @param version DSVersion tested
*/
private void checkMethod(BaseObject obj, String methodName, String methodDesc, DSVersion version) {
ComponentContainer<?> container = newContainer();
SingleComponentManager<?> icm = new SingleComponentManager(container, new ComponentMethodsImpl());
ActivateMethod am = new ActivateMethod(methodName, methodName != null, obj.getClass(), version, false, false);
am.invoke(obj, new ActivatorParameter(new ComponentContextImpl(icm, m_bundle, null), -1), null);
Method m = am.getMethod();
assertNotNull(m);
assertEquals(methodName, m.getName());
assertEquals(methodDesc, obj.getCalledMethod());
}
use of org.apache.felix.scr.impl.inject.ComponentMethodsImpl in project felix by apache.
the class ActivateMethodTest method ensureMethodNotFoundMethod.
/**
* Ensures no method with the given name accepting any of the
* activate/deactive method parameters can be found.
*
* @param obj
* @param methodName
* @param version DS version tested
* @throws InvocationTargetException
* @throws IllegalAccessException
*/
private void ensureMethodNotFoundMethod(BaseObject obj, String methodName, DSVersion version) {
ComponentContainer container = newContainer();
SingleComponentManager icm = new SingleComponentManager(container, new ComponentMethodsImpl());
ActivateMethod am = new ActivateMethod(methodName, methodName != null, obj.getClass(), version, false, false);
am.invoke(obj, new ActivatorParameter(new ComponentContextImpl(icm, m_bundle, null), -1), null);
Method m = am.getMethod();
assertNull(m);
assertNull(obj.getCalledMethod());
}
use of org.apache.felix.scr.impl.inject.ComponentMethodsImpl 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());
}
use of org.apache.felix.scr.impl.inject.ComponentMethodsImpl in project felix by apache.
the class SingleComponentManagerTest method testGetServiceWithNullComponentContext.
@Test
public void testGetServiceWithNullComponentContext() 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<?> 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);
scm.setState(scm.getState(), State.unsatisfiedReference);
assertNull("m_componentContext is null, this should not cause an NPE", scm.getService(b, serviceRegistration));
Field u = SingleComponentManager.class.getDeclaredField("m_useCount");
u.setAccessible(true);
AtomicInteger use = (AtomicInteger) u.get(scm);
assertEquals(0, use.get());
}
Aggregations