Package org.osgi.service.component

Examples of org.osgi.service.component.ComponentContext


    }
           
    @Before
    public void setup() throws InvalidSyntaxException {
        setupTimestamp = System.currentTimeMillis();
        final ComponentContext ctx = Mockito.mock(ComponentContext.class);

        // context properties
        final Dictionary<String, Object> props = new Hashtable<String, Object>();
        props.put(HealthCheckTestsProvider.PROP_TAG_GROUPS, TAG_GROUPS);
        props.put(Constants.SERVICE_PID, getClass().getName());
        Mockito.when(ctx.getProperties()).thenReturn(props);
       
        // bundle context
        final BundleContext bc = Mockito.mock(BundleContext.class);
        Mockito.when(ctx.getBundleContext()).thenReturn(bc);
       
        // HealthCheck ServiceReferences mocks
        Mockito.when(bc.getServiceReferences(Mockito.anyString(), Mockito.anyString())).thenAnswer(
            new Answer<ServiceReference[]> () {
                @Override
View Full Code Here


                        with(any(Dictionary.class)),
                        with(any(HttpContext.class)));
            }
        });
        PrivateAccessor.setField(servlet, "httpService", httpService);
        ComponentContext cc = null;
        PrivateAccessor.invoke(servlet, "activate", new Class[] {ComponentContext.class}, new Object[] {cc});

        ServletHolder holder =
                new ServletHolder(servlet);
