Skip to content

Commit

Permalink
fix tests based on the new work item handler
Browse files Browse the repository at this point in the history
  • Loading branch information
elguardian committed Sep 11, 2024
1 parent 0960f52 commit a3914e4
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import java.util.Optional;

import org.kie.kogito.Application;
import org.kie.kogito.auth.SecurityPolicy;
import org.kie.kogito.internal.process.workitem.KogitoWorkItem;
import org.kie.kogito.internal.process.workitem.KogitoWorkItemHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@

import io.quarkus.test.junit.QuarkusTest;

import static java.util.Collections.singletonList;

import jakarta.inject.Inject;
import jakarta.inject.Named;

import static java.util.Collections.singletonList;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public void testApprovalProcess() {
results.put("approved", true);
processInstance.completeWorkItem(workItems.get(0).getId(), results, policy);

policy = SecurityPolicy.of(IdentityProviders.of("admin", Arrays.asList("mgmt")));
workItems = processInstance.workItems(policy);
assertEquals(0, workItems.size());

Expand Down Expand Up @@ -119,8 +120,10 @@ public void testApprovalProcessViaPhases() {

KogitoWorkItemHandler handler = approvalsProcess.getKogitoWorkItemHandler(workItems.get(0).getWorkItemHandlerName());
processInstance.transitionWorkItem(workItems.get(0).getId(), handler.newTransition("claim", workItems.get(0).getPhaseStatus(), emptyMap(), policy));
workItems = processInstance.workItems(policy);
processInstance.transitionWorkItem(workItems.get(0).getId(), handler.newTransition("complete", workItems.get(0).getPhaseStatus(), singletonMap("approved", true), policy));

policy = SecurityPolicy.of(IdentityProviders.of("admin", Arrays.asList("mgmt")));
workItems = processInstance.workItems(policy);
assertEquals(0, workItems.size());

Expand All @@ -132,6 +135,7 @@ public void testApprovalProcessViaPhases() {
assertEquals(1, workItems.size());

processInstance.transitionWorkItem(workItems.get(0).getId(), handler.newTransition("claim", workItems.get(0).getPhaseStatus(), emptyMap(), policy));
workItems = processInstance.workItems(policy);
processInstance.transitionWorkItem(workItems.get(0).getId(), handler.newTransition("complete", workItems.get(0).getPhaseStatus(), singletonMap("approved", false), policy));

assertEquals(org.kie.api.runtime.process.ProcessInstance.STATE_COMPLETED, processInstance.status());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public void testApprovalProcess() {
results.put("approved", true);
processInstance.completeWorkItem(workItems.get(0).getId(), results, policy);

policy = SecurityPolicy.of(IdentityProviders.of("admin", Collections.singletonList("mgmt")));
workItems = processInstance.workItems(policy);
assertEquals(0, workItems.size());

Expand Down Expand Up @@ -119,8 +120,10 @@ public void testApprovalProcessViaPhases() {

KogitoWorkItemHandler handler = approvalsProcess.getKogitoWorkItemHandler(workItems.get(0).getWorkItemHandlerName());
processInstance.transitionWorkItem(workItems.get(0).getId(), handler.newTransition("claim", workItems.get(0).getPhaseStatus(), emptyMap(), policy));
workItems = processInstance.workItems(policy);
processInstance.transitionWorkItem(workItems.get(0).getId(), handler.newTransition("complete", workItems.get(0).getPhaseStatus(), singletonMap("approved", true), policy));

policy = SecurityPolicy.of(IdentityProviders.of("admin", Collections.singletonList("mgmt")));
workItems = processInstance.workItems(policy);
assertEquals(0, workItems.size());

Expand All @@ -132,6 +135,7 @@ public void testApprovalProcessViaPhases() {
assertEquals(1, workItems.size());

processInstance.transitionWorkItem(workItems.get(0).getId(), handler.newTransition("claim", workItems.get(0).getPhaseStatus(), emptyMap(), policy));
workItems = processInstance.workItems(policy);
processInstance.transitionWorkItem(workItems.get(0).getId(), handler.newTransition("complete", workItems.get(0).getPhaseStatus(), singletonMap("approved", false), policy));

assertEquals(org.kie.api.runtime.process.ProcessInstance.STATE_COMPLETED, processInstance.status());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,18 @@ public void testApprovalProcess() {

SecurityPolicy policy = SecurityPolicy.of(IdentityProviders.of("admin", Collections.singletonList("managers")));

processInstance.workItems(policy);

List<WorkItem> workItems = processInstance.workItems(policy);
assertEquals(1, workItems.size());
Map<String, Object> results = new HashMap<>();
results.put("approved", true);
processInstance.completeWorkItem(workItems.get(0).getId(), results, policy);

policy = SecurityPolicy.of(IdentityProviders.of("admin", Collections.singletonList("mgmt")));
workItems = processInstance.workItems(policy);
assertEquals(0, workItems.size());

policy = SecurityPolicy.of(IdentityProviders.of("john", Collections.singletonList("managers")));

processInstance.workItems(policy);

workItems = processInstance.workItems(policy);
assertEquals(1, workItems.size());

Expand Down Expand Up @@ -122,8 +119,10 @@ public void testApprovalProcessViaPhases() {

KogitoWorkItemHandler handler = approvalsProcess.getKogitoWorkItemHandler(workItems.get(0).getWorkItemHandlerName());
processInstance.transitionWorkItem(workItems.get(0).getId(), handler.newTransition("claim", workItems.get(0).getPhaseStatus(), Collections.emptyMap(), policy));
workItems = processInstance.workItems(policy);
processInstance.transitionWorkItem(workItems.get(0).getId(), handler.newTransition("complete", workItems.get(0).getPhaseStatus(), Collections.singletonMap("approved", true), policy));

policy = SecurityPolicy.of(IdentityProviders.of("admin", Collections.singletonList("mgmt")));
workItems = processInstance.workItems(policy);
assertEquals(0, workItems.size());

Expand All @@ -135,6 +134,7 @@ public void testApprovalProcessViaPhases() {
assertEquals(1, workItems.size());

processInstance.transitionWorkItem(workItems.get(0).getId(), handler.newTransition("claim", workItems.get(0).getPhaseStatus(), Collections.emptyMap(), policy));
workItems = processInstance.workItems(policy);
processInstance.transitionWorkItem(workItems.get(0).getId(), handler.newTransition("complete", workItems.get(0).getPhaseStatus(), Collections.singletonMap("approved", false), policy));

assertEquals(org.kie.api.runtime.process.ProcessInstance.STATE_COMPLETED, processInstance.status());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public void testApprovalProcess() {
results.put("approved", true);
processInstance.completeWorkItem(workItems.get(0).getId(), results, policy);

policy = SecurityPolicy.of(IdentityProviders.of("admin", Collections.singletonList("mgmt")));
workItems = processInstance.workItems(policy);
assertEquals(0, workItems.size());

Expand Down Expand Up @@ -124,8 +125,10 @@ public void testApprovalProcessViaPhases() {

KogitoWorkItemHandler handler = approvalsProcess.getKogitoWorkItemHandler(workItems.get(0).getWorkItemHandlerName());
processInstance.transitionWorkItem(workItems.get(0).getId(), handler.newTransition("claim", workItems.get(0).getPhaseStatus(), emptyMap(), policy));
workItems = processInstance.workItems(policy);
processInstance.transitionWorkItem(workItems.get(0).getId(), handler.newTransition("complete", workItems.get(0).getPhaseStatus(), singletonMap("approved", true), policy));

policy = SecurityPolicy.of(IdentityProviders.of("admin", Collections.singletonList("mgmt")));
workItems = processInstance.workItems(policy);
assertEquals(0, workItems.size());

Expand All @@ -137,6 +140,7 @@ public void testApprovalProcessViaPhases() {
assertEquals(1, workItems.size());

processInstance.transitionWorkItem(workItems.get(0).getId(), handler.newTransition("claim", workItems.get(0).getPhaseStatus(), emptyMap(), policy));
workItems = processInstance.workItems(policy);
processInstance.transitionWorkItem(workItems.get(0).getId(), handler.newTransition("complete", workItems.get(0).getPhaseStatus(), singletonMap("approved", false), policy));

assertEquals(org.kie.api.runtime.process.ProcessInstance.STATE_COMPLETED, processInstance.status());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public void testApprovalProcess() {
results.put("approved", true);
processInstance.completeWorkItem(workItems.get(0).getId(), results, policy);

policy = SecurityPolicy.of(IdentityProviders.of("admin", Collections.singletonList("mgmt")));
workItems = processInstance.workItems(policy);
assertEquals(0, workItems.size());

Expand Down Expand Up @@ -124,8 +125,10 @@ public void testApprovalProcessViaPhases() {

KogitoWorkItemHandler handler = approvalsProcess.getKogitoWorkItemHandler(workItems.get(0).getWorkItemHandlerName());
processInstance.transitionWorkItem(workItems.get(0).getId(), handler.newTransition("claim", workItems.get(0).getPhaseStatus(), emptyMap(), policy));
workItems = processInstance.workItems(policy);
processInstance.transitionWorkItem(workItems.get(0).getId(), handler.newTransition("complete", workItems.get(0).getPhaseStatus(), singletonMap("approved", true), policy));

policy = SecurityPolicy.of(IdentityProviders.of("admin", Collections.singletonList("mgmt")));
workItems = processInstance.workItems(policy);
assertEquals(0, workItems.size());

Expand All @@ -137,6 +140,7 @@ public void testApprovalProcessViaPhases() {
assertEquals(1, workItems.size());

processInstance.transitionWorkItem(workItems.get(0).getId(), handler.newTransition("claim", workItems.get(0).getPhaseStatus(), emptyMap(), policy));
workItems = processInstance.workItems(policy);
processInstance.transitionWorkItem(workItems.get(0).getId(), handler.newTransition("complete", workItems.get(0).getPhaseStatus(), singletonMap("approved", false), policy));

assertEquals(org.kie.api.runtime.process.ProcessInstance.STATE_COMPLETED, processInstance.status());
Expand Down

0 comments on commit a3914e4

Please sign in to comment.