|
19 | 19 | package org.kie.kogito.process.dynamic;
|
20 | 20 |
|
21 | 21 | import java.util.Map;
|
| 22 | +import java.util.concurrent.ExecutorService; |
| 23 | +import java.util.concurrent.Executors; |
| 24 | +import java.util.concurrent.Future; |
22 | 25 |
|
23 | 26 | import org.junit.jupiter.api.Test;
|
24 | 27 |
|
25 | 28 | import io.quarkus.test.junit.QuarkusTest;
|
26 | 29 | import io.restassured.http.ContentType;
|
27 | 30 |
|
28 | 31 | import static io.restassured.RestAssured.*;
|
| 32 | +import static org.hamcrest.Matchers.containsString; |
29 | 33 |
|
30 | 34 | @QuarkusTest
|
31 | 35 | public class DynamicCallResourceTest {
|
32 | 36 |
|
33 | 37 | @Test
|
34 | 38 | void testDynamicCall() {
|
35 | 39 |
|
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(); |
44 | 41 |
|
45 | 42 | given()
|
46 | 43 | .contentType(ContentType.JSON)
|
@@ -68,4 +65,121 @@ void testDynamicCall() {
|
68 | 65 | .statusCode(404);
|
69 | 66 | }
|
70 | 67 |
|
| 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 | + |
71 | 185 | }
|
0 commit comments