Skip to content

Commit 6cd4dc5

Browse files
GH-2346 - Add additional tests for verifying persistence of related entities with assigned ids.
There is no need for an additional fix, the root cause had been addressed in #2347 already. This closes #2346.
1 parent 8f8416e commit 6cd4dc5

File tree

3 files changed

+99
-5
lines changed

3 files changed

+99
-5
lines changed

src/test/java/org/springframework/data/neo4j/integration/issues/gh2347/GH2347IT.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void entitiesWithAssignedIdsSavedInBatchMustBeIdentifiableWithTheirInternalIds(
4545
List<Application> savedApplications = applicationRepository.saveAll(Collections.singletonList(createData()));
4646

4747
assertThat(savedApplications).hasSize(1);
48-
assertDatabase(driver);
48+
assertSingleApplicationNodeWithMultipleWorkflows(driver);
4949
}
5050

5151
@Test
@@ -54,12 +54,41 @@ void entitiesWithAssignedIdsMustBeIdentifiableWithTheirInternalIds(
5454
@Autowired Driver driver
5555
) {
5656
applicationRepository.save(createData());
57-
assertDatabase(driver);
57+
assertSingleApplicationNodeWithMultipleWorkflows(driver);
58+
}
59+
60+
@Test // GH-2346
61+
void relationshipsStartingAtEntitiesWithAssignedIdsShouldBeCreated(
62+
@Autowired ApplicationRepository applicationRepository,
63+
@Autowired Driver driver
64+
) {
65+
createData((applications, workflows) -> {
66+
List<Application> savedApplications = applicationRepository.saveAll(applications);
67+
68+
assertThat(savedApplications).hasSize(2);
69+
assertMultipleApplicationsNodeWithASingleWorkflow(driver);
70+
});
71+
}
72+
73+
@Test // GH-2346
74+
void relationshipsStartingAtEntitiesWithAssignedIdsShouldBeCreatedOtherDirection(
75+
@Autowired WorkflowRepository workflowRepository,
76+
@Autowired Driver driver
77+
) {
78+
createData((applications, workflows) -> {
79+
List<Workflow> savedWorkflows = workflowRepository.saveAll(workflows);
80+
81+
assertThat(savedWorkflows).hasSize(2);
82+
assertMultipleApplicationsNodeWithASingleWorkflow(driver);
83+
});
5884
}
5985

6086
interface ApplicationRepository extends Neo4jRepository<Application, String> {
6187
}
6288

89+
interface WorkflowRepository extends Neo4jRepository<Workflow, String> {
90+
}
91+
6392
@Configuration
6493
@EnableTransactionManagement
6594
@EnableNeo4jRepositories(considerNestedRepositories = true)

src/test/java/org/springframework/data/neo4j/integration/issues/gh2347/ReactiveGH2347IT.java

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void entitiesWithAssignedIdsSavedInBatchMustBeIdentifiableWithTheirInternalIds(
4747
.expectNextCount(1L)
4848
.verifyComplete();
4949

50-
assertDatabase(driver);
50+
assertSingleApplicationNodeWithMultipleWorkflows(driver);
5151
}
5252

5353
@Test
@@ -60,12 +60,45 @@ void entitiesWithAssignedIdsMustBeIdentifiableWithTheirInternalIds(
6060
.as(StepVerifier::create)
6161
.expectNextCount(1L)
6262
.verifyComplete();
63-
assertDatabase(driver);
63+
assertSingleApplicationNodeWithMultipleWorkflows(driver);
64+
}
65+
66+
@Test // GH-2346
67+
void relationshipsStartingAtEntitiesWithAssignedIdsShouldBeCreated(
68+
@Autowired ApplicationRepository applicationRepository,
69+
@Autowired Driver driver
70+
) {
71+
createData((applications, workflows) -> {
72+
applicationRepository.saveAll(applications)
73+
.as(StepVerifier::create)
74+
.expectNextCount(2L)
75+
.verifyComplete();
76+
77+
assertMultipleApplicationsNodeWithASingleWorkflow(driver);
78+
});
79+
}
80+
81+
@Test // GH-2346
82+
void relationshipsStartingAtEntitiesWithAssignedIdsShouldBeCreatedOtherDirection(
83+
@Autowired WorkflowRepository workflowRepository,
84+
@Autowired Driver driver
85+
) {
86+
createData((applications, workflows) -> {
87+
workflowRepository.saveAll(workflows)
88+
.as(StepVerifier::create)
89+
.expectNextCount(2L)
90+
.verifyComplete();
91+
92+
assertMultipleApplicationsNodeWithASingleWorkflow(driver);
93+
});
6494
}
6595

6696
interface ApplicationRepository extends ReactiveNeo4jRepository<Application, String> {
6797
}
6898

99+
interface WorkflowRepository extends ReactiveNeo4jRepository<Workflow, String> {
100+
}
101+
69102
@Configuration
70103
@EnableTransactionManagement
71104
@EnableReactiveNeo4jRepositories(considerNestedRepositories = true)

src/test/java/org/springframework/data/neo4j/integration/issues/gh2347/TestBase.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
import static org.assertj.core.api.Assertions.assertThat;
1919

2020
import java.util.Arrays;
21+
import java.util.List;
2122
import java.util.UUID;
23+
import java.util.function.BiConsumer;
2224

2325
import org.junit.jupiter.api.BeforeEach;
2426
import org.neo4j.driver.Driver;
@@ -57,7 +59,22 @@ protected final Application createData() {
5759
return app1;
5860
}
5961

60-
protected final void assertDatabase(Driver driver) {
62+
protected final void createData(BiConsumer<List<Application>, List<Workflow>> actualTest) {
63+
64+
Application app1 = new Application("app-1");
65+
Workflow wf1 = new Workflow("wf-1");
66+
wf1.setApplication(app1);
67+
app1.getWorkflows().add(wf1);
68+
69+
Application app2 = new Application("app-2");
70+
Workflow wf2 = new Workflow("wf-2");
71+
wf2.setApplication(app2);
72+
app2.getWorkflows().add(wf2);
73+
74+
actualTest.accept(Arrays.asList(app1, app2), Arrays.asList(wf1, wf2));
75+
}
76+
77+
protected final void assertSingleApplicationNodeWithMultipleWorkflows(Driver driver) {
6178

6279
try (Session session = driver.session()) {
6380
Record record = session.readTransaction(
@@ -67,4 +84,19 @@ protected final void assertDatabase(Driver driver) {
6784
"wf-1", "wf-2");
6885
}
6986
}
87+
88+
protected final void assertMultipleApplicationsNodeWithASingleWorkflow(Driver driver) {
89+
90+
try (Session session = driver.session()) {
91+
List<Record> records = session.readTransaction(
92+
tx -> tx.run("MATCH (a:Application)-->(w) RETURN a, collect(w) as workflows").list());
93+
assertThat(records).hasSize(2);
94+
assertThat(records.get(0).get("a").asNode().get("id").asString()).isEqualTo("app-1");
95+
assertThat(records.get(0).get("workflows")
96+
.asList(v -> v.asNode().get("id").asString())).containsExactlyInAnyOrder("wf-1");
97+
assertThat(records.get(1).get("a").asNode().get("id").asString()).isEqualTo("app-2");
98+
assertThat(records.get(1).get("workflows")
99+
.asList(v -> v.asNode().get("id").asString())).containsExactlyInAnyOrder("wf-2");
100+
}
101+
}
70102
}

0 commit comments

Comments
 (0)