Search in sources :

Example 6 with ResourceResolver

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());
}
Also used : ResourceResolver(com.tvd12.ezyhttp.server.core.resources.ResourceResolver) EzyPropertyFetcher(com.tvd12.ezyfox.bean.EzyPropertyFetcher) Test(org.testng.annotations.Test)

Example 7 with ResourceResolver

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);
}
Also used : EzyBeanContext(com.tvd12.ezyfox.bean.EzyBeanContext) ResourceResolver(com.tvd12.ezyhttp.server.core.resources.ResourceResolver) ApplicationContextBuilder(com.tvd12.ezyhttp.server.core.ApplicationContextBuilder) Test(org.testng.annotations.Test)

Example 8 with ResourceResolver

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();
}
Also used : ApplicationContext(com.tvd12.ezyhttp.server.core.ApplicationContext) ResourceDownloadManager(com.tvd12.ezyhttp.core.resources.ResourceDownloadManager) EzyBeanContext(com.tvd12.ezyfox.bean.EzyBeanContext) ResourceResolver(com.tvd12.ezyhttp.server.core.resources.ResourceResolver) ApplicationContextBuilder(com.tvd12.ezyhttp.server.core.ApplicationContextBuilder) Test(org.testng.annotations.Test)

Example 9 with ResourceResolver

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();
}
Also used : ApplicationContext(com.tvd12.ezyhttp.server.core.ApplicationContext) ResourceDownloadManager(com.tvd12.ezyhttp.core.resources.ResourceDownloadManager) EzyHttpApplication(com.tvd12.ezyhttp.server.core.EzyHttpApplication) EzyBeanContext(com.tvd12.ezyfox.bean.EzyBeanContext) UserService(com.tvd12.ezyhttp.server.core.test.service.UserService) ResourceResolver(com.tvd12.ezyhttp.server.core.resources.ResourceResolver) ViewContextBuilder(com.tvd12.ezyhttp.server.core.view.ViewContextBuilder) Test(org.testng.annotations.Test)

Aggregations

ResourceResolver (com.tvd12.ezyhttp.server.core.resources.ResourceResolver)9 Test (org.testng.annotations.Test)8 EzyBeanContext (com.tvd12.ezyfox.bean.EzyBeanContext)5 ResourceDownloadManager (com.tvd12.ezyhttp.core.resources.ResourceDownloadManager)5 ApplicationContext (com.tvd12.ezyhttp.server.core.ApplicationContext)4 ApplicationContextBuilder (com.tvd12.ezyhttp.server.core.ApplicationContextBuilder)3 UserService (com.tvd12.ezyhttp.server.core.test.service.UserService)3 ViewContextBuilder (com.tvd12.ezyhttp.server.core.view.ViewContextBuilder)3 EzyPropertyFetcher (com.tvd12.ezyfox.bean.EzyPropertyFetcher)2 EzyHttpApplication (com.tvd12.ezyhttp.server.core.EzyHttpApplication)2 Resource (com.tvd12.ezyhttp.server.core.resources.Resource)2 RequestHandler (com.tvd12.ezyhttp.server.core.handler.RequestHandler)1 ResourceRequestHandler (com.tvd12.ezyhttp.server.core.handler.ResourceRequestHandler)1 ComponentManager (com.tvd12.ezyhttp.server.core.manager.ComponentManager)1 RequestURI (com.tvd12.ezyhttp.server.core.request.RequestURI)1 EventService (com.tvd12.ezyhttp.server.core.test.event.EventService)1 SourceService (com.tvd12.ezyhttp.server.core.test.event.SourceService)1 UserService0 (com.tvd12.ezyhttp.server.core.test.service.UserService0)1 Properties (java.util.Properties)1