Search in sources :

Example 11 with MappingMongoConverter

use of org.springframework.data.mongodb.core.convert.MappingMongoConverter in project spring-data-mongodb by spring-projects.

the class AbstractReactiveMongoConfiguration method mappingMongoConverter.

/**
 * Creates a {@link MappingMongoConverter} using the configured {@link #reactiveMongoDbFactory()} and
 * {@link #mongoMappingContext()}. Will get {@link #customConversions()} applied.
 *
 * @see #customConversions()
 * @see #mongoMappingContext()
 * @see #reactiveMongoDbFactory()
 * @return never {@literal null}.
 * @throws Exception
 */
@Bean
public MappingMongoConverter mappingMongoConverter() throws Exception {
    MappingMongoConverter converter = new MappingMongoConverter(ReactiveMongoTemplate.NO_OP_REF_RESOLVER, mongoMappingContext());
    converter.setCustomConversions(customConversions());
    return converter;
}
Also used : MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) Bean(org.springframework.context.annotation.Bean)

Example 12 with MappingMongoConverter

use of org.springframework.data.mongodb.core.convert.MappingMongoConverter in project spring-data-mongodb by spring-projects.

the class SpelExpressionTransformerIntegrationTests method shouldThrowExceptionIfNestedPropertyCannotBeFound.

// DATAMONGO-774
@Test
public void shouldThrowExceptionIfNestedPropertyCannotBeFound() {
    exception.expect(MappingException.class);
    exception.expectMessage("value2");
    MappingMongoConverter converter = new MappingMongoConverter(dbRefResolver, new MongoMappingContext());
    TypeBasedAggregationOperationContext ctxt = new TypeBasedAggregationOperationContext(Data.class, new MongoMappingContext(), new QueryMapper(converter));
    assertThat(transformer.transform("item.value2", ctxt, new Object[0]).toString(), is("$item.value2"));
}
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 13 with MappingMongoConverter

use of org.springframework.data.mongodb.core.convert.MappingMongoConverter 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(), is("$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 14 with MappingMongoConverter

use of org.springframework.data.mongodb.core.convert.MappingMongoConverter in project spring-data-mongodb by spring-projects.

the class StringBasedMongoQueryUnitTests method setUp.

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

Example 15 with MappingMongoConverter

use of org.springframework.data.mongodb.core.convert.MappingMongoConverter in project spring-data-mongodb by spring-projects.

the class SpringDataMongodbSerializerUnitTests method takesCustomConversionForEnumsIntoAccount.

// DATAMONGO-1485
@Test
public void takesCustomConversionForEnumsIntoAccount() {
    MongoMappingContext context = new MongoMappingContext();
    MappingMongoConverter converter = new MappingMongoConverter(dbFactory, context);
    converter.setCustomConversions(new MongoCustomConversions(Collections.singletonList(new SexTypeWriteConverter())));
    converter.afterPropertiesSet();
    this.converter = converter;
    this.serializer = new SpringDataMongodbSerializer(this.converter);
    Object mappedPredicate = this.serializer.handle(QPerson.person.sex.eq(Sex.FEMALE));
    assertThat(mappedPredicate, is(instanceOf(DBObject.class)));
    assertThat(((DBObject) mappedPredicate).get("sex"), is((Object) "f"));
}
Also used : MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) MongoCustomConversions(org.springframework.data.mongodb.core.convert.MongoCustomConversions) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) Test(org.junit.Test)

Aggregations

MappingMongoConverter (org.springframework.data.mongodb.core.convert.MappingMongoConverter)35 MongoMappingContext (org.springframework.data.mongodb.core.mapping.MongoMappingContext)21 Before (org.junit.Before)19 DefaultDbRefResolver (org.springframework.data.mongodb.core.convert.DefaultDbRefResolver)14 DbRefResolver (org.springframework.data.mongodb.core.convert.DbRefResolver)9 Bean (org.springframework.context.annotation.Bean)7 Test (org.junit.Test)6 Document (org.bson.Document)5 MongoTemplate (org.springframework.data.mongodb.core.MongoTemplate)5 SimpleMongoDbFactory (org.springframework.data.mongodb.core.SimpleMongoDbFactory)5 QueryMapper (org.springframework.data.mongodb.core.convert.QueryMapper)5 MongoDbFactory (org.springframework.data.mongodb.MongoDbFactory)3 MongoCustomConversions (org.springframework.data.mongodb.core.convert.MongoCustomConversions)3 MongoTypeMapper (org.springframework.data.mongodb.core.convert.MongoTypeMapper)3 BasicDBObject (com.mongodb.BasicDBObject)2 MongoClientURI (com.mongodb.MongoClientURI)2 CountOptions (com.mongodb.client.model.CountOptions)2 ClientSession (com.mongodb.session.ClientSession)2 Net (de.flapdoodle.embed.mongo.config.Net)2 BsonValueCodec (org.bson.codecs.BsonValueCodec)2