use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.
the class EzyDisconnectUserImplTest method test.
@Test
public void test() {
// given
String token = RandomUtil.randomShortAlphabetString();
EzySession session = newSession();
session.setToken(token);
String username = RandomUtil.randomShortAlphabetString();
EzySimpleUser user = newUser();
user.setName(username);
user.addSession(session);
// when
EzySimpleSocketDisconnection disconnection = new EzySimpleSocketDisconnection(session, EzyDisconnectReason.ADMIN_BAN);
// when
Asserts.assertEquals(user.getName(), username);
Asserts.assertEquals(user.getSession(), session);
Asserts.assertEquals(session.getToken(), token);
Asserts.assertEquals(disconnection.getSession(), session);
Asserts.assertEquals(disconnection.getDisconnectReason(), EzyDisconnectReason.ADMIN_BAN);
}
use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.
the class EzyDisconnectUserImplTest method test2.
@Test
public void test2() {
MyTestUser user = new MyTestUser();
user.setName("dungtv");
EzySession session = newSession();
session.setToken("abc");
user.addSession(session);
}
use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.
the class EzyAppResponseImplTest method testPerformance.
@Test
public void testPerformance() {
EzyAppResponse response = newResponse();
EzyUser user1 = new ExUser("user1");
EzySession session1 = new ExSession();
EzySession session2 = new ExSession();
user1.addSession(session1);
user1.addSession(session2);
EzyUser user2 = new ExUser("user2");
EzySession session3 = new ExSession();
EzySession session4 = new ExSession();
user2.addSession(session3);
user2.addSession(session4);
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection") List<Object> list = new ArrayList<>();
long time = Performance.create().loop(1000000).test(() -> {
response.users(new EzyUser[] { user1, user2 }, false);
list.add(user1);
list.add(user2);
list.add(Arrays.asList(user1, user2));
list.addAll(user1.getSessions());
list.addAll(user2.getSessions());
response.user(user1);
response.user(user2);
}).getTime();
System.out.println("time = " + time);
}
use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.
the class EzyWsResponseApiTest method responseTest.
@Test
public void responseTest() throws Exception {
// given
EzyObjectToStringEncoder encoder = mock(EzyObjectToStringEncoder.class);
EzyWsResponseApi sut = new EzyWsResponseApi(encoder);
EzyArray data = EzyEntityFactory.EMPTY_ARRAY;
EzySimplePackage pack = new EzySimplePackage();
pack.setData(data);
pack.setEncrypted(true);
pack.setTransportType(EzyTransportType.TCP);
int sessionCount = RandomUtil.randomSmallInt() + 1;
List<EzySession> sessions = RandomUtil.randomList(sessionCount, () -> {
EzySession session = mock(EzySession.class);
when(session.getConnectionType()).thenReturn(EzyConnectionType.WEBSOCKET);
return session;
});
pack.addRecipients(sessions);
// when
sut.response(pack);
// then
verify(encoder, times(1)).encode(data, String.class);
verify(encoder, times(0)).toMessageContent(data);
verify(encoder, times(0)).encryptMessageContent(any(byte[].class), any(byte[].class));
}
use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.
the class EzySendResponseImplTest method responseOneSuccessButIsPong.
@Test
public void responseOneSuccessButIsPong() throws Exception {
// given
EzySimpleSettings settings = new EzySimpleSettings();
settings.setDebug(true);
EzyResponseApi responseApi = spy(EzyAbstractResponseApi.class);
EzySimpleServer server = new EzySimpleServer();
server.setResponseApi(responseApi);
server.setSettings(settings);
EzySendResponseImpl cmd = new EzySendResponseImpl(server);
EzyResponse response = new EzySimpleResponse(EzyCommand.PONG);
EzySession recipient = spy(EzyAbstractSession.class);
// when
cmd.execute(response, recipient, false, false, EzyTransportType.TCP);
// then
verify(responseApi, times(1)).response(any(EzyPackage.class), anyBoolean());
}
Aggregations