use of dev.morphia.test.models.Rectangle in project morphia by mongodb.
the class TestLegacyQuery method testAliasedFieldSort.
@Test
public void testAliasedFieldSort() {
getDs().save(asList(new Rectangle(1, 10), new Rectangle(3, 8), new Rectangle(6, 10), new Rectangle(10, 10), new Rectangle(10, 1)));
Rectangle r1 = getDs().find(Rectangle.class).execute(new FindOptions().sort(ascending("w")).limit(1)).tryNext();
assertNotNull(r1);
assertEquals(r1.getWidth(), 1, 0);
r1 = getDs().find(Rectangle.class).execute(new FindOptions().sort(descending("w")).limit(1)).tryNext();
assertNotNull(r1);
assertEquals(r1.getWidth(), 10, 0);
}
use of dev.morphia.test.models.Rectangle in project morphia by mongodb.
the class TestTransactions method delete.
@Test
public void delete() {
Rectangle rectangle = new Rectangle(1, 1);
getDs().save(rectangle);
getDs().withTransaction(builder().defaultTransactionOptions(TransactionOptions.builder().writeConcern(MAJORITY).build()).build(), (session) -> {
assertNotNull(getDs().find(Rectangle.class).first());
assertNotNull(session.find(Rectangle.class).first());
session.delete(rectangle);
assertNotNull(getDs().find(Rectangle.class).first());
assertNull(session.find(Rectangle.class).first());
return null;
});
assertNull(getDs().find(Rectangle.class).first());
}
use of dev.morphia.test.models.Rectangle in project morphia by mongodb.
the class TestTransactions method saveList.
@Test
public void saveList() {
List<Rectangle> rectangles = List.of(new Rectangle(5, 7), new Rectangle(1, 1));
getDs().withTransaction((session) -> {
session.save(rectangles);
assertNull(getDs().find(Rectangle.class).first());
assertEquals(session.find(Rectangle.class).count(), 2);
return null;
});
assertEquals(getDs().find(Rectangle.class).count(), 2);
}
use of dev.morphia.test.models.Rectangle in project morphia by mongodb.
the class TestTransactions method before.
@BeforeMethod
public void before() {
checkMinServerVersion(4.0);
assumeTrue(isReplicaSet(), "These tests require a replica set");
getDs().save(new Rectangle(1, 1));
getDs().find(Rectangle.class).findAndDelete();
getDs().save(new User("", LocalDate.now()));
getDs().find(User.class).findAndDelete();
}
use of dev.morphia.test.models.Rectangle in project morphia by mongodb.
the class TestDatastore method testIdUpdatedOnSave.
@Test
public void testIdUpdatedOnSave() {
final Rectangle rect = new Rectangle(10, 10);
getDs().save(rect);
assertNotNull(rect.getId());
}
Aggregations