use of codeu.model.data.User in project codeu-2018-team12 by codeu-2018-team12.
the class UserStoreTest method testGetUser_byId_notFound.
@Test
public void testGetUser_byId_notFound() {
User resultUser = userStore.getUser(UUID.randomUUID());
Assert.assertNull(resultUser);
}
use of codeu.model.data.User in project codeu-2018-team12 by codeu-2018-team12.
the class PersistentDataStoreTest method testSaveAndLoadUsersNoPassHash.
@Test
public void testSaveAndLoadUsersNoPassHash() throws PersistentDataStoreException {
UUID idOne = UUID.randomUUID();
String nameOne = "test_username_one";
String passwordOne = "test_password_one";
Instant creationOne = Instant.ofEpochMilli(1000);
User inputUserOne = new User(idOne, nameOne, passwordOne, null, creationOne);
UUID idTwo = UUID.randomUUID();
String nameTwo = "test_username_two";
String passwordTwo = "test_password_two";
Instant creationTwo = Instant.ofEpochMilli(2000);
User inputUserTwo = new User(idTwo, nameTwo, passwordTwo, null, creationTwo);
// save
persistentDataStore.writeThrough(inputUserOne);
persistentDataStore.writeThrough(inputUserTwo);
// load
List<User> resultUsers = persistentDataStore.loadUsers();
// confirm that what we saved matches what we loaded
User resultUserOne = resultUsers.get(0);
Assert.assertEquals(idOne, resultUserOne.getId());
Assert.assertEquals(nameOne, resultUserOne.getName());
Assert.assertTrue(BCrypt.checkpw(passwordOne, resultUserOne.getPassword()));
Assert.assertEquals(creationOne, resultUserOne.getCreationTime());
User resultUserTwo = resultUsers.get(1);
Assert.assertEquals(idTwo, resultUserTwo.getId());
Assert.assertEquals(nameTwo, resultUserTwo.getName());
Assert.assertTrue(BCrypt.checkpw(passwordTwo, resultUserTwo.getPassword()));
Assert.assertEquals(creationTwo, resultUserTwo.getCreationTime());
}
use of codeu.model.data.User in project codeu-2018-team12 by codeu-2018-team12.
the class PersistentStorageAgentTest method testWriteThroughUser.
@Test
public void testWriteThroughUser() {
User user = new User(UUID.randomUUID(), "test_username", "password", null, Instant.now());
persistentStorageAgent.writeThrough(user);
Mockito.verify(mockPersistentDataStore).writeThrough(user);
}
use of codeu.model.data.User in project codeu-2018-team12 by codeu-2018-team12.
the class ChatServletTest method testDoPost_UserJoinedConversation.
@Test
public void testDoPost_UserJoinedConversation() 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());
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);
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");
}
use of codeu.model.data.User in project codeu-2018-team12 by codeu-2018-team12.
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", "password", "test biography", 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);
fakeConversation.getConversationUsers().add(fakeUser);
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");
}
Aggregations