Search in sources :

Example 1 with EzyUserRequestAppEvent

use of com.tvd12.ezyfoxserver.event.EzyUserRequestAppEvent in project ezyfox-server by youngmonkeys.

the class EzyUserRequestAppSingletonControllerTest method handleClientRequest.

private void handleClientRequest(EzyAppContext context) {
    EzySimpleApplication app = (EzySimpleApplication) context.getApp();
    EzyAppRequestController requestController = app.getRequestController();
    EzyAbstractSession session = spy(EzyAbstractSession.class);
    EzySimpleUser user = new EzySimpleUser();
    EzyArray data = EzyEntityFactory.newArrayBuilder().append("hello").append(EzyEntityFactory.newObjectBuilder().append("who", "Mr.Young Monkey!")).build();
    EzyUserRequestAppEvent event = new EzySimpleUserRequestAppEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("responseFactoryTest").append(EzyEntityFactory.newObjectBuilder().append("who", "Mr.Young Monkey!")).build();
    event = new EzySimpleUserRequestAppEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("no command").build();
    event = new EzySimpleUserRequestAppEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("hello2").append(EzyEntityFactory.newObjectBuilder().append("who", "Mr.Young Monkey!")).build();
    event = new EzySimpleUserRequestAppEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("hello6").append(EzyEntityFactory.newObjectBuilder().append("who", "Mr.Young Monkey!")).build();
    event = new EzySimpleUserRequestAppEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("c_hello").append(EzyEntityFactory.newObjectBuilder().append("who", "Mr.Young Monkey!")).build();
    event = new EzySimpleUserRequestAppEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("badRequestSend").build();
    event = new EzySimpleUserRequestAppEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("badRequestNotSend").build();
    event = new EzySimpleUserRequestAppEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("requestException").append(EzyEntityFactory.newObjectBuilder().append("who", "Mr.Young Monkey!")).build();
    event = new EzySimpleUserRequestAppEvent(user, session, data);
    requestController.handle(context, event);
    try {
        data = EzyEntityFactory.newArrayBuilder().append("requestException2").build();
        event = new EzySimpleUserRequestAppEvent(user, session, data);
        requestController.handle(context, event);
    } catch (Exception e) {
        assert e.getCause().getClass() == Exception.class;
    }
    data = EzyEntityFactory.newArrayBuilder().append("requestException3").append(EzyEntityFactory.newObjectBuilder().append("who", "Mr.Young Monkey!")).build();
    event = new EzySimpleUserRequestAppEvent(user, session, data);
    requestController.handle(context, event);
    try {
        data = EzyEntityFactory.newArrayBuilder().append("exception").build();
        event = new EzySimpleUserRequestAppEvent(user, session, data);
        requestController.handle(context, event);
    } catch (Exception e) {
        assert e instanceof IllegalStateException;
    }
}
Also used : EzySimpleApplication(com.tvd12.ezyfoxserver.EzySimpleApplication) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzySimpleUserRequestAppEvent(com.tvd12.ezyfoxserver.event.EzySimpleUserRequestAppEvent) EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzyAppRequestController(com.tvd12.ezyfoxserver.app.EzyAppRequestController) EzyUserRequestAppEvent(com.tvd12.ezyfoxserver.event.EzyUserRequestAppEvent)

Example 2 with EzyUserRequestAppEvent

use of com.tvd12.ezyfoxserver.event.EzyUserRequestAppEvent in project ezyfox-server by youngmonkeys.

the class EzySimpleAppEntryTest method handleClientRequest.

