Skip to content

Commit

Permalink
tests: new CheckedRunnable applied where possible, code cleanup
Browse files Browse the repository at this point in the history
FailableProducer usage was replaced by Callable
  • Loading branch information
virgo47 committed Jun 9, 2022
1 parent 50d3f22 commit 949a9d4
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 63 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
* Copyright (c) 2010-2019 Evolveum and contributors
* Copyright (C) 2010-2022 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/

package com.evolveum.midpoint.wf.impl;

import com.evolveum.midpoint.util.CheckedRunnable;
import com.evolveum.midpoint.xml.ns._public.common.common_3.CaseWorkItemType;

public class ApprovalInstruction {
Expand Down Expand Up @@ -44,9 +44,4 @@ public String toString() {
", comment='" + comment + '\'' +
'}';
}

@FunctionalInterface
public interface CheckedRunnable {
void run() throws Exception;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010-2021 Evolveum and contributors
* Copyright (C) 2010-2022 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
Expand All @@ -19,8 +19,7 @@

import java.io.File;
import java.util.*;

import com.evolveum.midpoint.prism.xml.XmlTypeConverter;
import javax.xml.datatype.XMLGregorianCalendar;

import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
Expand All @@ -35,12 +34,14 @@
import com.evolveum.midpoint.prism.delta.ObjectDeltaCollectionsUtil;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.util.PrismAsserts;
import com.evolveum.midpoint.prism.xml.XmlTypeConverter;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.cases.CaseTypeUtil;
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.schema.util.cases.CaseTypeUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.test.TestResource;
import com.evolveum.midpoint.util.CheckedRunnable;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.exception.PolicyViolationException;
import com.evolveum.midpoint.wf.impl.AbstractWfTestPolicy;
Expand All @@ -49,8 +50,6 @@
import com.evolveum.midpoint.wf.impl.ExpectedWorkItem;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import javax.xml.datatype.XMLGregorianCalendar;

/**
* A special test dealing with assigning roles that have different metarole-induced approval policies.
* <p>
Expand Down Expand Up @@ -1051,9 +1050,9 @@ public void test830EnableAssignment() throws Exception {

assertUser(USER_HOLDER_OF_ROLE_BEING_ENABLED.oid, "after")
.assignments()
.single()
.activation()
.assertValidTo((XMLGregorianCalendar) null);
.single()
.activation()
.assertValidTo((XMLGregorianCalendar) null);
}

/**
Expand Down Expand Up @@ -1090,10 +1089,10 @@ public void test840DisableAssignment() throws Exception {

assertUser(USER_HOLDER_OF_ROLE_BEING_DISABLED.oid, "after")
.assignments()
.single()
.activation()
.assertValidTo(newValidTo)
.assertEffectiveStatus(ActivationStatusType.DISABLED);
.single()
.activation()
.assertValidTo(newValidTo)
.assertEffectiveStatus(ActivationStatusType.DISABLED);
}

/**
Expand Down Expand Up @@ -1133,10 +1132,10 @@ public void test850DisableAssignmentWithApproval() throws Exception {

assertUser(USER_HOLDER_OF_ROLE_BEING_DISABLED_WITH_APPROVAL.oid, "after")
.assignments()
.single()
.activation()
.assertValidTo((XMLGregorianCalendar) null)
.assertEffectiveStatus(ActivationStatusType.ENABLED);
.single()
.activation()
.assertValidTo((XMLGregorianCalendar) null)
.assertEffectiveStatus(ActivationStatusType.ENABLED);

when("approving the operation");
approveWorkItem(approvalCase.getWorkItem().get(0), task, result);
Expand All @@ -1146,10 +1145,10 @@ public void test850DisableAssignmentWithApproval() throws Exception {

assertUser(USER_HOLDER_OF_ROLE_BEING_DISABLED_WITH_APPROVAL.oid, "after")
.assignments()
.single()
.activation()
.assertValidTo(newValidTo)
.assertEffectiveStatus(ActivationStatusType.DISABLED);
.single()
.activation()
.assertValidTo(newValidTo)
.assertEffectiveStatus(ActivationStatusType.DISABLED);
}

/**
Expand All @@ -1168,8 +1167,8 @@ public void test900AssignIdempotentRole() throws Exception {
ObjectDelta<UserType> delta = prismContext.deltaFor(UserType.class)
.item(UserType.F_ASSIGNMENT)
.add(
new AssignmentType(prismContext).targetRef(ROLE_IDEMPOTENT.oid, RoleType.COMPLEX_TYPE),
new AssignmentType(prismContext)
new AssignmentType().targetRef(ROLE_IDEMPOTENT.oid, RoleType.COMPLEX_TYPE),
new AssignmentType()
.targetRef(ROLE_IDEMPOTENT.oid, RoleType.COMPLEX_TYPE)
.beginActivation().validFrom("1990-01-01T00:00:00").end())
.asObjectDeltaCast(userJackOid);
Expand Down Expand Up @@ -1208,8 +1207,8 @@ public void test910AssignRoleWithIdempotentMetarole() throws Exception {
ObjectDelta<UserType> delta = prismContext.deltaFor(UserType.class)
.item(UserType.F_ASSIGNMENT)
.add(
new AssignmentType(prismContext).targetRef(ROLE_WITH_IDEMPOTENT_METAROLE.oid, RoleType.COMPLEX_TYPE),
new AssignmentType(prismContext)
new AssignmentType().targetRef(ROLE_WITH_IDEMPOTENT_METAROLE.oid, RoleType.COMPLEX_TYPE),
new AssignmentType()
.targetRef(ROLE_WITH_IDEMPOTENT_METAROLE.oid, RoleType.COMPLEX_TYPE)
.beginActivation().validFrom("1990-01-01T00:00:00").end())
.asObjectDeltaCast(userJackOid);
Expand Down Expand Up @@ -1250,7 +1249,7 @@ public void test920AssignRoleWithComputedSkip() throws Exception {

ObjectDelta<UserType> delta = prismContext.deltaFor(UserType.class)
.item(UserType.F_ASSIGNMENT)
.add(new AssignmentType(prismContext).targetRef(ROLE_SKIPPED_FILE.oid, RoleType.COMPLEX_TYPE))
.add(new AssignmentType().targetRef(ROLE_SKIPPED_FILE.oid, RoleType.COMPLEX_TYPE))
.asObjectDeltaCast(userJackOid);

executeChanges(delta, null, task, result);
Expand All @@ -1274,7 +1273,7 @@ public void test930UnassignRoleWithApproval() throws Exception {
executeChanges(
prismContext.deltaFor(UserType.class)
.item(UserType.F_ASSIGNMENT)
.add(new AssignmentType(prismContext).targetRef(ROLE_APPROVE_UNASSIGN.oid, RoleType.COMPLEX_TYPE))
.add(new AssignmentType().targetRef(ROLE_APPROVE_UNASSIGN.oid, RoleType.COMPLEX_TYPE))
.<UserType>asObjectDeltaCast(userJackOid), null, task, result);
assertUser(userJackOid, "before")
.assertAssignments(1);
Expand All @@ -1283,7 +1282,7 @@ public void test930UnassignRoleWithApproval() throws Exception {
executeChanges(
prismContext.deltaFor(UserType.class)
.item(UserType.F_ASSIGNMENT)
.delete(new AssignmentType(prismContext).targetRef(ROLE_APPROVE_UNASSIGN.oid, RoleType.COMPLEX_TYPE))
.delete(new AssignmentType().targetRef(ROLE_APPROVE_UNASSIGN.oid, RoleType.COMPLEX_TYPE))
.<UserType>asObjectDeltaCast(userJackOid), null, task, result);

then();
Expand Down Expand Up @@ -1419,7 +1418,7 @@ public List<ApprovalInstruction> getApprovalSequence() {
new ExpectedWorkItem(userLead23Oid, roleRole23Oid, tasks.get(2)), approve3a, userLead23Oid, null));
if (approve3a) {
ExpectedWorkItem expectedWorkItem = new ExpectedWorkItem(userSecurityApproverOid, roleRole23Oid, tasks.get(2));
ApprovalInstruction.CheckedRunnable before = () -> {
CheckedRunnable before = () -> {
login(getUserFromRepo(userSecurityApproverOid));
checkVisibleWorkItem(expectedWorkItem, 1, task, task.getResult());
login(getUserFromRepo(userSecurityApproverDeputyOid));
Expand Down Expand Up @@ -1475,7 +1474,7 @@ private void previewAssignRolesToJack(boolean immediate, boolean also24) throws
tracer.storeTrace(task, result, null);
}

// we do not assert success here, because there are (intentional) exceptions in some of the expressions
// we do not assert success here, because there are (intentional) exceptions in some expressions

assertEquals("Wrong # of schema execution information pieces", also24 ? 5 : 4, approvalInfo.size());
assertNotNull("No enforcement preview output", enforceInfo);
Expand Down Expand Up @@ -1705,7 +1704,7 @@ private AssignmentType toDelete(AssignmentType assignment, boolean byId) {
if (!byId) {
return assignment.clone();
} else {
AssignmentType rv = new AssignmentType(prismContext);
AssignmentType rv = new AssignmentType();
rv.setId(assignment.getId());
return rv;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
/*
* Copyright (c) 2010-2019 Evolveum and contributors
* Copyright (C) 2010-2022 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.provisioning.impl.dummy;

import static com.evolveum.midpoint.schema.constants.SchemaConstants.RI_GROUP_OBJECT_CLASS;
import static org.testng.AssertJUnit.assertEquals;

import static com.evolveum.midpoint.schema.constants.SchemaConstants.RI_GROUP_OBJECT_CLASS;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.Callable;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.schema.constants.MidPointConstants;
import com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition;
import com.evolveum.midpoint.schema.processor.ResourceSchemaFactory;

import org.apache.commons.lang3.mutable.MutableBoolean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
Expand All @@ -36,7 +34,10 @@
import com.evolveum.midpoint.schema.ResultHandler;
import com.evolveum.midpoint.schema.SearchResultList;
import com.evolveum.midpoint.schema.cache.CacheConfigurationManager;
import com.evolveum.midpoint.schema.constants.MidPointConstants;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition;
import com.evolveum.midpoint.schema.processor.ResourceSchemaFactory;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.result.OperationResultStatus;
import com.evolveum.midpoint.schema.statistics.ConnectorOperationalStatus;
Expand All @@ -46,7 +47,6 @@
import com.evolveum.midpoint.test.asserter.ShadowAsserter;
import com.evolveum.midpoint.test.util.Counter;
import com.evolveum.midpoint.test.util.ParallelTestThread;
import com.evolveum.midpoint.util.FailableProducer;
import com.evolveum.midpoint.util.exception.*;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

Expand Down Expand Up @@ -289,7 +289,7 @@ public void test204ParallelModifyDisable() throws Exception {
}

private PrismObject<ShadowType> parallelModifyTest(
FailableProducer<ObjectDelta<ShadowType>> deltaProducer) throws Exception {
Callable<ObjectDelta<ShadowType>> deltaProducer) throws Exception {

// GIVEN
Task task = getTestTask();
Expand All @@ -314,7 +314,7 @@ private PrismObject<ShadowType> parallelModifyTest(
randomDelay(CONCURRENT_TEST_MAX_START_DELAY_SLOW);
logger.info("{} starting to do some work", Thread.currentThread().getName());

ObjectDelta<ShadowType> delta = deltaProducer.run();
ObjectDelta<ShadowType> delta = deltaProducer.call();
displayDumpable("ObjectDelta", delta);

provisioningService.modifyObject(ShadowType.class, accountMorganOid, delta.getModifications(), null, null, localTask, localResult);
Expand Down Expand Up @@ -491,7 +491,7 @@ public void test214ParallelModifyDisableSlow() throws Exception {
}

private PrismObject<ShadowType> parallelModifyTestSlow(
FailableProducer<ObjectDelta<ShadowType>> deltaProducer) throws Exception {
Callable<ObjectDelta<ShadowType>> deltaProducer) throws Exception {

given();
Task task = getTestTask();
Expand All @@ -515,7 +515,7 @@ private PrismObject<ShadowType> parallelModifyTestSlow(
randomDelay(CONCURRENT_TEST_MAX_START_DELAY_SLOW);
logger.info("{} starting to do some work", Thread.currentThread().getName());

ObjectDelta<ShadowType> delta = deltaProducer.run();
ObjectDelta<ShadowType> delta = deltaProducer.call();
displayDumpable("ObjectDelta", delta);

provisioningService.modifyObject(ShadowType.class, accountElizabethOid,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
/*
* Copyright (c) 2019 Evolveum and contributors
* Copyright (C) 2019-2022 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/

package com.evolveum.midpoint.test;

import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import com.evolveum.midpoint.util.CheckedRunnable;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;

/**
* EXPERIMENTAL
* EXPERIMENTAL
*/
public class ThreadTestExecutor {

private static final Trace LOGGER = TraceManager.getTrace(ThreadTestExecutor.class);

private static final long WAIT_STEP = 100;

private int threadsCount;
private long timeout;
private final int threadsCount;
private final long timeout;

private List<Thread> threads;
private List<Thread> failedThreads;
Expand All @@ -36,12 +36,7 @@ public ThreadTestExecutor(int threadsCount, long timeout) {
this.timeout = timeout;
}

@FunctionalInterface
public interface ThrowingRunnable {
void run() throws Exception;
}

public void execute(ThrowingRunnable runnable) throws InterruptedException {
public void execute(CheckedRunnable runnable) throws InterruptedException {
threads = new ArrayList<>();
failedThreads = new ArrayList<>();

Expand Down

0 comments on commit 949a9d4

Please sign in to comment.