use of codeu.model.data.User in project codeu-2018-team12 by codeu-2018-team12.
the class ChatServletTest method testDoPost_StoresActivity.
@Test
public void testDoPost_StoresActivity() 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", "testbiography", Instant.now());
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);
Mockito.when(mockRequest.getParameter("message")).thenReturn("Test message.");
Activity activity = new Activity(UUID.randomUUID(), fakeUser.getId(), fakeConversation.getId(), Instant.now(), "sentMessage", "test_activity_message" + "Test message.");
mockActivityStore.addActivity(activity);
Mockito.when(mockActivityStore.getActivityWithId(activity.getId())).thenReturn(activity);
chatServlet.doPost(mockRequest, mockResponse);
ArgumentCaptor<Message> messageArgumentCaptor = ArgumentCaptor.forClass(Message.class);
Mockito.verify(mockMessageStore).addMessage(messageArgumentCaptor.capture());
Mockito.verify(mockActivityStore).addActivity(activity);
Assert.assertEquals("Test message.", messageArgumentCaptor.getValue().getContent());
Assert.assertTrue(mockActivityStore.getActivityWithId(activity.getId()).getActivityMessage().contains("Test message."));
Mockito.verify(mockResponse).sendRedirect("/chat/test_conversation");
}
use of codeu.model.data.User in project codeu-2018-team12 by codeu-2018-team12.
the class ChatServletTest method testDoPost_UserNotJoinedConversation.
@Test
public void testDoPost_UserNotJoinedConversation() 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());
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);
chatServlet.doPost(mockRequest, mockResponse);
Mockito.verify(mockMessageStore, Mockito.never()).addMessage(Mockito.any(Message.class));
Mockito.verify(mockResponse).sendRedirect("/chat/test_conversation");
}
use of codeu.model.data.User in project codeu-2018-team12 by codeu-2018-team12.
the class ConversationServletTest method testDoPost_EmptyConversationName.
@Test
public void testDoPost_EmptyConversationName() throws IOException, ServletException {
Mockito.when(mockRequest.getParameter("conversationTitle")).thenReturn("");
Mockito.when(mockSession.getAttribute("user")).thenReturn("test_username");
User fakeUser = new User(UUID.randomUUID(), "test_username", "password", "test biography", Instant.now());
Mockito.when(mockUserStore.getUser("test_username")).thenReturn(fakeUser);
conversationServlet.doPost(mockRequest, mockResponse);
Mockito.verify(mockConversationStore, Mockito.never()).addConversation(Mockito.any(Conversation.class));
Mockito.verify(mockRequest).setAttribute("error", "Please specify a name for this chat.");
Mockito.verify(mockRequestDispatcher).forward(mockRequest, mockResponse);
}
use of codeu.model.data.User in project codeu-2018-team12 by codeu-2018-team12.
the class ConversationServletTest method testDoPost_StoreActivities.
@Test
public void testDoPost_StoreActivities() throws IOException, ServletException {
Mockito.when(mockRequest.getParameter("conversationTitle")).thenReturn("test_conversation");
Mockito.when(mockSession.getAttribute("user")).thenReturn("test_username");
User fakeUser = new User(UUID.randomUUID(), "test_username", "password", "test biography", Instant.now());
Mockito.when(mockUserStore.getUser("test_username")).thenReturn(fakeUser);
Mockito.when(mockConversationStore.isTitleTaken("test_conversation")).thenReturn(false);
conversationServlet.doPost(mockRequest, mockResponse);
ArgumentCaptor<Conversation> conversationArgumentCaptor = ArgumentCaptor.forClass(Conversation.class);
Mockito.verify(mockConversationStore).addConversation(conversationArgumentCaptor.capture());
Assert.assertEquals(conversationArgumentCaptor.getValue().getTitle(), "test_conversation");
ArgumentCaptor<Activity> activityArgumentCaptor = ArgumentCaptor.forClass(Activity.class);
Mockito.verify(mockActivityStore).addActivity(activityArgumentCaptor.capture());
Assert.assertEquals(activityArgumentCaptor.getValue().getActivityType(), "createdConvo");
Mockito.verify(mockResponse).sendRedirect("/chat/test_conversation");
}
use of codeu.model.data.User in project codeu-2018-team12 by codeu-2018-team12.
the class ConversationServletTest method testDoPost_ConversationNameTaken.
@Test
public void testDoPost_ConversationNameTaken() throws IOException, ServletException {
Mockito.when(mockRequest.getParameter("conversationTitle")).thenReturn("test_conversation");
Mockito.when(mockSession.getAttribute("user")).thenReturn("test_username");
User fakeUser = new User(UUID.randomUUID(), "test_username", "password", "test biography", Instant.now());
Mockito.when(mockUserStore.getUser("test_username")).thenReturn(fakeUser);
Mockito.when(mockConversationStore.isTitleTaken("test_conversation")).thenReturn(true);
conversationServlet.doPost(mockRequest, mockResponse);
Mockito.verify(mockConversationStore, Mockito.never()).addConversation(Mockito.any(Conversation.class));
Mockito.verify(mockResponse).sendRedirect("/chat/test_conversation");
}
Aggregations