Search in sources :

Example 26 with EzyAppContext

use of com.tvd12.ezyfoxserver.context.EzyAppContext in project ezyfox-server by youngmonkeys.

the class EzySimpleAppEntry method setAppRequestController.

private void setAppRequestController(EzyAppContext appContext, EzyBeanContext beanContext) {
    EzyAppSetup setup = appContext.get(EzyAppSetup.class);
    EzyAppRequestController controller = newUserRequestController(beanContext);
    setup.setRequestController(controller);
    Set<String> commands = ((EzyCommandsAware) controller).getCommands();
    appContext.setProperty(COMMANDS, commands);
}
Also used : EzyCommandsAware(com.tvd12.ezyfoxserver.support.controller.EzyCommandsAware) EzyAppSetup(com.tvd12.ezyfoxserver.command.EzyAppSetup) EzyAppRequestController(com.tvd12.ezyfoxserver.app.EzyAppRequestController)

Example 27 with EzyAppContext

use of com.tvd12.ezyfoxserver.context.EzyAppContext in project ezyfox-server by youngmonkeys.

the class EzySimpleAppEntry method createAppResponseFactory.

private EzyResponseFactory createAppResponseFactory(EzyAppContext appContext, EzyMarshaller marshaller) {
    EzyAppResponseFactory factory = new EzyAppResponseFactory();
    factory.setAppContext(appContext);
    factory.setMarshaller(marshaller);
    return factory;
}
Also used : EzyAppResponseFactory(com.tvd12.ezyfoxserver.support.factory.EzyAppResponseFactory)

Example 28 with EzyAppContext

use of com.tvd12.ezyfoxserver.context.EzyAppContext in project ezyfox-server by youngmonkeys.

the class EzyUserRequestPrototypeControllerTest method test.

@Test
public void test() {
    // given
    EzyPrototypeFactory prototypeFactory = mock(EzyPrototypeFactory.class);
    when(prototypeFactory.getSuppliers(EzyRequestListener.class)).thenReturn(Collections.emptyList());
    EzyBeanContext beanContext = mock(EzyBeanContext.class);
    when(beanContext.getPrototypeFactory()).thenReturn(prototypeFactory);
    InternalController sut = new InternalController.Builder().beanContext(beanContext).build();
    // when
    EzyAppContext appContext = mock(EzyAppContext.class);
    EzyUserRequestEvent event = mock(EzyUserRequestEvent.class);
    String cmd = RandomUtil.randomShortAlphabetString();
    EzyHandler handler = mock(EzyHandler.class);
    sut.postHandle(appContext, event, cmd, handler);
    // then
    verify(beanContext, times(1)).getPrototypeFactory();
    verify(beanContext, times(1)).getSingleton("unmarshaller", EzyUnmarshaller.class);
}
Also used : EzyPrototypeFactory(com.tvd12.ezyfox.bean.EzyPrototypeFactory) EzyBeanContext(com.tvd12.ezyfox.bean.EzyBeanContext) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) EzyUserRequestEvent(com.tvd12.ezyfoxserver.event.EzyUserRequestEvent) EzyHandler(com.tvd12.ezyfox.function.EzyHandler) Test(org.testng.annotations.Test)

Example 29 with EzyAppContext

use of com.tvd12.ezyfoxserver.context.EzyAppContext 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 30 with EzyAppContext

use of com.tvd12.ezyfoxserver.context.EzyAppContext in project ezyfox-server by youngmonkeys.

the class EzyAppResponseImplTest method test.

