Search in sources :

Example 56 with Conversation

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

the class PersistentDataStoreTest method testSaveAndLoadConversations.

@Test
public void testSaveAndLoadConversations() throws PersistentDataStoreException {
    UUID idOne = UUID.randomUUID();
    UUID ownerOne = UUID.randomUUID();
    String titleOne = "Test_Title";
    Instant creationOne = Instant.ofEpochMilli(1000);
    Conversation inputConversationOne = new Conversation(idOne, ownerOne, titleOne, creationOne);
    UUID idTwo = UUID.randomUUID();
    UUID ownerTwo = UUID.randomUUID();
    String titleTwo = "Test_Title_Two";
    Instant creationTwo = Instant.ofEpochMilli(2000);
    Conversation inputConversationTwo = new Conversation(idTwo, ownerTwo, titleTwo, creationTwo);
    // save
    persistentDataStore.writeThrough(inputConversationOne);
    persistentDataStore.writeThrough(inputConversationTwo);
    // load
    List<Conversation> resultConversations = persistentDataStore.loadConversations();
    // confirm that what we saved matches what we loaded
    Conversation resultConversationOne = resultConversations.get(0);
    Assert.assertEquals(idOne, resultConversationOne.getId());
    Assert.assertEquals(ownerOne, resultConversationOne.getOwnerId());
    Assert.assertEquals(titleOne, resultConversationOne.getTitle());
    Assert.assertEquals(creationOne, resultConversationOne.getCreationTime());
    Conversation resultConversationTwo = resultConversations.get(1);
    Assert.assertEquals(idTwo, resultConversationTwo.getId());
    Assert.assertEquals(ownerTwo, resultConversationTwo.getOwnerId());
    Assert.assertEquals(titleTwo, resultConversationTwo.getTitle());
    Assert.assertEquals(creationTwo, resultConversationTwo.getCreationTime());
}
Also used : Instant(java.time.Instant) Conversation(codeu.model.data.Conversation) UUID(java.util.UUID) Test(org.junit.Test)

Example 57 with Conversation

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

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

Conversation (codeu.model.data.Conversation)57 Test (org.junit.Test)38 User (codeu.model.data.User)29 Message (codeu.model.data.Message)23 UUID (java.util.UUID)12 ArrayList (java.util.ArrayList)9 Instant (java.time.Instant)6 Activity (codeu.model.data.Activity)5 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 OutputSettings (org.jsoup.nodes.Document.OutputSettings)1