use of dev.morphia.query.ValidationException in project morphia by mongodb.
the class IndexHelperTest method findField.
@Test
public void findField() {
getMapper().map(MappedInterface.class, MappedInterfaceImpl.class, AbstractParent.class, IndexedClass.class);
EntityModel model = getMapper().getEntityModel(IndexedClass.class);
IndexOptions options = indexOptionsBuilder().build();
assertEquals(getIndexHelper().findField(model, options, "indexName"), "indexName");
assertEquals(getIndexHelper().findField(model, options, "nested.name"), "nest.name");
assertEquals(getIndexHelper().findField(model, options, "nest.name"), "nest.name");
try {
assertEquals(getIndexHelper().findField(model, options, "nest.whatsit"), "nest.whatsit");
fail("Should have failed on the bad index path");
} catch (ValidationException e) {
// alles ist gut
}
assertEquals(getIndexHelper().findField(model, indexOptionsBuilder().disableValidation(true).build(), "nest.whatsit.nested.more.deeply.than.the.object.model"), "nest.whatsit.nested.more.deeply.than.the.object.model");
}
use of dev.morphia.query.ValidationException in project morphia by mongodb.
the class TestQuery method testProject.
@Test
public void testProject() {
getDs().save(new ContainsRenamedFields("Frank", "Zappa"));
ContainsRenamedFields found = getDs().find(ContainsRenamedFields.class).iterator(new FindOptions().projection().include("first_name").limit(1)).tryNext();
assertNotNull(found.firstName);
assertNull(found.lastName);
found = getDs().find(ContainsRenamedFields.class).iterator(new FindOptions().projection().include("first_name").limit(1)).tryNext();
assertNotNull(found.firstName);
assertNull(found.lastName);
try {
getDs().find(ContainsRenamedFields.class).iterator(new FindOptions().projection().include("bad field name").limit(1)).tryNext();
fail("Validation should have caught the bad field");
} catch (ValidationException e) {
// success!
}
Query<ContainsRenamedFields> query = getDs().find(ContainsRenamedFields.class);
}
use of dev.morphia.query.ValidationException in project morphia by mongodb.
the class TestQuery method testRetrievedFields.
@Test
public void testRetrievedFields() {
getDs().save(new ContainsRenamedFields("Frank", "Zappa"));
ContainsRenamedFields found = getDs().find(ContainsRenamedFields.class).iterator(new FindOptions().projection().include("first_name").limit(1)).tryNext();
assertNotNull(found.firstName);
assertNull(found.lastName);
found = getDs().find(ContainsRenamedFields.class).iterator(new FindOptions().projection().include("firstName").limit(1)).tryNext();
assertNotNull(found.firstName);
assertNull(found.lastName);
try {
getDs().find(ContainsRenamedFields.class).iterator(new FindOptions().projection().include("bad field name").limit(1)).tryNext();
fail("Validation should have caught the bad field");
} catch (ValidationException e) {
// success!
}
}
use of dev.morphia.query.ValidationException in project morphia by mongodb.
the class TestLegacyQuery method testMixedProjection.
@Test
public void testMixedProjection() {
getDs().save(new ContainsRenamedFields("Frank", "Zappa"));
try {
getDs().find(ContainsRenamedFields.class).execute(new FindOptions().projection().include("first_name").projection().exclude("last_name"));
fail("An exception should have been thrown indication a mixed projection");
} catch (ValidationException e) {
// all good
}
try {
getDs().find(ContainsRenamedFields.class).execute(new FindOptions().projection().include("first_name", "last_name").projection().exclude("_id"));
} catch (ValidationException e) {
fail("An exception should not have been thrown indication a mixed projection because _id suppression is a special case");
}
try {
getDs().find(ContainsRenamedFields.class).execute(new FindOptions().projection().exclude("first_name", "last_name").projection().include("_id"));
fail("An exception should have been thrown indication a mixed projection");
} catch (ValidationException e) {
// all good
}
try {
getDs().find(IntVector.class).execute(new FindOptions().projection().exclude("name").projection().project("scalars", new ArraySlice(5)));
fail("An exception should have been thrown indication a mixed projection");
} catch (ValidationException e) {
// all good
}
}
use of dev.morphia.query.ValidationException in project morphia by mongodb.
the class TestLegacyQuery method testProject.
@Test
public void testProject() {
getDs().save(new ContainsRenamedFields("Frank", "Zappa"));
ContainsRenamedFields found = getDs().find(ContainsRenamedFields.class).execute(new FindOptions().projection().include("first_name").limit(1)).tryNext();
assertNotNull(found.firstName);
assertNull(found.lastName);
found = getDs().find(ContainsRenamedFields.class).execute(new FindOptions().projection().include("first_name").limit(1)).tryNext();
assertNotNull(found.firstName);
assertNull(found.lastName);
try {
getDs().find(ContainsRenamedFields.class).execute(new FindOptions().projection().include("bad field name").limit(1)).tryNext();
fail("Validation should have caught the bad field");
} catch (ValidationException e) {
// success!
}
}
Aggregations