use of org.springframework.data.mongodb.core.mapping.MongoMappingContext in project spring-data-mongodb by spring-projects.
the class ProjectionOperationUnitTests method mappedFieldReferenceAsArray.
// DATAMONGO-2312
@Test
void mappedFieldReferenceAsArray() {
MongoMappingContext mappingContext = new MongoMappingContext();
org.bson.Document doc = Aggregation.newAggregation(BookWithFieldAnnotation.class, project("title", "author").asArray("myArray")).toDocument("coll", new TypeBasedAggregationOperationContext(BookWithFieldAnnotation.class, mappingContext, new QueryMapper(new MappingMongoConverter(NoOpDbRefResolver.INSTANCE, mappingContext))));
assertThat(doc).isEqualTo(Document.parse("{\"aggregate\":\"coll\", \"pipeline\":[ { $project: { myArray: [ \"$ti_t_le\", \"$author\" ] } } ] }"));
}
use of org.springframework.data.mongodb.core.mapping.MongoMappingContext in project spring-data-mongodb by spring-projects.
the class MappingMongoConverterTests method setUp.
@BeforeEach
void setUp() {
MongoDatabase database = client.getDatabase(DATABASE);
database.getCollection("samples").deleteMany(new Document());
database.getCollection("java-time-types").deleteMany(new Document());
dbRefResolver = spy(new DefaultDbRefResolver(factory));
mappingContext = new MongoMappingContext();
mappingContext.setSimpleTypeHolder(new MongoCustomConversions(Collections.emptyList()).getSimpleTypeHolder());
mappingContext.setInitialEntitySet(new HashSet<>(Arrays.asList(WithLazyDBRefAsConstructorArg.class, WithLazyDBRef.class, WithJavaTimeTypes.class)));
mappingContext.setAutoIndexCreation(false);
mappingContext.afterPropertiesSet();
converter = new MappingMongoConverter(dbRefResolver, mappingContext);
converter.afterPropertiesSet();
}
use of org.springframework.data.mongodb.core.mapping.MongoMappingContext in project spring-data-mongodb by spring-projects.
the class DbRefMappingMongoConverterUnitTests method setUp.
@BeforeEach
void setUp() {
when(dbFactory.getExceptionTranslator()).thenReturn(new MongoExceptionTranslator());
this.dbRefResolver = spy(new DefaultDbRefResolver(dbFactory));
this.mappingContext = new MongoMappingContext();
this.mappingContext.setSimpleTypeHolder(new MongoCustomConversions(Collections.emptyList()).getSimpleTypeHolder());
this.converter = new MappingMongoConverter(dbRefResolver, mappingContext);
}
use of org.springframework.data.mongodb.core.mapping.MongoMappingContext in project spring-data-mongodb by spring-projects.
the class MongoPersistentEntityIndexResolverUnitTests method prepareMappingContextAndResolveIndexForType.
private static List<IndexDefinitionHolder> prepareMappingContextAndResolveIndexForType(Class<?>... types) {
MongoMappingContext mappingContext = prepareMappingContext(types);
MongoPersistentEntityIndexResolver resolver = new MongoPersistentEntityIndexResolver(mappingContext);
return resolver.resolveIndexForEntity(mappingContext.getRequiredPersistentEntity(types[0]));
}
use of org.springframework.data.mongodb.core.mapping.MongoMappingContext in project spring-data-mongodb by spring-projects.
the class ReactiveMongoPersistentEntityIndexCreatorUnitTests method prepareMappingContext.
private static MongoMappingContext prepareMappingContext(Class<?> type) {
MongoMappingContext mappingContext = new MongoMappingContext();
mappingContext.setInitialEntitySet(Collections.singleton(type));
mappingContext.initialize();
return mappingContext;
}
Aggregations