use of com.tvd12.ezyhttp.server.core.annotation.Controller 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.ezyhttp.server.core.annotation.Controller in project ezyfox-server by youngmonkeys.
the class EzyLoginControllerTest method allowGuestLoginTest.
@Test
public void allowGuestLoginTest() {
EzySimpleServerContext ctx = (EzySimpleServerContext) newServerContext();
EzySimpleServer server = (EzySimpleServer) ctx.getServer();
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.ezyhttp.server.core.annotation.Controller in project ezyfox-server by youngmonkeys.
the class EzyLoginControllerTest method testExceptionCase.
@SuppressWarnings("rawtypes")
@Test(expectedExceptions = IllegalStateException.class)
public void testExceptionCase() {
EzyServerContext ctx = mock(EzyServerContext.class);
doThrow(new IllegalStateException("server maintain")).when(ctx).send(any(EzyResponse.class), any(EzySession.class), any(boolean.class));
EzyStatistics userStats = new EzySimpleStatistics();
EzySimpleServer server = new EzySimpleServer();
server.setStatistics(userStats);
when(ctx.getServer()).thenReturn(server);
server.setResponseApi(mock(EzyResponseApi.class));
EzySessionManager sessionManager = mock(EzySessionManager.class);
server.setSessionManager(sessionManager);
EzyZoneContext zoneContext = mock(EzyZoneContext.class);
when(ctx.getZoneContext("example")).thenReturn(zoneContext);
EzySimpleZone zone = new EzySimpleZone();
EzySimpleZoneSetting zoneSetting = new EzySimpleZoneSetting();
zone.setSetting(zoneSetting);
when(zoneContext.getZone()).thenReturn(zone);
EzyZoneUserManager zoneUserManager = EzyZoneUserManagerImpl.builder().maxUsers(1).build();
zone.setUserManager(zoneUserManager);
EzySession session = newSession();
session.setToken("abcdef");
EzyArray data = newLoginData();
EzyLoginController controller = new EzyLoginController() {
@Override
protected void responseLoginError(EzyServerContext ctx, EzySession session, EzyILoginError error) {
}
};
EzySimpleLoginRequest request = new EzySimpleLoginRequest();
request.deserializeParams(data);
request.setSession(session);
controller.handle(ctx, request);
}
use of com.tvd12.ezyhttp.server.core.annotation.Controller in project ezyfox-server by youngmonkeys.
the class EzyExitAppControllerTest method test.
@Test
public void test() {
EzyExitAppController controller = new EzyExitAppController();
EzyServerContext serverContext = mock(EzyServerContext.class);
EzyAppContext appContext = mock(EzyAppContext.class);
EzyApplication app = mock(EzyApplication.class);
when(appContext.getApp()).thenReturn(app);
EzyAppUserManager userManager = mock(EzyAppUserManager.class);
when(app.getUserManager()).thenReturn(userManager);
when(serverContext.getAppContext(1)).thenReturn(appContext);
EzySimpleExitAppRequest request = new EzySimpleExitAppRequest();
request.deserializeParams(EzyEntityFactory.newArrayBuilder().append(1).build());
controller.handle(serverContext, request);
}
use of com.tvd12.ezyhttp.server.core.annotation.Controller in project ezyfox-server by youngmonkeys.
the class EzyEventControllerSettingBuilderTest method test.
@Test
public void test() {
// given
EzyEventControllerSettingBuilder sut = new EzyEventControllerSettingBuilder().controller(A.class).eventType(EzyEventType.SERVER_READY);
// when
EzyEventControllerSetting eventController = sut.build();
// then
Asserts.assertEquals(A.class.getName(), eventController.getController());
Asserts.assertEquals(EzyEventType.SERVER_READY.toString(), eventController.getEventType());
}
Aggregations