use of com.mongodb.DBRef in project spring-data-mongodb by spring-projects.
the class MappingMongoConverterUnitTests method readsDBRefMap.
// DATAMONGO-424
@Test
void readsDBRefMap() {
DBRef dbRef = mock(DBRef.class);
org.bson.Document refMap = new org.bson.Document("foo", dbRef);
org.bson.Document document = new org.bson.Document("refMap", refMap);
DBRefWrapper result = converter.read(DBRefWrapper.class, document);
assertThat(result.refMap.entrySet()).hasSize(1);
assertThat(result.refMap.values()).contains(dbRef);
}
use of com.mongodb.DBRef in project spring-data-mongodb by spring-projects.
the class DbRefMappingMongoConverterUnitTests method createsDBRefWithClientSpecCorrectly.
// DATAMONGO-347
@Test
void createsDBRefWithClientSpecCorrectly() {
PropertyPath path = PropertyPath.from("person", PersonClient.class);
MongoPersistentProperty property = mappingContext.getPersistentPropertyPath(path).getLeafProperty();
Person person = new Person();
person.id = "foo";
DBRef dbRef = converter.toDBRef(person, property);
assertThat(dbRef.getId()).isEqualTo("foo");
assertThat(dbRef.getCollectionName()).isEqualTo("person");
}
use of com.mongodb.DBRef in project spring-data-mongodb by spring-projects.
the class DbRefMappingMongoConverterUnitTests method shouldNotEagerlyResolveIdPropertyWithPropertyAccess.
// DATAMONGO-1012
@Test
void shouldNotEagerlyResolveIdPropertyWithPropertyAccess() {
MongoPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(ClassWithLazyDbRefs.class);
MongoPersistentProperty property = entity.getRequiredPersistentProperty("dbRefToConcreteTypeWithPropertyAccess");
String idValue = new ObjectId().toString();
DBRef dbRef = converter.toDBRef(new LazyDbRefTargetPropertyAccess(idValue), property);
Document object = new Document("dbRefToConcreteTypeWithPropertyAccess", dbRef);
ClassWithLazyDbRefs result = converter.read(ClassWithLazyDbRefs.class, object);
LazyDbRefTargetPropertyAccess proxy = result.dbRefToConcreteTypeWithPropertyAccess;
assertThat(ReflectionTestUtils.getField(proxy, "id")).isNull();
assertProxyIsResolved(proxy, false);
}
use of com.mongodb.DBRef in project spring-data-mongodb by spring-projects.
the class DbRefMappingMongoConverterUnitTests method shouldEagerlyResolveIdPropertyWithFieldAccess.
// DATAMONGO-1012
@Test
void shouldEagerlyResolveIdPropertyWithFieldAccess() {
MongoPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(ClassWithLazyDbRefs.class);
MongoPersistentProperty property = entity.getRequiredPersistentProperty("dbRefToConcreteType");
MongoPersistentEntity<?> propertyEntity = mappingContext.getRequiredPersistentEntity(property);
String idValue = new ObjectId().toString();
DBRef dbRef = converter.toDBRef(new LazyDbRefTarget(idValue), property);
Document object = new Document("dbRefToConcreteType", dbRef);
ClassWithLazyDbRefs result = converter.read(ClassWithLazyDbRefs.class, object);
PersistentPropertyAccessor accessor = propertyEntity.getPropertyAccessor(result.dbRefToConcreteType);
MongoPersistentProperty idProperty = mappingContext.getRequiredPersistentEntity(LazyDbRefTarget.class).getIdProperty();
assertThat(accessor.getProperty(idProperty)).isNotNull();
assertProxyIsResolved(result.dbRefToConcreteType, false);
}
use of com.mongodb.DBRef in project spring-data-mongodb by spring-projects.
the class UpdateMapperUnitTests method updateOnDbrefPropertyOfInterfaceTypeWithoutExplicitGetterForIdShouldBeMappedCorrectly.
// DATAMONGO-897
@Test
void updateOnDbrefPropertyOfInterfaceTypeWithoutExplicitGetterForIdShouldBeMappedCorrectly() {
Update update = new Update().set("referencedDocument", new InterfaceDocumentDefinitionImpl("1", "Foo"));
Document mappedObject = mapper.getMappedObject(update.getUpdateObject(), context.getPersistentEntity(DocumentWithReferenceToInterfaceImpl.class));
Document $set = DocumentTestUtils.getAsDocument(mappedObject, "$set");
Object model = $set.get("referencedDocument");
DBRef expectedDBRef = new DBRef("interfaceDocumentDefinitionImpl", "1");
assertThat(model).isInstanceOf(DBRef.class).isEqualTo(expectedDBRef);
}
Aggregations