Search in sources :

Example 21 with User

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);
    }
}
Also used : User(codeu.model.data.User) Conversation(codeu.model.data.Conversation)

Example 22 with User

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");
}
Also used : User(codeu.model.data.User) Conversation(codeu.model.data.Conversation) Test(org.junit.Test)

Example 23 with User

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);
}
Also used : User(codeu.model.data.User) Test(org.junit.Test)

Example 24 with User

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);
    }
}
Also used : User(codeu.model.data.User)

Example 25 with 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);
    }
}
Also used : User(codeu.model.data.User) Conversation(codeu.model.data.Conversation)

Aggregations

User (codeu.model.data.User)91 Test (org.junit.Test)60 Conversation (codeu.model.data.Conversation)36 Message (codeu.model.data.Message)23 UserStore (codeu.model.store.basic.UserStore)9 UUID (java.util.UUID)9 HttpSession (javax.servlet.http.HttpSession)8 Activity (codeu.model.data.Activity)7 Instant (java.time.Instant)7 ArrayList (java.util.ArrayList)7 PersistentDataStoreException (codeu.model.store.persistence.PersistentDataStoreException)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 Comparator (java.util.Comparator)2 ActivityStore (codeu.model.store.basic.ActivityStore)1 OutputSettings (org.jsoup.nodes.Document.OutputSettings)1