use of com.tvd12.ezyfoxserver.setting.EzyZoneSetting in project ezyfox-server by youngmonkeys.
the class EzyLoginControllerTest method processChangeSessionTest.
@Test
public void processChangeSessionTest() {
EzySimpleServerContext ctx = (EzySimpleServerContext) newServerContext();
EzySimpleServer server = (EzySimpleServer) ctx.getServer();
EzyZoneContext zoneContext = ctx.getZoneContext("example");
EzyZoneSetting zoneSetting = zoneContext.getZone().getSetting();
EzySimpleUserManagementSetting userManagementSetting = (EzySimpleUserManagementSetting) zoneSetting.getUserManagement();
userManagementSetting.setMaxSessionPerUser(1);
userManagementSetting.setAllowChangeSession(true);
server.setResponseApi(mock(EzyResponseApi.class));
EzySession session = newSession();
session.setToken("abcdef");
EzyArray data = newLoginData();
data.set(1, "helloworld");
EzyLoginController controller = new EzyLoginController();
EzySimpleLoginRequest request = new EzySimpleLoginRequest();
request.deserializeParams(data);
request.setSession(session);
controller.handle(ctx, request);
controller.handle(ctx, request);
}
use of com.tvd12.ezyfoxserver.setting.EzyZoneSetting in project ezyfox-server by youngmonkeys.
the class EzyLoginControllerTest method invalidUsernameTest.
@Test(expectedExceptions = EzyLoginErrorException.class)
public void invalidUsernameTest() {
EzySimpleServerContext ctx = (EzySimpleServerContext) newServerContext();
EzySimpleServer server = (EzySimpleServer) ctx.getServer();
EzyZoneContext zoneContext = ctx.getZoneContext("example");
EzyZoneSetting zoneSetting = zoneContext.getZone().getSetting();
EzySimpleUserManagementSetting userManagementSetting = (EzySimpleUserManagementSetting) zoneSetting.getUserManagement();
userManagementSetting.setAllowGuestLogin(false);
server.setResponseApi(mock(EzyResponseApi.class));
EzySession session = newSession();
session.setToken("abcdef");
EzyArray data = newLoginData();
data.set(1, "");
EzyLoginController controller = new EzyLoginController();
EzySimpleLoginRequest request = new EzySimpleLoginRequest();
request.deserializeParams(data);
request.setSession(session);
controller.handle(ctx, request);
}
use of com.tvd12.ezyfoxserver.setting.EzyZoneSetting in project ezyfox-server by youngmonkeys.
the class EzySimpleServerContextBuilder method newZoneContexts.
protected Collection<EzyZoneContext> newZoneContexts(EzyServerContext parent) {
Collection<EzyZoneContext> contexts = new ArrayList<>();
EzySettings settings = EzyServerContexts.getSettings(parent);
for (Integer zoneId : settings.getZoneIds()) {
EzyZoneSetting zoneSetting = settings.getZoneById(zoneId);
EzySimpleZone zone = new EzySimpleZone();
zone.setSetting(zoneSetting);
EzyUserDelegate userDelegate = newUserDelegate(parent);
EzyZoneUserManager userManager = newZoneUserManager(zoneSetting, userDelegate);
EzyEventControllers eventControllers = newEventControllers(zoneSetting.getEventControllers());
zone.setUserManager(userManager);
zone.setEventControllers(eventControllers);
EzySimpleZoneContext zoneContext = new EzySimpleZoneContext();
zoneContext.setParent(parent);
zoneContext.setZone(zone);
zoneContext.addAppContexts(newAppContexts(zoneContext));
zoneContext.addPluginContexts(newPluginContexts(zoneContext));
zoneContext.init();
contexts.add(zoneContext);
processWithException(((EzyStartable) userManager)::start);
}
return contexts;
}
use of com.tvd12.ezyfoxserver.setting.EzyZoneSetting in project ezyfox-server by youngmonkeys.
the class EzyLoginProcessor method newLoginResponse.
protected EzyResponse newLoginResponse(EzyZoneContext zoneContext, EzyUser user, EzyData loginOutputData) {
EzyZoneSetting zoneSetting = getZoneSetting(zoneContext);
EzyLoginParams params = new EzyLoginParams();
params.setData(loginOutputData);
params.setUserId(user.getId());
params.setUsername(user.getName());
params.setZoneId(zoneSetting.getId());
params.setZoneName(zoneSetting.getName());
return new EzyLoginResponse(params);
}
use of com.tvd12.ezyfoxserver.setting.EzyZoneSetting in project ezyfox-server by youngmonkeys.
the class EzySocketUserRemovalHandlerTest method notifyUserRemovedToPluginsExceptionCaseTest.
@Test
public void notifyUserRemovedToPluginsExceptionCaseTest() {
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 RuntimeException()).when(appContext1).handleEvent(any(EzyConstant.class), any(EzyUserEvent.class));
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));
EzyZone zone = mock(EzyZone.class);
when(zoneContext.getZone()).thenReturn(zone);
EzyZoneSetting zoneSetting = mock(EzyZoneSetting.class);
when(zoneSetting.getName()).thenReturn("test");
when(zone.getSetting()).thenReturn(zoneSetting);
doThrow(new RuntimeException()).when(zoneContext).broadcastPlugins(any(EzyConstant.class), any(EzyUserEvent.class), anyBoolean());
EzySimpleUser user = new EzySimpleUser();
user.setName("test");
EzySocketUserRemoval item = new EzySimpleSocketUserRemoval(zoneContext, user, EzyUserRemoveReason.EXIT_APP);
queue.add(item);
EzySocketUserRemovalHandler handler = new EzySocketUserRemovalHandler(queue);
handler.handleEvent();
handler.destroy();
}
Aggregations