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);
}
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();
}
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;
}
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);
}
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));
}
Aggregations