|
| 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.requests; |
| 20 | + |
| 21 | +import lombok.Getter; |
| 22 | +import lombok.Setter; |
| 23 | +import neo4j.org.testkit.backend.TestkitState; |
| 24 | +import neo4j.org.testkit.backend.holder.ResultCursorHolder; |
| 25 | +import neo4j.org.testkit.backend.messages.responses.TestkitResponse; |
| 26 | +import reactor.core.publisher.Mono; |
| 27 | + |
| 28 | +import java.util.concurrent.CompletionStage; |
| 29 | + |
| 30 | +import org.neo4j.driver.Record; |
| 31 | +import org.neo4j.driver.async.ResultCursor; |
| 32 | + |
| 33 | +@Setter |
| 34 | +@Getter |
| 35 | +public class ResultSingle implements TestkitRequest |
| 36 | +{ |
| 37 | + private ResultSingleBody data; |
| 38 | + |
| 39 | + @Override |
| 40 | + public TestkitResponse process( TestkitState testkitState ) |
| 41 | + { |
| 42 | + return createResponse( testkitState.getResultHolder( data.getResultId() ).getResult().single() ); |
| 43 | + } |
| 44 | + |
| 45 | + @Override |
| 46 | + public CompletionStage<TestkitResponse> processAsync( TestkitState testkitState ) |
| 47 | + { |
| 48 | + return testkitState.getAsyncResultHolder( data.getResultId() ) |
| 49 | + .thenApply( ResultCursorHolder::getResult ) |
| 50 | + .thenCompose( ResultCursor::singleAsync ) |
| 51 | + .thenApply( this::createResponse ); |
| 52 | + } |
| 53 | + |
| 54 | + @Override |
| 55 | + public Mono<TestkitResponse> processRx( TestkitState testkitState ) |
| 56 | + { |
| 57 | + throw new UnsupportedOperationException( "Single method is not supported by reactive API" ); |
| 58 | + } |
| 59 | + |
| 60 | + @Override |
| 61 | + public Mono<TestkitResponse> processReactive( TestkitState testkitState ) |
| 62 | + { |
| 63 | + throw new UnsupportedOperationException( "Single method is not supported by reactive API" ); |
| 64 | + } |
| 65 | + |
| 66 | + private neo4j.org.testkit.backend.messages.responses.TestkitResponse createResponse( Record record ) |
| 67 | + { |
| 68 | + return neo4j.org.testkit.backend.messages.responses.Record.builder() |
| 69 | + .data( neo4j.org.testkit.backend.messages.responses.Record.RecordBody.builder() |
| 70 | + .values( record ) |
| 71 | + .build() ) |
| 72 | + .build(); |
| 73 | + } |
| 74 | + |
| 75 | + @Setter |
| 76 | + @Getter |
| 77 | + public static class ResultSingleBody |
| 78 | + { |
| 79 | + private String resultId; |
| 80 | + } |
| 81 | +} |
0 commit comments