forked from eclipse-dataplane-core/dataplane-sdk-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataplaneClient.java
More file actions
118 lines (99 loc) · 4.06 KB
/
DataplaneClient.java
File metadata and controls
118 lines (99 loc) · 4.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* Copyright (c) 2025 Think-it GmbH
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Think-it GmbH - initial API and implementation
*
*/
package org.eclipse.dataplane;
import io.restassured.http.ContentType;
import io.restassured.response.ValidatableResponse;
import io.restassured.specification.RequestSpecification;
import org.eclipse.dataplane.domain.Result;
import org.eclipse.dataplane.domain.dataflow.DataFlowPrepareMessage;
import org.eclipse.dataplane.domain.dataflow.DataFlowResumeMessage;
import org.eclipse.dataplane.domain.dataflow.DataFlowStartMessage;
import org.eclipse.dataplane.domain.dataflow.DataFlowStartedNotificationMessage;
import org.eclipse.dataplane.domain.dataflow.DataFlowSuspendMessage;
import org.eclipse.dataplane.domain.dataflow.DataFlowTerminateMessage;
import java.util.function.Supplier;
import static io.restassured.RestAssured.given;
public class DataplaneClient {
private final String baseUri;
private final Supplier<Result<String>> authorizationTokenGenerator;
public DataplaneClient(String baseUri, Supplier<Result<String>> authorizationTokenGenerator) {
this.baseUri = baseUri;
this.authorizationTokenGenerator = authorizationTokenGenerator;
}
public ValidatableResponse prepare(DataFlowPrepareMessage prepareMessage) {
return baseRequest()
.body(prepareMessage)
.post("/v1/dataflows/prepare")
.then()
.log().ifValidationFails();
}
public ValidatableResponse start(DataFlowStartMessage startMessage) {
return baseRequest()
.body(startMessage)
.post("/v1/dataflows/start")
.then()
.log().ifValidationFails();
}
public ValidatableResponse terminate(String dataFlowId, DataFlowTerminateMessage terminateMessage) {
return baseRequest()
.body(terminateMessage)
.post("/v1/dataflows/{id}/terminate", dataFlowId)
.then()
.log().ifValidationFails();
}
public ValidatableResponse status(String dataFlowId) {
return given()
.baseUri(baseUri)
.get("/v1/dataflows/{id}/status", dataFlowId)
.then()
.log().ifValidationFails();
}
public ValidatableResponse started(String dataFlowId, DataFlowStartedNotificationMessage startedNotificationMessage) {
return baseRequest()
.body(startedNotificationMessage)
.post("/v1/dataflows/{id}/started", dataFlowId)
.then()
.log().ifValidationFails();
}
public ValidatableResponse completed(String dataFlowId) {
return baseRequest()
.post("/v1/dataflows/{id}/completed", dataFlowId)
.then()
.log().ifValidationFails();
}
public ValidatableResponse suspend(String flowId, DataFlowSuspendMessage suspendMessage) {
return baseRequest()
.body(suspendMessage)
.post("/v1/dataflows/{id}/suspend", flowId)
.then()
.log().ifValidationFails();
}
public ValidatableResponse resume(String flowId, DataFlowResumeMessage resumeMessage) {
return baseRequest()
.body(resumeMessage)
.post("/v1/dataflows/{id}/resume", flowId)
.then()
.log().ifValidationFails();
}
private RequestSpecification baseRequest() {
var requestSpecification = given()
.contentType(ContentType.JSON)
.baseUri(baseUri);
if (authorizationTokenGenerator != null) {
authorizationTokenGenerator.get()
.onSuccess(authorizationHeader -> requestSpecification.header("Authorization", authorizationHeader));
}
return requestSpecification;
}
}