-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Temporary:CypherPathAndRelationship support in Testkit backend (#…
- Loading branch information
1 parent
95037cd
commit ad1a312
Showing
5 changed files
with
125 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...a/neo4j/org/testkit/backend/messages/responses/serializer/TestkitPathValueSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ) ); | ||
} ); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...org/testkit/backend/messages/responses/serializer/TestkitRelationshipValueSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() ) ) ); | ||
} ); | ||
} | ||
} |