Skip to content

Commit f64d674

Browse files
committed
test: migrate to testcontainers v2 and Beam tests to Junit Jupiter
1 parent c22593f commit f64d674

File tree

10 files changed

+107
-89
lines changed

10 files changed

+107
-89
lines changed

core/pom.xml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
<artifactId>beam-sdks-java-io-jdbc</artifactId>
3030
<scope>test</scope>
3131
</dependency>
32+
<dependency>
33+
<groupId>org.apache.beam</groupId>
34+
<artifactId>beam-sdks-java-testing-junit</artifactId>
35+
<scope>test</scope>
36+
</dependency>
3237
<dependency>
3338
<groupId>org.assertj</groupId>
3439
<artifactId>assertj-core</artifactId>
@@ -67,22 +72,22 @@
6772
</dependency>
6873
<dependency>
6974
<groupId>org.testcontainers</groupId>
70-
<artifactId>junit-jupiter</artifactId>
75+
<artifactId>testcontainers</artifactId>
7176
<scope>test</scope>
7277
</dependency>
7378
<dependency>
7479
<groupId>org.testcontainers</groupId>
75-
<artifactId>neo4j</artifactId>
80+
<artifactId>testcontainers-junit-jupiter</artifactId>
7681
<scope>test</scope>
7782
</dependency>
7883
<dependency>
7984
<groupId>org.testcontainers</groupId>
80-
<artifactId>postgresql</artifactId>
85+
<artifactId>testcontainers-neo4j</artifactId>
8186
<scope>test</scope>
8287
</dependency>
8388
<dependency>
8489
<groupId>org.testcontainers</groupId>
85-
<artifactId>testcontainers</artifactId>
90+
<artifactId>testcontainers-postgresql</artifactId>
8691
<scope>test</scope>
8792
</dependency>
8893
</dependencies>

core/src/test/java/org/neo4j/importer/v1/e2e/AdminImportIT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,17 @@
5555
import org.neo4j.importer.v1.targets.Target;
5656
import org.neo4j.importer.v1.targets.Targets;
5757
import org.testcontainers.containers.BindMode;
58-
import org.testcontainers.containers.Neo4jContainer;
5958
import org.testcontainers.junit.jupiter.Container;
6059
import org.testcontainers.junit.jupiter.Testcontainers;
60+
import org.testcontainers.neo4j.Neo4jContainer;
6161
import org.testcontainers.utility.DockerImageName;
6262
import org.testcontainers.utility.MountableFile;
6363

