Skip to content

Commit

Permalink
Merge branches 'support-4.2' and 'support-4.2' of https://github.com/…
Browse files Browse the repository at this point in the history
…Evolveum/midpoint into support-4.2
  • Loading branch information
katkav committed Jan 26, 2021
2 parents b68e6cc + 5efdddd commit 640218d
Show file tree
Hide file tree
Showing 10 changed files with 411 additions and 4 deletions.
Expand Up @@ -9,6 +9,12 @@
import static org.assertj.core.api.Assertions.assertThat;

import java.io.File;
import java.io.IOException;

import com.evolveum.midpoint.prism.path.ItemName;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;

import com.evolveum.midpoint.util.exception.SchemaException;

import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
Expand All @@ -27,6 +33,12 @@
import com.evolveum.midpoint.test.TestResource;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

/**
* Tests various bugs related to tracing.
*
* E.g. illegal chars (not serializable to XML) in mapping output.
* Or compile-class-less PCVs in mapping output.
*/
@ContextConfiguration(locations = { "classpath:ctx-model-intest-test-main.xml" })
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
public class TestTracing extends AbstractEmptyModelIntegrationTest {
Expand All @@ -39,6 +51,16 @@ public class TestTracing extends AbstractEmptyModelIntegrationTest {
private static final TestResource<RoleType> ROLE_ILLEGAL = new TestResource<>(TEST_DIR, "role-illegal.xml", "13ca97ae-5919-42fb-91fb-cbc88704fd91");
private static final DummyTestResource RESOURCE_ILLEGAL = new DummyTestResource(TEST_DIR, "resource-illegal.xml", "793bb9f5-edae-4251-bce7-4e99a72ac23f", "illegal");

private static final TestResource<UserType> USER_JIM = new TestResource<>(TEST_DIR, "user-jim.xml", "5a85ea58-ecf7-4e23-ab4f-750f877dc13a");
private static final TestResource<RoleType> ROLE_CLASS_LESS_VALUES = new TestResource<>(TEST_DIR, "role-class-less-values.xml", "c903aee4-8726-47cd-99e9-8aad7a60b12f");
private static final TestResource<FunctionLibraryType> FUNCTION_LIBRARY_HACKING = new TestResource<>(TEST_DIR, "function-library-hacking.xml", "87b91749-5f92-4328-bcc3-6f1b6e6e8364");

private static final String CONTAINERS_NS = "http://super.org/midpoint";
private static final ItemName NAME_MY_CONTAINER = new ItemName(CONTAINERS_NS, "myContainer");
public static final ItemName NAME_VALUE = new ItemName(CONTAINERS_NS, "value");
public static final ItemName NAME_EMBEDDED = new ItemName(CONTAINERS_NS, "embedded");
public static final ItemName TYPE_MY_CONTAINER = new ItemName(CONTAINERS_NS, "MyContainerType");

@Override
public void initSystem(Task initTask, OperationResult initResult)
throws Exception {
Expand All @@ -49,19 +71,28 @@ public void initSystem(Task initTask, OperationResult initResult)

initDummyResource(RESOURCE_ILLEGAL, initTask, initResult);
assertSuccess(modelService.testResource(RESOURCE_ILLEGAL.oid, initTask));

repoAdd(USER_JIM, initResult);
repoAdd(ROLE_CLASS_LESS_VALUES, initResult);
repoAdd(FUNCTION_LIBRARY_HACKING, initResult);
}

@Override
protected File getSystemConfigurationFile() {
return SYSTEM_CONFIGURATION_FILE;
}

/**
* Tests illegal chars in mapping output.
*/
@Test
public void test100IllegalChars() throws Exception {
given();
Task task = getTestTask();
OperationResult result = getTestOperationResult();

deleteReportDataObjects(result);

when();
ModelExecuteOptions options = executeOptions();
options.tracingProfile(createModelAndProvisioningLoggingTracingProfile());
Expand Down Expand Up @@ -92,10 +123,60 @@ public void test100IllegalChars() throws Exception {
RESOURCE_ILLEGAL.controller.assertAccountByUsername("joe")
.assertFullName("A\u0007B");

SearchResultList<PrismObject<ReportDataType>> reportDatas =
assertTraceCanBeParsed(result);
}

/**
* Tests class-less PCVs.
*/
@Test
public void test200ClassLessValues() throws Exception {
given();
Task task = getTestTask();
OperationResult result = getTestOperationResult();

deleteReportDataObjects(result);

when();
ModelExecuteOptions options = executeOptions();
options.tracingProfile(createModelAndProvisioningLoggingTracingProfile());

ObjectDelta<UserType> delta = deltaFor(UserType.class)
.item(UserType.F_ASSIGNMENT)
.add(new AssignmentType(prismContext)
.targetRef(ROLE_CLASS_LESS_VALUES.oid, RoleType.COMPLEX_TYPE))
.asObjectDelta(USER_JIM.oid);

executeChanges(delta, options, task, result);

then();
assertSuccess(result);
assertUserAfter(USER_JIM.oid)
.assignments()
.assertAssignments(1)
.end()
.extensionContainer(NAME_MY_CONTAINER)
.assertSize(1)
.value(0)
.assertItems(NAME_VALUE, NAME_EMBEDDED);

assertTraceCanBeParsed(result);
}

private void deleteReportDataObjects(OperationResult result) throws ObjectNotFoundException, SchemaException {
SearchResultList<PrismObject<ReportDataType>> objects = repositoryService.searchObjects(
ReportDataType.class, null, null, result);
for (PrismObject<ReportDataType> object : objects) {
repositoryService.deleteObject(ReportDataType.class, object.getOid(), result);
}
}

private void assertTraceCanBeParsed(OperationResult result)
throws SchemaException, IOException {
SearchResultList<PrismObject<ReportDataType>> reportDataObjects =
repositoryService.searchObjects(ReportDataType.class, null, null, result);
assertThat(reportDatas.size()).as("# of report outputs").isEqualTo(1);
String file = reportDatas.get(0).asObjectable().getFilePath();
assertThat(reportDataObjects.size()).as("# of report outputs").isEqualTo(1);
String file = reportDataObjects.get(0).asObjectable().getFilePath();

TraceParser parser = new TraceParser(prismContext);
TracingOutputType parsed = parser.parse(new File(file));
Expand Down
53 changes: 53 additions & 0 deletions model/model-intest/src/test/resources/schema/containers.xsd
@@ -0,0 +1,53 @@


<!--
~ Copyright (c) 2020 Evolveum and contributors
~
~ This work is dual-licensed under the Apache License 2.0
~ and European Union Public License. See LICENSE file for details.
-->

<xsd:schema elementFormDefault="qualified"
targetNamespace="http://super.org/midpoint"
xmlns:tns="http://super.org/midpoint"
xmlns:a="http://prism.evolveum.com/xml/ns/public/annotation-3"
xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<xsd:import namespace="http://prism.evolveum.com/xml/ns/public/query-3"/>
<xsd:import namespace="http://prism.evolveum.com/xml/ns/public/types-3"/>

<xsd:complexType name="UserExtensionType">
<xsd:annotation>
<xsd:appinfo>
<a:extension ref="c:UserType"/>
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="myContainer" type="tns:MyContainerType" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name="MyContainerType">
<xsd:annotation>
<xsd:appinfo>
<a:container/>
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="value" type="xsd:string"/>
<xsd:element name="embedded" type="tns:EmbeddedContainerType" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name="EmbeddedContainerType">
<xsd:annotation>
<xsd:appinfo>
<a:container/>
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="value" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
@@ -0,0 +1,57 @@
<!--
~ Copyright (c) 2020 Evolveum and contributors
~
~ This work is dual-licensed under the Apache License 2.0
~ and European Union Public License. See LICENSE file for details.
-->

<functionLibrary
xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:t="http://prism.evolveum.com/xml/ns/public/types-3"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
oid="87b91749-5f92-4328-bcc3-6f1b6e6e8364">
<name>hacking</name>
<function>
<name>createContainerValue</name>
<parameter>
<name>name</name>
<type>xsd:string</type>
</parameter>
<returnType>t:ItemDeltaType</returnType>
<script>
<code>
import com.evolveum.midpoint.model.intest.misc.TestTracing
import com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType
import com.evolveum.prism.xml.ns._public.types_3.RawType

import static com.evolveum.midpoint.model.intest.misc.TestTracing.NAME_EMBEDDED
import static com.evolveum.midpoint.model.intest.misc.TestTracing.NAME_VALUE
import static com.evolveum.midpoint.model.intest.misc.TestTracing.TYPE_MY_CONTAINER

itemFactory = midpoint.prismContext.itemFactory()
rootPcv = itemFactory.createContainerValue()

value1 = itemFactory.createProperty(NAME_VALUE)
value1.setRealValue('value1')
rootPcv.add(value1)

embedded = itemFactory.createContainer(NAME_EMBEDDED)
embeddedPcv = itemFactory.createContainerValue()
embedded.add(embeddedPcv)
rootPcv.add(embedded)

value2 = itemFactory.createProperty(NAME_VALUE)
value2.setRealValue('value2')
embedded.add(value2)

log.info('created PCV:\n{}', rootPcv.debugDump())
rootPcv

idt = new ItemDeltaType()
idt.value.add(new RawType(rootPcv, TYPE_MY_CONTAINER, midpoint.prismContext))
// idt.value.add(rootPcv)
idt
</code>
</script>
</function>
</functionLibrary>
@@ -0,0 +1,34 @@
<!--
~ Copyright (c) 2020 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"
oid="c903aee4-8726-47cd-99e9-8aad7a60b12f">
<name>class-less-values</name>
<inducement>
<focusMappings>
<mapping>
<strength>strong</strength>
<source>
<path>name</path>
</source>
<expression>
<script>
<code>
raw = hacking.execute("createContainerValue", [name: name]).getValue().get(0)
pcv = raw.getParsedValue(null, null) // brutal hack
log.info('value = {}', pcv)
pcv
</code>
</script>
</expression>
<target>
<path>extension/myContainer</path>
</target>
</mapping>
</focusMappings>
</inducement>
</role>
11 changes: 11 additions & 0 deletions model/model-intest/src/test/resources/tracing/user-jim.xml
@@ -0,0 +1,11 @@
<!--
~ Copyright (c) 2020 Evolveum and contributors
~
~ This work is dual-licensed under the Apache License 2.0
~ and European Union Public License. See LICENSE file for details.
-->

<user xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
oid="5a85ea58-ecf7-4e23-ab4f-750f877dc13a">
<name>jim</name>
</user>
Expand Up @@ -584,7 +584,11 @@ private ArrayList<String> getImportStringValues(Object realValue, boolean isSing
if (isSingleValue || realValue == null) {
stringValues.add((String) realValue);
} else {
stringValues.addAll((List<String>) realValue);
if (realValue instanceof String) {
stringValues.add((String) realValue);
} else {
stringValues.addAll((List<String>) realValue);
}
}
return stringValues;
}
Expand Down
Expand Up @@ -189,6 +189,14 @@ public void test200ImportReportForUser() throws Exception {
assertTrue(user.asObjectable().getSubtype().isEmpty());
assertEquals("Test import: test_NICK2", user.asObjectable().getNickName().getOrig());
assertTrue(user.asObjectable().getAssignment().isEmpty());

user = searchObjectByName(UserType.class, "testUser03");
assertNotNull("User testUser03 was not created", user);
assertEquals(ActivationStatusType.ENABLED, user.asObjectable().getActivation().getAdministrativeStatus());
assertEquals("2020-07-07T00:00:00.000+02:00", user.asObjectable().getActivation().getValidFrom().toString());
assertEquals("sub31", user.asObjectable().getSubtype().get(0));
assertEquals("Test import: test_NICK3", user.asObjectable().getNickName().getOrig());
assertTrue(user.asObjectable().getAssignment().isEmpty());
}

@Test(dependsOnMethods = {"test115CreateObjectCollectionReportWithCondition"})
Expand Down
@@ -1,3 +1,4 @@
"Name (Collection)";"Administrative status";"Valid from";"Nick";"AssignmentOid";"Subtype"
"testUser01";"enabled";"2020-07-07T00:00:00.000+02:00";"test_NICK";"00000000-0000-0000-0000-000000000008,00000000-0000-0000-0000-000000000004";"sub1,sub22"
"testUser02";"enabled";"2020-07-07T00:00:00.000+02:00";"test_NICK2";;
"testUser03";"enabled";"2020-07-07T00:00:00.000+02:00";"test_NICK3";;"sub31"

0 comments on commit 640218d

Please sign in to comment.