diff --git a/api/kogito-api/src/main/java/org/kie/kogito/usertask/model/TransitionInfo.java b/api/kogito-api/src/main/java/org/kie/kogito/usertask/model/TransitionInfo.java new file mode 100644 index 00000000000..c76ce87ce96 --- /dev/null +++ b/api/kogito-api/src/main/java/org/kie/kogito/usertask/model/TransitionInfo.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.kie.kogito.usertask.model; + +import java.util.Collections; +import java.util.Map; + +public class TransitionInfo { + + private String transitionId; + + private Map data; + + public TransitionInfo() { + // do nothing + } + + public TransitionInfo(String transitionId) { + this(transitionId, Collections.emptyMap()); + } + + public TransitionInfo(String transitionId, Map data) { + this.transitionId = transitionId; + this.data = data; + } + + public Map getData() { + return data; + } + + public void setData(Map data) { + this.data = data; + } + + public String getTransitionId() { + return transitionId; + } + + public void setTransitionId(String transitionId) { + this.transitionId = transitionId; + } +} diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/StandaloneBPMNProcessTest.java b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/StandaloneBPMNProcessTest.java index 78088212334..010789d20c6 100755 --- a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/StandaloneBPMNProcessTest.java +++ b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/StandaloneBPMNProcessTest.java @@ -117,7 +117,6 @@ import org.jbpm.test.utils.ProcessTestHelper; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.Timeout; import org.kie.api.event.process.ProcessStartedEvent; import org.kie.api.io.Resource; import org.kie.internal.io.ResourceFactory; @@ -384,7 +383,6 @@ public void testEventBasedSplitAfter() { } @Test - @Timeout(10) public void testEventBasedSplit2() throws Exception { ProcessCompletedCountDownProcessEventListener countDownListener = new ProcessCompletedCountDownProcessEventListener(2); Application app = ProcessTestHelper.newApplication(); @@ -537,7 +535,6 @@ public void testErrorBoundaryEvent() throws Exception { } @Test - @Timeout(10) public void testTimerBoundaryEvent() throws Exception { Application app = ProcessTestHelper.newApplication(); NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("TimerEvent", 1); @@ -556,7 +553,6 @@ public void testTimerBoundaryEvent() throws Exception { } @Test - @Timeout(10) public void testTimerBoundaryEventInterrupting() { Application app = ProcessTestHelper.newApplication(); NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("TimerEvent", 1); @@ -697,7 +693,6 @@ public void testIntermediateCatchEventMessage() { } @Test - @Timeout(10) public void testIntermediateCatchEventTimer() { Application app = ProcessTestHelper.newApplication(); NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 1); @@ -786,7 +781,6 @@ public void testConditionalStart() throws Exception { } @Test - @Timeout(1000) public void testTimerStart() throws Exception { Application app = ProcessTestHelper.newApplication(); NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("StartProcess", 5); diff --git a/kogito-codegen-modules/kogito-codegen-processes/src/main/resources/class-templates/usertask/RestResourceUserTaskQuarkusTemplate.java b/kogito-codegen-modules/kogito-codegen-processes/src/main/resources/class-templates/usertask/RestResourceUserTaskQuarkusTemplate.java index 0c78cff0f3b..8a7039263d0 100644 --- a/kogito-codegen-modules/kogito-codegen-processes/src/main/resources/class-templates/usertask/RestResourceUserTaskQuarkusTemplate.java +++ b/kogito-codegen-modules/kogito-codegen-processes/src/main/resources/class-templates/usertask/RestResourceUserTaskQuarkusTemplate.java @@ -79,10 +79,10 @@ public UserTaskView find(@PathParam("taskId") String taskId, @QueryParam("user") @Produces(MediaType.APPLICATION_JSON) public UserTaskView transition( @PathParam("taskId") String taskId, - @QueryParam("transitionId") String transitionId, @QueryParam("user") String user, - @QueryParam("group") List groups, Map data) { - return userTaskService.transition(taskId, transitionId, data, IdentityProviders.of(user, groups)).orElseThrow(UserTaskInstanceNotFoundException::new); + @QueryParam("group") List groups, + TransitionInfo transitionInfo) { + return userTaskService.transition(taskId, transitionInfo.getTransitionId(), transitionInfo.getData(), IdentityProviders.of(user, groups)).orElseThrow(UserTaskInstanceNotFoundException::new); } @GET diff --git a/kogito-codegen-modules/kogito-codegen-processes/src/main/resources/class-templates/usertask/RestResourceUserTaskSpringTemplate.java b/kogito-codegen-modules/kogito-codegen-processes/src/main/resources/class-templates/usertask/RestResourceUserTaskSpringTemplate.java index 87c757d3d79..6ca7d8e002c 100644 --- a/kogito-codegen-modules/kogito-codegen-processes/src/main/resources/class-templates/usertask/RestResourceUserTaskSpringTemplate.java +++ b/kogito-codegen-modules/kogito-codegen-processes/src/main/resources/class-templates/usertask/RestResourceUserTaskSpringTemplate.java @@ -71,11 +71,10 @@ public UserTaskView find(@PathVariable("taskId") String taskId, @RequestParam("u @PostMapping(value = "/{taskId}/transition") public UserTaskView transition( @PathVariable("taskId") String taskId, - @RequestParam("transitionId") String transitionId, @RequestParam("user") String user, @RequestParam("group") List groups, - @RequestBody Map data) { - return userTaskService.transition(taskId, transitionId, data, IdentityProviders.of(user, groups)).orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND)); + @RequestBody TransitionInfo transitionInfo) { + return userTaskService.transition(taskId, transitionInfo.getTransitionId(), transitionInfo.getData(), IdentityProviders.of(user, groups)).orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND)); } @GetMapping(value = "/{taskId}/transition", produces = MediaType.APPLICATION_JSON_VALUE) diff --git a/quarkus/integration-tests/integration-tests-quarkus-processes-persistence/integration-tests-quarkus-processes-infinispan/src/main/resources/AddedTask.bpmn2 b/quarkus/integration-tests/integration-tests-quarkus-processes-persistence/integration-tests-processes-persistence-common/src/main/resources/AddedTask.bpmn similarity index 99% rename from quarkus/integration-tests/integration-tests-quarkus-processes-persistence/integration-tests-quarkus-processes-infinispan/src/main/resources/AddedTask.bpmn2 rename to quarkus/integration-tests/integration-tests-quarkus-processes-persistence/integration-tests-processes-persistence-common/src/main/resources/AddedTask.bpmn index 6d8f8618cd1..6668aa4f716 100644 --- a/quarkus/integration-tests/integration-tests-quarkus-processes-persistence/integration-tests-quarkus-processes-infinispan/src/main/resources/AddedTask.bpmn2 +++ b/quarkus/integration-tests/integration-tests-quarkus-processes-persistence/integration-tests-processes-persistence-common/src/main/resources/AddedTask.bpmn @@ -16,7 +16,7 @@ - + diff --git a/quarkus/integration-tests/integration-tests-quarkus-processes-persistence/integration-tests-processes-persistence-common/src/test/java/org/kie/kogito/it/PersistenceTest.java b/quarkus/integration-tests/integration-tests-quarkus-processes-persistence/integration-tests-processes-persistence-common/src/test/java/org/kie/kogito/it/PersistenceTest.java index c0d75bce397..d9c94d5c5e7 100644 --- a/quarkus/integration-tests/integration-tests-quarkus-processes-persistence/integration-tests-processes-persistence-common/src/test/java/org/kie/kogito/it/PersistenceTest.java +++ b/quarkus/integration-tests/integration-tests-quarkus-processes-persistence/integration-tests-processes-persistence-common/src/test/java/org/kie/kogito/it/PersistenceTest.java @@ -32,6 +32,7 @@ import org.kie.kogito.AddressType; import org.kie.kogito.Person; import org.kie.kogito.Status; +import org.kie.kogito.usertask.model.TransitionInfo; import io.restassured.RestAssured; import io.restassured.http.ContentType; @@ -42,11 +43,13 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.Matchers.emptyOrNullString; public abstract class PersistenceTest { + private static final String USER_TASK_BASE_PATH = "/usertasks/instance"; public static final Duration TIMEOUT = Duration.ofSeconds(10); public static final String PROCESS_ID = "hello"; @@ -59,6 +62,71 @@ public abstract class PersistenceTest { RestAssured.enableLoggingOfRequestAndResponseIfValidationFails(); } + @Test + public void testStartApprovalAuthorized() { + // start new approval + String id = given() + .body("{}") + .contentType(ContentType.JSON) + .when() + .post("/AddedTask") + .then() + .statusCode(201) + .body("id", notNullValue()).extract().path("id"); + // get all active approvals + given() + .accept(ContentType.JSON) + .when() + .get("/AddedTask") + .then() + .statusCode(200) + .body("size()", is(1), "[0].id", is(id)); + + // get just started approval + given() + .accept(ContentType.JSON) + .when() + .get("/AddedTask/" + id) + .then() + .statusCode(200) + .body("id", is(id)); + + // tasks assigned in just started approval + + String userTaskId = given() + .basePath(USER_TASK_BASE_PATH) + .queryParam("user", "mary") + .queryParam("group", "managers") + .contentType(ContentType.JSON) + .when() + .get() + .then() + .statusCode(200) + .extract() + .body() + .path("[0].id"); + + given() + .contentType(ContentType.JSON) + .basePath(USER_TASK_BASE_PATH) + .queryParam("user", "mary") + .queryParam("group", "managers") + .body(new TransitionInfo("complete")) + .when() + .post("/{userTaskId}/transition", userTaskId) + .then() + .statusCode(200); + + // get all active approvals + given() + .accept(ContentType.JSON) + .when() + .get("/AddedTask") + .then() + .statusCode(200) + .body("size()", is(1)); + } + @Test void testPersistence() { Person person = new Person("Name", 10, BigDecimal.valueOf(5.0), Instant.now().truncatedTo(ChronoUnit.MILLIS), ZonedDateTime.now(ZoneOffset.UTC)); diff --git a/quarkus/integration-tests/integration-tests-quarkus-processes-persistence/integration-tests-quarkus-processes-infinispan/src/test/java/org/kie/kogito/it/InfinispanPersistenceIT.java b/quarkus/integration-tests/integration-tests-quarkus-processes-persistence/integration-tests-quarkus-processes-infinispan/src/test/java/org/kie/kogito/it/InfinispanPersistenceIT.java index cc668b06431..fd779ca5759 100644 --- a/quarkus/integration-tests/integration-tests-quarkus-processes-persistence/integration-tests-quarkus-processes-infinispan/src/test/java/org/kie/kogito/it/InfinispanPersistenceIT.java +++ b/quarkus/integration-tests/integration-tests-quarkus-processes-persistence/integration-tests-quarkus-processes-infinispan/src/test/java/org/kie/kogito/it/InfinispanPersistenceIT.java @@ -18,84 +18,9 @@ */ package org.kie.kogito.it; -import java.util.Collections; - -import org.junit.jupiter.api.Test; - import io.quarkus.test.junit.QuarkusIntegrationTest; -import io.restassured.http.ContentType; - -import static io.restassured.RestAssured.given; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; @QuarkusIntegrationTest class InfinispanPersistenceIT extends PersistenceTest { - private static final String USER_TASK_BASE_PATH = "/usertasks/instance"; - - @Test - public void testStartApprovalAuthorized() { - // start new approval - String id = given() - .body("{}") - .contentType(ContentType.JSON) - .when() - .post("/AddedTask") - .then() - .statusCode(201) - .body("id", notNullValue()).extract().path("id"); - // get all active approvals - given() - .accept(ContentType.JSON) - .when() - .get("/AddedTask") - .then() - .statusCode(200) - .body("size()", is(1), "[0].id", is(id)); - - // get just started approval - given() - .accept(ContentType.JSON) - .when() - .get("/AddedTask/" + id) - .then() - .statusCode(200) - .body("id", is(id)); - - // tasks assigned in just started approval - - String userTaskId = given() - .basePath(USER_TASK_BASE_PATH) - .queryParam("user", "mary") - .queryParam("group", "managers") - .contentType(ContentType.JSON) - .when() - .get() - .then() - .statusCode(200) - .extract() - .body() - .path("[0].id"); - - given() - .contentType(ContentType.JSON) - .basePath(USER_TASK_BASE_PATH) - .queryParam("transitionId", "complete") - .queryParam("user", "mary") - .queryParam("group", "managers") - .body(Collections.emptyMap()) - .when() - .post("/{userTaskId}/transition", userTaskId) - .then() - .statusCode(200); - // get all active approvals - given() - .accept(ContentType.JSON) - .when() - .get("/AddedTask") - .then() - .statusCode(200) - .body("size()", is(1)); - } }