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;
}
use of org.springframework.data.mongodb.core.mapping.MongoMappingContext in project spring-data-mongodb by spring-projects.
the class UpdateMapperUnitTests method mappingShouldConsiderCustomConvertersForEnumMapKeys.
// DATAMONGO-1423, DATAMONGO-2155
@Test
@SuppressWarnings("unchecked")
void mappingShouldConsiderCustomConvertersForEnumMapKeys() {
CustomConversions conversions = new MongoCustomConversions(Arrays.asList(ClassWithEnum.AllocationToStringConverter.INSTANCE, ClassWithEnum.StringToAllocationConverter.INSTANCE));
MongoMappingContext mappingContext = new MongoMappingContext();
mappingContext.setSimpleTypeHolder(conversions.getSimpleTypeHolder());
mappingContext.afterPropertiesSet();
MappingMongoConverter converter = new MappingMongoConverter(mock(DbRefResolver.class), mappingContext);
converter.setCustomConversions(conversions);
converter.afterPropertiesSet();
UpdateMapper mapper = new UpdateMapper(converter);
Update update = new Update().set("enumAsMapKey", Collections.singletonMap(ClassWithEnum.Allocation.AVAILABLE, 100));
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(), mappingContext.getPersistentEntity(ClassWithEnum.class));
Document $set = DocumentTestUtils.getAsDocument(mappedUpdate, "$set");
assertThat($set.containsKey("enumAsMapKey")).isTrue();
Map enumAsMapKey = $set.get("enumAsMapKey", Map.class);
assertThat(enumAsMapKey.get("V")).isEqualTo(100);
}
Aggregations