Search in sources :

Example 1 with BundleName

use of org.motechproject.osgi.web.bundle.BundleName in project motech by motech.

the class BundleNameTest method shouldUnderscoreBundleName.

@Test
public void shouldUnderscoreBundleName() {
    String underscoredBundleName = new BundleName("org.motechproject.com-sms-api-bundle").underscore();
    assertThat(underscoredBundleName, Is.is("org_motechproject_com_sms_api_bundle"));
}
Also used : BundleName(org.motechproject.osgi.web.bundle.BundleName) Test(org.junit.Test)

Example 2 with BundleName

use of org.motechproject.osgi.web.bundle.BundleName in project motech by motech.

the class HttpContextFactoryTest method shouldCreateFileSystemAwareUiHttpContext.

@Test
public void shouldCreateFileSystemAwareUiHttpContext() {
    HttpContext httpContext = mock(HttpContext.class);
    PowerMockito.mockStatic(ApplicationEnvironment.class);
    MockBundle bundle = new MockBundle("org.motechproject.com-sms-api-bundle");
    when(ApplicationEnvironment.isInDevelopmentMode()).thenReturn(true);
    when(ApplicationEnvironment.getModulePath(new BundleName("org.motechproject.com-sms-api-bundle"))).thenReturn("/Users/s/project/motech/modules/sms/src/main/resources");
    FileSystemAwareUIHttpContext fileSystemAwareUIHttpContext = (FileSystemAwareUIHttpContext) HttpContextFactory.getHttpContext(httpContext, bundle);
    assertThat(fileSystemAwareUIHttpContext, IsNot.not(notNull()));
    assertThat(fileSystemAwareUIHttpContext.getResourceRootDirectoryPath(), Is.is("/Users/s/project/motech/modules/sms/src/main/resources"));
}
Also used : FileSystemAwareUIHttpContext(org.motechproject.osgi.web.http.FileSystemAwareUIHttpContext) HttpContext(org.osgi.service.http.HttpContext) FileSystemAwareUIHttpContext(org.motechproject.osgi.web.http.FileSystemAwareUIHttpContext) BundleName(org.motechproject.osgi.web.bundle.BundleName) MockBundle(org.eclipse.gemini.blueprint.mock.MockBundle) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with BundleName

use of org.motechproject.osgi.web.bundle.BundleName in project motech by motech.

the class HttpContextFactory method getHttpContext.

/**
 * Decorates the given HttpContext with a @{link FileSystemAwareUIHttpContext} if dynamic resource loading
 * is set up.
 * @param httpContext the default http context for a given bundle
 * @param bundle the bundle for which this http context will be registered
 * @return the decorated instance of the provided context if dynamic loading was set up, the original instance otherwise
 */
public static HttpContext getHttpContext(HttpContext httpContext, Bundle bundle) {
    LOGGER.info("Environment is " + ApplicationEnvironment.getEnvironment());
    if (!ApplicationEnvironment.isInDevelopmentMode()) {
        return httpContext;
    }
    String resourceDirPath = ApplicationEnvironment.getModulePath(new BundleName(bundle.getSymbolicName()));
    if (isBlank(resourceDirPath)) {
        LOGGER.info(String.format("Resource path not given for bundle %s", bundle.getSymbolicName()));
        return httpContext;
    }
    LOGGER.info(String.format("Resource path for bundle %s is %s", bundle.getSymbolicName(), resourceDirPath));
    return new FileSystemAwareUIHttpContext(httpContext, resourceDirPath);
}
Also used : FileSystemAwareUIHttpContext(org.motechproject.osgi.web.http.FileSystemAwareUIHttpContext) BundleName(org.motechproject.osgi.web.bundle.BundleName)

Example 4 with BundleName

use of org.motechproject.osgi.web.bundle.BundleName in project motech by motech.

the class BundleNameTest method shouldTestBundleNameEquality.

@Test
public void shouldTestBundleNameEquality() {
    assertThat(new BundleName("bundle-a"), Is.is(new BundleName("bundle-a")));
    assertThat(new BundleName("bundle-a"), IsNot.not(new BundleName("bundle-b")));
}
Also used : BundleName(org.motechproject.osgi.web.bundle.BundleName) Test(org.junit.Test)

Aggregations

BundleName (org.motechproject.osgi.web.bundle.BundleName)4 Test (org.junit.Test)3 FileSystemAwareUIHttpContext (org.motechproject.osgi.web.http.FileSystemAwareUIHttpContext)2 MockBundle (org.eclipse.gemini.blueprint.mock.MockBundle)1 HttpContext (org.osgi.service.http.HttpContext)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1