View Full Code Here

                        with(any(Object.class)), with(any(Dictionary.class)));
                will(VoidAction.INSTANCE);
            }
        });

        final ComponentContext cc = context.mock(ComponentContext.class);
        context.checking(new Expectations() {
            {
                allowing(cc).getProperties();
                will(returnValue(new Properties()));
View Full Code Here

        // setup mock OSGi environment
        Dictionary<String, Object> resourceProviderFactoryProps = new Hashtable<String, Object>();
        resourceProviderFactoryProps.put(Constants.SERVICE_VENDOR, "sling-mock");
        resourceProviderFactoryProps.put(Constants.SERVICE_DESCRIPTION, "sling-mock");
        resourceProviderFactoryProps.put("resource.resolver.manglenamespaces", true);
        ComponentContext componentContext = MockOsgi.newComponentContext(resourceProviderFactoryProps);

        // setup mocked JCR environment
        componentContext.getBundleContext()
                .registerService(SlingRepository.class.getName(), this.slingRepository, null);

        // setup real sling JCR resource provider implementation for use in
        // mocked context
        JcrResourceProviderFactory jcrResourceProviderFactory = new JcrResourceProviderFactory();
        MockOsgi.injectServices(jcrResourceProviderFactory, componentContext.getBundleContext());
        MockOsgi.activate(jcrResourceProviderFactory, componentContext.getBundleContext(),
                ImmutableMap.<String, Object> of());
       
        ResourceProvider resourceProvider;
        if (isAdmin) {
            resourceProvider = jcrResourceProviderFactory.getAdministrativeResourceProvider(authenticationInfo);
        }
        else {
            resourceProvider = jcrResourceProviderFactory.getResourceProvider(authenticationInfo);
        }
       
        Dictionary<Object, Object> resourceProviderProps = new Hashtable<Object, Object>();
        resourceProviderProps.put(ResourceProvider.ROOTS, new String[] { "/" });
        componentContext.getBundleContext().registerService(ResourceProvider.class.getName(), resourceProvider,
                resourceProviderProps);
        ServiceReference resourceProviderServiceReference = componentContext.getBundleContext().getServiceReference(
                ResourceProvider.class.getName());

        // setup real sling resource resolver implementation for use in mocked
        // context
        MockResourceResolverFactoryActivator activator = new MockResourceResolverFactoryActivator();
View Full Code Here

    /**
     * Check the preconditions and if it changed, either register factory or unregister
     */
    private void checkFactoryPreconditions() {
        final ComponentContext localContext = this.componentContext;
        if ( localContext != null ) {
            final boolean result = this.preconds.checkPreconditions();
            if ( result ) {
                this.registerFactory(localContext);
            } else {
View Full Code Here

        requestPath = "/NO_PATH_YET";
    }
   
    private void setProvider(final TestProvider provider) throws Exception {
        final BundleContext bundleContext = mockery.mock(BundleContext.class);
        final ComponentContext componentContext = mockery.mock(ComponentContext.class);
       
        final Action storeStatus = new Action() {
            public void describeTo(Description d) {
                d.appendText("Store HTTP response values");
            }
View Full Code Here

    }

    @Test
    public void testPackageAdditionWithMultipleFailingItemsDeliveryAndErrorQueue() throws Exception {
        ErrorAwareQueueDistributionStrategy errorAwareDistributionStrategy = new ErrorAwareQueueDistributionStrategy();
        ComponentContext context = mock(ComponentContext.class);
        Dictionary properties = mock(Dictionary.class);
        when(properties.get("attempts.threshold")).thenReturn(new String[]{"1"});
        when(properties.get("stuck.handling")).thenReturn(new String[]{"ERROR"});
        when(context.getProperties()).thenReturn(properties);
        errorAwareDistributionStrategy.activate(context);
        ReplicationPackage replicationPackage = mock(ReplicationPackage.class);
        ReplicationQueueProvider queueProvider = mock(ReplicationQueueProvider.class);
        ReplicationQueue queue = mock(ReplicationQueue.class);
        ReplicationQueueItem queueItem = mock(ReplicationQueueItem.class);
View Full Code Here

    }

    @Test
    public void testPackageAdditionWithMultipleFailingItemsDeliveryAndDropFromQueue() throws Exception {
        ErrorAwareQueueDistributionStrategy errorAwareDistributionStrategy = new ErrorAwareQueueDistributionStrategy();
        ComponentContext context = mock(ComponentContext.class);
        Dictionary properties = mock(Dictionary.class);
        when(properties.get("attempts.threshold")).thenReturn(new String[]{"1"});
        when(properties.get("stuck.handling")).thenReturn(new String[]{"DROP"});
        when(context.getProperties()).thenReturn(properties);
        errorAwareDistributionStrategy.activate(context);
        ReplicationPackage replicationPackage = mock(ReplicationPackage.class);
        ReplicationQueueProvider queueProvider = mock(ReplicationQueueProvider.class);
        ReplicationQueue queue = mock(ReplicationQueue.class);
View Full Code Here

public class PriorityPathQueueDistributionStrategyTest {

    @Test
    public void testPackageAdditionWithSucceedingItemDelivery() throws Exception {
        PriorityPathDistributionStrategy priorityPathDistributionStrategy = new PriorityPathDistributionStrategy();
        ComponentContext context = mock(ComponentContext.class);
        Dictionary properties = mock(Dictionary.class);
        when(properties.get("priority.paths")).thenReturn(new String[]{"/content", "/apps"});
        when(context.getProperties()).thenReturn(properties);
        priorityPathDistributionStrategy.activate(context);
        ReplicationPackage replicationPackage = mock(ReplicationPackage.class);
        when(replicationPackage.getPaths()).thenReturn(new String[]{"/etc"});
        ReplicationQueueProvider queueProvider = mock(ReplicationQueueProvider.class);
        ReplicationQueue queue = mock(ReplicationQueue.class);
View Full Code Here

    }

    @Test
    public void testPackageAdditionWithSucceedingItemDeliveryOnPriorityPath() throws Exception {
        PriorityPathDistributionStrategy priorityPathDistributionStrategy = new PriorityPathDistributionStrategy();
        ComponentContext context = mock(ComponentContext.class);
        Dictionary properties = mock(Dictionary.class);
        when(properties.get("priority.paths")).thenReturn(new String[]{"/content", "/apps"});
        when(context.getProperties()).thenReturn(properties);
        priorityPathDistributionStrategy.activate(context);
        ReplicationPackage replicationPackage = mock(ReplicationPackage.class);
        when(replicationPackage.getPaths()).thenReturn(new String[]{"/content/sample1"});
        ReplicationQueueProvider queueProvider = mock(ReplicationQueueProvider.class);
        ReplicationQueue queue = mock(ReplicationQueue.class);
View Full Code Here

TOP

Related Classes of org.osgi.service.component.ComponentContext

Copyright © 2018 www.massapicom. 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.