diff --git a/.gitignore b/.gitignore index 38acd51906..c870b67e29 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,4 @@ community/server-plugin-test/neo4j-home enterprise/server-enterprise/neo4j-home integrationtests/data dependency-reduced-pom.xml +venv 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 588d7949c9..9df43cc0c0 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 @@ -19,12 +19,17 @@ package neo4j.org.testkit.backend.messages; import com.fasterxml.jackson.databind.module.SimpleModule; +import neo4j.org.testkit.backend.messages.requests.deserializer.TestkitListDeserializer; +import neo4j.org.testkit.backend.messages.responses.serializer.TestkitBookmarkSerializer; 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.TestkitRecordSerializer; import neo4j.org.testkit.backend.messages.responses.serializer.TestkitValueSerializer; +import java.util.List; + +import org.neo4j.driver.Bookmark; import org.neo4j.driver.Record; import org.neo4j.driver.Value; import org.neo4j.driver.internal.value.ListValue; @@ -35,10 +40,13 @@ public class TestkitModule extends SimpleModule { public TestkitModule() { + this.addDeserializer( List.class, new TestkitListDeserializer() ); + this.addSerializer( Value.class, new TestkitValueSerializer() ); this.addSerializer( NodeValue.class, new TestkitNodeValueSerializer() ); this.addSerializer( ListValue.class, new TestkitListValueSerializer() ); this.addSerializer( Record.class, new TestkitRecordSerializer() ); this.addSerializer( MapValue.class, new TestkitMapValueSerializer() ); + this.addSerializer( Bookmark.class, new TestkitBookmarkSerializer() ); } } diff --git a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/NewSession.java b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/NewSession.java index 98e9688cb5..c0c4cff55a 100644 --- a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/NewSession.java +++ b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/NewSession.java @@ -56,6 +56,11 @@ public TestkitResponse process( TestkitState testkitState ) Optional.ofNullable( data.database ).ifPresent( builder::withDatabase ); + if ( data.getFetchSize() != 0 ) + { + builder.withFetchSize( data.getFetchSize() ); + } + org.neo4j.driver.Session session = driver.session( builder.build() ); String newId = testkitState.newId(); testkitState.getSessionStates().put( newId, new SessionState( session ) ); diff --git a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/SessionBeginTransaction.java b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/SessionBeginTransaction.java index 8f91cf45e3..51fad1a4ef 100644 --- a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/SessionBeginTransaction.java +++ b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/SessionBeginTransaction.java @@ -26,6 +26,7 @@ import neo4j.org.testkit.backend.messages.responses.TestkitResponse; import neo4j.org.testkit.backend.messages.responses.Transaction; +import java.time.Duration; import java.util.Map; import java.util.Optional; @@ -47,7 +48,12 @@ public TestkitResponse process( TestkitState testkitState ) { TransactionConfig.Builder builder = TransactionConfig.builder(); Optional.ofNullable( data.txMeta ).ifPresent( builder::withMetadata ); - // Optional.ofNullable( data.timeout ).ifPresent( builder::withTimeout ); + + if ( data.getTimeout() != null ) + { + builder.withTimeout( Duration.ofMillis( data.getTimeout() ) ); + } + String txId = testkitState.newId(); org.neo4j.driver.Transaction tx = session.beginTransaction( builder.build() ); testkitState.getTransactions().put( txId, tx ); diff --git a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/SessionLastBookmarks.java b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/SessionLastBookmarks.java new file mode 100644 index 0000000000..1a38ca3025 --- /dev/null +++ b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/SessionLastBookmarks.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2002-2020 "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.requests; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import neo4j.org.testkit.backend.SessionState; +import neo4j.org.testkit.backend.TestkitState; +import neo4j.org.testkit.backend.messages.responses.Bookmarks; +import neo4j.org.testkit.backend.messages.responses.TestkitResponse; + +import java.util.Optional; + +import org.neo4j.driver.Bookmark; + +@Setter +@Getter +@NoArgsConstructor +public class SessionLastBookmarks implements TestkitRequest +{ + private SessionLastBookmarksBody data; + + @Override + public TestkitResponse process( TestkitState testkitState ) + { + return Optional.ofNullable( testkitState.getSessionStates().getOrDefault( data.sessionId, null ) ) + .map( SessionState::getSession ) + .map( session -> + { + Bookmark bookmark = testkitState.getSessionStates().get( data.getSessionId() ).getSession().lastBookmark(); + return Bookmarks.builder().data( Bookmarks.BookmarksBody.builder().bookmarks( bookmark ).build() ).build(); + } ) + .orElseThrow( () -> new RuntimeException( "Could not find session" ) ); + } + + @Setter + @Getter + @NoArgsConstructor + public static class SessionLastBookmarksBody + { + private String sessionId; + } +} diff --git a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/SessionRun.java b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/SessionRun.java index 0432c16748..c9cfcb5040 100644 --- a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/SessionRun.java +++ b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/SessionRun.java @@ -23,15 +23,17 @@ import lombok.NoArgsConstructor; import lombok.Setter; import neo4j.org.testkit.backend.TestkitState; -import neo4j.org.testkit.backend.messages.TestkitCypherTypeDeserializer; +import neo4j.org.testkit.backend.messages.requests.deserializer.TestkitCypherParamDeserializer; import neo4j.org.testkit.backend.messages.responses.Result; import neo4j.org.testkit.backend.messages.responses.TestkitResponse; +import java.time.Duration; import java.util.Map; import java.util.Optional; import org.neo4j.driver.Query; import org.neo4j.driver.Session; +import org.neo4j.driver.TransactionConfig; @Setter @Getter @@ -47,7 +49,10 @@ public TestkitResponse process( TestkitState testkitState ) Query query = Optional.ofNullable( data.params ) .map( params -> new Query( data.cypher, data.params ) ) .orElseGet( () -> new Query( data.cypher ) ); - org.neo4j.driver.Result result = session.run( query ); + TransactionConfig.Builder transactionConfig = TransactionConfig.builder(); + Optional.ofNullable( data.getTxMeta() ).ifPresent( transactionConfig::withMetadata ); + Optional.ofNullable( data.getTimeout() ).ifPresent( to -> transactionConfig.withTimeout( Duration.ofMillis( to ) ) ); + org.neo4j.driver.Result result = session.run( query, transactionConfig.build() ); String newId = testkitState.newId(); testkitState.getResults().put( newId, result ); @@ -59,12 +64,13 @@ public TestkitResponse process( TestkitState testkitState ) @NoArgsConstructor public static class SessionRunBody { + @JsonDeserialize( using = TestkitCypherParamDeserializer.class ) + private Map params; + private String sessionId; private String cypher; + private Map txMeta; + private Integer timeout; - @JsonDeserialize( using = TestkitCypherTypeDeserializer.class ) - private Map params; - private String txMeta; - private int timeout; } } diff --git a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/SessionWriteTransaction.java b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/SessionWriteTransaction.java new file mode 100644 index 0000000000..8be0999ab4 --- /dev/null +++ b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/SessionWriteTransaction.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2002-2020 "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.requests; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import neo4j.org.testkit.backend.SessionState; +import neo4j.org.testkit.backend.TestkitState; +import neo4j.org.testkit.backend.messages.responses.RetryableDone; +import neo4j.org.testkit.backend.messages.responses.RetryableTry; +import neo4j.org.testkit.backend.messages.responses.TestkitResponse; + +import java.util.Map; +import java.util.Optional; + +import org.neo4j.driver.Session; +import org.neo4j.driver.TransactionWork; + +@Setter +@Getter +@NoArgsConstructor +public class SessionWriteTransaction implements TestkitRequest +{ + private SessionWriteTransactionBody data; + + @Override + public TestkitResponse process( TestkitState testkitState ) + { + return Optional.ofNullable( testkitState.getSessionStates().getOrDefault( data.getSessionId(), null ) ) + .map( sessionState -> + { + Session session = sessionState.getSession(); + session.writeTransaction( handle( testkitState, sessionState ) ); + return retryableDone(); + } ).orElseThrow( () -> new RuntimeException( "Could not find session" ) ); + } + + private TransactionWork handle( TestkitState testkitState, SessionState sessionState ) + { + return tx -> + { + System.out.println( "Start" ); + sessionState.setRetryableState( 0 ); + String txId = testkitState.newId(); + testkitState.getTransactions().put( txId, tx ); + testkitState.getResponseWriter().accept( retryableTry( txId ) ); + + while ( true ) + { + // Process commands as usual but blocking in here + testkitState.getProcessor().get(); + + // Check if state changed on session + switch ( sessionState.retryableState ) + { + case 0: + // Nothing happened to session state while processing command + break; + case 1: + // Client is happy to commit + return 0; + case -1: + // Client wants to rollback + if ( !"".equals( sessionState.retryableErrorId ) ) + { + throw testkitState.getErrors().get( sessionState.retryableErrorId ); + } + else + { + throw new RuntimeException( "Error from client in retryable tx" ); + } + } + } + }; + } + + private RetryableTry retryableTry( String txId ) + { + return RetryableTry.builder().data( RetryableTry.RetryableTryBody.builder().id( txId ).build() ).build(); + } + + private RetryableDone retryableDone() + { + return RetryableDone.builder().build(); + } + + @Setter + @Getter + @NoArgsConstructor + public static class SessionWriteTransactionBody + { + private String sessionId; + private Map txMeta; + private String timeout; + } +} diff --git a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/TestkitRequest.java b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/TestkitRequest.java index 6157c38086..92909f95ff 100644 --- a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/TestkitRequest.java +++ b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/TestkitRequest.java @@ -30,7 +30,8 @@ @JsonSubTypes.Type( SessionClose.class ), @JsonSubTypes.Type( DriverClose.class ), @JsonSubTypes.Type( RetryableNegative.class ), @JsonSubTypes.Type( SessionReadTransaction.class ), @JsonSubTypes.Type( TransactionRun.class ), @JsonSubTypes.Type( RetryablePositive.class ), - @JsonSubTypes.Type( SessionBeginTransaction.class ), @JsonSubTypes.Type( TransactionCommit.class ) + @JsonSubTypes.Type( SessionBeginTransaction.class ), @JsonSubTypes.Type( TransactionCommit.class ), + @JsonSubTypes.Type( SessionLastBookmarks.class ), @JsonSubTypes.Type( SessionWriteTransaction.class ) } ) public interface TestkitRequest { diff --git a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/TransactionRun.java b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/TransactionRun.java index eb18d403ee..65bd70624a 100644 --- a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/TransactionRun.java +++ b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/TransactionRun.java @@ -18,13 +18,17 @@ */ package neo4j.org.testkit.backend.messages.requests; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import neo4j.org.testkit.backend.TestkitState; +import neo4j.org.testkit.backend.messages.requests.deserializer.TestkitCypherParamDeserializer; import neo4j.org.testkit.backend.messages.responses.Result; import neo4j.org.testkit.backend.messages.responses.TestkitResponse; +import java.util.Collections; +import java.util.Map; import java.util.Optional; @Setter @@ -38,7 +42,8 @@ public class TransactionRun implements TestkitRequest public TestkitResponse process( TestkitState testkitState ) { return Optional.ofNullable( testkitState.getTransactions().get( data.txId ) ) - .map( tx -> tx.run( data.cypher ) ) + .map( tx -> + tx.run( data.cypher, data.getParams() != null ? data.getParams() : Collections.emptyMap() ) ) .map( result -> { String resultId = testkitState.newId(); @@ -60,5 +65,7 @@ public static class TransactionRunBody { private String txId; private String cypher; + @JsonDeserialize( using = TestkitCypherParamDeserializer.class ) + private Map params; } } diff --git a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/TestkitCypherTypeDeserializer.java b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/deserializer/TestkitCypherParamDeserializer.java similarity index 75% rename from testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/TestkitCypherTypeDeserializer.java rename to testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/deserializer/TestkitCypherParamDeserializer.java index a4b725c6cf..2876bacdf3 100644 --- a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/TestkitCypherTypeDeserializer.java +++ b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/deserializer/TestkitCypherParamDeserializer.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package neo4j.org.testkit.backend.messages; +package neo4j.org.testkit.backend.messages.requests.deserializer; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; @@ -27,17 +27,18 @@ import java.io.IOException; import java.util.Collections; import java.util.HashMap; -import java.util.List; import java.util.Map; -public class TestkitCypherTypeDeserializer extends StdDeserializer> +import static neo4j.org.testkit.backend.messages.responses.serializer.GenUtils.cypherTypeToJavaType; + +public class TestkitCypherParamDeserializer extends StdDeserializer> { - public TestkitCypherTypeDeserializer() + public TestkitCypherParamDeserializer() { super( Map.class ); } - public TestkitCypherTypeDeserializer( Class typeClass ) + public TestkitCypherParamDeserializer( Class typeClass ) { super( typeClass ); } @@ -86,37 +87,23 @@ public Map deserialize( JsonParser p, DeserializationContext ctxt result.put( key, null ); } else { - result.put( key, p.readValueAs( mapValueType ) ); + if ( paramType.equals( "CypherMap" ) ) // special recursive case for maps + { + result.put( key, deserialize( p, ctxt ) ); + } + else + { + result.put( key, p.readValueAs( mapValueType ) ); + } } } } - + p.nextToken(); //close value + p.nextToken(); // close map } - return result; - } - private Class cypherTypeToJavaType( String typeString ) - { - switch ( typeString ) - { - case "CypherBool": - return Boolean.class; - case "CypherInt": - return Integer.class; - case "CypherFloat": - return Double.class; - case "CypherString": - return String.class; - case "CypherList": - return List.class; - case "CypherMap": - return Map.class; - case "CypherNull": - return null; - default: - return null; - } + return result; } } diff --git a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/deserializer/TestkitListDeserializer.java b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/deserializer/TestkitListDeserializer.java new file mode 100644 index 0000000000..5daff1eff1 --- /dev/null +++ b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/deserializer/TestkitListDeserializer.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2002-2020 "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.requests.deserializer; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import static neo4j.org.testkit.backend.messages.responses.serializer.GenUtils.cypherTypeToJavaType; + +public class TestkitListDeserializer extends StdDeserializer> +{ + + public TestkitListDeserializer() + { + super( List.class ); + } + + @Override + public List deserialize( JsonParser p, DeserializationContext ctxt ) throws IOException, JsonProcessingException + { + List result = new ArrayList<>(); + + JsonToken t = p.getCurrentToken(); + if ( t == JsonToken.END_OBJECT ) + { + return result; + } + if ( t != JsonToken.START_ARRAY ) + { + ctxt.reportWrongTokenException( this, JsonToken.FIELD_NAME, null ); + } + + JsonToken nextToken = p.nextToken(); + + // standard list + if ( nextToken == JsonToken.VALUE_STRING ) + { + while ( nextToken != JsonToken.END_ARRAY && nextToken != null ) + { + result.add( p.readValueAs( String.class ) ); + nextToken = p.nextToken(); + } + return result; + } + + //cypher parameter list + while ( nextToken != JsonToken.END_ARRAY ) + { + String paramType = null; + + if ( nextToken == JsonToken.START_OBJECT ) + { + String fieldName = p.nextFieldName(); + if ( fieldName.equals( "name" ) ) + { + paramType = p.nextTextValue(); + Class mapValueType = cypherTypeToJavaType( paramType ); + p.nextFieldName(); // next is data which we can drop + p.nextToken(); + p.nextToken(); + p.nextToken(); + if ( mapValueType == null ) + { + result.add( null ); + } + else + { + result.add( p.readValueAs( mapValueType ) ); + } + } + } + nextToken = p.nextToken(); + } + p.nextToken(); + p.nextToken(); + return result; + } +} \ No newline at end of file diff --git a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/responses/Bookmarks.java b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/responses/Bookmarks.java new file mode 100644 index 0000000000..2935ddce5b --- /dev/null +++ b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/responses/Bookmarks.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2002-2020 "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; + +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; + +import org.neo4j.driver.Bookmark; + +@Setter +@Getter +@Builder +public class Bookmarks implements TestkitResponse +{ + BookmarksBody data; + + @Override + public String testkitName() + { + return "Bookmarks"; + } + + @Setter + @Getter + @Builder + public static class BookmarksBody + { + private Bookmark bookmarks; + } +} diff --git a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/responses/TeskitBackendErrorResponse.java b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/responses/TestkitBackendErrorResponse.java similarity index 93% rename from testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/responses/TeskitBackendErrorResponse.java rename to testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/responses/TestkitBackendErrorResponse.java index 13a7e5a1ae..bf68d2ec94 100644 --- a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/responses/TeskitBackendErrorResponse.java +++ b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/responses/TestkitBackendErrorResponse.java @@ -25,7 +25,7 @@ @Setter @Getter @Builder -public class TeskitBackendErrorResponse implements TestkitResponse +public class TestkitBackendErrorResponse implements TestkitResponse { @Override public String testkitName() diff --git a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/responses/serializer/GenUtils.java b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/responses/serializer/GenUtils.java index fa29189226..a11095c757 100644 --- a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/responses/serializer/GenUtils.java +++ b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/responses/serializer/GenUtils.java @@ -24,6 +24,7 @@ import java.io.IOException; import java.util.List; +import java.util.Map; @AllArgsConstructor( access = AccessLevel.PRIVATE ) public final class GenUtils @@ -60,6 +61,29 @@ public static void cypherObject( JsonGenerator gen, String name, RunnableWit } ); } + public static Class cypherTypeToJavaType( String typeString ) + { + switch ( typeString ) + { + case "CypherBool": + return Boolean.class; + case "CypherInt": + return Integer.class; + case "CypherFloat": + return Double.class; + case "CypherString": + return String.class; + case "CypherList": + return List.class; + case "CypherMap": + return Map.class; + case "CypherNull": + return null; + default: + return null; + } + } + interface RunnableWithIOException { void run() throws IOException; diff --git a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/responses/serializer/TestkitBookmarkSerializer.java b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/responses/serializer/TestkitBookmarkSerializer.java new file mode 100644 index 0000000000..51d9223428 --- /dev/null +++ b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/responses/serializer/TestkitBookmarkSerializer.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2002-2020 "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.Set; + +import org.neo4j.driver.Bookmark; + +public class TestkitBookmarkSerializer extends StdSerializer +{ + public TestkitBookmarkSerializer() + { + super( Bookmark.class ); + } + + @Override + public void serialize( Bookmark value, JsonGenerator gen, SerializerProvider provider ) throws IOException + { + gen.writeStartArray(); + + Set bookmarks = value.values(); + + for ( String bm : bookmarks ) + { + gen.writeString( bm ); + } + + gen.writeEndArray(); + } +}