6464
@Testcontainers
6565
public class AdminImportIT {
6666

6767
@Container
68-
private static final Neo4jContainer<?> NEO4J = new Neo4jContainer<>(DockerImageName.parse("neo4j:5-enterprise"))
68+
private static final Neo4jContainer NEO4J = new Neo4jContainer(DockerImageName.parse("neo4j:5-enterprise"))
6969
.withEnv("NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes")
7070
.withAdminPassword("letmein!")
7171
.withCreateContainerCmdModifier(cmd -> cmd.withUser("neo4j"))
@@ -325,7 +325,7 @@ private static NodeKeyConstraint singleNodeKey(NodeTarget nodeTarget) {
325325
}
326326

327327
public static void executeImport(
328-
Neo4jContainer<?> neo4j, Driver driver, ImportSpecification importSpec, String neo4jDatabase)
328+
Neo4jContainer neo4j, Driver driver, ImportSpecification importSpec, String neo4jDatabase)
329329
throws Exception {
330330

331331
var command = importCommand(importSpec, neo4jDatabase);

core/src/test/java/org/neo4j/importer/v1/e2e/BeamIT.java

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.apache.beam.sdk.io.jdbc.JdbcIO.DataSourceConfiguration;
3434
import org.apache.beam.sdk.schemas.SchemaCoder;
3535
import org.apache.beam.sdk.testing.TestPipeline;
36+
import org.apache.beam.sdk.testing.TestPipelineExtension;
3637
import org.apache.beam.sdk.transforms.Create;
3738
import org.apache.beam.sdk.transforms.DoFn;
3839
import org.apache.beam.sdk.transforms.PTransform;
@@ -43,11 +44,10 @@
4344
import org.apache.beam.sdk.values.Row;
4445
import org.assertj.core.api.Assertions;
4546
import org.jetbrains.annotations.NotNull;
46-
import org.junit.After;
47-
import org.junit.Before;
48-
import org.junit.ClassRule;
49-
import org.junit.Rule;
50-
import org.junit.Test;
47+
import org.junit.jupiter.api.AfterEach;
48+
import org.junit.jupiter.api.BeforeEach;
49+
import org.junit.jupiter.api.Test;
50+
import org.junit.jupiter.api.extension.ExtendWith;
5151
import org.neo4j.driver.AuthTokens;
5252
import org.neo4j.driver.Driver;
5353
import org.neo4j.driver.GraphDatabase;
@@ -68,28 +68,29 @@
6868
import org.neo4j.importer.v1.sources.JdbcSource;
6969
import org.neo4j.importer.v1.sources.Source;
7070
import org.neo4j.importer.v1.targets.PropertyMapping;
71-
import org.testcontainers.containers.Neo4jContainer;
72-
import org.testcontainers.containers.PostgreSQLContainer;
71+
import org.testcontainers.junit.jupiter.Container;
72+
import org.testcontainers.junit.jupiter.Testcontainers;
73+
import org.testcontainers.neo4j.Neo4jContainer;
74+
import org.testcontainers.postgresql.PostgreSQLContainer;
7375
import org.testcontainers.utility.DockerImageName;
7476

77+
@ExtendWith(TestPipelineExtension.class)
78+
@Testcontainers
7579
public class BeamIT {
7680

77-
@Rule
78-
public final TestPipeline pipeline = TestPipeline.create();
79-
80-
@ClassRule
81-
public static Neo4jContainer<?> NEO4J = new Neo4jContainer<>(DockerImageName.parse("neo4j:5-enterprise"))
81+
@Container
82+
public static Neo4jContainer NEO4J = new Neo4jContainer(DockerImageName.parse("neo4j:5-enterprise"))
8283
.withEnv("NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes")
8384
.withAdminPassword("letmein!");
8485

85-
@ClassRule
86-
public static PostgreSQLContainer<?> POSTGRES = new PostgreSQLContainer<>(DockerImageName.parse("postgres:16.2"))
86+
@Container
87+
public static PostgreSQLContainer POSTGRES = new PostgreSQLContainer(DockerImageName.parse("postgres:16.2"))
8788
.withDatabaseName("northwind")
8889
.withInitScript("e2e/postgres-dump/northwind.sql");
8990

9091
private Driver neo4jDriver;
9192

92-
@Before
93+
@BeforeEach
9394
public void prepare() {
9495
neo4jDriver = GraphDatabase.driver(NEO4J.getBoltUrl(), AuthTokens.basic("neo4j", NEO4J.getAdminPassword()));
9596
neo4jDriver.verifyConnectivity();
@@ -99,22 +100,22 @@ public void prepare() {
99100
}
100101
}
101102

102-
@After
103+
@AfterEach
103104
public void cleanUp() {
104105
neo4jDriver.close();
105106
}
106107

107108
@Test
108-
public void imports_data_via_Beam_and_json_spec() throws Exception {
109-
runBeamImport("json");
109+
public void imports_data_via_Beam_and_json_spec(TestPipeline pipeline) throws Exception {
110+
runBeamImport(pipeline, "json");
110111
}
111112

112113
@Test
113-
public void imports_data_via_Beam_and_yaml_spec() throws Exception {
114-
runBeamImport("yaml");
114+
public void imports_data_via_Beam_and_yaml_spec(TestPipeline pipeline) throws Exception {
115+
runBeamImport(pipeline, "yaml");
115116
}
116117

117-
private void runBeamImport(String extension) throws Exception {
118+
private void runBeamImport(TestPipeline pipeline, String extension) throws Exception {
118119
String neo4jUrl = NEO4J.getBoltUrl();
119120
String neo4jPassword = NEO4J.getAdminPassword();
120121
var importSpec =

examples/apache-beam/pom.xml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
<artifactId>beam-sdks-java-io-parquet</artifactId>
2929
<scope>test</scope>
3030
</dependency>
31+
<dependency>
32+
<groupId>org.apache.beam</groupId>
33+
<artifactId>beam-sdks-java-testing-junit</artifactId>
34+
<scope>test</scope>
35+
</dependency>
3136
<dependency>
3237
<!-- required by Beam's ParquetIO -->
3338
<groupId>org.apache.hadoop</groupId>
@@ -81,17 +86,17 @@
8186
</dependency>
8287
<dependency>
8388
<groupId>org.testcontainers</groupId>
84-
<artifactId>junit-jupiter</artifactId>
89+
<artifactId>testcontainers</artifactId>
8590
<scope>test</scope>
8691
</dependency>
8792
<dependency>
8893
<groupId>org.testcontainers</groupId>
89-
<artifactId>neo4j</artifactId>
94+
<artifactId>testcontainers-junit-jupiter</artifactId>
9095
<scope>test</scope>
9196
</dependency>
9297
<dependency>
9398
<groupId>org.testcontainers</groupId>
94-
<artifactId>testcontainers</artifactId>
99+
<artifactId>testcontainers-neo4j</artifactId>
95100
<scope>test</scope>
96101
</dependency>
97102
</dependencies>

examples/apache-beam/src/test/java/org/neo4j/importer/BeamExampleIT.java

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import org.apache.beam.sdk.extensions.avro.coders.AvroCoder;
6161
import org.apache.beam.sdk.io.parquet.ParquetIO;
6262
import org.apache.beam.sdk.testing.TestPipeline;
63+
import org.apache.beam.sdk.testing.TestPipelineExtension;
6364
import org.apache.beam.sdk.transforms.Create;
6465
import org.apache.beam.sdk.transforms.DoFn;
6566
import org.apache.beam.sdk.transforms.GroupIntoBatches;
@@ -70,10 +71,8 @@
7071
import org.apache.beam.sdk.transforms.WithKeys;
7172
import org.apache.beam.sdk.values.KV;
7273
import org.apache.beam.sdk.values.PCollection;
73-
import org.checkerframework.checker.nullness.qual.NonNull;
74-
import org.junit.ClassRule;
75-
import org.junit.Rule;
76-
import org.junit.Test;
74+
import org.junit.jupiter.api.Test;
75+
import org.junit.jupiter.api.extension.ExtendWith;
7776
import org.neo4j.cypherdsl.core.Cypher;
7877
import org.neo4j.cypherdsl.core.Expression;
7978
import org.neo4j.cypherdsl.core.MapExpression;
@@ -102,21 +101,22 @@
102101
import org.neo4j.importer.v1.sources.Source;
103102
import org.neo4j.importer.v1.sources.SourceProvider;
104103
import org.neo4j.importer.v1.targets.PropertyType;
105-
import org.testcontainers.containers.Neo4jContainer;
104+
import org.testcontainers.junit.jupiter.Container;
105+
import org.testcontainers.junit.jupiter.Testcontainers;
106+
import org.testcontainers.neo4j.Neo4jContainer;
106107
import org.testcontainers.utility.DockerImageName;
107108

109+
@ExtendWith(TestPipelineExtension.class)
110+
@Testcontainers
108111
public class BeamExampleIT {
109112

110-
@Rule
111-
public final TestPipeline pipeline = TestPipeline.create();
112-
113-
@ClassRule
114-
public static Neo4jContainer<?> NEO4J = new Neo4jContainer<>(DockerImageName.parse("neo4j:5-enterprise"))
113+
@Container
114+
public static Neo4jContainer NEO4J = new Neo4jContainer(DockerImageName.parse("neo4j:5-enterprise"))
115115
.withEnv("NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes")
116116
.withAdminPassword("letmein!");
117117

118118
@Test
119-
public void imports_dvd_rental_data_set() throws Exception {
119+
public void imports_dvd_rental_data_set(TestPipeline pipeline) throws Exception {
120120
try (InputStream stream = this.getClass().getResourceAsStream("/specs/dvd_rental.yaml")) {
121121
assertThat(stream).isNotNull();
122122

@@ -125,9 +125,9 @@ public void imports_dvd_rental_data_set() throws Exception {
125125
var importPipeline = ImportPipeline.of(ImportSpecificationDeserializer.deserialize(reader));
126126
importPipeline.forEach(step -> {
127127
switch (step) {
128-
case SourceStep source -> handleSource(source, outputs);
129-
case ActionStep action -> handleAction(action, outputs);
130-
case TargetStep target -> handleTarget(target, outputs);
128+
case SourceStep source -> handleSource(source, pipeline, outputs);
129+
case ActionStep action -> handleAction(action, pipeline, outputs);
130+
case TargetStep target -> handleTarget(target, pipeline, outputs);
131131
default -> throw new IllegalStateException("Unexpected value: " + step);
132132
}
133133
});
@@ -152,7 +152,7 @@ public void imports_dvd_rental_data_set() throws Exception {
152152
}
153153
}
154154

155-
private void handleSource(SourceStep step, Map<String, PCollection<?>> outputs) {
155+
private void handleSource(SourceStep step, TestPipeline pipeline, Map<String, PCollection<?>> outputs) {
156156
var name = step.name();
157157
var source = step.source();
158158
assertThat(source).isInstanceOf(ParquetSource.class);
@@ -165,7 +165,7 @@ private void handleSource(SourceStep step, Map<String, PCollection<?>> outputs)
165165
outputs.put(source.getName(), output);
166166
}
167167

168-
private void handleAction(ActionStep step, Map<String, PCollection<?>> outputs) {
168+
private void handleAction(ActionStep step, TestPipeline pipeline, Map<String, PCollection<?>> outputs) {
169169
var actionName = step.name();
170170
var action = step.action();
171171
assertThat(action).isInstanceOf(CypherAction.class);
@@ -183,7 +183,7 @@ private void handleAction(ActionStep step, Map<String, PCollection<?>> outputs)
183183
}
184184

185185
@SuppressWarnings("unchecked")
186-
private void handleTarget(TargetStep step, Map<String, PCollection<?>> outputs) {
186+
private void handleTarget(TargetStep step, TestPipeline pipeline, Map<String, PCollection<?>> outputs) {
187187
var stepName = step.name();
188188
assertThat(step).isInstanceOf(EntityTargetStep.class);
189189
var entityTargetStep = (EntityTargetStep) step;
@@ -351,8 +351,7 @@ public String getName() {
351351
}
352352
}
353353

354-
private static class TargetSchemaIO
355-
extends PTransform<@NonNull PCollection<Integer>, @NonNull PCollection<WriteCounters>> {
354+
private static class TargetSchemaIO extends PTransform<PCollection<Integer>, PCollection<WriteCounters>> {
356355

357356
private final String url;
358357

@@ -366,13 +365,13 @@ private TargetSchemaIO(String url, String password, EntityTargetStep target) {
366365
this.target = target;
367366
}
368367

369-
public static PTransform<@NonNull PCollection<Integer>, @NonNull PCollection<WriteCounters>> initSchema(
368+
public static PTransform<PCollection<Integer>, PCollection<WriteCounters>> initSchema(
370369
String url, String password, EntityTargetStep target) {
371370
return new TargetSchemaIO(url, password, target);
372371
}
373372

374373
@Override
375-
public @NonNull PCollection<WriteCounters> expand(@NonNull PCollection<Integer> input) {
374+
public PCollection<WriteCounters> expand(PCollection<Integer> input) {
376375
return input.apply(ParDo.of(TargetSchemaWriteFn.of(url, password, target)));
377376
}
378377

@@ -556,8 +555,7 @@ private static String propertyType(PropertyType propertyType) {
556555
}
557556

558557
private static class TargetIO
559-
extends PTransform<
560-
@NonNull PCollection<KV<Integer, Iterable<GenericRecord>>>, @NonNull PCollection<WriteCounters>> {
558+
extends PTransform<PCollection<KV<Integer, Iterable<GenericRecord>>>, PCollection<WriteCounters>> {
561559

562560
private final String url;
563561

@@ -571,14 +569,13 @@ private TargetIO(String url, String password, EntityTargetStep target) {
571569
this.target = target;
572570
}
573571

574-
public static PTransform<
575-
@NonNull PCollection<KV<Integer, Iterable<GenericRecord>>>, @NonNull PCollection<WriteCounters>>
572+
public static PTransform<PCollection<KV<Integer, Iterable<GenericRecord>>>, PCollection<WriteCounters>>
576573
writeAll(String boltUrl, String adminPassword, EntityTargetStep target) {
577574
return new TargetIO(boltUrl, adminPassword, target);
578575
}
579576

580577
@Override
581-
public @NonNull PCollection<WriteCounters> expand(PCollection<KV<Integer, Iterable<GenericRecord>>> input) {
578+
public PCollection<WriteCounters> expand(PCollection<KV<Integer, Iterable<GenericRecord>>> input) {
582579
return input.apply(ParDo.of(TargetWriteFn.of(url, password, target)));
583580
}
584581

@@ -778,7 +775,7 @@ public static Coder<GenericRecord> create() {
778775
}
779776

780777
@Override
781-
public void encode(GenericRecord value, @NonNull OutputStream outStream) throws IOException {
778+
public void encode(GenericRecord value, OutputStream outStream) throws IOException {
782779
assertThat(value).isNotNull();
783780
var schema = value.getSchema();
784781
String schemaString = schema.toString();
@@ -790,7 +787,7 @@ public void encode(GenericRecord value, @NonNull OutputStream outStream) throws
790787
}
791788

792789
@Override
793-
public GenericRecord decode(@NonNull InputStream inStream) throws IOException {
790+
public GenericRecord decode(InputStream inStream) throws IOException {
794791
String schemaString = StringUtf8Coder.of().decode(inStream);
795792
String schemaHash = StringUtf8Coder.of().decode(inStream);
796793
AvroCoder<GenericRecord> coder =
@@ -1009,8 +1006,7 @@ public String toString() {
10091006
}
10101007
}
10111008

1012-
private static class CypherActionIO
1013-
extends PTransform<@NonNull PCollection<Integer>, @NonNull PCollection<Integer>> {
1009+
private static class CypherActionIO extends PTransform<PCollection<Integer>, PCollection<Integer>> {
10141010

10151011
private final CypherAction action;
10161012

@@ -1024,13 +1020,13 @@ private CypherActionIO(CypherAction action, String url, String password) {
10241020
this.password = password;
10251021
}
10261022

1027-
public static PTransform<@NonNull PCollection<Integer>, @NonNull PCollection<Integer>> run(
1023+
public static PTransform<PCollection<Integer>, PCollection<Integer>> run(
10281024
CypherAction action, String url, String password) {
10291025
return new CypherActionIO(action, url, password);
10301026
}
10311027

10321028
@Override
1033-
public @NonNull PCollection<Integer> expand(@NonNull PCollection<Integer> input) {
1029+
public PCollection<Integer> expand(PCollection<Integer> input) {
10341030
return input.apply(ParDo.of(new CypherActionFn(action, url, password)));
10351031
}
10361032
}

0 commit comments

Comments
 (0)