Skip to content

Commit ff6b06b

Browse files
authored
Add edge tests (#3619)
1 parent 86b0d62 commit ff6b06b

File tree

1 file changed

+122
-8
lines changed

1 file changed

+122
-8
lines changed

quarkus/addons/dynamic/integration-tests/src/test/java/org/kie/kogito/process/dynamic/DynamicCallResourceTest.java

Lines changed: 122 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,25 @@
1919
package org.kie.kogito.process.dynamic;
2020

2121
import java.util.Map;
22+
import java.util.concurrent.ExecutorService;
23+
import java.util.concurrent.Executors;
24+
import java.util.concurrent.Future;
2225

2326
import org.junit.jupiter.api.Test;
2427

2528
import io.quarkus.test.junit.QuarkusTest;
2629
import io.restassured.http.ContentType;
2730

2831
import static io.restassured.RestAssured.*;
32+
import static org.hamcrest.Matchers.containsString;
2933

3034
@QuarkusTest
3135
public class DynamicCallResourceTest {
3236

3337
@Test
3438
void testDynamicCall() {
3539

36-
String id = given()
37-
.contentType(ContentType.JSON)
38-
.accept(ContentType.JSON)
39-
.when()
40-
.post("/dynamicWait")
41-
.then()
42-
.statusCode(201)
43-
.extract().path("id");
40+
String id = createDynamicWaitProcessInstance();
4441

4542
given()
4643
.contentType(ContentType.JSON)
@@ -68,4 +65,121 @@ void testDynamicCall() {
6865
.statusCode(404);
6966
}
7067

68+
@Test
69+
void testDynamicCallWithInvalidProcessId() {
70+
String invalidId = "invalid-process-id";
71+
72+
given()
73+
.contentType(ContentType.JSON)
74+
.accept(ContentType.JSON)
75+
.body(Map.of("endpoint", "/example/{processInstanceId}", "port", 8081, "method", "post", "outputExpression", "{message}"))
76+
.when()
77+
.post("/_dynamic/dynamicWait/" + invalidId + "/rest")
78+
.then()
79+
.statusCode(400)
80+
.body("message", containsString("Cannot find process instance"));
81+
}
82+
83+
@Test
84+
void testDynamicCallWithMissingUrlParameter() {
85+
String id = createDynamicWaitProcessInstance();
86+
87+
given()
88+
.contentType(ContentType.JSON)
89+
.accept(ContentType.JSON)
90+
.body(Map.of("port", 8081))
91+
.when()
92+
.post("/_dynamic/dynamicWait/" + id + "/rest")
93+
.then()
94+
.statusCode(400)
95+
.body("message", containsString("Missing required parameter Url"));
96+
}
97+
98+
@Test
99+
void testDynamicCallWithMissingMethodParameter() {
100+
String id = createDynamicWaitProcessInstance();
101+
102+
given()
103+
.contentType(ContentType.JSON)
104+
.accept(ContentType.JSON)
105+
.body(Map.of("endpoint", "/example/{processInstanceId}", "port", 8081, "outputExpression", "{message}"))
106+
.when()
107+
.post("/_dynamic/dynamicWait/" + id + "/rest")
108+
.then()
109+
.statusCode(500)
110+
.body("message", containsString("Method Not Allowed"));
111+
}
112+
113+
@Test
114+
void testDynamicCallWithMissingPortParameter() {
115+
String id = createDynamicWaitProcessInstance();
116+
117+
given()
118+
.contentType(ContentType.JSON)
119+
.accept(ContentType.JSON)
120+
.body(Map.of("endpoint", "/example/{processInstanceId}", "method", "post", "outputExpression", "{message}"))
121+
.when()
122+
.post("/_dynamic/dynamicWait/" + id + "/rest")
123+
.then()
124+
.statusCode(500);
125+
}
126+
127+
@Test
128+
void testDynamicCallWithInvalidEndpointFormat() {
129+
String id = createDynamicWaitProcessInstance();
130+
131+
given()
132+
.contentType(ContentType.JSON)
133+
.accept(ContentType.JSON)
134+
.body(Map.of("endpoint", "invalid-endpoint-format", "port", 8081, "method", "post", "outputExpression", "{message}"))
135+
.when()
136+
.post("/_dynamic/dynamicWait/" + id + "/rest")
137+
.then()
138+
.statusCode(404)
139+
.body("message", containsString("endpoint invalid-endpoint-format failed"));
140+
}
141+
142+
@Test
143+
void testConcurrentDynamicCalls() throws Exception {
144+
String id1 = createDynamicWaitProcessInstance();
145+
146+
String id2 = createDynamicWaitProcessInstance();
147+
148+
ExecutorService executor = Executors.newFixedThreadPool(2);
149+
150+
Future<?> future1 = executor.submit(() -> given()
151+
.contentType(ContentType.JSON)
152+
.accept(ContentType.JSON)
153+
.body(Map.of("endpoint", "/example/{processInstanceId}", "port", 8081, "method", "post", "outputExpression", "{message}"))
154+
.when()
155+
.post("/_dynamic/dynamicWait/" + id1 + "/rest")
156+
.then()
157+
.statusCode(200));
158+
159+
Future<?> future2 = executor.submit(() -> given()
160+
.contentType(ContentType.JSON)
161+
.accept(ContentType.JSON)
162+
.body(Map.of("endpoint", "/example/{processInstanceId}", "port", 8081, "method", "post", "outputExpression", "{message}"))
163+
.when()
164+
.post("/_dynamic/dynamicWait/" + id2 + "/rest")
165+
.then()
166+
.statusCode(200));
167+
168+
future1.get();
169+
future2.get();
170+
171+
executor.shutdown();
172+
}
173+
174+
private String createDynamicWaitProcessInstance() {
175+
return given()
176+
.contentType(ContentType.JSON)
177+
.accept(ContentType.JSON)
178+
.when()
179+
.post("/dynamicWait")
180+
.then()
181+
.statusCode(201)
182+
.extract().path("id");
183+
}
184+
71185
}

0 commit comments

Comments
 (0)