use of com.tvd12.ezyfox.bean.EzyBeanContext in project ezyhttp by youngmonkeys.
the class GraphQLConfigurationTest method test.
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void test() throws NoSuchFieldException, IllegalAccessException {
// given
EzyBeanContextBuilder builder = new EzySimpleBeanContext.Builder();
Set<String> packagesToScan = RandomUtil.randomSet(8, String.class);
packagesToScan.add("com.tvd12.ezyhttp.server.graphql.test.config");
for (String p : packagesToScan) {
builder.scan(p);
}
EzyBeanContext context = builder.build();
GraphQLConfiguration sut = new GraphQLConfiguration();
EzySingletonFactory singletonFactory = context.getSingletonFactory();
sut.setSingletonFactory(singletonFactory);
sut.setObjectMapper(new ObjectMapper());
sut.setGraphQLEnable(true);
// when
sut.config();
GraphQLController controller = (GraphQLController) singletonFactory.getSingleton(GraphQLController.class);
Field dataFetcherManagerField = GraphQLController.class.getDeclaredField("dataFetcherManager");
dataFetcherManagerField.setAccessible(true);
GraphQLDataFetcherManager dataFetcherManager = (GraphQLDataFetcherManager) dataFetcherManagerField.get(controller);
Field dataFetchersField = GraphQLDataFetcherManager.class.getDeclaredField("dataFetchers");
dataFetchersField.setAccessible(true);
Map<String, GraphQLDataFetcher> dataFetchers = (Map<String, GraphQLDataFetcher>) dataFetchersField.get(dataFetcherManager);
// then
Asserts.assertNotNull(controller);
Asserts.assertTrue(dataFetchers.containsKey("A"));
}
use of com.tvd12.ezyfox.bean.EzyBeanContext in project ezyhttp by youngmonkeys.
the class ApplicationContextBuilderTest method buildViewContextTemplateResolverNotNullIsNull.
@Test
public void buildViewContextTemplateResolverNotNullIsNull() {
// given
EzyBeanContext beanContext = mock(EzyBeanContext.class);
ViewContextBuilder viewContextBuilder = mock(ViewContextBuilder.class);
when(beanContext.getSingleton(ViewContextBuilder.class)).thenReturn(viewContextBuilder);
TemplateResolver templateResolver = mock(TemplateResolver.class);
when(beanContext.getSingleton(TemplateResolver.class)).thenReturn(templateResolver);
when(viewContextBuilder.templateResolver(templateResolver)).thenReturn(viewContextBuilder);
ViewContext viewContext = mock(ViewContext.class);
when(viewContextBuilder.build()).thenReturn(viewContext);
EzySingletonFactory singletonFactory = mock(EzySingletonFactory.class);
when(beanContext.getSingletonFactory()).thenReturn(singletonFactory);
ViewDialect viewDialect = mock(ViewDialect.class);
List<ViewDialect> viewDialects = Collections.singletonList(viewDialect);
when(beanContext.getSingletonsOf(ViewDialect.class)).thenReturn(viewDialects);
when(viewContextBuilder.viewDialects(viewDialects)).thenReturn(viewContextBuilder);
ViewDecorator viewDecorator = mock(ViewDecorator.class);
List<ViewDecorator> viewDecorators = Collections.singletonList(viewDecorator);
when(beanContext.getSingletonsOf(ViewDecorator.class)).thenReturn(viewDecorators);
when(viewContextBuilder.viewDecorators(viewDecorators)).thenReturn(viewContextBuilder);
MessageProvider messageProvider = mock(MessageProvider.class);
List<MessageProvider> messageProviders = Collections.singletonList(messageProvider);
when(beanContext.getSingletonsOf(MessageProvider.class)).thenReturn(messageProviders);
when(viewContextBuilder.messageProviders(messageProviders)).thenReturn(viewContextBuilder);
AbsentMessageResolver absentMessageResolver = mock(AbsentMessageResolver.class);
when(beanContext.getSingleton(AbsentMessageResolver.class)).thenReturn(absentMessageResolver);
when(viewContextBuilder.absentMessageResolver(absentMessageResolver)).thenReturn(viewContextBuilder);
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)).getSingleton(ViewContextBuilder.class);
verify(beanContext, times(1)).getSingleton(TemplateResolver.class);
verify(beanContext, times(1)).getSingletonsOf(ViewDialect.class);
verify(beanContext, times(1)).getSingletonsOf(ViewDecorator.class);
verify(beanContext, times(1)).getSingleton(AbsentMessageResolver.class);
verify(beanContext, times(1)).getSingletonsOf(MessageProvider.class);
verify(viewContextBuilder, times(1)).templateResolver(templateResolver);
verify(viewContextBuilder, times(1)).viewDialects(viewDialects);
verify(viewContextBuilder, times(1)).viewDecorators(viewDecorators);
verify(viewContextBuilder, times(1)).messageProviders(messageProviders);
verify(viewContextBuilder, times(1)).absentMessageResolver(absentMessageResolver);
verify(viewContextBuilder, times(1)).build();
verify(singletonFactory, times(1)).addSingleton(viewContext);
}
use of com.tvd12.ezyfox.bean.EzyBeanContext 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.ezyfox.bean.EzyBeanContext 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.ezyfox.bean.EzyBeanContext 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);
}
Aggregations