Search in sources :

Example 16 with EzyUser

use of com.tvd12.ezyfoxserver.client.entity.EzyUser in project ezyfox-server by youngmonkeys.

the class HelloController2 method greet.

@EzyDoHandle("Hello")
public void greet(GreetRequest request, EzyUser user, EzySession session) {
    GreetResponse response = new GreetResponse("Hello " + request.getWho() + "!");
    System.out.println("HelloController::Big/Hello response: " + response);
}
Also used : GreetResponse(com.tvd12.ezyfoxserver.support.test.data.GreetResponse) EzyDoHandle(com.tvd12.ezyfox.core.annotation.EzyDoHandle)

Example 17 with EzyUser

use of com.tvd12.ezyfoxserver.client.entity.EzyUser in project ezyfox-server by youngmonkeys.

the class EzyRequestAppEventImplTest method test.

@Test
public void test() {
    EzyUser user = newUser();
    EzyArray data = newArrayBuilder().append(100).build();
    EzyUserRequestAppEvent event = new EzySimpleUserRequestAppEvent(user, null, data);
    assert event.getData() == data;
    assert event.getUser() == user;
}
Also used : EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) EzySimpleUserRequestAppEvent(com.tvd12.ezyfoxserver.event.EzySimpleUserRequestAppEvent) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzyUserRequestAppEvent(com.tvd12.ezyfoxserver.event.EzyUserRequestAppEvent) BaseCoreTest(com.tvd12.ezyfoxserver.testing.BaseCoreTest) Test(org.testng.annotations.Test)

Example 18 with EzyUser

use of com.tvd12.ezyfoxserver.client.entity.EzyUser in project ezyfox-server-android-client by youngmonkeys.

the class EzyLoginSuccessHandler method handle.

@Override
public void handle(EzyArray data) {
    EzyData responseData = data.get(4, EzyData.class);
    EzyUser user = newUser(data);
    EzyZone zone = newZone(data);
    ((EzyMeAware) client).setMe(user);
    ((EzyZoneAware) client).setZone(zone);
    handleLoginSuccess(responseData);
    EzyLogger.debug("user: " + user + " logged in successfully");
}
Also used : EzyZone(com.tvd12.ezyfoxserver.client.entity.EzyZone) EzyUser(com.tvd12.ezyfoxserver.client.entity.EzyUser) EzyZoneAware(com.tvd12.ezyfoxserver.client.entity.EzyZoneAware) EzyData(com.tvd12.ezyfoxserver.client.entity.EzyData) EzyMeAware(com.tvd12.ezyfoxserver.client.entity.EzyMeAware)

Example 19 with EzyUser

use of com.tvd12.ezyfoxserver.client.entity.EzyUser in project ezyfox-server-android-client by youngmonkeys.

the class EzyLoginSuccessHandler method newUser.

protected EzyUser newUser(EzyArray data) {
    long userId = data.get(2, long.class);
    String username = data.get(3, String.class);
    EzySimpleUser user = new EzySimpleUser(userId, username);
    return user;
}
Also used : EzySimpleUser(com.tvd12.ezyfoxserver.client.entity.EzySimpleUser)

Example 20 with EzyUser

use of com.tvd12.ezyfoxserver.client.entity.EzyUser 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)

Aggregations

EzyUser (com.tvd12.ezyfoxserver.entity.EzyUser)26 Test (org.testng.annotations.Test)16 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)13 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)12 GreetResponse (com.tvd12.ezyfoxserver.support.test.data.GreetResponse)8 EzyDoHandle (com.tvd12.ezyfox.core.annotation.EzyDoHandle)7 EzyApplication (com.tvd12.ezyfoxserver.EzyApplication)6 EzyAppContext (com.tvd12.ezyfoxserver.context.EzyAppContext)6 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)5 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)5 EzyLoginProcessor (com.tvd12.ezyfoxserver.controller.EzyLoginProcessor)5 EzyResponse (com.tvd12.ezyfoxserver.response.EzyResponse)5 EzyZoneUserManager (com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager)5 EzySimpleZone (com.tvd12.ezyfoxserver.EzySimpleZone)4 EzySessionDelegate (com.tvd12.ezyfoxserver.delegate.EzySessionDelegate)4 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)4 EzyUserLoginEvent (com.tvd12.ezyfoxserver.event.EzyUserLoginEvent)4 EzyAppUserManager (com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager)4 EzyConstant (com.tvd12.ezyfox.constant.EzyConstant)3 EzyArray (com.tvd12.ezyfox.entity.EzyArray)3