Search in sources :

Example 6 with EzySessionDelegate

use of com.tvd12.ezyfoxserver.delegate.EzySessionDelegate 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 7 with EzySessionDelegate

use of com.tvd12.ezyfoxserver.delegate.EzySessionDelegate 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)

Aggregations

EzySessionDelegate (com.tvd12.ezyfoxserver.delegate.EzySessionDelegate)7 Test (org.testng.annotations.Test)7 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)6 EzySimpleZone (com.tvd12.ezyfoxserver.EzySimpleZone)6 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)6 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)6 EzyLoginProcessor (com.tvd12.ezyfoxserver.controller.EzyLoginProcessor)6 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)6 EzyUserLoginEvent (com.tvd12.ezyfoxserver.event.EzyUserLoginEvent)6 EzySimpleZoneSetting (com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting)6 EzyStatistics (com.tvd12.ezyfoxserver.statistics.EzyStatistics)6 EzyUserStatistics (com.tvd12.ezyfoxserver.statistics.EzyUserStatistics)6 EzySessionManager (com.tvd12.ezyfoxserver.wrapper.EzySessionManager)6 EzyZoneUserManager (com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager)6 EzyUser (com.tvd12.ezyfoxserver.entity.EzyUser)4 EzyAbstractSessionDelegate (com.tvd12.ezyfoxserver.delegate.EzyAbstractSessionDelegate)1 EzySimpleUser (com.tvd12.ezyfoxserver.entity.EzySimpleUser)1 BaseTest (com.tvd12.test.base.BaseTest)1