Search in sources :

Example 1 with ComponentContainer

use of org.apache.felix.scr.impl.manager.ComponentContainer in project felix by apache.

the class BindMethodTest method testMethod.

private void testMethod(final String methodName, final T1 component, final DSVersion dsVersion, final String expectCallPerformed) {
    ComponentContainer container = newContainer();
    SingleComponentManager icm = new SingleComponentManager(container, new ComponentMethodsImpl());
    BindMethod bm = new BindMethod(methodName, component.getClass(), FakeService.class.getName(), dsVersion, false);
    RefPair refPair = new SingleRefPair(m_serviceReference);
    ComponentContextImpl<T1> cc = new ComponentContextImpl(icm, new MockBundle(), null);
    assertTrue(bm.getServiceObject(cc, refPair, m_context, icm));
    BindParameters bp = new BindParameters(cc, refPair);
    bm.invoke(component, bp, null, icm);
    assertEquals(expectCallPerformed, component.callPerformed);
}
Also used : SingleComponentManager(org.apache.felix.scr.impl.manager.SingleComponentManager) ComponentContextImpl(org.apache.felix.scr.impl.manager.ComponentContextImpl) BindMethod(org.apache.felix.scr.impl.inject.BindMethod) RefPair(org.apache.felix.scr.impl.manager.RefPair) SingleRefPair(org.apache.felix.scr.impl.manager.SingleRefPair) BindParameters(org.apache.felix.scr.impl.inject.BindParameters) ComponentContainer(org.apache.felix.scr.impl.manager.ComponentContainer) FakeService(org.apache.felix.scr.impl.manager.components.FakeService) MockBundle(org.apache.felix.scr.impl.MockBundle) T1(org.apache.felix.scr.impl.manager.components.T1) SingleRefPair(org.apache.felix.scr.impl.manager.SingleRefPair)

Example 2 with ComponentContainer

use of org.apache.felix.scr.impl.manager.ComponentContainer 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());
}
Also used : SingleComponentManager(org.apache.felix.scr.impl.manager.SingleComponentManager) ComponentContextImpl(org.apache.felix.scr.impl.manager.ComponentContextImpl) ActivatorParameter(org.apache.felix.scr.impl.inject.ActivatorParameter) ComponentContainer(org.apache.felix.scr.impl.manager.ComponentContainer) ComponentMethodsImpl(org.apache.felix.scr.impl.inject.ComponentMethodsImpl) AcceptMethod(org.apache.felix.scr.impl.metadata.instances.AcceptMethod) Method(java.lang.reflect.Method)

Example 3 with ComponentContainer

use of org.apache.felix.scr.impl.manager.ComponentContainer in project felix by apache.

the class ActivateMethodTest method newContainer.

private ComponentContainer newContainer() {
    final ComponentMetadata metadata = newMetadata();
    ComponentContainer container = new ComponentContainer() {

        @Override
        public ComponentActivator getActivator() {
            final ComponentActivator ca = Mockito.mock(ComponentActivator.class);
            Mockito.when(ca.getBundleContext()).thenReturn(Mockito.mock(BundleContext.class));
            return ca;
        }

        @Override
        public ComponentMetadata getComponentMetadata() {
            return metadata;
        }

        @Override
        public void disposed(SingleComponentManager component) {
        }

        public boolean isEnabled() {
            return false;
        }

        @Override
        public ComponentLogger getLogger() {
            return new MockComponentLogger();
        }
    };
    return container;
}
Also used : SingleComponentManager(org.apache.felix.scr.impl.manager.SingleComponentManager) ComponentActivator(org.apache.felix.scr.impl.manager.ComponentActivator) ComponentContainer(org.apache.felix.scr.impl.manager.ComponentContainer) MockComponentLogger(org.apache.felix.scr.impl.logger.MockComponentLogger) ComponentMetadata(org.apache.felix.scr.impl.metadata.ComponentMetadata) BundleContext(org.osgi.framework.BundleContext)

Example 4 with ComponentContainer

use of org.apache.felix.scr.impl.manager.ComponentContainer 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(m_ctx, -1), null, icm);
    Method m = am.getMethod();
    assertNull(m);
    assertNull(obj.getCalledMethod());
}
Also used : SingleComponentManager(org.apache.felix.scr.impl.manager.SingleComponentManager) ComponentContainer(org.apache.felix.scr.impl.manager.ComponentContainer) AcceptMethod(org.apache.felix.scr.impl.metadata.instances.AcceptMethod) Method(java.lang.reflect.Method)

Example 5 with ComponentContainer

use of org.apache.felix.scr.impl.manager.ComponentContainer 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;
}
Also used : SingleComponentManager(org.apache.felix.scr.impl.manager.SingleComponentManager) ComponentContainer(org.apache.felix.scr.impl.manager.ComponentContainer) ComponentMetadata(org.apache.felix.scr.impl.metadata.ComponentMetadata)

Aggregations

ComponentContainer (org.apache.felix.scr.impl.manager.ComponentContainer)6 SingleComponentManager (org.apache.felix.scr.impl.manager.SingleComponentManager)6 ComponentMetadata (org.apache.felix.scr.impl.metadata.ComponentMetadata)3 Method (java.lang.reflect.Method)2 ComponentContextImpl (org.apache.felix.scr.impl.manager.ComponentContextImpl)2 AcceptMethod (org.apache.felix.scr.impl.metadata.instances.AcceptMethod)2 MockBundle (org.apache.felix.scr.impl.MockBundle)1 ActivatorParameter (org.apache.felix.scr.impl.inject.ActivatorParameter)1 BindMethod (org.apache.felix.scr.impl.inject.BindMethod)1 BindParameters (org.apache.felix.scr.impl.inject.BindParameters)1 ComponentMethodsImpl (org.apache.felix.scr.impl.inject.ComponentMethodsImpl)1 MockComponentLogger (org.apache.felix.scr.impl.logger.MockComponentLogger)1 ComponentActivator (org.apache.felix.scr.impl.manager.ComponentActivator)1 RefPair (org.apache.felix.scr.impl.manager.RefPair)1 SingleRefPair (org.apache.felix.scr.impl.manager.SingleRefPair)1 FakeService (org.apache.felix.scr.impl.manager.components.FakeService)1 T1 (org.apache.felix.scr.impl.manager.components.T1)1 BundleContext (org.osgi.framework.BundleContext)1