Search in sources :

Example 1 with EzyAppContext

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

the class EzyAbstractServerControllerTest method test.

@SuppressWarnings("rawtypes")
@Test
public void test() {
    EzySimpleServer server = mock(EzySimpleServer.class);
    EzyAppContext appContext = mock(EzyAppContext.class);
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    ServerController controller = new ServerController();
    EzyServerContext serverContext = mock(EzyServerContext.class);
    when(serverContext.getZoneContext("example")).thenReturn(zoneContext);
    when(serverContext.getZoneContext(1)).thenReturn(zoneContext);
    when(serverContext.getAppContext(1)).thenReturn(appContext);
    when(zoneContext.getAppContext("abc")).thenReturn(appContext);
    when(zoneContext.getAppContext(1)).thenReturn(appContext);
    assertEquals(controller.getAppContext(serverContext, 1), appContext);
    when(zoneContext.getAppContext("abc")).thenReturn(appContext);
    EzyServerControllers controllers = mock(EzyServerControllers.class);
    when(server.getControllers()).thenReturn(controllers);
    when(serverContext.getServer()).thenReturn(server);
    EzyController ctr = mock(EzyController.class);
    when(controllers.getController(EzyCommand.APP_ACCESS)).thenReturn(ctr);
    assertEquals(controller.getControllers(serverContext), controllers);
    assertEquals(controller.getController(serverContext, EzyCommand.APP_ACCESS), ctr);
}
Also used : EzyController(com.tvd12.ezyfoxserver.controller.EzyController) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) EzyServerControllers(com.tvd12.ezyfoxserver.wrapper.EzyServerControllers) EzyAbstractServerController(com.tvd12.ezyfoxserver.controller.EzyAbstractServerController) BaseCoreTest(com.tvd12.ezyfoxserver.testing.BaseCoreTest) Test(org.testng.annotations.Test)

Example 2 with EzyAppContext

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

the class EzyAppResponseImplTest method executeTest.

@Test
public void executeTest() {
    EzyAppContext appContext = mock(EzyAppContext.class);
    EzyApplication app = mock(EzyApplication.class);
    EzyAppUserManager userManager = EzyAppUserManagerImpl.builder().build();
    when(app.getUserManager()).thenReturn(userManager);
    when(appContext.getApp()).thenReturn(app);
    EzyAppResponse cmd = (EzyAppResponse) new EzyAppResponseImpl(appContext).command("test").transportType(EzyTransportType.TCP).params(EzyEntityFactory.newArrayBuilder());
    cmd.execute();
}
Also used : EzyApplication(com.tvd12.ezyfoxserver.EzyApplication) 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) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 3 with EzyAppContext

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

the class EzyBroadcastAppsEventImplTest method newAppContext.

private EzyAppContext newAppContext(String appName, EzyEvent event2) {
    EzyAppContext appContext = mock(EzyAppContext.class);
    EzyApplication app = mock(EzyApplication.class);
    when(appContext.getApp()).thenReturn(app);
    EzySimpleAppSetting setting = new EzySimpleAppSetting();
    setting.setName(appName);
    when(app.getSetting()).thenReturn(setting);
    EzyAppUserManager appUserManager = EzyAppUserManagerImpl.builder().appName(appName).maxUsers(99).build();
    when(app.getUserManager()).thenReturn(appUserManager);
    EzySimpleUser user = new EzySimpleUser();
    user.setName("user" + appName);
    appUserManager.addUser(user);
    doThrow(new IllegalStateException()).when(appContext).handleEvent(EzyEventType.SERVER_INITIALIZING, event2);
    return appContext;
}
Also used : EzySimpleAppSetting(com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting) EzyApplication(com.tvd12.ezyfoxserver.EzyApplication) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext)

Example 4 with EzyAppContext

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

the class EzyBroadcastAppsEventImplTest method test.

