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"));
}
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);
}
Aggregations