Search in sources :

Example 61 with Conversation

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

Example 62 with Conversation

use of codeu.model.data.Conversation in project codeu-2018-team12 by codeu-2018-team12.

the class PersistentDataStoreTest method testSaveAndLoadConversations.

@Test
public void testSaveAndLoadConversations() throws PersistentDataStoreException {
    UUID idOne = UUID.randomUUID();
    User ownerOne = new User(UUID.randomUUID(), "test_username_one", "password one", "test biography", Instant.ofEpochMilli(1000), "codeUChatTestEmail@gmail.com");
    UUID ownerOneUUID = ownerOne.getId();
    UserStore.getInstance().addUser(ownerOne);
    String titleOne = "Test_Title";
    Instant creationOne = Instant.ofEpochMilli(1000);
    Conversation inputConversationOne = new Conversation(idOne, ownerOneUUID, titleOne, creationOne, true);
    // save
    ConversationStore.getInstance().addConversation(inputConversationOne);
    UUID idTwo = UUID.randomUUID();
    User ownerTwo = new User(UUID.randomUUID(), "test_username_one", "password one", "test biography", Instant.ofEpochMilli(1000), "codeUChatTestEmail@gmail.com");
    UUID ownerTwoUUID = ownerOne.getId();
    UserStore.getInstance().addUser(ownerTwo);
    String titleTwo = "Test_Title_Two";
    Instant creationTwo = Instant.ofEpochMilli(2000);
    Conversation inputConversationTwo = new Conversation(idTwo, ownerTwoUUID, titleTwo, creationTwo, false);
    // save
    ConversationStore.getInstance().addConversation(inputConversationTwo);
    // load
    List<Conversation> resultConversations = persistentDataStore.loadConversations();
    // confirm that what we saved matches what we loaded
    Conversation resultConversationOne = resultConversations.get(0);
    Assert.assertEquals(idOne, resultConversationOne.getId());
    Assert.assertEquals(ownerOneUUID, resultConversationOne.getOwnerId());
    Assert.assertEquals(titleOne, resultConversationOne.getTitle());
    Assert.assertEquals(creationOne, resultConversationOne.getCreationTime());
    Conversation resultConversationTwo = resultConversations.get(1);
    Assert.assertEquals(idTwo, resultConversationTwo.getId());
    Assert.assertEquals(ownerTwoUUID, resultConversationTwo.getOwnerId());
    Assert.assertEquals(titleTwo, resultConversationTwo.getTitle());
    Assert.assertEquals(creationTwo, resultConversationTwo.getCreationTime());
}
Also used : User(codeu.model.data.User) Instant(java.time.Instant) Conversation(codeu.model.data.Conversation) UUID(java.util.UUID) Test(org.junit.Test)

Example 63 with Conversation

use of codeu.model.data.Conversation in project codeu-2018-team12 by codeu-2018-team12.

the class ConversationServlet method doGet.

/**
 * This function fires when a user navigates to the conversations page. It gets all of the
 * conversations from the model and forwards to conversations.jsp for rendering the list.
 */
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    User loggedInUser = userStore.getUser((String) request.getSession().getAttribute("user"));
    List<Conversation> conversations = loggedInUser == null ? sort(conversationStore.getAllPublicConversations()) : sort(conversationStore.getAllPermittedConversations(loggedInUser.getId()));
    List<Conversation> directMessages = new ArrayList<Conversation>();
    for (Conversation convo : conversations) {
        if (convo.getTitle().startsWith("direct:")) {
            directMessages.add(convo);
        }
    }
    conversations.removeAll(directMessages);
    request.setAttribute("conversations", conversations);
    request.setAttribute("directMessages", directMessages);
    request.getRequestDispatcher("/WEB-INF/view/conversations.jsp").forward(request, response);
}
Also used : User(codeu.model.data.User) ArrayList(java.util.ArrayList) Conversation(codeu.model.data.Conversation)

Example 64 with Conversation

use of codeu.model.data.Conversation in project codeu-2018-team12 by codeu-2018-team12.

the class ConversationStoreTest method testGetConversationWithTitle_found.

@Test
public void testGetConversationWithTitle_found() {
    Conversation resultConversation = conversationStore.getConversationWithTitle(CONVERSATION_ONE.getTitle());
    assertEquals(CONVERSATION_ONE, resultConversation);
}
Also used : Conversation(codeu.model.data.Conversation) Test(org.junit.Test)

Example 65 with Conversation

use of codeu.model.data.Conversation in project codeu-2018-team12 by codeu-2018-team12.

the class ConversationStoreTest method testGetConversationWithId_notFound.

@Test
public void testGetConversationWithId_notFound() {
    Conversation resultConversation = conversationStore.getConversationWithId(UUID.randomUUID());
    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