Skip to content

Commit

Permalink
Fix TestCorrelators
Browse files Browse the repository at this point in the history
There was a subtle bug introduced when introducing classpath-based
test resources in 41c7d3b.
  • Loading branch information
mederly committed Jan 13, 2023
1 parent 75c8eec commit 4df2305
Showing 1 changed file with 21 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import com.evolveum.midpoint.util.LocalizableMessage;
import com.evolveum.midpoint.util.MiscUtil;

import com.evolveum.midpoint.util.exception.*;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -39,7 +41,6 @@

import com.evolveum.concepts.func.FailableConsumer;
import com.evolveum.icf.dummy.resource.ConflictException;
import com.evolveum.icf.dummy.resource.ObjectAlreadyExistsException;
import com.evolveum.icf.dummy.resource.SchemaViolationException;
import com.evolveum.midpoint.model.api.correlation.CompleteCorrelationResult;
import com.evolveum.midpoint.model.api.correlation.CorrelationCaseDescription;
Expand All @@ -62,10 +63,6 @@
import com.evolveum.midpoint.test.DummyTestResource;
import com.evolveum.midpoint.test.TestResource;
import com.evolveum.midpoint.test.util.MidPointTestConstants;
import com.evolveum.midpoint.util.exception.CommonException;
import com.evolveum.midpoint.util.exception.ConfigurationException;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

/**
Expand Down Expand Up @@ -320,7 +317,7 @@ public void test250SmartWithMatchingRules() throws Exception {
@SuppressWarnings("SameParameterValue")
private void executeTest(String name, File usersFile)
throws ConflictException, EncryptionException, CommonException, IOException, SchemaViolationException,
InterruptedException, ObjectAlreadyExistsException {
InterruptedException, com.evolveum.icf.dummy.resource.ObjectAlreadyExistsException {
executeTest(
correlator(name),
usersFile,
Expand All @@ -332,7 +329,7 @@ private void executeTest(String name, File usersFile)
@SuppressWarnings("SameParameterValue")
private void executeTest(String name, File usersFile, TestResource<ObjectTemplateType> template)
throws ConflictException, EncryptionException, CommonException, IOException, SchemaViolationException,
InterruptedException, ObjectAlreadyExistsException {
InterruptedException, com.evolveum.icf.dummy.resource.ObjectAlreadyExistsException {
executeTest(
correlator(name, template),
usersFile,
Expand All @@ -341,26 +338,14 @@ private void executeTest(String name, File usersFile, TestResource<ObjectTemplat
null);
}

@SuppressWarnings("SameParameterValue")
private void executeTest(String name, File usersFile, TestResource<ObjectTemplateType> template, DescriptionMode mode)
throws ConflictException, EncryptionException, CommonException, IOException, SchemaViolationException,
InterruptedException, ObjectAlreadyExistsException {
executeTest(
correlator(name, template),
usersFile,
accountsFile(name),
mode,
null);
}

@SuppressWarnings("SameParameterValue")
private void executeTest(
String name,
File usersFile,
DescriptionMode descriptionMode,
FailableConsumer<List<CorrelationTestingAccount>, CommonException> additionalInitializer)
throws CommonException, IOException, ConflictException, SchemaViolationException,
InterruptedException, ObjectAlreadyExistsException, EncryptionException {
InterruptedException, EncryptionException, com.evolveum.icf.dummy.resource.ObjectAlreadyExistsException {
executeTest(
correlator(name),
usersFile,
Expand All @@ -376,7 +361,7 @@ private void executeTest(
DescriptionMode descriptionMode,
FailableConsumer<List<CorrelationTestingAccount>, CommonException> additionalInitializer)
throws CommonException, IOException, ConflictException, SchemaViolationException,
InterruptedException, ObjectAlreadyExistsException, EncryptionException {
InterruptedException, EncryptionException, com.evolveum.icf.dummy.resource.ObjectAlreadyExistsException {
Task task = getTestTask();
OperationResult result = task.getResult();

Expand All @@ -385,11 +370,7 @@ private void executeTest(
String userTemplateOid = userTemplateResource != null ? userTemplateResource.oid : null;
if (!Objects.equals(userTemplateOid, currentlyUsedTemplateOid)) {
if (userTemplateResource != null) {
repoAdd(userTemplateResource, result);
ObjectTemplateType expanded =
archetypeManager.getExpandedObjectTemplate(
userTemplateResource.oid, TaskExecutionMode.PRODUCTION, result);
userTemplateResource.set(expanded.asPrismObject());
importUserTemplateIfNeeded(userTemplateResource, result);
}
System.out.println("Setting user template OID (in system config) to be " + userTemplateOid);
setDefaultObjectTemplate(UserType.COMPLEX_TYPE, userTemplateOid, result);
Expand Down Expand Up @@ -453,6 +434,20 @@ private void executeTest(
}
}

private void importUserTemplateIfNeeded(TestResource<ObjectTemplateType> userTemplateResource, OperationResult result)
throws SchemaException, IOException, EncryptionException, ObjectNotFoundException, ConfigurationException {
try {
repoAdd(userTemplateResource, result);
} catch (ObjectAlreadyExistsException e) {
// OK, the template was already imported
return;
}
ObjectTemplateType expanded =
archetypeManager.getExpandedObjectTemplate(
userTemplateResource.oid, TaskExecutionMode.PRODUCTION, result);
userTemplateResource.set(expanded.asPrismObject());
}

private void deleteUsers(OperationResult result) throws SchemaException, ObjectNotFoundException {
List<PrismObject<UserType>> users = repositoryService.searchObjects(UserType.class, null, null, result);
for (PrismObject<UserType> user : users) {
Expand Down

0 comments on commit 4df2305

Please sign in to comment.