Skip to content

Commit

Permalink
Add edge tests (#3619)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmunozfe authored Aug 14, 2024
1 parent 86b0d62 commit ff6b06b
Showing 1 changed file with 122 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,25 @@
package org.kie.kogito.process.dynamic;

import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusTest;
import io.restassured.http.ContentType;

import static io.restassured.RestAssured.*;
import static org.hamcrest.Matchers.containsString;

@QuarkusTest
public class DynamicCallResourceTest {

@Test
void testDynamicCall() {

String id = given()
.contentType(ContentType.JSON)
.accept(ContentType.JSON)
.when()
.post("/dynamicWait")
.then()
.statusCode(201)
.extract().path("id");
String id = createDynamicWaitProcessInstance();

given()
.contentType(ContentType.JSON)
Expand Down Expand Up @@ -68,4 +65,121 @@ void testDynamicCall() {
.statusCode(404);
}

@Test
void testDynamicCallWithInvalidProcessId() {
String invalidId = "invalid-process-id";

given()
.contentType(ContentType.JSON)
.accept(ContentType.JSON)
.body(Map.of("endpoint", "/example/{processInstanceId}", "port", 8081, "method", "post", "outputExpression", "{message}"))
.when()
.post("/_dynamic/dynamicWait/" + invalidId + "/rest")
.then()
.statusCode(400)
.body("message", containsString("Cannot find process instance"));
}

@Test
void testDynamicCallWithMissingUrlParameter() {
String id = createDynamicWaitProcessInstance();

given()
.contentType(ContentType.JSON)
.accept(ContentType.JSON)
.body(Map.of("port", 8081))
.when()
.post("/_dynamic/dynamicWait/" + id + "/rest")
.then()
.statusCode(400)
.body("message", containsString("Missing required parameter Url"));
}

@Test
void testDynamicCallWithMissingMethodParameter() {
String id = createDynamicWaitProcessInstance();

given()
.contentType(ContentType.JSON)
.accept(ContentType.JSON)
.body(Map.of("endpoint", "/example/{processInstanceId}", "port", 8081, "outputExpression", "{message}"))
.when()
.post("/_dynamic/dynamicWait/" + id + "/rest")
.then()
.statusCode(500)
.body("message", containsString("Method Not Allowed"));
}

@Test
void testDynamicCallWithMissingPortParameter() {
String id = createDynamicWaitProcessInstance();

given()
.contentType(ContentType.JSON)
.accept(ContentType.JSON)
.body(Map.of("endpoint", "/example/{processInstanceId}", "method", "post", "outputExpression", "{message}"))
.when()
.post("/_dynamic/dynamicWait/" + id + "/rest")
.then()
.statusCode(500);
}

@Test
void testDynamicCallWithInvalidEndpointFormat() {
String id = createDynamicWaitProcessInstance();

given()
.contentType(ContentType.JSON)
.accept(ContentType.JSON)
.body(Map.of("endpoint", "invalid-endpoint-format", "port", 8081, "method", "post", "outputExpression", "{message}"))
.when()
.post("/_dynamic/dynamicWait/" + id + "/rest")
.then()
.statusCode(404)
.body("message", containsString("endpoint invalid-endpoint-format failed"));
}

@Test
void testConcurrentDynamicCalls() throws Exception {
String id1 = createDynamicWaitProcessInstance();

String id2 = createDynamicWaitProcessInstance();

ExecutorService executor = Executors.newFixedThreadPool(2);

Future<?> future1 = executor.submit(() -> given()
.contentType(ContentType.JSON)
.accept(ContentType.JSON)
.body(Map.of("endpoint", "/example/{processInstanceId}", "port", 8081, "method", "post", "outputExpression", "{message}"))
.when()
.post("/_dynamic/dynamicWait/" + id1 + "/rest")
.then()
.statusCode(200));

Future<?> future2 = executor.submit(() -> given()
.contentType(ContentType.JSON)
.accept(ContentType.JSON)
.body(Map.of("endpoint", "/example/{processInstanceId}", "port", 8081, "method", "post", "outputExpression", "{message}"))
.when()
.post("/_dynamic/dynamicWait/" + id2 + "/rest")
.then()
.statusCode(200));

future1.get();
future2.get();

executor.shutdown();
}

private String createDynamicWaitProcessInstance() {
return given()
.contentType(ContentType.JSON)
.accept(ContentType.JSON)
.when()
.post("/dynamicWait")
.then()
.statusCode(201)
.extract().path("id");
}

}

0 comments on commit ff6b06b

Please sign in to comment.