Search in sources :

Example 6 with EzySession

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);
}
Also used : EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzySimpleSocketDisconnection(com.tvd12.ezyfoxserver.socket.EzySimpleSocketDisconnection) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) BaseCoreTest(com.tvd12.ezyfoxserver.testing.BaseCoreTest) Test(org.testng.annotations.Test)

Example 7 with EzySession

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);
}
Also used : MyTestUser(com.tvd12.ezyfoxserver.testing.MyTestUser) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) BaseCoreTest(com.tvd12.ezyfoxserver.testing.BaseCoreTest) Test(org.testng.annotations.Test)

Example 8 with EzySession

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);
}
Also used : EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) ArrayList(java.util.ArrayList) EzyAppResponse(com.tvd12.ezyfoxserver.command.EzyAppResponse) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 9 with EzySession

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));
}
Also used : EzySimplePackage(com.tvd12.ezyfoxserver.socket.EzySimplePackage) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzyObjectToStringEncoder(com.tvd12.ezyfox.codec.EzyObjectToStringEncoder) EzyWsResponseApi(com.tvd12.ezyfoxserver.api.EzyWsResponseApi) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test)

Example 10 with EzySession

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());
}
Also used : EzySimpleResponse(com.tvd12.ezyfoxserver.response.EzySimpleResponse) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyPackage(com.tvd12.ezyfoxserver.response.EzyPackage) EzySimpleSettings(com.tvd12.ezyfoxserver.setting.EzySimpleSettings) EzyResponse(com.tvd12.ezyfoxserver.response.EzyResponse) EzyResponseApi(com.tvd12.ezyfoxserver.api.EzyResponseApi) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzySendResponseImpl(com.tvd12.ezyfoxserver.command.impl.EzySendResponseImpl) Test(org.testng.annotations.Test)

Aggregations

EzySession (com.tvd12.ezyfoxserver.entity.EzySession)112 Test (org.testng.annotations.Test)92 EzyArray (com.tvd12.ezyfox.entity.EzyArray)33 EzyResponseApi (com.tvd12.ezyfoxserver.api.EzyResponseApi)26 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)25 EzyResponse (com.tvd12.ezyfoxserver.response.EzyResponse)25 BaseTest (com.tvd12.test.base.BaseTest)25 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)15 EzySimpleServerContext (com.tvd12.ezyfoxserver.context.EzySimpleServerContext)14 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)13 EzyUser (com.tvd12.ezyfoxserver.entity.EzyUser)13 EzySimpleLoginRequest (com.tvd12.ezyfoxserver.request.EzySimpleLoginRequest)13 EzyLoginController (com.tvd12.ezyfoxserver.controller.EzyLoginController)12 EzySimpleSettings (com.tvd12.ezyfoxserver.setting.EzySimpleSettings)11 EzySendResponseImpl (com.tvd12.ezyfoxserver.command.impl.EzySendResponseImpl)8 EzyHandshakeController (com.tvd12.ezyfoxserver.controller.EzyHandshakeController)8 EzyHandshakeParams (com.tvd12.ezyfoxserver.request.EzyHandshakeParams)8 EzySimpleResponse (com.tvd12.ezyfoxserver.response.EzySimpleResponse)8 GreetResponse (com.tvd12.ezyfoxserver.support.test.data.GreetResponse)8 BaseCoreTest (com.tvd12.ezyfoxserver.testing.BaseCoreTest)8