76
76
import org .springframework .data .neo4j .config .AbstractNeo4jConfig ;
77
77
import org .springframework .data .neo4j .core .DatabaseSelection ;
78
78
import org .springframework .data .neo4j .core .DatabaseSelectionProvider ;
79
+ import org .springframework .data .neo4j .core .Neo4jTemplate ;
79
80
import org .springframework .data .neo4j .core .convert .Neo4jConversions ;
80
81
import org .springframework .data .neo4j .integration .imperative .repositories .PersonRepository ;
81
82
import org .springframework .data .neo4j .integration .imperative .repositories .ThingRepository ;
86
87
import org .springframework .data .neo4j .integration .shared .BidirectionalEnd ;
87
88
import org .springframework .data .neo4j .integration .shared .BidirectionalStart ;
88
89
import org .springframework .data .neo4j .integration .shared .Club ;
90
+ import org .springframework .data .neo4j .integration .shared .ClubRelationship ;
89
91
import org .springframework .data .neo4j .integration .shared .DeepRelationships ;
90
92
import org .springframework .data .neo4j .integration .shared .EntityWithConvertedId ;
91
93
import org .springframework .data .neo4j .integration .shared .Friend ;
100
102
import org .springframework .data .neo4j .integration .shared .PersonWithNoConstructor ;
101
103
import org .springframework .data .neo4j .integration .shared .PersonWithRelationship ;
102
104
import org .springframework .data .neo4j .integration .shared .PersonWithRelationshipWithProperties ;
105
+ import org .springframework .data .neo4j .integration .shared .PersonWithRelationshipWithProperties2 ;
103
106
import org .springframework .data .neo4j .integration .shared .PersonWithWither ;
104
107
import org .springframework .data .neo4j .integration .shared .Pet ;
105
108
import org .springframework .data .neo4j .integration .shared .SimilarThing ;
@@ -903,6 +906,33 @@ void findEntityWithRelationshipWithAssignedId(@Autowired PetRepository repositor
903
906
@ Nested
904
907
class RelationshipProperties extends IntegrationTestBase {
905
908
909
+ @ Test // DATAGRAPH-1397
910
+ void shouldBeStorableOnSets (
911
+ @ Autowired Neo4jTemplate template ) {
912
+
913
+ long personId ;
914
+
915
+ try (Session session = createSession ()) {
916
+ Record record = session .run ("CREATE (n:PersonWithRelationshipWithProperties2{name:'Freddie'}),"
917
+ + " (n)-[l1:LIKES "
918
+ + "{since: 1995, active: true, localDate: date('1995-02-26'), myEnum: 'SOMETHING', point: point({x: 0, y: 1})}"
919
+ + "]->(h1:Hobby{name:'Music'}), "
920
+ + "(n)-[l2:LIKES "
921
+ + "{since: 2000, active: false, localDate: date('2000-06-28'), myEnum: 'SOMETHING_DIFFERENT', point: point({x: 2, y: 3})}"
922
+ + "]->(h2:Hobby{name:'Something else'})"
923
+ + "RETURN n, h1, h2" ).single ();
924
+
925
+ Node personNode = record .get ("n" ).asNode ();
926
+ personId = personNode .id ();
927
+ }
928
+
929
+ Optional <PersonWithRelationshipWithProperties2 > optionalPerson = template .findById (personId , PersonWithRelationshipWithProperties2 .class );
930
+ assertThat (optionalPerson ).hasValueSatisfying (person -> {
931
+ assertThat (person .getName ()).isEqualTo ("Freddie" );
932
+ assertThat (person .getHobbies ()).hasSize (2 ).extracting (LikesHobbyRelationship ::getSince ).containsExactlyInAnyOrder (1995 , 2000 );
933
+ });
934
+ }
935
+
906
936
@ Test
907
937
void findEntityWithRelationshipWithProperties (
908
938
@ Autowired PersonWithRelationshipWithPropertiesRepository repository ) {
@@ -913,11 +943,16 @@ void findEntityWithRelationshipWithProperties(
913
943
914
944
try (Session session = createSession ()) {
915
945
Record record = session .run ("CREATE (n:PersonWithRelationshipWithProperties{name:'Freddie'}),"
916
- + " (n)-[l1:LIKES"
946
+ + " (n)-[l1:LIKES "
917
947
+ "{since: 1995, active: true, localDate: date('1995-02-26'), myEnum: 'SOMETHING', point: point({x: 0, y: 1})}"
918
- + "]->(h1:Hobby{name:'Music'})," + " (n)-[l2:LIKES"
948
+ + "]->(h1:Hobby{name:'Music'}), "
949
+ + "(n)-[l2:LIKES "
919
950
+ "{since: 2000, active: false, localDate: date('2000-06-28'), myEnum: 'SOMETHING_DIFFERENT', point: point({x: 2, y: 3})}"
920
- + "]->(h2:Hobby{name:'Something else'})" + "RETURN n, h1, h2" ).single ();
951
+ + "]->(h2:Hobby{name:'Something else'}), "
952
+ + "(n) - [:OWNS] -> (p:Pet {name: 'A Pet'}), "
953
+ + "(n) - [:OWNS {place: 'The place to be'}] -> (c1:Club {name: 'Berlin Mitte'}), "
954
+ + "(n) - [:OWNS {place: 'Whatever'}] -> (c2:Club {name: 'Schachklub'}) "
955
+ + "RETURN n, h1, h2" ).single ();
921
956
922
957
Node personNode = record .get ("n" ).asNode ();
923
958
Node hobbyNode1 = record .get ("h1" ).asNode ();
@@ -932,6 +967,7 @@ void findEntityWithRelationshipWithProperties(
932
967
assertThat (optionalPerson ).isPresent ();
933
968
PersonWithRelationshipWithProperties person = optionalPerson .get ();
934
969
assertThat (person .getName ()).isEqualTo ("Freddie" );
970
+ assertThat (person .getPets ()).hasSize (1 ).first ().extracting (Pet ::getName ).isEqualTo ("A Pet" );
935
971
936
972
Hobby hobby1 = new Hobby ();
937
973
hobby1 .setName ("Music" );
@@ -955,17 +991,22 @@ void findEntityWithRelationshipWithProperties(
955
991
assertThat (hobbies ).containsExactlyInAnyOrder (rel1 , rel2 );
956
992
assertThat (hobbies .get (hobbies .indexOf (rel1 )).getHobby ()).isEqualTo (hobby1 );
957
993
assertThat (hobbies .get (hobbies .indexOf (rel2 )).getHobby ()).isEqualTo (hobby2 );
994
+
995
+ assertThat (person .getClubs ()).hasSize (2 )
996
+ .extracting (ClubRelationship ::getPlace )
997
+ .containsExactlyInAnyOrder ("The place to be" , "Whatever" );
958
998
}
959
999
960
1000
@ Test
961
- void findEntityWithRelationshipWithPropertiesScalar (
962
- @ Autowired PersonWithRelationshipWithPropertiesRepository repository ) {
1001
+ void findEntityWithRelationshipWithPropertiesScalar (@ Autowired PersonWithRelationshipWithPropertiesRepository repository ) {
963
1002
964
1003
long personId ;
965
1004
966
1005
try (Session session = createSession ()) {
967
1006
Record record = session .run ("CREATE (n:PersonWithRelationshipWithProperties{name:'Freddie'}),"
968
- + " (n)-[:WORKS_IN{since: 1995}]->(:Club{name:'Blubb'})"
1007
+ + " (n)-[:WORKS_IN{since: 1995}]->(:Club{name:'Blubb'}),"
1008
+ + "(n) - [:OWNS {place: 'The place to be'}] -> (c1:Club {name: 'Berlin Mitte'}), "
1009
+ + "(n) - [:OWNS {place: 'Whatever'}] -> (c2:Club {name: 'Schachklub'}) "
969
1010
+ "RETURN n" ).single ();
970
1011
971
1012
Node personNode = record .get ("n" ).asNode ();
0 commit comments