Search in sources :

Example 1 with FileSystemAwareUIHttpContext

use of org.motechproject.osgi.web.http.FileSystemAwareUIHttpContext 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 2 with FileSystemAwareUIHttpContext

use of org.motechproject.osgi.web.http.FileSystemAwareUIHttpContext 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)

Aggregations

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