Skip to content

Commit

Permalink
Add Temporary:CypherPathAndRelationship support in Testkit backend (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
injectives authored Jan 14, 2022
1 parent 95037cd commit ad1a312
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
Expand All @@ -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() );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> SYNC_FEATURES = new HashSet<>( Arrays.asList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 )
Expand Down
Original file line number Diff line number Diff line change
@@ -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<PathValue>
{
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 ) );
} );
}
}
Original file line number Diff line number Diff line change
@@ -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<RelationshipValue>
{
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() ) ) );
} );
}
}

0 comments on commit ad1a312

Please sign in to comment.