Search in sources :

Example 31 with MongoMappingContext

use of org.springframework.data.mongodb.core.mapping.MongoMappingContext in project spring-data-mongodb by spring-projects.

the class ReactiveStringBasedAggregationUnitTests method setUp.

@BeforeEach
public void setUp() {
    converter = new MappingMongoConverter(dbRefResolver, new MongoMappingContext());
    when(operations.getConverter()).thenReturn(converter);
    when(operations.aggregate(any(TypedAggregation.class), any())).thenReturn(Flux.empty());
    when(operations.execute(any())).thenReturn(Flux.empty());
}
Also used : MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) TypedAggregation(org.springframework.data.mongodb.core.aggregation.TypedAggregation) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 32 with MongoMappingContext

use of org.springframework.data.mongodb.core.mapping.MongoMappingContext in project spring-data-mongodb by spring-projects.

the class PartTreeMongoQueryUnitTests method setUp.

@BeforeEach
void setUp() {
    mappingContext = new MongoMappingContext();
    MongoConverter converter = new MappingMongoConverter(NoOpDbRefResolver.INSTANCE, mappingContext);
    doReturn(converter).when(mongoOperationsMock).getConverter();
    doReturn(findOperationMock).when(mongoOperationsMock).query(any());
}
Also used : MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) MongoConverter(org.springframework.data.mongodb.core.convert.MongoConverter) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 33 with MongoMappingContext

use of org.springframework.data.mongodb.core.mapping.MongoMappingContext in project spring-data-mongodb by spring-projects.

the class StringBasedMongoQueryUnitTests method setUp.

@BeforeEach
public void setUp() {
    this.converter = new MappingMongoConverter(factory, new MongoMappingContext());
    doReturn(findOperation).when(operations).query(any());
    doReturn(MongoClientSettings.getDefaultCodecRegistry()).when(operations).execute(any());
}
Also used : MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 34 with MongoMappingContext

use of org.springframework.data.mongodb.core.mapping.MongoMappingContext in project spring-data-mongodb by spring-projects.

the class SessionBoundMongoTemplateTests method getDefaultMongoConverter.

private MongoConverter getDefaultMongoConverter(MongoDatabaseFactory factory) {
    DbRefResolver dbRefResolver = new DefaultDbRefResolver(factory);
    MongoCustomConversions conversions = new MongoCustomConversions(Collections.emptyList());
    MongoMappingContext mappingContext = new MongoMappingContext();
    mappingContext.setSimpleTypeHolder(conversions.getSimpleTypeHolder());
    mappingContext.afterPropertiesSet();
    MappingMongoConverter converter = new MappingMongoConverter(dbRefResolver, mappingContext);
    converter.setCustomConversions(conversions);
    converter.setCodecRegistryProvider(factory);
    converter.afterPropertiesSet();
    return converter;
}
Also used : DefaultDbRefResolver(org.springframework.data.mongodb.core.convert.DefaultDbRefResolver) MongoCustomConversions(org.springframework.data.mongodb.core.convert.MongoCustomConversions) MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) DbRefResolver(org.springframework.data.mongodb.core.convert.DbRefResolver) DefaultDbRefResolver(org.springframework.data.mongodb.core.convert.DefaultDbRefResolver)

Example 35 with MongoMappingContext

use of org.springframework.data.mongodb.core.mapping.MongoMappingContext in project spring-data-mongodb by spring-projects.

the class AggregationUnitTests method shouldNotConvertIncludeExcludeValuesForProjectOperation.

// GH-3898
@Test
void shouldNotConvertIncludeExcludeValuesForProjectOperation() {
    MongoMappingContext mappingContext = new MongoMappingContext();
    RelaxedTypeBasedAggregationOperationContext context = new RelaxedTypeBasedAggregationOperationContext(WithRetypedIdField.class, mappingContext, new QueryMapper(new MappingMongoConverter(NoOpDbRefResolver.INSTANCE, mappingContext)));
    Document document = project(WithRetypedIdField.class).toDocument(context);
    assertThat(document).isEqualTo(new Document("$project", new Document("_id", 1).append("renamed-field", 1)));
}
Also used : MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) QueryMapper(org.springframework.data.mongodb.core.convert.QueryMapper) Document(org.bson.Document) Test(org.junit.jupiter.api.Test)

Aggregations

MongoMappingContext (org.springframework.data.mongodb.core.mapping.MongoMappingContext)118 MappingMongoConverter (org.springframework.data.mongodb.core.convert.MappingMongoConverter)56 Test (org.junit.jupiter.api.Test)41 BeforeEach (org.junit.jupiter.api.BeforeEach)31 Document (org.bson.Document)19 QueryMapper (org.springframework.data.mongodb.core.convert.QueryMapper)19 DefaultDbRefResolver (org.springframework.data.mongodb.core.convert.DefaultDbRefResolver)13 MongoCustomConversions (org.springframework.data.mongodb.core.convert.MongoCustomConversions)10 Bson (org.bson.conversions.Bson)8 Before (org.junit.Before)8 Test (org.junit.Test)8 MongoTemplate (org.springframework.data.mongodb.core.MongoTemplate)8 IndexOptions (com.mongodb.client.model.IndexOptions)7 CustomConversions (org.springframework.data.convert.CustomConversions)6 DbRefResolver (org.springframework.data.mongodb.core.convert.DbRefResolver)6 Document (org.springframework.data.mongodb.core.mapping.Document)6 Set (java.util.Set)5 MongoDbFactory (org.springframework.data.mongodb.MongoDbFactory)5 CountOptions (com.mongodb.client.model.CountOptions)4 List (java.util.List)4