Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add edge tests #3

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
}

}
Loading