Search in sources :

Example 6 with ValidationException

use of dev.morphia.query.ValidationException in project morphia by mongodb.

the class TestQuery method testMixedProjection.

@Test
public void testMixedProjection() {
    getDs().save(new ContainsRenamedFields("Frank", "Zappa"));
    try {
        getDs().find(ContainsRenamedFields.class).iterator(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).iterator(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).iterator(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).iterator(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
    }
}
Also used : FindOptions(dev.morphia.query.FindOptions) ValidationException(dev.morphia.query.ValidationException) ArraySlice(dev.morphia.query.ArraySlice) Test(org.testng.annotations.Test)

Aggregations

ValidationException (dev.morphia.query.ValidationException)6 Test (org.testng.annotations.Test)6 FindOptions (dev.morphia.query.FindOptions)5 ArraySlice (dev.morphia.query.ArraySlice)2 IndexOptions (dev.morphia.annotations.IndexOptions)1 EntityModel (dev.morphia.mapping.codec.pojo.EntityModel)1