diff --git a/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/misc/TestTracing.java b/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/misc/TestTracing.java index 51c8b7ba897..efcb282adfe 100644 --- a/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/misc/TestTracing.java +++ b/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/misc/TestTracing.java @@ -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; @@ -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 { @@ -39,6 +51,16 @@ public class TestTracing extends AbstractEmptyModelIntegrationTest { private static final TestResource 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 USER_JIM = new TestResource<>(TEST_DIR, "user-jim.xml", "5a85ea58-ecf7-4e23-ab4f-750f877dc13a"); + private static final TestResource ROLE_CLASS_LESS_VALUES = new TestResource<>(TEST_DIR, "role-class-less-values.xml", "c903aee4-8726-47cd-99e9-8aad7a60b12f"); + private static final TestResource 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 { @@ -49,6 +71,10 @@ 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 @@ -56,12 +82,17 @@ 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()); @@ -92,10 +123,60 @@ public void test100IllegalChars() throws Exception { RESOURCE_ILLEGAL.controller.assertAccountByUsername("joe") .assertFullName("A\u0007B"); - SearchResultList> 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 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> objects = repositoryService.searchObjects( + ReportDataType.class, null, null, result); + for (PrismObject object : objects) { + repositoryService.deleteObject(ReportDataType.class, object.getOid(), result); + } + } + + private void assertTraceCanBeParsed(OperationResult result) + throws SchemaException, IOException { + SearchResultList> 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)); diff --git a/model/model-intest/src/test/resources/schema/containers.xsd b/model/model-intest/src/test/resources/schema/containers.xsd new file mode 100644 index 00000000000..31f2fdf04b6 --- /dev/null +++ b/model/model-intest/src/test/resources/schema/containers.xsd @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/model/model-intest/src/test/resources/tracing/function-library-hacking.xml b/model/model-intest/src/test/resources/tracing/function-library-hacking.xml new file mode 100644 index 00000000000..c4c897f2fab --- /dev/null +++ b/model/model-intest/src/test/resources/tracing/function-library-hacking.xml @@ -0,0 +1,57 @@ + + + + hacking + + createContainerValue + + name + xsd:string + + t:ItemDeltaType + + + diff --git a/model/model-intest/src/test/resources/tracing/role-class-less-values.xml b/model/model-intest/src/test/resources/tracing/role-class-less-values.xml new file mode 100644 index 00000000000..6b86c333fb6 --- /dev/null +++ b/model/model-intest/src/test/resources/tracing/role-class-less-values.xml @@ -0,0 +1,34 @@ + + + + class-less-values + + + + strong + + name + + + + + + extension/myContainer + + + + + diff --git a/model/model-intest/src/test/resources/tracing/user-jim.xml b/model/model-intest/src/test/resources/tracing/user-jim.xml new file mode 100644 index 00000000000..d02ff693b72 --- /dev/null +++ b/model/model-intest/src/test/resources/tracing/user-jim.xml @@ -0,0 +1,11 @@ + + + + jim +