Search in sources :

Example 1 with GraphQLConfiguration

use of com.tvd12.ezyhttp.server.graphql.GraphQLConfiguration 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"));
}
Also used : GraphQLDataFetcher(com.tvd12.ezyhttp.server.graphql.GraphQLDataFetcher) EzyBeanContext(com.tvd12.ezyfox.bean.EzyBeanContext) EzyBeanContextBuilder(com.tvd12.ezyfox.bean.EzyBeanContextBuilder) GraphQLController(com.tvd12.ezyhttp.server.graphql.controller.GraphQLController) EzySingletonFactory(com.tvd12.ezyfox.bean.EzySingletonFactory) Field(java.lang.reflect.Field) EzyBeanContextBuilder(com.tvd12.ezyfox.bean.EzyBeanContextBuilder) GraphQLDataFetcherManager(com.tvd12.ezyhttp.server.graphql.GraphQLDataFetcherManager) Map(java.util.Map) GraphQLConfiguration(com.tvd12.ezyhttp.server.graphql.GraphQLConfiguration) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.testng.annotations.Test)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 EzyBeanContext (com.tvd12.ezyfox.bean.EzyBeanContext)1 EzyBeanContextBuilder (com.tvd12.ezyfox.bean.EzyBeanContextBuilder)1 EzySingletonFactory (com.tvd12.ezyfox.bean.EzySingletonFactory)1 GraphQLConfiguration (com.tvd12.ezyhttp.server.graphql.GraphQLConfiguration)1 GraphQLDataFetcher (com.tvd12.ezyhttp.server.graphql.GraphQLDataFetcher)1 GraphQLDataFetcherManager (com.tvd12.ezyhttp.server.graphql.GraphQLDataFetcherManager)1 GraphQLController (com.tvd12.ezyhttp.server.graphql.controller.GraphQLController)1 Field (java.lang.reflect.Field)1 Map (java.util.Map)1 Test (org.testng.annotations.Test)1