use of com.tvd12.ezyfoxserver.command.EzyResponse in project ezyfox-server by youngmonkeys.
the class EzySendResponseImplTest method responseMultiSuccessCaseButNotDebug.
@Test
public void responseMultiSuccessCaseButNotDebug() throws Exception {
// when
EzySimpleSettings settings = new EzySimpleSettings();
settings.setDebug(false);
EzyResponseApi responseApi = mock(EzyResponseApi.class);
EzySimpleServer server = new EzySimpleServer();
server.setResponseApi(responseApi);
server.setSettings(settings);
EzySendResponseImpl cmd = new EzySendResponseImpl(server);
EzyResponse response = new EzySimpleResponse(EzyCommand.APP_REQUEST);
EzySession recipient = spy(EzyAbstractSession.class);
List<EzySession> recipients = Collections.singletonList(recipient);
// when
cmd.execute(response, recipients, false, false, EzyTransportType.TCP);
// then
verify(responseApi, times(1)).response(any(EzyPackage.class), anyBoolean());
}
use of com.tvd12.ezyfoxserver.command.EzyResponse in project ezyfox-server by youngmonkeys.
the class EzySendResponseImplTest method responseMultiErrorTest.
@Test
public void responseMultiErrorTest() throws Exception {
// given
EzySimpleSettings settings = new EzySimpleSettings();
settings.setDebug(true);
EzyResponseApi responseApi = mock(EzyResponseApi.class);
doThrow(new IllegalArgumentException()).when(responseApi).response(any(EzyPackage.class), anyBoolean());
EzySimpleServer server = new EzySimpleServer();
server.setResponseApi(responseApi);
server.setSettings(settings);
EzySendResponseImpl cmd = new EzySendResponseImpl(server);
EzyResponse response = new EzySimpleResponse(EzyCommand.APP_REQUEST);
EzySession recipient = spy(EzyAbstractSession.class);
List<EzySession> recipients = Collections.singletonList(recipient);
// when
cmd.execute(response, recipients, false, false, EzyTransportType.TCP);
// then
verify(responseApi, times(1)).response(any(EzyPackage.class), anyBoolean());
}
use of com.tvd12.ezyfoxserver.command.EzyResponse in project ezyfox-server by youngmonkeys.
the class EzySimpleServerContextTest method sendNowTest.
@Test
public void sendNowTest() {
// given
EzyResponse response = mock(EzyResponse.class);
EzySession recipient = mock(EzySession.class);
EzySendResponse sendResponse = mock(EzySendResponse.class);
doNothing().when(sendResponse).execute(response, recipient, false, true, EzyTransportType.TCP);
EzySimpleServerContext sut = new EzySimpleServerContext();
FieldUtil.setFieldValue(sut, "sendResponse", sendResponse);
// when
sut.sendNow(response, recipient);
// then
verify(sendResponse, times(1)).execute(response, recipient, false, true, EzyTransportType.TCP);
}
use of com.tvd12.ezyfoxserver.command.EzyResponse in project ezyfox-server by youngmonkeys.
the class EzySimpleZoneContextTest method normalCaseTest.
@SuppressWarnings("unchecked")
@Test
public void normalCaseTest() {
EzyServerContext parent = mock(EzyServerContext.class);
EzySimpleZoneSetting zoneSetting = new EzySimpleZoneSetting();
zoneSetting.setName("test");
EzySimpleZone zone = new EzySimpleZone();
zone.setUserManager(mock(EzyZoneUserManager.class));
zone.setSetting(zoneSetting);
EzySimpleZoneContext context = new EzySimpleZoneContext();
context.setZone(zone);
context.setParent(parent);
context.init();
assert context.get(EzyBroadcastEvent.class) != null;
Asserts.assertNull(context.get(Void.class));
context.addCommand(ExCommand.class, ExCommand::new);
assert context.cmd(ExCommand.class) != null;
Asserts.assertNull(context.cmd(Void.class));
context.broadcast(EzyEventType.SERVER_INITIALIZING, new EzySimpleServerInitializingEvent(), true);
context.broadcastApps(EzyEventType.SERVER_READY, new EzySimpleServerReadyEvent(), true);
EzySimpleUser user = new EzySimpleUser();
user.setName("dungtv");
EzyUserAccessAppEvent accessAppEvent = new EzySimpleUserAccessAppEvent(user);
context.broadcastApps(EzyEventType.USER_ACCESS_APP, accessAppEvent, "dungtv", true);
context.broadcastApps(EzyEventType.USER_ACCESS_APP, accessAppEvent, user, true);
context.broadcastApps(EzyEventType.USER_ACCESS_APP, accessAppEvent, EzyPredicates.ALWAYS_TRUE, true);
// noinspection EqualsWithItself
assert context.equals(context);
EzyZoneContext zoneContext2 = mock(EzyZoneContext.class);
EzySimpleZone zone2 = new EzySimpleZone();
when(zoneContext2.getZone()).thenReturn(zone2);
assert !zoneContext2.equals(context);
System.out.println(context.hashCode() + ", " + context.hashCode());
assert context.hashCode() == context.hashCode();
EzyResponse response = mock(EzyResponse.class);
EzySession recipient = spy(EzyAbstractSession.class);
context.send(response, recipient, false);
context.send(response, Lists.newArrayList(recipient), false);
context.stream(new byte[0], recipient);
context.stream(new byte[0], Lists.newArrayList(recipient));
context.destroy();
}
use of com.tvd12.ezyfoxserver.command.EzyResponse in project ezyfox-server by youngmonkeys.
the class EzyResponseTest method test.
@Test
public void test() {
// given
String username1 = RandomUtil.randomShortAlphabetString();
String username2 = RandomUtil.randomShortAlphabetString();
EzySession session1 = mock(EzySession.class);
EzySession session2 = mock(EzySession.class);
EzyUser user1 = mock(EzyUser.class);
when(user1.getSessions()).thenReturn(Collections.singletonList(session1));
EzyUser user2 = mock(EzyUser.class);
when(user2.getSessions()).thenReturn(Collections.singletonList(session2));
EzyAppUserManager userManager = mock(EzyAppUserManager.class);
when(userManager.getUser(username1)).thenReturn(user1);
when(userManager.getUser(username2)).thenReturn(user2);
EzyApplication app = mock(EzyApplication.class);
when(app.getUserManager()).thenReturn(userManager);
EzyAppContext appContext = mock(EzyAppContext.class);
when(appContext.getApp()).thenReturn(app);
// when
EzyResponse sut = new EzyAppResponseImpl(appContext).usernames(username1, username2).usernames(Arrays.asList(username1, username2));
// then
Set<EzySession> recipients = FieldUtil.getFieldValue(sut, "recipients");
Asserts.assertEquals(recipients, Sets.newHashSet(session1, session2));
verify(user1, times(2)).getSessions();
verify(user2, times(2)).getSessions();
verify(appContext, times(1)).getApp();
verify(app, times(1)).getUserManager();
verify(userManager, times(2)).getUser(username1);
verify(userManager, times(2)).getUser(username2);
}
Aggregations