Skip to content

Commit

Permalink
Improve exceptions in ResourceObjectConverter
Browse files Browse the repository at this point in the history
Exceptions thrown in this class provided too little context.
For example, there was no indication of the resource on which
the problem occurred.

This could be solved by upper layers, but that would require
extensive extension wrapping - which may or may not be good;
but there's no time to consider all consequences.

Instead, this commit provides reasonable context in (almost)
all messages thrown in this class. Resource name, object class,
object type, and optionally connector information is added.

This should resolve MID-6712.

Some tests (checking the exceptions) may fail. They will be
adapted later.
  • Loading branch information
mederly committed Mar 8, 2023
1 parent e5cfb19 commit fa436e5
Show file tree
Hide file tree
Showing 8 changed files with 301 additions and 199 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
*/
package com.evolveum.midpoint.model.intest;

import static com.evolveum.midpoint.test.DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_PATH;

import static org.assertj.core.api.Assertions.assertThat;
import static org.testng.AssertJUnit.*;

import static com.evolveum.midpoint.test.DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_PATH;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -53,53 +54,53 @@ public class TestIteration extends AbstractInitializedModelIntegrationTest {
public static final File TEST_DIR = new File("src/test/resources/iteration");

// Plain iteration, no iteration expressions
protected static final File RESOURCE_DUMMY_PINK_FILE = new File(TEST_DIR, "resource-dummy-pink.xml");
protected static final String RESOURCE_DUMMY_PINK_OID = "10000000-0000-0000-0000-00000000a104";
protected static final String RESOURCE_DUMMY_PINK_NAME = "pink";
private static final File RESOURCE_DUMMY_PINK_FILE = new File(TEST_DIR, "resource-dummy-pink.xml");
private static final String RESOURCE_DUMMY_PINK_OID = "10000000-0000-0000-0000-00000000a104";
private static final String RESOURCE_DUMMY_PINK_NAME = "pink";

// Iteration with token expression, pre-iteration condition and post-iteration condition
protected static final File RESOURCE_DUMMY_VIOLET_FILE = new File(TEST_DIR, "resource-dummy-violet.xml");
protected static final String RESOURCE_DUMMY_VIOLET_OID = "10000000-0000-0000-0000-00000000a204";
protected static final String RESOURCE_DUMMY_VIOLET_NAME = "violet";
private static final File RESOURCE_DUMMY_VIOLET_FILE = new File(TEST_DIR, "resource-dummy-violet.xml");
private static final String RESOURCE_DUMMY_VIOLET_OID = "10000000-0000-0000-0000-00000000a204";
private static final String RESOURCE_DUMMY_VIOLET_NAME = "violet";

// similar to violet but it works in the inbound direction
protected static final File RESOURCE_DUMMY_DARK_VIOLET_FILE = new File(TEST_DIR, "resource-dummy-dark-violet.xml");
protected static final String RESOURCE_DUMMY_DARK_VIOLET_OID = "10000000-0000-0000-0000-0000000da204";
protected static final String RESOURCE_DUMMY_DARK_VIOLET_NAME = "darkViolet";
private static final File RESOURCE_DUMMY_DARK_VIOLET_FILE = new File(TEST_DIR, "resource-dummy-dark-violet.xml");
private static final String RESOURCE_DUMMY_DARK_VIOLET_OID = "10000000-0000-0000-0000-0000000da204";
private static final String RESOURCE_DUMMY_DARK_VIOLET_NAME = "darkViolet";

// iteration, token expression, post-iteration condition that invokes isUniquAccountValue()
protected static final File RESOURCE_DUMMY_MAGENTA_FILE = new File(TEST_DIR, "resource-dummy-magenta.xml");
protected static final String RESOURCE_DUMMY_MAGENTA_OID = "10000000-0000-0000-0000-00000000a304";
protected static final String RESOURCE_DUMMY_MAGENTA_NAME = "magenta";
private static final File RESOURCE_DUMMY_MAGENTA_FILE = new File(TEST_DIR, "resource-dummy-magenta.xml");
private static final String RESOURCE_DUMMY_MAGENTA_OID = "10000000-0000-0000-0000-00000000a304";
private static final String RESOURCE_DUMMY_MAGENTA_NAME = "magenta";

// Plain iteration (no expressions). Has synchronization block.
protected static final File RESOURCE_DUMMY_FUCHSIA_FILE = new File(TEST_DIR, "resource-dummy-fuchsia.xml");
protected static final String RESOURCE_DUMMY_FUCHSIA_OID = "10000000-0000-0000-0000-0000000dd204";
protected static final String RESOURCE_DUMMY_FUCHSIA_NAME = "fuchsia";
private static final File RESOURCE_DUMMY_FUCHSIA_FILE = new File(TEST_DIR, "resource-dummy-fuchsia.xml");
private static final String RESOURCE_DUMMY_FUCHSIA_OID = "10000000-0000-0000-0000-0000000dd204";
private static final String RESOURCE_DUMMY_FUCHSIA_NAME = "fuchsia";

// Source for "changing template" test (test820)
protected static final File RESOURCE_DUMMY_ASSOCIATE_FILE = new File(TEST_DIR, "resource-dummy-associate.xml");
protected static final String RESOURCE_DUMMY_ASSOCIATE_OID = "18c109fd-1287-4a9b-9086-9ab878931ac0";
protected static final String RESOURCE_DUMMY_ASSOCIATE_NAME = "associate";
private static final File RESOURCE_DUMMY_ASSOCIATE_FILE = new File(TEST_DIR, "resource-dummy-associate.xml");
private static final String RESOURCE_DUMMY_ASSOCIATE_OID = "18c109fd-1287-4a9b-9086-9ab878931ac0";
private static final String RESOURCE_DUMMY_ASSOCIATE_NAME = "associate";

protected static final File TASK_LIVE_SYNC_DUMMY_DARK_VIOLET_FILE = new File(TEST_DIR, "task-dumy-dark-violet-livesync.xml");
protected static final String TASK_LIVE_SYNC_DUMMY_DARK_VIOLET_OID = "10000000-0000-0000-5555-555500da0204";
private static final File TASK_LIVE_SYNC_DUMMY_DARK_VIOLET_FILE = new File(TEST_DIR, "task-dumy-dark-violet-livesync.xml");
private static final String TASK_LIVE_SYNC_DUMMY_DARK_VIOLET_OID = "10000000-0000-0000-5555-555500da0204";

// Iteration with token expression and pre- and post-condition. Sequential suffix.
// Configured in dark-violet dummy resource as account sync template
protected static final File USER_TEMPLATE_ITERATION_FILE = new File(TEST_DIR, "user-template-iteration.xml");
protected static final String USER_TEMPLATE_ITERATION_OID = "10000000-0000-0000-0000-0000000d0002";
private static final File USER_TEMPLATE_ITERATION_FILE = new File(TEST_DIR, "user-template-iteration.xml");
private static final String USER_TEMPLATE_ITERATION_OID = "10000000-0000-0000-0000-0000000d0002";

// Iteration that generates random suffix. Token expression and post- and pre-conditions.
protected static final File USER_TEMPLATE_ITERATION_RANDOM_FILE = new File(TEST_DIR, "user-template-iteration-random.xml");
private static final File USER_TEMPLATE_ITERATION_RANDOM_FILE = new File(TEST_DIR, "user-template-iteration-random.xml");

// Iteration with token expression (sequential) and post-condition that checks for e-mail uniquness.
protected static final File USER_TEMPLATE_ITERATION_UNIQUE_EMAIL_FILE = new File(TEST_DIR, "user-template-iteration-unique-email.xml");
protected static final String USER_TEMPLATE_ITERATION_UNIQUE_EMAIL_OID = "10000000-0000-0000-0000-0000000d0004";
private static final File USER_TEMPLATE_ITERATION_UNIQUE_EMAIL_FILE = new File(TEST_DIR, "user-template-iteration-unique-email.xml");
private static final String USER_TEMPLATE_ITERATION_UNIQUE_EMAIL_OID = "10000000-0000-0000-0000-0000000d0004";

// Simple focus iteration (to be used with "changing template" test)
protected static final File USER_TEMPLATE_ITERATION_ASSOCIATE_FILE = new File(TEST_DIR, "user-template-iteration-associate.xml");
protected static final String USER_TEMPLATE_ITERATION_ASSOCIATE_OID = "c0ee8964-0d2a-45d5-8a8e-6ee4f31e1c12";
private static final File USER_TEMPLATE_ITERATION_ASSOCIATE_FILE = new File(TEST_DIR, "user-template-iteration-associate.xml");
private static final String USER_TEMPLATE_ITERATION_ASSOCIATE_OID = "c0ee8964-0d2a-45d5-8a8e-6ee4f31e1c12";

private static final String USER_ANGELICA_NAME = "angelica";
private static final String ACCOUNT_SPARROW_NAME = "sparrow";
Expand All @@ -108,7 +109,7 @@ public class TestIteration extends AbstractInitializedModelIntegrationTest {
private static final String ACCOUNT_DEWATT_NAME = "DeWatt";

private static final String USER_LARGO_NAME = "largo";
public static final String ACCOUNT_LARGO_DUMMY_USERNAME = "largo";
private static final String ACCOUNT_LARGO_DUMMY_USERNAME = "largo";

private static final String DESCRIPTION_RUM = "Where's the rum?";

Expand Down Expand Up @@ -151,10 +152,10 @@ public class TestIteration extends AbstractInitializedModelIntegrationTest {

private static final String EMAIL_SUFFIX = "@example.com";

protected String jupiterUserOid;
private String jupiterUserOid;

String iterationTokenDiplomatico;
String iterationTokenMillonario;
private String iterationTokenDiplomatico;
private String iterationTokenMillonario;

@Override
public void initSystem(Task initTask, OperationResult initResult) throws Exception {
Expand Down Expand Up @@ -521,6 +522,13 @@ public void test235HackerAddAccountDummyEternalConflict() throws Exception {
}
assertTrue("result message is does not contain expected '" + exp + "', instead it is: '" + msg + "'", msg.contains(exp));

and("details are captured in the exception message (MID-6712)");
assertThat(msg).as("exception message")
.contains("Dummy Resource Pink")
.contains("AccountObjectClass")
.contains("Default Account")
.contains("DummyConnector");

PrismObject<UserType> userHackerAfter = findUserByUsername("hacker");
display("User after change execution", userHackerAfter);
assertUser(userHackerAfter, null, "hacker", "Joe Hacker", null, null, null);
Expand Down Expand Up @@ -645,7 +653,7 @@ public void test262JupiterCleanup() throws Exception {
cleanUpJupiter();
}

protected void cleanUpJupiter()
private void cleanUpJupiter()
throws SchemaException, ObjectAlreadyExistsException, ObjectNotFoundException,
ExpressionEvaluationException, CommunicationException, ConfigurationException,
PolicyViolationException, SecurityViolationException, SchemaViolationException,
Expand Down Expand Up @@ -2122,6 +2130,7 @@ public void test820SubtypeSetByInbound() throws Exception {
assertEquals("Wrong name of user 2", "jim-1", usersAfter.get(1).getName().getOrig());
}

@SuppressWarnings("SameParameterValue")
private PrismObject<UserType> createUser(String username, String givenName,
String familyName, String nickname, boolean enabled) throws SchemaException {
PrismObject<UserType> user = createUser(username, givenName, familyName, enabled);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.CapabilityType;

import static com.evolveum.midpoint.prism.polystring.PolyString.getOrig;
import static com.evolveum.midpoint.schema.util.ResourceTypeUtil.isDiscoveryAllowed;

/**
Expand Down Expand Up @@ -682,4 +683,35 @@ public void checkExecutionFullyPersistent() {
throw new IllegalStateException("Invoking 'modifying' provisioning operation while being in a simulation mode");
}
}

/** Convenience method for {@link #getExceptionDescription(ConnectorInstance)}. */
public String getExceptionDescription() {
return getExceptionDescription(null);
}

/** Provides basic information about the context in which an exception occurred. See MID-6712. */
public String getExceptionDescription(ConnectorInstance connector) {
StringBuilder sb = new StringBuilder();
sb.append(getOrig(resource.getName()));
if (resourceObjectDefinition != null) {
sb.append(": ");
ResourceObjectTypeDefinition typeDefinition = resourceObjectDefinition.getTypeDefinition();
if (typeDefinition != null) {
String typeName = typeDefinition.getDisplayName();
if (typeName != null) {
sb.append(typeName);
} else {
sb.append(typeDefinition.getTypeIdentification());
}
// TODO consider using object class display name, if present
sb.append(" (").append(resourceObjectDefinition.getObjectClassName().getLocalPart()).append(")");
} else {
sb.append(resourceObjectDefinition.getObjectClassName().getLocalPart());
}
}
if (connector != null) {
sb.append(", ").append(connector.getHumanReadableDescription());
}
return sb.toString();
}
}

0 comments on commit fa436e5

Please sign in to comment.