Package org.osgi.framework

Examples of org.osgi.framework.BundleContext


        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
                public ServiceReference[] answer(InvocationOnMock invocation) throws Throwable {
                    return getMockReferences(bc, (String)invocation.getArguments()[1]);
                }
View Full Code Here


        settings.writeSlingId(slingIdFile, slingId);
    }

    private SlingSettingsServiceImpl getSlingSettings(File slingIdFile, File optionsFile)
            throws IOException {
        BundleContext context = Mockito.mock(BundleContext.class);
        Mockito.when(context.getDataFile(SLING_ID_FILE_NAME))
                .thenReturn(slingIdFile);
        Mockito.when(context.getDataFile(OPTIONS_FILE_NAME))
                .thenReturn(optionsFile);
        StartupHandler handler = Mockito.mock(StartupHandler.class);
        // write options
        List<SlingSettingsServiceImpl.Options> options = new ArrayList<SlingSettingsServiceImpl.Options>();
        FileOutputStream fos = null;
View Full Code Here

    /**
     * Helper method to create a mock component context
     */
    protected ComponentContext createComponentContext() throws Exception {
        final BundleContext bundleCtx = this.context.mock(BundleContext.class);
        final Filter filter = this.context.mock(Filter.class);
        final ComponentContext ctx = this.context.mock(ComponentContext.class);
        this.context.checking(new Expectations() {{
            allowing(ctx).locateService(with(any(String.class)), with(any(ServiceReference.class)));
            will(returnValue(new MockAdapterFactory()));
View Full Code Here

        /**
     * Helper method to create a mock component context
     */
    protected ComponentContext createMultipleAdaptersComponentContext(final ServiceReference firstServiceReference, final ServiceReference secondServiceReference) throws Exception {
        final BundleContext bundleCtx = this.context.mock(BundleContext.class);
        final Filter filter = this.context.mock(Filter.class);
        final ComponentContext ctx = this.context.mock(ComponentContext.class);
        this.context.checking(new Expectations() {{
            allowing(ctx).locateService(with(any(String.class)), with(firstServiceReference));
            will(returnValue(new FirstImplementationAdapterFactory()));
View Full Code Here

     * @return Sling script helper instance
     */
    public static SlingScriptHelper newSlingScriptHelper() {
        SlingHttpServletRequest request = new MockSlingHttpServletRequest(newResourceResolver());
        SlingHttpServletResponse response = new MockSlingHttpServletResponse();
        BundleContext bundleContext = MockOsgi.newBundleContext();
        return newSlingScriptHelper(request, response, bundleContext);
    }
View Full Code Here

        super(clazz);
    }
   
    @Override
    protected Object createTest() throws Exception {
        final BundleContext ctx = Activator.getBundleContext();
        final ServiceReference ref = ctx.getServiceReference(TestObjectProcessor.class.getName());
        final TestObjectProcessor top = ref == null ? null : (TestObjectProcessor)ctx.getService(ref);

        if(top == null) {
            log.info("No TestObjectProcessor service available, annotations will not be processed");
            return super.createTest();
        } else {
View Full Code Here

        return settingsService;
    }

    public static ComponentContext mockComponentContext() {
        Mockery context = new JUnit4Mockery();
        final BundleContext bc = context.mock(BundleContext.class);
        context.checking(new Expectations() {
            {
                allowing(bc).registerService(with(any(String.class)),
                        with(any(Object.class)), with(any(Dictionary.class)));
                will(VoidAction.INSTANCE);
View Full Code Here

        };

        ServiceTracker tracker = mock(ServiceTracker.class);
        when(tracker.getService()).thenReturn(mockEA);

        BundleContext bundleContext = mock(BundleContext.class);
        when(bundleContext.createFilter(any(String.class))).thenReturn(null);
        when(bundleContext.getServiceReference(any(String.class))).thenReturn(null);
        when(bundleContext.getService(null)).thenReturn(mockEA);
        when(bundleContext.registerService(any(String.class), any(Object.class), any(Dictionary.class)))
                .thenAnswer(new Answer<ServiceRegistration>() {
                    public ServiceRegistration answer(InvocationOnMock invocation) throws Throwable {
                        Object[] arguments = invocation.getArguments();
                        registerObserver(whiteboard, (Observer) arguments[1]);
                        return mock(ServiceRegistration.class);
View Full Code Here

        String home = (String) environment.get(REPOSITORY_HOME_DIR);

        // ensure absolute home (path)
        File homeFile = new File(home);
        if (!homeFile.isAbsolute()) {
            BundleContext context = getComponentContext().getBundleContext();
            String slingHomePath = context.getProperty("sling.home");
            if (slingHomePath != null) {
                homeFile = new File(slingHomePath, home);
            } else {
                homeFile = homeFile.getAbsoluteFile();
            }
View Full Code Here

        when(repository.loginAdministrative(null)).thenReturn(session);

        EventAdmin eventAdmin = mock(EventAdmin.class);
        ServiceReference serviceRef = mock(ServiceReference.class);
        ServiceReference[] serviceRefs = new ServiceReference[]{serviceRef};
        BundleContext bundleContext = mock(BundleContext.class);
        when(bundleContext.getServiceReferences(anyString(), anyString())).thenReturn(serviceRefs);
        when(bundleContext.getService(serviceRef)).thenReturn(eventAdmin);

        jcrResourceListener = new JcrResourceListener("/", new ObservationListenerSupport(bundleContext, repository));

        Event event = mock(MockEvent.class);
        events = mock(EventIterator.class);
View Full Code Here

TOP

Related Classes of org.osgi.framework.BundleContext

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.