Search in sources :

Example 21 with EzySimpleUser

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

the class EzySocketUserRemovalHandlerTest method test.

@Test
public void test() {
    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);
    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));
    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();
}
Also used : EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) EzyApplication(com.tvd12.ezyfoxserver.EzyApplication) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) Test(org.testng.annotations.Test)

Example 22 with EzySimpleUser

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

the class EzySocketUserRemovalHandlerTest method processUserRemovalQueueThrowableCaseTest.

@Test
public void processUserRemovalQueueThrowableCaseTest() {
    TestBlockingSocketUserRemovalQueue queue = new TestBlockingSocketUserRemovalQueue();
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    EzySimpleUser user = new EzySimpleUser();
    user.setName("test");
    EzySocketUserRemoval item = new EzySimpleSocketUserRemoval(zoneContext, user, EzyUserRemoveReason.EXIT_APP) {

        @Override
        public void release() {
            throw new RuntimeException();
        }
    };
    queue.add(item);
    EzySocketUserRemovalHandler handler = new EzySocketUserRemovalHandler(queue);
    handler.handleEvent();
}
Also used : EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) Test(org.testng.annotations.Test)

Example 23 with EzySimpleUser

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

the class EzySocketUserRemovalHandlerTest method removeUserFromAppExceptionCaseTest.

@Test
public void removeUserFromAppExceptionCaseTest() {
    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 IllegalArgumentException()).when(userManager1).removeUser(any(), any());
    EzySimpleAppSetting appSetting1 = new EzySimpleAppSetting();
    appSetting1.setName("app1");
    when(app1.getSetting()).thenReturn(appSetting1);
    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));
    EzySimpleUser user = new EzySimpleUser();
    user.setName("test");
    EzySocketUserRemoval item = new EzySimpleSocketUserRemoval(zoneContext, user, EzyUserRemoveReason.EXIT_APP);
    queue.add(item);
    EzySocketUserRemovalQueue userRemovalQueue = new EzyBlockingSocketUserRemovalQueue();
    new EzySocketUserRemovalHandler(userRemovalQueue);
    EzySocketUserRemovalHandler handler = new EzySocketUserRemovalHandler(queue);
    handler.handleEvent();
    handler.destroy();
}
Also used : EzySimpleAppSetting(com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting) EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) EzyApplication(com.tvd12.ezyfoxserver.EzyApplication) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager) Test(org.testng.annotations.Test)

Example 24 with EzySimpleUser

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

the class EzySimpleUserTest method equalTest.

@Test
public void equalTest() {
    // given
    EzySimpleUser user1 = new EzySimpleUser();
    user1.setId(1L);
    user1.setName("user");
    user1.setPassword("123456");
    user1.setZoneId(1);
    user1.setMaxSessions(30);
    user1.setStartIdleTime(System.currentTimeMillis());
    user1.setMaxIdleTime(100L);
    user1.setDestroyed(false);
    EzySimpleUser user2 = new EzySimpleUser();
    user2.setId(1L);
    EzySimpleUser user3 = new EzySimpleUser();
    // when
    // then
    // noinspection ConstantConditions
    Asserts.assertFalse(user1.equals(null));
    // noinspection EqualsWithItself
    Asserts.assertTrue(user1.equals(user1));
    Asserts.assertTrue(user1.equals(user2));
    Asserts.assertFalse(user1.equals(user3));
    Asserts.assertFalse(user1.equals(new Object()));
}
Also used : EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) BaseTest(com.tvd12.test.base.BaseTest) Test(org.testng.annotations.Test)

Example 25 with EzySimpleUser

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

Aggregations

EzySimpleUser (com.tvd12.ezyfoxserver.entity.EzySimpleUser)39 Test (org.testng.annotations.Test)29 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)17 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)17 BaseTest (com.tvd12.test.base.BaseTest)13 EzyArray (com.tvd12.ezyfox.entity.EzyArray)11 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)10 EzyAppContext (com.tvd12.ezyfoxserver.context.EzyAppContext)9 EzyApplication (com.tvd12.ezyfoxserver.EzyApplication)6 EzySimpleApplication (com.tvd12.ezyfoxserver.EzySimpleApplication)6 EzySimplePlugin (com.tvd12.ezyfoxserver.EzySimplePlugin)6 EzySimpleAppSetting (com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting)6 EzyZone (com.tvd12.ezyfoxserver.EzyZone)5 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)5 BaseCoreTest (com.tvd12.ezyfoxserver.testing.BaseCoreTest)5 EzyAppUserManager (com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager)5 EzyUser (com.tvd12.ezyfoxserver.entity.EzyUser)4 EzyPluginRequestController (com.tvd12.ezyfoxserver.plugin.EzyPluginRequestController)4 EzyZoneUserManager (com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager)4 EzyServer (com.tvd12.ezyfoxserver.EzyServer)3