use of org.springframework.data.mongodb.core.mapping.MongoPersistentProperty in project spring-data-mongodb by spring-projects.
the class PathUnitTests method shouldIdentifyCycle.
// DATAMONGO-962, DATAMONGO-1782
@Test
public void shouldIdentifyCycle() {
MongoPersistentProperty foo = createPersistentPropertyMock(entityMock, "foo");
MongoPersistentProperty bar = createPersistentPropertyMock(entityMock, "bar");
Path path = Path.of(foo).append(bar).append(bar);
assertThat(path.isCycle(), is(true));
assertThat(path.toCyclePath(), is(equalTo("bar -> bar")));
assertThat(path.toString(), is(equalTo("foo -> bar -> bar")));
}
use of org.springframework.data.mongodb.core.mapping.MongoPersistentProperty in project spring-data-mongodb by spring-projects.
the class PathUnitTests method isCycleShouldReturnFalseCycleForNonEqualProperties.
// DATAMONGO-1782
@Test
public void isCycleShouldReturnFalseCycleForNonEqualProperties() {
MongoPersistentProperty foo = createPersistentPropertyMock(entityMock, "foo");
MongoPersistentProperty bar = createPersistentPropertyMock(entityMock, "bar");
MongoPersistentProperty bar2 = createPersistentPropertyMock(mock(MongoPersistentEntity.class), "bar");
assertThat(Path.of(foo).append(bar).append(bar2).isCycle(), is(false));
}
use of org.springframework.data.mongodb.core.mapping.MongoPersistentProperty in project spring-data-mongodb by spring-projects.
the class DbRefMappingMongoConverterUnitTests method shouldEagerlyResolveIdPropertyWithFieldAccess.
// DATAMONGO-1012
@Test
public 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), is(notNullValue()));
assertProxyIsResolved(result.dbRefToConcreteType, false);
}
use of org.springframework.data.mongodb.core.mapping.MongoPersistentProperty in project spring-data-mongodb by spring-projects.
the class DbRefMappingMongoConverterUnitTests method createsDBRefWithClientSpecCorrectly.
// DATAMONGO-347
@Test
public 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(), is("foo"));
assertThat(dbRef.getCollectionName(), is("person"));
}
use of org.springframework.data.mongodb.core.mapping.MongoPersistentProperty in project spring-data-mongodb by spring-projects.
the class DbRefMappingMongoConverterUnitTests method shouldNotEagerlyResolveIdPropertyWithPropertyAccess.
// DATAMONGO-1012
@Test
public 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"), is(nullValue()));
assertProxyIsResolved(proxy, false);
}
Aggregations