Search in sources :

Example 1 with MongoTypeMapper

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

the class MongoOperationsUnitTests method operationsSetUp.

@Before
public final void operationsSetUp() {
    person = new Person("Oliver");
    persons = Arrays.asList(person);
    converter = new AbstractMongoConverter(null) {

        public void write(Object t, Bson bson) {
            ((Document) bson).put("firstName", person.getFirstName());
        }

        @SuppressWarnings("unchecked")
        public <S extends Object> S read(Class<S> clazz, Bson bson) {
            return (S) person;
        }

        public MappingContext<? extends MongoPersistentEntity<?>, MongoPersistentProperty> getMappingContext() {
            return null;
        }

        public Object convertToMongoType(Object obj, TypeInformation<?> typeInformation) {
            return null;
        }

        public DBRef toDBRef(Object object, MongoPersistentProperty referingProperty) {
            return null;
        }

        @Override
        public MongoTypeMapper getTypeMapper() {
            return null;
        }
    };
}
Also used : MongoPersistentProperty(org.springframework.data.mongodb.core.mapping.MongoPersistentProperty) DBRef(com.mongodb.DBRef) AbstractMongoConverter(org.springframework.data.mongodb.core.convert.AbstractMongoConverter) Bson(org.bson.conversions.Bson) MappingContext(org.springframework.data.mapping.context.MappingContext) MongoPersistentEntity(org.springframework.data.mongodb.core.mapping.MongoPersistentEntity) MongoTypeMapper(org.springframework.data.mongodb.core.convert.MongoTypeMapper) Before(org.junit.Before)

Example 2 with MongoTypeMapper

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

the class AbstractMongoConfigurationUnitTests method shouldBeAbleToConfigureCustomTypeMapperViaJavaConfig.

// DATAMONGO-725
@Test
public void shouldBeAbleToConfigureCustomTypeMapperViaJavaConfig() {
    AbstractApplicationContext context = new AnnotationConfigApplicationContext(SampleMongoConfiguration.class);
    MongoTypeMapper typeMapper = context.getBean(CustomMongoTypeMapper.class);
    MappingMongoConverter mmc = context.getBean(MappingMongoConverter.class);
    assertThat(mmc, is(notNullValue()));
    assertThat(mmc.getTypeMapper(), is(typeMapper));
    context.close();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) MongoTypeMapper(org.springframework.data.mongodb.core.convert.MongoTypeMapper) Test(org.junit.Test)

Example 3 with MongoTypeMapper

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

the class AbstractReactiveMongoConfigurationUnitTests method shouldBeAbleToConfigureCustomTypeMapperViaJavaConfig.

// DATAMONGO-1444
@Test
public void shouldBeAbleToConfigureCustomTypeMapperViaJavaConfig() {
    AbstractApplicationContext context = new AnnotationConfigApplicationContext(SampleMongoConfiguration.class);
    MongoTypeMapper typeMapper = context.getBean(CustomMongoTypeMapper.class);
    MappingMongoConverter mmc = context.getBean(MappingMongoConverter.class);
    assertThat(mmc, is(notNullValue()));
    assertThat(mmc.getTypeMapper(), is(typeMapper));
    context.close();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) MongoTypeMapper(org.springframework.data.mongodb.core.convert.MongoTypeMapper) Test(org.junit.Test)

Example 4 with MongoTypeMapper

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

the class MappingMongoConverterParserIntegrationTests method hasCustomTypeMapper.

// DATAMONGO-725
@Test
public void hasCustomTypeMapper() {
    loadValidConfiguration();
    MappingMongoConverter converter = factory.getBean("converter", MappingMongoConverter.class);
    MongoTypeMapper customMongoTypeMapper = factory.getBean(CustomMongoTypeMapper.class);
    assertThat(converter.getTypeMapper(), is(customMongoTypeMapper));
}
Also used : MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) MongoTypeMapper(org.springframework.data.mongodb.core.convert.MongoTypeMapper) Test(org.junit.Test)

Aggregations

MongoTypeMapper (org.springframework.data.mongodb.core.convert.MongoTypeMapper)4 Test (org.junit.Test)3 MappingMongoConverter (org.springframework.data.mongodb.core.convert.MappingMongoConverter)3 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 AbstractApplicationContext (org.springframework.context.support.AbstractApplicationContext)2 DBRef (com.mongodb.DBRef)1 Bson (org.bson.conversions.Bson)1 Before (org.junit.Before)1 MappingContext (org.springframework.data.mapping.context.MappingContext)1 AbstractMongoConverter (org.springframework.data.mongodb.core.convert.AbstractMongoConverter)1 MongoPersistentEntity (org.springframework.data.mongodb.core.mapping.MongoPersistentEntity)1 MongoPersistentProperty (org.springframework.data.mongodb.core.mapping.MongoPersistentProperty)1