use of codeu.model.data.Activity 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");
}
use of codeu.model.data.Activity 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");
Mockito.when(mockRequest.getSession().getAttribute("user")).thenReturn("testuser");
User testloggedInUser = new User(UUID.randomUUID(), "testuser", null, null, Instant.now(), null);
Mockito.when(mockUserStore.getUser("testuser")).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);
ArrayList<Activity> activities = new ArrayList<Activity>();
Activity activityOne = new Activity(UUID.randomUUID(), testUser.getId(), UUID.randomUUID(), Instant.ofEpochMilli(2000), "leftConvo", "test_message", new ArrayList<UUID>(), false);
Activity activityTwo = new Activity(UUID.randomUUID(), testUser.getId(), UUID.randomUUID(), Instant.ofEpochMilli(1000), "leftConvo", "test_message", new ArrayList<UUID>(), true);
activities.add(activityOne);
activities.add(activityTwo);
Mockito.when(sort(mockActivityStore.getAllPermittedActivitiesWithUserId(testUser.getId(), testloggedInUser.getId()))).thenReturn(activities);
Mockito.when(mockActivityStore.getActivitiesPerPrivacy(testUser, activities)).thenReturn(activities);
profileServlet.doGet(mockRequest, mockResponse);
Mockito.verify(mockRequest).setAttribute("user", testUser);
Mockito.verify(mockRequest).setAttribute("activities", activities);
Mockito.verify(mockRequestDispatcher).forward(mockRequest, mockResponse);
}
use of codeu.model.data.Activity in project codeu-2018-team12 by codeu-2018-team12.
the class RegisterServletTest method testDoPost_NewUser.
@Test
public void testDoPost_NewUser() throws IOException, ServletException {
Mockito.when(mockRequest.getParameter("username")).thenReturn("test username");
Mockito.when(mockRequest.getParameter("password")).thenReturn("test password");
Mockito.when(mockRequest.getParameter("confirmPassword")).thenReturn("test password");
Mockito.when(mockRequest.getParameter("email")).thenReturn("testEmail");
UserStore mockUserStore = Mockito.mock(UserStore.class);
Mockito.when(mockUserStore.isUserRegistered("test username")).thenReturn(false);
registerServlet.setUserStore(mockUserStore);
ActivityStore mockActivityStore = Mockito.mock(ActivityStore.class);
registerServlet.setActivityStore(mockActivityStore);
HttpSession mockSession = Mockito.mock(HttpSession.class);
Mockito.when(mockRequest.getSession()).thenReturn(mockSession);
registerServlet.doPost(mockRequest, mockResponse);
ArgumentCaptor<User> userArgumentCaptor = ArgumentCaptor.forClass(User.class);
ArgumentCaptor<Activity> activityArgumentCaptor = ArgumentCaptor.forClass(Activity.class);
Mockito.verify(mockUserStore).addUser(userArgumentCaptor.capture());
Assert.assertEquals(userArgumentCaptor.getValue().getName(), "test username");
Mockito.verify(mockActivityStore).addActivity(activityArgumentCaptor.capture());
Assert.assertEquals(activityArgumentCaptor.getValue().getUserId(), userArgumentCaptor.getValue().getId());
Mockito.verify(mockResponse).sendRedirect("/login");
}
use of codeu.model.data.Activity in project codeu-2018-team12 by codeu-2018-team12.
the class PersistentStorageAgentTest method testWriteThroughActivity.
@Test
public void testWriteThroughActivity() {
Activity activity = new Activity(UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), Instant.now(), "messageSent", "sampleMessage", new ArrayList<UUID>(), true);
persistentStorageAgent.writeThrough(activity);
Mockito.verify(mockPersistentDataStore).writeThrough(activity);
}
use of codeu.model.data.Activity in project codeu-2018-team12 by codeu-2018-team12.
the class ActivityServletTest method testDoGet.
@Test
public void testDoGet() throws IOException, ServletException {
List<Activity> sampleActivities = new ArrayList<>();
sampleActivities.add(new Activity(UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), Instant.ofEpochMilli(2000), "joinedApp", "testMessage", new ArrayList<UUID>(), true));
sampleActivities.add(new Activity(UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), Instant.ofEpochMilli(1000), "createdConvo", "testMessage", new ArrayList<UUID>(), true));
Mockito.when(mockRequest.getSession().getAttribute("user")).thenReturn("testuser");
User testUser = new User(UUID.randomUUID(), "testuser", null, null, Instant.now(), null);
Mockito.when(mockUserStore.getUser("testuser")).thenReturn(testUser);
Mockito.when(sort(mockActivityStore.getAllPermittedActivities(testUser.getId()))).thenReturn(sampleActivities);
Mockito.when(sort(mockActivityStore.getActivitiesPerPrivacy(testUser, sampleActivities))).thenReturn(sampleActivities);
activityServlet.doGet(mockRequest, mockResponse);
Mockito.verify(mockRequest).setAttribute("activities", sampleActivities);
Mockito.verify(mockRequestDispatcher).forward(mockRequest, mockResponse);
}
Aggregations