Skip to content

Commit

Permalink
MID-4568 added test with metarole + inducement + CoD
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Oct 26, 2022
1 parent 7875e53 commit 1e40df3
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16107,11 +16107,51 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="previewChanges" type="tns:PreviewChangesType">

</xsd:element>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:long"/>
</xsd:complexType>
<xsd:element name="modelExecuteOptions" type="tns:ModelExecuteOptionsType"/>

<xsd:simpleType name="PreviewChangesType">
<xsd:annotation>
<xsd:documentation>
Specifies whether a particular part should be processed or not.
</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumClass/>
</xsd:appinfo>
</xsd:annotation>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="safe">
<xsd:annotation>
<xsd:documentation>
<p>
<!-- todo -->
</p>
</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="SAFE"/>
</xsd:appinfo>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="unsafe">
<xsd:annotation>
<xsd:documentation>
<p>
<!-- todo -->
</p>
</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="UNSAFE"/>
</xsd:appinfo>
</xsd:annotation>
</xsd:enumeration>
</xsd:restriction>
</xsd:simpleType>

<xsd:complexType name="OperationBusinessContextType">
<xsd:annotation>
<xsd:documentation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,20 @@
import java.io.File;
import java.util.Arrays;

import com.evolveum.midpoint.model.api.ModelExecuteOptions;

import com.evolveum.midpoint.model.api.context.ModelContext;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.delta.ObjectDelta;

import com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType;

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

import com.evolveum.midpoint.model.api.ModelExecuteOptions;
import com.evolveum.midpoint.model.api.context.ModelContext;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
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;

/**
* Created by Viliam Repan (lazyman).
Expand All @@ -41,6 +40,10 @@ public class TestPreviewChangesCoD extends AbstractEmptyModelIntegrationTest {

private static final File ORG_CHILD = new File(TEST_DIR, "org-child.xml");

private static final File ROLE_META = new File(TEST_DIR, "meta-role.xml");

private static final String ROLE_META_OID = "1ac00214-ffd0-49db-a1b9-51b46a0e9ae1";

@Override
protected File getSystemConfigurationFile() {
return SYSTEM_CONFIGURATION_FILE;
Expand All @@ -51,38 +54,70 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
super.initSystem(initTask, initResult);

addObject(OBJECT_TEMPLATE_ORG, initTask, initResult);
addObject(ROLE_META, initTask, initResult);
}

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

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

searchObjectsIterative(OrgType.class, null, null, 0);
final Integer ORG_COUNT = modelService.countObjects(OrgType.class, null, null, task, result);

when();

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

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

then();

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

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

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

searchObjectsIterative(OrgType.class, null, null, 0);
final Integer ORG_COUNT = modelService.countObjects(OrgType.class, null, null, task, result);
final Integer ROLE_COUNT = modelService.countObjects(RoleType.class, null, null, task, result);

when();

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

System.out.println(delta.debugDump());

ModelContext<OrgType> context = modelInteractionService.previewChanges(Arrays.asList(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));
}

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

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

when();


then();

}

@Test
Expand All @@ -93,7 +128,16 @@ public void test300UserInOrgProvisioned() throws Exception {

when();


then();
}

@Test
public void test400AssociationTargetSearch() throws Exception {

}

@Test
public void test500ReferenceTargetSearch() throws Exception {

}
}
61 changes: 61 additions & 0 deletions model/model-intest/src/test/resources/preview-cod/meta-role.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<!--
~ 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.
-->

<role xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3"
oid="1ac00214-ffd0-49db-a1b9-51b46a0e9ae1">

<name>meta role</name>

<inducement>
<focusMappings>
<mapping>
<name>Create new read role</name>
<strength>strong</strength>
<source>
<path>name</path>
</source>
<expression>
<assignmentTargetSearch>
<targetType>RoleType</targetType>
<filter>
<q:equal>
<q:path>name</q:path>
<expression>
<path>$name</path>
</expression>
</q:equal>
</filter>
<createOnDemand>true</createOnDemand>
<populateObject>
<populateItem>
<expression>
<script>
<code>name + '-Read'</code>
</script>
</expression>
<target>
<path>name</path>
</target>
</populateItem>
</populateObject>
</assignmentTargetSearch>
</expression>
<target>
<path>assignment</path>
</target>
<condition>
<script>
<code>
"add".equals(operation)
</code>
</script>
</condition>
</mapping>
</focusMappings>
</inducement>
</role>
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
-->

<org xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:pc="http://midpoint.evolveum.com/xml/ns/samples/preview-changes"
oid="689eae33-14ea-4f59-9426-93bd6f51d9e0">
xmlns:pc="http://midpoint.evolveum.com/xml/ns/samples/preview-changes">

<name>child org</name>

Expand Down

0 comments on commit 1e40df3

Please sign in to comment.