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);
}
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());
}
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();
}
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();
}
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();
}
Aggregations