use of com.tvd12.ezyhttp.server.core.annotation.Controller in project ezyhttp by youngmonkeys.
the class GraphQLControllerTest method testQueryWithVariables.
@Test
public void testQueryWithVariables() throws Exception {
// given
GraphQLSchemaParser schemaParser = new GraphQLSchemaParser();
GraphQLDataFetcher welcomeDataFetcher = new GraphQLWelcomeDataFetcher();
GraphQLDataFetcherManager dataFetcherManager = GraphQLDataFetcherManager.builder().addDataFetcher(welcomeDataFetcher).build();
ObjectMapper objectMapper = new ObjectMapper();
GraphQLController controller = GraphQLController.builder().schemaParser(schemaParser).dataFetcherManager(dataFetcherManager).objectMapper(objectMapper).build();
String welcomeQuery = "{welcome}";
String variables = "{\"name\": \"Foo\"}";
GraphQLRequest welcomeRequest = new GraphQLRequest();
welcomeRequest.setQuery(welcomeQuery);
welcomeRequest.setVariables(variables);
// when
Object welcomeResult1 = controller.doGet(welcomeQuery, variables);
Object welcomeResult2 = controller.doPost(welcomeRequest);
// then
Asserts.assertEquals(welcomeResult1.toString(), "{welcome=Welcome Foo}");
Asserts.assertEquals(welcomeResult2.toString(), "{welcome=Welcome Foo}");
}
use of com.tvd12.ezyhttp.server.core.annotation.Controller in project ezyhttp by youngmonkeys.
the class GraphQLControllerTest method testFetcherNotFoundException.
@Test
public void testFetcherNotFoundException() {
// given
GraphQLSchemaParser schemaParser = new GraphQLSchemaParser();
GraphQLDataFetcherManager dataFetcherManager = GraphQLDataFetcherManager.builder().build();
ObjectMapper objectMapper = new ObjectMapper();
GraphQLController controller = GraphQLController.builder().schemaParser(schemaParser).dataFetcherManager(dataFetcherManager).objectMapper(objectMapper).build();
String heroQuery = "{hero}";
// when
Throwable e = Asserts.assertThrows(() -> controller.doGet(heroQuery, null));
// then
Asserts.assertEquals(HttpNotFoundException.class.toString(), e.getClass().toString());
}
use of com.tvd12.ezyhttp.server.core.annotation.Controller in project ezyhttp by youngmonkeys.
the class GraphQLControllerTest method testInvalidScheme.
@Test
public void testInvalidScheme() {
// given
GraphQLSchemaParser schemaParser = new GraphQLSchemaParser();
GraphQLDataFetcher meDataFetcher = new GraphQLYouDataFetcher();
GraphQLDataFetcherManager dataFetcherManager = GraphQLDataFetcherManager.builder().addDataFetcher(meDataFetcher).build();
ObjectMapper objectMapper = new ObjectMapper();
GraphQLController controller = GraphQLController.builder().schemaParser(schemaParser).dataFetcherManager(dataFetcherManager).objectMapper(objectMapper).build();
GraphQLRequest youRequest = new GraphQLRequest();
youRequest.setQuery("query{you{friends{name}}}}");
// when
Throwable e = Asserts.assertThrows(() -> controller.doPost(youRequest));
// then
Asserts.assertEquals(GraphQLInvalidSchemeException.class.toString(), e.getClass().toString());
}
use of com.tvd12.ezyhttp.server.core.annotation.Controller in project ezyhttp by youngmonkeys.
the class GraphQLConfiguration method config.
@SuppressWarnings("rawtypes")
@Override
public void config() {
GraphQLSchemaParser schemaParser = new GraphQLSchemaParser();
GraphQLDataFetcherManager.Builder dataFetcherManagerBuilder = GraphQLDataFetcherManager.builder();
List singletons = singletonFactory.getSingletons();
for (Object singleton : singletons) {
dataFetcherManagerBuilder.addDataFetcher(singleton);
}
GraphQLDataFetcherManager dataFetcherManager = dataFetcherManagerBuilder.build();
GraphQLController controller = GraphQLController.builder().objectMapper(objectMapper).dataFetcherManager(dataFetcherManager).schemaParser(schemaParser).build();
singletonFactory.addSingleton(controller);
}
use of com.tvd12.ezyhttp.server.core.annotation.Controller in project ezyhttp by youngmonkeys.
the class RequestHandlersImplementerTest method implementOneAllowOverrideURI.
@Test
public void implementOneAllowOverrideURI() {
// given
RequestHandlersImplementer sut = new RequestHandlersImplementer();
Controller controller = new Controller();
RequestHandlerManager manager = new RequestHandlerManager();
manager.setAllowOverrideURI(true);
// when
manager.addHandlers(sut.implement(Collections.singletonList(controller)));
// then
RequestURI uri = new RequestURI(HttpMethod.GET, "/get", false);
Asserts.assertThat(manager.getHandlerListByURI().get(uri).size()).isEqualsTo(2);
}
Aggregations