Search in sources :

Example 6 with ApplicationContextBuilder

use of com.tvd12.ezyhttp.server.core.ApplicationContextBuilder 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 7 with ApplicationContextBuilder

use of com.tvd12.ezyhttp.server.core.ApplicationContextBuilder 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 8 with ApplicationContextBuilder

use of com.tvd12.ezyhttp.server.core.ApplicationContextBuilder in project ezyhttp by youngmonkeys.

the class ApplicationContextBuilderTest method buildViewContextViewContextNotNull.

@Test
public void buildViewContextViewContextNotNull() {
    // given
    EzyBeanContext beanContext = mock(EzyBeanContext.class);
    ViewContext viewContext = mock(ViewContext.class);
    when(beanContext.getSingleton(ViewContext.class)).thenReturn(viewContext);
    EzySingletonFactory singletonFactory = mock(EzySingletonFactory.class);
    when(beanContext.getSingletonFactory()).thenReturn(singletonFactory);
    ApplicationContextBuilder sut = new ApplicationContextBuilder();
    // when
    ViewContext actual = MethodInvoker.create().object(sut).method("buildViewContext").param(EzyBeanContext.class, beanContext).invoke(ViewContext.class);
    // then
    Asserts.assertEquals(viewContext, actual);
    verify(beanContext, times(1)).getSingleton(ViewContext.class);
    verify(beanContext, times(1)).getSingletonFactory();
    verify(singletonFactory, times(1)).addSingleton(viewContext);
}
Also used : ViewContext(com.tvd12.ezyhttp.server.core.view.ViewContext) EzyBeanContext(com.tvd12.ezyfox.bean.EzyBeanContext) EzySingletonFactory(com.tvd12.ezyfox.bean.EzySingletonFactory) ApplicationContextBuilder(com.tvd12.ezyhttp.server.core.ApplicationContextBuilder) Test(org.testng.annotations.Test)

Example 9 with ApplicationContextBuilder

use of com.tvd12.ezyhttp.server.core.ApplicationContextBuilder in project ezyhttp by youngmonkeys.

the class ApplicationContextBuilder method addComponentClass.

public ApplicationContextBuilder addComponentClass(Class<?> componentClass) {
    ComponentsScan componentsScan = componentClass.getAnnotation(ComponentsScan.class);
    if (componentsScan != null) {
        scan(componentsScan.value().length != 0 ? componentsScan.value() : new String[] { componentClass.getPackage().getName() });
    }
    EzyPackagesToScan packagesToScan = componentClass.getAnnotation(EzyPackagesToScan.class);
    if (packagesToScan != null) {
        scan(packagesToScan.value().length != 0 ? packagesToScan.value() : new String[] { componentClass.getPackage().getName() });
    }
    ComponentClasses componentClasses = componentClass.getAnnotation(ComponentClasses.class);
    if (componentClasses != null) {
        addComponentClasses(componentClasses.value());
    }
    PropertiesSources propertiesSources = componentClass.getAnnotation(PropertiesSources.class);
    if (propertiesSources != null) {
        addPropertiesSources(propertiesSources.value());
    }
    this.componentClasses.add(componentClass);
    return this;
}
Also used : EzyPackagesToScan(com.tvd12.ezyfox.annotation.EzyPackagesToScan) ComponentClasses(com.tvd12.ezyhttp.server.core.annotation.ComponentClasses) PropertiesSources(com.tvd12.ezyhttp.server.core.annotation.PropertiesSources) ComponentsScan(com.tvd12.ezyhttp.server.core.annotation.ComponentsScan)

Aggregations

ApplicationContextBuilder (com.tvd12.ezyhttp.server.core.ApplicationContextBuilder)8 Test (org.testng.annotations.Test)8 EzyBeanContext (com.tvd12.ezyfox.bean.EzyBeanContext)6 ResourceResolver (com.tvd12.ezyhttp.server.core.resources.ResourceResolver)3 ViewContext (com.tvd12.ezyhttp.server.core.view.ViewContext)3 EzySingletonFactory (com.tvd12.ezyfox.bean.EzySingletonFactory)2 ResourceDownloadManager (com.tvd12.ezyhttp.core.resources.ResourceDownloadManager)2 ApplicationContext (com.tvd12.ezyhttp.server.core.ApplicationContext)2 ViewContextBuilder (com.tvd12.ezyhttp.server.core.view.ViewContextBuilder)2 EzyPackagesToScan (com.tvd12.ezyfox.annotation.EzyPackagesToScan)1 EzyPropertiesMap (com.tvd12.ezyfox.bean.EzyPropertiesMap)1 EzyReflection (com.tvd12.ezyfox.reflect.EzyReflection)1 ComponentClasses (com.tvd12.ezyhttp.server.core.annotation.ComponentClasses)1 ComponentsScan (com.tvd12.ezyhttp.server.core.annotation.ComponentsScan)1 PropertiesSources (com.tvd12.ezyhttp.server.core.annotation.PropertiesSources)1 ComponentManager (com.tvd12.ezyhttp.server.core.manager.ComponentManager)1 EventService (com.tvd12.ezyhttp.server.core.test.event.EventService)1 SourceService (com.tvd12.ezyhttp.server.core.test.event.SourceService)1 UserService (com.tvd12.ezyhttp.server.core.test.service.UserService)1 UserService0 (com.tvd12.ezyhttp.server.core.test.service.UserService0)1