Skip to content

Commit e823156

Browse files
committed
Test-Case for spring-projects#2437
1 parent 4215593 commit e823156

File tree

8 files changed

+132
-2
lines changed

8 files changed

+132
-2
lines changed

src/test/java/org/springframework/data/neo4j/integration/imperative/RepositoryIT.java

+32-1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@
9797
import org.springframework.data.neo4j.integration.imperative.repositories.PersonWithNoConstructorRepository;
9898
import org.springframework.data.neo4j.integration.imperative.repositories.PersonWithWitherRepository;
9999
import org.springframework.data.neo4j.integration.imperative.repositories.ThingRepository;
100+
import org.springframework.data.neo4j.integration.issues.gh2421.BaseNodeEntity;
101+
import org.springframework.data.neo4j.integration.issues.gh2421.MeasurementMeta;
102+
import org.springframework.data.neo4j.integration.issues.gh2421.projections.ApiMeasurementMetaProjection;
100103
import org.springframework.data.neo4j.integration.shared.common.AltHobby;
101104
import org.springframework.data.neo4j.integration.shared.common.AltLikedByPersonRelationship;
102105
import org.springframework.data.neo4j.integration.shared.common.AltPerson;
@@ -151,6 +154,8 @@
151154
import org.springframework.data.neo4j.test.Neo4jExtension;
152155
import org.springframework.data.neo4j.types.CartesianPoint2d;
153156
import org.springframework.data.neo4j.types.GeographicPoint2d;
157+
import org.springframework.data.projection.TargetAware;
158+
import org.springframework.data.repository.Repository;
154159
import org.springframework.data.repository.query.FluentQuery;
155160
import org.springframework.data.repository.query.Param;
156161
import org.springframework.test.annotation.DirtiesContext;
@@ -3054,6 +3059,15 @@ void setupData(Transaction transaction) {
30543059
true, 1L, TEST_PERSON1_BORN_ON, "something", Arrays.asList("a", "b"), NEO4J_HQ, createdAt.toInstant());
30553060
person2 = new PersonWithAllConstructor(id2, TEST_PERSON2_NAME, TEST_PERSON2_FIRST_NAME, TEST_PERSON_SAMEVALUE,
30563061
false, 2L, TEST_PERSON2_BORN_ON, null, Collections.emptyList(), SFO, null);
3062+
3063+
transaction.run("" +
3064+
"CREATE (m1:MeasurementMeta{nodeId: 'm1'}) "+
3065+
"CREATE (m2:MeasurementMeta{nodeId: 'm2'}) "+
3066+
"CREATE (nt2:NodeType{nodeTypeId: 'nt2'}) "+
3067+
"CREATE (m1)-[:HAS_TYPE]->(nt2)" +
3068+
"CREATE (m2)-[:HAS_TYPE]->(nt2)" +
3069+
"CREATE (m1)-[:WEIGHTS]->(m2)"
3070+
);
30573071
}
30583072

30593073
@Test
@@ -3390,6 +3404,18 @@ void existsById(@Autowired PersonRepository repository) {
33903404
assertThat(exists).isTrue();
33913405
}
33923406

