Skip to content

Commit

Permalink
Add "classpath-based" test objects
Browse files Browse the repository at this point in the history
In order to reach test objects (like set of initial tags) from various
modules the new ClassPathTestResource was created. Highly experimental.

Allowed by this, CommonInitialObjects were moved into model-test. Now
they can be imported and used from any place on or above model-impl.

Other changes:

1. Methods of AbstractTestResource and its ancestors were cleaned up
(at least for this time) and somewhat documented.
2. Many places where old-style API was used had to be fixed.

Work in progress.
  • Loading branch information
mederly committed Dec 21, 2022
1 parent 63a21f7 commit 41c7d3b
Show file tree
Hide file tree
Showing 89 changed files with 880 additions and 674 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ protected Map<String, AssignmentType> getSelectedAssignmentsMap() {
String intent = getIntentValue();
selectedObjects.forEach(selectedObject -> {
AssignmentType newConstructionAssignment = ObjectTypeUtil.createAssignmentWithConstruction(
selectedObject.asPrismObject(), kind, intent, getPageBase().getPrismContext());
selectedObject.asPrismObject(), kind, intent);
if (isEntitlementAssignment()) {
NameItemPathSegment segment = getAssociationValue() != null ? new NameItemPathSegment(getAssociationValue().getName()) : null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,11 @@ public static <T extends ObjectType> AssignmentType createAssignmentTo(@NotNull
}

@NotNull
public static AssignmentType createAssignmentWithConstruction(@NotNull PrismObject<ResourceType> object, ShadowKindType kind,
String intent, PrismContext prismContext) {
AssignmentType assignment = new AssignmentType(prismContext);
ConstructionType construction = new ConstructionType(prismContext);
construction.setResourceRef(createObjectRef(object, prismContext));
public static AssignmentType createAssignmentWithConstruction(
@NotNull PrismObject<ResourceType> object, ShadowKindType kind, String intent) {
AssignmentType assignment = new AssignmentType();
ConstructionType construction = new ConstructionType();
construction.setResourceRef(createObjectRef(object));
construction.setKind(kind);
construction.setIntent(intent);
assignment.setConstruction(construction);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
public interface SimpleObjectResolver {

<O extends ObjectType> PrismObject<O> getObject(Class<O> type, String oid, Collection<SelectorOptions<GetOperationOptions>> options,
OperationResult parentResult)
<O extends ObjectType> PrismObject<O> getObject(
Class<O> type, String oid, Collection<SelectorOptions<GetOperationOptions>> options, OperationResult result)
throws ObjectNotFoundException, SchemaException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
repoAddObjectFromFile(USER_JACK_FILE, UserType.class, initResult).asObjectable();
repoAddObjectFromFile(USER_GUYBRUSH_FILE, UserType.class, initResult).asObjectable();

TASK_TRIGGER_SCANNER_ON_DEMAND.initialize(this, initTask, initResult);
TASK_TRIGGER_SCANNER_ON_DEMAND.init(this, initTask, initResult);

messages = new MessageSourceAccessor(messageSource);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,13 @@ public class TestMappingMetadata extends AbstractModelCommonTest {
private static final String MAPPING_VALUE_FULLNAME_METADATA_XML = "mapping-value-fullname-metadata.xml";
private MappingTestEvaluator evaluator;

private static final TestResource<ObjectTemplateType> TEMPLATE_PROVENANCE = new TestResource<>(TEST_DIR, "template-provenance.xml", "0ca5cef4-6df3-42c3-82b6-daae691e960d");
private static final TestResource<ObjectTemplateType> TEMPLATE_PROVENANCE =
new TestResource<>(TEST_DIR, "template-provenance.xml", "0ca5cef4-6df3-42c3-82b6-daae691e960d");

@BeforeClass
public void setupFactory() throws SAXException, IOException, SchemaException {
evaluator = new MappingTestEvaluator();
evaluator.initWithMetadata();

TEMPLATE_PROVENANCE.read();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,12 +384,12 @@ private void executeTest(
TestResource<ObjectTemplateType> userTemplateResource = correlator.userTemplateResource;
String userTemplateOid = userTemplateResource != null ? userTemplateResource.oid : null;
if (!Objects.equals(userTemplateOid, currentlyUsedTemplateOid)) {
if (userTemplateResource != null && userTemplateResource.getObject() == null) {
if (userTemplateResource != null) {
repoAdd(userTemplateResource, result);
ObjectTemplateType expanded =
archetypeManager.getExpandedObjectTemplate(
userTemplateResource.oid, TaskExecutionMode.PRODUCTION, result);
userTemplateResource.object = expanded.asPrismObject();
userTemplateResource.set(expanded.asPrismObject());
}
System.out.println("Setting user template OID (in system config) to be " + userTemplateOid);
setDefaultObjectTemplate(UserType.COMPLEX_TYPE, userTemplateOid, result);
Expand Down Expand Up @@ -482,7 +482,7 @@ private void initializeCorrelator(TestCorrelator correlator, Task task, Operatio
private CorrelationContext createCorrelationContext(
CorrelationTestingAccount account, TestCorrelator correlator, Task task, OperationResult result)
throws CommonException {
ResourceType resource = RESOURCE_DUMMY_CORRELATION.getResource().asObjectable();
ResourceType resource = RESOURCE_DUMMY_CORRELATION.getObjectable();

SynchronizationPolicy synchronizationPolicy = getSynchronizationPolicy();

Expand All @@ -509,7 +509,7 @@ private CorrelationContext createCorrelationContext(
SynchronizationPolicyFactory.forKindAndIntent(
ShadowKindType.ACCOUNT,
SchemaConstants.INTENT_DEFAULT,
RESOURCE_DUMMY_CORRELATION.getResource().asObjectable()),
RESOURCE_DUMMY_CORRELATION.getObjectable()),
"no synchronization policy");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,14 +359,13 @@ public void test100AddResourceFromTemplate() throws CommonException, IOException
OperationResult result = task.getResult();

given("there is a resource template");
importObjectFromFile(RESOURCE_TEMPLATE.file, task, result);
importObject(RESOURCE_TEMPLATE, task, result);

when("adding a specific resource");
RESOURCE_SPECIFIC_1.read();
modelService.executeChanges(
List.of(
DeltaFactory.Object.createAddDelta(
RESOURCE_SPECIFIC_1.getObject())),
RESOURCE_SPECIFIC_1.get())),
null,
task,
result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void test100ReCorrelationForActive() throws Exception {
then("the shadow is there, with 'no owner' correlation state and 'unmatched' situation");
PrismObject<ShadowType> shadow =
MiscUtil.requireNonNull(
findShadowByPrismName(accountName, RESOURCE_DUMMY_ACTIVE.getResource(), result),
findShadowByPrismName(accountName, RESOURCE_DUMMY_ACTIVE.get(), result),
() -> "no shadow '" + accountName + "' is there");
String shadowOid = shadow.getOid();
assertShadowAfter(shadow)
Expand Down Expand Up @@ -123,7 +123,7 @@ public void test110ReCorrelationForProposed() throws Exception {
then("the shadow is there, with 'no owner' correlation state and 'unmatched' situation");
PrismObject<ShadowType> shadow =
MiscUtil.requireNonNull(
findShadowByPrismName(accountName, RESOURCE_DUMMY_PROPOSED.getResource(), result),
findShadowByPrismName(accountName, RESOURCE_DUMMY_PROPOSED.get(), result),
() -> "no shadow '" + accountName + "' is there");
String shadowOid = shadow.getOid();
assertShadowAfter(shadow)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ public void test400BrokenCorrelator() throws Exception {
RESOURCE_DUMMY_BROKEN.controller.addAccount(accountName);

when("import task is run");
TASK_IMPORT_DUMMY_BROKEN.initialize(this, task, result);
TASK_IMPORT_DUMMY_BROKEN.init(this, task, result);
waitForTaskCloseOrSuspend(TASK_IMPORT_DUMMY_BROKEN.oid, 20000);

then("error is correctly recorded both in task and in shadow");
Expand All @@ -1052,7 +1052,7 @@ public void test400BrokenCorrelator() throws Exception {
.assertLastFailureObjectName(accountName)
.assertLastFailureMessage(expectedMessage);

PrismObject<ShadowType> shadow = findShadowByPrismName(accountName, RESOURCE_DUMMY_BROKEN.getResource(), result);
PrismObject<ShadowType> shadow = findShadowByPrismName(accountName, RESOURCE_DUMMY_BROKEN.get(), result);
assertShadowAfter(shadow)
.assertCorrelationSituation(CorrelationSituationType.ERROR)
.assertHasComplexOperationExecutionFailureWithMessage(TASK_IMPORT_DUMMY_BROKEN.oid, expectedMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import static com.evolveum.midpoint.model.intest.CommonArchetypes.ARCHETYPE_TASK_ITERATIVE_BULK_ACTION;
import static com.evolveum.midpoint.model.intest.CommonArchetypes.ARCHETYPE_TASK_SINGLE_BULK_ACTION;
import static com.evolveum.midpoint.model.intest.CommonInitialObjects.*;
import static com.evolveum.midpoint.model.test.CommonInitialObjects.*;
import static com.evolveum.midpoint.model.intest.CommonTasks.TASK_TRIGGER_SCANNER_ON_DEMAND;

import java.io.File;
Expand Down Expand Up @@ -106,23 +106,6 @@ protected void importTaskArchetypes(OperationResult initResult) throws SchemaExc
repoAdd(ARCHETYPE_TASK_SINGLE_BULK_ACTION, initResult);
}

// To be used when needed
protected void importTags(OperationResult initResult) throws SchemaException,
ObjectAlreadyExistsException, EncryptionException, IOException {
// assuming that standard functions are loaded
repoAdd(ARCHETYPE_EVENT_TAG, initResult);
repoAdd(ARCHETYPE_POLICY_SITUATION, initResult);
repoAdd(TAG_FOCUS_ENABLED, initResult);
repoAdd(TAG_FOCUS_DISABLED, initResult);
repoAdd(TAG_FOCUS_NAME_CHANGED, initResult);
repoAdd(TAG_FOCUS_ASSIGNMENT_CHANGED, initResult);
repoAdd(TAG_FOCUS_ARCHETYPE_CHANGED, initResult);
repoAdd(TAG_FOCUS_PARENT_ORG_REFERENCE_CHANGED, initResult);
repoAdd(TAG_FOCUS_ROLE_MEMBERSHIP_CHANGED, initResult);
repoAdd(TAG_PROJECTION_ENABLED, initResult);
repoAdd(TAG_PROJECTION_DISABLED, initResult);
}

/**
* Runs "trigger scanner on demand" task: starts it and waits for its completion.
*
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,17 @@
*/
package com.evolveum.midpoint.model.intest;

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

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

import static com.evolveum.midpoint.schema.constants.SchemaConstants.PATH_ACTIVATION_ENABLE_TIMESTAMP;
import static com.evolveum.midpoint.schema.constants.SchemaConstants.RI_ACCOUNT_OBJECT_CLASS;
import static com.evolveum.midpoint.schema.util.ObjectTypeUtil.cast;

import java.io.File;
import java.util.*;
import java.util.Objects;
import javax.xml.bind.JAXBElement;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.audit.api.AuditEventRecord;
import com.evolveum.midpoint.prism.PrismProperty;
import com.evolveum.midpoint.prism.path.ItemPath;

import com.evolveum.midpoint.schema.SchemaConstantsGenerated;

import com.evolveum.midpoint.schema.constants.MidPointConstants;

import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
Expand All @@ -36,24 +25,28 @@
import org.testng.annotations.Test;

import com.evolveum.icf.dummy.resource.*;
import com.evolveum.midpoint.audit.api.AuditEventRecord;
import com.evolveum.midpoint.model.api.ModelExecuteOptions;
import com.evolveum.midpoint.model.intest.sync.TestValidityRecomputeTask;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismProperty;
import com.evolveum.midpoint.prism.delta.ChangeType;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.prism.delta.PropertyDelta;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.util.PrismAsserts;
import com.evolveum.midpoint.prism.util.PrismTestUtil;
import com.evolveum.midpoint.prism.xml.XmlTypeConverter;
import com.evolveum.midpoint.schema.ObjectDeltaOperation;
import com.evolveum.midpoint.schema.SchemaConstantsGenerated;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.MiscSchemaUtil;
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.test.DummyResourceContoller;
import com.evolveum.midpoint.test.TestResource;
import com.evolveum.midpoint.test.DummyTestResource;
import com.evolveum.midpoint.test.util.TestUtil;
import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
Expand Down Expand Up @@ -82,8 +75,8 @@ public class TestActivation extends AbstractInitializedModelIntegrationTest {
private static final String RESOURCE_DUMMY_CORAL_OID = "10000000-0000-0000-0000-0000000b1004";
private static final String RESOURCE_DUMMY_CORAL_NAME = "coral";

private static final TestResource RESOURCE_DUMMY_PRECREATE = new TestResource(TEST_DIR, "resource-dummy-precreate.xml", "f18711a2-5db5-4562-b50d-3ef4c74f2e1d");
private static final String RESOURCE_DUMMY_PRECREATE_NAME = "precreate";
private static final DummyTestResource RESOURCE_DUMMY_PRECREATE = new DummyTestResource(TEST_DIR,
"resource-dummy-precreate.xml", "f18711a2-5db5-4562-b50d-3ef4c74f2e1d", "precreate");

private static final String ACCOUNT_MANCOMB_DUMMY_USERNAME = "mancomb";
private static final Date ACCOUNT_MANCOMB_VALID_FROM_DATE = MiscUtil.asDate(2011, 2, 3, 4, 5, 6);
Expand All @@ -107,11 +100,6 @@ public class TestActivation extends AbstractInitializedModelIntegrationTest {
private ResourceType resourceDummyCoralType;
private PrismObject<ResourceType> resourceDummyCoral;

private DummyResource dummyResourcePrecreate;
private DummyResourceContoller dummyResourceCtlPrecreate;
private ResourceType resourceDummyPrecreateType;
private PrismObject<ResourceType> resourceDummyPrecreate;

@Override
public void initSystem(Task initTask, OperationResult initResult)
throws Exception {
Expand All @@ -132,11 +120,7 @@ public void initSystem(Task initTask, OperationResult initResult)
resourceDummyCoralType = resourceDummyCoral.asObjectable();
dummyResourceCtlCoral.setResource(resourceDummyCoral);

dummyResourceCtlPrecreate = DummyResourceContoller.create(RESOURCE_DUMMY_PRECREATE_NAME, resourceDummyPrecreate);
dummyResourcePrecreate = dummyResourceCtlPrecreate.getDummyResource();
resourceDummyPrecreate = importAndGetObjectFromFile(ResourceType.class, RESOURCE_DUMMY_PRECREATE.file, RESOURCE_DUMMY_PRECREATE.oid, initTask, initResult);
resourceDummyPrecreateType = resourceDummyPrecreate.asObjectable();
dummyResourceCtlPrecreate.setResource(resourceDummyPrecreate);
RESOURCE_DUMMY_PRECREATE.init(this, initTask, initResult);
//
// setGlobalTracingOverride(createModelLoggingTracingProfile());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void test100AddParent() throws Exception {
// @formatter:off
ObjectDelta<UserType> delta = deltaFor(UserType.class)
.item(UserType.F_ASSIGNMENT)
.add(ObjectTypeUtil.createAssignmentTo(USER_ABRAHAM.object, CHILD))
.add(ObjectTypeUtil.createAssignmentTo(USER_ABRAHAM.get(), CHILD))
.asObjectDelta(USER_ISAAC.oid);
// @formatter:on

Expand Down

0 comments on commit 41c7d3b

Please sign in to comment.