use of org.springframework.data.mongodb.core.mapping.MongoPersistentProperty in project spring-data-mongodb by spring-projects.
the class ReactivePerformanceTests method setUp.
@Before
public void setUp() throws Exception {
mongo = MongoClients.create();
SimpleReactiveMongoDatabaseFactory mongoDbFactory = new SimpleReactiveMongoDatabaseFactory(this.mongo, DATABASE_NAME);
MongoMappingContext context = new MongoMappingContext();
context.setInitialEntitySet(Collections.singleton(Person.class));
context.afterPropertiesSet();
converter = new MappingMongoConverter(new DbRefResolver() {
@Override
public Object resolveDbRef(MongoPersistentProperty property, DBRef dbref, DbRefResolverCallback callback, DbRefProxyHandler proxyHandler) {
return null;
}
@Override
public DBRef createDbRef(org.springframework.data.mongodb.core.mapping.DBRef annotation, MongoPersistentEntity<?> entity, Object id) {
return null;
}
@Override
public Document fetch(DBRef dbRef) {
return null;
}
@Override
public List<Document> bulkFetch(List<DBRef> dbRefs) {
return null;
}
}, context);
operations = new ReactiveMongoTemplate(mongoDbFactory, converter);
ReactiveMongoRepositoryFactory factory = new ReactiveMongoRepositoryFactory(operations);
repository = factory.getRepository(ReactivePersonRepository.class);
}
use of org.springframework.data.mongodb.core.mapping.MongoPersistentProperty in project spring-data-mongodb by spring-projects.
the class PathUnitTests method isCycleShouldReturnFalseWhenNoCyclePresent.
// DATAMONGO-1782
@Test
public void isCycleShouldReturnFalseWhenNoCyclePresent() {
MongoPersistentProperty foo = createPersistentPropertyMock(entityMock, "foo");
MongoPersistentProperty bar = createPersistentPropertyMock(entityMock, "bar");
Path path = Path.of(foo).append(bar);
assertThat(path.isCycle(), is(false));
assertThat(path.toCyclePath(), is(equalTo("")));
assertThat(path.toString(), is(equalTo("foo -> bar")));
}
use of org.springframework.data.mongodb.core.mapping.MongoPersistentProperty in project spring-data-mongodb by spring-projects.
the class PathUnitTests method createPersistentPropertyMock.
@SuppressWarnings({ "rawtypes", "unchecked" })
private static MongoPersistentProperty createPersistentPropertyMock(MongoPersistentEntity owner, String fieldname) {
MongoPersistentProperty property = Mockito.mock(MongoPersistentProperty.class);
when(property.getOwner()).thenReturn(owner);
when(property.getName()).thenReturn(fieldname);
return property;
}
use of org.springframework.data.mongodb.core.mapping.MongoPersistentProperty in project spring-data-mongodb by spring-projects.
the class DbRefMappingMongoConverterUnitTests method shouldNotTriggerResolvingOfLazyLoadedProxyWhenFinalizeMethodIsInvoked.
// DATAMONGO-1076
@Test
public void shouldNotTriggerResolvingOfLazyLoadedProxyWhenFinalizeMethodIsInvoked() throws Exception {
MongoPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(WithObjectMethodOverrideLazyDbRefs.class);
MongoPersistentProperty property = entity.getRequiredPersistentProperty("dbRefToPlainObject");
String idValue = new ObjectId().toString();
DBRef dbRef = converter.toDBRef(new LazyDbRefTargetPropertyAccess(idValue), property);
WithObjectMethodOverrideLazyDbRefs result = converter.read(WithObjectMethodOverrideLazyDbRefs.class, new Document("dbRefToPlainObject", dbRef));
ReflectionTestUtils.invokeMethod(result.dbRefToPlainObject, "finalize");
assertProxyIsResolved(result.dbRefToPlainObject, false);
}
use of org.springframework.data.mongodb.core.mapping.MongoPersistentProperty in project spring-data-mongodb by spring-projects.
the class MappingMongoConverterUnitTests method eagerlyReturnsDBRefObjectIfTargetAlreadyIsOne.
// DATAMGONGO-508
@Test
public void eagerlyReturnsDBRefObjectIfTargetAlreadyIsOne() {
DBRef dbRef = new DBRef("collection", "id");
MongoPersistentProperty property = mock(MongoPersistentProperty.class);
assertThat(converter.createDBRef(dbRef, property), is(dbRef));
}
Aggregations