GopikaReghunath commented on code in PR #4273: URL: https://github.com/apache/incubator-kie-kogito-runtimes/pull/4273#discussion_r3216659258
########## quarkus/integration-tests/integration-tests-quarkus-usertasks/src/test/java/org/jbpm/userTask/jpa/it/UserTaskFilterIT.java: ########## @@ -0,0 +1,395 @@ +/* + * 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.jbpm.userTask.jpa.it; + +import java.util.List; + +import org.acme.travels.Address; +import org.acme.travels.Traveller; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; +import org.kie.kogito.testcontainers.quarkus.PostgreSqlQuarkusTestResource; + +import io.quarkus.test.common.QuarkusTestResource; +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.Matchers.hasItem; + +/** + * Integration test for user task filtering functionality. + * Tests the filter query parameters on the /usertasks/instance endpoint. + */ +@QuarkusIntegrationTest +@QuarkusTestResource(value = PostgreSqlQuarkusTestResource.class, restrictToAnnotatedClass = true) +public class UserTaskFilterIT extends BaseUserTaskIT { + + @AfterEach + public void cleanUp() { + // Get all process instances and delete them to ensure test isolation + List<String> processInstanceIds = given() + .contentType(ContentType.JSON) + .when() + .get("/{processId}", PROCESS_ID) + .then() + .extract() + .jsonPath() + .getList("id", String.class); + + processInstanceIds.forEach(processInstanceId -> { + given() + .contentType(ContentType.JSON) + .when() + .delete("/{processId}/{processInstanceId}", PROCESS_ID, processInstanceId) + .then() + .statusCode(200); + }); + } + + @Test + public void testFilterByProcessId() { + // Given - Start two process instances + Traveller traveller1 = new Traveller("John", "Doe", "[email protected]", "American", + new Address("main street", "Boston", "10005", "US")); + Traveller traveller2 = new Traveller("Jane", "Smith", "[email protected]", "Canadian", + new Address("second street", "Toronto", "20005", "CA")); + + startProcessInstance(traveller1); + startProcessInstance(traveller2); + + // When - Query with processId filter + given().contentType(ContentType.JSON) + .queryParam("user", "manager") + .queryParam("group", "department-managers") + .queryParam("processId", PROCESS_ID) + .when() + .get(USER_TASKS_ENDPOINT) + .then() + .statusCode(200) + .body("$.size()", is(2)) + .body("[0].processInfo.processId", is(PROCESS_ID)) + .body("[1].processInfo.processId", is(PROCESS_ID)); + } + + @Test + public void testFilterByProcessInstanceId() { + // Given - Start a process instance + Traveller traveller = new Traveller("John", "Doe", "[email protected]", "American", + new Address("main street", "Boston", "10005", "US")); + String pid = startProcessInstance(traveller); + + // When - Query with processInstanceId filter + given().contentType(ContentType.JSON) + .queryParam("user", "manager") + .queryParam("group", "department-managers") + .queryParam("processInstanceId", pid) + .when() + .get(USER_TASKS_ENDPOINT) + .then() + .statusCode(200) + .body("$.size()", is(1)) + .body("[0].processInfo.processInstanceId", is(pid)); + } + + @Test + public void testFilterByStatus() { + // Given - Start a process instance (creates task in Reserved status) + Traveller traveller = new Traveller("John", "Doe", "[email protected]", "American", + new Address("main street", "Boston", "10005", "US")); + startProcessInstance(traveller); + + // When - Query with status filter + given().contentType(ContentType.JSON) + .queryParam("user", "manager") + .queryParam("group", "department-managers") + .queryParam("status", "Reserved") + .when() + .get(USER_TASKS_ENDPOINT) + .then() + .statusCode(200) + .body("$.size()", is(1)) + .body("[0].status.name", is("Reserved")); + } + + @Test + public void testFilterByTaskName() { + // Given - Start a process instance + Traveller traveller = new Traveller("John", "Doe", "[email protected]", "American", + new Address("main street", "Boston", "10005", "US")); + startProcessInstance(traveller); + + // When - Query with taskName filter (case-insensitive partial match) + given().contentType(ContentType.JSON) + .queryParam("user", "manager") + .queryParam("group", "department-managers") + .queryParam("taskName", "approval") + .when() + .get(USER_TASKS_ENDPOINT) + .then() + .statusCode(200) + .body("$.size()", is(1)) + .body("[0].taskName", is("firstLineApproval")); + } + + @Test + public void testCombinedFilters() { + // Given - Start a process instance + Traveller traveller = new Traveller("John", "Doe", "[email protected]", "American", + new Address("main street", "Boston", "10005", "US")); + String pid = startProcessInstance(traveller); + + // When - Query with multiple filters + given().contentType(ContentType.JSON) + .queryParam("user", "manager") + .queryParam("group", "department-managers") + .queryParam("processId", PROCESS_ID) + .queryParam("processInstanceId", pid) + .queryParam("status", "Reserved") + .queryParam("taskName", "firstLine") + .when() + .get(USER_TASKS_ENDPOINT) + .then() + .statusCode(200) + .body("$.size()", is(1)) + .body("[0].processInfo.processId", is(PROCESS_ID)) + .body("[0].processInfo.processInstanceId", is(pid)) + .body("[0].status.name", is("Reserved")) + .body("[0].taskName", is("firstLineApproval")); + } + + @Test + public void testFilterWithNoMatches() { + // Given - Start a process instance + Traveller traveller = new Traveller("John", "Doe", "[email protected]", "American", + new Address("main street", "Boston", "10005", "US")); + startProcessInstance(traveller); + + // When - Query with filter that doesn't match + given().contentType(ContentType.JSON) + .queryParam("user", "manager") + .queryParam("group", "department-managers") + .queryParam("processId", "nonexistent") + .when() + .get(USER_TASKS_ENDPOINT) + .then() + .statusCode(200) + .body("$.size()", is(0)); + } + + @Test + public void testFilterByTaskNameCaseInsensitive() { + // Given - Start a process instance + Traveller traveller = new Traveller("John", "Doe", "[email protected]", "American", + new Address("main street", "Boston", "10005", "US")); + startProcessInstance(traveller); + + // When - Query with uppercase taskName (should match case-insensitively) + given().contentType(ContentType.JSON) + .queryParam("user", "manager") + .queryParam("group", "department-managers") + .queryParam("taskName", "APPROVAL") Review Comment: Yes, The task name match is partial and case-insensitive. Task names with spaces are treated as below Stored: "HR Interview" + Search: "HR Interview" → ✅ Exact match Stored: "HR Interview" + Search: "Interview" → ✅ Partial match Stored: "HR Interview" + Search: "HR Int" → ✅ Partial match with space Stored: "HR Interview" + Search: "hr interview" → ✅ Case-insensitive exact match I have added more test cases on this -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
