use of com.tvd12.ezyhttp.server.core.resources.ResourceResolver 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.ResourceResolver in project ezyhttp by youngmonkeys.
the class ApplicationContextBuilderTest method test.
@Test
public void test() {
// given
EzyBeanContext internalBeanContext = EzyBeanContext.builder().addSingleton(new InternalSingleton1()).build();
Properties properties = new Properties();
properties.put("b", 2);
ApplicationContext applicationContext = new ApplicationContextBuilder().scan("com.tvd12.ezyhttp.server.core.test.component", "com.tvd12.ezyhttp.server.core.test.config", "com.tvd12.ezyhttp.server.core.test.controller").scan(Arrays.asList("com.tvd12.ezyhttp.server.core.test.reflect", "com.tvd12.ezyhttp.server.core.test.request", "com.tvd12.ezyhttp.server.core.test.resources", "com.tvd12.ezyhttp.server.core.test.service")).addComponentClasses(Collections.singletonList(SourceService.class)).addPropertiesSources(Collections.singletonList("application3.yaml")).addPropertiesSource("application-enable.yaml").addProperty("a", "1").addProperties(properties).addProperties(Collections.singletonMap("c", "3")).beanContext(internalBeanContext).addSingleton(new InternalSingleton2()).addSingleton(Collections.singletonMap("internalSingleton3", new InternalSingleton3())).addSingleton(mock(AbsentMessageResolver.class)).addComponentClass(InternalSingleton1.class).addPropertiesSources().build();
EzyBeanContext beanContext = applicationContext.getBeanContext();
// when
int actualOneProp = beanContext.getProperty("one", int.class);
boolean managementEnable = beanContext.getProperty("management.enable", boolean.class);
Boolean resourceEnable = beanContext.getProperty("resources.enable", boolean.class);
Boolean resourceUploadEnable = beanContext.getProperty("resources.upload.enable", boolean.class);
UserService userService = beanContext.getSingleton(UserService.class);
UserService0 userService0 = beanContext.getSingleton(UserService0.class);
ViewContextBuilder viewContextBuilder = beanContext.getSingleton(ViewContextBuilder.class);
ResourceResolver resourceResolver = beanContext.getSingleton(ResourceResolver.class);
ResourceDownloadManager resourceDownloadManager = beanContext.getSingleton(ResourceDownloadManager.class);
Set<String> packagesToScan = beanContext.getPackagesToScan();
EventService eventService = beanContext.getSingleton(EventService.class);
SourceService sourceService = beanContext.getSingleton(SourceService.class);
String helloValue = beanContext.getProperty("hello", String.class);
InternalSingleton1 internalSingleton1 = beanContext.getBeanCast(InternalSingleton1.class);
InternalSingleton2 internalSingleton2 = beanContext.getBeanCast(InternalSingleton2.class);
InternalSingleton3 internalSingleton3 = beanContext.getBeanCast(InternalSingleton3.class);
// then
Asserts.assertEquals(1, actualOneProp);
Asserts.assertTrue(managementEnable);
Asserts.assertTrue(resourceEnable);
Asserts.assertTrue(resourceUploadEnable);
Asserts.assertNotNull(userService);
Asserts.assertNotNull(userService0);
Asserts.assertNotNull(viewContextBuilder);
Asserts.assertNotNull(resourceDownloadManager);
Asserts.assertEquals(4, resourceResolver.getResources().size());
Asserts.assertNotNull(eventService);
Asserts.assertNotNull(sourceService);
Asserts.assertNotNull(helloValue);
Asserts.assertEquals("1", beanContext.getProperty("a", String.class));
Asserts.assertEquals(2, beanContext.getProperty("b", int.class));
Asserts.assertEquals("3", beanContext.getProperty("c", String.class));
Asserts.assertEquals("3", applicationContext.getProperty("c", String.class));
Asserts.assertEquals(packagesToScan, Sets.newHashSet("com.tvd12.ezyhttp.server", "com.tvd12.ezyhttp.server.core.test", "com.tvd12.ezyhttp.server.core.test.component", "com.tvd12.ezyhttp.server.core.test.config", "com.tvd12.ezyhttp.server.core.test.controller", "com.tvd12.ezyhttp.server.core.test.event", "com.tvd12.ezyhttp.server.core.test.api", "com.tvd12.ezyhttp.server.core.test.reflect", "com.tvd12.ezyhttp.server.core.test.request", "com.tvd12.ezyhttp.server.core.test.resources", "com.tvd12.ezyhttp.server.core.test.service"));
Asserts.assertNotNull(internalSingleton1);
Asserts.assertNotNull(internalSingleton2);
Asserts.assertNotNull(internalSingleton3);
ComponentManager componentManager = ComponentManager.getInstance();
Asserts.assertEquals(componentManager.getAsyncDefaultTimeout(), 10000);
System.out.println(applicationContext);
applicationContext.destroy();
}
use of com.tvd12.ezyhttp.server.core.resources.ResourceResolver in project ezyhttp by youngmonkeys.
the class EzyHttpApplicationTest method startWith2Params.
@Test
public void startWith2Params() throws Exception {
// given
EzyHttpApplication sut = EzyHttpApplication.start(EzyHttpApplicationTest.class, getClass());
ApplicationContext applicationContext = sut.getApplicationContext();
EzyBeanContext beanContext = applicationContext.getBeanContext();
// when
int actualOneProp = beanContext.getProperty("one", int.class);
boolean managementEnable = beanContext.getProperty("management.enable", boolean.class);
UserService userService = applicationContext.getSingleton(UserService.class);
ViewContextBuilder viewContextBuilder = beanContext.getSingleton(ViewContextBuilder.class);
ResourceResolver resourceResolver = beanContext.getSingleton(ResourceResolver.class);
ResourceDownloadManager resourceDownloadManager = beanContext.getSingleton(ResourceDownloadManager.class);
List<Object> bootstraps = applicationContext.getSingletons(ApplicationBootstrap.class);
// then
Asserts.assertEquals(1, actualOneProp);
Asserts.assertTrue(managementEnable);
Asserts.assertNotNull(userService);
Asserts.assertNotNull(viewContextBuilder);
Asserts.assertNotNull(resourceDownloadManager);
Asserts.assertEquals(4, resourceResolver.getResources().size());
Asserts.assertFalse(bootstraps.isEmpty());
sut.stop();
}
use of com.tvd12.ezyhttp.server.core.resources.ResourceResolver 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());
}
use of com.tvd12.ezyhttp.server.core.resources.ResourceResolver in project ezyhttp by youngmonkeys.
the class ResourceResolversTest method testWithNullPattern.
@Test
public void testWithNullPattern() {
// given
EzyPropertyFetcher propertyFetcher = mock(EzyPropertyFetcher.class);
when(propertyFetcher.getProperty(RESOURCE_ENABLE, boolean.class, false)).thenReturn(true);
when(propertyFetcher.getProperty(RESOURCE_LOCATIONS, String[].class)).thenReturn(new String[] { "static" });
// when
ResourceResolver resourceResolver = ResourceResolvers.createResourdeResolver(propertyFetcher);
// then
assert resourceResolver != null;
Asserts.assertEquals(4, resourceResolver.getResources().size());
}
Aggregations