Skip to content

Commit ed55b7d

Browse files
committed
test: notifyErrored
1 parent 9979d4e commit ed55b7d

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

@@ -29,6 +30,7 @@
2930
import java.net.URI;
3031

3132
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
33+
import static com.github.tomakehurst.wiremock.client.WireMock.absent;
3234
import static com.github.tomakehurst.wiremock.client.WireMock.and;
3335
import static com.github.tomakehurst.wiremock.client.WireMock.anyUrl;
3436
import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
@@ -42,6 +44,7 @@
4244
import static org.assertj.core.api.Assertions.assertThat;
4345
import static org.assertj.core.api.Assertions.assertThatThrownBy;
4446
import static org.eclipse.dataplane.domain.dataflow.DataFlow.State.COMPLETED;
47+
import static org.eclipse.dataplane.domain.dataflow.DataFlow.State.TERMINATED;
4548

4649
class DataplaneTest {
4750

@@ -107,12 +110,41 @@ void shouldTransitionToCompleted_whenControlPlaneRespondCorrectly() {
107110
assertThat(result.succeeded()).isTrue();
108111
assertThat(dataplane.status("dataFlowId").getContent().state()).isEqualTo(COMPLETED.name());
109112
}
113+
}
114+
115+
@Nested
116+
class NotifyErrored {
117+
@Test
118+
void shouldFail_whenDataFlowDoesNotExist() {
119+
var dataplane = Dataplane.newInstance().build();
110120

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);
114125
}
115126

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+
}
116148
}
117149

118150
@Nested
@@ -160,4 +192,8 @@ void shouldFail_whenStatusIsNot200() {
160192
}
161193
}
162194

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+
}
163199
}

0 commit comments

Comments
 (0)