use of com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting in project ezyfox-server by youngmonkeys.
the class EzyExitedAppResponseTest method test.
@Test
public void test() {
EzySimpleAppSetting setting = new EzySimpleAppSetting();
EzyExitedAppParams params = new EzyExitedAppParams();
params.setReason(EzyUserRemoveReason.EXIT_APP);
params.setApp(setting);
EzyExitedAppResponse response = new EzyExitedAppResponse(params);
assert response.getParams() == params;
assert response.getCommand() == EzyCommand.APP_EXIT;
assert response.serialize().size() > 0;
assert params.getApp() == setting;
assert params.getReason() == EzyUserRemoveReason.EXIT_APP;
response.release();
}
use of com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting in project ezyfox-server by youngmonkeys.
the class EzySocketUserRemovalHandlerTest method removeUserFromAppExceptionCaseTest.
@Test
public void removeUserFromAppExceptionCaseTest() {
TestBlockingSocketUserRemovalQueue queue = new TestBlockingSocketUserRemovalQueue();
EzyAppContext appContext1 = mock(EzyAppContext.class);
EzyAppUserManager userManager1 = mock(EzyAppUserManager.class);
when(userManager1.containsUser(any(EzyUser.class))).thenReturn(true);
EzyApplication app1 = mock(EzyApplication.class);
when(app1.getUserManager()).thenReturn(userManager1);
when(appContext1.getApp()).thenReturn(app1);
doThrow(new IllegalArgumentException()).when(userManager1).removeUser(any(), any());
EzySimpleAppSetting appSetting1 = new EzySimpleAppSetting();
appSetting1.setName("app1");
when(app1.getSetting()).thenReturn(appSetting1);
EzyAppContext appContext2 = mock(EzyAppContext.class);
EzyAppUserManager userManager2 = mock(EzyAppUserManager.class);
when(userManager2.containsUser(any(EzyUser.class))).thenReturn(false);
EzyApplication app2 = mock(EzyApplication.class);
when(app2.getUserManager()).thenReturn(userManager2);
when(appContext2.getApp()).thenReturn(app2);
EzyZoneContext zoneContext = mock(EzyZoneContext.class);
when(zoneContext.getAppContexts()).thenReturn(Lists.newArrayList(appContext1, appContext2));
EzySimpleUser user = new EzySimpleUser();
user.setName("test");
EzySocketUserRemoval item = new EzySimpleSocketUserRemoval(zoneContext, user, EzyUserRemoveReason.EXIT_APP);
queue.add(item);
EzySocketUserRemovalQueue userRemovalQueue = new EzyBlockingSocketUserRemovalQueue();
new EzySocketUserRemovalHandler(userRemovalQueue);
EzySocketUserRemovalHandler handler = new EzySocketUserRemovalHandler(queue);
handler.handleEvent();
handler.destroy();
}
use of com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting in project ezyfox-server by youngmonkeys.
the class EzySimpleAppUserDelegateTest method testExceptionCase.
@Test
public void testExceptionCase() {
EzyZoneContext zoneContext = mock(EzyZoneContext.class);
EzyAppContext appContext = mock(EzyAppContext.class);
EzyApplication app = mock(EzyApplication.class);
when(appContext.getApp()).thenReturn(app);
EzySimpleAppSetting appSetting = new EzySimpleAppSetting();
when(app.getSetting()).thenReturn(appSetting);
when(appContext.getParent()).thenReturn(zoneContext);
doThrow(new IllegalStateException()).when(appContext).handleEvent(any(), any());
EzySimpleAppUserDelegate delegate = new EzySimpleAppUserDelegate();
delegate.setAppContext(appContext);
EzySimpleUser user = new EzySimpleUser();
user.setName("test");
delegate.onUserRemoved(user, EzyUserRemoveReason.EXIT_APP);
}
use of com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting in project ezyfox-server by youngmonkeys.
the class EzySimpleAppUserDelegateTest method test.
@Test
public void test() {
EzyZoneContext zoneContext = mock(EzyZoneContext.class);
EzyAppContext appContext = mock(EzyAppContext.class);
EzyApplication app = mock(EzyApplication.class);
when(appContext.getApp()).thenReturn(app);
EzySimpleAppSetting appSetting = new EzySimpleAppSetting();
when(app.getSetting()).thenReturn(appSetting);
when(appContext.getParent()).thenReturn(zoneContext);
EzySimpleAppUserDelegate delegate = new EzySimpleAppUserDelegate();
delegate.setAppContext(appContext);
EzySimpleUser user = new EzySimpleUser();
user.setName("test");
delegate.onUserRemoved(user, EzyUserRemoveReason.EXIT_APP);
}
use of com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting in project ezyfox-server by youngmonkeys.
the class EzyAccessAppControllerTest method accessAppSuccessfullyBut2Times.
@Test
public void accessAppSuccessfullyBut2Times() {
// 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().appName("test").userDelegate(userDelegate).build();
when(app.getUserManager()).thenReturn(appUserManager);
when(zoneContext.getAppContext("test")).thenReturn(appContext);
EzySimpleAccessAppRequest request = newRequest(1);
EzyAccessAppController underTest = new EzyAccessAppController();
// when
underTest.handle(serverContext, request);
underTest.handle(serverContext, request);
// then
verify(appContext, times(2)).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();
verify(serverContext, times(2)).send(any(EzyResponse.class), any(EzySession.class), any(boolean.class));
}
Aggregations