3407+
@Test
3408+
void test(@Autowired MeasurementMetaRepository repository) {
3409+
Optional<ApiMeasurementMetaProjection> m1 = repository.findByNodeId("m1", ApiMeasurementMetaProjection.class);
3410+
assertThat(m1)
3411+
.isPresent()
3412+
.get()
3413+
.extracting(projection -> (MeasurementMeta) ((TargetAware)projection).getTarget())
3414+
.extracting(BaseNodeEntity::getParent)
3415+
.extracting(BaseNodeEntity::getNodeType)
3416+
.isNull();
3417+
}
3418+
33933419
@Test // GH-2033
33943420
void existsByProperty(@Autowired PersonRepository repository) {
33953421

@@ -4492,6 +4518,10 @@ interface SameIdEntitiesRepository extends Neo4jRepository<SameIdProperty.PolEnt
44924518
interface EntityWithCustomIdAndDynamicLabelsRepository
44934519
extends Neo4jRepository<EntitiesWithDynamicLabels.EntityWithCustomIdAndDynamicLabels, String> {}
44944520

4521+
interface MeasurementMetaRepository extends Repository<MeasurementMeta, String> {
4522+
<R> Optional<R> findByNodeId(String nodeId, Class<R> clazz);
4523+
}
4524+
44954525
@SpringJUnitConfig(Config.class)
44964526
static abstract class IntegrationTestBase {
44974527

@@ -4544,7 +4574,8 @@ public Driver driver() {
45444574
protected Collection<String> getMappingBasePackages() {
45454575
return Arrays.asList(
45464576
PersonWithAllConstructor.class.getPackage().getName(),
4547-
Flight.class.getPackage().getName()
4577+
Flight.class.getPackage().getName(),
4578+
MeasurementMeta.class.getPackage().getName()
45484579
);
45494580
}
45504581

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package org.springframework.data.neo4j.integration.issues.gh2421;
2+
3+
import lombok.*;
4+
import lombok.experimental.SuperBuilder;
5+
import org.springframework.data.neo4j.core.schema.GeneratedValue;
6+
import org.springframework.data.neo4j.core.schema.Id;
7+
import org.springframework.data.neo4j.core.schema.Relationship;
8+
import org.springframework.data.neo4j.core.support.UUIDStringGenerator;
9+
10+
import static org.springframework.data.neo4j.core.schema.Relationship.Direction.OUTGOING;
11+
12+
@Data
13+
@Setter(AccessLevel.PRIVATE)
14+
@NoArgsConstructor(access = AccessLevel.PROTECTED)
15+
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
16+
@SuperBuilder(toBuilder = true)
17+
abstract public class BaseNodeEntity {
18+
19+
@Id
20+
@GeneratedValue(UUIDStringGenerator.class)
21+
@EqualsAndHashCode.Include
22+
private String nodeId;
23+
24+
@Relationship(type = "CHILD_OF", direction = OUTGOING)
25+
private NodeEntity parent;
26+
27+
@Relationship(type = "HAS_TYPE", direction = OUTGOING)
28+
private NodeType nodeType;
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.springframework.data.neo4j.integration.issues.gh2421;
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+
@EqualsAndHashCode(callSuper = true, onlyExplicitlyIncluded = true)
15+
@SuperBuilder(toBuilder = true)
16+
public class MeasurementMeta extends BaseNodeEntity {
17+
18+
@Relationship(type = "WEIGHTS", direction = OUTGOING)
19+
private MeasurementMeta baseMeasurement;
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.springframework.data.neo4j.integration.issues.gh2421;
2+
3+
import lombok.*;
4+
import lombok.experimental.SuperBuilder;
5+
import org.springframework.data.neo4j.core.schema.Node;
6+
7+
@Node
8+
@Data
9+
@Setter(AccessLevel.PRIVATE)
10+
@NoArgsConstructor(access = AccessLevel.PROTECTED)
11+
@EqualsAndHashCode(callSuper = true, onlyExplicitlyIncluded = true)
12+
@SuperBuilder(toBuilder = true)
13+
public class NodeEntity extends BaseNodeEntity {
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.springframework.data.neo4j.integration.issues.gh2421;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.EqualsAndHashCode;
5+
import lombok.Value;
6+
import org.springframework.data.annotation.Immutable;
7+
import org.springframework.data.neo4j.core.schema.Id;
8+
import org.springframework.data.neo4j.core.schema.Node;
9+
10+
@Node
11+
@Value
12+
@AllArgsConstructor
13+
@EqualsAndHashCode
14+
@Immutable
15+
public class NodeType {
16+
@Id
17+
String nodeTypeId;
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.springframework.data.neo4j.integration.issues.gh2421.projections;
2+
3+
import org.springframework.data.neo4j.integration.issues.gh2421.NodeType;
4+
5+
public interface ApiMeasurementMetaProjection extends BaseNodeFieldsProjection {
6+
BaseNodeFieldsProjection getParent();
7+
8+
NodeType getNodeType();
9+
10+
BaseNodeFieldsProjection getBaseMeasurement();
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.springframework.data.neo4j.integration.issues.gh2421.projections;
2+
3+
4+
public interface BaseNodeFieldsProjection {
5+
6+
String getNodeId();
7+
}

src/test/resources/logback-test.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<logger name="OutboundMessageHandler" level="info"/>
3030
<logger name="InboundMessageDispatcher" level="info"/>
3131

32-
<logger name="org.springframework.data.neo4j.cypher" level="info"/>
32+
<logger name="org.springframework.data.neo4j.cypher" level="trace"/>
3333
<logger name="org.springframework.data.neo4j" level="info"/>
3434
<logger name="org.springframework.data.neo4j.test" level="info"/>
3535
<logger name="org.springframework.data.neo4j.repository.query.Neo4jQuerySupport" level="debug" />

0 commit comments

Comments
 (0)