Search in sources :

Example 36 with EzySimpleUser

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

the class EzySimplePluginEntryTest method handleClientRequest.

private void handleClientRequest(EzyPluginContext context) {
    EzySimplePlugin plugin = (EzySimplePlugin) context.getPlugin();
    EzyPluginRequestController requestController = plugin.getRequestController();
    EzyAbstractSession session = spy(EzyAbstractSession.class);
    EzySimpleUser user = new EzySimpleUser();
    EzyArray data = EzyEntityFactory.newArrayBuilder().append("chat").append(EzyEntityFactory.newObjectBuilder().append("message", "greet")).build();
    EzyUserRequestPluginEvent event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("chat").build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("no command").append(EzyEntityFactory.newObjectBuilder().append("message", "greet")).build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("noUser").append(EzyEntityFactory.newObjectBuilder().append("message", "greet")).build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("noSession").append(EzyEntityFactory.newObjectBuilder().append("message", "greet")).build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("noDataBinding").build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("badRequestSend").build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("badRequestNoSend").build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("exception").build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    try {
        requestController.handle(context, event);
    } catch (Exception e) {
        assert e instanceof IllegalStateException;
    }
    data = EzyEntityFactory.newArrayBuilder().append("plugin").build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
}
Also used : EzySimpleUserRequestPluginEvent(com.tvd12.ezyfoxserver.event.EzySimpleUserRequestPluginEvent) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzyPluginRequestController(com.tvd12.ezyfoxserver.plugin.EzyPluginRequestController) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzySimplePlugin(com.tvd12.ezyfoxserver.EzySimplePlugin) EzyUserRequestPluginEvent(com.tvd12.ezyfoxserver.event.EzyUserRequestPluginEvent)

Example 37 with EzySimpleUser

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

the class EzySynchronizedUserManagerTest method test.

@Test
public void test() {
    new EzySynchronizedUserManager(100);
    EzySynchronizedUserManager userManager = EzySynchronizedUserManager.builder().maxUsers(2).build();
    EzySimpleUser user1 = new EzySimpleUser();
    user1.setName("user1");
    EzySimpleUser user2 = new EzySimpleUser();
    user2.setName("user2");
    assert userManager.addUser(user1) == null;
    assert userManager.addUser(user1) != null;
    assert userManager.addUser(user2) == null;
    assert userManager.getUser(user1.getId()) == user1;
    assert userManager.getUser(user1.getName()) == user1;
    assert userManager.getUserList().size() == 2;
    assert userManager.containsUser(user2.getId());
    assert userManager.containsUser(user2.getName());
    assert userManager.removeUser(user2) == user2;
    assert userManager.getUserCount() == 1;
    assert userManager.available();
    assert userManager.getLock(user1.getName()) != null;
    assert userManager.getSynchronizedLock() != null;
    userManager.removeLock(user1.getName());
    userManager.clear();
    userManager.destroy();
}
Also used : EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzySynchronizedUserManager(com.tvd12.ezyfoxserver.wrapper.EzySynchronizedUserManager) Test(org.testng.annotations.Test)

Example 38 with EzySimpleUser

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

the class EzyZoneUserManagerImplTest method newAndAddIdleUser.

private void newAndAddIdleUser(EzyZoneUserManagerImpl manager) {
    EzyAbstractSession session = mock(EzyAbstractSession.class);
    EzySimpleUser user = new EzySimpleUser();
    user.setZoneId(1);
    user.setName("user3");
    user.setMaxIdleTime(Integer.MAX_VALUE);
    manager.addUser(session, user);
    user.removeSession(session);
    user.setMaxIdleTime(0);
}
Also used : EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession)

Example 39 with EzySimpleUser

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

the class EzySocketUserRemovalHandlerTest method notifyUserRemovedToPluginsExceptionCaseTest.

@Test
public void notifyUserRemovedToPluginsExceptionCaseTest() {
    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 RuntimeException()).when(appContext1).handleEvent(any(EzyConstant.class), any(EzyUserEvent.class));
    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));
    EzyZone zone = mock(EzyZone.class);
    when(zoneContext.getZone()).thenReturn(zone);
    EzyZoneSetting zoneSetting = mock(EzyZoneSetting.class);
    when(zoneSetting.getName()).thenReturn("test");
    when(zone.getSetting()).thenReturn(zoneSetting);
    doThrow(new RuntimeException()).when(zoneContext).broadcastPlugins(any(EzyConstant.class), any(EzyUserEvent.class), anyBoolean());
    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 : EzyZone(com.tvd12.ezyfoxserver.EzyZone) EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyZoneSetting(com.tvd12.ezyfoxserver.setting.EzyZoneSetting) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) EzyApplication(com.tvd12.ezyfoxserver.EzyApplication) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager) EzyConstant(com.tvd12.ezyfox.constant.EzyConstant) EzyUserEvent(com.tvd12.ezyfoxserver.event.EzyUserEvent) Test(org.testng.annotations.Test)

Example 40 with EzySimpleUser

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

the class EzyAppUserManagerImplTest method test.

@Test
public void test() {
    EzyAppUserDelegate userDelegate = mock(EzyAppUserDelegate.class);
    EzyAppUserManager manager = EzyAppUserManagerImpl.builder().appName("test").userDelegate(userDelegate).build();
    EzySimpleUser user = new EzySimpleUser();
    user.setName("test");
    manager.removeUser(user, EzyUserRemoveReason.EXIT_APP);
    manager.addUser(user);
    manager.removeUser(user, EzyUserRemoveReason.EXIT_APP);
}
Also used : EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager) EzyAppUserDelegate(com.tvd12.ezyfoxserver.delegate.EzyAppUserDelegate) BaseTest(com.tvd12.test.base.BaseTest) Test(org.testng.annotations.Test)

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