Skip to content

Commit cde185c

Browse files
committed
Update MongoDB support tests
1 parent 0b1d920 commit cde185c

File tree

3 files changed

+20
-28
lines changed

3 files changed

+20
-28
lines changed

spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/MongoDBJobExplorerIntegrationTests.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
*/
1616
package org.springframework.batch.core.repository.support;
1717

18+
import java.io.IOException;
19+
import java.nio.file.Files;
1820
import java.time.LocalDateTime;
19-
import java.util.Map;
2021

21-
import org.bson.Document;
2222
import org.junit.jupiter.api.BeforeAll;
2323
import org.junit.jupiter.api.Test;
2424
import org.springframework.batch.core.job.Job;
@@ -29,6 +29,8 @@
2929
import org.springframework.batch.core.step.StepExecution;
3030
import org.springframework.batch.core.launch.JobOperator;
3131
import org.springframework.beans.factory.annotation.Autowired;
32+
import org.springframework.core.io.FileSystemResource;
33+
import org.springframework.core.io.Resource;
3234
import org.springframework.data.mongodb.core.MongoTemplate;
3335
import org.springframework.test.annotation.DirtiesContext;
3436
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
@@ -51,17 +53,10 @@ public class MongoDBJobExplorerIntegrationTests {
5153
private JobRepository jobRepository;
5254

5355
@BeforeAll
54-
static void setUp(@Autowired MongoTemplate mongoTemplate) {
55-
mongoTemplate.createCollection("BATCH_JOB_INSTANCE");
56-
mongoTemplate.createCollection("BATCH_JOB_EXECUTION");
57-
mongoTemplate.createCollection("BATCH_STEP_EXECUTION");
58-
mongoTemplate.createCollection("BATCH_SEQUENCES");
59-
mongoTemplate.getCollection("BATCH_SEQUENCES")
60-
.insertOne(new Document(Map.of("_id", "BATCH_JOB_INSTANCE_SEQ", "count", 0L)));
61-
mongoTemplate.getCollection("BATCH_SEQUENCES")
62-
.insertOne(new Document(Map.of("_id", "BATCH_JOB_EXECUTION_SEQ", "count", 0L)));
63-
mongoTemplate.getCollection("BATCH_SEQUENCES")
64-
.insertOne(new Document(Map.of("_id", "BATCH_STEP_EXECUTION_SEQ", "count", 0L)));
56+
static void setUp(@Autowired MongoTemplate mongoTemplate) throws IOException {
57+
Resource resource = new FileSystemResource(
58+
"src/main/resources/org/springframework/batch/core/schema-mongodb.jsonl");
59+
Files.lines(resource.getFilePath()).forEach(line -> mongoTemplate.executeCommand(line));
6560
}
6661

6762
@Test

spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/MongoDBJobRepositoryIntegrationTests.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
import org.springframework.batch.core.job.parameters.JobParametersBuilder;
3434
import org.springframework.batch.core.launch.JobOperator;
3535
import org.springframework.beans.factory.annotation.Autowired;
36-
import org.springframework.core.io.ClassPathResource;
36+
import org.springframework.core.io.FileSystemResource;
37+
import org.springframework.core.io.Resource;
3738
import org.springframework.data.mongodb.core.MongoTemplate;
3839
import org.springframework.test.annotation.DirtiesContext;
3940
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
@@ -52,7 +53,8 @@ public class MongoDBJobRepositoryIntegrationTests {
5253

5354
@BeforeEach
5455
public void setUp() throws IOException {
55-
ClassPathResource resource = new ClassPathResource("org/springframework/batch/core/schema-mongodb.jsonl");
56+
Resource resource = new FileSystemResource(
57+
"src/main/resources/org/springframework/batch/core/schema-mongodb.jsonl");
5658
Files.lines(resource.getFilePath()).forEach(line -> mongoTemplate.executeCommand(line));
5759
}
5860

spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/MongoExecutionContextDaoIntegrationTests.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
*/
1616
package org.springframework.batch.core.repository.support;
1717

18+
import java.io.IOException;
19+
import java.nio.file.Files;
1820
import java.time.LocalDateTime;
19-
import java.util.Map;
2021

21-
import org.bson.Document;
2222
import org.junit.jupiter.api.BeforeAll;
2323
import org.junit.jupiter.api.Test;
2424
import org.springframework.batch.core.job.Job;
@@ -35,6 +35,8 @@
3535
import org.springframework.beans.factory.annotation.Autowired;
3636
import org.springframework.context.annotation.Bean;
3737
import org.springframework.context.annotation.Configuration;
38+
import org.springframework.core.io.FileSystemResource;
39+
import org.springframework.core.io.Resource;
3840
import org.springframework.data.mongodb.core.MongoOperations;
3941
import org.springframework.data.mongodb.core.MongoTemplate;
4042
import org.springframework.test.annotation.DirtiesContext;
@@ -55,17 +57,10 @@
5557
public class MongoExecutionContextDaoIntegrationTests {
5658

5759
@BeforeAll
58-
static void setUp(@Autowired MongoTemplate mongoTemplate) {
59-
mongoTemplate.createCollection("BATCH_JOB_INSTANCE");
60-
mongoTemplate.createCollection("BATCH_JOB_EXECUTION");
61-
mongoTemplate.createCollection("BATCH_STEP_EXECUTION");
62-
mongoTemplate.createCollection("BATCH_SEQUENCES");
63-
mongoTemplate.getCollection("BATCH_SEQUENCES")
64-
.insertOne(new Document(Map.of("_id", "BATCH_JOB_INSTANCE_SEQ", "count", 0L)));
65-
mongoTemplate.getCollection("BATCH_SEQUENCES")
66-
.insertOne(new Document(Map.of("_id", "BATCH_JOB_EXECUTION_SEQ", "count", 0L)));
67-
mongoTemplate.getCollection("BATCH_SEQUENCES")
68-
.insertOne(new Document(Map.of("_id", "BATCH_STEP_EXECUTION_SEQ", "count", 0L)));
60+
static void setUp(@Autowired MongoTemplate mongoTemplate) throws IOException {
61+
Resource resource = new FileSystemResource(
62+
"src/main/resources/org/springframework/batch/core/schema-mongodb.jsonl");
63+
Files.lines(resource.getFilePath()).forEach(line -> mongoTemplate.executeCommand(line));
6964
}
7065

7166
@Test

0 commit comments

Comments
 (0)