use of com.tvd12.ezyfoxserver.entity.EzyAbstractSession in project ezyfox-server by youngmonkeys.
the class EzyProxyResponseApiTest method test.
@Test
public void test() throws Exception {
EzyCodecFactory codecFactory = mock(EzyCodecFactory.class);
EzyProxyResponseApi api = new EzyProxyResponseApi(codecFactory);
EzyPackage pack = mock(EzyPackage.class);
api.response(pack);
EzyObjectToByteEncoder byteEncoder = mock(EzyObjectToByteEncoder.class);
EzyObjectToStringEncoder stringEncoder = mock(EzyObjectToStringEncoder.class);
when(codecFactory.newEncoder(EzyConnectionType.SOCKET)).thenReturn(byteEncoder);
when(codecFactory.newEncoder(EzyConnectionType.WEBSOCKET)).thenReturn(stringEncoder);
api = new EzyProxyResponseApi(codecFactory);
api.response(pack);
api.response(pack, true);
EzyImmediateDeliver immediateDeliver = mock(EzyImmediateDeliver.class);
EzyAbstractSession session = spy(EzyAbstractSession.class);
session.setImmediateDeliver(immediateDeliver);
when(pack.getRecipients(any(EzyConstant.class))).thenReturn(Lists.newArrayList(session));
api.response(pack);
api.response(pack, true);
}
use of com.tvd12.ezyfoxserver.entity.EzyAbstractSession 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.entity.EzyAbstractSession 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.entity.EzyAbstractSession in project ezyfox-server by youngmonkeys.
the class EzySocketWriterTest method packageQueueNullCaseTest.
@Test
public void packageQueueNullCaseTest() {
EzySessionTicketsQueue sessionTicketsQueue = new EzyBlockingSessionTicketsQueue();
EzySocketWriterGroupFetcher writerGroupFetcher = mock(EzySocketWriterGroupFetcher.class);
EzySocketWriterGroup writerGroup = mock(EzySocketWriterGroup.class);
when(writerGroupFetcher.getWriterGroup(any(EzySession.class))).thenReturn(writerGroup);
EzySocketWriter socketWriter = new EzySocketWriter();
socketWriter.setSessionTicketsQueue(sessionTicketsQueue);
socketWriter.setWriterGroupFetcher(writerGroupFetcher);
EzyAbstractSession session = spy(EzyAbstractSession.class);
session.setActivated(true);
session.setSessionTicketsQueue(sessionTicketsQueue);
session.setPacketQueue(null);
sessionTicketsQueue.add(session);
socketWriter.handleEvent();
}
use of com.tvd12.ezyfoxserver.entity.EzyAbstractSession in project ezyfox-server by youngmonkeys.
the class EzySocketWriterTest method processSessionTicketsQueue0ExceptionCase.
@Test
public void processSessionTicketsQueue0ExceptionCase() {
EzySessionTicketsQueue sessionTicketsQueue = new EzyBlockingSessionTicketsQueue();
EzySocketWriterGroupFetcher writerGroupFetcher = mock(EzySocketWriterGroupFetcher.class);
when(writerGroupFetcher.getWriterGroup(any(EzySession.class))).thenThrow(new IllegalArgumentException());
EzySocketWriter socketWriter = new EzySocketWriter();
socketWriter.setSessionTicketsQueue(sessionTicketsQueue);
socketWriter.setWriterGroupFetcher(writerGroupFetcher);
EzyPacketQueue packetQueue = new EzyNonBlockingPacketQueue();
EzyPacket packet = new EzySimplePacket();
packetQueue.add(packet);
EzyAbstractSession session = spy(EzyAbstractSession.class);
session.setActivated(true);
session.setSessionTicketsQueue(sessionTicketsQueue);
session.setPacketQueue(packetQueue);
sessionTicketsQueue.add(session);
socketWriter.handleEvent();
}
Aggregations