public static NodeValue[] nodes( long... ids ) { return Arrays.stream( ids ) .mapToObj( id -> nodeValue( id, stringArray( "L" ), emptyMap() ) ) .toArray( NodeValue[]::new ); }
@Test public void shouldSerializeNode() throws Throwable { NodeValue nodeValue = nodeValue( 12L, stringArray( "User", "Banana" ), VirtualValues .map( new String[]{"name", "age"}, new AnyValue[]{stringValue( "Bob" ), intValue( 14 )} ) ); assertThat( serialized( nodeValue ), equalTo( "B1 71 91 B3 4E 0C 92 84 55 73 65 72 86 42 61 6E" + lineSeparator() + "61 6E 61 A2 84 6E 61 6D 65 83 42 6F 62 83 61 67" + lineSeparator() + "65 0E" ) ); }
@Test public void shouldSerializeNode() throws Throwable { NodeValue nodeValue = nodeValue( 12L, stringArray( "User", "Banana" ), map( new String[]{"name", "age"}, new AnyValue[]{stringValue( "Bob" ), intValue( 14 )} ) ); assertThat( serialized( nodeValue ), equalTo( "B1 71 91 B3 4E 0C 92 84 55 73 65 72 86 42 61 6E" + lineSeparator() + "61 6E 61 A2 84 6E 61 6D 65 83 42 6F 62 83 61 67" + lineSeparator() + "65 0E" ) ); }
@Test public void shouldSerializeRelationship() throws Throwable { RelationshipValue rel = relationshipValue( 12L, nodeValue( 1L, stringArray(), VirtualValues.EMPTY_MAP ), nodeValue( 2L, stringArray(), VirtualValues.EMPTY_MAP ), stringValue( "KNOWS" ), map( new String[]{"name", "age"}, new AnyValue[]{stringValue( "Bob" ), intValue( 14 )} ) ); assertThat( serialized( rel ), equalTo( "B1 71 91 B5 52 0C 01 02 85 4B 4E 4F 57 53 A2 84" + lineSeparator() + "6E 61 6D 65 83 42 6F 62 83 61 67 65 0E" ) ); }
@Test public void shouldHandleRelationships() { // Given RelationshipValue relValue = relationshipValue( 1L, nodeValue( 42L, stringArray( "L" ), EMPTY_MAP ), nodeValue( 42L, stringArray( "L" ), EMPTY_MAP ), stringValue( "R" ), EMPTY_MAP ); // When relValue.writeTo( converter ); // Then assertThat( converter.value(), equalTo( VirtualValues.relationship( 1L ) ) ); }
@Test void shouldHandleEdgeValueWithoutProperties() { NodeValue startNode = VirtualValues.nodeValue( 1L, Values.stringArray( "L" ), EMPTY_MAP ); NodeValue endNode = VirtualValues.nodeValue( 2L, Values.stringArray( "L" ), EMPTY_MAP ); RelationshipValue rel = VirtualValues.relationshipValue( 42L, startNode, endNode, stringValue( "R" ), EMPTY_MAP ); PrettyPrinter printer = new PrettyPrinter(); // When rel.writeTo( printer ); // Then assertThat( printer.value(), equalTo( "-[id=42 :R]-" ) ); }
public static NodeValue node( long id, String... labels ) { TextValue[] labelValues = new TextValue[labels.length]; for ( int i = 0; i < labels.length; i++ ) { labelValues[i] = stringValue( labels[i] ); } return nodeValue( id, stringArray( labels ), emptyMap() ); }
@Test public void shouldHandleNodes() { // Given NodeValue nodeValue = nodeValue( 42L, stringArray( "L" ), EMPTY_MAP ); // When nodeValue.writeTo( converter ); // Then assertThat( converter.value(), equalTo( VirtualValues.node( 42L ) ) ); }
@Test void shouldHandleNodeValueWithoutProperties() { // Given NodeValue node = VirtualValues.nodeValue( 42L, Values.stringArray( "L1", "L2", "L3" ), EMPTY_MAP ); PrettyPrinter printer = new PrettyPrinter(); // When node.writeTo( printer ); // Then assertThat( printer.value(), equalTo( "(id=42 :L1:L2:L3)" ) ); }
@Test void shouldHandleNodeValueWithoutLabelsNorProperties() { // Given NodeValue node = VirtualValues.nodeValue( 42L, Values.stringArray(), EMPTY_MAP ); PrettyPrinter printer = new PrettyPrinter(); // When node.writeTo( printer ); // Then assertThat( printer.value(), equalTo( "(id=42)" ) ); }
@Test void shouldHandleEdgeValueWithoutLabelsNorProperties() { // Given NodeValue node = VirtualValues.nodeValue( 42L, Values.stringArray(), EMPTY_MAP ); PrettyPrinter printer = new PrettyPrinter(); // When node.writeTo( printer ); // Then assertThat( printer.value(), equalTo( "(id=42)" ) ); }
@Test public void shouldSerializeRelationship() throws Throwable { RelationshipValue rel = relationshipValue( 12L, nodeValue( 1L, stringArray(), VirtualValues.EMPTY_MAP ), nodeValue( 2L, stringArray(), VirtualValues.EMPTY_MAP ), stringValue( "KNOWS" ), VirtualValues.map( new String[]{"name", "age"}, new AnyValue[]{stringValue( "Bob" ), intValue( 14 )} ) ); assertThat( serialized( rel ), equalTo( "B1 71 91 B5 52 0C 01 02 85 4B 4E 4F 57 53 A2 84" + lineSeparator() + "6E 61 6D 65 83 42 6F 62 83 61 67 65 0E" ) ); }
@Test void shouldHandlePaths() { // Given NodeValue startNode = VirtualValues.nodeValue( 1L, Values.stringArray( "L" ), EMPTY_MAP ); NodeValue endNode = VirtualValues.nodeValue( 2L, Values.stringArray( "L" ), EMPTY_MAP ); RelationshipValue rel = VirtualValues.relationshipValue( 42L, startNode, endNode, stringValue( "R" ), EMPTY_MAP ); PathValue path = VirtualValues.path( new NodeValue[]{startNode, endNode}, new RelationshipValue[]{rel} ); PrettyPrinter printer = new PrettyPrinter(); // When path.writeTo( printer ); // Then assertThat( printer.value(), equalTo( "(id=1 :L)-[id=42 :R]->(id=2 :L)" ) ); }
@Test public void shouldHandlePaths() { // Given NodeValue n1 = nodeValue( 42L, stringArray( "L" ), EMPTY_MAP ); NodeValue n2 = nodeValue( 43L, stringArray( "L" ), EMPTY_MAP ); PathValue p = path( new NodeValue[]{n1, n2}, new RelationshipValue[]{relationshipValue( 1L, n1, n2, stringValue( "T" ), EMPTY_MAP )} ); // When p.writeTo( converter ); // Then Object value = converter.value(); assertThat( value, instanceOf( Path.class ) ); Path path = (Path) value; assertThat( path.length(), equalTo( 1 ) ); assertThat( path.startNode().getId(), equalTo( 42L ) ); assertThat( path.endNode().getId(), equalTo( 43L ) ); assertThat( path.relationships().iterator().next().getId(), equalTo( 1L ) ); }
@Test void shouldHandleEdgeValue() { // Given NodeValue startNode = VirtualValues.nodeValue( 1L, Values.stringArray( "L" ), EMPTY_MAP ); NodeValue endNode = VirtualValues.nodeValue( 2L, Values.stringArray( "L" ), EMPTY_MAP ); RelationshipValue rel = VirtualValues.relationshipValue( 42L, startNode, endNode, stringValue( "R" ), props( "foo", intValue( 42 ), "bar", list( intValue( 1337 ), stringValue( "baz" ) ) ) ); PrettyPrinter printer = new PrettyPrinter(); // When rel.writeTo( printer ); // Then assertThat( printer.value(), equalTo( "-[id=42 :R {bar: [1337, \"baz\"], foo: 42}]-" ) ); }
@Test void shouldHandleNodeValue() { // Given NodeValue node = VirtualValues.nodeValue( 42L, Values.stringArray( "L1", "L2", "L3" ), props( "foo", intValue( 42 ), "bar", list( intValue( 1337 ), stringValue( "baz" ) ) ) ); PrettyPrinter printer = new PrettyPrinter(); // When node.writeTo( printer ); // Then assertThat( printer.value(), equalTo( "(id=42 :L1:L2:L3 {bar: [1337, \"baz\"], foo: 42})" ) ); }
@Test void shouldHandleNodeValueWithoutLabels() { // Given NodeValue node = VirtualValues.nodeValue( 42L, Values.stringArray(), props( "foo", intValue( 42 ), "bar", list( intValue( 1337 ), stringValue( "baz" ) ) ) ); PrettyPrinter printer = new PrettyPrinter(); // When node.writeTo( printer ); // Then assertThat( printer.value(), equalTo( "(id=42 {bar: [1337, \"baz\"], foo: 42})" ) ); }
private static Stream<AnyValue> unsupportedValues() { return Stream.of( nodeValue( 42, stringArray( "Person" ), EMPTY_MAP ), newRelationshipValue(), pointValue( CoordinateReferenceSystem.WGS84, new double[2] ), byteArray( new byte[]{1, 2, 3} ), Values.of( Duration.ofHours( 1 ) ), Values.of( LocalDate.now() ), Values.of( LocalTime.now() ), Values.of( OffsetTime.now() ), Values.of( LocalDateTime.now() ), Values.of( ZonedDateTime.now() ) ); }
@Test public void shouldMapDirectRelationship() { // Given Node start, end; Relationship relationship; try ( Transaction tx = db.beginTx() ) { start = db.createNode(); end = db.createNode(); relationship = start.createRelationshipTo( end, RelationshipType.withName( "R" ) ); tx.success(); } RelationshipValue relationshipValue = VirtualValues.relationshipValue( relationship.getId(), nodeValue( start.getId(), Values.EMPTY_TEXT_ARRAY, EMPTY_MAP ), nodeValue( start.getId(), Values.EMPTY_TEXT_ARRAY, EMPTY_MAP ), stringValue( "R" ), EMPTY_MAP ); // When Relationship coreAPIRelationship = mapper.mapRelationship( relationshipValue ); // Then try ( Transaction ignore = db.beginTx() ) { assertThat( coreAPIRelationship.getId(), equalTo( relationship.getId() ) ); assertThat( coreAPIRelationship.getStartNode(), equalTo( start ) ); assertThat( coreAPIRelationship.getEndNode(), equalTo( end ) ); } }