Skip to content

Commit

Permalink
Improve TestAssociations
Browse files Browse the repository at this point in the history
Also, migrate latest dummy scenarios (HR, DMS, trivial AD) to modern
(non-legacy) schema.

Work in progress.
  • Loading branch information
mederly committed Apr 17, 2024
1 parent 96a803a commit 8707a7b
Show file tree
Hide file tree
Showing 15 changed files with 189 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ void initialize() {
}

@Override
public @NotNull String getNativeObjectClassName() {
return OBJECT_CLASS_NAME.local();
public @NotNull ObjectClassName getObjectClassName() {
return OBJECT_CLASS_NAME;
}
}

Expand All @@ -80,8 +80,8 @@ void initialize() {
}

@Override
public @NotNull String getNativeObjectClassName() {
return OBJECT_CLASS_NAME.local();
public @NotNull ObjectClassName getObjectClassName() {
return OBJECT_CLASS_NAME;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ void initialize() {
}

@Override
public @NotNull String getNativeObjectClassName() {
return OBJECT_CLASS_NAME.local();
public @NotNull ObjectClassName getObjectClassName() {
return OBJECT_CLASS_NAME;
}
}

Expand All @@ -88,8 +88,8 @@ void initialize() {
}

@Override
public @NotNull String getNativeObjectClassName() {
return OBJECT_CLASS_NAME.local();
public @NotNull ObjectClassName getObjectClassName() {
return OBJECT_CLASS_NAME;
}
}

Expand All @@ -111,10 +111,9 @@ void initialize() {
}

@Override
public @NotNull String getNativeObjectClassName() {
return OBJECT_CLASS_NAME.local();
public @NotNull ObjectClassName getObjectClassName() {
return OBJECT_CLASS_NAME;
}

}

public class AccountAccess extends ScenarioLinkClass {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import static com.evolveum.midpoint.test.AttrName.icfs;
import static com.evolveum.midpoint.test.AttrName.ri;
import static com.evolveum.midpoint.test.ObjectClassName.custom;
import static com.evolveum.midpoint.test.ObjectClassName.legacyCustom;

import java.time.ZonedDateTime;

Expand Down Expand Up @@ -55,7 +54,7 @@ public DummyHrScenarioExtended initialize() {

public class Person extends ScenarioObjectClass {

public static final ObjectClassName OBJECT_CLASS_NAME = legacyCustom("person");
public static final ObjectClassName OBJECT_CLASS_NAME = custom("person");

public static class AttributeNames {
public static final AttrName NAME = icfs("name");
Expand All @@ -77,14 +76,14 @@ void initialize() {
}

@Override
public @NotNull String getNativeObjectClassName() {
return OBJECT_CLASS_NAME.local();
public @NotNull ObjectClassName getObjectClassName() {
return OBJECT_CLASS_NAME;
}
}

public class Contract extends ScenarioObjectClass {

public static final ObjectClassName OBJECT_CLASS_NAME = legacyCustom("contract");
public static final ObjectClassName OBJECT_CLASS_NAME = custom("contract");

public static class AttributeNames {
public static final AttrName VALID_FROM = ri("validFrom");
Expand All @@ -107,15 +106,15 @@ void initialize() {
}

@Override
public @NotNull String getNativeObjectClassName() {
return OBJECT_CLASS_NAME.local();
public @NotNull ObjectClassName getObjectClassName() {
return OBJECT_CLASS_NAME;
}
}

public class OrgUnit extends ScenarioObjectClass {

// for simplicity, we are not reusing standard "org" class
public static final ObjectClassName OBJECT_CLASS_NAME = legacyCustom("orgUnit");
public static final ObjectClassName OBJECT_CLASS_NAME = custom("orgUnit");

public static class AttributeNames {
public static final AttrName DESCRIPTION = ri("description");
Expand All @@ -132,14 +131,14 @@ void initialize() {
}

@Override
public @NotNull String getNativeObjectClassName() {
return OBJECT_CLASS_NAME.local();
public @NotNull ObjectClassName getObjectClassName() {
return OBJECT_CLASS_NAME;
}
}

public class CostCenter extends ScenarioObjectClass {

public static final ObjectClassName OBJECT_CLASS_NAME = legacyCustom("costCenter");
public static final ObjectClassName OBJECT_CLASS_NAME = custom("costCenter");

public static class AttributeNames {
public static final AttrName DESCRIPTION = ri("description");
Expand All @@ -156,8 +155,8 @@ void initialize() {
}

@Override
public @NotNull String getNativeObjectClassName() {
return OBJECT_CLASS_NAME.local();
public @NotNull ObjectClassName getObjectClassName() {
return OBJECT_CLASS_NAME;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
import java.io.File;

import com.evolveum.icf.dummy.resource.DummyObject;
import com.evolveum.midpoint.model.intest.TestEntitlements;
import com.evolveum.midpoint.model.intest.associations.DummyHrScenarioExtended.CostCenter;
import com.evolveum.midpoint.model.intest.associations.DummyHrScenarioExtended.OrgUnit;
import com.evolveum.midpoint.model.intest.gensync.TestAssociationInbound;
import com.evolveum.midpoint.prism.path.ItemName;
import com.evolveum.midpoint.schema.processor.ResourceObjectTypeIdentification;
import com.evolveum.midpoint.schema.util.Resource;
import com.evolveum.midpoint.test.DummyHrScenario;

import com.evolveum.midpoint.test.TestObject;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
Expand All @@ -33,17 +35,25 @@
import static org.assertj.core.api.Assertions.assertThat;

/**
* Tests the inbound processing of native associations.
* Tests the inbound/outbound processing of native associations.
* Later may be extended to other aspects and/or to simulated associations.
*
* @see TestEntitlements
* @see TestAssociationInbound
*/
@ContextConfiguration(locations = { "classpath:ctx-model-intest-test-main.xml" })
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
public class TestInboundAssociations extends AbstractEmptyModelIntegrationTest {
public class TestAssociations extends AbstractEmptyModelIntegrationTest {

private static final File TEST_DIR = new File("src/test/resources/associations");

private static final File SYSTEM_CONFIGURATION_FILE = new File(TEST_DIR, "system-configuration.xml");

private static final String NS_HR = "http://midpoint.evolveum.com/xml/ns/samples/hr";
private static final String NS_DMS = "http://midpoint.evolveum.com/xml/ns/samples/dms";

private static final ItemName HR_COST_CENTER = new ItemName(NS_HR, "costCenter");

private static final String LEVEL_READ = "read";
private static final String LEVEL_WRITE = "write";
private static final String LEVEL_ADMIN = "admin";
Expand All @@ -59,6 +69,10 @@ public class TestInboundAssociations extends AbstractEmptyModelIntegrationTest {

private static final String INTENT_GROUP = "group";

private static final String ORG_SCIENCES_NAME = "sciences";
private static final String ORG_LAW_NAME = "law";
private static final String CC_1000_NAME = "cc1000";

private static DummyHrScenarioExtended hrScenario;
private static DummyDmsScenario dmsScenario;
private static DummyAdTrivialScenario adScenario;
Expand All @@ -82,6 +96,8 @@ public class TestInboundAssociations extends AbstractEmptyModelIntegrationTest {
private static final TestObject<ArchetypeType> ARCHETYPE_DOCUMENT = TestObject.file(
TEST_DIR, "archetype-document.xml", "ce92f877-9f22-44cf-9ef1-f55675760eb0");

private OrgType cc1000;

@Override
protected File getSystemConfigurationFile() {
return SYSTEM_CONFIGURATION_FILE;
Expand All @@ -107,15 +123,18 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
importGroups();
}

/** These objects should be usable in all tests. */
/**
* These objects should be usable in all tests. They should not be modified by tests; if needed, a test should create
* its own objects to work with.
*/
private void createCommonHrObjects() throws Exception {
DummyObject sciences = hrScenario.orgUnit.add("sciences")
DummyObject sciences = hrScenario.orgUnit.add(ORG_SCIENCES_NAME)
.addAttributeValues(OrgUnit.AttributeNames.DESCRIPTION.local(), "Faculty of Sciences");
DummyObject law = hrScenario.orgUnit.add("law")
DummyObject law = hrScenario.orgUnit.add(ORG_LAW_NAME)
.addAttributeValues(OrgUnit.AttributeNames.DESCRIPTION.local(), "Faculty of Law");

DummyObject cc1000 = hrScenario.costCenter.add("cc1000")
.addAttributeValues(CostCenter.AttributeNames.DESCRIPTION.local(), "cc1000");
DummyObject cc1000 = hrScenario.costCenter.add(CC_1000_NAME)
.addAttributeValues(CostCenter.AttributeNames.DESCRIPTION.local(), CC_1000_NAME);

DummyObject john = hrScenario.person.add("john")
.addAttributeValue(DummyHrScenarioExtended.Person.AttributeNames.FIRST_NAME.local(), "John")
Expand Down Expand Up @@ -143,11 +162,11 @@ private void importCostCenters() throws Exception {
.withProcessingAllAccounts()
.executeOnForeground(getTestOperationResult());

assertOrgByName("cc1000", "after")
.display();
cc1000 = assertOrgByName(CC_1000_NAME, "after")
.display()
.getObjectable();
}

/** Temporary. Later we create these objects via midPoint/outbounds. */
private void createCommonDmsObjects() throws Exception {
DummyObject jack = dmsScenario.account.add("jack");
DummyObject guide = dmsScenario.document.add("guide");
Expand All @@ -158,7 +177,6 @@ private void createCommonDmsObjects() throws Exception {
dmsScenario.accessDocument.add(jackCanReadGuide, guide);
}

/** Temporary. Later we create all via outbounds. */
private void importDocuments() throws Exception {
importAccountsRequest()
.withResourceOid(RESOURCE_DUMMY_DMS.oid)
Expand All @@ -170,15 +188,13 @@ private void importDocuments() throws Exception {
.display();
}

/** Temporary. Later we create these objects via midPoint/outbounds. */
private void createCommonAdObjects() {
DummyObject jim = adScenario.account.add("jim");
DummyObject administrators = adScenario.group.add("administrators");

adScenario.accountGroup.add(jim, administrators);
}

/** Temporary. Later we create all via outbounds. */
private void importGroups() throws Exception {
importAccountsRequest()
.withResourceOid(RESOURCE_DUMMY_AD.oid)
Expand All @@ -190,15 +206,16 @@ private void importGroups() throws Exception {
.display();
}

/** Checks that simply getting the account gets the correct results. A prerequisite for the following test. */
@Test
public void test100GetJohn() throws Exception {
var task = getTestTask();
var result = task.getResult();

when("john is get");
var query = Resource.of(RESOURCE_DUMMY_HR.get())
.queryFor(DummyHrScenario.Person.OBJECT_CLASS_NAME.xsd())
.and().item(DummyHrScenario.Person.AttributeNames.NAME.path()).eq("john")
.queryFor(DummyHrScenarioExtended.Person.OBJECT_CLASS_NAME.xsd())
.and().item(DummyHrScenarioExtended.Person.AttributeNames.NAME.path()).eq("john")
.build();
var shadows = modelService.searchObjects(ShadowType.class, query, null, task, result);

Expand All @@ -208,11 +225,18 @@ public void test100GetJohn() throws Exception {
assertThat(shadows).as("shadows").hasSize(1);

assertShadowAfter(shadows.get(0))
.assertKind(ShadowKindType.ACCOUNT)
.assertIntent(INTENT_PERSON)
.associations()
.association(DummyHrScenario.Person.LinkNames.CONTRACT.q())
.assertSize(1)
.association(DummyHrScenarioExtended.Person.LinkNames.CONTRACT.q())
.assertSize(2);

// We do not check the details here. The provisioning module behavior should be checked in the provisioning tests,
// in particular in TestDummyAssociations / TestDummyNativeAssociations.
}

/** Checks that the account and its associations are correctly imported. */
@Test
public void test110ImportJohn() throws Exception {
var task = getTestTask();
Expand All @@ -226,8 +250,30 @@ public void test110ImportJohn() throws Exception {
.withTracingProfile(createModelAndProvisioningLoggingTracingProfile())
.executeOnForeground(result);

then("john is found");
assertUserAfterByUsername("john");
then("orgs are there (they were created on demand)");
var orgSciencesOid = assertOrgByName(ORG_SCIENCES_NAME, "after")
.display()
.getOid();
var orgLawOid = assertOrgByName(ORG_LAW_NAME, "after")
.display()
.getOid();

and("john is found");
// @formatter:off
assertUserAfterByUsername("john")
.assignments()
.assertAssignments(3)
.by().targetType(ArchetypeType.COMPLEX_TYPE).find()
.assertTargetOid(ARCHETYPE_PERSON.oid)
.end()
.by().identifier("contract:10703321").find()
.assertTargetOid(orgSciencesOid)
.assertSubtype("contract")
.extension()
.assertPropertyValuesEqual(HR_COST_CENTER, CC_1000_NAME)
.end()
.assertOrgRef(cc1000.getOid(), OrgType.COMPLEX_TYPE);
// @formatter:on
}

@Test
Expand Down

0 comments on commit 8707a7b

Please sign in to comment.