Search in sources :

Example 11 with EzySimpleUser

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

the class EzyPluginInfoControllerTest method test.

@Test
public void test() {
    EzyPluginInfoController controller = new EzyPluginInfoController();
    EzyServerContext serverContext = mock(EzyServerContext.class);
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    when(serverContext.getZoneContext(1)).thenReturn(zoneContext);
    EzySimplePluginInfoRequest request = new EzySimplePluginInfoRequest();
    EzyAbstractSession session = spy(EzyAbstractSession.class);
    EzySimpleUser user = new EzySimpleUser();
    user.setZoneId(1);
    request.setSession(session);
    request.setUser(user);
    EzyArray data = EzyEntityFactory.newArrayBuilder().append("test").build();
    request.deserializeParams(data);
    controller.handle(serverContext, request);
    EzyPluginContext pluginContext = mock(EzyPluginContext.class);
    EzySimplePlugin plugin = new EzySimplePlugin();
    EzySimplePluginSetting pluginSetting = new EzySimplePluginSetting();
    plugin.setSetting(pluginSetting);
    when(pluginContext.getPlugin()).thenReturn(plugin);
    when(zoneContext.getPluginContext("test")).thenReturn(pluginContext);
    controller.handle(serverContext, request);
}
Also used : EzySimplePluginInfoRequest(com.tvd12.ezyfoxserver.request.EzySimplePluginInfoRequest) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyPluginContext(com.tvd12.ezyfoxserver.context.EzyPluginContext) EzyPluginInfoController(com.tvd12.ezyfoxserver.controller.EzyPluginInfoController) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzySimplePlugin(com.tvd12.ezyfoxserver.EzySimplePlugin) EzySimplePluginSetting(com.tvd12.ezyfoxserver.setting.EzySimplePluginSetting) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 12 with EzySimpleUser

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

the class EzySessionAdapterTest method test.

@Test
public void test() {
    EzySessionDelegate delegate = new EzyAbstractSessionDelegate() {
    };
    delegate.onSessionLoggedIn(new EzySimpleUser());
}
Also used : EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzySessionDelegate(com.tvd12.ezyfoxserver.delegate.EzySessionDelegate) EzyAbstractSessionDelegate(com.tvd12.ezyfoxserver.delegate.EzyAbstractSessionDelegate) BaseTest(com.tvd12.test.base.BaseTest) Test(org.testng.annotations.Test)

Example 13 with EzySimpleUser

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

the class EzySimpleUserManagerTest method fromConstructorTest.

@Test
public void fromConstructorTest() {
    EzySimpleUserManager manager = new EzySimpleUserManager(1);
    assert manager.getMaxUsers() == 1;
    assert manager.available();
    EzySimpleUser user1 = new EzySimpleUser();
    user1.setName("user1");
    manager.addUser(user1);
    try {
        EzySimpleUser user2 = new EzySimpleUser();
        user2.setName("user2");
        manager.addUser(user2);
    } catch (Exception e) {
        assert e instanceof EzyMaxUserException;
    }
    assert !manager.available();
    manager.getLock(user1.getName());
    manager.clear();
    manager.destroy();
}
Also used : EzyMaxUserException(com.tvd12.ezyfoxserver.exception.EzyMaxUserException) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzySimpleUserManager(com.tvd12.ezyfoxserver.wrapper.EzySimpleUserManager) EzyMaxUserException(com.tvd12.ezyfoxserver.exception.EzyMaxUserException) Test(org.testng.annotations.Test)

Example 14 with EzySimpleUser

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

the class EzySimpleUserManagerTest method fromBuilderTest.

@Test
public void fromBuilderTest() {
    int maxUsers = RandomUtil.randomSmallInt() + 3;
    EzySimpleUserManager manager = (EzySimpleUserManager) EzySimpleUserManager.builder().maxUsers(maxUsers).build();
    assert manager.getMaxUsers() == maxUsers;
    assert manager.available();
    EzySimpleUser user1 = new EzySimpleUser();
    user1.setName("user1");
    manager.addUser(user1);
    try {
        EzySimpleUser user2 = new EzySimpleUser();
        user2.setName("user2");
        manager.addUser(user2);
    } catch (Exception e) {
        assert e instanceof EzyMaxUserException;
    }
    assert manager.available();
    manager.getLock(user1.getName());
    manager.clear();
    manager.destroy();
}
Also used : EzyMaxUserException(com.tvd12.ezyfoxserver.exception.EzyMaxUserException) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzySimpleUserManager(com.tvd12.ezyfoxserver.wrapper.EzySimpleUserManager) EzyMaxUserException(com.tvd12.ezyfoxserver.exception.EzyMaxUserException) Test(org.testng.annotations.Test)

Example 15 with EzySimpleUser

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

the class EzyZoneUserManagerImplTest method test.

@Test
public void test() throws Exception {
    EzyServerContext serverContext = mock(EzyServerContext.class);
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    when(serverContext.getZoneContext(1)).thenReturn(zoneContext);
    TestBlockingSocketUserRemovalQueue queue = new TestBlockingSocketUserRemovalQueue();
    EzySimpleUserDelegate userDelegate = new EzySimpleUserDelegate(serverContext, queue);
    EzyZoneUserManagerImpl manager = (EzyZoneUserManagerImpl) EzyZoneUserManagerImpl.builder().idleValidationDelay(10).idleValidationInterval(10).idleValidationThreadPoolSize(1).userDelegate(userDelegate).maxIdleTime(10).build();
    EzyAbstractSession session1 = mock(EzyAbstractSession.class);
    EzySimpleUser user1 = new EzySimpleUser();
    user1.setZoneId(1);
    user1.setName("user1");
    user1.setMaxIdleTime(0);
    manager.addUser(session1, user1);
    assert manager.getUserCount() == 1;
    assert manager.getUser(session1) == user1;
    EzyAbstractSession session12 = mock(EzyAbstractSession.class);
    manager.bind(session12, user1);
    manager.unmapSessionUser(session12, EzyUserRemoveReason.EXIT_APP);
    assert manager.getUserCount() == 0;
    EzyAbstractSession session2 = mock(EzyAbstractSession.class);
    EzySimpleUser user2 = new EzySimpleUser();
    user2.setZoneId(1);
    user2.setName("user2");
    user2.setMaxIdleTime(Integer.MAX_VALUE);
    user2.addSession(session2);
    manager.addUser(session2, user2);
    assert manager.getUserCount() == 1;
    newAndAddIdleUser(manager);
    assert manager.getUserCount() == 2;
    newAndAddIdleUser(manager);
    assert manager.getUserCount() == 3;
    manager.start();
    Thread.sleep(300);
    assert manager.getUserCount() == 1;
    manager.destroy();
}
Also used : EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzySimpleUserDelegate(com.tvd12.ezyfoxserver.delegate.EzySimpleUserDelegate) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyZoneUserManagerImpl(com.tvd12.ezyfoxserver.wrapper.impl.EzyZoneUserManagerImpl) TestBlockingSocketUserRemovalQueue(com.tvd12.ezyfoxserver.testing.socket.TestBlockingSocketUserRemovalQueue) 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