use of org.springframework.data.mongodb.core.convert.QueryMapper in project spring-data-mongodb by spring-projects.
the class MongoTemplateUnitTests method convertsUpdateConstraintsUsingConverters.
// DATAMONGO-374
@Test
void convertsUpdateConstraintsUsingConverters() {
CustomConversions conversions = new MongoCustomConversions(Collections.singletonList(MyConverter.INSTANCE));
this.converter.setCustomConversions(conversions);
this.converter.afterPropertiesSet();
Query query = new Query();
Update update = new Update().set("foo", new AutogenerateableId());
template.updateFirst(query, update, Wrapper.class);
QueryMapper queryMapper = new QueryMapper(converter);
Document reference = queryMapper.getMappedObject(update.getUpdateObject(), Optional.empty());
verify(collection, times(1)).updateOne(any(org.bson.Document.class), eq(reference), any(UpdateOptions.class));
}
use of org.springframework.data.mongodb.core.convert.QueryMapper in project spring-data-mongodb by spring-projects.
the class AddFieldsOperationUnitTests 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)).continueOnMissingFieldReference();
}
use of org.springframework.data.mongodb.core.convert.QueryMapper in project spring-data-mongodb by spring-projects.
the class CountQueryUnitTests method setUp.
@BeforeEach
void setUp() {
this.context = new MongoMappingContext();
this.converter = new MappingMongoConverter(NoOpDbRefResolver.INSTANCE, context);
this.converter.afterPropertiesSet();
this.mapper = new QueryMapper(converter);
}
use of org.springframework.data.mongodb.core.convert.QueryMapper in project spring-data-mongodb by spring-projects.
the class DefaultBulkOperationsUnitTests method noAfterSaveEventOnFailure.
// DATAMONGO-2290
@Test
void noAfterSaveEventOnFailure() {
ApplicationEventPublisher eventPublisher = mock(ApplicationEventPublisher.class);
when(collection.bulkWrite(anyList(), any(BulkWriteOptions.class))).thenThrow(new MongoWriteException(new WriteError(89, "NetworkTimeout", new BsonDocument("hi", new BsonString("there!"))), null));
ops = new DefaultBulkOperations(template, "collection-1", new BulkOperationContext(BulkMode.ORDERED, Optional.of(mappingContext.getPersistentEntity(Person.class)), new QueryMapper(converter), new UpdateMapper(converter), eventPublisher, null));
ops.insert(new SomeDomainType());
verify(eventPublisher).publishEvent(any(BeforeConvertEvent.class));
try {
ops.execute();
fail("Missing MongoWriteException");
} catch (MongoWriteException expected) {
}
verify(eventPublisher).publishEvent(any(BeforeSaveEvent.class));
}
use of org.springframework.data.mongodb.core.convert.QueryMapper in project spring-data-mongodb by spring-projects.
the class DefaultBulkOperationsUnitTests method setUp.
@BeforeEach
void setUp() {
when(factory.getMongoDatabase()).thenReturn(database);
when(factory.getExceptionTranslator()).thenReturn(new NullExceptionTranslator());
when(database.getCollection(anyString(), eq(Document.class))).thenReturn(collection);
mappingContext = new MongoMappingContext();
mappingContext.afterPropertiesSet();
converter = new MappingMongoConverter(dbRefResolver, mappingContext);
template = new MongoTemplate(factory, converter);
ops = new DefaultBulkOperations(template, "collection-1", new BulkOperationContext(BulkMode.ORDERED, Optional.of(mappingContext.getPersistentEntity(SomeDomainType.class)), new QueryMapper(converter), new UpdateMapper(converter), null, null));
}
Aggregations