use of codeu.model.data.Conversation in project codeu-2018-team12 by codeu-2018-team12.
the class ChatServletTest method testDoGet.
@Test
public void testDoGet() throws IOException, ServletException {
Mockito.when(mockRequest.getRequestURI()).thenReturn("/chat/test_conversation");
UUID fakeConversationId = UUID.randomUUID();
Conversation fakeConversation = new Conversation(fakeConversationId, UUID.randomUUID(), "test_conversation", Instant.now());
Mockito.when(mockConversationStore.getConversationWithTitle("test_conversation")).thenReturn(fakeConversation);
List<Message> fakeMessageList = new ArrayList<>();
fakeMessageList.add(new Message(UUID.randomUUID(), fakeConversationId, UUID.randomUUID(), "test message", Instant.now(), false));
Mockito.when(mockMessageStore.getMessagesInConversation(fakeConversationId)).thenReturn(fakeMessageList);
chatServlet.doGet(mockRequest, mockResponse);
Mockito.verify(mockRequest).setAttribute("conversation", fakeConversation);
Mockito.verify(mockRequest).setAttribute("messages", fakeMessageList);
Mockito.verify(mockRequestDispatcher).forward(mockRequest, mockResponse);
}
use of codeu.model.data.Conversation in project codeu-2018-team12 by codeu-2018-team12.
the class ChatServletTest method testDoPost_UserJoinedConversation.
@Test
public void testDoPost_UserJoinedConversation() throws IOException, ServletException {
Mockito.when(mockRequest.getRequestURI()).thenReturn("/chat/test_conversation");
Mockito.when(mockSession.getAttribute("user")).thenReturn("test_username");
User fakeUser = new User(UUID.randomUUID(), "test_username", "password", "testbio", Instant.now(), "codeUChatTestEmail@gmail.com");
Mockito.when(mockUserStore.getUser("test_username")).thenReturn(fakeUser);
Conversation fakeConversation = new Conversation(UUID.randomUUID(), UUID.randomUUID(), "test_conversation", Instant.now());
Mockito.when(mockConversationStore.getConversationWithTitle("test_conversation")).thenReturn(fakeConversation);
fakeConversation.getConversationUsers().add(fakeUser.getId());
Mockito.when(mockRequest.getParameter("submitText")).thenReturn("submitText");
Mockito.when(mockRequest.getParameter("message")).thenReturn("Test message.");
chatServlet.doPost(mockRequest, mockResponse);
ArgumentCaptor<Message> messageArgumentCaptor = ArgumentCaptor.forClass(Message.class);
Mockito.verify(mockMessageStore).addMessage(messageArgumentCaptor.capture());
Assert.assertEquals("Test message.", messageArgumentCaptor.getValue().getContent());
Mockito.verify(mockResponse).sendRedirect("/chat/test_conversation");
}
use of codeu.model.data.Conversation in project codeu-2018-team12 by codeu-2018-team12.
the class ChatServletTest method testDoPost_CleansHtmlContent.
@Test
public void testDoPost_CleansHtmlContent() throws IOException, ServletException {
Mockito.when(mockRequest.getRequestURI()).thenReturn("/chat/test_conversation");
Mockito.when(mockSession.getAttribute("user")).thenReturn("test_username");
User fakeUser = new User(UUID.randomUUID(), "test_username", "password", "test biography", Instant.now(), "codeUChatTestEmail@gmail.com");
Mockito.when(mockUserStore.getUser("test_username")).thenReturn(fakeUser);
Conversation fakeConversation = new Conversation(UUID.randomUUID(), UUID.randomUUID(), "test_conversation", Instant.now());
Mockito.when(mockConversationStore.getConversationWithTitle("test_conversation")).thenReturn(fakeConversation);
fakeConversation.getConversationUsers().add(fakeUser.getId());
Mockito.when(mockRequest.getParameter("submitText")).thenReturn("submitText");
Mockito.when(mockRequest.getParameter("message")).thenReturn("Contains <b>html</b> and <script>JavaScript</script> content.");
chatServlet.doPost(mockRequest, mockResponse);
ArgumentCaptor<Message> messageArgumentCaptor = ArgumentCaptor.forClass(Message.class);
Mockito.verify(mockMessageStore).addMessage(messageArgumentCaptor.capture());
Assert.assertEquals("Contains html and content.", messageArgumentCaptor.getValue().getContent());
Mockito.verify(mockResponse).sendRedirect("/chat/test_conversation");
}
use of codeu.model.data.Conversation in project codeu-2018-team12 by codeu-2018-team12.
the class DirectMessageServletTest method testDoPost.
@Test
public void testDoPost() throws IOException, ServletException {
Mockito.when(mockRequest.getRequestURI()).thenReturn("/direct/test_user");
Mockito.when(mockRequest.getSession().getAttribute("user")).thenReturn("test_user2");
User testloggedInUser = new User(UUID.randomUUID(), "test_user2", null, null, Instant.now(), null);
Mockito.when(mockUserStore.getUser("test_user2")).thenReturn(testloggedInUser);
User testUser = new User(UUID.randomUUID(), "test_user", "password", null, Instant.now(), "codeUChatTestEmail@gmail.com");
Mockito.when(mockUserStore.getUser("test_user")).thenReturn(testUser);
Conversation fakeConversation = new Conversation(UUID.randomUUID(), UUID.randomUUID(), "direct:test_user-test_user2", Instant.now());
Mockito.when(mockConversationStore.getConversationWithTitle("direct:test_user-test_user2")).thenReturn(fakeConversation);
fakeConversation.getConversationUsers().add(testloggedInUser.getId());
Mockito.when(mockRequest.getParameter("submitText")).thenReturn("submitText");
Mockito.when(mockRequest.getParameter("message")).thenReturn("Test message.");
directMessageServlet.doPost(mockRequest, mockResponse);
ArgumentCaptor<Message> messageArgumentCaptor = ArgumentCaptor.forClass(Message.class);
Mockito.verify(mockMessageStore).addMessage(messageArgumentCaptor.capture());
Assert.assertEquals("Test message.", messageArgumentCaptor.getValue().getContent());
Mockito.verify(mockResponse).sendRedirect("/direct/test_user");
}
Aggregations