use of org.mongodb.morphia.mapping.Mapper in project morphia by mongodb.
the class MappedFieldTypeValidatorTest method shouldAllowArraysOfNumbers.
@Test
public void shouldAllowArraysOfNumbers() {
// given
MappedClass mappedClass = new MappedClass(EntityWithListsAndArrays.class, new Mapper());
MappedField mappedField = mappedClass.getMappedField("arrayOfInts");
// expect
assertThat(MappedFieldTypeValidator.isArrayOfNumbers(mappedField), is(true));
}
use of org.mongodb.morphia.mapping.Mapper in project morphia by mongodb.
the class SizeOperationValidatorTest method shouldAllowSizeOperatorForIterableTypesAndIntegerValues.
@Test
public void shouldAllowSizeOperatorForIterableTypesAndIntegerValues() {
// given
MappedClass mappedClass = new MappedClass(EntityWithListsAndArrays.class, new Mapper());
MappedField mappedField = mappedClass.getMappedField("setOfIntegers");
List<ValidationFailure> validationFailures = new ArrayList<ValidationFailure>();
// when
boolean validationApplied = SizeOperationValidator.getInstance().apply(mappedField, SIZE, 3, 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 IndexHelperTest method createIndex.
@Test
public void createIndex() {
checkMinServerVersion(3.4);
String collectionName = getDs().getCollection(IndexedClass.class).getName();
MongoCollection<Document> collection = getDatabase().getCollection(collectionName);
Mapper mapper = getMorphia().getMapper();
indexHelper.createIndex(collection, mapper.getMappedClass(IndexedClass.class), false);
List<DBObject> indexInfo = getDs().getCollection(IndexedClass.class).getIndexInfo();
assertEquals("Should have 6 indexes", 6, indexInfo.size());
for (DBObject dbObject : indexInfo) {
String name = dbObject.get("name").toString();
if (name.equals("latitude_1")) {
assertEquals(parse("{ 'latitude' : 1 }"), dbObject.get("key"));
} else if (name.equals("behind_interface")) {
assertEquals(parse("{ 'nest.name' : -1} "), dbObject.get("key"));
assertEquals(parse("{ 'locale' : 'en' , 'caseLevel' : false , 'caseFirst' : 'off' , 'strength' : 2 , 'numericOrdering' :" + " false , 'alternate' : 'non-ignorable' , 'maxVariable' : 'punct' , 'normalization' : false , " + "'backwards' : false , 'version' : '57.1'}"), dbObject.get("collation"));
} else if (name.equals("nest.name_1")) {
assertEquals(parse("{ 'nest.name' : 1} "), dbObject.get("key"));
} else if (name.equals("searchme")) {
assertEquals(parse("{ 'text' : 10 }"), dbObject.get("weights"));
} else if (name.equals("indexName_1")) {
assertEquals(parse("{'indexName': 1 }"), dbObject.get("key"));
} else {
if (!"_id_".equals(dbObject.get("name"))) {
throw new MappingException("Found an index I wasn't expecting: " + dbObject);
}
}
}
collection = getDatabase().getCollection(getDs().getCollection(AbstractParent.class).getName());
indexHelper.createIndex(collection, mapper.getMappedClass(AbstractParent.class), false);
indexInfo = getDs().getCollection(AbstractParent.class).getIndexInfo();
assertTrue("Shouldn't find any indexes: " + indexInfo, indexInfo.isEmpty());
}
Aggregations