Search in sources :

Example 6 with Versioned

use of dev.morphia.test.models.versioned.Versioned in project morphia by mongodb.

the class TestVersioning method testVersionNumbersIncrementWithEachSave.

@Test
public void testVersionNumbersIncrementWithEachSave() {
    final Versioned version1 = new Versioned();
    getDs().save(version1);
    assertEquals(version1.getVersion(), Long.valueOf(1));
    final Versioned version2 = getDs().find(Versioned.class).filter(eq("_id", version1.getId())).first();
    getDs().save(version2);
    assertEquals(version2.getVersion(), Long.valueOf(2));
}
Also used : Versioned(dev.morphia.test.models.versioned.Versioned) Test(org.testng.annotations.Test)

Example 7 with Versioned

use of dev.morphia.test.models.versioned.Versioned in project morphia by mongodb.

the class TestVersioning method testUpdatesToVersionedFileAreReflectedInTheDatastore.

@Test
public void testUpdatesToVersionedFileAreReflectedInTheDatastore() {
    final Versioned version1 = new Versioned();
    version1.setName("foo");
    this.getDs().save(version1);
    final Versioned version1Updated = getDs().find(Versioned.class).filter(eq("_id", version1.getId())).first();
    version1Updated.setName("bar");
    this.getDs().merge(version1Updated);
    final Versioned versionedEntityFromDs = this.getDs().find(Versioned.class).filter(eq("_id", version1.getId())).first();
    assertEquals(version1Updated.getName(), versionedEntityFromDs.getName());
}
Also used : Versioned(dev.morphia.test.models.versioned.Versioned) Test(org.testng.annotations.Test)

Example 8 with Versioned

use of dev.morphia.test.models.versioned.Versioned in project morphia by mongodb.

the class TestVersioning method testVersionedInserts.

@Test
public void testVersionedInserts() {
    List<Versioned> list = asList(new Versioned(), new Versioned(), new Versioned(), new Versioned(), new Versioned());
    getDs().insert(list);
    for (Versioned versioned : list) {
        assertNotNull(versioned.getVersion());
    }
}
Also used : Versioned(dev.morphia.test.models.versioned.Versioned) Test(org.testng.annotations.Test)

Aggregations

Versioned (dev.morphia.test.models.versioned.Versioned)8 Test (org.testng.annotations.Test)8 Datastore (dev.morphia.Datastore)3 Morphia.createDatastore (dev.morphia.Morphia.createDatastore)3 DeleteOptions (dev.morphia.DeleteOptions)2 UpdateOptions (dev.morphia.UpdateOptions)2 ModifyOptions (dev.morphia.ModifyOptions)1 FindOptions (dev.morphia.query.FindOptions)1