Search in sources :

Example 11 with EzyUserLoginEvent

use of com.tvd12.ezyfoxserver.event.EzyUserLoginEvent in project ezyfox-server by youngmonkeys.

the class EzyLoginProcessorTest method processUserSessionsButNotAllowToChangeSession.

@SuppressWarnings("rawtypes")
@Test
public void processUserSessionsButNotAllowToChangeSession() {
    // given
    EzySimpleZoneSetting zoneSetting = new EzySimpleZoneSetting();
    zoneSetting.getUserManagement().setMaxSessionPerUser(1);
    zoneSetting.getUserManagement().setAllowChangeSession(false);
    EzySimpleZone zone = new EzySimpleZone();
    zone.setSetting(zoneSetting);
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    when(zoneContext.getZone()).thenReturn(zone);
    EzySimpleServer server = new EzySimpleServer();
    EzySessionManager sessionManager = mock(EzySessionManager.class);
    server.setSessionManager(sessionManager);
    EzyZoneUserManager userManager = EzyZoneUserManagerImpl.builder().build();
    EzyUser user = mock(EzyUser.class);
    when(user.getName()).thenReturn("monkey");
    when(user.getSessionCount()).thenReturn(1);
    userManager.addUser(user);
    zone.setUserManager(userManager);
    EzyStatistics statistics = mock(EzyStatistics.class);
    EzyUserStatistics userStatistics = mock(EzyUserStatistics.class);
    when(statistics.getUserStats()).thenReturn(userStatistics);
    server.setStatistics(statistics);
    EzyServerContext serverContext = mock(EzyServerContext.class);
    when(serverContext.getServer()).thenReturn(server);
    EzyLoginProcessor sut = new EzyLoginProcessor(serverContext);
    EzySessionDelegate sessionDelegate = mock(EzySessionDelegate.class);
    EzyAbstractSession session = spy(EzyAbstractSession.class);
    session.setDelegate(sessionDelegate);
    EzyUserLoginEvent event = mock(EzyUserLoginEvent.class);
    when(event.getUsername()).thenReturn("monkey");
    when(event.getSession()).thenReturn(session);
    // when
    Throwable e = Asserts.assertThrows(() -> sut.apply(zoneContext, event));
    // then
    Asserts.assertEquals(EzyLoginErrorException.class, e.getClass());
}
Also used : EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyStatistics(com.tvd12.ezyfoxserver.statistics.EzyStatistics) EzySessionManager(com.tvd12.ezyfoxserver.wrapper.EzySessionManager) EzyUserLoginEvent(com.tvd12.ezyfoxserver.event.EzyUserLoginEvent) EzyUserStatistics(com.tvd12.ezyfoxserver.statistics.EzyUserStatistics) EzyZoneUserManager(com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager) EzySimpleZone(com.tvd12.ezyfoxserver.EzySimpleZone) EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzySessionDelegate(com.tvd12.ezyfoxserver.delegate.EzySessionDelegate) EzySimpleZoneSetting(com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting) EzyLoginProcessor(com.tvd12.ezyfoxserver.controller.EzyLoginProcessor) Test(org.testng.annotations.Test)

Example 12 with EzyUserLoginEvent

use of com.tvd12.ezyfoxserver.event.EzyUserLoginEvent in project ezyfox-server by youngmonkeys.

the class EzyLoginProcessorTest method applyWithStreamingDisableByEvent.

@SuppressWarnings("rawtypes")
@Test
public void applyWithStreamingDisableByEvent() {
    // given
    EzySimpleZoneSetting zoneSetting = new EzySimpleZoneSetting();
    zoneSetting.getStreaming().setEnable(true);
    EzySimpleZone zone = new EzySimpleZone();
    zone.setSetting(zoneSetting);
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    when(zoneContext.getZone()).thenReturn(zone);
    EzySimpleServer server = new EzySimpleServer();
    EzySessionManager sessionManager = mock(EzySessionManager.class);
    server.setSessionManager(sessionManager);
    EzyZoneUserManager userManager = EzyZoneUserManagerImpl.builder().build();
    zone.setUserManager(userManager);
    EzyStatistics statistics = mock(EzyStatistics.class);
    EzyUserStatistics userStatistics = mock(EzyUserStatistics.class);
    when(statistics.getUserStats()).thenReturn(userStatistics);
    server.setStatistics(statistics);
    EzyServerContext serverContext = mock(EzyServerContext.class);
    when(serverContext.getServer()).thenReturn(server);
    EzyLoginProcessor sut = new EzyLoginProcessor(serverContext);
    EzySessionDelegate sessionDelegate = mock(EzySessionDelegate.class);
    EzyAbstractSession session = spy(EzyAbstractSession.class);
    session.setDelegate(sessionDelegate);
    EzyUserLoginEvent event = mock(EzyUserLoginEvent.class);
    when(event.getUsername()).thenReturn("monkey");
    when(event.getSession()).thenReturn(session);
    when(event.isStreamingEnable()).thenReturn(false);
    // when
    sut.apply(zoneContext, event);
    // then
    Asserts.assertFalse(session.isStreamingEnable());
}
Also used : EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyStatistics(com.tvd12.ezyfoxserver.statistics.EzyStatistics) EzySessionManager(com.tvd12.ezyfoxserver.wrapper.EzySessionManager) EzyUserLoginEvent(com.tvd12.ezyfoxserver.event.EzyUserLoginEvent) EzyUserStatistics(com.tvd12.ezyfoxserver.statistics.EzyUserStatistics) EzyZoneUserManager(com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager) EzySimpleZone(com.tvd12.ezyfoxserver.EzySimpleZone) EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzySessionDelegate(com.tvd12.ezyfoxserver.delegate.EzySessionDelegate) EzySimpleZoneSetting(com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting) EzyLoginProcessor(com.tvd12.ezyfoxserver.controller.EzyLoginProcessor) Test(org.testng.annotations.Test)