private void handleClientRequest(EzyAppContext context) {
    EzySimpleApplication app = (EzySimpleApplication) context.getApp();
    EzyAppRequestController requestController = app.getRequestController();
    EzyAbstractSession session = spy(EzyAbstractSession.class);
    EzySimpleUser user = new EzySimpleUser();
    EzyArray data = EzyEntityFactory.newArrayBuilder().append("chat").append(EzyEntityFactory.newObjectBuilder().append("message", "greet")).build();
    EzyUserRequestAppEvent event = new EzySimpleUserRequestAppEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("chat").build();
    event = new EzySimpleUserRequestAppEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("no command").append(EzyEntityFactory.newObjectBuilder().append("message", "greet")).build();
    event = new EzySimpleUserRequestAppEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("noUser").append(EzyEntityFactory.newObjectBuilder().append("message", "greet")).build();
    event = new EzySimpleUserRequestAppEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("noSession").append(EzyEntityFactory.newObjectBuilder().append("message", "greet")).build();
    event = new EzySimpleUserRequestAppEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("noDataBinding").build();
    event = new EzySimpleUserRequestAppEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("badRequestSend").build();
    event = new EzySimpleUserRequestAppEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("badRequestNoSend").build();
    event = new EzySimpleUserRequestAppEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("exception").build();
    event = new EzySimpleUserRequestAppEvent(user, session, data);
    try {
        requestController.handle(context, event);
    } catch (Exception e) {
        assert e instanceof IllegalStateException;
    }
    data = EzyEntityFactory.newArrayBuilder().append("app").build();
    event = new EzySimpleUserRequestAppEvent(user, session, data);
    requestController.handle(context, event);
}
Also used : EzySimpleApplication(com.tvd12.ezyfoxserver.EzySimpleApplication) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzySimpleUserRequestAppEvent(com.tvd12.ezyfoxserver.event.EzySimpleUserRequestAppEvent) EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzyAppRequestController(com.tvd12.ezyfoxserver.app.EzyAppRequestController) EzyUserRequestAppEvent(com.tvd12.ezyfoxserver.event.EzyUserRequestAppEvent)

Example 3 with EzyUserRequestAppEvent

use of com.tvd12.ezyfoxserver.event.EzyUserRequestAppEvent in project ezyfox-server by youngmonkeys.

the class EzyRequestAppEventImplTest method test.

@Test
public void test() {
    EzyUser user = newUser();
    EzyArray data = newArrayBuilder().append(100).build();
    EzyUserRequestAppEvent event = new EzySimpleUserRequestAppEvent(user, null, data);
    assert event.getData() == data;
    assert event.getUser() == user;
}
Also used : EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) EzySimpleUserRequestAppEvent(com.tvd12.ezyfoxserver.event.EzySimpleUserRequestAppEvent) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzyUserRequestAppEvent(com.tvd12.ezyfoxserver.event.EzyUserRequestAppEvent) BaseCoreTest(com.tvd12.ezyfoxserver.testing.BaseCoreTest) Test(org.testng.annotations.Test)

Example 4 with EzyUserRequestAppEvent

use of com.tvd12.ezyfoxserver.event.EzyUserRequestAppEvent in project ezyfox-server by youngmonkeys.

the class EzyDefaultAppEntryTest method handleClientRequest.

private void handleClientRequest(EzyAppContext context) {
    EzySimpleApplication app = (EzySimpleApplication) context.getApp();
    EzyAppRequestController requestController = app.getRequestController();
    EzyAbstractSession session = spy(EzyAbstractSession.class);
    EzySimpleUser user = new EzySimpleUser();
    EzyArray data = EzyEntityFactory.newArrayBuilder().append("chat").append(EzyEntityFactory.newObjectBuilder().append("message", "greet")).build();
    EzyUserRequestAppEvent event = new EzySimpleUserRequestAppEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("chat").build();
    event = new EzySimpleUserRequestAppEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("no command").append(EzyEntityFactory.newObjectBuilder().append("message", "greet")).build();
    event = new EzySimpleUserRequestAppEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("noUser").append(EzyEntityFactory.newObjectBuilder().append("message", "greet")).build();
    event = new EzySimpleUserRequestAppEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("noSession").append(EzyEntityFactory.newObjectBuilder().append("message", "greet")).build();
    event = new EzySimpleUserRequestAppEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("noDataBinding").build();
    event = new EzySimpleUserRequestAppEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("badRequestSend").build();
    event = new EzySimpleUserRequestAppEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("badRequestNoSend").build();
    event = new EzySimpleUserRequestAppEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("exception").build();
    event = new EzySimpleUserRequestAppEvent(user, session, data);
    try {
        requestController.handle(context, event);
    } catch (Exception e) {
        assert e instanceof IllegalStateException;
    }
    data = EzyEntityFactory.newArrayBuilder().append("app").build();
    event = new EzySimpleUserRequestAppEvent(user, session, data);
    requestController.handle(context, event);
}
Also used : EzySimpleApplication(com.tvd12.ezyfoxserver.EzySimpleApplication) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzySimpleUserRequestAppEvent(com.tvd12.ezyfoxserver.event.EzySimpleUserRequestAppEvent) EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzyAppRequestController(com.tvd12.ezyfoxserver.app.EzyAppRequestController) EzyUserRequestAppEvent(com.tvd12.ezyfoxserver.event.EzyUserRequestAppEvent)

