Skip to content

Commit ad1a312

Browse files
authored
Add Temporary:CypherPathAndRelationship support in Testkit backend (#1107) (#1111)
1 parent 95037cd commit ad1a312

File tree

5 files changed

+125
-2
lines changed

5 files changed

+125
-2
lines changed

testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/TestkitModule.java

+6
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
import neo4j.org.testkit.backend.messages.responses.serializer.TestkitListValueSerializer;
2525
import neo4j.org.testkit.backend.messages.responses.serializer.TestkitMapValueSerializer;
2626
import neo4j.org.testkit.backend.messages.responses.serializer.TestkitNodeValueSerializer;
27+
import neo4j.org.testkit.backend.messages.responses.serializer.TestkitPathValueSerializer;
2728
import neo4j.org.testkit.backend.messages.responses.serializer.TestkitRecordSerializer;
29+
import neo4j.org.testkit.backend.messages.responses.serializer.TestkitRelationshipValueSerializer;
2830
import neo4j.org.testkit.backend.messages.responses.serializer.TestkitValueSerializer;
2931

3032
import java.util.List;
@@ -35,6 +37,8 @@
3537
import org.neo4j.driver.internal.value.ListValue;
3638
import org.neo4j.driver.internal.value.MapValue;
3739
import org.neo4j.driver.internal.value.NodeValue;
40+
import org.neo4j.driver.internal.value.PathValue;
41+
import org.neo4j.driver.internal.value.RelationshipValue;
3842

3943
public class TestkitModule extends SimpleModule
4044
{
@@ -48,5 +52,7 @@ public TestkitModule()
4852
this.addSerializer( Record.class, new TestkitRecordSerializer() );
4953
this.addSerializer( MapValue.class, new TestkitMapValueSerializer() );
5054
this.addSerializer( Bookmark.class, new TestkitBookmarkSerializer() );
55+
this.addSerializer( PathValue.class, new TestkitPathValueSerializer() );
56+
this.addSerializer( RelationshipValue.class, new TestkitRelationshipValueSerializer() );
5157
}
5258
}

testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/GetFeatures.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ public class GetFeatures implements TestkitRequest
5656
"Feature:API:Liveness.Check",
5757
"Temporary:DriverMaxConnectionPoolSize",
5858
"Temporary:ConnectionAcquisitionTimeout",
59-
"Temporary:GetConnectionPoolMetrics"
59+
"Temporary:GetConnectionPoolMetrics",
60+
"Temporary:CypherPathAndRelationship"
6061
) );
6162

6263
private static final Set<String> SYNC_FEATURES = new HashSet<>( Arrays.asList(

testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/responses/serializer/TestkitNodeValueSerializer.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.function.Function;
2727
import java.util.stream.StreamSupport;
2828

29+
import org.neo4j.driver.internal.value.IntegerValue;
2930
import org.neo4j.driver.internal.value.ListValue;
3031
import org.neo4j.driver.internal.value.MapValue;
3132
import org.neo4j.driver.internal.value.NodeValue;
@@ -48,7 +49,7 @@ public void serialize( NodeValue nodeValue, JsonGenerator gen, SerializerProvide
4849
cypherObject( gen, "Node", () ->
4950
{
5051
Node node = nodeValue.asNode();
51-
gen.writeObjectField( "id", node.id() );
52+
gen.writeObjectField( "id", new IntegerValue( node.id() ) );
5253

5354
StringValue[] labels = StreamSupport.stream( node.labels().spliterator(), false )
5455
.map( StringValue::new )
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
package neo4j.org.testkit.backend.messages.responses.serializer;
20+
21+
import com.fasterxml.jackson.core.JsonGenerator;
22+
import com.fasterxml.jackson.databind.SerializerProvider;
23+
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
24+
25+
import java.io.IOException;
26+
import java.util.stream.StreamSupport;
27+
28+
import org.neo4j.driver.internal.value.ListValue;
29+
import org.neo4j.driver.internal.value.NodeValue;
30+
import org.neo4j.driver.internal.value.PathValue;
31+
import org.neo4j.driver.internal.value.RelationshipValue;
32+
import org.neo4j.driver.types.Path;
33+
34+
import static neo4j.org.testkit.backend.messages.responses.serializer.GenUtils.cypherObject;
35+
36+
public class TestkitPathValueSerializer extends StdSerializer<PathValue>
37+
{
38+
public TestkitPathValueSerializer()
39+
{
40+
super( PathValue.class );
41+
}
42+
43+
@Override
44+
public void serialize( PathValue pathValue, JsonGenerator gen, SerializerProvider provider ) throws IOException
45+
{
46+
cypherObject( gen, "Path", () ->
47+
{
48+
Path path = pathValue.asPath();
49+
NodeValue[] nodes = StreamSupport.stream( path.nodes().spliterator(), false )
50+
.map( NodeValue::new )
51+
.toArray( NodeValue[]::new );
52+
gen.writeObjectField( "nodes", new ListValue( nodes ) );
53+
RelationshipValue[] relationships = StreamSupport.stream( path.relationships().spliterator(), false )
54+
.map( RelationshipValue::new )
55+
.toArray( RelationshipValue[]::new );
56+
gen.writeObjectField( "relationships", new ListValue( relationships ) );
57+
} );
58+
}
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
package neo4j.org.testkit.backend.messages.responses.serializer;
20+
21+
import com.fasterxml.jackson.core.JsonGenerator;
22+
import com.fasterxml.jackson.databind.SerializerProvider;
23+
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
24+
25+
import java.io.IOException;
26+
import java.util.function.Function;
27+
28+
import org.neo4j.driver.internal.value.IntegerValue;
29+
import org.neo4j.driver.internal.value.MapValue;
30+
import org.neo4j.driver.internal.value.RelationshipValue;
31+
import org.neo4j.driver.internal.value.StringValue;
32+
import org.neo4j.driver.types.Relationship;
33+
34+
import static neo4j.org.testkit.backend.messages.responses.serializer.GenUtils.cypherObject;
35+
36+
public class TestkitRelationshipValueSerializer extends StdSerializer<RelationshipValue>
37+
{
38+
public TestkitRelationshipValueSerializer()
39+
{
40+
super( RelationshipValue.class );
41+
}
42+
43+
@Override
44+
public void serialize( RelationshipValue relationshipValue, JsonGenerator gen, SerializerProvider provider ) throws IOException
45+
{
46+
cypherObject( gen, "Relationship", () ->
47+
{
48+
Relationship relationship = relationshipValue.asRelationship();
49+
gen.writeObjectField( "id", new IntegerValue( relationship.id() ) );
50+
gen.writeObjectField( "startNodeId", new IntegerValue( relationship.startNodeId() ) );
51+
gen.writeObjectField( "endNodeId", new IntegerValue( relationship.endNodeId() ) );
52+
gen.writeObjectField( "type", new StringValue( relationship.type() ) );
53+
gen.writeObjectField( "props", new MapValue( relationship.asMap( Function.identity() ) ) );
54+
} );
55+
}
56+
}

0 commit comments

Comments
 (0)