Search in sources :

Example 46 with Mapper

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));
}
Also used : MappedField(org.mongodb.morphia.mapping.MappedField) Mapper(org.mongodb.morphia.mapping.Mapper) ArrayList(java.util.ArrayList) MappedClass(org.mongodb.morphia.mapping.MappedClass) Test(org.junit.Test)

Example 47 with Mapper

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)));
}
Also used : Mapper(org.mongodb.morphia.mapping.Mapper) AnotherNested(org.mongodb.morphia.mapping.EmbeddedMappingTest.AnotherNested) Nested(org.mongodb.morphia.mapping.EmbeddedMappingTest.Nested) MappedClass(org.mongodb.morphia.mapping.MappedClass) Test(org.junit.Test)

Example 48 with Mapper

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);
}
Also used : Mapper(org.mongodb.morphia.mapping.Mapper) MappedClass(org.mongodb.morphia.mapping.MappedClass) Test(org.junit.Test)

Example 49 with Mapper

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());
}
Also used : Mapper(org.mongodb.morphia.mapping.Mapper) MappedClass(org.mongodb.morphia.mapping.MappedClass) Test(org.junit.Test)

Example 50 with Mapper

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());
}
Also used : Mapper(org.mongodb.morphia.mapping.Mapper) MappedClass(org.mongodb.morphia.mapping.MappedClass) Test(org.junit.Test)

Aggregations

Mapper (org.mongodb.morphia.mapping.Mapper)62 Test (org.junit.Test)61 MappedClass (org.mongodb.morphia.mapping.MappedClass)53 MappedField (org.mongodb.morphia.mapping.MappedField)46 ArrayList (java.util.ArrayList)41 BasicDBObject (com.mongodb.BasicDBObject)9 DBObject (com.mongodb.DBObject)5 List (java.util.List)5 ObjectId (org.bson.types.ObjectId)5 SimpleEntity (org.mongodb.morphia.entities.SimpleEntity)5 Key (org.mongodb.morphia.Key)4 ParentType (org.mongodb.morphia.entities.ParentType)2 DefaultEntityCache (org.mongodb.morphia.mapping.cache.DefaultEntityCache)2 CollectionIdConverter (edu.stanford.bmir.protege.web.server.collection.CollectionIdConverter)1 CollectionItemConverter (edu.stanford.bmir.protege.web.server.collection.CollectionItemConverter)1 FormDataConverter (edu.stanford.bmir.protege.web.server.form.FormDataConverter)1 FormDataValueConverter (edu.stanford.bmir.protege.web.server.form.FormDataValueConverter)1 BsonDocument (org.bson.BsonDocument)1 BsonString (org.bson.BsonString)1 Document (org.bson.Document)1