Skip to content

Commit 103c3c2

Browse files
committed
Test-Case for spring-projects#2526 (Projecting rich relation for inherited nodes fails)
1 parent 4a81fae commit 103c3c2

File tree

7 files changed

+234
-0
lines changed

7 files changed

+234
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.springframework.data.neo4j.integration.issues.gh2526;
2+
3+
import lombok.*;
4+
import lombok.experimental.SuperBuilder;
5+
import org.springframework.data.neo4j.core.schema.Node;
6+
import org.springframework.data.neo4j.core.schema.Relationship;
7+
8+
import static org.springframework.data.neo4j.core.schema.Relationship.Direction.OUTGOING;
9+
10+
@Node
11+
@Data
12+
@Setter(AccessLevel.PRIVATE)
13+
@NoArgsConstructor(access = AccessLevel.PROTECTED)
14+
@AllArgsConstructor(access = AccessLevel.PROTECTED)
15+
@EqualsAndHashCode(callSuper = true, onlyExplicitlyIncluded = true)
16+
@SuperBuilder(toBuilder = true)
17+
public class AccountingMeasurementMeta extends MeasurementMeta {
18+
19+
private String formula;
20+
21+
@Relationship(type = "WEIGHTS", direction = OUTGOING)
22+
private MeasurementMeta baseMeasurement;
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.springframework.data.neo4j.integration.issues.gh2526;
2+
3+
import lombok.*;
4+
import lombok.experimental.NonFinal;
5+
import lombok.experimental.SuperBuilder;
6+
import org.springframework.data.neo4j.core.schema.GeneratedValue;
7+
import org.springframework.data.neo4j.core.schema.Id;
8+
import org.springframework.data.neo4j.core.support.UUIDStringGenerator;
9+
10+
@org.springframework.data.neo4j.core.schema.Node
11+
@NonFinal
12+
@Data
13+
@Setter(AccessLevel.PRIVATE)
14+
@NoArgsConstructor(access = AccessLevel.PROTECTED)
15+
@AllArgsConstructor(access = AccessLevel.PROTECTED)
16+
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
17+
@SuperBuilder(toBuilder = true)
18+
public class BaseNodeEntity {
19+
20+
@Id
21+
@GeneratedValue(UUIDStringGenerator.class)
22+
@EqualsAndHashCode.Include
23+
private String nodeId;
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2011-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.neo4j.integration.issues.gh2526;
17+
18+
import org.springframework.data.neo4j.repository.Neo4jRepository;
19+
20+
public interface BaseNodeRepository extends Neo4jRepository<BaseNodeEntity, String> {
21+
22+
<R> R findByNodeId(String nodeIds, Class<R> clazz);
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.springframework.data.neo4j.integration.issues.gh2526;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.EqualsAndHashCode;
5+
import lombok.Value;
6+
import lombok.With;
7+
import org.springframework.data.annotation.Immutable;
8+
import org.springframework.data.neo4j.core.schema.RelationshipId;
9+
import org.springframework.data.neo4j.core.schema.RelationshipProperties;
10+
import org.springframework.data.neo4j.core.schema.TargetNode;
11+
12+
@RelationshipProperties
13+
@Value
14+
@With
15+
@AllArgsConstructor
16+
@Immutable
17+
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
18+
public class DataPoint {
19+
20+
@RelationshipId
21+
Long id;
22+
23+
boolean manual;
24+
25+
@TargetNode
26+
@EqualsAndHashCode.Include
27+
Measurand measurand;
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Copyright 2011-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.neo4j.integration.issues.gh2526;
17+
18+
import java.util.Set;
19+
20+
import org.junit.jupiter.api.BeforeEach;
21+
import org.junit.jupiter.api.Test;
22+
import org.neo4j.driver.Driver;
23+
import org.neo4j.driver.Session;
24+
import org.springframework.beans.factory.annotation.Autowired;
25+
import org.springframework.context.annotation.Bean;
26+
import org.springframework.context.annotation.Configuration;
27+
import org.springframework.data.neo4j.config.AbstractNeo4jConfig;
28+
import org.springframework.data.neo4j.core.DatabaseSelectionProvider;
29+
import org.springframework.data.neo4j.core.transaction.Neo4jBookmarkManager;
30+
import org.springframework.data.neo4j.core.transaction.Neo4jTransactionManager;
31+
import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories;
32+
import org.springframework.data.neo4j.test.BookmarkCapture;
33+
import org.springframework.data.neo4j.test.Neo4jExtension;
34+
import org.springframework.data.neo4j.test.Neo4jIntegrationTest;
35+
import org.springframework.transaction.PlatformTransactionManager;
36+
import org.springframework.transaction.annotation.EnableTransactionManagement;
37+
38+
import static org.assertj.core.api.Assertions.assertThat;
39+
40+
@Neo4jIntegrationTest
41+
public class GH2526 {
42+
43+
protected static Neo4jExtension.Neo4jConnectionSupport neo4jConnectionSupport;
44+
45+
@BeforeEach
46+
void setupData(@Autowired Driver driver, @Autowired BookmarkCapture bookmarkCapture) {
47+
48+
try (Session session = driver.session()) {
49+
session.run("MATCH (n) DETACH DELETE n").consume();
50+
session.run(
51+
"CREATE (o1:Measurand {measurandId: 'o1'})" +
52+
"CREATE (acc1:AccountingMeasurementMeta:BaseNodeEntity {nodeId: 'acc1'})" +
53+
"CREATE (o1)-[:IS_MEASURED_BY{ manual: true }]->(acc1)"
54+
).consume();
55+
bookmarkCapture.seedWith(session.lastBookmark());
56+
}
57+
}
58+
59+
@Test
60+
void test(@Autowired BaseNodeRepository repository) {
61+
Projection m = repository.findByNodeId("acc1", Projection.class);
62+
assertThat(m).isNotNull();
63+
}
64+
65+
interface Projection {
66+
String getNodeId();
67+
Set<DataPoint> getDataPoints();
68+
}
69+
70+
71+
@Configuration
72+
@EnableTransactionManagement
73+
@EnableNeo4jRepositories
74+
static class Config extends AbstractNeo4jConfig {
75+
76+
@Bean
77+
public BookmarkCapture bookmarkCapture() {
78+
return new BookmarkCapture();
79+
}
80+
81+
@Override
82+
public PlatformTransactionManager transactionManager(
83+
Driver driver, DatabaseSelectionProvider databaseNameProvider)
84+
{
85+
86+
BookmarkCapture bookmarkCapture = bookmarkCapture();
87+
return new Neo4jTransactionManager(driver, databaseNameProvider,
88+
Neo4jBookmarkManager.create(bookmarkCapture));
89+
}
90+
91+
@Bean
92+
public Driver driver() {
93+
94+
return neo4jConnectionSupport.getDriver();
95+
}
96+
}
97+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.springframework.data.neo4j.integration.issues.gh2526;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Value;
5+
import org.springframework.data.annotation.Immutable;
6+
import org.springframework.data.neo4j.core.schema.Id;
7+
import org.springframework.data.neo4j.core.schema.Node;
8+
9+
@Node
10+
@Value
11+
@AllArgsConstructor
12+
@Immutable
13+
public class Measurand {
14+
15+
@Id
16+
String measurandId;
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.springframework.data.neo4j.integration.issues.gh2526;
2+
3+
import java.util.Set;
4+
5+
import lombok.*;
6+
import lombok.experimental.SuperBuilder;
7+
import org.springframework.data.neo4j.core.schema.Relationship;
8+
9+
import static org.springframework.data.neo4j.core.schema.Relationship.Direction.INCOMING;
10+
11+
@org.springframework.data.neo4j.core.schema.Node
12+
@Data
13+
@Setter(AccessLevel.PRIVATE)
14+
@NoArgsConstructor(access = AccessLevel.PROTECTED)
15+
@AllArgsConstructor(access = AccessLevel.PROTECTED)
16+
@EqualsAndHashCode(callSuper = true, onlyExplicitlyIncluded = true)
17+
@SuperBuilder(toBuilder = true)
18+
public class MeasurementMeta extends BaseNodeEntity {
19+
20+
@Relationship(type = "IS_MEASURED_BY", direction = INCOMING)
21+
private Set<DataPoint> dataPoints;
22+
}

0 commit comments

Comments
 (0)