Skip to content

Commit 09a2e13

Browse files
committed
test: notifyErrored
1 parent c351fda commit 09a2e13

1 file changed

Lines changed: 39 additions & 3 deletions

File tree

src/test/java/org/eclipse/dataplane/DataplaneTest.java

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*
1010
* Contributors:
1111
* Think-it GmbH - initial API and implementation
12+
* Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. - introduce DataFlowStatusMessage
1213
*
1314
*/
1415

@@ -30,6 +31,7 @@
3031
import java.net.URI;
3132

3233
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
34+
import static com.github.tomakehurst.wiremock.client.WireMock.absent;
3335
import static com.github.tomakehurst.wiremock.client.WireMock.and;
3436
import static com.github.tomakehurst.wiremock.client.WireMock.anyUrl;
3537
import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
@@ -43,6 +45,7 @@
4345
import static org.assertj.core.api.Assertions.assertThat;
4446
import static org.assertj.core.api.Assertions.assertThatThrownBy;
4547
import static org.eclipse.dataplane.domain.dataflow.DataFlow.State.COMPLETED;
48+
import static org.eclipse.dataplane.domain.dataflow.DataFlow.State.TERMINATED;
4649

4750
class DataplaneTest {
4851

@@ -111,12 +114,41 @@ void shouldTransitionToCompleted_whenControlPlaneRespondCorrectly() {
111114
assertThat(result.succeeded()).isTrue();
112115
assertThat(dataplane.status("dataFlowId").getContent().state()).isEqualTo(COMPLETED.name());
113116
}
117+
}
118+
119+
@Nested
120+
class NotifyErrored {
121+
@Test
122+
void shouldFail_whenDataFlowDoesNotExist() {
123+
var dataplane = Dataplane.newInstance().build();
114124

115-
private DataFlowPrepareMessage createPrepareMessage() {
116-
return new DataFlowPrepareMessage("any", "any", "any", "any", "dataFlowId", "any", "any",
117-
URI.create(controlPlane.baseUrl()), "Something-PUSH", emptyList(), emptyMap());
125+
var result = dataplane.notifyErrored("dataFlowId", new RuntimeException("some-error"));
126+
127+
assertThat(result.failed()).isTrue();
128+
assertThatThrownBy(result::orElseThrow).isExactlyInstanceOf(ResourceNotFoundException.class);
118129
}
119130

131+
@Test
132+
void shouldSendDataFlowStatusMessage_whenDataFlowIsErrored() {
133+
controlPlane.stubFor(post(anyUrl()).willReturn(aResponse().withStatus(200)));
134+
var dataplane = Dataplane.newInstance().id("dataplane-id").onPrepare(Result::success).build();
135+
dataplane.prepare(createPrepareMessage());
136+
137+
var result = dataplane.notifyErrored("dataFlowId", new RuntimeException("some-error"));
138+
139+
assertThat(result.succeeded()).isTrue();
140+
assertThat(dataplane.status("dataFlowId").getContent().state()).isEqualTo(TERMINATED.name());
141+
142+
controlPlane.verify(postRequestedFor(urlPathEqualTo("/transfers/dataFlowId/dataflow/errored"))
143+
.withRequestBody(and(
144+
matchingJsonPath("dataplaneId", equalTo("dataplane-id")),
145+
matchingJsonPath("dataFlowId", equalTo("dataFlowId")),
146+
matchingJsonPath("state", equalTo("TERMINATED")),
147+
matchingJsonPath("dataAddress", absent()),
148+
matchingJsonPath("error", equalTo("some-error"))
149+
))
150+
);
151+
}
120152
}
121153

122154
@Nested
@@ -164,4 +196,8 @@ void shouldFail_whenStatusIsNot200() {
164196
}
165197
}
166198

199+
private DataFlowPrepareMessage createPrepareMessage() {
200+
return new DataFlowPrepareMessage("any", "any", "any", "any", "dataFlowId", "any", "any",
201+
URI.create(controlPlane.baseUrl()), "Something-PUSH", emptyList(), emptyMap());
202+
}
167203
}

0 commit comments

Comments
 (0)