Skip to content

Commit bf0449e

Browse files
committed
Polishing.
1 parent c35867e commit bf0449e

2 files changed

Lines changed: 22 additions & 26 deletions

File tree

mongodb/example/pom.xml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,18 @@
4545
</build>
4646

4747
<dependencies>
48+
4849
<dependency>
4950
<groupId>com.fasterxml.jackson.core</groupId>
5051
<artifactId>jackson-databind</artifactId>
5152
</dependency>
52-
<dependency>
53-
<groupId>org.springframework</groupId>
54-
<artifactId>spring-core</artifactId>
55-
<version>7.0.3</version>
56-
</dependency>
53+
5754
<dependency>
5855
<groupId>org.springframework.data.examples</groupId>
5956
<artifactId>spring-data-mongodb-example-utils</artifactId>
6057
<scope>test</scope>
6158
</dependency>
59+
6260
</dependencies>
6361

6462
</project>
Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2025 the original author or authors.
2+
* Copyright 2025-present the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,12 +15,14 @@
1515
*/
1616
package example.springdata.mongodb.bulk;
1717

18-
import static org.assertj.core.api.Assertions.assertThat;
19-
import static org.springframework.data.mongodb.core.query.Criteria.where;
18+
import static org.assertj.core.api.Assertions.*;
19+
import static org.springframework.data.mongodb.core.query.Criteria.*;
2020

2121
import example.springdata.mongodb.util.MongoContainers;
22+
2223
import org.junit.jupiter.api.BeforeEach;
2324
import org.junit.jupiter.api.Test;
25+
2426
import org.springframework.beans.factory.annotation.Autowired;
2527
import org.springframework.boot.data.mongodb.test.autoconfigure.DataMongoTest;
2628
import org.springframework.data.mongodb.core.MongoOperations;
@@ -30,30 +32,29 @@
3032
import org.springframework.data.mongodb.core.query.Update;
3133
import org.springframework.test.context.DynamicPropertyRegistry;
3234
import org.springframework.test.context.DynamicPropertySource;
35+
3336
import org.testcontainers.junit.jupiter.Container;
3437
import org.testcontainers.junit.jupiter.Testcontainers;
3538
import org.testcontainers.mongodb.MongoDBContainer;
3639

3740
/**
38-
* Integration test demonstrating {@link MongoOperations#bulkWrite(Bulk, BulkWriteOptions)} with a combination of
39-
* insert and update operations in a single request.
41+
* Integration test demonstrating {@link MongoOperations#bulkWrite(Bulk, BulkWriteOptions)} with a combination of insert
42+
* and update operations in a single request.
4043
*
4144
* @author Christoph Strobl
4245
*/
4346
@Testcontainers
4447
@DataMongoTest
4548
class BulkWriteIntegrationTest {
4649

47-
@Container
48-
private static MongoDBContainer mongoDBContainer = MongoContainers.getDefaultContainer();
50+
@Container private static MongoDBContainer mongoDBContainer = MongoContainers.getDefaultContainer();
4951

5052
@DynamicPropertySource
5153
static void setProperties(DynamicPropertyRegistry registry) {
5254
registry.add("spring.mongodb.uri", mongoDBContainer::getReplicaSetUrl);
5355
}
5456

55-
@Autowired
56-
MongoOperations operations;
57+
@Autowired MongoOperations operations;
5758

5859
@BeforeEach
5960
void setUp() {
@@ -63,12 +64,12 @@ void setUp() {
6364
@Test
6465
void bulkWriteInsertAndUpdateInOrder() {
6566

66-
Bulk bulk = Bulk.create(builder -> builder.inCollection(Jedi.class, spec -> spec
67-
.insert(new Jedi("Luke", "Skywalker"))
68-
.insert(new Jedi("Leia", "Princess"))
69-
.updateOne(where("firstname").is("Leia"), new Update().set("lastname", "Organa")))
70-
.inCollection(Sith.class, spec -> spec.upsert(where("name").is("Darth Sidious"), Update.update("realName", "Palpatine")))
71-
);
67+
Bulk bulk = Bulk.create(builder -> builder
68+
.inCollection(Jedi.class,
69+
spec -> spec.insert(new Jedi("Luke", "Skywalker")).insert(new Jedi("Leia", "Princess"))
70+
.updateOne(where("firstname").is("Leia"), new Update().set("lastname", "Organa")))
71+
.inCollection(Sith.class,
72+
spec -> spec.upsert(where("name").is("Darth Sidious"), Update.update("realName", "Palpatine"))));
7273

7374
BulkWriteResult result = operations.bulkWrite(bulk, BulkWriteOptions.ordered());
7475

@@ -77,12 +78,9 @@ void bulkWriteInsertAndUpdateInOrder() {
7778
assertThat(result.modifiedCount()).isOne(); // leia
7879
assertThat(result.upsertCount()).isOne(); // darth sidious
7980

80-
assertThat(operations.findAll(Jedi.class))
81-
.extracting(Jedi::fullName)
82-
.containsExactlyInAnyOrder("Luke Skywalker", "Leia Organa");
81+
assertThat(operations.findAll(Jedi.class)).extracting(Jedi::fullName).containsExactlyInAnyOrder("Luke Skywalker",
82+
"Leia Organa");
8383

84-
assertThat(operations.findAll(Sith.class))
85-
.extracting(Sith::name)
86-
.containsExactlyInAnyOrder("Darth Sidious");
84+
assertThat(operations.findAll(Sith.class)).extracting(Sith::name).containsExactlyInAnyOrder("Darth Sidious");
8785
}
8886
}

0 commit comments

Comments
 (0)