diff --git a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/TestkitModule.java b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/TestkitModule.java index d66c93b47a..47f9a7fb44 100644 --- a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/TestkitModule.java +++ b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/TestkitModule.java @@ -24,7 +24,9 @@ import neo4j.org.testkit.backend.messages.responses.serializer.TestkitListValueSerializer; import neo4j.org.testkit.backend.messages.responses.serializer.TestkitMapValueSerializer; import neo4j.org.testkit.backend.messages.responses.serializer.TestkitNodeValueSerializer; +import neo4j.org.testkit.backend.messages.responses.serializer.TestkitPathValueSerializer; import neo4j.org.testkit.backend.messages.responses.serializer.TestkitRecordSerializer; +import neo4j.org.testkit.backend.messages.responses.serializer.TestkitRelationshipValueSerializer; import neo4j.org.testkit.backend.messages.responses.serializer.TestkitValueSerializer; import java.util.List; @@ -35,6 +37,8 @@ import org.neo4j.driver.internal.value.ListValue; import org.neo4j.driver.internal.value.MapValue; import org.neo4j.driver.internal.value.NodeValue; +import org.neo4j.driver.internal.value.PathValue; +import org.neo4j.driver.internal.value.RelationshipValue; public class TestkitModule extends SimpleModule { @@ -48,5 +52,7 @@ public TestkitModule() this.addSerializer( Record.class, new TestkitRecordSerializer() ); this.addSerializer( MapValue.class, new TestkitMapValueSerializer() ); this.addSerializer( Bookmark.class, new TestkitBookmarkSerializer() ); + this.addSerializer( PathValue.class, new TestkitPathValueSerializer() ); + this.addSerializer( RelationshipValue.class, new TestkitRelationshipValueSerializer() ); } } diff --git a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/GetFeatures.java b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/GetFeatures.java index 06609ca817..67806aba1a 100644 --- a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/GetFeatures.java +++ b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/GetFeatures.java @@ -56,7 +56,8 @@ public class GetFeatures implements TestkitRequest "Feature:API:Liveness.Check", "Temporary:DriverMaxConnectionPoolSize", "Temporary:ConnectionAcquisitionTimeout", - "Temporary:GetConnectionPoolMetrics" + "Temporary:GetConnectionPoolMetrics", + "Temporary:CypherPathAndRelationship" ) ); private static final Set SYNC_FEATURES = new HashSet<>( Arrays.asList( diff --git a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/responses/serializer/TestkitNodeValueSerializer.java b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/responses/serializer/TestkitNodeValueSerializer.java index a84acef07a..19dd829cf4 100644 --- a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/responses/serializer/TestkitNodeValueSerializer.java +++ b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/responses/serializer/TestkitNodeValueSerializer.java @@ -26,6 +26,7 @@ import java.util.function.Function; import java.util.stream.StreamSupport; +import org.neo4j.driver.internal.value.IntegerValue; import org.neo4j.driver.internal.value.ListValue; import org.neo4j.driver.internal.value.MapValue; import org.neo4j.driver.internal.value.NodeValue; @@ -48,7 +49,7 @@ public void serialize( NodeValue nodeValue, JsonGenerator gen, SerializerProvide cypherObject( gen, "Node", () -> { Node node = nodeValue.asNode(); - gen.writeObjectField( "id", node.id() ); + gen.writeObjectField( "id", new IntegerValue( node.id() ) ); StringValue[] labels = StreamSupport.stream( node.labels().spliterator(), false ) .map( StringValue::new ) diff --git a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/responses/serializer/TestkitPathValueSerializer.java b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/responses/serializer/TestkitPathValueSerializer.java new file mode 100644 index 0000000000..e56346e856 --- /dev/null +++ b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/responses/serializer/TestkitPathValueSerializer.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) "Neo4j" + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package neo4j.org.testkit.backend.messages.responses.serializer; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; + +import java.io.IOException; +import java.util.stream.StreamSupport; + +import org.neo4j.driver.internal.value.ListValue; +import org.neo4j.driver.internal.value.NodeValue; +import org.neo4j.driver.internal.value.PathValue; +import org.neo4j.driver.internal.value.RelationshipValue; +import org.neo4j.driver.types.Path; + +import static neo4j.org.testkit.backend.messages.responses.serializer.GenUtils.cypherObject; + +public class TestkitPathValueSerializer extends StdSerializer +{ + public TestkitPathValueSerializer() + { + super( PathValue.class ); + } + + @Override + public void serialize( PathValue pathValue, JsonGenerator gen, SerializerProvider provider ) throws IOException + { + cypherObject( gen, "Path", () -> + { + Path path = pathValue.asPath(); + NodeValue[] nodes = StreamSupport.stream( path.nodes().spliterator(), false ) + .map( NodeValue::new ) + .toArray( NodeValue[]::new ); + gen.writeObjectField( "nodes", new ListValue( nodes ) ); + RelationshipValue[] relationships = StreamSupport.stream( path.relationships().spliterator(), false ) + .map( RelationshipValue::new ) + .toArray( RelationshipValue[]::new ); + gen.writeObjectField( "relationships", new ListValue( relationships ) ); + } ); + } +} diff --git a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/responses/serializer/TestkitRelationshipValueSerializer.java b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/responses/serializer/TestkitRelationshipValueSerializer.java new file mode 100644 index 0000000000..8bbbcc41ad --- /dev/null +++ b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/responses/serializer/TestkitRelationshipValueSerializer.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) "Neo4j" + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package neo4j.org.testkit.backend.messages.responses.serializer; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; + +import java.io.IOException; +import java.util.function.Function; + +import org.neo4j.driver.internal.value.IntegerValue; +import org.neo4j.driver.internal.value.MapValue; +import org.neo4j.driver.internal.value.RelationshipValue; +import org.neo4j.driver.internal.value.StringValue; +import org.neo4j.driver.types.Relationship; + +import static neo4j.org.testkit.backend.messages.responses.serializer.GenUtils.cypherObject; + +public class TestkitRelationshipValueSerializer extends StdSerializer +{ + public TestkitRelationshipValueSerializer() + { + super( RelationshipValue.class ); + } + + @Override + public void serialize( RelationshipValue relationshipValue, JsonGenerator gen, SerializerProvider provider ) throws IOException + { + cypherObject( gen, "Relationship", () -> + { + Relationship relationship = relationshipValue.asRelationship(); + gen.writeObjectField( "id", new IntegerValue( relationship.id() ) ); + gen.writeObjectField( "startNodeId", new IntegerValue( relationship.startNodeId() ) ); + gen.writeObjectField( "endNodeId", new IntegerValue( relationship.endNodeId() ) ); + gen.writeObjectField( "type", new StringValue( relationship.type() ) ); + gen.writeObjectField( "props", new MapValue( relationship.asMap( Function.identity() ) ) ); + } ); + } +}