Search in sources :

Example 31 with Controller

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}");
}
Also used : GraphQLSchemaParser(com.tvd12.ezyhttp.server.graphql.GraphQLSchemaParser) GraphQLRequest(com.tvd12.ezyhttp.server.graphql.data.GraphQLRequest) GraphQLDataFetcher(com.tvd12.ezyhttp.server.graphql.GraphQLDataFetcher) GraphQLDataFetcherManager(com.tvd12.ezyhttp.server.graphql.GraphQLDataFetcherManager) GraphQLController(com.tvd12.ezyhttp.server.graphql.controller.GraphQLController) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.testng.annotations.Test)

Example 32 with Controller

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());
}
Also used : GraphQLSchemaParser(com.tvd12.ezyhttp.server.graphql.GraphQLSchemaParser) HttpNotFoundException(com.tvd12.ezyhttp.core.exception.HttpNotFoundException) GraphQLDataFetcherManager(com.tvd12.ezyhttp.server.graphql.GraphQLDataFetcherManager) GraphQLController(com.tvd12.ezyhttp.server.graphql.controller.GraphQLController) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.testng.annotations.Test)

Example 33 with Controller

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());
}
Also used : GraphQLSchemaParser(com.tvd12.ezyhttp.server.graphql.GraphQLSchemaParser) GraphQLRequest(com.tvd12.ezyhttp.server.graphql.data.GraphQLRequest) GraphQLDataFetcher(com.tvd12.ezyhttp.server.graphql.GraphQLDataFetcher) GraphQLDataFetcherManager(com.tvd12.ezyhttp.server.graphql.GraphQLDataFetcherManager) GraphQLController(com.tvd12.ezyhttp.server.graphql.controller.GraphQLController) GraphQLInvalidSchemeException(com.tvd12.ezyhttp.server.graphql.exception.GraphQLInvalidSchemeException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.testng.annotations.Test)

Example 34 with Controller

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);
}
Also used : GraphQLController(com.tvd12.ezyhttp.server.graphql.controller.GraphQLController) List(java.util.List)

Example 35 with 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);
}
Also used : RequestHandlersImplementer(com.tvd12.ezyhttp.server.core.asm.RequestHandlersImplementer) RequestHandlerManager(com.tvd12.ezyhttp.server.core.manager.RequestHandlerManager) RequestURI(com.tvd12.ezyhttp.server.core.request.RequestURI) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)38 EzyArray (com.tvd12.ezyfox.entity.EzyArray)18 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)14 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)14 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)14 EzyResponseApi (com.tvd12.ezyfoxserver.api.EzyResponseApi)12 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)12 EzyLoginController (com.tvd12.ezyfoxserver.controller.EzyLoginController)12 EzySimpleLoginRequest (com.tvd12.ezyfoxserver.request.EzySimpleLoginRequest)12 EzySimpleServerContext (com.tvd12.ezyfoxserver.context.EzySimpleServerContext)11 BaseTest (com.tvd12.test.base.BaseTest)10 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 GraphQLController (com.tvd12.ezyhttp.server.graphql.controller.GraphQLController)6 GraphQLDataFetcherManager (com.tvd12.ezyhttp.server.graphql.GraphQLDataFetcherManager)5 EzySimpleUserManagementSetting (com.tvd12.ezyfoxserver.setting.EzySimpleUserManagementSetting)4 EzyZoneSetting (com.tvd12.ezyfoxserver.setting.EzyZoneSetting)4 EzySessionManager (com.tvd12.ezyfoxserver.wrapper.EzySessionManager)4 GraphQLDataFetcher (com.tvd12.ezyhttp.server.graphql.GraphQLDataFetcher)4 GraphQLSchemaParser (com.tvd12.ezyhttp.server.graphql.GraphQLSchemaParser)4 EzySimplePlugin (com.tvd12.ezyfoxserver.EzySimplePlugin)3