Search in sources :

Example 21 with Conversation

use of codeu.model.data.Conversation 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");
    UUID userUUID = UUID.randomUUID();
    User fakeUser = new User(userUUID, "test_username", "password", "test biography", Instant.now(), "codeUChatTestEmail@gmail.com");
    Mockito.when(mockUserStore.getUser("test_username")).thenReturn(fakeUser);
    Mockito.when(mockUserStore.getUser(userUUID)).thenReturn(fakeUser);
    Conversation fakeConversation = new Conversation(UUID.randomUUID(), userUUID, "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("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) UUID(java.util.UUID) Test(org.junit.Test)

Example 22 with Conversation

use of codeu.model.data.Conversation 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(), "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("**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 23 with Conversation

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

the class DirectMessageServletTest method testDoGet.

@Test
public void testDoGet() throws IOException, ServletException {
    Mockito.when(mockRequest.getRequestURI()).thenReturn("/direct/test_user");
    Mockito.when(mockRequest.getSession().getAttribute("user")).thenReturn("test_user2");
    User testloggedInUser = new User(UUID.randomUUID(), "test_user2", null, null, Instant.now(), null);
    Mockito.when(mockUserStore.getUser("test_user2")).thenReturn(testloggedInUser);
    User testUser = new User(UUID.randomUUID(), "test_user", "password", null, Instant.now(), "codeUChatTestEmail@gmail.com");
    Mockito.when(mockUserStore.getUser("test_user")).thenReturn(testUser);
    UUID fakeConversationId = UUID.randomUUID();
    Conversation fakeConversation = new Conversation(fakeConversationId, UUID.randomUUID(), "test_conversation", Instant.now());
    Mockito.when(mockConversationStore.getConversationWithTitle("direct:test_user-test_user2")).thenReturn(fakeConversation);
    List<Message> fakeMessageList = new ArrayList<>();
    fakeMessageList.add(new Message(UUID.randomUUID(), fakeConversationId, UUID.randomUUID(), "test message", Instant.now(), false));
    Mockito.when(mockMessageStore.getMessagesInConversation(fakeConversationId)).thenReturn(fakeMessageList);
    directMessageServlet.doGet(mockRequest, mockResponse);
    Mockito.verify(mockRequest).setAttribute("loggedInUser", testloggedInUser);
    Mockito.verify(mockRequest).setAttribute("otherUser", testUser);
    Mockito.verify(mockRequest).setAttribute("conversation", fakeConversation);
    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) Conversation(codeu.model.data.Conversation) UUID(java.util.UUID) Test(org.junit.Test)

Example 24 with Conversation

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

the class DirectMessageServletTest method testDoGet_ConversationNotFound.

@Test
public void testDoGet_ConversationNotFound() throws IOException, ServletException {
    Mockito.when(mockRequest.getRequestURI()).thenReturn("/direct/test_user");
    Mockito.when(mockRequest.getSession().getAttribute("user")).thenReturn("test_user2");
    User testloggedInUser = new User(UUID.randomUUID(), "test_user2", null, null, Instant.now(), null);
    Mockito.when(mockUserStore.getUser("test_user2")).thenReturn(testloggedInUser);
    User testUser = new User(UUID.randomUUID(), "test_user", "password", null, Instant.now(), "codeUChatTestEmail@gmail.com");
    Mockito.when(mockUserStore.getUser("test_user")).thenReturn(testUser);
    UUID fakeConversationId = UUID.randomUUID();
    Mockito.when(mockConversationStore.getConversationWithTitle("direct:test_user-test_user2")).thenReturn(null);
    directMessageServlet.doGet(mockRequest, mockResponse);
    ArgumentCaptor<Conversation> conversationArgumentCaptor = ArgumentCaptor.forClass(Conversation.class);
    Mockito.verify(mockConversationStore).addConversation(conversationArgumentCaptor.capture());
    Assert.assertEquals(conversationArgumentCaptor.getValue().getTitle(), "direct:test_user-test_user2");
    Mockito.verify(mockRequest).setAttribute("loggedInUser", testloggedInUser);
    Mockito.verify(mockRequest).setAttribute("otherUser", testUser);
    Mockito.verify(mockRequest).setAttribute("conversation", conversationArgumentCaptor.getValue());
    Mockito.verify(mockRequest).setAttribute("messages", new ArrayList<Message>());
    Mockito.verify(mockRequestDispatcher).forward(mockRequest, mockResponse);
}
Also used : User(codeu.model.data.User) Message(codeu.model.data.Message) Conversation(codeu.model.data.Conversation) UUID(java.util.UUID) Test(org.junit.Test)

Example 25 with Conversation

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

the class DirectMessageServletTest method testDoPost_StoresActivity.

@Test
public void testDoPost_StoresActivity() throws IOException, ServletException {
    Mockito.when(mockRequest.getRequestURI()).thenReturn("/direct/test_user");
    Mockito.when(mockRequest.getSession().getAttribute("user")).thenReturn("test_user2");
    User testloggedInUser = new User(UUID.randomUUID(), "test_user2", null, null, Instant.now(), null);
    Mockito.when(mockUserStore.getUser("test_user2")).thenReturn(testloggedInUser);
    User testUser = new User(UUID.randomUUID(), "test_user", "password", null, Instant.now(), "codeUChatTestEmail@gmail.com");
    Mockito.when(mockUserStore.getUser("test_user")).thenReturn(testUser);
    Conversation fakeConversation = new Conversation(UUID.randomUUID(), UUID.randomUUID(), "direct:test_user-test_user2", Instant.now());
    Mockito.when(mockConversationStore.getConversationWithTitle("direct:test_user-test_user2")).thenReturn(fakeConversation);
    fakeConversation.getConversationUsers().add(testloggedInUser.getId());
    Mockito.when(mockRequest.getParameter("submitText")).thenReturn("submitText");
    Mockito.when(mockRequest.getParameter("message")).thenReturn("Test message.");
    Activity activity = new Activity(UUID.randomUUID(), testloggedInUser.getId(), fakeConversation.getId(), Instant.now(), "sentMessage", "test_activity_message" + "Test message.", fakeConversation.getConversationUsers(), fakeConversation.getIsPublic());
    mockActivityStore.addActivity(activity);
    Mockito.when(mockActivityStore.getActivityWithId(activity.getId())).thenReturn(activity);
    directMessageServlet.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(mockActivityStore).addActivity(activity);
    Assert.assertTrue(mockActivityStore.getActivityWithId(activity.getId()).getActivityMessage().contains("Test message."));
    Mockito.verify(mockResponse).sendRedirect("/direct/test_user");
}
Also used : User(codeu.model.data.User) Message(codeu.model.data.Message) Activity(codeu.model.data.Activity) 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