Example 5 with EzyUserRequestAppEvent

use of com.tvd12.ezyfoxserver.event.EzyUserRequestAppEvent in project ezyfox-server by youngmonkeys.

the class EzyRequestAppController method handle.

@Override
public void handle(EzyServerContext ctx, EzyRequestAppRequest request) {
    EzyRequestAppParams params = request.getParams();
    EzyAppContext appCtx = ctx.getAppContext(params.getAppId());
    EzyApplication app = appCtx.getApp();
    EzyAppRequestController requestController = app.getRequestController();
    // user manager for checking, user must be managed
    EzyUserManager userManger = appCtx.getApp().getUserManager();
    EzyUser user = request.getUser();
    // check user joined app or not to prevent spam request
    boolean hasAccessed = userManger.containsUser(user);
    if (hasAccessed) {
        // redirect handling to app
        EzyUserRequestAppEvent event = newRequestAppEvent(request);
        requestController.handle(appCtx, event);
    } else {
        EzySession session = request.getSession();
        responseRequestAppError(ctx, session);
    }
}
Also used : EzyApplication(com.tvd12.ezyfoxserver.EzyApplication) EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) EzyRequestAppParams(com.tvd12.ezyfoxserver.request.EzyRequestAppParams) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) EzyAppRequestController(com.tvd12.ezyfoxserver.app.EzyAppRequestController) EzyUserManager(com.tvd12.ezyfoxserver.wrapper.EzyUserManager) EzyUserRequestAppEvent(com.tvd12.ezyfoxserver.event.EzyUserRequestAppEvent) EzySession(com.tvd12.ezyfoxserver.entity.EzySession)

Aggregations

EzyUserRequestAppEvent (com.tvd12.ezyfoxserver.event.EzyUserRequestAppEvent)5 EzyArray (com.tvd12.ezyfox.entity.EzyArray)4 EzyAppRequestController (com.tvd12.ezyfoxserver.app.EzyAppRequestController)4 EzySimpleUserRequestAppEvent (com.tvd12.ezyfoxserver.event.EzySimpleUserRequestAppEvent)4 EzySimpleApplication (com.tvd12.ezyfoxserver.EzySimpleApplication)3 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)3 EzySimpleUser (com.tvd12.ezyfoxserver.entity.EzySimpleUser)3 EzyUser (com.tvd12.ezyfoxserver.entity.EzyUser)2 EzyApplication (com.tvd12.ezyfoxserver.EzyApplication)1 EzyAppContext (com.tvd12.ezyfoxserver.context.EzyAppContext)1 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)1 EzyRequestAppParams (com.tvd12.ezyfoxserver.request.EzyRequestAppParams)1 BaseCoreTest (com.tvd12.ezyfoxserver.testing.BaseCoreTest)1 EzyUserManager (com.tvd12.ezyfoxserver.wrapper.EzyUserManager)1 Test (org.testng.annotations.Test)1