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");
}
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());
}
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);
}
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);
}
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);
}
Aggregations