use of com.tvd12.ezyhttp.server.core.resources.Resource in project ezyhttp by youngmonkeys.
the class ApplicationContextBuilder method addResourceRequestHandlers.
protected void addResourceRequestHandlers(EzyBeanContext beanContext) {
ResourceResolver resourceResolver = getResourceResolver(beanContext);
if (resourceResolver == null) {
return;
}
ResourceDownloadManager downloadManager = beanContext.getSingleton(ResourceDownloadManager.class);
Map<String, Resource> resources = resourceResolver.getResources();
for (String resourceURI : resources.keySet()) {
Resource resource = resources.get(resourceURI);
RequestURI requestURI = new RequestURI(HttpMethod.GET, resourceURI, false, true, true, resource.getFullPath());
RequestHandler requestHandler = new ResourceRequestHandler(resource.getPath(), resource.getUri(), resource.getExtension(), downloadManager);
requestHandlerManager.addHandler(requestURI, requestHandler);
}
}
use of com.tvd12.ezyhttp.server.core.resources.Resource in project ezyhttp by youngmonkeys.
the class ResourceLoaderTest method urlPathEmpty.
@Test
public void urlPathEmpty() {
// given
ResourceLoader sut = new ResourceLoader() {
@Override
protected Set<URL> getResourceURLs(String resource) {
try {
return Sets.newHashSet(new URL("http://locahost"));
} catch (MalformedURLException e) {
e.printStackTrace();
throw new IllegalArgumentException(e);
}
}
};
// when
List<String> listResources = sut.listResources("application.yaml");
// then
Asserts.assertTrue(listResources.isEmpty());
}
use of com.tvd12.ezyhttp.server.core.resources.Resource in project ezyhttp by youngmonkeys.
the class RequestHandlerManagerTest method test.
@Test
public void test() {
// given
RequestHandlerManager sut = new RequestHandlerManager();
RequestHandler requestHandler = mock(RequestHandler.class);
RequestURI requestURI = new RequestURI(HttpMethod.GET, "/get", RequestURIMeta.builder().api(true).authenticated(true).management(true).resource(true).payment(true).feature("hello.world").resourceFullPath("/").build());
sut.addHandler(requestURI, requestHandler);
// when
FeatureURIManager featureURIManager = sut.getFeatureURIManager();
// then
Asserts.assertEquals(featureURIManager.getFeatureByURI(HttpMethod.GET, "/get"), "hello.world");
Asserts.assertEquals(featureURIManager.getFeatureByURI(HttpMethod.GET, "/get/"), "hello.world");
}
use of com.tvd12.ezyhttp.server.core.resources.Resource in project ezyhttp by youngmonkeys.
the class ResourceResolverTest method test.
@Test
public void test() {
// given
ResourceResolver sut = new ResourceResolver();
sut.register("static/css");
sut.register(new String[] { "templates/js" });
// when
Map<String, Resource> resources = sut.getResources();
// then
Asserts.assertEquals(3, resources.size());
}
Aggregations