Search in sources :

Example 1 with HelloController

use of com.tvd12.ezyfoxserver.support.test.controller.HelloController in project ezyfox-server by youngmonkeys.

the class EzyRequestControllerTest method test.

@Test
public void test() {
    Object instance = new HelloController();
    EzyRequestControllerProxy controllerProxy = new EzyRequestControllerProxy(instance);
    assert controllerProxy.getInstance() == instance;
    // noinspection ConstantConditions
    assert controllerProxy.getExceptionHandlerMethods().size() >= 0;
    System.out.println(controllerProxy);
}
Also used : HelloController(com.tvd12.ezyfoxserver.support.test.controller.HelloController) EzyRequestControllerProxy(com.tvd12.ezyfoxserver.support.reflect.EzyRequestControllerProxy) Test(org.testng.annotations.Test)

Example 2 with HelloController

use of com.tvd12.ezyfoxserver.support.test.controller.HelloController in project ezyfox-server by youngmonkeys.

the class EzyRequestHandlersImplementerTest method testImplementFailedCase.

@Test(expectedExceptions = IllegalStateException.class)
public void testImplementFailedCase() {
    EzyRequestControllerProxy proxy = new EzyRequestControllerProxy(new HelloController());
    EzyRequestHandlerImplementer implementer = new EzyRequestHandlerImplementer(proxy, proxy.getRequestHandlerMethods().get(0)) {

        @Override
        protected EzyAsmRequestHandler doImplement() {
            throw new RuntimeException("test");
        }
    };
    implementer.implement();
}
Also used : EzyRequestHandlerImplementer(com.tvd12.ezyfoxserver.support.asm.EzyRequestHandlerImplementer) EzyRequestControllerProxy(com.tvd12.ezyfoxserver.support.reflect.EzyRequestControllerProxy) HelloController(com.tvd12.ezyfoxserver.support.test.controller.HelloController) Test(org.testng.annotations.Test)

Example 3 with HelloController

use of com.tvd12.ezyfoxserver.support.test.controller.HelloController 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 4 with HelloController

use of com.tvd12.ezyfoxserver.support.test.controller.HelloController 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 5 with HelloController

use of com.tvd12.ezyfoxserver.support.test.controller.HelloController 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)

Aggregations

GreetResponse (com.tvd12.ezyfoxserver.support.test.data.GreetResponse)8 EzyDoHandle (com.tvd12.ezyfox.core.annotation.EzyDoHandle)7 HelloController (com.tvd12.ezyfoxserver.support.test.controller.HelloController)5 Test (org.testng.annotations.Test)5 EzyRequestHandlersImplementer (com.tvd12.ezyfoxserver.support.asm.EzyRequestHandlersImplementer)3 EzyFeatureCommandManager (com.tvd12.ezyfoxserver.support.manager.EzyFeatureCommandManager)3 EzyRequestCommandManager (com.tvd12.ezyfoxserver.support.manager.EzyRequestCommandManager)3 EzyRequestControllerProxy (com.tvd12.ezyfoxserver.support.reflect.EzyRequestControllerProxy)2 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 EzyRequestHandlerImplementer (com.tvd12.ezyfoxserver.support.asm.EzyRequestHandlerImplementer)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 GreetRequest (com.tvd12.ezyfoxserver.support.test.data.GreetRequest)1