use of org.mongodb.morphia.mapping.Mapper in project morphia by mongodb.
the class SizeOperationValidatorTest method shouldAllowSizeOperatorForListTypesAndLongValues.
@Test
public void shouldAllowSizeOperatorForListTypesAndLongValues() {
// given
MappedClass mappedClass = new MappedClass(EntityWithListsAndArrays.class, new Mapper());
MappedField mappedField = mappedClass.getMappedField("listOfIntegers");
List<ValidationFailure> validationFailures = new ArrayList<ValidationFailure>();
// when
boolean validationApplied = SizeOperationValidator.getInstance().apply(mappedField, SIZE, 3L, validationFailures);
// then
assertThat(validationApplied, is(true));
assertThat(validationFailures.size(), is(0));
}
use of org.mongodb.morphia.mapping.Mapper in project morphia by mongodb.
the class TestMapper method subTypes.
@Test
public void subTypes() {
getMorphia().map(NestedImpl.class, AnotherNested.class);
Mapper mapper = getMorphia().getMapper();
List<MappedClass> subTypes = mapper.getSubTypes(mapper.getMappedClass(Nested.class));
Assert.assertTrue(subTypes.contains(mapper.getMappedClass(NestedImpl.class)));
Assert.assertTrue(subTypes.contains(mapper.getMappedClass(AnotherNested.class)));
}
use of org.mongodb.morphia.mapping.Mapper in project morphia by mongodb.
the class ExternalMapperExtTest method testExternalMapping.
@Test
public void testExternalMapping() throws Exception {
final Mapper mapper = getMorphia().getMapper();
final CloneMapper helper = new CloneMapper(mapper);
helper.map(Skeleton.class, EntityWithNoAnnotations.class);
final MappedClass mc = mapper.getMappedClass(EntityWithNoAnnotations.class);
mc.update();
assertNotNull(mc.getIdField());
assertNotNull(mc.getEntityAnnotation());
assertEquals("special", mc.getEntityAnnotation().value());
EntityWithNoAnnotations ent = new EntityWithNoAnnotations();
ent.id = "test";
final Key<EntityWithNoAnnotations> k = getDs().save(ent);
assertNotNull(k);
ent = getDs().get(EntityWithNoAnnotations.class, "test");
assertNotNull(ent);
assertEquals("test", ent.id);
}
use of org.mongodb.morphia.mapping.Mapper in project morphia by mongodb.
the class PathTargetTest method arrays.
@Test
public void arrays() {
getMorphia().map(EntityWithListsAndArrays.class, EmbeddedType.class, Student.class);
Mapper mapper = getMorphia().getMapper();
MappedClass mappedClass = mapper.getMappedClass(EntityWithListsAndArrays.class);
PathTarget pathTarget = new PathTarget(mapper, mappedClass, "listEmbeddedType.1.number");
Assert.assertEquals("listEmbeddedType.1.number", pathTarget.translatedPath());
Assert.assertEquals(mapper.getMappedClass(EmbeddedType.class).getMappedFieldByJavaField("number"), pathTarget.getTarget());
assertEquals("listEmbeddedType.$", new PathTarget(mapper, mappedClass, "listEmbeddedType.$").translatedPath());
assertEquals("listEmbeddedType.1", new PathTarget(mapper, mappedClass, "listEmbeddedType.1").translatedPath());
}
use of org.mongodb.morphia.mapping.Mapper in project morphia by mongodb.
the class PathTargetTest method interfaces.
@Test
public void interfaces() {
getMorphia().map(WithNested.class, Nested.class, NestedImpl.class, AnotherNested.class);
Mapper mapper = getMorphia().getMapper();
MappedClass mappedClass = mapper.getMappedClass(WithNested.class);
PathTarget pathTarget = new PathTarget(mapper, mappedClass, "nested.value");
Assert.assertEquals("nested.value", pathTarget.translatedPath());
Assert.assertEquals(mapper.getMappedClass(AnotherNested.class).getMappedFieldByJavaField("value"), pathTarget.getTarget());
pathTarget = new PathTarget(mapper, mappedClass, "nested.field");
Assert.assertEquals("nested.field", pathTarget.translatedPath());
Assert.assertEquals(mapper.getMappedClass(NestedImpl.class).getMappedFieldByJavaField("field"), pathTarget.getTarget());
}
Aggregations