Search in sources :

Example 6 with User

use of codeu.model.data.User in project CodeU-Spring-2018 by jwang281.

the class UserStoreTest method testAddUser.

@Test
public void testAddUser() {
    User inputUser = new User(UUID.randomUUID(), "test_username", "test_userpw", Instant.now());
    userStore.addUser(inputUser);
    User resultUser = userStore.getUser("test_username");
    assertEquals(inputUser, resultUser);
    Mockito.verify(mockPersistentStorageAgent).writeThrough(inputUser);
}
Also used : User(codeu.model.data.User) Test(org.junit.Test)

Example 7 with User

use of codeu.model.data.User in project CodeU-Spring-2018 by jwang281.

the class UserStoreTest method testGetUser_byUsername_found.

@Test
public void testGetUser_byUsername_found() {
    User resultUser = userStore.getUser(USER_ONE.getName());
    assertEquals(USER_ONE, resultUser);
}
Also used : User(codeu.model.data.User) Test(org.junit.Test)

Example 8 with User

use of codeu.model.data.User in project CodeU-Spring-2018 by jwang281.

the class PersistentDataStoreTest method testSaveAndLoadUsers.

@Test
public void testSaveAndLoadUsers() throws PersistentDataStoreException {
    UUID idOne = UUID.randomUUID();
    String nameOne = "test_username_one";
    String pwOne = "test_password_one";
    Instant creationOne = Instant.ofEpochMilli(1000);
    User inputUserOne = new User(idOne, nameOne, pwOne, creationOne);
    UUID idTwo = UUID.randomUUID();
    String nameTwo = "test_username_two";
    String pwTwo = "test_password_two";
    Instant creationTwo = Instant.ofEpochMilli(2000);
    User inputUserTwo = new User(idTwo, nameTwo, pwTwo, 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.assertEquals(pwOne, resultUserOne.getPassword());
    Assert.assertEquals(creationOne, resultUserOne.getCreationTime());
    User resultUserTwo = resultUsers.get(1);
    Assert.assertEquals(idTwo, resultUserTwo.getId());
    Assert.assertEquals(nameTwo, resultUserTwo.getName());
    Assert.assertEquals(pwTwo, resultUserTwo.getPassword());
    Assert.assertEquals(creationTwo, resultUserTwo.getCreationTime());
}
Also used : User(codeu.model.data.User) Instant(java.time.Instant) UUID(java.util.UUID) Test(org.junit.Test)

Example 9 with User

use of codeu.model.data.User in project CodeU-Spring-2018 by jwang281.

the class PersistentStorageAgentTest method testWriteThroughUser.

@Test
public void testWriteThroughUser() {
    User user = new User(UUID.randomUUID(), "test_username", "test_password", Instant.now());
    persistentStorageAgent.writeThrough(user);
    Mockito.verify(mockPersistentDataStore).writeThrough(user);
}
Also used : User(codeu.model.data.User) Test(org.junit.Test)

Example 10 with User

use of codeu.model.data.User in project CodeU-Spring-2018 by jwang281.

the class DefaultDataStore method addRandomMessages.

private void addRandomMessages() {
    for (int i = 0; i < DEFAULT_MESSAGE_COUNT; i++) {
        Conversation conversation = getRandomElement(conversations);
        User author = getRandomElement(users);
        String content = getRandomMessageContent();
        Message message = new Message(UUID.randomUUID(), conversation.getId(), author.getId(), content, Instant.now());
        PersistentStorageAgent.getInstance().writeThrough(message);
        messages.add(message);
    }
}
Also used : User(codeu.model.data.User) Message(codeu.model.data.Message) 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