use of org.bson.types.ObjectId in project morphia by mongodb.
the class QueryValidatorTest method shouldNotAllowNonKeyTypeWithKeyValue.
@Test
public void shouldNotAllowNonKeyTypeWithKeyValue() {
// expect
MappedClass mappedClass = new MappedClass(EntityWithListsAndArrays.class, new Mapper());
MappedField mappedField = mappedClass.getMappedField("listOfIntegers");
assertThat(QueryValidator.isCompatibleForOperator(mappedClass, mappedField, SimpleEntity.class, EQUAL, new Key<String>(String.class, "kind", new ObjectId()), new ArrayList<ValidationFailure>()), is(false));
}
use of org.bson.types.ObjectId in project morphia by mongodb.
the class QueryValidatorTest method shouldAllowTypeThatMatchesKeyTypeValue.
@Test
public void shouldAllowTypeThatMatchesKeyTypeValue() {
// expect
MappedClass mappedClass = new MappedClass(SimpleEntity.class, new Mapper());
MappedField mappedField = mappedClass.getMappedField("integer");
assertThat(QueryValidator.isCompatibleForOperator(mappedClass, mappedField, Integer.class, EQUAL, new Key<Number>(Integer.class, "Integer", new ObjectId()), new ArrayList<ValidationFailure>()), is(true));
}
use of org.bson.types.ObjectId in project morphia by mongodb.
the class TestQuery method testComplexIdQuery.
@Test
public void testComplexIdQuery() {
final CustomId cId = new CustomId();
cId.setId(new ObjectId());
cId.setType("banker");
final UsesCustomIdObject object = new UsesCustomIdObject();
object.setId(cId);
object.setText("hllo");
getDs().save(object);
assertNotNull(getDs().find(UsesCustomIdObject.class).filter("_id.type", "banker").get());
assertNotNull(getDs().find(UsesCustomIdObject.class).field("_id").hasAnyOf(singletonList(cId)).get());
}
use of org.bson.types.ObjectId in project morphia by mongodb.
the class TestQuery method testComplexIdQueryWithRenamedField.
@Test
public void testComplexIdQueryWithRenamedField() {
final CustomId cId = new CustomId();
cId.setId(new ObjectId());
cId.setType("banker");
final UsesCustomIdObject object = new UsesCustomIdObject();
object.setId(cId);
object.setText("hllo");
getDs().save(object);
assertNotNull(getDs().find(UsesCustomIdObject.class).filter("_id.t", "banker").get());
}
use of org.bson.types.ObjectId in project morphia by mongodb.
the class EntityTypeAndIdValueValidatorTest method shouldAllowTypeThatIsAMappedEntityAndAValueWithSameClassAsIdOfMappedEntity.
@Test
public void shouldAllowTypeThatIsAMappedEntityAndAValueWithSameClassAsIdOfMappedEntity() {
// given
ArrayList<ValidationFailure> validationFailures = new ArrayList<ValidationFailure>();
// when
MappedClass mappedClass = new MappedClass(SimpleEntity.class, new Mapper());
MappedField mappedField = mappedClass.getMappedField("_id");
boolean validationApplied = EntityTypeAndIdValueValidator.getInstance().apply(mappedClass, mappedField, new ObjectId(), validationFailures);
// then
assertThat(validationApplied, is(true));
assertThat(validationFailures.size(), is(0));
}
Aggregations