use of codeu.model.data.User in project CodeU-Spring-2018 by maksymko.
the class DefaultDataStore method addRandomConversations.
private void addRandomConversations() {
for (int i = 1; i <= DEFAULT_CONVERSATION_COUNT; i++) {
User user = getRandomElement(users);
String title = "Conversation_" + i;
Conversation conversation = new Conversation(UUID.randomUUID(), user.getId(), title, Instant.now());
PersistentStorageAgent.getInstance().writeThrough(conversation);
conversations.add(conversation);
}
}
use of codeu.model.data.User in project CodeU-Spring-2018 by maksymko.
the class ConversationServletTest method testDoPost_ConversationNameTaken.
@Test
public void testDoPost_ConversationNameTaken() 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", "test_password", Instant.now());
Mockito.when(mockUserStore.getUser("test_username")).thenReturn(fakeUser);
Mockito.when(mockConversationStore.isTitleTaken("test_conversation")).thenReturn(true);
conversationServlet.doPost(mockRequest, mockResponse);
Mockito.verify(mockConversationStore, Mockito.never()).addConversation(Mockito.any(Conversation.class));
Mockito.verify(mockResponse).sendRedirect("/chat/test_conversation");
}
use of codeu.model.data.User in project CodeU-Spring-2018 by maksymko.
the class ProfileServletTest method testDoGet.
@Test
public void testDoGet() throws IOException, ServletException {
Mockito.when(mockRequest.getRequestURI()).thenReturn("/profile/test_name");
User mockUser = Mockito.mock(User.class);
Mockito.when(mockUserStore.getUser("test_name")).thenReturn(mockUser);
profileServlet.doGet(mockRequest, mockResponse);
Mockito.verify(mockRequest).setAttribute("view_user", mockUser);
Mockito.verify(mockRequestDispatcher).forward(mockRequest, mockResponse);
}
use of codeu.model.data.User in project codeu-2018-team12 by codeu-2018-team12.
the class DefaultDataStore method addRandomUsers.
private void addRandomUsers() {
List<String> randomUsernames = getRandomUsernames();
Collections.shuffle(randomUsernames);
for (int i = 0; i < DEFAULT_USER_COUNT; i++) {
User user = new User(UUID.randomUUID(), getRandomElement(randomUsernames), BCrypt.hashpw("password", BCrypt.gensalt()), "this is a test biography", Instant.now());
PersistentStorageAgent.getInstance().writeThrough(user);
users.add(user);
}
}
use of codeu.model.data.User in project codeu-2018-team12 by codeu-2018-team12.
the class DefaultDataStore method addRandomConversations.
private void addRandomConversations() {
for (int i = 1; i <= DEFAULT_CONVERSATION_COUNT; i++) {
User user = getRandomElement(users);
String title = "Conversation_" + i;
Conversation conversation = new Conversation(UUID.randomUUID(), user.getId(), title, Instant.now());
PersistentStorageAgent.getInstance().writeThrough(conversation);
conversations.add(conversation);
}
}
Aggregations