use of com.tvd12.ezyhttp.server.core.resources.ResourceResolver in project ezyhttp by youngmonkeys.
the class ResourceResolversTest method test.
@Test
public void test() {
// 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(propertyFetcher.getProperty(RESOURCE_PATTERN, String.class)).thenReturn("static/.+");
// when
ResourceResolver resourceResolver = ResourceResolvers.createResourdeResolver(propertyFetcher);
// then
assert resourceResolver != null;
Asserts.assertEquals(4, resourceResolver.getResources().size());
}
use of com.tvd12.ezyhttp.server.core.resources.ResourceResolver in project ezyhttp by youngmonkeys.
the class ApplicationContextBuilderTest method getResourceResolverNotNull.
@Test
public void getResourceResolverNotNull() {
// given
EzyBeanContext beanContext = mock(EzyBeanContext.class);
ResourceResolver resolver = mock(ResourceResolver.class);
when(beanContext.getSingleton(ResourceResolver.class)).thenReturn(resolver);
ApplicationContextBuilder sut = new ApplicationContextBuilder();
// when
ResourceResolver actual = MethodInvoker.create().object(sut).method("getResourceResolver").param(EzyBeanContext.class, beanContext).invoke(ResourceResolver.class);
// then
Asserts.assertEquals(resolver, actual);
verify(beanContext, times(1)).getSingleton(ResourceResolver.class);
}
use of com.tvd12.ezyhttp.server.core.resources.ResourceResolver in project ezyhttp by youngmonkeys.
the class ApplicationContextBuilderTest method testNotEnable.
@Test
public void testNotEnable() {
// given
System.setProperty(EzyBeanContext.ACTIVE_PROFILES_KEY, "disable");
ApplicationContext applicationContext = new ApplicationContextBuilder().scan("i_dont_know").build();
System.setProperty(EzyBeanContext.ACTIVE_PROFILES_KEY, "enable");
EzyBeanContext beanContext = applicationContext.getBeanContext();
// when
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);
ResourceResolver resourceResolver = beanContext.getSingleton(ResourceResolver.class);
ResourceDownloadManager resourceDownloadManager = beanContext.getSingleton(ResourceDownloadManager.class);
Set<String> packagesToScan = beanContext.getPackagesToScan();
// then
Asserts.assertFalse(managementEnable);
Asserts.assertFalse(resourceEnable);
Asserts.assertFalse(resourceUploadEnable);
Asserts.assertNull(resourceResolver);
Asserts.assertNull(resourceDownloadManager);
Asserts.assertEquals(Sets.newHashSet("i_dont_know", "com.tvd12.ezyhttp.server", "com.tvd12.ezyhttp.server.core.test", "com.tvd12.ezyhttp.server.core.test.config", "com.tvd12.ezyhttp.server.core.test.event", "com.tvd12.ezyhttp.server.core.test.api"), packagesToScan);
applicationContext.destroy();
}
use of com.tvd12.ezyhttp.server.core.resources.ResourceResolver in project ezyhttp by youngmonkeys.
the class EzyHttpApplicationTest method test.
@Test
public void test() throws Exception {
// given
EzyHttpApplication sut = EzyHttpApplication.start(EzyHttpApplicationTest.class);
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 = beanContext.getSingleton(UserService.class);
ViewContextBuilder viewContextBuilder = beanContext.getSingleton(ViewContextBuilder.class);
ResourceResolver resourceResolver = beanContext.getSingleton(ResourceResolver.class);
ResourceDownloadManager resourceDownloadManager = beanContext.getSingleton(ResourceDownloadManager.class);
// then
Asserts.assertEquals(1, actualOneProp);
Asserts.assertTrue(managementEnable);
Asserts.assertNotNull(userService);
Asserts.assertNotNull(viewContextBuilder);
Asserts.assertNotNull(resourceDownloadManager);
Asserts.assertEquals(4, resourceResolver.getResources().size());
sut.stop();
}
Aggregations