Search in sources :

Example 1 with ImplementsInterfacePropertyModel2

use of org.apache.sling.models.testmodels.classes.implextend.ImplementsInterfacePropertyModel2 in project sling by apache.

the class ImplementsExtendsTest method setup.

@SuppressWarnings("unchecked")
@Before
public void setup() throws ClassNotFoundException, MalformedURLException {
    when(componentCtx.getBundleContext()).thenReturn(bundleContext);
    when(componentCtx.getProperties()).thenReturn(new Hashtable<String, Object>());
    when(bundleContext.registerService(anyString(), anyObject(), any(Dictionary.class))).then(new Answer<ServiceRegistration>() {

        @Override
        public ServiceRegistration answer(InvocationOnMock invocation) throws Throwable {
            final Dictionary<String, Object> props = (Dictionary<String, Object>) invocation.getArguments()[2];
            ServiceRegistration reg = mock(ServiceRegistration.class);
            ServiceReference ref = mock(ServiceReference.class);
            when(reg.getReference()).thenReturn(ref);
            when(ref.getProperty(anyString())).thenAnswer(new Answer<Object>() {

                @Override
                public Object answer(InvocationOnMock invocation) throws Throwable {
                    String key = (String) invocation.getArguments()[0];
                    return props.get(key);
                }
            });
            return reg;
        }
    });
    factory = new ModelAdapterFactory();
    factory.activate(componentCtx);
    factory.bindInjector(new ValueMapInjector(), new ServicePropertiesMap(2, 2));
    factory.bindImplementationPicker(firstImplementationPicker, firstImplementationPickerProps);
    // simulate bundle add for ModelPackageBundleListener
    Dictionary<String, String> headers = new Hashtable<String, String>();
    headers.put(ModelPackageBundleListener.PACKAGE_HEADER, "org.apache.sling.models.testmodels.classes.implextend");
    when(bundle.getHeaders()).thenReturn(headers);
    Vector<URL> classUrls = new Vector<URL>();
    classUrls.add(getClassUrl(ExtendsClassPropertyModel.class));
    classUrls.add(getClassUrl(ImplementsInterfacePropertyModel.class));
    classUrls.add(getClassUrl(ImplementsInterfacePropertyModel2.class));
    classUrls.add(getClassUrl(InvalidImplementsInterfacePropertyModel.class));
    classUrls.add(getClassUrl(InvalidSampleServiceInterface.class));
    classUrls.add(getClassUrl(SampleServiceInterface.class));
    classUrls.add(getClassUrl(SimplePropertyModel.class));
    when(bundle.findEntries(anyString(), anyString(), anyBoolean())).thenReturn(classUrls.elements());
    when(bundle.loadClass(anyString())).then(new Answer<Class<?>>() {

        @Override
        public Class<?> answer(InvocationOnMock invocation) throws ClassNotFoundException {
            String className = (String) invocation.getArguments()[0];
            return ImplementsExtendsTest.this.getClass().getClassLoader().loadClass(className);
        }
    });
    registeredAdapterFactories = (ServiceRegistration[]) factory.listener.addingBundle(bundle, bundleEvent);
}
Also used : Dictionary(java.util.Dictionary) SimplePropertyModel(org.apache.sling.models.testmodels.classes.implextend.SimplePropertyModel) ImplementsInterfacePropertyModel2(org.apache.sling.models.testmodels.classes.implextend.ImplementsInterfacePropertyModel2) Matchers.anyString(org.mockito.Matchers.anyString) URL(java.net.URL) InvalidImplementsInterfacePropertyModel(org.apache.sling.models.testmodels.classes.implextend.InvalidImplementsInterfacePropertyModel) Vector(java.util.Vector) ServiceRegistration(org.osgi.framework.ServiceRegistration) ValueMapInjector(org.apache.sling.models.impl.injectors.ValueMapInjector) Hashtable(java.util.Hashtable) SampleServiceInterface(org.apache.sling.models.testmodels.classes.implextend.SampleServiceInterface) InvalidSampleServiceInterface(org.apache.sling.models.testmodels.classes.implextend.InvalidSampleServiceInterface) ImplementsInterfacePropertyModel(org.apache.sling.models.testmodels.classes.implextend.ImplementsInterfacePropertyModel) InvalidImplementsInterfacePropertyModel(org.apache.sling.models.testmodels.classes.implextend.InvalidImplementsInterfacePropertyModel) ServiceReference(org.osgi.framework.ServiceReference) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ExtendsClassPropertyModel(org.apache.sling.models.testmodels.classes.implextend.ExtendsClassPropertyModel) Matchers.anyObject(org.mockito.Matchers.anyObject) InvalidSampleServiceInterface(org.apache.sling.models.testmodels.classes.implextend.InvalidSampleServiceInterface) Before(org.junit.Before)

Aggregations

URL (java.net.URL)1 Dictionary (java.util.Dictionary)1 Hashtable (java.util.Hashtable)1 Vector (java.util.Vector)1 ValueMapInjector (org.apache.sling.models.impl.injectors.ValueMapInjector)1 ExtendsClassPropertyModel (org.apache.sling.models.testmodels.classes.implextend.ExtendsClassPropertyModel)1 ImplementsInterfacePropertyModel (org.apache.sling.models.testmodels.classes.implextend.ImplementsInterfacePropertyModel)1 ImplementsInterfacePropertyModel2 (org.apache.sling.models.testmodels.classes.implextend.ImplementsInterfacePropertyModel2)1 InvalidImplementsInterfacePropertyModel (org.apache.sling.models.testmodels.classes.implextend.InvalidImplementsInterfacePropertyModel)1 InvalidSampleServiceInterface (org.apache.sling.models.testmodels.classes.implextend.InvalidSampleServiceInterface)1 SampleServiceInterface (org.apache.sling.models.testmodels.classes.implextend.SampleServiceInterface)1 SimplePropertyModel (org.apache.sling.models.testmodels.classes.implextend.SimplePropertyModel)1 Before (org.junit.Before)1 Matchers.anyObject (org.mockito.Matchers.anyObject)1 Matchers.anyString (org.mockito.Matchers.anyString)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1 ServiceReference (org.osgi.framework.ServiceReference)1 ServiceRegistration (org.osgi.framework.ServiceRegistration)1