Skip to content

Commit 7f5bfb3

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 9ed7557 commit 7f5bfb3

File tree

3 files changed

+103
-5
lines changed

3 files changed

+103
-5
lines changed

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

+33-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void entitiesWithAssignedIdsSavedInBatchMustBeIdentifiableWithTheirInternalIds(
5151
List<Application> savedApplications = applicationRepository.saveAll(Collections.singletonList(createData()));
5252

5353
assertThat(savedApplications).hasSize(1);
54-
assertDatabase(driver, bookmarkCapture);
54+
assertSingleApplicationNodeWithMultipleWorkflows(driver, bookmarkCapture);
5555
}
5656

5757
@Test
@@ -61,12 +61,43 @@ void entitiesWithAssignedIdsMustBeIdentifiableWithTheirInternalIds(
6161
@Autowired BookmarkCapture bookmarkCapture
6262
) {
6363
applicationRepository.save(createData());
64-
assertDatabase(driver, bookmarkCapture);
64+
assertSingleApplicationNodeWithMultipleWorkflows(driver, bookmarkCapture);
65+
}
66+
67+
@Test // GH-2346
68+
void relationshipsStartingAtEntitiesWithAssignedIdsShouldBeCreated(
69+
@Autowired ApplicationRepository applicationRepository,
70+
@Autowired Driver driver,
71+
@Autowired BookmarkCapture bookmarkCapture
72+
) {
73+
createData((applications, workflows) -> {
74+
List<Application> savedApplications = applicationRepository.saveAll(applications);
75+
76+
assertThat(savedApplications).hasSize(2);
77+
assertMultipleApplicationsNodeWithASingleWorkflow(driver, bookmarkCapture);
78+
});
79+
}
80+
81+
@Test // GH-2346
82+
void relationshipsStartingAtEntitiesWithAssignedIdsShouldBeCreatedOtherDirection(
83+
@Autowired WorkflowRepository workflowRepository,
84+
@Autowired Driver driver,
85+
@Autowired BookmarkCapture bookmarkCapture
86+
) {
87+
createData((applications, workflows) -> {
88+
List<Workflow> savedWorkflows = workflowRepository.saveAll(workflows);
89+
90+
assertThat(savedWorkflows).hasSize(2);
91+
assertMultipleApplicationsNodeWithASingleWorkflow(driver, bookmarkCapture);
92+
});
6593
}
6694

6795
interface ApplicationRepository extends Neo4jRepository<Application, String> {
6896
}
6997

98+
interface WorkflowRepository extends Neo4jRepository<Workflow, String> {
99+
}
100+
70101
@Configuration
71102
@EnableTransactionManagement
72103
@EnableNeo4jRepositories(considerNestedRepositories = true)

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

+37-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void entitiesWithAssignedIdsSavedInBatchMustBeIdentifiableWithTheirInternalIds(
5252
.expectNextCount(1L)
5353
.verifyComplete();
5454

55-
assertDatabase(driver, bookmarkCapture);
55+
assertSingleApplicationNodeWithMultipleWorkflows(driver, bookmarkCapture);
5656
}
5757

5858
@Test
@@ -66,12 +66,47 @@ void entitiesWithAssignedIdsMustBeIdentifiableWithTheirInternalIds(
6666
.as(StepVerifier::create)
6767
.expectNextCount(1L)
6868
.verifyComplete();
69-
assertDatabase(driver, bookmarkCapture);
69+
assertSingleApplicationNodeWithMultipleWorkflows(driver, bookmarkCapture);
70+
}
71+
72+
@Test // GH-2346
73+
void relationshipsStartingAtEntitiesWithAssignedIdsShouldBeCreated(
74+
@Autowired ApplicationRepository applicationRepository,
75+
@Autowired Driver driver,
76+
@Autowired BookmarkCapture bookmarkCapture
77+
) {
78+
createData((applications, workflows) -> {
79+
applicationRepository.saveAll(applications)
80+
.as(StepVerifier::create)
81+
.expectNextCount(2L)
82+
.verifyComplete();
83+
84+
assertMultipleApplicationsNodeWithASingleWorkflow(driver, bookmarkCapture);
85+
});
86+
}
87+
88+
@Test // GH-2346
89+
void relationshipsStartingAtEntitiesWithAssignedIdsShouldBeCreatedOtherDirection(
90+
@Autowired WorkflowRepository workflowRepository,
91+
@Autowired Driver driver,
92+
@Autowired BookmarkCapture bookmarkCapture
93+
) {
94+
createData((applications, workflows) -> {
95+
workflowRepository.saveAll(workflows)
96+
.as(StepVerifier::create)
97+
.expectNextCount(2L)
98+
.verifyComplete();
99+
100+
assertMultipleApplicationsNodeWithASingleWorkflow(driver, bookmarkCapture);
101+
});
70102
}
71103

72104
interface ApplicationRepository extends ReactiveNeo4jRepository<Application, String> {
73105
}
74106

107+
interface WorkflowRepository extends ReactiveNeo4jRepository<Workflow, String> {
108+
}
109+
75110
@Configuration
76111
@EnableTransactionManagement
77112
@EnableReactiveNeo4jRepositories(considerNestedRepositories = true)

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

+33-1
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;
@@ -60,7 +62,22 @@ protected final Application createData() {
6062
return app1;
6163
}
6264

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

6582
try (Session session = driver.session(bookmarkCapture.createSessionConfig())) {
6683
Record record = session.readTransaction(
@@ -70,4 +87,19 @@ protected final void assertDatabase(Driver driver, BookmarkCapture bookmarkCaptu
7087
"wf-1", "wf-2");
7188
}
7289
}
90+
91+
protected final void assertMultipleApplicationsNodeWithASingleWorkflow(Driver driver, BookmarkCapture bookmarkCapture) {
92+
93+
try (Session session = driver.session(bookmarkCapture.createSessionConfig())) {
94+
List<Record> records = session.readTransaction(
95+
tx -> tx.run("MATCH (a:Application)-->(w) RETURN a, collect(w) as workflows").list());
96+
assertThat(records).hasSize(2);
97+
assertThat(records.get(0).get("a").asNode().get("id").asString()).isEqualTo("app-1");
98+
assertThat(records.get(0).get("workflows")
99+
.asList(v -> v.asNode().get("id").asString())).containsExactlyInAnyOrder("wf-1");
100+
assertThat(records.get(1).get("a").asNode().get("id").asString()).isEqualTo("app-2");
101+
assertThat(records.get(1).get("workflows")
102+
.asList(v -> v.asNode().get("id").asString())).containsExactlyInAnyOrder("wf-2");
103+
}
104+
}
73105
}

0 commit comments

Comments
 (0)