Skip to content

Commit

Permalink
Merge pull request apache#42 from rgdoliveira/sync_main
Browse files Browse the repository at this point in the history
Sync main branch with Apache main branch
  • Loading branch information
rgdoliveira authored Oct 11, 2024
2 parents 7d7eddf + 1eb66ec commit 74d41ce
Show file tree
Hide file tree
Showing 184 changed files with 1,888 additions and 1,587 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.kie.kogito.flexible.example.quarkus;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -42,6 +43,7 @@
class ServiceDeskProcessTest {

private static final String BASE_PATH = "/serviceDesk";
private static final String USER_TASK_BASE_PATH = "/usertasks/instance";

static {
RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
Expand Down Expand Up @@ -91,31 +93,75 @@ private String createSupportCase() {
}

private void addSupportComment(String id) {
String location = given()
given()
.basePath(BASE_PATH)
.contentType(ContentType.JSON)
.queryParam("user", "kelly")
.queryParam("group", "support")
.when()
.post("/{id}/ReceiveSupportComment", id)
.post("/{id}/ReceiveSupportComment/trigger", id)
.then()
.statusCode(201)
.header("Location", notNullValue())
.extract()
.header("Location");

String taskId = location.substring(location.lastIndexOf("/") + 1);
String userTaskId = given()
.basePath(USER_TASK_BASE_PATH)
.queryParam("user", "kelly")
.queryParam("group", "support")
.contentType(ContentType.JSON)
.when()
.get()
.then()
.statusCode(200)
.extract()
.body()
.path("[0].id");

given()
.contentType(ContentType.JSON)
.basePath(USER_TASK_BASE_PATH)
.queryParam("transitionId", "claim")
.queryParam("user", "kelly")
.queryParam("group", "support")
.body(Collections.emptyMap())
.when()
.post("/{userTaskId}/transition", userTaskId)
.then()
.statusCode(200);

Map<String, Object> params = new HashMap<>();
params.put("comment", "Have you tried to turn it off and on again?");

given()
.basePath(BASE_PATH)
.contentType(ContentType.JSON)
.basePath(USER_TASK_BASE_PATH)
.queryParam("user", "kelly")
.queryParam("group", "support")
.body(params)
.when()
.put("/{userTaskId}/outputs", userTaskId)
.then()
.statusCode(200);

given()
.contentType(ContentType.JSON)
.basePath(USER_TASK_BASE_PATH)
.queryParam("transitionId", "complete")
.queryParam("user", "kelly")
.queryParam("group", "support")
.body(Collections.emptyMap())
.when()
.body(params)
.post("/{id}/ReceiveSupportComment/{taskId}", id, taskId)
.post("/{userTaskId}/transition", userTaskId)
.then()
.statusCode(200);

given()
.basePath(BASE_PATH)
.contentType(ContentType.JSON)
.when()
.get(id)
.then()
.statusCode(200)
.body("supportCase.state", is(State.WAITING_FOR_CUSTOMER.name()))
Expand All @@ -125,37 +171,82 @@ private void addSupportComment(String id) {
}

private void addCustomerComment(String id) {
String location = given()
given()
.basePath(BASE_PATH)
.contentType(ContentType.JSON)
.queryParam("user", "Paco")
.queryParam("group", "customer")
.when()
.post("/{id}/ReceiveCustomerComment", id)
.post("/{id}/ReceiveCustomerComment/trigger", id)
.then()
.statusCode(201)
.header("Location", notNullValue())
.extract()
.header("Location");

String taskId = location.substring(location.lastIndexOf("/") + 1);
String userTaskId = given()
.basePath(USER_TASK_BASE_PATH)
.queryParam("user", "Paco")
.queryParam("group", "customer")
.contentType(ContentType.JSON)
.when()
.get()
.then()
.statusCode(200)
.extract()
.body()
.path("[0].id");

given()
.contentType(ContentType.JSON)
.basePath(USER_TASK_BASE_PATH)
.queryParam("transitionId", "claim")
.queryParam("user", "Paco")
.queryParam("group", "customer")
.body(Collections.emptyMap())
.when()
.post("/{userTaskId}/transition", userTaskId)
.then()
.statusCode(200);

Map<String, Object> params = new HashMap<>();
params.put("comment", "Great idea!");

given()
.basePath(BASE_PATH)
.contentType(ContentType.JSON)
.basePath(USER_TASK_BASE_PATH)
.queryParam("user", "Paco")
.queryParam("group", "customer")
.body(params)
.when()
.put("/{userTaskId}/outputs", userTaskId)
.then()
.statusCode(200);

given()
.contentType(ContentType.JSON)
.basePath(USER_TASK_BASE_PATH)
.queryParam("transitionId", "complete")
.queryParam("user", "Paco")
.queryParam("group", "customer")
.body(Collections.emptyMap())
.when()
.body(params)
.post("/{id}/ReceiveCustomerComment/{taskId}", id, taskId)
.post("/{userTaskId}/transition", userTaskId)
.then()
.statusCode(200);

given()
.basePath(BASE_PATH)
.contentType(ContentType.JSON)
.when()
.get(id)
.then()
.statusCode(200)
.body("supportCase.state", is(State.WAITING_FOR_OWNER.name()))
.body("supportCase.comments[1].text", is(params.get("comment")))
.body("supportCase.comments[1].author", is("Paco"))
.body("supportCase.comments[1].date", notNullValue());

}

private void resolveCase(String id) {
Expand All @@ -170,9 +261,10 @@ private void resolveCase(String id) {
}

private void sendQuestionnaire(String id) {
String taskId = given()
given()
.basePath(BASE_PATH)
.contentType(ContentType.JSON)
.queryParam("user", "Paco")
.queryParam("group", "customer")
.when()
.get("/{id}/tasks", id)
Expand All @@ -182,32 +274,67 @@ private void sendQuestionnaire(String id) {
.body("[0].name", is("Questionnaire"))
.extract()
.path("[0].id");

String userTaskId = given()
.basePath(USER_TASK_BASE_PATH)
.queryParam("user", "Paco")
.queryParam("group", "customer")
.contentType(ContentType.JSON)
.when()
.get()
.then()
.statusCode(200)
.extract()
.body()
.path("[0].id");

given()
.contentType(ContentType.JSON)
.basePath(USER_TASK_BASE_PATH)
.queryParam("transitionId", "claim")
.queryParam("user", "Paco")
.queryParam("group", "customer")
.body(Collections.emptyMap())
.when()
.post("/{userTaskId}/transition", userTaskId)
.then()
.statusCode(200);

Map<String, Object> params = new HashMap<>();
params.put("comment", "Kogito is great!");
params.put("evaluation", 10);

given()
.basePath(BASE_PATH)
.contentType(ContentType.JSON)
.basePath(USER_TASK_BASE_PATH)
.queryParam("user", "Paco")
.queryParam("group", "customer")
.body(params)
.when()
.put("/{userTaskId}/outputs", userTaskId)
.then()
.statusCode(200);

given()
.contentType(ContentType.JSON)
.basePath(USER_TASK_BASE_PATH)
.queryParam("transitionId", "complete")
.queryParam("user", "Paco")
.queryParam("group", "customer")
.body(Collections.emptyMap())
.when()
.body(params)
.post("/{id}/Questionnaire/{taskId}/", id, taskId)
.post("/{userTaskId}/transition", userTaskId)
.then()
.statusCode(200)
.body("supportCase.state", is(State.CLOSED.name()))
.body("supportCase.questionnaire.comment", is(params.get("comment")))
.body("supportCase.questionnaire.evaluation", is(params.get("evaluation")))
.body("supportCase.questionnaire.date", notNullValue());
.statusCode(200);

}

private void checkAllProcessesFinished() {
List<?> processes = given()
.basePath(BASE_PATH)
.contentType(ContentType.JSON)
.when()
.get("/")
.get("")
.as(List.class);

assertTrue(processes.isEmpty());
Expand Down
Loading

0 comments on commit 74d41ce

Please sign in to comment.