|
9 | 9 | import com.google.protobuf.AbstractMessage; |
10 | 10 | import com.google.protobuf.GeneratedMessageV3.Builder; |
11 | 11 | import io.contract_testing.contractcase.ContractCaseCoreError; |
| 12 | +import io.contract_testing.contractcase.case_boundary.BoundaryResult; |
| 13 | +import io.contract_testing.contractcase.case_boundary.BoundaryStateHandler; |
12 | 14 | import io.contract_testing.contractcase.case_boundary.ILogPrinter; |
13 | 15 | import io.contract_testing.contractcase.case_boundary.IResultPrinter; |
14 | 16 | import io.contract_testing.contractcase.case_boundary.IRunTestCallback; |
15 | | -import io.contract_testing.contractcase.grpc.ContractCaseStream; |
16 | 17 | import io.contract_testing.contractcase.grpc.ContractCaseStream.ContractResponse; |
17 | 18 | import io.contract_testing.contractcase.grpc.ContractCaseStream.ResultResponse; |
18 | | -import io.contract_testing.contractcase.grpc.ContractCaseStream.ResultSuccess; |
| 19 | +import io.contract_testing.contractcase.grpc.ContractCaseStream.StateHandlerHandle.Stage; |
19 | 20 | import io.grpc.Status; |
20 | 21 | import io.grpc.stub.StreamObserver; |
21 | 22 | import org.jetbrains.annotations.NotNull; |
@@ -50,13 +51,20 @@ public void onNext(final ContractResponse note) { |
50 | 51 | switch (note.getKindCase()) { |
51 | 52 | case RUN_STATE_HANDLER -> { |
52 | 53 | final var stateHandlerRunRequest = note.getRunStateHandler(); |
53 | | - // TODO Implement this properly |
| 54 | + var stateName = stateHandlerRunRequest.getStateHandlerHandle() |
| 55 | + .getHandle() |
| 56 | + .getValue(); |
| 57 | + var handle = configHandle.getStateHandler( |
| 58 | + stateName); |
| 59 | + |
54 | 60 | rpcConnector.sendResponse( |
55 | 61 | ResultResponse.newBuilder() |
56 | | - .setResult(ContractCaseStream.BoundaryResult.newBuilder() |
57 | | - .setSuccess(ResultSuccess.newBuilder().build()) |
58 | | - .build() |
59 | | - ).build(), |
| 62 | + .setResult(mapResult(runStateHandler( |
| 63 | + stateHandlerRunRequest.getStateHandlerHandle() |
| 64 | + .getStage(), |
| 65 | + stateName, |
| 66 | + handle |
| 67 | + ))).build(), |
60 | 68 | requestId |
61 | 69 | ); |
62 | 70 | } |
@@ -135,7 +143,6 @@ public void onNext(final ContractResponse note) { |
135 | 143 | } |
136 | 144 | case START_TEST_EVENT -> { |
137 | 145 | var startTestEvent = note.getStartTestEvent(); |
138 | | - |
139 | 146 | rpcConnector.sendResponse( |
140 | 147 | mapResultResponse( |
141 | 148 | runTestCallback.runTest( |
@@ -185,4 +192,17 @@ public void onError(final Throwable t) { |
185 | 192 | @Override |
186 | 193 | public void onCompleted() { |
187 | 194 | } |
| 195 | + |
| 196 | + @NotNull |
| 197 | + private static BoundaryResult runStateHandler(Stage stage, |
| 198 | + String stateName, |
| 199 | + BoundaryStateHandler handle) { |
| 200 | + return switch (stage) { |
| 201 | + case STAGE_SETUP_UNSPECIFIED -> handle.setup(); |
| 202 | + case STAGE_TEARDOWN -> handle.teardown(); |
| 203 | + case UNRECOGNIZED -> throw new ContractCaseCoreError( |
| 204 | + "Unrecognised state handler stage while trying to run '" + stateName + |
| 205 | + "'"); |
| 206 | + }; |
| 207 | + } |
188 | 208 | } |
0 commit comments