Skip to content

Commit

Permalink
MID-4568 more config files for test cases, wip
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Oct 27, 2022
1 parent c2d4b8a commit 4261208
Show file tree
Hide file tree
Showing 6 changed files with 372 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,29 @@
import java.io.FileNotFoundException;
import java.net.ConnectException;
import java.util.Arrays;

import com.evolveum.icf.dummy.resource.ConflictException;
import com.evolveum.icf.dummy.resource.SchemaViolationException;
import com.evolveum.midpoint.model.intest.AbstractConfiguredModelIntegrationTest;
import com.evolveum.midpoint.test.DummyResourceContoller;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.testng.AssertJUnit;
import org.testng.annotations.Test;

import com.evolveum.icf.dummy.resource.ConflictException;
import com.evolveum.icf.dummy.resource.SchemaViolationException;
import com.evolveum.midpoint.model.api.ModelExecuteOptions;
import com.evolveum.midpoint.model.api.context.ModelContext;
import com.evolveum.midpoint.model.intest.AbstractConfiguredModelIntegrationTest;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.test.DummyResourceContoller;
import com.evolveum.midpoint.test.DummyTestResource;
import com.evolveum.midpoint.test.TestResource;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

/**
* Created by Viliam Repan (lazyman).
Expand All @@ -45,18 +46,26 @@ public class TestPreviewChangesCoD extends AbstractConfiguredModelIntegrationTes

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

private static final File OBJECT_TEMPLATE_ORG = new File(TEST_DIR, "object-template-org.xml");
private static final TestResource<ObjectTemplateType> OBJECT_TEMPLATE_ORG =
new TestResource<>(TEST_DIR, "object-template-org.xml", "80d8bdb4-7288-41fe-a8a3-e39f1c9d2de3");

private static final TestResource<ObjectTemplateType> OBJECT_TEMPLATE_USER =
new TestResource<>(TEST_DIR, "object-template-user.xml", "fc5bfc7b-0612-450a-85d2-ab5cff7e4ed9");

private static final File ORG_CHILD = new File(TEST_DIR, "org-child.xml");
private static final DummyTestResource RESOURCE_DUMMY = new DummyTestResource(TEST_DIR, "resource-dummy.xml",
"8dfeccc9-e144-4864-a692-e483f4b1873a", "resource-preview-changes-cod", TestPreviewChangesCoD::createAttributeDefinitions);

private static final TestResource<OrgType> ORG_CHILD = new TestResource<>(TEST_DIR, "org-child.xml");

private static final TestResource<UserType> USER_BOB = new TestResource<>(TEST_DIR, "user-bob.xml");

private static final TestResource<RoleType> ROLE_META_ASSIGNMENT_SEARCH =
new TestResource<>(TEST_DIR, "role-meta-assignment-search.xml", "1ac00214-ffd0-49db-a1b9-51b46a0e9ae1");

private static final TestResource<RoleType> ROLE_META_ASSOCIATION_SEARCH =
new TestResource(TEST_DIR, "role-meta-assignment-search.xml", "07edb2fc-5662-4886-aba7-54fbc58ce5ca");
new TestResource<>(TEST_DIR, "role-meta-assignment-search.xml", "07edb2fc-5662-4886-aba7-54fbc58ce5ca");

private static final DummyTestResource RESOURCE_DUMMY = new DummyTestResource(TEST_DIR, "resource-dummy.xml",
"8dfeccc9-e144-4864-a692-e483f4b1873a", "resource-preview-changes-cod", TestPreviewChangesCoD::createAttributeDefinitions);
private static final Class<? extends ObjectType>[] COLLECT_COUNT_TYPES = new Class[] { FocusType.class, ShadowType.class };

@Override
protected File getSystemConfigurationFile() {
Expand All @@ -67,7 +76,10 @@ protected File getSystemConfigurationFile() {
public void initSystem(Task initTask, OperationResult initResult) throws Exception {
super.initSystem(initTask, initResult);

TestResource.read(ORG_CHILD, USER_BOB);

addObject(OBJECT_TEMPLATE_ORG, initTask, initResult);
addObject(OBJECT_TEMPLATE_USER, initTask, initResult);
addObject(ROLE_META_ASSIGNMENT_SEARCH, initTask, initResult);

initDummyResource(RESOURCE_DUMMY, initTask, initResult);
Expand All @@ -88,19 +100,19 @@ public void test100OrgNotProvisioned() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();

final Integer ORG_COUNT = modelService.countObjects(OrgType.class, null, null, task, result);
Map<Class<? extends ObjectType>, Integer> counts = collectCounts(task, result);

when();

PrismObject<OrgType> orgChild = prismContext.parseObject(ORG_CHILD);
ObjectDelta delta = orgChild.createAddDelta();
PrismObject<OrgType> orgChild = ORG_CHILD.getObject().clone();
ObjectDelta<OrgType> delta = orgChild.createAddDelta();

ModelContext<OrgType> context = modelInteractionService.previewChanges(Arrays.asList(delta), ModelExecuteOptions.create(), task, result);
ModelContext<OrgType> context = modelInteractionService.previewChanges(Collections.singletonList(delta), ModelExecuteOptions.create(), task, result);

then();

AssertJUnit.assertNotNull(context);
AssertJUnit.assertEquals("Orgs were created", ORG_COUNT, modelService.countObjects(OrgType.class, null, null, task, result));
assertCollectedCounts(counts, task, result);
}

@Test
Expand All @@ -110,65 +122,92 @@ public void test150OrgNotProvisionedWithMetarole() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();

final Integer ORG_COUNT = modelService.countObjects(OrgType.class, null, null, task, result);
final Integer ROLE_COUNT = modelService.countObjects(RoleType.class, null, null, task, result);
Map<Class<? extends ObjectType>, Integer> counts = collectCounts(task, result);

when();

PrismObject<OrgType> orgChild = prismContext.parseObject(ORG_CHILD);
PrismObject<OrgType> orgChild = ORG_CHILD.getObject().clone();
// we'll add assignment to meta role
orgChild.asObjectable().getAssignment().add(new AssignmentType().targetRef(ROLE_META_ASSIGNMENT_SEARCH.oid, RoleType.COMPLEX_TYPE));
ObjectDelta delta = orgChild.createAddDelta();
ObjectDelta<OrgType> delta = orgChild.createAddDelta();

ModelContext<OrgType> context = modelInteractionService.previewChanges(Arrays.asList(delta), ModelExecuteOptions.create(), task, result);
ModelContext<OrgType> context = modelInteractionService.previewChanges(Collections.singletonList(delta), ModelExecuteOptions.create(), task, result);

then();

AssertJUnit.assertNotNull(context);
AssertJUnit.assertEquals("Orgs were created", ORG_COUNT, modelService.countObjects(OrgType.class, null, null, task, result));
AssertJUnit.assertEquals("Roles were created", ROLE_COUNT, modelService.countObjects(RoleType.class, null, null, task, result));
assertCollectedCounts(counts, task, result);
}

@Test
public void test200EmptyOrgProvisioned() throws Exception {
public void test200ComplexCase() throws Exception {
given();

Task task = getTestTask();
OperationResult result = task.getResult();

Map<Class<? extends ObjectType>, Integer> counts = collectCounts(task, result);

when();

PrismObject<UserType> orgChild = USER_BOB.getObject().clone();
ObjectDelta<UserType> delta = orgChild.createAddDelta();

ModelContext<UserType> context = modelInteractionService.previewChanges(Collections.singletonList(delta), ModelExecuteOptions.create(), task, result);

then();

AssertJUnit.assertNotNull(context);
assertCollectedCounts(counts, task, result);
}

@Test
public void test300UserInOrgProvisioned() throws Exception {
given();

Task task = getTestTask();
OperationResult result = task.getResult();

when();

then();
public void test300ReferenceTargetSearch() throws Exception {
// given();
//
// Task task = getTestTask();
// OperationResult result = task.getResult();
//
// Map<Class<? extends ObjectType>, Integer> counts = collectCounts(task, result);
//
// when();
//
// then();
//
// AssertJUnit.assertNotNull(context);
// assertCollectedCounts(counts, task, result);
}

/**
* MID-7155
*/
@Test
public void test400AssociationTargetSearch() throws Exception {
public void test400MultiThreadSupportForCreateOnDemand() throws Exception {

}

@Test
public void test500ReferenceTargetSearch() throws Exception {
private Map<Class<? extends ObjectType>, Integer> collectCounts(Task task, OperationResult result) throws Exception {
Map<Class<? extends ObjectType>, Integer> map = new HashMap<>();

for (ObjectTypes type : ObjectTypes.values()) {
Class<? extends ObjectType> clazz = type.getClassDefinition();
if (Arrays.stream(COLLECT_COUNT_TYPES).noneMatch(c -> c.isAssignableFrom(clazz))) {
continue;
}

int count = modelService.countObjects(clazz, null, null, task, result);
map.put(clazz, count);
}

return map;
}

/**
* MID-7155
*/
@Test
public void test600MultithreadedSupportForCreateOnDemand() throws Exception {
private void assertCollectedCounts(Map<Class<? extends ObjectType>, Integer> counts, Task task, OperationResult result) throws Exception {
for (Class<? extends ObjectType> clazz : counts.keySet()) {
int expected = counts.get(clazz);

int real = modelService.countObjects(clazz, null, null, task, result);
AssertJUnit.assertEquals(clazz.getSimpleName() + " were created", expected, real);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,30 @@

<name>Org object template</name>

<mapping>
<strength>weak</strength>
<source>
<path>identifier</path>
</source>
<expression>
<script>
<code>
"Org: " + identifier
</code>
</script>
</expression>
<target>
<path>name</path>
</target>
<condition>
<script>
<code>
identifier != null
</code>
</script>
</condition>
</mapping>

<mapping>
<source>
<path>extension/pc:parentIdentifier</path>
Expand All @@ -25,7 +49,7 @@
<expression>
<script>
<code>
parentIdentifier
parentIdentifier.split(':').last()
</code>
</script>
</expression>
Expand All @@ -37,28 +61,35 @@
<expression>
<script>
<code>
parentIdentifier.tokenize("-")[0] + " org"
parentIdentifier.split(':').last()
</code>
</script>
</expression>
<target>
<path>name</path>
<path>identifier</path>
</target>
</populateItem>
<populateItem>
<expression>
<script>
<code>
parentIdentifier
parentIdentifier.substring(0, parentIdentifier.lastIndexOf(":"))
</code>
</script>
</expression>
<target>
<path>identifier</path>
<path>extension/pc:parentIdentifier</path>
</target>
</populateItem>
</populateObject>
</assignmentTargetSearch>
</expression>
<condition>
<script>
<code>
parentIdentifier != null
</code>
</script>
</condition>
</mapping>
</objectTemplate>
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<!--
~ 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.
-->

<objectTemplate xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3"
xmlns:pc="http://midpoint.evolveum.com/xml/ns/samples/preview-changes"
oid="fc5bfc7b-0612-450a-85d2-ab5cff7e4ed9">

<name>object template user</name>

<mapping>
<source>
<path>organization</path>
</source>
<expression>
<assignmentTargetSearch>
<targetType>OrgType</targetType>
<filter>
<q:equal>
<q:path>identifier</q:path>
<expression>
<script>
<code>
organization.split(':').last()
</code>
</script>
</expression>
</q:equal>
</filter>
<createOnDemand>true</createOnDemand>
<populateObject>
<populateItem>
<expression>
<script>
<code>
organization.split(':').last()
</code>
</script>
</expression>
<target>
<path>identifier</path>
</target>
</populateItem>
<populateItem>
<expression>
<script>
<code>
organization.substring(0, organization.lastIndexOf(":"))
</code>
</script>
</expression>
<target>
<path>extension/pc:parentIdentifier</path>
</target>
</populateItem>
</populateObject>
<assignmentProperties>
<subtype>org</subtype>
</assignmentProperties>
</assignmentTargetSearch>
</expression>
<target>
<path>assignment</path>
<set>
<condition>
<script>
<code>
assignment.subtype.contains("org")
</code>
</script>
</condition>
</set>
</target>
</mapping>
</objectTemplate>

0 comments on commit 4261208

Please sign in to comment.