Example 13 with EzyUserLoginEvent

use of com.tvd12.ezyfoxserver.event.EzyUserLoginEvent in project ezyfox-server by youngmonkeys.

the class EzyLoginProcessorTest method checkUsernameIsNull.

@SuppressWarnings("rawtypes")
@Test
public void checkUsernameIsNull() {
    // given
    EzySimpleZoneSetting zoneSetting = new EzySimpleZoneSetting();
    EzySimpleZone zone = new EzySimpleZone();
    zone.setSetting(zoneSetting);
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    when(zoneContext.getZone()).thenReturn(zone);
    EzySimpleServer server = new EzySimpleServer();
    EzySessionManager sessionManager = mock(EzySessionManager.class);
    server.setSessionManager(sessionManager);
    EzyStatistics statistics = mock(EzyStatistics.class);
    EzyUserStatistics userStatistics = mock(EzyUserStatistics.class);
    when(statistics.getUserStats()).thenReturn(userStatistics);
    server.setStatistics(statistics);
    EzyServerContext serverContext = mock(EzyServerContext.class);
    when(serverContext.getServer()).thenReturn(server);
    EzyLoginProcessor sut = new EzyLoginProcessor(serverContext);
    EzyUserLoginEvent event = mock(EzyUserLoginEvent.class);
    // when
    Throwable e = Asserts.assertThrows(() -> sut.apply(zoneContext, event));
    // then
    Asserts.assertEquals(EzyLoginErrorException.class, e.getClass());
}
Also used : EzySimpleZone(com.tvd12.ezyfoxserver.EzySimpleZone) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyStatistics(com.tvd12.ezyfoxserver.statistics.EzyStatistics) EzySessionManager(com.tvd12.ezyfoxserver.wrapper.EzySessionManager) EzyUserLoginEvent(com.tvd12.ezyfoxserver.event.EzyUserLoginEvent) EzySimpleZoneSetting(com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting) EzyUserStatistics(com.tvd12.ezyfoxserver.statistics.EzyUserStatistics) EzyLoginProcessor(com.tvd12.ezyfoxserver.controller.EzyLoginProcessor) Test(org.testng.annotations.Test)

Example 14 with EzyUserLoginEvent

use of com.tvd12.ezyfoxserver.event.EzyUserLoginEvent in project ezyfox-server by youngmonkeys.

the class EzyLoginController method handle.

@Override
public void handle(EzyServerContext ctx, EzyLoginRequest request) {
    try {
        EzySession session = request.getSession();
        EzyLoginParams params = request.getParams();
        EzyZoneContext zoneContext = ctx.getZoneContext(params.getZoneName());
        EzyUserLoginEvent loginEvent = newLoginEvent(session, params);
        try {
            control(ctx, zoneContext, loginEvent);
        } finally {
            loginEvent.release();
        }
    } catch (EzyLoginErrorException e) {
        processException(ctx, request.getSession(), e);
        throw e;
    } catch (EzyMaxUserException e) {
        processException(ctx, request.getSession(), maximumUsers(e));
        throw e;
    } catch (EzyZoneNotFoundException e) {
        processException(ctx, request.getSession(), zoneNotFound(e));
        throw e;
    } catch (Exception e) {
        processException(ctx, request.getSession(), serverError(e));
        throw e;
    }
}
Also used : EzyMaxUserException(com.tvd12.ezyfoxserver.exception.EzyMaxUserException) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyZoneNotFoundException(com.tvd12.ezyfoxserver.exception.EzyZoneNotFoundException) EzyLoginParams(com.tvd12.ezyfoxserver.request.EzyLoginParams) EzyLoginErrorException(com.tvd12.ezyfoxserver.exception.EzyLoginErrorException) EzyUserLoginEvent(com.tvd12.ezyfoxserver.event.EzyUserLoginEvent) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyLoginErrorException(com.tvd12.ezyfoxserver.exception.EzyLoginErrorException) EzyMaxUserException(com.tvd12.ezyfoxserver.exception.EzyMaxUserException) EzyZoneNotFoundException(com.tvd12.ezyfoxserver.exception.EzyZoneNotFoundException)

Aggregations

EzyUserLoginEvent (com.tvd12.ezyfoxserver.event.EzyUserLoginEvent)11 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)10 Test (org.testng.annotations.Test)10 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)9 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)8 EzySimpleZone (com.tvd12.ezyfoxserver.EzySimpleZone)7 EzyLoginProcessor (com.tvd12.ezyfoxserver.controller.EzyLoginProcessor)7 EzySimpleZoneSetting (com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting)7 EzyStatistics (com.tvd12.ezyfoxserver.statistics.EzyStatistics)7 EzyUserStatistics (com.tvd12.ezyfoxserver.statistics.EzyUserStatistics)7 EzySessionManager (com.tvd12.ezyfoxserver.wrapper.EzySessionManager)7 EzyZoneUserManager (com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager)7 EzySessionDelegate (com.tvd12.ezyfoxserver.delegate.EzySessionDelegate)6 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)6 EzyUser (com.tvd12.ezyfoxserver.entity.EzyUser)5 EzyLoginErrorException (com.tvd12.ezyfoxserver.exception.EzyLoginErrorException)5 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)4 EzyArray (com.tvd12.ezyfox.entity.EzyArray)3 EzyResponseApi (com.tvd12.ezyfoxserver.api.EzyResponseApi)2 EzySimpleServerContext (com.tvd12.ezyfoxserver.context.EzySimpleServerContext)2