Skip to content

Commit

Permalink
[incubator-kie-issues-1484] Create endpoints for user task
Browse files Browse the repository at this point in the history
  • Loading branch information
elguardian committed Oct 3, 2024
1 parent 2066640 commit 66edc38
Show file tree
Hide file tree
Showing 24 changed files with 1,227 additions and 583 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 66edc38

Please sign in to comment.