use of org.springframework.data.mongodb.core.DefaultBulkOperations.BulkOperationContext 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));
}
use of org.springframework.data.mongodb.core.DefaultBulkOperations.BulkOperationContext in project spring-data-mongodb by spring-projects.
the class DefaultBulkOperationsUnitTests method shouldRetainNestedArrayPathWithPlaceholdersForMappedEntity.
// DATAMONGO-2502
@Test
void shouldRetainNestedArrayPathWithPlaceholdersForMappedEntity() {
DefaultBulkOperations ops = new DefaultBulkOperations(template, "collection-1", new BulkOperationContext(BulkMode.ORDERED, Optional.of(mappingContext.getPersistentEntity(OrderTest.class)), new QueryMapper(converter), new UpdateMapper(converter), null, null));
ops.updateOne(new BasicQuery("{}"), Update.update("items.$.documents.0.fileId", "file-id")).execute();
verify(collection).bulkWrite(captor.capture(), any());
UpdateOneModel<Document> updateModel = (UpdateOneModel<Document>) captor.getValue().get(0);
assertThat(updateModel.getUpdate()).isEqualTo(new Document("$set", new Document("items.$.documents.0.the_file_id", "file-id")));
}
use of org.springframework.data.mongodb.core.DefaultBulkOperations.BulkOperationContext in project spring-data-mongodb by spring-projects.
the class DefaultBulkOperationsIntegrationTests method createBulkOps.
private BulkOperations createBulkOps(BulkMode mode, Class<?> entityType) {
Optional<? extends MongoPersistentEntity<?>> entity = entityType != null ? Optional.of(operations.getConverter().getMappingContext().getPersistentEntity(entityType)) : Optional.empty();
BulkOperationContext bulkOperationContext = new BulkOperationContext(mode, entity, new QueryMapper(operations.getConverter()), new UpdateMapper(operations.getConverter()), null, null);
DefaultBulkOperations bulkOps = new DefaultBulkOperations(operations, COLLECTION_NAME, bulkOperationContext);
bulkOps.setDefaultWriteConcern(WriteConcern.ACKNOWLEDGED);
return bulkOps;
}
Aggregations