Search in sources :

Example 1 with GreetRequest

use of com.tvd12.quick.rpc.examples.hello_world.data.GreetRequest in project ezyfox-server by youngmonkeys.

the class EzyRequestHandlersImplementerTest method test.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void test() {
    // given
    EzyAppContext context = mock(EzyAppContext.class);
    EzySession session = mock(EzyAbstractSession.class);
    EzyUser user = new EzySimpleUser();
    EzyUserSessionEvent event = new EzySimpleUserSessionEvent(user, session);
    EzyRequestHandlerImplementer.setDebug(true);
    EzyRequestHandlersImplementer implementer = new EzyRequestHandlersImplementer();
    EzyResponseFactory responseFactory = mock(EzyResponseFactory.class);
    EzyObjectResponse objectResponse = mock(EzyObjectResponse.class);
    when(responseFactory.newObjectResponse()).thenReturn(objectResponse);
    when(objectResponse.command("Big/Hello6")).thenReturn(objectResponse);
    when(objectResponse.data(new GreetResponse("Hello Dzung!"))).thenReturn(objectResponse);
    when(objectResponse.session(any())).thenReturn(objectResponse);
    doNothing().when(objectResponse).execute();
    implementer.setResponseFactory(responseFactory);
    EzyFeatureCommandManager featureCommandManager = new EzyFeatureCommandManager();
    EzyRequestCommandManager requestCommandManager = new EzyRequestCommandManager();
    implementer.setFeatureCommandManager(featureCommandManager);
    implementer.setRequestCommandManager(requestCommandManager);
    Map<String, EzyUserRequestHandler> handlers = implementer.implement(Collections.singletonList(new HelloController()));
    for (EzyUserRequestHandler handler : handlers.values()) {
        handler.handle(context, event, new GreetRequest("Dzung"));
    }
    EzyRequestHandlerImplementer.setDebug(false);
    implementer = new EzyRequestHandlersImplementer();
    implementer.setFeatureCommandManager(featureCommandManager);
    implementer.setRequestCommandManager(requestCommandManager);
    // when
    handlers = implementer.implement(Collections.singletonList(new HelloController()));
    // then
    Asserts.assertTrue(handlers.containsKey("Big/Hello"));
    verify(responseFactory, times(1)).newObjectResponse();
    verify(objectResponse, times(1)).command("Big/Hello6");
    verify(objectResponse, times(1)).data(new GreetResponse("Hello Dzung!"));
}
Also used : EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) EzyResponseFactory(com.tvd12.ezyfoxserver.support.factory.EzyResponseFactory) GreetRequest(com.tvd12.ezyfoxserver.support.test.data.GreetRequest) HelloController(com.tvd12.ezyfoxserver.support.test.controller.HelloController) EzyFeatureCommandManager(com.tvd12.ezyfoxserver.support.manager.EzyFeatureCommandManager) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) EzyRequestCommandManager(com.tvd12.ezyfoxserver.support.manager.EzyRequestCommandManager) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyRequestHandlersImplementer(com.tvd12.ezyfoxserver.support.asm.EzyRequestHandlersImplementer) GreetResponse(com.tvd12.ezyfoxserver.support.test.data.GreetResponse) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyUserSessionEvent(com.tvd12.ezyfoxserver.event.EzyUserSessionEvent) EzyUserRequestHandler(com.tvd12.ezyfoxserver.support.handler.EzyUserRequestHandler) EzySimpleUserSessionEvent(com.tvd12.ezyfoxserver.event.EzySimpleUserSessionEvent) EzyObjectResponse(com.tvd12.ezyfoxserver.support.command.EzyObjectResponse) Test(org.testng.annotations.Test)

Example 2 with GreetRequest

use of com.tvd12.quick.rpc.examples.hello_world.data.GreetRequest in project ezyfox-server by youngmonkeys.

the class HelloController2 method greet.

@EzyDoHandle("Hello")
public void greet(@EzyRequestData GreetRequest request, EzyUser user, EzySession session, Integer nothing) {
    GreetResponse response = new GreetResponse("Hello " + request.getWho() + "!");
    System.out.println("HelloController::Big/Hello response: " + response);
}
Also used : GreetResponse(com.tvd12.ezyfoxserver.support.test.data.GreetResponse) EzyDoHandle(com.tvd12.ezyfox.core.annotation.EzyDoHandle)