@Test
public void test() {
    EzyEvent event2 = new EzySimpleServerInitializingEvent();
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    List<EzyAppContext> appContexts = Lists.newArrayList(newAppContext("1", event2), newAppContext("2", event2), newAppContext("3", event2));
    when(zoneContext.getAppContexts()).thenReturn(appContexts);
    EzyZone zone = mock(EzyZone.class);
    EzySimpleZoneSetting zoneSetting = new EzySimpleZoneSetting();
    zoneSetting.setName("test");
    when(zone.getSetting()).thenReturn(zoneSetting);
    when(zoneContext.getZone()).thenReturn(zone);
    EzyBroadcastAppsEventImpl cmd = new EzyBroadcastAppsEventImpl(zoneContext);
    EzyEvent event = new EzySimpleServerInitializingEvent();
    cmd.fire(EzyEventType.SERVER_INITIALIZING, event, true);
    cmd.fire(EzyEventType.SERVER_INITIALIZING, event, false);
    EzySimpleUser user = new EzySimpleUser();
    user.setName("user1");
    cmd.fire(EzyEventType.SERVER_INITIALIZING, event, user, true);
    cmd.fire(EzyEventType.SERVER_INITIALIZING, event, "user1", true);
    cmd.fire(EzyEventType.SERVER_INITIALIZING, event2, true);
}
Also used : EzySimpleServerInitializingEvent(com.tvd12.ezyfoxserver.event.EzySimpleServerInitializingEvent) EzyZone(com.tvd12.ezyfoxserver.EzyZone) EzyEvent(com.tvd12.ezyfoxserver.event.EzyEvent) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyBroadcastAppsEventImpl(com.tvd12.ezyfoxserver.command.impl.EzyBroadcastAppsEventImpl) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) EzySimpleZoneSetting(com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 5 with EzyAppContext

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

the class EzyAccessAppControllerTest method accessAppFailedDueToMaxUser.

@Test
public void accessAppFailedDueToMaxUser() {
    // given
    EzyServerContext serverContext = mock(EzyServerContext.class);
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    when(serverContext.getZoneContext(1)).thenReturn(zoneContext);
    EzyAppContext appContext = mock(EzyAppContext.class);
    EzyApplication app = mock(EzyApplication.class);
    EzySimpleAppSetting appSetting = new EzySimpleAppSetting();
    appSetting.setName("test");
    when(app.getSetting()).thenReturn(appSetting);
    when(appContext.getApp()).thenReturn(app);
    EzySimpleAppUserDelegate userDelegate = new EzySimpleAppUserDelegate();
    userDelegate.setAppContext(appContext);
    EzyAppUserManager appUserManager = EzyAppUserManagerImpl.builder().maxUsers(1).appName("test").userDelegate(userDelegate).build();
    when(app.getUserManager()).thenReturn(appUserManager);
    when(zoneContext.getAppContext("test")).thenReturn(appContext);
    EzySimpleAccessAppRequest request1 = newRequest(1);
    EzySimpleAccessAppRequest request2 = newRequest(2);
    EzyAccessAppController underTest = new EzyAccessAppController();
    // when
    underTest.handle(serverContext, request1);
    Throwable e = Asserts.assertThrows(() -> underTest.handle(serverContext, request2));
    // then
    Asserts.assertEqualsType(e, EzyAccessAppException.class);
    Asserts.assertEqualsType(e.getCause(), EzyMaxUserException.class);
    verify(appContext, times(1)).handleEvent(eq(EzyEventType.USER_ACCESS_APP), any(EzySimpleUserAccessAppEvent.class));
    verify(appContext, times(1)).handleEvent(eq(EzyEventType.USER_ACCESSED_APP), any(EzySimpleUserAccessedAppEvent.class));
    verify(serverContext, times(2)).getZoneContext(1);
    verify(zoneContext, times(2)).getAppContext("test");
    verify(appContext, times(2)).getApp();
    verify(app, times(2)).getSetting();
    verify(app, times(2)).getUserManager();
    // 1 for success, 1 for failure
    verify(serverContext, times(2)).send(any(EzyResponse.class), any(EzySession.class), any(boolean.class));
}
Also used : EzySimpleAppSetting(com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzySimpleAppUserDelegate(com.tvd12.ezyfoxserver.delegate.EzySimpleAppUserDelegate) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) EzySimpleUserAccessedAppEvent(com.tvd12.ezyfoxserver.event.EzySimpleUserAccessedAppEvent) EzyResponse(com.tvd12.ezyfoxserver.response.EzyResponse) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyApplication(com.tvd12.ezyfoxserver.EzyApplication) EzyAccessAppController(com.tvd12.ezyfoxserver.controller.EzyAccessAppController) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager) EzySimpleAccessAppRequest(com.tvd12.ezyfoxserver.request.EzySimpleAccessAppRequest) EzySimpleUserAccessAppEvent(com.tvd12.ezyfoxserver.event.EzySimpleUserAccessAppEvent) 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