use of org.springframework.data.mongodb.core.mapping.MongoMappingContext in project spring-data-mongodb by spring-projects.
the class MongoPersistentEntityIndexCreatorUnitTests method createIndexShouldUsePersistenceExceptionTranslatorForNonDataIntegrityConcerns.
// DATAMONGO-1125
@Test
void createIndexShouldUsePersistenceExceptionTranslatorForNonDataIntegrityConcerns() {
doThrow(new MongoException(6, "HostUnreachable")).when(collection).createIndex(any(org.bson.Document.class), any(IndexOptions.class));
MongoMappingContext mappingContext = prepareMappingContext(Person.class);
assertThatThrownBy(() -> new MongoPersistentEntityIndexCreator(mappingContext, mongoTemplate)).isInstanceOf(DataAccessException.class);
}
use of org.springframework.data.mongodb.core.mapping.MongoMappingContext in project spring-data-mongodb by spring-projects.
the class MongoPersistentEntityIndexCreatorUnitTests method indexCreationShouldNotCreateNewCollectionForNestedGeoSpatialIndexStructures.
// DATAMONGO-367
@Test
void indexCreationShouldNotCreateNewCollectionForNestedGeoSpatialIndexStructures() {
MongoMappingContext mappingContext = prepareMappingContext(Wrapper.class);
new MongoPersistentEntityIndexCreator(mappingContext, mongoTemplate);
ArgumentCaptor<String> collectionNameCapturer = ArgumentCaptor.forClass(String.class);
verify(db, times(1)).getCollection(collectionNameCapturer.capture(), any());
assertThat(collectionNameCapturer.getValue()).isEqualTo("wrapper");
}
use of org.springframework.data.mongodb.core.mapping.MongoMappingContext in project spring-data-mongodb by spring-projects.
the class UnsetOperationUnitTests method contextFor.
private static AggregationOperationContext contextFor(@Nullable Class<?> type) {
if (type == null) {
return Aggregation.DEFAULT_CONTEXT;
}
MappingMongoConverter mongoConverter = new MappingMongoConverter(NoOpDbRefResolver.INSTANCE, new MongoMappingContext());
mongoConverter.afterPropertiesSet();
return new TypeBasedAggregationOperationContext(type, mongoConverter.getMappingContext(), new QueryMapper(mongoConverter));
}
use of org.springframework.data.mongodb.core.mapping.MongoMappingContext in project spring-data-mongodb by spring-projects.
the class ProjectionOperationUnitTests method typeProjectionShouldMapFieldNames.
// DATAMONGO-2200
@Test
void typeProjectionShouldMapFieldNames() {
MongoMappingContext mappingContext = new MongoMappingContext();
MongoConverter converter = new MappingMongoConverter(NoOpDbRefResolver.INSTANCE, mappingContext);
Document document = Aggregation.project(BookRenamed.class).toDocument(new TypeBasedAggregationOperationContext(Book.class, mappingContext, new QueryMapper(converter)));
Document projectClause = DocumentTestUtils.getAsDocument(document, PROJECT);
//
assertThat(projectClause).hasSize(//
2).containsEntry("ti_tl_e", //
1).containsEntry("author", 1);
}
use of org.springframework.data.mongodb.core.mapping.MongoMappingContext in project spring-data-mongodb by spring-projects.
the class GeoNearOperationUnitTests method typedAggregationOperationContext.
private TypeBasedAggregationOperationContext typedAggregationOperationContext(Class<?> type) {
MongoMappingContext mappingContext = new MongoMappingContext();
MongoConverter converter = new MappingMongoConverter(NoOpDbRefResolver.INSTANCE, mappingContext);
return new TypeBasedAggregationOperationContext(type, mappingContext, new QueryMapper(converter));
}
Aggregations