Example 3 with GreetRequest

use of com.tvd12.quick.rpc.examples.hello_world.data.GreetRequest in project ezyfox-server by youngmonkeys.

the class HelloController2 method greet.

@EzyDoHandle("Hello")
public void greet(GreetRequest request, EzyUser user, EzySession session) {
    GreetResponse response = new GreetResponse("Hello " + request.getWho() + "!");
    System.out.println("HelloController::Big/Hello response: " + response);
}
Also used : GreetResponse(com.tvd12.ezyfoxserver.support.test.data.GreetResponse) EzyDoHandle(com.tvd12.ezyfox.core.annotation.EzyDoHandle)

Example 4 with GreetRequest

use of com.tvd12.quick.rpc.examples.hello_world.data.GreetRequest in project ezyfox-examples by tvd12.

the class HelloWorldRpcClientExample method main.

public static void main(String[] args) throws Exception {
    QuickRpcClient client = QuickRpcClient.builder().scan("com.tvd12.quick.rpc.examples.hello_world.data").build();
    GreetResponse response = client.call(new GreetRequest("World"), GreetResponse.class);
    System.out.println(response.getMessage());
}
Also used : GreetResponse(com.tvd12.quick.rpc.examples.hello_world.data.GreetResponse) GreetRequest(com.tvd12.quick.rpc.examples.hello_world.data.GreetRequest) QuickRpcClient(com.tvd12.quick.rpc.client.QuickRpcClient)

Example 5 with GreetRequest

use of com.tvd12.quick.rpc.examples.hello_world.data.GreetRequest in project ezyfox-server by youngmonkeys.

the class HelloController method greet.

@EzyDoHandle("Hello2")
public void greet(@EzyRequestData GreetRequest request, EzyUser user, EzySession session, Integer nothing) {
    GreetResponse response = new GreetResponse("Hello " + request.getWho() + "!");
    System.out.println("HelloController::Big/Hello response: " + response);
}
Also used : GreetResponse(com.tvd12.ezyfoxserver.support.test.data.GreetResponse) EzyDoHandle(com.tvd12.ezyfox.core.annotation.EzyDoHandle)

Aggregations

GreetResponse (com.tvd12.ezyfoxserver.support.test.data.GreetResponse)8 EzyDoHandle (com.tvd12.ezyfox.core.annotation.EzyDoHandle)7 EzyAppContext (com.tvd12.ezyfoxserver.context.EzyAppContext)1 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)1 EzySimpleUser (com.tvd12.ezyfoxserver.entity.EzySimpleUser)1 EzyUser (com.tvd12.ezyfoxserver.entity.EzyUser)1 EzySimpleUserSessionEvent (com.tvd12.ezyfoxserver.event.EzySimpleUserSessionEvent)1 EzyUserSessionEvent (com.tvd12.ezyfoxserver.event.EzyUserSessionEvent)1 EzyRequestHandlersImplementer (com.tvd12.ezyfoxserver.support.asm.EzyRequestHandlersImplementer)1 EzyObjectResponse (com.tvd12.ezyfoxserver.support.command.EzyObjectResponse)1 EzyResponseFactory (com.tvd12.ezyfoxserver.support.factory.EzyResponseFactory)1 EzyUserRequestHandler (com.tvd12.ezyfoxserver.support.handler.EzyUserRequestHandler)1 EzyFeatureCommandManager (com.tvd12.ezyfoxserver.support.manager.EzyFeatureCommandManager)1 EzyRequestCommandManager (com.tvd12.ezyfoxserver.support.manager.EzyRequestCommandManager)1 HelloController (com.tvd12.ezyfoxserver.support.test.controller.HelloController)1 GreetRequest (com.tvd12.ezyfoxserver.support.test.data.GreetRequest)1 QuickRpcClient (com.tvd12.quick.rpc.client.QuickRpcClient)1 GreetRequest (com.tvd12.quick.rpc.examples.hello_world.data.GreetRequest)1 GreetResponse (com.tvd12.quick.rpc.examples.hello_world.data.GreetResponse)1 Test (org.testng.annotations.Test)1