Search in sources :

Example 11 with MongoMappingContext

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

the class ReactiveMongoTemplateIndexTests method setUp.

@BeforeEach
void setUp() {
    factory = new SimpleReactiveMongoDatabaseFactory(client, "reactive-template-index-tests");
    MongoMappingContext mappingContext = new MongoMappingContext();
    mappingContext.setAutoIndexCreation(true);
    template = new ReactiveMongoTemplate(factory, new MappingMongoConverter(NoOpDbRefResolver.INSTANCE, mappingContext));
    MongoTestUtils.dropCollectionNow("reactive-template-index-tests", "person", client);
    MongoTestUtils.dropCollectionNow("reactive-template-index-tests", "indexfail", client);
    MongoTestUtils.dropCollectionNow("reactive-template-index-tests", "indexedSample", client);
}
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 12 with MongoMappingContext

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

the class ReactiveSessionBoundMongoTemplateUnitTests method setUp.

@Before
public void setUp() {
    when(client.getDatabase(anyString())).thenReturn(database);
    when(codecRegistry.get(any(Class.class))).thenReturn(new BsonValueCodec());
    when(database.getCodecRegistry()).thenReturn(codecRegistry);
    when(database.getCollection(anyString())).thenReturn(collection);
    when(database.getCollection(anyString(), any())).thenReturn(collection);
    when(database.listCollectionNames(any(ClientSession.class))).thenReturn(findPublisher);
    when(database.createCollection(any(ClientSession.class), any(), any())).thenReturn(resultPublisher);
    when(database.runCommand(any(ClientSession.class), any(), any(Class.class))).thenReturn(resultPublisher);
    when(collection.find(any(ClientSession.class))).thenReturn(findPublisher);
    when(collection.find(any(ClientSession.class), any(Document.class))).thenReturn(findPublisher);
    when(collection.find(any(ClientSession.class), any(Class.class))).thenReturn(findPublisher);
    when(collection.find(any(ClientSession.class), any(), any())).thenReturn(findPublisher);
    when(collection.deleteMany(any(ClientSession.class), any(), any())).thenReturn(resultPublisher);
    when(collection.insertOne(any(ClientSession.class), any(Document.class))).thenReturn(resultPublisher);
    when(collection.aggregate(any(ClientSession.class), anyList(), any(Class.class))).thenReturn(aggregatePublisher);
    when(collection.countDocuments(any(ClientSession.class), any(), any(CountOptions.class))).thenReturn(resultPublisher);
    when(collection.drop(any(ClientSession.class))).thenReturn(resultPublisher);
    when(collection.findOneAndUpdate(any(ClientSession.class), any(), any(Bson.class), any())).thenReturn(resultPublisher);
    when(collection.distinct(any(ClientSession.class), any(), any(Bson.class), any())).thenReturn(distinctPublisher);
    when(collection.updateOne(any(ClientSession.class), any(), any(Bson.class), any(UpdateOptions.class))).thenReturn(resultPublisher);
    when(collection.updateMany(any(ClientSession.class), any(), any(Bson.class), any(UpdateOptions.class))).thenReturn(resultPublisher);
    when(collection.dropIndex(any(ClientSession.class), anyString())).thenReturn(resultPublisher);
    when(collection.mapReduce(any(ClientSession.class), any(), any(), any())).thenReturn(mapReducePublisher);
    when(findPublisher.projection(any())).thenReturn(findPublisher);
    when(findPublisher.limit(anyInt())).thenReturn(findPublisher);
    when(findPublisher.collation(any())).thenReturn(findPublisher);
    when(findPublisher.first()).thenReturn(resultPublisher);
    when(aggregatePublisher.allowDiskUse(anyBoolean())).thenReturn(aggregatePublisher);
    factory = new SimpleReactiveMongoDatabaseFactory(client, "foo");
    this.mappingContext = new MongoMappingContext();
    this.converter = new MappingMongoConverter(NoOpDbRefResolver.INSTANCE, mappingContext);
    this.template = new ReactiveSessionBoundMongoTemplate(clientSession, new ReactiveMongoTemplate(factory, converter));
}
Also used : BsonValueCodec(org.bson.codecs.BsonValueCodec) ClientSession(com.mongodb.reactivestreams.client.ClientSession) MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) CountOptions(com.mongodb.client.model.CountOptions) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) Document(org.bson.Document) FindOneAndUpdateOptions(com.mongodb.client.model.FindOneAndUpdateOptions) UpdateOptions(com.mongodb.client.model.UpdateOptions) ReactiveSessionBoundMongoTemplate(org.springframework.data.mongodb.core.ReactiveMongoTemplate.ReactiveSessionBoundMongoTemplate) Bson(org.bson.conversions.Bson) Before(org.junit.Before)

Example 13 with MongoMappingContext

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

the class FilterExpressionUnitTests method setUp.

@BeforeEach
void setUp() {
    mappingContext = new MongoMappingContext();
    aggregationContext = new TypeBasedAggregationOperationContext(Sales.class, mappingContext, new QueryMapper(new MappingMongoConverter(NoOpDbRefResolver.INSTANCE, mappingContext)));
}
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) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 14 with MongoMappingContext

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

the class SpelExpressionTransformerIntegrationTests method shouldConvertCompoundExpressionToPropertyPath.

// DATAMONGO-774
@Test
public void shouldConvertCompoundExpressionToPropertyPath() {
    MappingMongoConverter converter = new MappingMongoConverter(dbRefResolver, new MongoMappingContext());
    TypeBasedAggregationOperationContext ctxt = new TypeBasedAggregationOperationContext(Data.class, new MongoMappingContext(), new QueryMapper(converter));
    assertThat(transformer.transform("item.primitiveIntValue", ctxt, new Object[0]).toString()).isEqualTo("$item.primitiveIntValue");
}
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) Test(org.junit.Test)

Example 15 with MongoMappingContext

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

the class SpelExpressionTransformerIntegrationTests method shouldThrowExceptionIfNestedPropertyCannotBeFound.

// DATAMONGO-774
@Test
public void shouldThrowExceptionIfNestedPropertyCannotBeFound() {
    MappingMongoConverter converter = new MappingMongoConverter(dbRefResolver, new MongoMappingContext());
    TypeBasedAggregationOperationContext ctxt = new TypeBasedAggregationOperationContext(Data.class, new MongoMappingContext(), new QueryMapper(converter));
    assertThatExceptionOfType(InvalidPersistentPropertyPath.class).isThrownBy(() -> {
        transformer.transform("item.value2", ctxt, new Object[0]).toString();
    });
}
Also used : InvalidPersistentPropertyPath(org.springframework.data.mapping.context.InvalidPersistentPropertyPath) MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) QueryMapper(org.springframework.data.mongodb.core.convert.QueryMapper) Test(org.junit.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