Search in sources :

Example 66 with Conversation

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

the class ConversationStoreTest method testAddConversation.

@Test
public void testAddConversation() {
    Conversation inputConversation = new Conversation(UUID.randomUUID(), UUID.randomUUID(), "test_conversation", Instant.now());
    conversationStore.addConversation(inputConversation);
    Conversation resultConversation = conversationStore.getConversationWithTitle("test_conversation");
    assertEquals(inputConversation, resultConversation);
    Mockito.verify(mockPersistentStorageAgent).writeThrough(inputConversation);
}
Also used : Conversation(codeu.model.data.Conversation) Test(org.junit.Test)

Example 67 with Conversation

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

the class ConversationStoreTest method testGetConversationWithId_found.

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

Example 68 with Conversation

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

the class PersistentStorageAgentTest method testUpdateEntityConversationUser.

@Test
public void testUpdateEntityConversationUser() {
    Conversation conversation = new Conversation(UUID.randomUUID(), UUID.randomUUID(), "test_conversation", Instant.now());
    persistentStorageAgent.updateConversationEntityUsers(conversation);
    Mockito.verify(mockPersistentDataStore).updateConversationEntityUsers(conversation);
}
Also used : Conversation(codeu.model.data.Conversation) Test(org.junit.Test)

Example 69 with Conversation

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

the class ChatServletTest method testDoPost_StoresActivity.

@Test
public void testDoPost_StoresActivity() 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", "testbiography", 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 message.");
    Activity activity = new Activity(UUID.randomUUID(), fakeUser.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);
    chatServlet.doPost(mockRequest, mockResponse);
    ArgumentCaptor<Message> messageArgumentCaptor = ArgumentCaptor.forClass(Message.class);
    Mockito.verify(mockMessageStore).addMessage(messageArgumentCaptor.capture());
    Mockito.verify(mockActivityStore).addActivity(activity);
    Assert.assertEquals("Test message.", messageArgumentCaptor.getValue().getContent());
    Assert.assertTrue(mockActivityStore.getActivityWithId(activity.getId()).getActivityMessage().contains("Test message."));
    Mockito.verify(mockResponse).sendRedirect("/chat/test_conversation");
}
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)

Example 70 with Conversation

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

the class ChatServletTest method testDoPost_UserNotJoinedConversation.

@Test
public void testDoPost_UserNotJoinedConversation() 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);
    chatServlet.doPost(mockRequest, mockResponse);
    Mockito.verify(mockMessageStore, Mockito.never()).addMessage(Mockito.any(Message.class));
    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