forked from serverlessworkflow/sdk-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApiTest.java
More file actions
141 lines (133 loc) · 6.17 KB
/
ApiTest.java
File metadata and controls
141 lines (133 loc) · 6.17 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
* Copyright 2020-Present The Serverless Workflow Specification Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.serverlessworkflow.api;
import static io.serverlessworkflow.api.WorkflowReader.readWorkflowFromClasspath;
import static org.assertj.core.api.Assertions.assertThat;
import io.serverlessworkflow.api.types.BearerAuthenticationPolicy;
import io.serverlessworkflow.api.types.CallFunction;
import io.serverlessworkflow.api.types.CallHTTP;
import io.serverlessworkflow.api.types.CallTask;
import io.serverlessworkflow.api.types.HTTPArguments;
import io.serverlessworkflow.api.types.OAuth2AuthenticationData;
import io.serverlessworkflow.api.types.OAuth2AuthenticationData.OAuth2AuthenticationDataGrant;
import io.serverlessworkflow.api.types.OAuth2AuthenticationPolicy;
import io.serverlessworkflow.api.types.OAuth2AuthenticationPolicyConfiguration;
import io.serverlessworkflow.api.types.OAuth2AuthenticationPropertiesEndpoints;
import io.serverlessworkflow.api.types.Task;
import io.serverlessworkflow.api.types.Workflow;
import java.io.IOException;
import java.net.URI;
import org.junit.jupiter.api.Test;
public class ApiTest {
@Test
void testCallHTTPAPI() throws IOException {
Workflow workflow = readWorkflowFromClasspath("features/callHttp.yaml");
assertThat(workflow.getDo()).isNotEmpty();
assertThat(workflow.getDo().get(0).getName()).isNotNull();
assertThat(workflow.getDo().get(0).getTask()).isNotNull();
Task task = workflow.getDo().get(0).getTask();
if (task.get() instanceof CallTask) {
CallTask callTask = task.getCallTask();
assertThat(callTask).isNotNull();
assertThat(task.getDoTask()).isNull();
CallHTTP httpCall = callTask.getCallHTTP();
assertThat(httpCall).isNotNull();
assertThat(callTask.getCallAsyncAPI()).isNull();
HTTPArguments httpParams = httpCall.getWith();
assertThat(httpParams.getMethod()).isEqualTo("get");
assertThat(
httpParams
.getEndpoint()
.getEndpointConfiguration()
.getUri()
.getLiteralEndpointURI()
.getLiteralUriTemplate())
.isEqualTo("https://petstore.swagger.io/v2/pet/{petId}");
}
}
@Test
void testCallFunctionAPIWithoutArguments() throws IOException {
Workflow workflow = readWorkflowFromClasspath("features/callFunction.yaml");
assertThat(workflow.getDo()).isNotEmpty();
assertThat(workflow.getDo().get(0).getName()).isNotNull();
assertThat(workflow.getDo().get(0).getTask()).isNotNull();
Task task = workflow.getDo().get(0).getTask();
CallTask callTask = task.getCallTask();
assertThat(callTask).isNotNull();
assertThat(callTask.get()).isInstanceOf(CallFunction.class);
CallFunction functionCall = callTask.getCallFunction();
assertThat(functionCall).isNotNull();
assertThat(callTask.getCallAsyncAPI()).isNull();
assertThat(functionCall.getWith()).isNull();
}
@Test
void testOauth2Auth() throws IOException {
Workflow workflow = readWorkflowFromClasspath("features/authentication-oauth2.yaml");
assertThat(workflow.getDo()).isNotEmpty();
assertThat(workflow.getDo().get(0).getName()).isNotNull();
assertThat(workflow.getDo().get(0).getTask()).isNotNull();
Task task = workflow.getDo().get(0).getTask();
CallTask callTask = task.getCallTask();
assertThat(callTask).isNotNull();
assertThat(callTask.get()).isInstanceOf(CallHTTP.class);
CallHTTP httpCall = callTask.getCallHTTP();
OAuth2AuthenticationPolicy oauthPolicy =
httpCall
.getWith()
.getEndpoint()
.getEndpointConfiguration()
.getAuthentication()
.getAuthenticationPolicy()
.getOAuth2AuthenticationPolicy();
assertThat(oauthPolicy).isNotNull();
OAuth2AuthenticationPolicyConfiguration oauth2Props =
oauthPolicy.getOauth2().getOAuth2ConnectAuthenticationProperties();
assertThat(oauth2Props).isNotNull();
OAuth2AuthenticationPropertiesEndpoints endpoints =
oauth2Props.getOAuth2ConnectAuthenticationProperties().getEndpoints();
assertThat(endpoints.getToken()).isEqualTo("/auth/token");
assertThat(endpoints.getIntrospection()).isEqualTo("/auth/introspect");
OAuth2AuthenticationData oauth2Data = oauth2Props.getOAuth2AuthenticationData();
assertThat(oauth2Data.getAuthority().getLiteralUri())
.isEqualTo(URI.create("http://keycloak/realms/fake-authority"));
assertThat(oauth2Data.getGrant()).isEqualTo(OAuth2AuthenticationDataGrant.CLIENT_CREDENTIALS);
assertThat(oauth2Data.getClient().getId()).isEqualTo("workflow-runtime-id");
assertThat(oauth2Data.getClient().getSecret()).isEqualTo("workflow-runtime-secret");
}
@Test
void testBearerAuth() throws IOException {
Workflow workflow = readWorkflowFromClasspath("features/authentication-bearer.yaml");
assertThat(workflow.getDo()).isNotEmpty();
assertThat(workflow.getDo().get(0).getName()).isNotNull();
assertThat(workflow.getDo().get(0).getTask()).isNotNull();
Task task = workflow.getDo().get(0).getTask();
CallTask callTask = task.getCallTask();
assertThat(callTask).isNotNull();
assertThat(callTask.get()).isInstanceOf(CallHTTP.class);
CallHTTP httpCall = callTask.getCallHTTP();
BearerAuthenticationPolicy bearerPolicy =
httpCall
.getWith()
.getEndpoint()
.getEndpointConfiguration()
.getAuthentication()
.getAuthenticationPolicy()
.getBearerAuthenticationPolicy();
assertThat(bearerPolicy).isNotNull();
assertThat(bearerPolicy.getBearer().getBearerAuthenticationProperties().getToken())
.isEqualTo("${ .token }");
}
}