use of codeu.model.data.Conversation in project codeu-2018-team12 by codeu-2018-team12.
the class SearchServletTest method testDoGetConversation.
@Test
public void testDoGetConversation() throws IOException, ServletException {
Mockito.when(mockRequest.getParameter("searchconvo")).thenReturn("test");
List<Conversation> fakeConversationList = new ArrayList<>();
fakeConversationList.add(new Conversation(UUID.randomUUID(), UUID.randomUUID(), "test_conversation", Instant.now()));
Mockito.when(mockRequest.getSession().getAttribute("user")).thenReturn("testuser");
User testUser = new User(UUID.randomUUID(), "testuser", null, null, Instant.now(), null);
Mockito.when(mockUserStore.getUser("testuser")).thenReturn(testUser);
Mockito.when(mockConversationStore.getAllPermittedConversations(testUser.getId())).thenReturn(fakeConversationList);
searchServlet.doGet(mockRequest, mockResponse);
Mockito.verify(mockRequest).setAttribute("conversations", fakeConversationList);
Mockito.verify(mockRequestDispatcher).forward(mockRequest, mockResponse);
}
use of codeu.model.data.Conversation in project codeu-2018-team12 by codeu-2018-team12.
the class SearchServletTest method testDoGetMessage.
@Test
public void testDoGetMessage() throws IOException, ServletException {
Mockito.when(mockRequest.getParameter("searchmessage")).thenReturn("test");
Conversation fakeConversation = new Conversation(UUID.randomUUID(), UUID.randomUUID(), "test_conversation", Instant.now());
Mockito.when(mockRequest.getParameter("searchbutton")).thenReturn("test_conversation");
Mockito.when(mockConversationStore.getConversationWithTitle("test_conversation")).thenReturn(fakeConversation);
List<Message> fakeMessageList = new ArrayList<Message>();
fakeMessageList.add(new Message(UUID.randomUUID(), fakeConversation.getId(), UUID.randomUUID(), "test", Instant.now(), true));
Mockito.when(mockMessageStore.getMessagesInConversation(fakeConversation.getId())).thenReturn(fakeMessageList);
searchServlet.doGet(mockRequest, mockResponse);
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 ConversationServletTest method testDoGet.
@Test
public void testDoGet() throws IOException, ServletException {
List<Conversation> fakeConversationList = new ArrayList<>();
fakeConversationList.add(new Conversation(UUID.randomUUID(), UUID.randomUUID(), "test_conversation", Instant.now()));
Mockito.when(mockRequest.getSession().getAttribute("user")).thenReturn("testuser");
User testUser = new User(UUID.randomUUID(), "testuser", null, null, Instant.now(), null);
Mockito.when(mockUserStore.getUser("testuser")).thenReturn(testUser);
Mockito.when(sort(mockConversationStore.getAllPermittedConversations(testUser.getId()))).thenReturn(fakeConversationList);
conversationServlet.doGet(mockRequest, mockResponse);
Mockito.verify(mockRequest).setAttribute("conversations", fakeConversationList);
Mockito.verify(mockRequestDispatcher).forward(mockRequest, mockResponse);
}
use of codeu.model.data.Conversation in project codeu-2018-team12 by codeu-2018-team12.
the class ConversationServletTest method testDoPost_NewConversation.
@Test
public void testDoPost_NewConversation() 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(), "codeUChatTestEmail@gmail.com");
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");
Mockito.verify(mockResponse).sendRedirect("/chat/test_conversation");
}
use of codeu.model.data.Conversation in project codeu-2018-team12 by codeu-2018-team12.
the class ConversationStoreTest method testGetConversationWithTitle_notFound.
@Test
public void testGetConversationWithTitle_notFound() {
Conversation resultConversation = conversationStore.getConversationWithTitle("unfound_title");
Assert.assertNull(resultConversation);
}
Aggregations