Skip to content

Commit

Permalink
MID-4568 orgs now create groups in dummy resource
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Oct 27, 2022
1 parent fb02dc5 commit fc930b2
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.io.File;
import java.io.FileNotFoundException;
import java.lang.reflect.Modifier;
import java.net.ConnectException;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -55,6 +56,9 @@ public class TestPreviewChangesCoD extends AbstractConfiguredModelIntegrationTes
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<RoleType> ROLE_ORG =
new TestResource<>(TEST_DIR, "role-org.xml", "3d82a1af-0380-4368-b80a-b28a8c87b5bb");

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");
Expand All @@ -81,6 +85,7 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
addObject(OBJECT_TEMPLATE_ORG, initTask, initResult);
addObject(OBJECT_TEMPLATE_USER, initTask, initResult);
addObject(ROLE_META_ASSIGNMENT_SEARCH, initTask, initResult);
addObject(ROLE_ORG, initTask, initResult);

RESOURCE_DUMMY.initAndTest(this, initTask, initResult);
}
Expand Down Expand Up @@ -191,6 +196,10 @@ private Map<Class<? extends ObjectType>, Integer> collectCounts(Task task, Opera

for (ObjectTypes type : ObjectTypes.values()) {
Class<? extends ObjectType> clazz = type.getClassDefinition();
if (Modifier.isAbstract(clazz.getModifiers())) {
continue;
}

if (Arrays.stream(COLLECT_COUNT_TYPES).noneMatch(c -> c.isAssignableFrom(clazz))) {
continue;
}
Expand All @@ -203,11 +212,21 @@ private Map<Class<? extends ObjectType>, Integer> collectCounts(Task task, Opera
}

private void assertCollectedCounts(Map<Class<? extends ObjectType>, Integer> counts, Task task, OperationResult result) throws Exception {
StringBuilder msg = new StringBuilder();

boolean fail = false;
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);
int real = repositoryService.countObjects(clazz, null, null, result);
if (expected != real) {
fail = true;
msg.append(clazz.getSimpleName() + " were created, expected: " + expected + ", real: " + real + "\n");
}
}

if (fail) {
AssertJUnit.fail(msg.toString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@
<expression>
<script>
<code>
parentIdentifier.substring(0, parentIdentifier.lastIndexOf(":"))
def index = parentIdentifier.lastIndexOf(":")
if (index &lt; 0) {
return null
}
parentIdentifier.substring(0, index)
</code>
</script>
</expression>
Expand All @@ -92,4 +96,32 @@
</script>
</condition>
</mapping>

<mapping>
<source>
<path>extension/pc:parentIdentifier</path>
</source>
<expression>
<script>
<code>
"Description " + parentIdentifier
</code>
</script>
</expression>
<target>
<path>description</path>
</target>
</mapping>

<mapping>
<expression>
<assignmentTargetSearch>
<targetType>RoleType</targetType>
<oid>3d82a1af-0380-4368-b80a-b28a8c87b5bb</oid>
</assignmentTargetSearch>
</expression>
<target>
<path>assignment</path>
</target>
</mapping>
</objectTemplate>
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<expression>
<script>
<code>
organization.split(':').last()
basic.stringify(organization).split(':').last()
</code>
</script>
</expression>
Expand All @@ -37,7 +37,7 @@
<expression>
<script>
<code>
organization.split(':').last()
basic.stringify(organization).split(':').last()
</code>
</script>
</expression>
Expand All @@ -49,7 +49,8 @@
<expression>
<script>
<code>
organization.substring(0, organization.lastIndexOf(":"))
def str = basic.stringify(organization)
str.substring(0, str.lastIndexOf(":"))
</code>
</script>
</expression>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<name>child org</name>

<extension>
<pc:parentIdentifier>parent-1</pc:parentIdentifier>
<pc:parentIdentifier>parentOfChild-1</pc:parentIdentifier>
</extension>

<identifier>child-1</identifier>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,10 @@

<attribute>
<ref>icfs:name</ref>
<displayName>Username</displayName>
<outbound>
<strength>strong</strength>
<source>
<path>$user/name</path>
<path>name</path>
</source>
<expression>
<script>
Expand All @@ -73,17 +72,9 @@
</script>
</expression>
</outbound>
<inbound>
<!-- This avoids "kickback" of a name from account to a user. -->
<strength>weak</strength>
<target>
<path>$user/name</path>
</target>
</inbound>
</attribute>
<attribute>
<ref>icfs:uid</ref>
<displayName>UID</displayName>
</attribute>
<attribute>
<ref>ri:fullName</ref>
Expand Down Expand Up @@ -122,6 +113,25 @@
<default>true</default>
<objectClass>ri:GroupObjectClass</objectClass>

<attribute>
<ref>icfs:name</ref>
<outbound>
<strength>strong</strength>
<source>
<path>name</path>
</source>
<expression>
<script>
<code>
name
</code>
</script>
</expression>
</outbound>
</attribute>
<attribute>
<ref>icfs:uid</ref>
</attribute>
<attribute>
<ref>ri:description</ref>
<outbound>
Expand Down
69 changes: 69 additions & 0 deletions model/model-intest/src/test/resources/simulation/cod/role-org.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<!--
~ 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="3d82a1af-0380-4368-b80a-b28a8c87b5bb">

<name>role org</name>

<inducement>
<construction>
<resourceRef oid="8dfeccc9-e144-4864-a692-e483f4b1873a"/>
<kind>entitlement</kind>
<intent>group</intent>
</construction>
</inducement>

<!--<inducement>
<focusMappings>
<mapping>
<name>Create new read role</name>
<strength>strong</strength>
<source>
<path>$focus/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" == operation
</code>
</script>
</condition>
</mapping>
</focusMappings>
</inducement>-->
</role>
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@
<objectTemplateRef oid="80d8bdb4-7288-41fe-a8a3-e39f1c9d2de3"/>
<type>OrgType</type>
</defaultObjectPolicyConfiguration>
<defaultObjectPolicyConfiguration>
<objectTemplateRef oid="fc5bfc7b-0612-450a-85d2-ab5cff7e4ed9"/>
<type>UserType</type>
</defaultObjectPolicyConfiguration>
</systemConfiguration>

0 comments on commit fc930b2

Please sign in to comment.