use of dev.morphia.test.models.DocumentValidation in project morphia by mongodb.
the class TestDocumentValidation method update.
@Test
@SuppressWarnings("rawtypes")
public void update() {
getMapper().map(DocumentValidation.class);
getDs().enableDocumentValidation();
getDs().save(new DocumentValidation("Harold", 100, new Date()));
Query<DocumentValidation> query = getDs().find(DocumentValidation.class);
UpdateOptions options = new UpdateOptions().bypassDocumentValidation(false);
Update<DocumentValidation> update = query.update(set("number", 5));
try {
update.execute(options);
fail("Document validation should have complained");
} catch (MongoWriteException e) {
// expected
}
options.bypassDocumentValidation(true);
update.execute(options);
Assert.assertNotNull(query.filter(eq("number", 5)).iterator(new FindOptions().limit(1)).tryNext());
}
Aggregations