|
9 | 9 | * |
10 | 10 | * Contributors: |
11 | 11 | * Think-it GmbH - initial API and implementation |
| 12 | + * Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. - introduce DataFlowStatusMessage |
12 | 13 | * |
13 | 14 | */ |
14 | 15 |
|
|
29 | 30 | import java.net.URI; |
30 | 31 |
|
31 | 32 | import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; |
| 33 | +import static com.github.tomakehurst.wiremock.client.WireMock.absent; |
32 | 34 | import static com.github.tomakehurst.wiremock.client.WireMock.and; |
33 | 35 | import static com.github.tomakehurst.wiremock.client.WireMock.anyUrl; |
34 | 36 | import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; |
|
42 | 44 | import static org.assertj.core.api.Assertions.assertThat; |
43 | 45 | import static org.assertj.core.api.Assertions.assertThatThrownBy; |
44 | 46 | import static org.eclipse.dataplane.domain.dataflow.DataFlow.State.COMPLETED; |
| 47 | +import static org.eclipse.dataplane.domain.dataflow.DataFlow.State.TERMINATED; |
45 | 48 |
|
46 | 49 | class DataplaneTest { |
47 | 50 |
|
@@ -107,12 +110,41 @@ void shouldTransitionToCompleted_whenControlPlaneRespondCorrectly() { |
107 | 110 | assertThat(result.succeeded()).isTrue(); |
108 | 111 | assertThat(dataplane.status("dataFlowId").getContent().state()).isEqualTo(COMPLETED.name()); |
109 | 112 | } |
| 113 | + } |
| 114 | + |
| 115 | + @Nested |
| 116 | + class NotifyErrored { |
| 117 | + @Test |
| 118 | + void shouldFail_whenDataFlowDoesNotExist() { |
| 119 | + var dataplane = Dataplane.newInstance().build(); |
110 | 120 |
|
111 | | - private DataFlowPrepareMessage createPrepareMessage() { |
112 | | - return new DataFlowPrepareMessage("any", "any", "any", "any", "dataFlowId", "any", "any", |
113 | | - URI.create(controlPlane.baseUrl()), "Something-PUSH", emptyList(), emptyMap()); |
| 121 | + var result = dataplane.notifyErrored("dataFlowId", new RuntimeException("some-error")); |
| 122 | + |
| 123 | + assertThat(result.failed()).isTrue(); |
| 124 | + assertThatThrownBy(result::orElseThrow).isExactlyInstanceOf(ResourceNotFoundException.class); |
114 | 125 | } |
115 | 126 |
|
| 127 | + @Test |
| 128 | + void shouldSendDataFlowStatusMessage_whenDataFlowIsErrored() { |
| 129 | + controlPlane.stubFor(post(anyUrl()).willReturn(aResponse().withStatus(200))); |
| 130 | + var dataplane = Dataplane.newInstance().id("dataplane-id").onPrepare(Result::success).build(); |
| 131 | + dataplane.prepare(createPrepareMessage()); |
| 132 | + |
| 133 | + var result = dataplane.notifyErrored("dataFlowId", new RuntimeException("some-error")); |
| 134 | + |
| 135 | + assertThat(result.succeeded()).isTrue(); |
| 136 | + assertThat(dataplane.status("dataFlowId").getContent().state()).isEqualTo(TERMINATED.name()); |
| 137 | + |
| 138 | + controlPlane.verify(postRequestedFor(urlPathEqualTo("/transfers/dataFlowId/dataflow/errored")) |
| 139 | + .withRequestBody(and( |
| 140 | + matchingJsonPath("dataplaneId", equalTo("dataplane-id")), |
| 141 | + matchingJsonPath("dataFlowId", equalTo("dataFlowId")), |
| 142 | + matchingJsonPath("state", equalTo("TERMINATED")), |
| 143 | + matchingJsonPath("dataAddress", absent()), |
| 144 | + matchingJsonPath("error", equalTo("some-error")) |
| 145 | + )) |
| 146 | + ); |
| 147 | + } |
116 | 148 | } |
117 | 149 |
|
118 | 150 | @Nested |
@@ -160,4 +192,8 @@ void shouldFail_whenStatusIsNot200() { |
160 | 192 | } |
161 | 193 | } |
162 | 194 |
|
| 195 | + private DataFlowPrepareMessage createPrepareMessage() { |
| 196 | + return new DataFlowPrepareMessage("any", "any", "any", "any", "dataFlowId", "any", "any", |
| 197 | + URI.create(controlPlane.baseUrl()), "Something-PUSH", emptyList(), emptyMap()); |
| 198 | + } |
163 | 199 | } |
0 commit comments