Search in sources :

Example 46 with ComponentContext

use of org.osgi.service.component.ComponentContext in project sling by apache.

the class MockOsgi method deactivate.

/**
     * Simulate deactivation of service instance. Invokes the @Deactivate annotated method.
     * @param target Service instance.
     * @param bundleContext Bundle context
     * @param properties Properties
     * @return true if deactivation method was called. False if no deactivate method is defined.
     */
public static boolean deactivate(Object target, BundleContext bundleContext, Dictionary<String, Object> properties) {
    Dictionary<String, Object> mergedProperties = propertiesMergeWithOsgiMetadata(target, getConfigAdmin(bundleContext), properties);
    ComponentContext componentContext = newComponentContext(bundleContext, mergedProperties);
    return OsgiServiceUtil.activateDeactivate(target, componentContext, false);
}
Also used : ComponentContext(org.osgi.service.component.ComponentContext)

Example 47 with ComponentContext

use of org.osgi.service.component.ComponentContext in project sling by apache.

the class MockOsgi method activate.

/**
     * Simulate activation of service instance. Invokes the @Activate annotated method.
     * @param target Service instance.
     * @param bundleContext Bundle context
     * @param properties Properties
     * @return true if activation method was called. False if no activate method is defined.
     */
public static boolean activate(Object target, BundleContext bundleContext, Dictionary<String, Object> properties) {
    Dictionary<String, Object> mergedProperties = propertiesMergeWithOsgiMetadata(target, getConfigAdmin(bundleContext), properties);
    ComponentContext componentContext = newComponentContext(bundleContext, mergedProperties);
    return OsgiServiceUtil.activateDeactivate(target, componentContext, true);
}
Also used : ComponentContext(org.osgi.service.component.ComponentContext)

Example 48 with ComponentContext

use of org.osgi.service.component.ComponentContext in project sling by apache.

the class MockOsgi method modified.

/**
     * Simulate configuration modification of service instance. Invokes the @Modified annotated method.
     * @param target Service instance.
     * @param bundleContext Bundle context
     * @param properties Properties
     * @return true if modified method was called. False if no modified method is defined.
     */
public static boolean modified(Object target, BundleContext bundleContext, Map<String, Object> properties) {
    Map<String, Object> mergedProperties = propertiesMergeWithOsgiMetadata(target, getConfigAdmin(bundleContext), properties);
    ComponentContext componentContext = newComponentContext(bundleContext, mergedProperties);
    return OsgiServiceUtil.modified(target, componentContext, mergedProperties);
}
Also used : ComponentContext(org.osgi.service.component.ComponentContext)

Example 49 with ComponentContext

use of org.osgi.service.component.ComponentContext in project sling by apache.

the class MockMimeTypeService method lazyInitialization.

/**
     * Do lazy initializing because reading to avoid reading all defined mime
     * types from disk if not required
     */
private void lazyInitialization() {
    if (!this.initialized) {
        this.initialized = true;
        // activate service in simulated OSGi environment
        ComponentContext componentContext = MockOsgi.newComponentContext();
        this.bindLogService(MockOsgi.newLogService(getClass()));
        activate(componentContext);
    }
}
Also used : ComponentContext(org.osgi.service.component.ComponentContext)

Example 50 with ComponentContext

use of org.osgi.service.component.ComponentContext in project sling by apache.

the class ResourceDetectionTest method testStopAndRestart.

@Test
public void testStopAndRestart() throws Exception {
    assertRegisteredPaths(contentHelper.FAKE_RESOURCES);
    assertRegisteredPaths(contentHelper.FAKE_CONFIGS);
    final ComponentContext cc = context.componentContext();
    // With the installer deactivated, remove two resources and add some new ones 
    osgiInstaller.clearRecordedCalls();
    installer.deactivate(cc);
    assertEquals("Expected no calls to OsgiInstaller when deactivating JcrInstaller", 0, osgiInstaller.getRecordedCalls().size());
    final int toRemove = 2;
    contentHelper.delete(contentHelper.FAKE_RESOURCES[toRemove]);
    contentHelper.delete(contentHelper.FAKE_CONFIGS[toRemove]);
    final String[] toAdd = { "/libs/foo/bar/install/" + System.currentTimeMillis() + ".jar", "/libs/foo/wii/install/" + +System.currentTimeMillis() + ".properties", "/libs/foo/wii/install/" + +System.currentTimeMillis() + ".cfg" };
    for (String path : toAdd) {
        contentHelper.createOrUpdateFile(path);
    }
    // Verify that no calls have been made to OSGi installer
    eventHelper.waitForEvents(TIMEOUT);
    Thread.sleep(JcrInstaller.RUN_LOOP_DELAY_MSEC * 3);
    assertEquals("Expected no calls to OsgiInstaller while JcrInstaller is stopped", 0, osgiInstaller.getRecordedCalls().size());
    // Restart JcrInstaller and verify that all remaining resources are re-registered
    installer.activate(cc);
    MiscUtil.waitAfterContentChanges(eventHelper, installer);
    for (int i = 0; i < contentHelper.FAKE_RESOURCES.length; i++) {
        final String path = contentHelper.FAKE_RESOURCES[i];
        if (i == toRemove) {
            assertFalse("Path should be absent from recorded calls", osgiInstaller.getRecordedCalls().contains(path));
        } else {
            assertRecordedCall("register", path);
        }
    }
    for (int i = 0; i < contentHelper.FAKE_CONFIGS.length; i++) {
        final String path = contentHelper.FAKE_CONFIGS[i];
        if (i == toRemove) {
            assertFalse("Path should be absent from recorded calls", osgiInstaller.getRecordedCalls().contains(path));
        } else {
            assertRecordedCall("register", path);
        }
    }
    for (String path : toAdd) {
        assertRecordedCall("register", path);
    }
}
Also used : ComponentContext(org.osgi.service.component.ComponentContext) Test(org.junit.Test)

Aggregations

ComponentContext (org.osgi.service.component.ComponentContext)74 BundleContext (org.osgi.framework.BundleContext)46 Test (org.junit.Test)32 Dictionary (java.util.Dictionary)17 Before (org.junit.Before)12 JaxbUser (org.opencastproject.security.api.JaxbUser)11 SecurityService (org.opencastproject.security.api.SecurityService)11 Hashtable (java.util.Hashtable)10 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)10 JaxbRole (org.opencastproject.security.api.JaxbRole)10 File (java.io.File)9 Bundle (org.osgi.framework.Bundle)9 URI (java.net.URI)8 OrganizationDirectoryService (org.opencastproject.security.api.OrganizationDirectoryService)7 User (org.opencastproject.security.api.User)7 UserDirectoryService (org.opencastproject.security.api.UserDirectoryService)7 ServiceReference (org.osgi.framework.ServiceReference)7 Workspace (org.opencastproject.workspace.api.Workspace)6 Version (org.osgi.framework.Version)6 IOException (java.io.IOException)5