Search in sources :

Example 16 with Message

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

the class MessageStore method getMostRecentMessageFromConvo.

/**
 * Access the content of the most recent message within a given conversation
 */
public String getMostRecentMessageFromConvo(UUID conversationId) {
    String recentMessage = "";
    messages.sort(msgComparator);
    for (Message message : messages) {
        if (message.getConversationId().equals(conversationId))
            recentMessage = message.getContent();
        break;
    }
    return recentMessage;
}
Also used : Message(codeu.model.data.Message)

Example 17 with Message

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

the class ChatServletTest method testDoPost_Markdown.

@Test
public void testDoPost_Markdown() 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);
    fakeConversation.getConversationUsers().add(fakeUser);
    Mockito.when(mockRequest.getParameter("message")).thenReturn("**test**");
    chatServlet.doPost(mockRequest, mockResponse);
    ArgumentCaptor<Message> messageArgumentCaptor = ArgumentCaptor.forClass(Message.class);
    Mockito.verify(mockMessageStore).addMessage(messageArgumentCaptor.capture());
    Assert.assertEquals("<strong>test</strong>", messageArgumentCaptor.getValue().getContent());
    Mockito.verify(mockResponse).sendRedirect("/chat/test_conversation");
}
Also used : User(codeu.model.data.User) Message(codeu.model.data.Message) Conversation(codeu.model.data.Conversation) Test(org.junit.Test)

Example 18 with Message

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

the class ChatServletTest method testDoPost_Emoji.

@Test
public void testDoPost_Emoji() 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);
    fakeConversation.getConversationUsers().add(fakeUser);
    Mockito.when(mockRequest.getParameter("message")).thenReturn(":japanese_goblin:");
    chatServlet.doPost(mockRequest, mockResponse);
    ArgumentCaptor<Message> messageArgumentCaptor = ArgumentCaptor.forClass(Message.class);
    Mockito.verify(mockMessageStore).addMessage(messageArgumentCaptor.capture());
    Assert.assertEquals("&#x1f47a;", messageArgumentCaptor.getValue().getContent());
    Mockito.verify(mockResponse).sendRedirect("/chat/test_conversation");
}
Also used : User(codeu.model.data.User) Message(codeu.model.data.Message) Conversation(codeu.model.data.Conversation) Test(org.junit.Test)

Example 19 with Message

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

the class ChatServletTest method testDoPost_StoresMessage.

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

Example 20 with Message

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

the class ProfileServletTest method testDoGet.

@Test
public void testDoGet() throws IOException, ServletException {
    Mockito.when(mockRequest.getRequestURI()).thenReturn("/profile/test_user");
    User testUser = new User(UUID.randomUUID(), "test_user", "password", null, Instant.now());
    Mockito.when(mockUserStore.getUser("test_user")).thenReturn(testUser);
    List<Message> fakeMessageList = new ArrayList<>();
    fakeMessageList.add(new Message(UUID.randomUUID(), UUID.randomUUID(), testUser.getId(), "test message 1", Instant.ofEpochMilli(2000)));
    fakeMessageList.add(new Message(UUID.randomUUID(), UUID.randomUUID(), testUser.getId(), "test message 2", Instant.ofEpochMilli(1000)));
    Mockito.when(mockMessageStore.getMessagesByAuthorSorted(testUser.getId())).thenReturn(fakeMessageList);
    profileServlet.doGet(mockRequest, mockResponse);
    Mockito.verify(mockRequest).setAttribute("user", testUser);
    Mockito.verify(mockRequest).setAttribute("messages", fakeMessageList);
    Mockito.verify(mockRequestDispatcher).forward(mockRequest, mockResponse);
}
Also used : User(codeu.model.data.User) Message(codeu.model.data.Message) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

Message (codeu.model.data.Message)39 Test (org.junit.Test)23 Conversation (codeu.model.data.Conversation)22 User (codeu.model.data.User)19 UUID (java.util.UUID)15 ArrayList (java.util.ArrayList)9 Instant (java.time.Instant)6 Activity (codeu.model.data.Activity)2 PersistentDataStoreException (codeu.model.store.persistence.PersistentDataStoreException)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)1