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