Search in sources :

Example 16 with Conversation

use of codeu.model.data.Conversation in project CodeU-Spring-2018 by maksymko.

the class ChatServletTest method testDoPost_CleansHtmlContent.

@Test
public void testDoPost_CleansHtmlContent() 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", "test_passord", 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);
    Mockito.when(mockRequest.getParameter("message")).thenReturn("Contains <b>html</b> and <script>JavaScript</script> content.");
    chatServlet.doPost(mockRequest, mockResponse);
    ArgumentCaptor<Message> messageArgumentCaptor = ArgumentCaptor.forClass(Message.class);
    Mockito.verify(mockMessageStore).addMessage(messageArgumentCaptor.capture());
    Assert.assertEquals("Contains html and  content.", 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 17 with Conversation

use of codeu.model.data.Conversation in project CodeU-Spring-2018 by maksymko.

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", "test_password", 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);
    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 18 with Conversation

use of codeu.model.data.Conversation in project CodeU-Spring-2018 by maksymko.

the class DefaultDataStore method addRandomConversations.

private void addRandomConversations() {
    for (int i = 1; i <= DEFAULT_CONVERSATION_COUNT; i++) {
        User user = getRandomElement(users);
        String title = "Conversation_" + i;
        Conversation conversation = new Conversation(UUID.randomUUID(), user.getId(), title, Instant.now());
        PersistentStorageAgent.getInstance().writeThrough(conversation);
        conversations.add(conversation);
    }
}
Also used : User(codeu.model.data.User) Conversation(codeu.model.data.Conversation)

Example 19 with Conversation

use of codeu.model.data.Conversation in project CodeU-Spring-2018 by maksymko.

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(mockConversationStore.getAllConversations()).thenReturn(fakeConversationList);
    conversationServlet.doGet(mockRequest, mockResponse);
    Mockito.verify(mockRequest).setAttribute("conversations", fakeConversationList);
    Mockito.verify(mockRequestDispatcher).forward(mockRequest, mockResponse);
}
Also used : ArrayList(java.util.ArrayList) Conversation(codeu.model.data.Conversation) Test(org.junit.Test)

Example 20 with Conversation

use of codeu.model.data.Conversation 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(), "codeUChatTestEmail@gmail.com");
    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.getId());
    Mockito.when(mockRequest.getParameter("submitText")).thenReturn("submitText");
    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)

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