Examples of MockServiceReference


Examples of org.apache.felix.cm.MockServiceReference

    }


    ServiceReference<?> createServiceReference( final Bundle bundle, final Object pids )
    {
        return new MockServiceReference()
        {
            @Override
            public Bundle getBundle()
            {
                return bundle;
View Full Code Here

Examples of org.apache.sling.adapter.mock.MockServiceReference

        TestSlingAdaptable2 data = new TestSlingAdaptable2();
        assertNull("Expect no adapter", am.getAdapter(data, ITestAdapter.class));

        Bundle bundle = new MockBundle(1L);
        MockServiceReference ref = new MockServiceReference(bundle);
        ref.setProperty(Constants.SERVICE_ID, 1L);
        ref.setProperty(AdapterFactory.ADAPTABLE_CLASSES, new String[]{ TestSlingAdaptable.class.getName() });
        ref.setProperty(AdapterFactory.ADAPTER_CLASSES, ITestAdapter.class.getName());
        am.bindAdapterFactory(ref);

        Object adapter = am.getAdapter(data, ITestAdapter.class);
        assertNotNull(adapter);
        assertTrue(adapter instanceof ITestAdapter);
View Full Code Here

Examples of org.apache.sling.adapter.mock.MockServiceReference

        TestSlingAdaptable data = new TestSlingAdaptable();
        assertNull("Expect no adapter", am.getAdapter(data, ITestAdapter.class));

        Bundle bundle = new MockBundle(1L);
        MockServiceReference ref = new MockServiceReference(bundle);
        ref.setProperty(Constants.SERVICE_ID, 1L);
        ref.setProperty(AdapterFactory.ADAPTABLE_CLASSES, new String[]{ TestSlingAdaptable.class.getName() });
        ref.setProperty(AdapterFactory.ADAPTER_CLASSES, ITestAdapter.class.getName());
        am.bindAdapterFactory(ref);

        ref = new MockServiceReference(bundle);
        ref.setProperty(Constants.SERVICE_ID, 2L);
        ref.setProperty(AdapterFactory.ADAPTABLE_CLASSES, new String[]{ TestSlingAdaptable2.class.getName() });
        ref.setProperty(AdapterFactory.ADAPTER_CLASSES, TestAdapter.class.getName());
        am.bindAdapterFactory(ref);

        Object adapter = am.getAdapter(data, ITestAdapter.class);
        assertNotNull(adapter);
        assertTrue(adapter instanceof ITestAdapter);
View Full Code Here

Examples of org.apache.sling.adapter.mock.MockServiceReference

        ComponentContext cc = new MockComponentContext();
        am.activate(cc);

        Bundle bundle = new MockBundle(1L);
        MockServiceReference ref = new MockServiceReference(bundle);
        ref.setProperty(Constants.SERVICE_ID, 1L);
        ref.setProperty(AdapterFactory.ADAPTABLE_CLASSES, new String[]{ TestSlingAdaptable.class.getName() });
        ref.setProperty(AdapterFactory.ADAPTER_CLASSES, ITestAdapter.class.getName());
        am.bindAdapterFactory(ref);

        ref = new MockServiceReference(bundle);
        ref.setProperty(Constants.SERVICE_ID, 2L);
        ref.setProperty(AdapterFactory.ADAPTABLE_CLASSES, new String[]{ TestSlingAdaptable2.class.getName() });
        ref.setProperty(AdapterFactory.ADAPTER_CLASSES, TestAdapter.class.getName());
        am.bindAdapterFactory(ref);

        TestSlingAdaptable data = new TestSlingAdaptable();
        Object adapter = am.getAdapter(data, ITestAdapter.class);
        assertNotNull(adapter);
View Full Code Here

Examples of org.apache.sling.adapter.mock.MockServiceReference

        assertNull("AdapterFactory cache must be null", am.getFactoryCache());
    }

    public void testBindBeforeActivate() {
        Bundle bundle = new MockBundle(1L);
        MockServiceReference ref = new MockServiceReference(bundle);
        ref.setProperty(Constants.SERVICE_ID, 1L);
        ref.setProperty(AdapterFactory.ADAPTABLE_CLASSES, new String[]{ TestSlingAdaptable.class.getName() });
        ref.setProperty(AdapterFactory.ADAPTER_CLASSES, ITestAdapter.class.getName());
        am.bindAdapterFactory(ref);

        // no cache and no factories yet
        assertNotNull("AdapterFactoryDescriptors must not be null", am.getFactories());
        assertTrue("AdapterFactoryDescriptors must be empty", am.getFactories().isEmpty());
View Full Code Here

Examples of org.apache.sling.adapter.mock.MockServiceReference

        assertNotNull("AdapterFactoryDescriptors must not be null", am.getFactories());
        assertTrue("AdapterFactoryDescriptors must be empty", am.getFactories().isEmpty());
        assertNull("AdapterFactory cache must be null", am.getFactoryCache());

        Bundle bundle = new MockBundle(1L);
        MockServiceReference ref = new MockServiceReference(bundle);
        ref.setProperty(Constants.SERVICE_ID, 1L);
        ref.setProperty(AdapterFactory.ADAPTABLE_CLASSES, new String[]{ TestSlingAdaptable.class.getName() });
        ref.setProperty(AdapterFactory.ADAPTER_CLASSES, ITestAdapter.class.getName());
        am.bindAdapterFactory(ref);

        // expect the factory, but cache is empty
        assertNotNull("AdapterFactoryDescriptors must not be null", am.getFactories());
        assertEquals("AdapterFactoryDescriptors must contain one entry", 1, am.getFactories().size());
View Full Code Here

Examples of org.apache.sling.adapter.mock.MockServiceReference

        TestSlingAdaptable data = new TestSlingAdaptable();
        assertNull("Expect no adapter", am.getAdapter(data, ITestAdapter.class));

        Bundle bundle = new MockBundle(1L);
        MockServiceReference ref = new MockServiceReference(bundle);
        ref.setProperty(Constants.SERVICE_ID, 1L);
        ref.setProperty(AdapterFactory.ADAPTABLE_CLASSES, new String[]{ TestSlingAdaptable.class.getName() });
        ref.setProperty(AdapterFactory.ADAPTER_CLASSES, ITestAdapter.class.getName());
        am.bindAdapterFactory(ref);

        Object adapter = am.getAdapter(data, ITestAdapter.class);
        assertNotNull(adapter);
        assertTrue(adapter instanceof ITestAdapter);
View Full Code Here

Examples of org.apache.sling.commons.testing.osgi.MockServiceReference

                return null;
            }
        };
        MockComponentContext mockComponentContext = new MockComponentContext(
            bundleContext, SlingServletResolverTest.this.servlet);
        MockServiceReference serviceReference = new MockServiceReference(bundle);
        serviceReference.setProperty(Constants.SERVICE_ID, 1L);
        serviceReference.setProperty(SLING_SERLVET_NAME,
            SERVLET_NAME);
        serviceReference.setProperty(
            ServletResolverConstants.SLING_SERVLET_PATHS, SERVLET_PATH);
        serviceReference.setProperty(
            ServletResolverConstants.SLING_SERVLET_EXTENSIONS,
            SERVLET_EXTENSION);
        mockComponentContext.locateService(SERVLET_NAME, serviceReference);

        configureComponentContext(mockComponentContext);
View Full Code Here

Examples of org.apache.sling.commons.testing.osgi.MockServiceReference

    private ServletResourceProviderFactory factory = new ServletResourceProviderFactory(
        ROOT, new String[] {"/apps/"});

    public void testCreateMethodsDefault() {
        MockServiceReference msr = new MockServiceReference(null);

        msr.setProperty(ServletResolverConstants.SLING_SERVLET_RESOURCE_TYPES,
            RES_TYPE);
        // msr.setProperty(ServletResolverConstants.SLING_SERVLET_METHODS, "*");
        ServletResourceProvider srp = factory.create(msr);
        assertNotNull(srp);
        srp.setServlet(TEST_SERVLET);
View Full Code Here

Examples of org.apache.sling.commons.testing.osgi.MockServiceReference

        assertTrue(checkerSet.isEmpty());
    }

    public void testCreateMethodsSingle() {
        MockServiceReference msr = new MockServiceReference(null);

        msr.setProperty(ServletResolverConstants.SLING_SERVLET_RESOURCE_TYPES,
            RES_TYPE);
        msr.setProperty(ServletResolverConstants.SLING_SERVLET_METHODS, "GET");

        ServletResourceProvider srp = factory.create(msr);
        assertNotNull(srp);
        srp.setServlet(TEST_SERVLET);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.