From ff1a56c2747a1ca1c5c78c4ea605c59a8914f6b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Mu=C3=B1oz?= Date: Mon, 6 Sep 2021 11:58:15 +0200 Subject: [PATCH] [JBPM-9867] Add parameterized test with NONE audit mode (#2005) --- .../UserTaskServiceImplAuditNoneTest.java | 46 +++++++++++++++++++ .../test/UserTaskServiceImplTest.java | 31 +++++++++++-- 2 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 jbpm-services/jbpm-kie-services/src/test/java/org/jbpm/kie/services/test/UserTaskServiceImplAuditNoneTest.java diff --git a/jbpm-services/jbpm-kie-services/src/test/java/org/jbpm/kie/services/test/UserTaskServiceImplAuditNoneTest.java b/jbpm-services/jbpm-kie-services/src/test/java/org/jbpm/kie/services/test/UserTaskServiceImplAuditNoneTest.java new file mode 100644 index 0000000000..267378eb25 --- /dev/null +++ b/jbpm-services/jbpm-kie-services/src/test/java/org/jbpm/kie/services/test/UserTaskServiceImplAuditNoneTest.java @@ -0,0 +1,46 @@ +/* + * Copyright 2021 Red Hat, Inc. and/or its affiliates. + * + * Licensed 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.kie.services.test; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.drools.compiler.kie.builder.impl.InternalKieModule; +import org.kie.api.KieServices; +import org.kie.api.builder.ReleaseId; +import org.kie.internal.runtime.conf.DeploymentDescriptor; +import org.kie.internal.runtime.manager.deploy.DeploymentDescriptorImpl; +import static org.kie.internal.runtime.conf.AuditMode.NONE; + +public class UserTaskServiceImplAuditNoneTest extends UserTaskServiceImplTest { + + @Override + protected InternalKieModule createKJAR(KieServices ks, ReleaseId releaseId, List processes) { + DeploymentDescriptor customDescriptor = new DeploymentDescriptorImpl("org.jbpm.domain"); + customDescriptor.getBuilder().auditMode(NONE); + + Map resources = new HashMap(); + resources.put("src/main/resources/" + DeploymentDescriptor.META_INF_LOCATION, customDescriptor.toXml()); + + return createKieJar(ks, releaseId, processes, resources); + } + + @Override + protected boolean isJPAAuditMode() { + return false; + } +} diff --git a/jbpm-services/jbpm-kie-services/src/test/java/org/jbpm/kie/services/test/UserTaskServiceImplTest.java b/jbpm-services/jbpm-kie-services/src/test/java/org/jbpm/kie/services/test/UserTaskServiceImplTest.java index 41736fc94f..f57f0b20a7 100644 --- a/jbpm-services/jbpm-kie-services/src/test/java/org/jbpm/kie/services/test/UserTaskServiceImplTest.java +++ b/jbpm-services/jbpm-kie-services/src/test/java/org/jbpm/kie/services/test/UserTaskServiceImplTest.java @@ -71,6 +71,8 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.junit.Assume.assumeTrue; +import static org.kie.internal.runtime.conf.AuditMode.JPA; import static org.kie.scanner.KieMavenRepository.getKieMavenRepository; public class UserTaskServiceImplTest extends AbstractKieServicesBaseTest { @@ -94,7 +96,7 @@ public void prepare() { processes.add("repo/processes/general/NoFormNameHumanTask.bpmn"); processes.add("repo/processes/general/BPMN2-UserTaskImageVar.bpmn2"); - InternalKieModule kJar1 = createKieJar(ks, releaseId, processes); + InternalKieModule kJar1 = createKJAR(ks, releaseId, processes); File pom = new File("target/kmodule", "pom.xml"); pom.getParentFile().mkdir(); try { @@ -116,6 +118,10 @@ public void prepare() { assertNotNull(processService); } + + protected InternalKieModule createKJAR(KieServices ks, ReleaseId releaseId, List processes) { + return createKieJar(ks, releaseId, processes); + } @After public void cleanup() { @@ -328,7 +334,7 @@ public void testStartAndForward() { task = runtimeDataService.getTaskById(taskId); assertNotNull(task); assertEquals(Status.Ready.toString(), task.getStatus()); - assertEquals("", task.getActualOwner()); + assertTrue(task.getActualOwner() == null || task.getActualOwner().isEmpty()); } @Test @@ -683,6 +689,8 @@ public void testGetTask() { @Test public void testGetTaskOfAbortedProcess() { + skipIfAuditModeIsNotJPA(); + processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument.noform"); assertNotNull(processInstanceId); List taskIds = runtimeDataService.getTasksByProcessInstanceId(processInstanceId); @@ -706,7 +714,7 @@ public void testGetTaskOfAbortedProcess() { assertTrue(StringUtils.isEmpty(((InternalTask)taskInstance).getFormName())); } - + @Test public void testUpdateTask() { processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument"); @@ -748,6 +756,8 @@ public void testUpdateTask() { @Test public void testUpdateTaskWithData() { + skipIfAuditModeIsNotJPA(); + TaskAuditService taskAuditService = getTaskAuditService(); processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument"); @@ -866,6 +876,8 @@ public void testUpdateTaskPermissionDenied() { @Test public void testProcessWithLazyLoadedVariable() { + skipIfAuditModeIsNotJPA(); + identityProvider.setName("john"); Image newImage = new Image("test"); Map params = new HashMap<>(); @@ -918,6 +930,8 @@ public void testProcessWithLazyLoadedVariable() { @Test public void testTaskOperationWithUserOrWithIdentityProvider() { + skipIfAuditModeIsNotJPA(); + processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument"); assertNotNull(processInstanceId); @@ -1006,6 +1020,15 @@ public void testCompleteAutoProgressWrongDeploymentId() { UserTaskInstanceDesc task = runtimeDataService.getTaskById(taskId); assertNotNull(task); assertEquals(Status.Ready.toString(), task.getStatus()); - assertCorrelationAndProcess(task, processInstanceId); + if (isJPAAuditMode()) + assertCorrelationAndProcess(task, processInstanceId); + } + + protected void skipIfAuditModeIsNotJPA() { + assumeTrue("skip if audit mode is not JPA", isJPAAuditMode()); + } + + protected boolean isJPAAuditMode() { + return true; } }