@@ -0,0 +1,2380 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public%0D%0A * License, v. 2.0. If a copy of the MPL was not distributed with this%0D%0A * file, You can obtain one at http://mozilla.org/MPL/2.0/. */%0D%0Apackage org.ocelotds.web;%0D%0A%0D%0Aimport java.util.ArrayList;%0D%0Aimport java.util.Collection;%0D%0Aimport java.util.UUID;%0D%0Aimport javax.websocket.RemoteEndpoint;%0D%0Aimport javax.websocket.Session;%0D%0Aimport org.junit.Test;%0D%0Aimport static org.assertj.core.api.Assertions.*;%0D%0Aimport org.junit.runner.RunWith;%0D%0Aimport org.mockito.ArgumentCaptor;%0D%0Aimport org.mockito.InjectMocks;%0D%0Aimport org.mockito.Mock;%0D%0Aimport org.ocelotds.core.SessionManager;%0D%0Aimport org.ocelotds.messaging.MessageToClient;%0D%0Aimport static org.mockito.Mockito.*;%0D%0Aimport org.mockito.runners.MockitoJUnitRunner;%0D%0Aimport org.ocelotds.messaging.MessageType;%0D%0A%0D%0A/**%0D%0A *%0D%0A * @author hhfrancois%0D%0A */%0D%0A@RunWith(MockitoJUnitRunner.class)%0D%0Apublic class TopicsMessagesBroadcasterTest %7B%0D%0A%09%0D%0A%09@Mock%0D%0A%09private SessionManager sessionManager;%0D%0A%0D%0A%09@InjectMocks%0D%0A%09private TopicsMessagesBroadcaster messagesBroadcaster = new TopicsMessagesBroadcaster();%0D%0A%09%0D%0A%09/**%0D%0A%09 * Test of sendMessageToTopic method, of class TopicsMessagesBroadcaster.%0D%0A%09 */%0D%0A%09@Test%0D%0A%09public void testSendMessageToTopic() %7B%0D%0A%09%09System.out.println(%22sendMessageToTopic%22);%0D%0A%09%09Collection%3CSession%3E sessions = new ArrayList%3C%3E();%0D%0A%09%09Session session1 = mock(Session.class);%0D%0A%09%09RemoteEndpoint.Async async = mock(RemoteEndpoint.Async.class);%0D%0A%09%09when(session1.isOpen()).thenReturn(true);%0D%0A%09%09when(session1.getAsyncRemote()).thenReturn(async);%0D%0A%09%09sessions.add(session1);%0D%0A%09%09Session session2 = mock(Session.class);%0D%0A%09%09sessions.add(session2);%0D%0A%09%09when(sessionManager.getSessionsForTopic(anyString())).thenReturn(sessions);%0D%0A%0D%0A%09%09MessageToClient msg = new MessageToClient();%0D%0A%09%09String id = UUID.randomUUID().toString();%0D%0A%09%09msg.setId(id);%0D%0A%09%09String expResult = %22RESULT%22;%0D%0A%09%09msg.setResult(expResult);%0D%0A%09%09messagesBroadcaster.sendMessageToTopic(msg);%0D%0A%0D%0A%09%09ArgumentCaptor%3CMessageToClient%3E captureMsg = ArgumentCaptor.forClass(MessageToClient.class);%0D%0A%09%09verify(async).sendObject(captureMsg.capture());%0D%0A%09%09assertThat(captureMsg.getValue().getResponse()).isEqualTo(expResult);%0D%0A%09%09assertThat(captureMsg.getValue().getId()).isEqualTo(id);%0D%0A%09%09assertThat(captureMsg.getValue().getType()).isEqualTo(MessageType.MESSAGE);%0D%0A%09%09assertThat(captureMsg.getValue().getDeadline()).isEqualTo(0L);%0D%0A%0D%0A%09%7D%0D%0A%09%0D%0A%7D%0D%0A

test TopicsMessagesBroadcaster