@SuppressWarnings("rawtypes")
@Test
public void test() throws Exception {
    EzyAppContext context = mock(EzyAppContext.class);
    EzyApplication application = mock(EzyApplication.class);
    EzyAppUserManager userManager = EzyAppUserManagerImpl.builder().build();
    when(context.getApp()).thenReturn(application);
    when(application.getUserManager()).thenReturn(userManager);
    EzyAppResponse response = new EzyAppResponseImpl(context);
    Field recipients = EzyAbstractResponse.class.getDeclaredField("recipients");
    Field exclusiveRecipients = EzyAbstractResponse.class.getDeclaredField("exclusiveRecipients");
    recipients.setAccessible(true);
    exclusiveRecipients.setAccessible(true);
    assert ((Collection) recipients.get(response)).size() == 0;
    assert ((Collection) exclusiveRecipients.get(response)).size() == 0;
    EzyUser user1 = newUser("user1");
    response.user(user1);
    assert ((Collection) recipients.get(response)).size() == 2;
    assert ((Collection) exclusiveRecipients.get(response)).size() == 0;
    EzyUser user2 = newUser("user2");
    response.user(user2);
    response.user(user2, true);
    assert ((Collection) recipients.get(response)).size() == 4;
    assert ((Collection) exclusiveRecipients.get(response)).size() == 2;
    EzyUser user3 = newUser("user3");
    EzyUser user4 = newUser("user4");
    response.users(user3, user4);
    response.users(new EzyUser[] { user3, null }, true);
    assert ((Collection) recipients.get(response)).size() == 8;
    assert ((Collection) exclusiveRecipients.get(response)).size() == 4;
    EzyUser user5 = newUser("user5");
    EzyUser user6 = newUser("user6");
    response.users(Lists.newArrayList(user5, user6));
    response.users(Lists.newArrayList(user5, null), true);
    assert ((Collection) recipients.get(response)).size() == 12;
    assert ((Collection) exclusiveRecipients.get(response)).size() == 6;
    EzyUser user7 = newUser("user7");
    EzyUser user8 = newUser("user8");
    userManager.addUser(user7);
    userManager.addUser(user8);
    response.username("user7");
    response.username("user7", true);
    assert ((Collection) recipients.get(response)).size() == 14;
    assert ((Collection) exclusiveRecipients.get(response)).size() == 8;
    EzyUser user9 = newUser("user9");
    EzyUser user10 = newUser("user10");
    EzyUser user11 = newUser("user11");
    userManager.addUser(user9);
    userManager.addUser(user10);
    userManager.addUser(user11);
    response.usernames("user9", "user10");
    response.usernames(new String[] { "user11" }, true);
    assert ((Collection) recipients.get(response)).size() == 18;
    assert ((Collection) exclusiveRecipients.get(response)).size() == 10;
    EzyUser user12 = newUser("user12");
    EzyUser user13 = newUser("user13");
    EzyUser user14 = newUser("user14");
    userManager.addUser(user12);
    userManager.addUser(user13);
    userManager.addUser(user14);
    response.usernames(Lists.newArrayList("user12", "user13"));
    response.usernames(Lists.newArrayList("user14"), true);
    assert ((Collection) recipients.get(response)).size() == 22;
    assert ((Collection) exclusiveRecipients.get(response)).size() == 12;
    EzySession session1 = new ExSession();
    response.session(session1);
    assert ((Collection) recipients.get(response)).size() == 23;
    assert ((Collection) exclusiveRecipients.get(response)).size() == 12;
    EzySession session2 = new ExSession();
    EzySession session3 = new ExSession();
    response.sessions(session2, session3);
    response.sessions(new EzySession[] { session3 }, true);
    assert ((Collection) recipients.get(response)).size() == 25;
    assert ((Collection) exclusiveRecipients.get(response)).size() == 13;
    EzySession session4 = new ExSession();
    EzySession session5 = new ExSession();
    response.sessions(Lists.newArrayList(session4, session5));
    response.sessions(Lists.newArrayList(session4, session5), true);
    assert ((Collection) recipients.get(response)).size() == 27;
    assert ((Collection) exclusiveRecipients.get(response)).size() == 15;
}
Also used : EzyApplication(com.tvd12.ezyfoxserver.EzyApplication) Field(java.lang.reflect.Field) EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) EzyAppResponseImpl(com.tvd12.ezyfoxserver.command.impl.EzyAppResponseImpl) EzyAppResponse(com.tvd12.ezyfoxserver.command.EzyAppResponse) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Aggregations

EzyAppContext (com.tvd12.ezyfoxserver.context.EzyAppContext)32 Test (org.testng.annotations.Test)24 EzyApplication (com.tvd12.ezyfoxserver.EzyApplication)21 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)18 EzyAppUserManager (com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager)18 BaseTest (com.tvd12.test.base.BaseTest)15 EzySimpleUser (com.tvd12.ezyfoxserver.entity.EzySimpleUser)12 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)11 EzySimpleAppSetting (com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting)11 EzyUser (com.tvd12.ezyfoxserver.entity.EzyUser)10 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)9 EzySimpleAppUserDelegate (com.tvd12.ezyfoxserver.delegate.EzySimpleAppUserDelegate)7 EzySimpleApplication (com.tvd12.ezyfoxserver.EzySimpleApplication)6 EzyAppRequestController (com.tvd12.ezyfoxserver.app.EzyAppRequestController)5 EzySimpleUserAccessAppEvent (com.tvd12.ezyfoxserver.event.EzySimpleUserAccessAppEvent)5 EzyResponse (com.tvd12.ezyfoxserver.response.EzyResponse)5 EzyAppSetting (com.tvd12.ezyfoxserver.setting.EzyAppSetting)5 EzyArray (com.tvd12.ezyfox.entity.EzyArray)4 EzyZone (com.tvd12.ezyfoxserver.EzyZone)4 EzyAccessAppController (com.tvd12.ezyfoxserver.controller.EzyAccessAppController)4