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);
}
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();
}
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);
}
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;
}
Aggregations