use of com.tvd12.ezyhttp.server.core.annotation.Controller in project ezyhttp by youngmonkeys.
the class GraphQLControllerTest method test.
@Test
public void test() throws Exception {
// given
GraphQLSchemaParser schemaParser = new GraphQLSchemaParser();
GraphQLDataFetcher meDataFetcher = new GraphQLMeDataFetcher();
GraphQLDataFetcher heroDataFetcher = new GraphQLHeroDataFetcher();
GraphQLDataFetcherManager dataFetcherManager = GraphQLDataFetcherManager.builder().addDataFetcher(meDataFetcher).addDataFetcher(heroDataFetcher).build();
ObjectMapper objectMapper = new ObjectMapper();
GraphQLController controller = GraphQLController.builder().schemaParser(schemaParser).dataFetcherManager(dataFetcherManager).objectMapper(objectMapper).build();
GraphQLRequest meRequest = new GraphQLRequest();
meRequest.setQuery("query{ me { name bank{id} friends{name} address}}");
String heroQuery = "{hero}";
// when
Object meResult = controller.doPost(meRequest);
Object heroResult = controller.doGet(heroQuery, null);
// then
Asserts.assertEquals(meResult.toString(), "{me={bank={id=1}, name=Dzung, friends=[{name=Foo}, {name=Bar}]}}");
Asserts.assertEquals(heroResult.toString(), "{hero=Hero 007}");
}
use of com.tvd12.ezyhttp.server.core.annotation.Controller in project ezyhttp by youngmonkeys.
the class RequestHandlersImplementer method implement.
public Map<RequestURI, List<RequestHandler>> implement(Object controller) {
Map<RequestURI, List<RequestHandler>> handlers = new HashMap<>();
ControllerProxy proxy = new ControllerProxy(controller);
String feature = proxy.getFeature();
for (RequestHandlerMethod method : proxy.getRequestHandlerMethods()) {
RequestHandlerImplementer implementer = newImplementer(proxy, method);
RequestHandler handler = implementer.implement();
HttpMethod httpMethod = handler.getMethod();
String requestURI = handler.getRequestURI();
String methodFeature = method.getFeature();
RequestURIMeta uriMeta = RequestURIMeta.builder().api(method.isApi() || proxy.isApi()).authenticated(method.isAuthenticated() || proxy.isAuthenticated()).management(method.isManagement() || proxy.isManagement()).payment(method.isPayment() || proxy.isPayment()).feature(methodFeature != null ? methodFeature : feature).build();
RequestURI uri = new RequestURI(httpMethod, requestURI, uriMeta);
handlers.computeIfAbsent(uri, k -> new ArrayList<>()).add(handler);
}
return handlers;
}
use of com.tvd12.ezyhttp.server.core.annotation.Controller in project ezyhttp by youngmonkeys.
the class ControllerAnnotations method getURI.
public static String getURI(Class<?> controllerClass) {
Controller annotation = controllerClass.getAnnotation(Controller.class);
String uri = ControllerAnnotations.getURI(annotation);
if (!uri.startsWith("/")) {
uri = "/" + uri;
}
return uri;
}
use of com.tvd12.ezyhttp.server.core.annotation.Controller in project ezyfox-server by youngmonkeys.
the class EzyRequestPluginControllerTest method test.
@Test
public void test() {
EzyRequestPluginController controller = new EzyRequestPluginController();
EzyServerContext serverContext = mock(EzyServerContext.class);
EzyZoneContext zoneContext = mock(EzyZoneContext.class);
when(serverContext.getZoneContext(1)).thenReturn(zoneContext);
EzyPluginContext pluginContext = mock(EzyPluginContext.class);
when(zoneContext.getPluginContext(1)).thenReturn(pluginContext);
EzyPlugin plugin = mock(EzyPlugin.class);
when(pluginContext.getPlugin()).thenReturn(plugin);
EzyPluginRequestController requestController = mock(EzyPluginRequestController.class);
when(plugin.getRequestController()).thenReturn(requestController);
EzySimpleRequestPluginRequest request = new EzySimpleRequestPluginRequest();
EzyAbstractSession session = spy(EzyAbstractSession.class);
EzySimpleUser user = new EzySimpleUser();
user.setZoneId(1);
user.setId(1);
user.setName("test");
request.setSession(session);
request.setUser(user);
EzyArray array = EzyEntityFactory.newArrayBuilder().append(1).append(EzyEntityFactory.newArrayBuilder()).build();
request.deserializeParams(array);
controller.handle(serverContext, request);
}
use of com.tvd12.ezyhttp.server.core.annotation.Controller in project ezyfox-server by youngmonkeys.
the class EzySimpleStreamingControllerTest method test.
@Test
public void test() {
EzySimpleStreamingController controller = new EzySimpleStreamingController();
EzyZoneContext zoneContext = mock(EzyZoneContext.class);
EzySimpleStreamingRequest request = new EzySimpleStreamingRequest();
controller.handle(zoneContext, request);
}
Aggregations