Skip to content

Add Temporary:CypherPathAndRelationship support in Testkit backend #1107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() ) ) );
} );
}
}