Search in sources :

Example 26 with Conversation

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);
}
Also used : User(codeu.model.data.User) ArrayList(java.util.ArrayList) Conversation(codeu.model.data.Conversation) Test(org.junit.Test)

Example 27 with Conversation

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);
}
Also used : Message(codeu.model.data.Message) ArrayList(java.util.ArrayList) Conversation(codeu.model.data.Conversation) Test(org.junit.Test)

Example 28 with Conversation

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);
}
Also used : User(codeu.model.data.User) ArrayList(java.util.ArrayList) Conversation(codeu.model.data.Conversation) Test(org.junit.Test)

Example 29 with Conversation

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");
}
Also used : User(codeu.model.data.User) Conversation(codeu.model.data.Conversation) Test(org.junit.Test)

Example 30 with 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);
}
Also used : Conversation(codeu.model.data.Conversation) Test(org.junit.Test)

Aggregations

Conversation (codeu.model.data.Conversation)74 Test (org.junit.Test)46 User (codeu.model.data.User)43 Message (codeu.model.data.Message)29 ArrayList (java.util.ArrayList)16 UUID (java.util.UUID)16 Activity (codeu.model.data.Activity)6 Instant (java.time.Instant)6 HashSet (java.util.HashSet)3 PersistentDataStoreException (codeu.model.store.persistence.PersistentDataStoreException)2 ImageStorage (codeu.utils.ImageStorage)2 Entity (com.google.appengine.api.datastore.Entity)2 PreparedQuery (com.google.appengine.api.datastore.PreparedQuery)2 Query (com.google.appengine.api.datastore.Query)2 OutputSettings (org.jsoup.nodes.Document.OutputSettings)2 ConversationFilterer (codeu.utils.ConversationFilterer)1 MessageFilterer (codeu.utils.MessageFilterer)1 DateTimeException (java.time.DateTimeException)1 ZonedDateTime (java.time.ZonedDateTime)1 List (java.util.List)1