From f2d0e2b287eb18d80cddb70e103437fb228c9892 Mon Sep 17 00:00:00 2001 From: Richard Richter Date: Thu, 17 Sep 2020 09:16:33 +0200 Subject: [PATCH 1/9] TestOpenDj: resu(tl)s typo fix, minor cleanup --- .../provisioning/impl/opendj/TestOpenDj.java | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/provisioning/provisioning-impl/src/test/java/com/evolveum/midpoint/provisioning/impl/opendj/TestOpenDj.java b/provisioning/provisioning-impl/src/test/java/com/evolveum/midpoint/provisioning/impl/opendj/TestOpenDj.java index e193b804498..511d7b9cdab 100644 --- a/provisioning/provisioning-impl/src/test/java/com/evolveum/midpoint/provisioning/impl/opendj/TestOpenDj.java +++ b/provisioning/provisioning-impl/src/test/java/com/evolveum/midpoint/provisioning/impl/opendj/TestOpenDj.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2018 Evolveum and contributors + * Copyright (C) 2010-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. @@ -12,7 +12,10 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; import javax.xml.datatype.XMLGregorianCalendar; import javax.xml.namespace.QName; @@ -983,7 +986,7 @@ public void test145ModifyAccountJackJpegPhoto() throws Exception { byte[] jpegPhotoLdap = OpenDJController.getAttributeValueBinary(entry, "jpegPhoto"); assertNotNull("No jpegPhoto in LDAP entry", jpegPhotoLdap); assertEquals("Byte length changed (LDAP)", bytesIn.length, jpegPhotoLdap.length); - assertTrue("Bytes do not match (LDAP)", Arrays.equals(bytesIn, jpegPhotoLdap)); + assertArrayEquals("Bytes do not match (LDAP)", bytesIn, jpegPhotoLdap); PrismObject shadow = provisioningService.getObject(ShadowType.class, ACCOUNT_JACK_OID, null, taskManager.createTaskInstance(), result); @@ -997,7 +1000,7 @@ public void test145ModifyAccountJackJpegPhoto() throws Exception { displayValue("Bytes out", MiscUtil.binaryToHex(bytesOut)); assertEquals("Byte length changed (shadow)", bytesIn.length, bytesOut.length); - assertTrue("Bytes do not match (shadow)", Arrays.equals(bytesIn, bytesOut)); + assertArrayEquals("Bytes do not match (shadow)", bytesIn, bytesOut); assertShadows(3); } @@ -1355,7 +1358,7 @@ public void test170DisableAccount() throws Exception { Entry response = openDJController.searchAndAssertByEntryUuid(uid); display("LDAP account", response); - String disabled = openDJController.getAttributeValue(response, "ds-pwp-account-disabled"); + String disabled = OpenDJController.getAttributeValue(response, "ds-pwp-account-disabled"); assertNotNull("no ds-pwp-account-disabled attribute in account " + uid, disabled); display("ds-pwp-account-disabled after change: " + disabled); @@ -1401,7 +1404,7 @@ public void test175AddDisabledAccount() throws Exception { Entry response = openDJController.searchAndAssertByEntryUuid(uid); display("LDAP account", response); - String disabled = openDJController.getAttributeValue(response, "ds-pwp-account-disabled"); + String disabled = OpenDJController.getAttributeValue(response, "ds-pwp-account-disabled"); assertNotNull("no ds-pwp-account-disabled attribute in account " + uid, disabled); System.out.println("ds-pwp-account-disabled after change: " + disabled); @@ -1449,7 +1452,7 @@ public void test176AddEnabledAccount() throws Exception { Entry response = openDJController.searchAndAssertByEntryUuid(uid); display("LDAP account", response); - String disabled = openDJController.getAttributeValue(response, "ds-pwp-account-disabled"); + String disabled = OpenDJController.getAttributeValue(response, "ds-pwp-account-disabled"); assertEquals("ds-pwp-account-disabled not set to \"FALSE\"", "FALSE", disabled); } @@ -1523,7 +1526,7 @@ public void test184UnlockAccount() throws Exception { Entry response = openDJController.searchAndAssertByEntryUuid(uid); display("LDAP account", response); - String pager = openDJController.getAttributeValue(response, "pager"); + String pager = OpenDJController.getAttributeValue(response, "pager"); assertNull("Pager attribute found in account " + uid + ": " + pager, pager); PrismAsserts.assertPropertyValue(shadow, SchemaConstants.PATH_ACTIVATION_LOCKOUT_STATUS, @@ -1593,7 +1596,7 @@ public void test201SearchObjects() throws Exception { // THEN result.computeStatus(); assertSuccess(result); - display("Search resutls", searchResults); + display("Search results", searchResults); assertEquals("Unexpected number of search results", 14, searchResults.size()); @@ -1763,7 +1766,7 @@ public void test230SearchObjectsPagedNoOffset() throws Exception { // THEN then(); assertSuccess(result); - display("Search resutls", searchResults); + display("Search results", searchResults); assertSearchResults(searchResults, "cook", "drake", "hbarbossa"); @@ -1796,7 +1799,7 @@ public void test231SearchObjectsPagedOffsetZero() throws Exception { // THEN then(); assertSuccess(result); - display("Search resutls", searchResults); + display("Search results", searchResults); assertSearchResults(searchResults, "cook", "drake", "hbarbossa", "idm"); @@ -1829,7 +1832,7 @@ public void test232SearchObjectsPagedOffset() throws Exception { then(); result.computeStatus(); assertSuccess(result); - display("Search resutls", searchResults); + display("Search results", searchResults); // The results should be this: assertSearchResults(searchResults, "hbarbossa", "idm", "jbeckett", "jbond", "jgibbs"); @@ -1866,7 +1869,7 @@ public void test233SearchObjectsPagedNoOffsetSortSn() throws Exception { then(); result.computeStatus(); assertSuccess(result); - display("Search resutls", searchResults); + display("Search results", searchResults); assertSearchResults(searchResults, "monk", "hbarbossa", "jbeckett", "jbond"); @@ -1902,7 +1905,7 @@ public void test234SearchObjectsPagedOffsetSortSn() throws Exception { then(); result.computeStatus(); assertSuccess(result); - display("Search resutls", searchResults); + display("Search results", searchResults); assertSearchResults(searchResults, "jbeckett", "jbond", "cook", "drake"); From 5e8e682c79f33276e09c39240b7ae0ab209c3c9a Mon Sep 17 00:00:00 2001 From: Richard Richter Date: Thu, 17 Sep 2020 23:05:08 +0200 Subject: [PATCH 2/9] *TestDummy*: typo sea(r)ch fix + newer operation results creation used --- .../impl/dummy/AbstractBasicDummyTest.java | 3 +- .../impl/dummy/AbstractDummyTest.java | 5 +- .../provisioning/impl/dummy/TestDummy.java | 54 +++++++++---------- .../impl/dummy/TestDummyCaseIgnore.java | 6 +-- .../TestDummyResourceAndSchemaCaching.java | 5 +- .../impl/dummy/TestDummySchemaless.java | 19 +++---- 6 files changed, 40 insertions(+), 52 deletions(-) diff --git a/provisioning/provisioning-impl/src/test/java/com/evolveum/midpoint/provisioning/impl/dummy/AbstractBasicDummyTest.java b/provisioning/provisioning-impl/src/test/java/com/evolveum/midpoint/provisioning/impl/dummy/AbstractBasicDummyTest.java index b92274cf181..eaf0ed388d9 100644 --- a/provisioning/provisioning-impl/src/test/java/com/evolveum/midpoint/provisioning/impl/dummy/AbstractBasicDummyTest.java +++ b/provisioning/provisioning-impl/src/test/java/com/evolveum/midpoint/provisioning/impl/dummy/AbstractBasicDummyTest.java @@ -839,8 +839,7 @@ public void test032ResourceAndConnectorCaching() throws Exception { @Test public void test034ResourceAndConnectorCachingForceFresh() throws Exception { // GIVEN - OperationResult result = new OperationResult(AbstractBasicDummyTest.class.getName() - + ".test011ResourceAndConnectorCachingForceFresh"); + OperationResult result = createOperationResult(); ConnectorInstance configuredConnectorInstance = resourceManager.getConfiguredConnectorInstance( resource, ReadCapabilityType.class, false, result); assertNotNull("No configuredConnectorInstance", configuredConnectorInstance); diff --git a/provisioning/provisioning-impl/src/test/java/com/evolveum/midpoint/provisioning/impl/dummy/AbstractDummyTest.java b/provisioning/provisioning-impl/src/test/java/com/evolveum/midpoint/provisioning/impl/dummy/AbstractDummyTest.java index 58be22ba044..07c5b3e0fb4 100644 --- a/provisioning/provisioning-impl/src/test/java/com/evolveum/midpoint/provisioning/impl/dummy/AbstractDummyTest.java +++ b/provisioning/provisioning-impl/src/test/java/com/evolveum/midpoint/provisioning/impl/dummy/AbstractDummyTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2019 Evolveum and contributors + * Copyright (C) 2010-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. @@ -235,8 +235,7 @@ protected void checkUniqueness(Collection> protected void checkUniqueness(PrismObject object) throws SchemaException { - OperationResult result = new OperationResult(TestDummyNegative.class.getName() - + ".checkConsistency"); + OperationResult result = createOperationResult("checkUniqueness"); PrismPropertyDefinition itemDef = ShadowUtil.getAttributesContainer(object).getDefinition().findAttributeDefinition(SchemaConstants.ICFS_NAME); diff --git a/provisioning/provisioning-impl/src/test/java/com/evolveum/midpoint/provisioning/impl/dummy/TestDummy.java b/provisioning/provisioning-impl/src/test/java/com/evolveum/midpoint/provisioning/impl/dummy/TestDummy.java index 0d8fcff06b9..8c7e26ebe56 100644 --- a/provisioning/provisioning-impl/src/test/java/com/evolveum/midpoint/provisioning/impl/dummy/TestDummy.java +++ b/provisioning/provisioning-impl/src/test/java/com/evolveum/midpoint/provisioning/impl/dummy/TestDummy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2017 Evolveum and contributors + * Copyright (C) 2010-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. @@ -514,7 +514,7 @@ public boolean handle(PrismObject object, OperationResult parentResu } @Test - public void test111SeachIterativeNoFetch() throws Exception { + public void test111SearchIterativeNoFetch() throws Exception { // GIVEN OperationResult result = createOperationResult(); @@ -566,7 +566,7 @@ public void test111SeachIterativeNoFetch() throws Exception { } @Test - public void test112SeachIterativeKindIntent() throws Exception { + public void test112SearchIterativeKindIntent() throws Exception { // GIVEN OperationResult result = createOperationResult(); @@ -619,8 +619,7 @@ private int countProtected(List> shadows) @Test public void test113SearchAllShadowsInRepository() throws Exception { // GIVEN - OperationResult result = new OperationResult(TestDummy.class.getName() - + ".test113SearchAllShadowsInRepository"); + OperationResult result = createOperationResult(); ObjectQuery query = IntegrationTestTools.createAllShadowsQuery(resourceType, prismContext); displayDumpable("All shadows query", query); @@ -720,8 +719,7 @@ public void test116SearchNullQueryResource() throws Exception { @Test public void test117CountNullQueryResource() throws Exception { // GIVEN - OperationResult result = new OperationResult(TestDummy.class.getName() - + ".test117CountNullQueryResource"); + OperationResult result = createOperationResult(); // WHEN int count = provisioningService.countObjects(ResourceType.class, null, null, null, result); @@ -1809,7 +1807,7 @@ public void test170SearchNull() throws Exception { @Test public void test171SearchShipSeaMonkey() throws Exception { - testSeachIterativeSingleAttrFilter( + testSearchIterativeSingleAttrFilter( DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME, "Sea Monkey", null, true, "meathook"); } @@ -1817,7 +1815,7 @@ public void test171SearchShipSeaMonkey() throws Exception { // See MID-1460 @Test(enabled = false) public void test172SearchShipNull() throws Exception { - testSeachIterativeSingleAttrFilter( + testSearchIterativeSingleAttrFilter( DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME, null, null, true, "daemon"); } @@ -1836,7 +1834,7 @@ public void test173SearchWeaponCutlass() throws Exception { IntegrationTestTools.display("dummy", dummyResource.debugDump()); - testSeachIterativeSingleAttrFilter( + testSearchIterativeSingleAttrFilter( DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, "cutlass", null, true, transformNameFromResource("morgan"), "carla"); } @@ -1844,7 +1842,7 @@ public void test173SearchWeaponCutlass() throws Exception { @Test public void test175SearchUidExact() throws Exception { dummyResource.setDisableNameHintChecks(true); - testSeachIterativeSingleAttrFilter( + testSearchIterativeSingleAttrFilter( SchemaConstants.ICFS_UID, willIcfUid, null, true, transformNameFromResource("Will")); dummyResource.setDisableNameHintChecks(false); @@ -1852,14 +1850,14 @@ public void test175SearchUidExact() throws Exception { @Test public void test176SearchUidExactNoFetch() throws Exception { - testSeachIterativeSingleAttrFilter(SchemaConstants.ICFS_UID, willIcfUid, + testSearchIterativeSingleAttrFilter(SchemaConstants.ICFS_UID, willIcfUid, GetOperationOptions.createNoFetch(), false, transformNameFromResource("Will")); } @Test public void test177SearchIcfNameRepoized() throws Exception { - testSeachIterativeSingleAttrFilter( + testSearchIterativeSingleAttrFilter( SchemaConstants.ICFS_NAME, getWillRepoIcfName(), null, true, transformNameFromResource(ACCOUNT_WILL_USERNAME)); } @@ -1868,7 +1866,7 @@ SchemaConstants.ICFS_NAME, getWillRepoIcfName(), null, true, public void test180SearchNullPagingOffset0Size3() throws Exception { ObjectPaging paging = prismContext.queryFactory().createPaging(0, 3); paging.setOrdering(createAttributeOrdering(SchemaConstants.ICFS_NAME)); - SearchResultMetadata searchMetadata = testSeachIterativePaging(null, paging, null, + SearchResultMetadata searchMetadata = testSearchIterativePaging(null, paging, null, getSortedUsernames18x(0, 3)); assertApproxNumberOfAllResults(searchMetadata, getTest18xApproxNumberOfSearchResults()); } @@ -1881,7 +1879,7 @@ public void test180SearchNullPagingOffset0Size3() throws Exception { public void test181SearchNullPagingOffset0Size3Desc() throws Exception { ObjectPaging paging = prismContext.queryFactory().createPaging(0, 3); paging.setOrdering(createAttributeOrdering(SchemaConstants.ICFS_NAME, OrderDirection.DESCENDING)); - SearchResultMetadata searchMetadata = testSeachIterativePaging(null, paging, null, + SearchResultMetadata searchMetadata = testSearchIterativePaging(null, paging, null, getSortedUsernames18xDesc(0, 3)); assertApproxNumberOfAllResults(searchMetadata, getTest18xApproxNumberOfSearchResults()); } @@ -1890,7 +1888,7 @@ public void test181SearchNullPagingOffset0Size3Desc() throws Exception { public void test182SearchNullPagingOffset1Size2() throws Exception { ObjectPaging paging = prismContext.queryFactory().createPaging(1, 2); paging.setOrdering(createAttributeOrdering(SchemaConstants.ICFS_NAME)); - SearchResultMetadata searchMetadata = testSeachIterativePaging(null, paging, null, + SearchResultMetadata searchMetadata = testSearchIterativePaging(null, paging, null, getSortedUsernames18x(1, 2)); assertApproxNumberOfAllResults(searchMetadata, getTest18xApproxNumberOfSearchResults()); } @@ -1899,7 +1897,7 @@ public void test182SearchNullPagingOffset1Size2() throws Exception { public void test183SearchNullPagingOffset2Size3Desc() throws Exception { ObjectPaging paging = prismContext.queryFactory().createPaging(2, 3); paging.setOrdering(createAttributeOrdering(SchemaConstants.ICFS_NAME, OrderDirection.DESCENDING)); - SearchResultMetadata searchMetadata = testSeachIterativePaging(null, paging, null, + SearchResultMetadata searchMetadata = testSearchIterativePaging(null, paging, null, getSortedUsernames18xDesc(2, 3)); assertApproxNumberOfAllResults(searchMetadata, getTest18xApproxNumberOfSearchResults()); } @@ -1932,21 +1930,21 @@ protected ObjectOrdering createAttributeOrdering(QName attrQname, OrderDirection @Test public void test194SearchIcfNameRepoizedNoFetch() throws Exception { - testSeachIterativeSingleAttrFilter(SchemaConstants.ICFS_NAME, getWillRepoIcfName(), + testSearchIterativeSingleAttrFilter(SchemaConstants.ICFS_NAME, getWillRepoIcfName(), GetOperationOptions.createNoFetch(), false, transformNameFromResource(ACCOUNT_WILL_USERNAME)); } @Test public void test195SearchIcfNameExact() throws Exception { - testSeachIterativeSingleAttrFilter( + testSearchIterativeSingleAttrFilter( SchemaConstants.ICFS_NAME, transformNameFromResource(ACCOUNT_WILL_USERNAME), null, true, transformNameFromResource(ACCOUNT_WILL_USERNAME)); } @Test public void test196SearchIcfNameExactNoFetch() throws Exception { - testSeachIterativeSingleAttrFilter(SchemaConstants.ICFS_NAME, transformNameFromResource(ACCOUNT_WILL_USERNAME), + testSearchIterativeSingleAttrFilter(SchemaConstants.ICFS_NAME, transformNameFromResource(ACCOUNT_WILL_USERNAME), GetOperationOptions.createNoFetch(), false, transformNameFromResource(ACCOUNT_WILL_USERNAME)); } @@ -1954,7 +1952,7 @@ public void test196SearchIcfNameExactNoFetch() throws Exception { // TEMPORARY todo move to more appropriate place (model-intest?) @Test public void test197SearchIcfNameAndUidExactNoFetch() throws Exception { - testSeachIterativeAlternativeAttrFilter(SchemaConstants.ICFS_NAME, transformNameFromResource(ACCOUNT_WILL_USERNAME), + testSearchIterativeAlternativeAttrFilter(SchemaConstants.ICFS_NAME, transformNameFromResource(ACCOUNT_WILL_USERNAME), SchemaConstants.ICFS_UID, willIcfUid, GetOperationOptions.createNoFetch(), false, transformNameFromResource(ACCOUNT_WILL_USERNAME)); @@ -2052,13 +2050,13 @@ private ObjectQuery createOnOffQuery() throws SchemaException { return query; } - protected void testSeachIterativeSingleAttrFilter(String attrName, T attrVal, + protected void testSearchIterativeSingleAttrFilter(String attrName, T attrVal, GetOperationOptions rootOptions, boolean fullShadow, String... expectedAccountIds) throws Exception { - testSeachIterativeSingleAttrFilter(dummyResourceCtl.getAttributeQName(attrName), attrVal, + testSearchIterativeSingleAttrFilter(dummyResourceCtl.getAttributeQName(attrName), attrVal, rootOptions, fullShadow, expectedAccountIds); } - protected void testSeachIterativeSingleAttrFilter(QName attrQName, T attrVal, + protected void testSearchIterativeSingleAttrFilter(QName attrQName, T attrVal, GetOperationOptions rootOptions, boolean fullShadow, String... expectedAccountNames) throws Exception { ResourceSchema resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(resource, prismContext); ObjectClassComplexTypeDefinition objectClassDef = resourceSchema.findObjectClassDefinition(SchemaTestConstants.ACCOUNT_OBJECT_CLASS_LOCAL_NAME); @@ -2069,7 +2067,7 @@ protected void testSeachIterativeSingleAttrFilter(QName attrQName, T attrVal testSearchIterative(filter, rootOptions, fullShadow, true, false, expectedAccountNames); } - protected void testSeachIterativeAlternativeAttrFilter(QName attr1QName, T attr1Val, + protected void testSearchIterativeAlternativeAttrFilter(QName attr1QName, T attr1Val, QName attr2QName, T attr2Val, GetOperationOptions rootOptions, boolean fullShadow, String... expectedAccountNames) throws Exception { ResourceSchema resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(resource, prismContext); @@ -2168,7 +2166,7 @@ public boolean handle(PrismObject shadow, OperationResult parentResu // This has to be a different method than ordinary search. We care about ordering here. // Also, paged search without sorting does not make much sense anyway. - private SearchResultMetadata testSeachIterativePaging(ObjectFilter attrFilter, + private SearchResultMetadata testSearchIterativePaging(ObjectFilter attrFilter, ObjectPaging paging, GetOperationOptions rootOptions, String... expectedAccountNames) throws Exception { OperationResult result = createOperationResult(); @@ -3975,8 +3973,7 @@ public void test800LiveSyncInit() throws Exception { dummyResource.clearDeltas(); syncServiceMock.reset(); - OperationResult result = new OperationResult(TestDummy.class.getName() - + ".test800LiveSyncInit"); + OperationResult result = createOperationResult(); // Dry run to remember the current sync token in the task instance. // Otherwise a last sync token whould be used and @@ -4663,5 +4660,4 @@ protected void assertSyncOldShadow(PrismObject oldShadow, assertEquals("Wrong value of ICF name attribute in old shadow", repoName, icfsNameAttribute.getRealValue()); } - } diff --git a/provisioning/provisioning-impl/src/test/java/com/evolveum/midpoint/provisioning/impl/dummy/TestDummyCaseIgnore.java b/provisioning/provisioning-impl/src/test/java/com/evolveum/midpoint/provisioning/impl/dummy/TestDummyCaseIgnore.java index 7c858d441d4..a29a7c956dc 100644 --- a/provisioning/provisioning-impl/src/test/java/com/evolveum/midpoint/provisioning/impl/dummy/TestDummyCaseIgnore.java +++ b/provisioning/provisioning-impl/src/test/java/com/evolveum/midpoint/provisioning/impl/dummy/TestDummyCaseIgnore.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2017 Evolveum and contributors + * Copyright (C) 2010-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. @@ -89,14 +89,14 @@ protected boolean isPreFetchResource() { @Test public void test175SearchUidCase() throws Exception { - testSeachIterativeSingleAttrFilter( + testSearchIterativeSingleAttrFilter( SchemaConstants.ICFS_UID, "wIlL", null, true, transformNameFromResource("Will")); } @Test public void test176SearchUidCaseNoFetch() throws Exception { - testSeachIterativeSingleAttrFilter( + testSearchIterativeSingleAttrFilter( SchemaConstants.ICFS_UID, "wIlL", GetOperationOptions.createNoFetch(), false, transformNameFromResource("Will")); } diff --git a/provisioning/provisioning-impl/src/test/java/com/evolveum/midpoint/provisioning/impl/dummy/TestDummyResourceAndSchemaCaching.java b/provisioning/provisioning-impl/src/test/java/com/evolveum/midpoint/provisioning/impl/dummy/TestDummyResourceAndSchemaCaching.java index 7be70a5ed1d..c33524eee53 100644 --- a/provisioning/provisioning-impl/src/test/java/com/evolveum/midpoint/provisioning/impl/dummy/TestDummyResourceAndSchemaCaching.java +++ b/provisioning/provisioning-impl/src/test/java/com/evolveum/midpoint/provisioning/impl/dummy/TestDummyResourceAndSchemaCaching.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2017 Evolveum and contributors + * Copyright (C) 2010-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. @@ -620,8 +620,7 @@ private String addAccount(File file) throws SchemaException, ObjectAlreadyExists } private PrismObject getAccount(String oid) throws ObjectNotFoundException, CommunicationException, SchemaException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException { - OperationResult result = new OperationResult(TestDummyResourceAndSchemaCaching.class.getName() - + ".getAccount"); + OperationResult result = createOperationResult("getAccount"); PrismObject account = provisioningService.getObject(ShadowType.class, oid, null, null, result); result.computeStatus(); TestUtil.assertSuccess(result); diff --git a/provisioning/provisioning-impl/src/test/java/com/evolveum/midpoint/provisioning/impl/dummy/TestDummySchemaless.java b/provisioning/provisioning-impl/src/test/java/com/evolveum/midpoint/provisioning/impl/dummy/TestDummySchemaless.java index b6b8fb5a004..6eb2d1e62e7 100644 --- a/provisioning/provisioning-impl/src/test/java/com/evolveum/midpoint/provisioning/impl/dummy/TestDummySchemaless.java +++ b/provisioning/provisioning-impl/src/test/java/com/evolveum/midpoint/provisioning/impl/dummy/TestDummySchemaless.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2019 Evolveum and contributors + * Copyright (C) 2010-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. @@ -37,7 +37,6 @@ import com.evolveum.midpoint.provisioning.api.ProvisioningService; import com.evolveum.midpoint.provisioning.impl.AbstractProvisioningIntegrationTest; import com.evolveum.midpoint.provisioning.impl.ProvisioningTestUtil; -import com.evolveum.midpoint.provisioning.impl.opendj.TestOpenDj; import com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance; import com.evolveum.midpoint.schema.CapabilityUtil; import com.evolveum.midpoint.schema.constants.ConnectorTestOperation; @@ -138,8 +137,7 @@ public void test000Integrity() throws Exception { assertNotNull("Resource is null", resourceSchemaless); assertNotNull("ResourceType is null", resourceTypeSchemaless); - OperationResult result = new OperationResult(TestDummySchemaless.class.getName() - + ".test000Integrity"); + OperationResult result = createOperationResult(); ResourceType resource = repositoryService.getObject(ResourceType.class, RESOURCE_DUMMY_NO_SCHEMA_OID, null, result) .asObjectable(); @@ -370,7 +368,7 @@ private void resourceStaticSchemaResourceAndConnectorCaching() throws Exception // Check resource schema caching ResourceSchema resourceSchemaAgain = RefinedResourceSchemaImpl.getResourceSchema(resourceAgain, prismContext); assertNotNull("No resource schema (again)", resourceSchemaAgain); - assertTrue("Resource schema was not cached", resourceSchemaBefore == resourceSchemaAgain); + assertSame("Resource schema was not cached", resourceSchemaBefore, resourceSchemaAgain); // Check capabilities caching @@ -397,11 +395,10 @@ private void resourceStaticSchemaResourceAndConnectorCaching() throws Exception ConnectorInstance configuredConnectorInstanceAgain = resourceManager.getConfiguredConnectorInstance( resourceAgain, ReadCapabilityType.class, false, result); assertNotNull("No configuredConnectorInstance (again)", configuredConnectorInstanceAgain); - assertTrue("Connector instance was not cached", configuredConnectorInstance == configuredConnectorInstanceAgain); + assertSame("Connector instance was not cached", configuredConnectorInstance, configuredConnectorInstanceAgain); // Check if the connector still works. - OperationResult testResult = new OperationResult(TestOpenDj.class.getName() - + ".test010ResourceAndConnectorCaching.test"); + OperationResult testResult = createOperationResult("test"); configuredConnectorInstanceAgain.test(testResult); testResult.computeStatus(); TestUtil.assertSuccess("Connector test failed", testResult); @@ -411,7 +408,7 @@ private void resourceStaticSchemaResourceAndConnectorCaching() throws Exception ConnectorInstance configuredConnectorInstanceAfterTest = resourceManager.getConfiguredConnectorInstance( resourceAgain, ReadCapabilityType.class, false, result); assertNotNull("No configuredConnectorInstance (again)", configuredConnectorInstanceAfterTest); - assertTrue("Connector instance was not cached", configuredConnectorInstanceAgain == configuredConnectorInstanceAfterTest); + assertSame("Connector instance was not cached", configuredConnectorInstanceAgain, configuredConnectorInstanceAfterTest); assertSteadyResource(); } @@ -500,8 +497,6 @@ public void test103ConnectionStaticSchema() throws Exception { RESOURCE_DUMMY_NO_SCHEMA_OID, null, result); ResourceType resourceTypeRepoAfter = resourceRepoAfter.asObjectable(); display("Resource after test", resourceTypeRepoAfter); - - // TODO } /** @@ -550,7 +545,7 @@ private void assertStaticSchemaSanity(ResourceSchema resorceSchema) { ObjectClassComplexTypeDefinition accountDefinition = resorceSchema.findObjectClassDefinition(objectClassQname); assertNotNull("No object class definition for " + objectClassQname + " in resource schema", accountDefinition); ObjectClassComplexTypeDefinition accountDef1 = resorceSchema.findDefaultObjectClassDefinition(ShadowKindType.ACCOUNT); - assertTrue("Mismatched account definition: " + accountDefinition + " <-> " + accountDef1, accountDefinition == accountDef1); + assertSame("Mismatched account definition: " + accountDefinition + " <-> " + accountDef1, accountDefinition, accountDef1); assertNotNull("No object class definition " + objectClassQname, accountDefinition); assertEquals("Object class " + objectClassQname + " is not account", ShadowKindType.ACCOUNT, accountDefinition.getKind()); From 53aa8ceca26956f74c50788e0325d9734fc9e29a Mon Sep 17 00:00:00 2001 From: Richard Richter Date: Thu, 17 Sep 2020 23:10:08 +0200 Subject: [PATCH 3/9] Resource*Panel: sea(r)ch typo fixes in operation name --- .../midpoint/web/page/admin/resources/ResourceContentPanel.java | 2 +- .../web/page/admin/resources/ResourceDetailsTabPanel.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/resources/ResourceContentPanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/resources/ResourceContentPanel.java index de91dae2a41..56aa7ae22eb 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/resources/ResourceContentPanel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/resources/ResourceContentPanel.java @@ -111,7 +111,7 @@ public abstract class ResourceContentPanel extends Panel { private static final Trace LOGGER = TraceManager.getTrace(ResourceContentPanel.class); private static final String DOT_CLASS = ResourceContentTabPanel.class.getName() + "."; - private static final String OPERATION_SEARCH_TASKS_FOR_RESOURCE = DOT_CLASS + "seachTasks"; + private static final String OPERATION_SEARCH_TASKS_FOR_RESOURCE = DOT_CLASS + "searchTasks"; private static final String OPERATION_CHANGE_OWNER = DOT_CLASS + "changeOwner"; private static final String OPERATION_LOAD_SHADOW_OWNER = DOT_CLASS + "loadOwner"; private static final String OPERATION_UPDATE_STATUS = DOT_CLASS + "updateStatus"; diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/resources/ResourceDetailsTabPanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/resources/ResourceDetailsTabPanel.java index 45400f86f5f..76f75c66bb5 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/resources/ResourceDetailsTabPanel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/resources/ResourceDetailsTabPanel.java @@ -61,7 +61,7 @@ public class ResourceDetailsTabPanel extends Panel { private static final Trace LOGGER = TraceManager.getTrace(ResourceDetailsTabPanel.class); private static final String DOT_CLASS = ResourceDetailsTabPanel.class.getName() + "."; - private static final String OPERATION_SEARCH_TASKS_FOR_RESOURCE = DOT_CLASS + "seachTasks"; + private static final String OPERATION_SEARCH_TASKS_FOR_RESOURCE = DOT_CLASS + "searchTasks"; public static final String ID_LAST_AVAILABILITY_STATUS = "lastStatus"; private static final String ID_SOURCE_TARGET = "sourceTarget"; From 54bfa446c46e133a3a7cf1842fe257d1783c0495 Mon Sep 17 00:00:00 2001 From: Richard Richter Date: Thu, 17 Sep 2020 23:16:02 +0200 Subject: [PATCH 4/9] conntest: sea(r)ch typo fixes + minor cleanup --- .../testing/conntest/AbstractEDirTest.java | 12 ++-- .../conntest/AbstractLdapConnTest.java | 20 +++--- .../ad/AbstractAdLdapMultidomainTest.java | 61 +++++++++---------- .../conntest/ad/AbstractAdLdapTest.java | 25 +++++--- 4 files changed, 59 insertions(+), 59 deletions(-) diff --git a/testing/conntest/src/test/java/com/evolveum/midpoint/testing/conntest/AbstractEDirTest.java b/testing/conntest/src/test/java/com/evolveum/midpoint/testing/conntest/AbstractEDirTest.java index 088e4f36048..4e99783e7ae 100644 --- a/testing/conntest/src/test/java/com/evolveum/midpoint/testing/conntest/AbstractEDirTest.java +++ b/testing/conntest/src/test/java/com/evolveum/midpoint/testing/conntest/AbstractEDirTest.java @@ -190,11 +190,11 @@ public void test050Capabilities() { assertTrue("No native activation capability", ResourceTypeUtil.hasResourceNativeActivationCapability(resourceType)); assertTrue("No native activation status capability", ResourceTypeUtil.hasResourceNativeActivationStatusCapability(resourceType)); assertTrue("No native lockout capability", ResourceTypeUtil.hasResourceNativeActivationLockoutCapability(resourceType)); - assertTrue("No native credentias capability", ResourceTypeUtil.isCredentialsCapabilityEnabled(resourceType, null)); // todo ok? + assertTrue("No native credentials capability", ResourceTypeUtil.isCredentialsCapabilityEnabled(resourceType, null)); // todo ok? } @Test - public void test100SeachJackByLdapUid() throws Exception { + public void test100SearchJackByLdapUid() throws Exception { // GIVEN Task task = getTestTask(); OperationResult result = task.getResult(); @@ -231,7 +231,7 @@ public void test100SeachJackByLdapUid() throws Exception { } @Test - public void test105SeachPiratesByCn() throws Exception { + public void test105SearchPiratesByCn() throws Exception { // GIVEN Task task = getTestTask(); OperationResult result = task.getResult(); @@ -342,7 +342,7 @@ public void test120JackLockout() throws Exception { * No paging. It should return all accounts. */ @Test - public void test150SeachAllAccounts() throws Exception { + public void test150SearchAllAccounts() throws Exception { // GIVEN Task task = getTestTask(); OperationResult result = task.getResult(); @@ -361,7 +361,7 @@ public void test150SeachAllAccounts() throws Exception { } @Test - public void test190SeachLockedAccounts() throws Exception { + public void test190SearchLockedAccounts() throws Exception { // GIVEN Task task = getTestTask(); OperationResult result = task.getResult(); @@ -833,7 +833,7 @@ public void test800JackLockoutExpires() throws Exception { } @Test - public void test810SeachLockedAccounts() throws Exception { + public void test810SearchLockedAccounts() throws Exception { // GIVEN Task task = getTestTask(); OperationResult result = task.getResult(); diff --git a/testing/conntest/src/test/java/com/evolveum/midpoint/testing/conntest/AbstractLdapConnTest.java b/testing/conntest/src/test/java/com/evolveum/midpoint/testing/conntest/AbstractLdapConnTest.java index d5ff847a37a..275050e38ba 100644 --- a/testing/conntest/src/test/java/com/evolveum/midpoint/testing/conntest/AbstractLdapConnTest.java +++ b/testing/conntest/src/test/java/com/evolveum/midpoint/testing/conntest/AbstractLdapConnTest.java @@ -178,7 +178,7 @@ public void test000Sanity() throws Exception { } @Test - public void test100SeachAccount0ByLdapUid() throws Exception { + public void test100SearchAccount0ByLdapUid() throws Exception { // GIVEN Task task = getTestTask(); OperationResult result = task.getResult(); @@ -212,7 +212,7 @@ public void test100SeachAccount0ByLdapUid() throws Exception { * No paging. It should return all accounts. */ @Test - public void test150SeachAllAccounts() throws Exception { + public void test150SearchAllAccounts() throws Exception { // GIVEN Task task = getTestTask(); OperationResult result = task.getResult(); @@ -258,7 +258,7 @@ protected void assertCountAllAccounts(Integer count) { * Blocksize is 100, so this is in one block. */ @Test - public void test152SeachFirst50Accounts() throws Exception { + public void test152SearchFirst50Accounts() throws Exception { // GIVEN Task task = getTestTask(); OperationResult result = task.getResult(); @@ -289,7 +289,7 @@ public void test152SeachFirst50Accounts() throws Exception { * Blocksize is 100, so this gets more than two blocks. */ @Test - public void test154SeachFirst222Accounts() throws Exception { + public void test154SearchFirst222Accounts() throws Exception { // GIVEN Task task = getTestTask(); OperationResult result = task.getResult(); @@ -320,7 +320,7 @@ public void test154SeachFirst222Accounts() throws Exception { * Make a search that starts in the list of all accounts but goes beyond the end. */ @Test - public void test156SeachThroughEnd() throws Exception { + public void test156SearchThroughEnd() throws Exception { // GIVEN Task task = getTestTask(); OperationResult result = task.getResult(); @@ -349,7 +349,7 @@ public void test156SeachThroughEnd() throws Exception { * Make a search that goes beyond the end of the list of all accounts. */ @Test - public void test158SeachBeyondEnd() throws Exception { + public void test158SearchBeyondEnd() throws Exception { // GIVEN Task task = getTestTask(); OperationResult result = task.getResult(); @@ -381,7 +381,7 @@ public void test158SeachBeyondEnd() throws Exception { } @Test - public void test162SeachFirst50AccountsOffset0() throws Exception { + public void test162SearchFirst50AccountsOffset0() throws Exception { // GIVEN Task task = getTestTask(); OperationResult result = task.getResult(); @@ -444,7 +444,7 @@ public void test172Search50AccountsOffset20() throws Exception { * No explicit sorting. */ @Test - public void test174SeachFirst222AccountsOffset20() throws Exception { + public void test174SearchFirst222AccountsOffset20() throws Exception { // GIVEN Task task = getTestTask(); OperationResult result = task.getResult(); @@ -538,7 +538,7 @@ public void test184SearchFirst222AccountsOffset20SortUid() throws Exception { * be returned anyway. */ @Test - public void test190SeachAllAccountsSizelimit() throws Exception { + public void test190SearchAllAccountsSizelimit() throws Exception { // GIVEN Task task = getTestTask(); OperationResult result = task.getResult(); @@ -1117,7 +1117,7 @@ public void test309UnassignRoleUndeadFromLechuck() throws Exception { } @Test - public void test310SeachGroupEvilByCn() throws Exception { + public void test310SearchGroupEvilByCn() throws Exception { // GIVEN Task task = getTestTask(); OperationResult result = task.getResult(); diff --git a/testing/conntest/src/test/java/com/evolveum/midpoint/testing/conntest/ad/AbstractAdLdapMultidomainTest.java b/testing/conntest/src/test/java/com/evolveum/midpoint/testing/conntest/ad/AbstractAdLdapMultidomainTest.java index b397884d29f..730d793c137 100644 --- a/testing/conntest/src/test/java/com/evolveum/midpoint/testing/conntest/ad/AbstractAdLdapMultidomainTest.java +++ b/testing/conntest/src/test/java/com/evolveum/midpoint/testing/conntest/ad/AbstractAdLdapMultidomainTest.java @@ -1,18 +1,19 @@ /* - * Copyright (c) 2015-2019 Evolveum and contributors + * Copyright (C) 2015-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. */ package com.evolveum.midpoint.testing.conntest.ad; +import static org.assertj.core.api.Assertions.assertThat; import static org.testng.AssertJUnit.*; import static com.evolveum.midpoint.schema.constants.SchemaConstants.PATH_CREDENTIALS_PASSWORD_VALUE; import java.io.File; import java.io.IOException; -import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.Enumeration; import java.util.List; @@ -20,9 +21,6 @@ import javax.xml.datatype.XMLGregorianCalendar; import javax.xml.namespace.QName; -import com.evolveum.midpoint.prism.PrismProperty; -import com.evolveum.midpoint.util.exception.ObjectNotFoundException; - import org.apache.commons.lang3.StringUtils; import org.apache.directory.api.ldap.model.cursor.CursorException; import org.apache.directory.api.ldap.model.entry.DefaultEntry; @@ -38,6 +36,7 @@ import com.evolveum.midpoint.common.refinery.RefinedResourceSchema; import com.evolveum.midpoint.prism.PrismObject; +import com.evolveum.midpoint.prism.PrismProperty; import com.evolveum.midpoint.prism.delta.ObjectDelta; import com.evolveum.midpoint.prism.delta.PropertyDelta; import com.evolveum.midpoint.prism.path.ItemPath; @@ -66,8 +65,8 @@ import com.evolveum.midpoint.testing.conntest.AbstractLdapTest; import com.evolveum.midpoint.testing.conntest.UserLdapConnectionConfig; import com.evolveum.midpoint.util.MiscUtil; +import com.evolveum.midpoint.util.exception.ObjectNotFoundException; import com.evolveum.midpoint.util.exception.SchemaException; -import com.evolveum.midpoint.util.exception.SystemException; import com.evolveum.midpoint.xml.ns._public.common.common_3.*; import com.evolveum.prism.xml.ns._public.types_3.PolyStringType; import com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType; @@ -76,7 +75,7 @@ * Active Directory multidomain test abstract superclass. * This tests configuration of Active Directory forrest with two domains: parent domain and child domain. * Whole forrest is configured as a single resource. - * + *

* This is a "live and conservative" conntest. * Which means that it runs on very realy and very live Active Directory forrest. * The AD servers are NOT cleaned and reset after/before test. @@ -177,8 +176,6 @@ public abstract class AbstractAdLdapMultidomainTest extends AbstractLdapTest private String accountSubmanOid; - private String accountSubmarineOid; - @Override protected String getResourceOid() { return "eced6d24-73e3-11e5-8457-93eff15a6b85"; @@ -357,8 +354,8 @@ public void test000Sanity() throws Exception { Properties p = System.getProperties(); Enumeration keys = p.keys(); while (keys.hasMoreElements()) { - String key = (String)keys.nextElement(); - String value = (String)p.get(key); + String key = (String) keys.nextElement(); + String value = (String) p.get(key); System.out.println("PROP: " + key + ": " + value); } @@ -402,7 +399,7 @@ public void test020Schema() throws Exception { } @Test - public void test100SeachJackBySamAccountName() throws Exception { + public void test100SearchJackBySamAccountName() throws Exception { // GIVEN Task task = getTestTask(); OperationResult result = task.getResult(); @@ -445,7 +442,7 @@ public void test100SeachJackBySamAccountName() throws Exception { * MID-3730 */ @Test - public void test101SeachJackByDn() throws Exception { + public void test101SearchJackByDn() throws Exception { // GIVEN Task task = getTestTask(); OperationResult result = task.getResult(); @@ -490,7 +487,7 @@ public void test101SeachJackByDn() throws Exception { * MID-3730 */ @Test - public void test102SeachNotExistByDn() throws Exception { + public void test102SearchNotExistByDn() throws Exception { // GIVEN Task task = getTestTask(); OperationResult result = task.getResult(); @@ -518,7 +515,7 @@ public void test102SeachNotExistByDn() throws Exception { } @Test - public void test105SeachPiratesByCn() throws Exception { + public void test105SearchPiratesByCn() throws Exception { // GIVEN Task task = getTestTask(); OperationResult result = task.getResult(); @@ -579,7 +576,7 @@ public void test110GetJack() throws Exception { IntegrationTestTools.assertAssociation(shadow, getAssociationGroupQName(), groupPiratesOid); - assertAttribute(shadow, "dn", "CN=Jack Sparrow,"+getPeopleLdapSuffix()); + assertAttribute(shadow, "dn", "CN=Jack Sparrow," + getPeopleLdapSuffix()); assertAttribute(shadow, "cn", ACCOUNT_JACK_FULL_NAME); assertAttribute(shadow, "sn", "Sparrow"); assertAttribute(shadow, "description", "The best pirate the world has ever seen"); @@ -601,7 +598,7 @@ public void test110GetJack() throws Exception { * No paging. It should return all accounts. */ @Test - public void test150SeachAllAccounts() throws Exception { + public void test150SearchAllAccounts() throws Exception { // GIVEN Task task = getTestTask(); OperationResult result = task.getResult(); @@ -635,7 +632,7 @@ public void test150SeachAllAccounts() throws Exception { * This is in one block. */ @Test - public void test152SeachFirst2Accounts() throws Exception { + public void test152SearchFirst2Accounts() throws Exception { // GIVEN Task task = getTestTask(); OperationResult result = task.getResult(); @@ -661,7 +658,7 @@ public void test152SeachFirst2Accounts() throws Exception { } @Test - public void test154SeachFirst5Accounts() throws Exception { + public void test154SearchFirst5Accounts() throws Exception { // GIVEN Task task = getTestTask(); OperationResult result = task.getResult(); @@ -687,7 +684,7 @@ public void test154SeachFirst5Accounts() throws Exception { } @Test - public void test162SeachFirst2AccountsOffset0() throws Exception { + public void test162SearchFirst2AccountsOffset0() throws Exception { // GIVEN Task task = getTestTask(); OperationResult result = task.getResult(); @@ -747,7 +744,7 @@ public void test172Search2AccountsOffset1() throws Exception { * No explicit sorting. */ @Test - public void test174SeachFirst5AccountsOffset2() throws Exception { + public void test174SearchFirst5AccountsOffset2() throws Exception { // GIVEN Task task = getTestTask(); OperationResult result = task.getResult(); @@ -812,7 +809,7 @@ public void test182Search2AccountsOffset1SortCn() throws Exception { } protected String getExpected182FirstShadow() { - return "CN=Administrator,"+getPeopleLdapSuffix(); + return "CN=Administrator," + getPeopleLdapSuffix(); } @Test @@ -1055,8 +1052,8 @@ public void test216ModifyAccountBarbossaUserParameters() throws Exception { assertModelShadow(shadowOid) .attributes() - .attribute(ATTRIBUTE_USER_PARAMETERS_NAME) - .assertRealValues(VERY_STRANGE_PARAMETER); + .attribute(ATTRIBUTE_USER_PARAMETERS_NAME) + .assertRealValues(VERY_STRANGE_PARAMETER); // assertLdapConnectorInstances(2); } @@ -2197,7 +2194,7 @@ public void test700AssignAccountSubmarineAndModify() throws Exception { String shadowOid = getSingleLinkOid(userAfter); PrismObject shadow = getShadowModel(shadowOid); display("Shadow (model)", shadow); - accountSubmarineOid = shadow.getOid(); + assertThat(shadow.getOid()).isNotBlank(); Collection> identifiers = ShadowUtil.getPrimaryIdentifiers(shadow); String accountIcfUid = (String) identifiers.iterator().next().getRealValue(); assertNotNull("No identifier in " + shadow, accountIcfUid); @@ -2251,7 +2248,7 @@ public void test850ReconcileAccounts() throws Exception { // DISABLED because we do not know how to properly configure sync privileges in a AD forrest. // More experiments are needed, but only after we migrate our old AD servers. - @Test(enabled=false) + @Test(enabled = false) public void test900ImportSyncTask() throws Exception { // GIVEN Task task = getTestTask(); @@ -2276,7 +2273,7 @@ public void test900ImportSyncTask() throws Exception { // DISABLED because we do not know how to properly configure sync privileges in a AD forrest. // More experiments are needed, but only after we migrate our old AD servers. - @Test(enabled=false) + @Test(enabled = false) public void test901SyncAddAccountHt() throws Exception { // GIVEN Task task = getTestTask(); @@ -2311,7 +2308,9 @@ protected void assertStepSyncToken(String syncTaskOid, int step, long tsStart, l PrismProperty syncTokenProperty = task.getExtensionPropertyOrClone(SchemaConstants.SYNC_TOKEN); assertNotNull("No sync token", syncTokenProperty); assertNotNull("No sync token value", syncTokenProperty.getRealValue()); - assertNotNull("Empty sync token value", StringUtils.isBlank(syncTokenProperty.getRealValue())); + assertThat(StringUtils.isBlank(syncTokenProperty.getRealValue())) + .as("Empty sync token value") + .isTrue(); assertSuccess(result); } @@ -2477,11 +2476,7 @@ protected Entry createAccountEntry(String uid, String cn, String givenName, Stri private byte[] encodePassword(String password) { String quotedPassword = "\"" + password + "\""; - try { - return quotedPassword.getBytes("UTF-16LE"); - } catch (UnsupportedEncodingException e) { - throw new SystemException(e.getMessage(), e); - } + return quotedPassword.getBytes(StandardCharsets.UTF_16LE); } public void assertAttribute(PrismObject shadow, String attrName, T... expectedValues) { diff --git a/testing/conntest/src/test/java/com/evolveum/midpoint/testing/conntest/ad/AbstractAdLdapTest.java b/testing/conntest/src/test/java/com/evolveum/midpoint/testing/conntest/ad/AbstractAdLdapTest.java index eb9b6bde36c..709c56e11b0 100644 --- a/testing/conntest/src/test/java/com/evolveum/midpoint/testing/conntest/ad/AbstractAdLdapTest.java +++ b/testing/conntest/src/test/java/com/evolveum/midpoint/testing/conntest/ad/AbstractAdLdapTest.java @@ -6,6 +6,7 @@ */ package com.evolveum.midpoint.testing.conntest.ad; +import static org.assertj.core.api.Assertions.assertThat; import static org.testng.AssertJUnit.*; import static com.evolveum.midpoint.schema.constants.SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS; @@ -242,7 +243,7 @@ public void test020Schema() throws Exception { // test050 in subclasses @Test - public void test100SeachJackBySamAccountName() throws Exception { + public void test100SearchJackBySamAccountName() throws Exception { // GIVEN Task task = getTestTask(); OperationResult result = task.getResult(); @@ -278,7 +279,7 @@ public void test100SeachJackBySamAccountName() throws Exception { } @Test - public void test105SeachPiratesByCn() throws Exception { + public void test105SearchPiratesByCn() throws Exception { // GIVEN Task task = getTestTask(); OperationResult result = task.getResult(); @@ -352,7 +353,7 @@ public void test110GetJack() throws Exception { * No paging. It should return all accounts. */ @Test - public void test150SeachAllAccounts() throws Exception { + public void test150SearchAllAccounts() throws Exception { // GIVEN Task task = getTestTask(); OperationResult result = task.getResult(); @@ -382,7 +383,7 @@ public void test150SeachAllAccounts() throws Exception { * Blocksize is 5, so this is in one block. */ @Test - public void test152SeachFirst2Accounts() throws Exception { + public void test152SearchFirst2Accounts() throws Exception { // GIVEN Task task = getTestTask(); OperationResult result = task.getResult(); @@ -410,7 +411,7 @@ public void test152SeachFirst2Accounts() throws Exception { * Blocksize is 5, so this gets more than two blocks. */ @Test - public void test154SeachFirst11Accounts() throws Exception { + public void test154SearchFirst11Accounts() throws Exception { // GIVEN Task task = getTestTask(); OperationResult result = task.getResult(); @@ -435,7 +436,7 @@ public void test154SeachFirst11Accounts() throws Exception { } @Test - public void test162SeachFirst2AccountsOffset0() throws Exception { + public void test162SearchFirst2AccountsOffset0() throws Exception { // GIVEN Task task = getTestTask(); OperationResult result = task.getResult(); @@ -495,7 +496,7 @@ public void test172Search2AccountsOffset1() throws Exception { * No explicit sorting. */ @Test - public void test174SeachFirst11AccountsOffset2() throws Exception { + public void test174SearchFirst11AccountsOffset2() throws Exception { // GIVEN Task task = getTestTask(); OperationResult result = task.getResult(); @@ -1237,16 +1238,20 @@ protected void assertStepSyncToken(String syncTaskOid, int step, long tsStart, l PrismProperty syncTokenProperty = task.getExtensionPropertyOrClone(SchemaConstants.SYNC_TOKEN); assertNotNull("No sync token", syncTokenProperty); assertNotNull("No sync token value", syncTokenProperty.getRealValue()); - assertNotNull("Empty sync token value", StringUtils.isBlank(syncTokenProperty.getRealValue())); + assertThat(StringUtils.isBlank(syncTokenProperty.getRealValue())) + .as("Empty sync token value") + .isTrue(); result.computeStatus(); TestUtil.assertSuccess(result); } - public void assertAttribute(PrismObject shadow, String attrName, T... expectedValues) { + @SafeVarargs + public final void assertAttribute(PrismObject shadow, String attrName, T... expectedValues) { assertAttribute(shadow, new QName(getResourceNamespace(), attrName), expectedValues); } - public void assertAttribute(PrismObject shadow, QName attrQname, T... expectedValues) { + @SafeVarargs + public final void assertAttribute(PrismObject shadow, QName attrQname, T... expectedValues) { List actualValues = ShadowUtil.getAttributeValues(shadow, attrQname); PrismAsserts.assertSets("attribute " + attrQname + " in " + shadow, actualValues, expectedValues); } From e6e142fd8923b2d3170714b5a40ce6ebbeecd131 Mon Sep 17 00:00:00 2001 From: Richard Richter Date: Fri, 18 Sep 2020 09:10:10 +0200 Subject: [PATCH 5/9] TestImportRecon.java: review, added TODO about random failure --- .../midpoint/model/intest/sync/TestImportRecon.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/sync/TestImportRecon.java b/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/sync/TestImportRecon.java index e1803dd2ec4..eda47a9352d 100644 --- a/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/sync/TestImportRecon.java +++ b/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/sync/TestImportRecon.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2020 Evolveum and contributors + * Copyright (C) 2010-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. @@ -76,7 +76,8 @@ public class TestImportRecon extends AbstractInitializedModelIntegrationTest { private static final File TEST_DIR = new File("src/test/resources/sync"); - private static final TestResource USER_IMPORTER = new TestResource(TEST_DIR, "user-importer.xml", "00000000-1111-1111-1111-000000000002"); + private static final TestResource USER_IMPORTER = new TestResource<>( + TEST_DIR, "user-importer.xml", "00000000-1111-1111-1111-000000000002"); private static final String ACCOUNT_OTIS_NAME = "otis"; private static final String ACCOUNT_OTIS_FULLNAME = "Otis"; @@ -2532,6 +2533,7 @@ public void test520ReconResourceDummyFilter() throws Exception { OperationStatsType statistics = taskAfter.getStoredOperationStats(); SynchronizationInformationType syncInfo = statistics.getSynchronizationInformation(); + // TODO: sometimes fails with: java.lang.AssertionError: expected:<12> but was:<0> assertEquals(17 - 3 - 2, syncInfo.getCountLinked()); //total (17) - filtered (3)- protectected (2) } From 6c9b475056df6e2e3a3b88528195832f8d0813f1 Mon Sep 17 00:00:00 2001 From: Richard Richter Date: Fri, 18 Sep 2020 09:13:45 +0200 Subject: [PATCH 6/9] TestInboundOutboundAssociation.java: review, TODO about random failure --- .../story/TestInboundOutboundAssociation.java | 41 +++---------------- 1 file changed, 6 insertions(+), 35 deletions(-) diff --git a/testing/story/src/test/java/com/evolveum/midpoint/testing/story/TestInboundOutboundAssociation.java b/testing/story/src/test/java/com/evolveum/midpoint/testing/story/TestInboundOutboundAssociation.java index f89598a7987..99667dee271 100644 --- a/testing/story/src/test/java/com/evolveum/midpoint/testing/story/TestInboundOutboundAssociation.java +++ b/testing/story/src/test/java/com/evolveum/midpoint/testing/story/TestInboundOutboundAssociation.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 Evolveum and contributors + * Copyright (C) 2018-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. @@ -90,14 +90,15 @@ public void test100ImportGroupPirates() throws Exception { DummyGroup group = new DummyGroup(GROUP_PIRATES_NAME); getDummyResourceDir().addGroup(group); - // WHEN when(); - + // TODO fails on JDK 8 long tests in funny way, every second time: + // java.lang.AssertionError: Timeout (25000) while waiting for Task(id:7d79f012-d861-11e8-b788-07bda6c5bb24, + // name:Live Sync: Dummy Dir Resource, oid:7d79f012-d861-11e8-b788-07bda6c5bb24) to finish. Last result R(run IN_PROGRESS null) + // at com.evolveum.midpoint.testing.story.TestInboundOutboundAssociation.liveSyncDir(TestInboundOutboundAssociation.java:514) + // This then takes with it tests 130, 140, 149, 150, 152, 153, 154 and 159. liveSyncDir(); - // THEN then(); - displayDumpable("dir after", getDummyResourceDir()); RoleAsserter rolePiratesAsserter = assertRoleAfterByName(groupRoleName(GROUP_PIRATES_NAME)); @@ -122,11 +123,9 @@ public void test110AssignJackDirAccount() throws Exception { Task task = getTestTask(); OperationResult result = task.getResult(); - // WHEN when(); assignAccount(UserType.class, USER_JACK_OID, RESOURCE_DUMMY_DIR_OID, null, task, result); - // THEN then(); assertSuccess(result); @@ -148,13 +147,10 @@ public void test110AssignJackDirAccount() throws Exception { */ @Test public void test115Stability() throws Exception { - // WHEN when(); liveSyncDir(); - // THEN then(); - displayDumpable("dir after", getDummyResourceDir()); assertDummyAccountByUsername(RESOURCE_DUMMY_DIR_NAME, USER_JACK_USERNAME) @@ -177,14 +173,10 @@ public void test120AddJackToGroupPirates() throws Exception { getDummyResourceDir().getAccountByUsername(USER_JACK_USERNAME) .replaceAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME, "rum"); - // WHEN when(); - liveSyncDir(); - // THEN then(); - displayDumpable("dir after", getDummyResourceDir()); assertUserAfter(USER_JACK_OID) @@ -207,11 +199,9 @@ public void test130JackUnassignRolePirates() throws Exception { Task task = getTestTask(); OperationResult result = task.getResult(); - // WHEN when(); unassignRole(USER_JACK_OID, rolePiratesOid, task, result); - // THEN then(); assertSuccess(result); @@ -234,11 +224,9 @@ public void test140JackAssignRolePirates() throws Exception { Task task = getTestTask(); OperationResult result = task.getResult(); - // WHEN when(); assignRole(USER_JACK_OID, rolePiratesOid, task, result); - // THEN then(); assertSuccess(result); @@ -268,11 +256,9 @@ public void test142JackUnAssignDirAccount() throws Exception { Task task = getTestTask(); OperationResult result = task.getResult(); - // WHEN when(); unassignAccount(UserType.class, USER_JACK_OID, RESOURCE_DUMMY_DIR_OID, null, task, result); - // THEN then(); assertSuccess(result); @@ -301,11 +287,9 @@ public void test149JackUnassignRolePirates() throws Exception { Task task = getTestTask(); OperationResult result = task.getResult(); - // WHEN when(); unassignRole(USER_JACK_OID, rolePiratesOid, task, result); - // THEN then(); assertSuccess(result); @@ -326,11 +310,9 @@ public void test150AssignJackDirAccount() throws Exception { Task task = getTestTask(); OperationResult result = task.getResult(); - // WHEN when(); assignAccount(UserType.class, USER_JACK_OID, RESOURCE_DUMMY_DIR_OID, null, task, result); - // THEN then(); assertSuccess(result); @@ -352,11 +334,9 @@ public void test152JackAssignRolePirates() throws Exception { Task task = getTestTask(); OperationResult result = task.getResult(); - // WHEN when(); assignRole(USER_JACK_OID, rolePiratesOid, task, result); - // THEN then(); assertSuccess(result); @@ -391,11 +371,9 @@ public void test153JackUnassignRolePiratesPreview() throws Exception { rolePiratesOid, RoleType.COMPLEX_TYPE, null, null, false); - // WHEN when(); ModelContext previewContext = previewChanges(focusDelta, null, task, result); - // THEN then(); assertSuccess(result); @@ -431,11 +409,9 @@ public void test154JackUnassignRolePirates() throws Exception { Task task = getTestTask(); OperationResult result = task.getResult(); - // WHEN when(); unassignRole(USER_JACK_OID, rolePiratesOid, task, result); - // THEN then(); assertSuccess(result); @@ -461,11 +437,9 @@ public void test159JackUnassignDirAccount() throws Exception { Task task = getTestTask(); OperationResult result = task.getResult(); - // WHEN when(); unassignAccount(UserType.class, USER_JACK_OID, RESOURCE_DUMMY_DIR_OID, null, task, result); - // THEN then(); assertSuccess(result); @@ -489,11 +463,9 @@ public void test200MancombAssignAccount() throws Exception { Task task = getTestTask(); OperationResult result = task.getResult(); - // WHEN when(); assignAccountToUser(USER_MANCOMB_OID, RESOURCE_DUMMY_DIR_OID, "default", task, result); - // THEN then(); assertSuccess(result); @@ -517,5 +489,4 @@ private void liveSyncDir() throws CommonException { private DummyResource getDummyResourceDir() { return getDummyResource(RESOURCE_DUMMY_DIR_NAME); } - } From 75807c7a9c788db45357384fa5e6a8e4440d7dc1 Mon Sep 17 00:00:00 2001 From: lskublik Date: Fri, 18 Sep 2020 10:05:04 +0200 Subject: [PATCH 7/9] fix for cluster authentication (MID-6503) --- .../module/AuthModuleRegistryImpl.java | 12 ++++++ .../module/HttpClusterModuleFactory.java | 2 +- .../HttpClusterAuthenticationFilter.java | 12 +++++- .../security/filter/MidpointAuthFilter.java | 35 +++++++++--------- .../security/provider/ClusterProvider.java | 8 ++-- ...idPointAbstractAuthenticationProvider.java | 8 +++- .../web/security/util/SecurityUtils.java | 37 +++++++++++++------ .../schema/util/SecurityPolicyUtil.java | 1 - 8 files changed, 77 insertions(+), 38 deletions(-) diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/security/factory/module/AuthModuleRegistryImpl.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/security/factory/module/AuthModuleRegistryImpl.java index f7210bebdf5..d7411297726 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/security/factory/module/AuthModuleRegistryImpl.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/security/factory/module/AuthModuleRegistryImpl.java @@ -65,4 +65,16 @@ public AbstractModuleFactory findModelFactory(AbstractAuthenticationModuleType c return factory; } + public T findModelFactoryByClass(Class clazz) { + + Optional opt = (Optional) moduleFactories.stream().filter(f -> f.getClass().equals(clazz)).findFirst(); + if (!opt.isPresent()) { + LOGGER.trace("No factory found for class {}", clazz); + return null; + } + T factory = opt.get(); + LOGGER.trace("Found component factory {} for class {}", factory, clazz); + return factory; + } + } diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/security/factory/module/HttpClusterModuleFactory.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/security/factory/module/HttpClusterModuleFactory.java index c3a8d2c8c71..852a940d3ff 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/security/factory/module/HttpClusterModuleFactory.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/security/factory/module/HttpClusterModuleFactory.java @@ -66,7 +66,7 @@ private ModuleWebSecurityConfig createModule(ModuleWebSecurityConfiguration conf } private AuthenticationProvider createProvider() { - return new ClusterProvider(); + return getObjectObjectPostProcessor().postProcess(new ClusterProvider()); } private ModuleAuthentication createEmptyModuleAuthentication(AbstractAuthenticationModuleType moduleType, ModuleWebSecurityConfiguration configuration) { diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/security/filter/HttpClusterAuthenticationFilter.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/security/filter/HttpClusterAuthenticationFilter.java index b1b235f4215..90801db960c 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/security/filter/HttpClusterAuthenticationFilter.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/security/filter/HttpClusterAuthenticationFilter.java @@ -7,6 +7,8 @@ package com.evolveum.midpoint.web.security.filter; import com.evolveum.midpoint.model.api.authentication.AuthenticationModuleNameConstants; +import com.evolveum.midpoint.model.api.authentication.MidpointAuthentication; +import com.evolveum.midpoint.model.api.authentication.ModuleAuthentication; import com.evolveum.midpoint.util.logging.Trace; import com.evolveum.midpoint.util.logging.TraceManager; import com.evolveum.midpoint.web.security.BasicMidPointAuthenticationSuccessHandler; @@ -15,6 +17,7 @@ import org.springframework.security.authentication.*; import org.springframework.security.core.Authentication; import org.springframework.security.core.AuthenticationException; +import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.web.AuthenticationEntryPoint; import org.springframework.security.web.authentication.AuthenticationSuccessHandler; import org.springframework.security.web.authentication.NullRememberMeServices; @@ -28,6 +31,7 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.Base64; +import java.util.List; /** * @author skublik @@ -89,7 +93,13 @@ protected void doFilterInternal(HttpServletRequest request, this.rememberMeServices.loginFail(request, response); - this.getAuthenticationEntryPoint().commence(request, response, failed); + StringBuilder sb = new StringBuilder(); + sb.append(AuthenticationModuleNameConstants.CLUSTER).append(" realm=\"midpoint\""); + response.setHeader("WWW-Authenticate",sb.toString()); + response.sendError(HttpServletResponse.SC_UNAUTHORIZED); + response.getWriter().write(" test error "); + response.getWriter().flush(); + response.getWriter().close(); return; } diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/security/filter/MidpointAuthFilter.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/security/filter/MidpointAuthFilter.java index bfe4dc37bf2..ce49978705c 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/security/filter/MidpointAuthFilter.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/security/filter/MidpointAuthFilter.java @@ -150,13 +150,20 @@ private void doFilterInternal(ServletRequest request, ServletResponse response, throw new AuthenticationServiceException("Couldn't find filters for sequence " + sequence.getName()); } - int indexOfProcessingModule = getIndexOfActualProcessingModule(mpAuthentication, httpRequest); + int indexOfProcessingModule; resolveErrorWithMoreModules(mpAuthentication, httpRequest); - if (needRestartAuthFlow(indexOfProcessingModule)) { - indexOfProcessingModule = restartAuthFlow(mpAuthentication, httpRequest, sequence, authModules); + if (SecurityUtils.isSpecificSequence(httpRequest)){ + indexOfProcessingModule = 0; + createMpAuthentication(httpRequest, sequence, authModules); mpAuthentication = (MidpointAuthentication) SecurityContextHolder.getContext().getAuthentication(); + } else { + indexOfProcessingModule = getIndexOfActualProcessingModule(mpAuthentication, httpRequest); + if (needRestartAuthFlow(indexOfProcessingModule)) { + indexOfProcessingModule = restartAuthFlow(httpRequest, sequence, authModules); + mpAuthentication = (MidpointAuthentication) SecurityContextHolder.getContext().getAuthentication(); + } } if (mpAuthentication.getAuthenticationChannel() == null) { @@ -172,14 +179,19 @@ private boolean needRestartAuthFlow(int indexOfProcessingModule) { return indexOfProcessingModule == -1; } - private int restartAuthFlow(MidpointAuthentication mpAuthentication, HttpServletRequest httpRequest, AuthenticationSequenceType sequence, List authModules) { + private int restartAuthFlow(HttpServletRequest httpRequest, AuthenticationSequenceType sequence, List authModules) { + createMpAuthentication(httpRequest,sequence,authModules); + MidpointAuthentication mpAuthentication = (MidpointAuthentication) SecurityContextHolder.getContext().getAuthentication(); + return mpAuthentication.resolveParallelModules(httpRequest, 0); + } + + private void createMpAuthentication(HttpServletRequest httpRequest, AuthenticationSequenceType sequence, List authModules) { SecurityContextHolder.getContext().setAuthentication(null); SecurityContextHolder.getContext().setAuthentication(new MidpointAuthentication(sequence)); - mpAuthentication = (MidpointAuthentication) SecurityContextHolder.getContext().getAuthentication(); + MidpointAuthentication mpAuthentication = (MidpointAuthentication) SecurityContextHolder.getContext().getAuthentication(); mpAuthentication.setAuthModules(authModules); mpAuthentication.setSessionId(httpRequest.getSession(false) != null ? httpRequest.getSession(false).getId() : RandomStringUtils.random(30, true, true).toUpperCase()); mpAuthentication.addAuthentications(authModules.get(0).getBaseModuleAuthentication()); - return mpAuthentication.resolveParallelModules(httpRequest, 0); } private void resolveErrorWithMoreModules(MidpointAuthentication mpAuthentication, HttpServletRequest httpRequest) { @@ -322,16 +334,5 @@ public void doFilter(ServletRequest request, ServletResponse response) } } } - - public interface FilterChainValidator { - void validate(MidpointAuthFilter filterChainProxy); - } - - private static class NullFilterChainValidator implements MidpointAuthFilter.FilterChainValidator { - @Override - public void validate(MidpointAuthFilter filterChainProxy) { - } - } - } diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/security/provider/ClusterProvider.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/security/provider/ClusterProvider.java index b0977bd0d7c..4ce67a48187 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/security/provider/ClusterProvider.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/security/provider/ClusterProvider.java @@ -55,7 +55,7 @@ protected Authentication internalAuthentication(Authentication authentication, L Authentication token; if (authentication instanceof ClusterAuthenticationToken) { String enteredPassword = (String) authentication.getCredentials(); - if (!nodeAuthenticator.authenticate(null, enteredUsername, enteredPassword, "?")) { + if (!nodeAuthenticator.authenticate(null, enteredUsername, enteredPassword, "node authentication")) { throw new AuthenticationServiceException("web.security.flexAuth.cluster.auth.null"); } else { token = SecurityContextHolder.getContext().getAuthentication(); @@ -65,10 +65,8 @@ protected Authentication internalAuthentication(Authentication authentication, L throw new AuthenticationServiceException("web.security.provider.unavailable"); } - MidPointPrincipal principal = (MidPointPrincipal)token.getPrincipal(); - - LOGGER.debug("User '{}' authenticated ({}), authorities: {}", authentication.getPrincipal(), - authentication.getClass().getSimpleName(), principal.getAuthorities()); + LOGGER.debug("Node '{}' authenticated}", authentication.getPrincipal()); + token.setAuthenticated(true); return token; } catch (AuthenticationException e) { diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/security/provider/MidPointAbstractAuthenticationProvider.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/security/provider/MidPointAbstractAuthenticationProvider.java index eb3b140fc0f..4be9238bf02 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/security/provider/MidPointAbstractAuthenticationProvider.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/security/provider/MidPointAbstractAuthenticationProvider.java @@ -94,8 +94,12 @@ public Authentication authenticate(Authentication originalAuthentication) throws if (actualAuthentication instanceof MidpointAuthentication) { MidpointAuthentication mpAuthentication = (MidpointAuthentication) actualAuthentication; ModuleAuthentication moduleAuthentication = getProcessingModule(mpAuthentication); - MidPointPrincipal principal = (MidPointPrincipal) token.getPrincipal(); - token = createNewAuthenticationToken(token, mpAuthentication.getAuthenticationChannel().resolveAuthorities(principal.getAuthorities())); + if (token.getPrincipal() instanceof MidPointPrincipal) { + MidPointPrincipal principal = (MidPointPrincipal) token.getPrincipal(); + token = createNewAuthenticationToken(token, mpAuthentication.getAuthenticationChannel().resolveAuthorities(principal.getAuthorities())); + } else { + token = createNewAuthenticationToken(token, token.getAuthorities()); + } writeAutentication(processingAuthentication, mpAuthentication, moduleAuthentication, token); return mpAuthentication; diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/security/util/SecurityUtils.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/security/util/SecurityUtils.java index 9752ea02efa..60fec45ccfc 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/security/util/SecurityUtils.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/security/util/SecurityUtils.java @@ -198,9 +198,8 @@ public static AuthenticationSequenceType getSequenceByPath(HttpServletRequest ht } String[] partsOfLocalPath = stripStartingSlashes(localePath).split("/"); - AuthenticationSequenceType specificSequence = getSpecificSequence(httpRequest); - if (specificSequence != null) { - return specificSequence; + if (isSpecificSequence(httpRequest)) { + return getSpecificSequence(httpRequest); } List sequences = getSequencesForNodeGroups(nodeGroups, authenticationPolicy); @@ -319,6 +318,8 @@ private static AuthenticationSequenceType getSpecificSequence(HttpServletRequest sequence.setName(AuthenticationModuleNameConstants.CLUSTER); AuthenticationSequenceChannelType seqChannel = new AuthenticationSequenceChannelType(); seqChannel.setUrlSuffix(AuthenticationModuleNameConstants.CLUSTER.toLowerCase()); + seqChannel.setChannelId(SchemaConstants.CHANNEL_REST_URI); + sequence.setChannel(seqChannel); return sequence; } } @@ -326,6 +327,21 @@ private static AuthenticationSequenceType getSpecificSequence(HttpServletRequest return null; } + public static boolean isSpecificSequence(HttpServletRequest httpRequest) { + String localePath = httpRequest.getRequestURI().substring(httpRequest.getContextPath().length()); + String channel = searchChannelByPath(localePath); + if (SchemaConstants.CHANNEL_REST_URI.equals(channel)) { + String header = httpRequest.getHeader("Authorization"); + if (header != null) { + String type = header.split(" ")[0]; + if (AuthenticationModuleNameConstants.CLUSTER.toLowerCase().equals(type.toLowerCase())) { + return true; + } + } + } + return false; + } + private static AuthenticationSequenceType searchSequence(String comparisonAttribute, boolean inputIsChannel, List sequences) { Validate.notBlank(comparisonAttribute, "Comparison attribute for searching of sequence is blank"); for (AuthenticationSequenceType sequence : sequences) { @@ -372,14 +388,14 @@ public static List buildModuleFilters(AuthModuleRegistryImpl authReg CredentialsPolicyType credentialPolicy, Map, Object> sharedObjects, AuthenticationChannel authenticationChannel) { Validate.notNull(authRegistry, "Registry for module factories is null"); - Validate.notEmpty(sequence.getModule(), "Sequence " + sequence.getName() + " don't contains authentication modules"); - List specificModules = getSpecificModuleFilter(sequence.getChannel().getUrlSuffix(), request, - sharedObjects, authenticationModulesType, credentialPolicy); - if (specificModules != null) { - return specificModules; + if (isSpecificSequence(request)) { + return getSpecificModuleFilter(authRegistry, sequence.getChannel().getUrlSuffix(), request, + sharedObjects, authenticationModulesType, credentialPolicy); } + Validate.notEmpty(sequence.getModule(), "Sequence " + sequence.getName() + " don't contains authentication modules"); + List sequenceModules = SecurityPolicyUtil.getSortedModules(sequence); List authModules = new ArrayList<>(); sequenceModules.forEach(sequenceModule -> { @@ -399,7 +415,7 @@ public static List buildModuleFilters(AuthModuleRegistryImpl authReg return authModules; } - private static List getSpecificModuleFilter(String urlSuffix, HttpServletRequest httpRequest, Map, Object> sharedObjects, + private static List getSpecificModuleFilter(AuthModuleRegistryImpl authRegistry, String urlSuffix, HttpServletRequest httpRequest, Map, Object> sharedObjects, AuthenticationModulesType authenticationModulesType, CredentialsPolicyType credentialPolicy) { String localePath = httpRequest.getRequestURI().substring(httpRequest.getContextPath().length()); String channel = searchChannelByPath(localePath); @@ -409,8 +425,7 @@ private static List getSpecificModuleFilter(String urlSuffix, HttpSe String type = header.split(" ")[0]; if (AuthenticationModuleNameConstants.CLUSTER.toLowerCase().equals(type.toLowerCase())) { List authModules = new ArrayList<>(); - WebApplicationContext context = ContextLoader.getCurrentWebApplicationContext(); - HttpClusterModuleFactory factory = context.getBean(HttpClusterModuleFactory.class); + HttpClusterModuleFactory factory = authRegistry.findModelFactoryByClass(HttpClusterModuleFactory.class); AbstractAuthenticationModuleType module = new AbstractAuthenticationModuleType() { }; module.setName(AuthenticationModuleNameConstants.CLUSTER.toLowerCase() + "-module"); diff --git a/infra/schema/src/main/java/com/evolveum/midpoint/schema/util/SecurityPolicyUtil.java b/infra/schema/src/main/java/com/evolveum/midpoint/schema/util/SecurityPolicyUtil.java index 92e09676408..2f25cd0608f 100644 --- a/infra/schema/src/main/java/com/evolveum/midpoint/schema/util/SecurityPolicyUtil.java +++ b/infra/schema/src/main/java/com/evolveum/midpoint/schema/util/SecurityPolicyUtil.java @@ -142,7 +142,6 @@ public static List getSortedModules(Authentica Validate.notNull(sequence); ArrayList modules = new ArrayList<>(sequence.getModule()); Validate.notNull(modules); - Validate.notEmpty(modules); Comparator comparator = (f1, f2) -> { Integer f1Order = f1.getOrder(); From 560015556b1fd0fca884a3264b3a06845f845234 Mon Sep 17 00:00:00 2001 From: Richard Richter Date: Fri, 18 Sep 2020 10:42:15 +0200 Subject: [PATCH 8/9] MID-6239 fix: generated HQL LIKE uses escape character for _ and % --- .../repo/sql/QueryInterpreterTest.java | 1324 ++++++++--------- .../sql/query/hqm/RootHibernateQuery.java | 25 +- .../condition/SimpleComparisonCondition.java | 8 +- 3 files changed, 611 insertions(+), 746 deletions(-) diff --git a/repo/repo-sql-impl-test/src/test/java/com/evolveum/midpoint/repo/sql/QueryInterpreterTest.java b/repo/repo-sql-impl-test/src/test/java/com/evolveum/midpoint/repo/sql/QueryInterpreterTest.java index 5a77700492a..1a5d81c5e08 100644 --- a/repo/repo-sql-impl-test/src/test/java/com/evolveum/midpoint/repo/sql/QueryInterpreterTest.java +++ b/repo/repo-sql-impl-test/src/test/java/com/evolveum/midpoint/repo/sql/QueryInterpreterTest.java @@ -38,7 +38,6 @@ import javax.xml.datatype.XMLGregorianCalendar; import javax.xml.namespace.QName; -import org.apache.commons.lang.StringUtils; import org.assertj.core.api.Assertions; import org.hibernate.Session; import org.jetbrains.annotations.NotNull; @@ -146,15 +145,13 @@ public void test001QueryNameNorm() throws Exception { ObjectQuery query = prismContext.queryFor(UserType.class) .item(F_NAME).eqPoly("asdf", "asdf").matchingNorm().build(); - String expected = "select\n" + - " u.oid, u.fullObject\n" + - "from\n" + - " RUser u\n" + - "where\n" + - " u.nameCopy.norm = :norm"; - String real = getInterpretedQuery(session, UserType.class, query); - assertEqualsIgnoreWhitespace(expected, real); + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + + " u.oid, u.fullObject\n" + + "from\n" + + " RUser u\n" + + "where\n" + + " u.nameCopy.norm = :norm"); } finally { close(session); } @@ -171,15 +168,13 @@ public void test002QueryNameOrig() throws Exception { ObjectQuery query = prismContext.queryFor(UserType.class) .item(F_NAME).eqPoly("asdf", "asdf").matchingOrig().build(); - String expected = "select\n" + - " u.oid, u.fullObject\n" + - "from\n" + - " RUser u\n" + - "where\n" + - " u.nameCopy.orig = :orig"; - String real = getInterpretedQuery(session, UserType.class, query); - assertEqualsIgnoreWhitespace(expected, real); + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + + " u.oid, u.fullObject\n" + + "from\n" + + " RUser u\n" + + "where\n" + + " u.nameCopy.orig = :orig"); } finally { close(session); } @@ -196,15 +191,13 @@ public void test003QueryNameStrict() throws Exception { ObjectQuery query = prismContext.queryFor(UserType.class) .item(F_NAME).eqPoly("asdf", "asdf").build(); - String expected = "select\n" + - " u.oid, u.fullObject\n" + - "from\n" + - " RUser u\n" + - "where\n" + - " ( u.nameCopy.orig = :orig and u.nameCopy.norm = :norm )"; - String real = getInterpretedQuery(session, UserType.class, query); - assertEqualsIgnoreWhitespace(expected, real); + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + + " u.oid, u.fullObject\n" + + "from\n" + + " RUser u\n" + + "where\n" + + " ( u.nameCopy.orig = :orig and u.nameCopy.norm = :norm )"); } finally { close(session); } @@ -221,17 +214,15 @@ public void test005QueryOrganizationNorm() throws Exception { ObjectQuery query = prismContext.queryFor(UserType.class) .item(UserType.F_ORGANIZATION).eqPoly("guľôčka v jamôčke").matchingNorm().build(); - String expected = "select\n" + - " u.oid, u.fullObject\n" + - "from\n" + - " RUser u\n" + - " left join u.organization o\n" + - "where\n" + - " o.norm = :norm"; - RQueryImpl rQuery = (RQueryImpl) getInterpretedQueryWhole(session, UserType.class, query, false, null); String real = rQuery.getQuery().getQueryString(); - assertEqualsIgnoreWhitespace(expected, real); + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + + " u.oid, u.fullObject\n" + + "from\n" + + " RUser u\n" + + " left join u.organization o\n" + + "where\n" + + " o.norm = :norm"); assertEquals("Wrong parameter value", "gulocka v jamocke", rQuery.getQuerySource().getParameters().get("norm").getValue()); } finally { @@ -249,16 +240,14 @@ public void test006QueryOrganizationOrig() throws Exception { ObjectQuery query = prismContext.queryFor(UserType.class) .item(UserType.F_ORGANIZATION).eqPoly("asdf", "asdf").matchingOrig().build(); - String expected = "select\n" + - " u.oid, u.fullObject\n" + - "from\n" + - " RUser u\n" + - " left join u.organization o\n" + - "where\n" + - " o.orig = :orig"; - String real = getInterpretedQuery(session, UserType.class, query); - assertEqualsIgnoreWhitespace(expected, real); + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + + " u.oid, u.fullObject\n" + + "from\n" + + " RUser u\n" + + " left join u.organization o\n" + + "where\n" + + " o.orig = :orig"); } finally { close(session); } @@ -274,16 +263,14 @@ public void test007QueryOrganizationStrict() throws Exception { ObjectQuery query = prismContext.queryFor(UserType.class) .item(UserType.F_ORGANIZATION).eqPoly("asdf", "asdf").matchingStrict().build(); - String expected = "select\n" + - " u.oid, u.fullObject\n" + - "from\n" + - " RUser u\n" + - " left join u.organization o\n" + - "where\n" + - " ( o.orig = :orig and o.norm = :norm )"; - String real = getInterpretedQuery(session, UserType.class, query); - assertEqualsIgnoreWhitespace(expected, real); + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + + " u.oid, u.fullObject\n" + + "from\n" + + " RUser u\n" + + " left join u.organization o\n" + + "where\n" + + " ( o.orig = :orig and o.norm = :norm )"); } finally { close(session); } @@ -302,17 +289,15 @@ public void test010QueryTwoOrganizationsNormAnd() throws Exception { .and().item(UserType.F_ORGANIZATION).eqPoly("ghjk", "ghjk").matchingNorm() .build(); - String expected = "select\n" + - " u.oid, u.fullObject\n" + - "from\n" + - " RUser u\n" + - " left join u.organization o\n" + - " left join u.organization o2\n" + - "where\n" + - " ( o.norm = :norm and o2.norm = :norm2 )"; - String real = getInterpretedQuery(session, UserType.class, query); - assertEqualsIgnoreWhitespace(expected, real); + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + + " u.oid, u.fullObject\n" + + "from\n" + + " RUser u\n" + + " left join u.organization o\n" + + " left join u.organization o2\n" + + "where\n" + + " ( o.norm = :norm and o2.norm = :norm2 )"); } finally { close(session); } @@ -331,21 +316,19 @@ public void test011QueryTwoOrganizationsStrictOr() throws Exception { .or().item(UserType.F_ORGANIZATION).eqPoly("ghjk", "ghjk") .build(); - String expected = "select\n" + - " u.oid, u.fullObject\n" + - "from\n" + - " RUser u\n" + - " left join u.organization o\n" + - " left join u.organization o2\n" + - "where\n" + - " ( ( o.orig = :orig and o.norm = :norm ) or\n" + - " ( o2.orig = :orig2 and o2.norm = :norm2 ) )"; + String real = getInterpretedQuery(session, UserType.class, query); // NOTE: this could be implemented more efficiently by using only one join... or the query itself can be formulated // via In filter (when available) or Exists filter (also, when available) - - String real = getInterpretedQuery(session, UserType.class, query); - assertEqualsIgnoreWhitespace(expected, real); + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + + " u.oid, u.fullObject\n" + + "from\n" + + " RUser u\n" + + " left join u.organization o\n" + + " left join u.organization o2\n" + + "where\n" + + " ( ( o.orig = :orig and o.norm = :norm ) or\n" + + " ( o2.orig = :orig2 and o2.norm = :norm2 ) )"); } finally { close(session); } @@ -361,16 +344,15 @@ public void test012QueryOrganizationOrigPolymorphic() throws Exception { ObjectQuery query = prismContext.queryFor(UserType.class) .item(UserType.F_ORGANIZATION).eqPoly("asdf", "asdf").matchingOrig() .build(); - String expected = "select\n" + - " o.oid, o.fullObject\n" + - "from\n" + - " RObject o\n" + - " left join o.organization o2\n" + - "where\n" + - " o2.orig = :orig"; String real = getInterpretedQuery(session, ObjectType.class, query); - assertEqualsIgnoreWhitespace(expected, real); + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + + " o.oid, o.fullObject\n" + + "from\n" + + " RObject o\n" + + " left join o.organization o2\n" + + "where\n" + + " o2.orig = :orig"); } finally { close(session); } @@ -388,16 +370,14 @@ public void test013QueryTaskDependent() throws Exception { .item(TaskType.F_DEPENDENT).eq("123456") .build(); - String expected = "select\n" + - " t.oid, t.fullObject\n" + - "from\n" + - " RTask t\n" + - " left join t.dependent d\n" + - "where\n" + - " d = :d"; - String real = getInterpretedQuery(session, TaskType.class, query); - assertEqualsIgnoreWhitespace(expected, real); + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + + " t.oid, t.fullObject\n" + + "from\n" + + " RTask t\n" + + " left join t.dependent d\n" + + "where\n" + + " d = :d"); } finally { close(session); } @@ -431,14 +411,12 @@ public void test015QueryEnum() throws Exception { .build(); String real = getInterpretedQuery(session, TaskType.class, query); - String expected = "select\n" + - " t.oid, t.fullObject\n" + - "from\n" + - " RTask t\n" + - "where\n" + - " t.executionStatus = :executionStatus\n"; - - assertEqualsIgnoreWhitespace(expected, real); + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + + " t.oid, t.fullObject\n" + + "from\n" + + " RTask t\n" + + "where\n" + + " t.executionStatus = :executionStatus\n"); } finally { close(session); } @@ -456,14 +434,12 @@ public void test016QueryEnabled() throws Exception { String real = getInterpretedQuery(session, UserType.class, new File(TEST_DIR, "query-user-by-enabled.xml")); - String expected = "select\n" + - " u.oid, u.fullObject\n" + - "from\n" + - " RUser u\n" + - "where\n" + - " u.activation.administrativeStatus = :administrativeStatus\n"; - - assertEqualsIgnoreWhitespace(expected, real); + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + + " u.oid, u.fullObject\n" + + "from\n" + + " RUser u\n" + + "where\n" + + " u.activation.administrativeStatus = :administrativeStatus\n"); } finally { close(session); } @@ -487,17 +463,17 @@ public void test017QueryGenericLong() throws Exception { getQuery(new File(TEST_DIR, "query-and-generic.xml"), GenericObjectType.class), false, null); String real = realQuery.getQuery().getQueryString(); - String expected = "select\n" + - " g.oid, g.fullObject\n" + - "from\n" + - " RGenericObject g\n" + - " left join g.longs l with ( l.ownerType = :ownerType and l.itemId = :itemId )\n" + - "where\n" + - " ( g.nameCopy.norm = :norm and l.value = :value )\n"; - - assertEqualsIgnoreWhitespace(expected, real); + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + + " g.oid, g.fullObject\n" + + "from\n" + + " RGenericObject g\n" + + " left join g.longs l with ( l.ownerType = :ownerType and l.itemId = :itemId )\n" + + "where\n" + + " ( g.nameCopy.norm = :norm and l.value = :value )\n"); - assertEquals("Wrong property ID for 'intType'", intTypeDefinition.getId(), realQuery.getQuerySource().getParameters().get("itemId").getValue()); + assertEquals("Wrong property ID for 'intType'", + intTypeDefinition.getId(), + realQuery.getQuerySource().getParameters().get("itemId").getValue()); } finally { close(session); } @@ -518,22 +494,20 @@ public void test018QueryGenericLongTwice() throws Exception { RootHibernateQuery source = ((RQueryImpl) realQuery).getQuerySource(); String real = ((RQueryImpl) realQuery).getQuery().getQueryString(); - String expected = "select\n" + - " g.oid, g.fullObject\n" + - "from\n" + - " RGenericObject g\n" + - " left join g.longs l with ( l.ownerType = :ownerType and l.itemId = :itemId )\n" + - " left join g.longs l2 with ( l2.ownerType = :ownerType2 and l2.itemId = :itemId2 )\n" + - "where\n" + - " (\n" + - " g.nameCopy.norm = :norm and\n" + - " l.value >= :value and\n" + - " l.value < :value2 and\n" + - " l2.value = :value3\n" + - " )"; - // note l and l2 cannot be merged as they point to different extension properties (intType, longType) - assertEqualsIgnoreWhitespace(expected, real); + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + + " g.oid, g.fullObject\n" + + "from\n" + + " RGenericObject g\n" + + " left join g.longs l with ( l.ownerType = :ownerType and l.itemId = :itemId )\n" + + " left join g.longs l2 with ( l2.ownerType = :ownerType2 and l2.itemId = :itemId2 )\n" + + "where\n" + + " (\n" + + " g.nameCopy.norm = :norm and\n" + + " l.value >= :value and\n" + + " l.value < :value2 and\n" + + " l2.value = :value3\n" + + " )"); assertEquals("Wrong property ID for 'intType'", intTypeDefinition.getId(), source.getParameters().get("itemId").getValue()); assertEquals("Wrong property ID for 'longType'", longTypeDefinition.getId(), source.getParameters().get("itemId2").getValue()); @@ -548,14 +522,13 @@ public void test019QueryAccountByNonExistingAttribute() throws Exception { try { String real = getInterpretedQuery(session, ShadowType.class, new File(TEST_DIR, "query-account-by-non-existing-attribute.xml")); - String expected = "select\n" + - " s.oid, s.fullObject\n" + - "from\n" + - " RShadow s\n" + - " left join s.strings s2 with ( s2.ownerType = :ownerType and 1=0 )\n" + - "where\n" + - " s2.value = :value\n"; - assertEqualsIgnoreWhitespace(expected, real); + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + + " s.oid, s.fullObject\n" + + "from\n" + + " RShadow s\n" + + " left join s.strings s2 with ( s2.ownerType = :ownerType and 1=0 )\n" + + "where\n" + + " s2.value = :value\n"); } finally { close(session); } @@ -567,14 +540,14 @@ public void test030QueryAccountByAttribute() throws Exception { try { String real = getInterpretedQuery(session, ShadowType.class, new File(TEST_DIR, "query-account-by-attribute.xml")); - String expected = "select\n" + - " s.oid, s.fullObject\n" + - "from\n" + - " RShadow s\n" + - " left join s.strings s2 with ( s2.ownerType = :ownerType and s2.itemId = :itemId )\n" + - "where\n" + - " s2.value = :value\n"; - assertEqualsIgnoreWhitespace(expected, real); + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + + " s.oid, s.fullObject\n" + + "from\n" + + " RShadow s\n" + + " left join s.strings s2 with ( s2.ownerType = :ownerType and s2.itemId = :itemId )\n" + + "where\n" + + " s2.value = :value\n"); } finally { close(session); } @@ -587,18 +560,19 @@ public void test031QueryAccountByAttributeAndExtensionValue() throws Exception { RQueryImpl realQuery = (RQueryImpl) getInterpretedQueryWhole(session, ShadowType.class, getQuery(new File(TEST_DIR, "query-account-by-attribute-and-extension-value.xml"), ShadowType.class), false, null); - String expected = "select\n" + - " s.oid, s.fullObject\n" + - "from\n" + - " RShadow s\n" + - " left join s.strings s2 with ( s2.ownerType = :ownerType and s2.itemId = :itemId )\n" + - " left join s.longs l with ( l.ownerType = :ownerType2 and l.itemId = :itemId2 )\n" + - "where\n" + - " (\n" + - " s2.value = :value and\n" + - " l.value = :value2\n" + - " )"; - assertEqualsIgnoreWhitespace(expected, realQuery.getQuery().getQueryString()); + + Assertions.assertThat(realQuery.getQuery().getQueryString()) + .isEqualToIgnoringWhitespace("select\n" + + " s.oid, s.fullObject\n" + + "from\n" + + " RShadow s\n" + + " left join s.strings s2 with ( s2.ownerType = :ownerType and s2.itemId = :itemId )\n" + + " left join s.longs l with ( l.ownerType = :ownerType2 and l.itemId = :itemId2 )\n" + + "where\n" + + " (\n" + + " s2.value = :value and\n" + + " l.value = :value2\n" + + " )"); assertEquals("Wrong property ID for 'a1'", a1Definition.getId(), realQuery.getQuerySource().getParameters().get("itemId").getValue()); assertEquals("Wrong property ID for 'shoeSize'", shoeSizeDefinition.getId(), realQuery.getQuerySource().getParameters().get("itemId2").getValue()); @@ -630,23 +604,6 @@ public void test033QueryOrComposite() throws Exception { RQueryImpl realQuery = (RQueryImpl) getInterpretedQueryWhole(session, ShadowType.class, getQuery(new File(TEST_DIR, "query-or-composite.xml"), ShadowType.class), false, null); - String expected = "select\n" + - " s.oid, s.fullObject\n" + - "from\n" + - " RShadow s\n" + - " left join s.strings s2 with ( s2.ownerType = :ownerType and s2.itemId = :itemId )\n" + - " left join s.strings s3 with ( s3.ownerType = :ownerType2 and s3.itemId = :itemId2 )\n" + - "where\n" + - " (\n" + - " s.intent = :intent or\n" + - " s2.value = :value or\n" + - " s3.value = :value2 or\n" + - " (\n" + - " s.resourceRef.targetOid = :targetOid and\n" + - " s.resourceRef.relation in (:relation)\n" + - " )\n" + - " )\n"; - /* ownerType = ATTRIBUTES (com.evolveum.midpoint.repo.sql.data.common.type.RObjectExtensionType.ATTRIBUTES) name = http://midpoint.evolveum.com/blabla#foo @@ -659,7 +616,23 @@ public void test033QueryOrComposite() throws Exception { relation = ... type = com.evolveum.midpoint.repo.sql.data.common.other.RObjectType.RESOURCE */ - assertEqualsIgnoreWhitespace(expected, realQuery.getQuery().getQueryString()); + Assertions.assertThat(realQuery.getQuery().getQueryString()) + .isEqualToIgnoringWhitespace("select\n" + + " s.oid, s.fullObject\n" + + "from\n" + + " RShadow s\n" + + " left join s.strings s2 with ( s2.ownerType = :ownerType and s2.itemId = :itemId )\n" + + " left join s.strings s3 with ( s3.ownerType = :ownerType2 and s3.itemId = :itemId2 )\n" + + "where\n" + + " (\n" + + " s.intent = :intent or\n" + + " s2.value = :value or\n" + + " s3.value = :value2 or\n" + + " (\n" + + " s.resourceRef.targetOid = :targetOid and\n" + + " s.resourceRef.relation in (:relation)\n" + + " )\n" + + " )\n"); assertEquals("Wrong property ID for 'foo'", fooDefinition.getId(), realQuery.getQuerySource().getParameters().get("itemId").getValue()); assertEquals("Wrong property ID for 'stringType'", stringTypeDefinition.getId(), realQuery.getQuerySource().getParameters().get("itemId2").getValue()); @@ -685,15 +658,14 @@ public void test040QueryExistsAssignment() throws Exception { .build(); String real = getInterpretedQuery(session, UserType.class, query); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid, u.fullObject\n" + "from\n" + " RUser u\n" + " left join u.assignments a with a.assignmentOwner = :assignmentOwner\n" + "where\n" + " a.activation.administrativeStatus = :administrativeStatus\n" + - "order by u.nameCopy.orig asc\n"; - assertEqualsIgnoreWhitespace(expected, real); + "order by u.nameCopy.orig asc\n"); } finally { close(session); } @@ -714,15 +686,14 @@ public void test041QueryExistsAssignmentWithRedundantBlock() throws Exception { .build(); String real = getInterpretedQuery(session, UserType.class, query); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid, u.fullObject\n" + "from\n" + " RUser u\n" + " left join u.assignments a with a.assignmentOwner = :assignmentOwner\n" + "where\n" + " a.activation.administrativeStatus = :administrativeStatus\n" + - "order by u.nameCopy.orig asc\n"; - assertEqualsIgnoreWhitespace(expected, real); + "order by u.nameCopy.orig asc\n"); } finally { close(session); } @@ -745,15 +716,14 @@ public void test042QueryExistsAssignmentWithRedundantBlock2() throws Exception { .build(); String real = getInterpretedQuery(session, UserType.class, query); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid, u.fullObject\n" + "from\n" + " RUser u\n" + " left join u.assignments a with a.assignmentOwner = :assignmentOwner\n" + "where\n" + " a.activation.administrativeStatus = :administrativeStatus\n" + - "order by u.nameCopy.orig asc\n"; - assertEqualsIgnoreWhitespace(expected, real); + "order by u.nameCopy.orig asc\n"); } finally { close(session); } @@ -771,7 +741,7 @@ public void test044QueryExistsWithAnd() throws Exception { .build(); String real = getInterpretedQuery(session, ShadowType.class, query); - String expected = "select\n" + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " s.oid,\n" + " s.fullObject\n" + "from\n" @@ -783,8 +753,7 @@ public void test044QueryExistsWithAnd() throws Exception { + " s.resourceRef.relation in (:relation)\n" + " ) and\n" + " s.pendingOperationCount > :pendingOperationCount\n" - + " )"; - assertEqualsIgnoreWhitespace(expected, real); + + " )"); } finally { close(session); } @@ -804,13 +773,12 @@ public void test049QueryExistsAssignmentAll() throws Exception { String real = getInterpretedQuery(session, UserType.class, query); // this doesn't work as expected ... maybe inner join would be better! Until implemented, we should throw UOO - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid, u.fullObject\n" + "from\n" + " RUser u\n" + " left join u.assignments a with a.assignmentOwner = :assignmentOwner\n" + - "order by u.name.orig asc\n"; - assertEqualsIgnoreWhitespace(expected, real); + "order by u.name.orig asc\n"); } finally { close(session); } @@ -828,7 +796,7 @@ public void test050QuerySingleAssignmentWithTargetAndTenant() throws Exception { .build(); String real = getInterpretedQuery(session, UserType.class, query); - String expected = "select\n" + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid, u.fullObject\n" + "from\n" + " RUser u\n" @@ -843,8 +811,7 @@ public void test050QuerySingleAssignmentWithTargetAndTenant() throws Exception { + " u.tenantRef.targetOid = :targetOid2 and\n" + " u.tenantRef.relation in (:relation2)\n" + " )\n" - + " )\n"; - assertEqualsIgnoreWhitespace(expected, real); + + " )\n"); } finally { close(session); } @@ -861,7 +828,7 @@ public void test052QueryAssignmentsWithTargetAndTenant() throws Exception { .build(); String real = getInterpretedQuery(session, UserType.class, query); - String expected = "select\n" + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid, u.fullObject\n" + "from\n" + " RUser u\n" @@ -877,8 +844,7 @@ public void test052QueryAssignmentsWithTargetAndTenant() throws Exception { + " a2.tenantRef.targetOid = :targetOid2 and\n" + " a2.tenantRef.relation in (:relation2)\n" + " )\n" - + " )\n"; - assertEqualsIgnoreWhitespace(expected, real); + + " )\n"); } finally { close(session); } @@ -902,7 +868,7 @@ public void test060QueryObjectByName() throws Exception { .build(); String real = getInterpretedQuery(session, ObjectType.class, query); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " o.oid, o.fullObject\n" + "from\n" + " RObject o\n" + @@ -911,8 +877,7 @@ public void test060QueryObjectByName() throws Exception { " o.name.orig = :orig and\n" + " o.name.norm = :norm\n" + " )\n" + - "order by o.name.orig asc\n"; - assertEqualsIgnoreWhitespace(expected, real); + "order by o.name.orig asc\n"); } finally { close(session); } @@ -925,13 +890,12 @@ public void test061QueryUserByFullName() throws Exception { try { String real = getInterpretedQuery(session, UserType.class, new File(TEST_DIR, "query-user-by-fullName.xml")); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid, u.fullObject\n" + "from\n" + " RUser u\n" + "where\n" + - " u.fullName.norm = :norm\n"; - assertEqualsIgnoreWhitespace(expected, real); + " u.fullName.norm = :norm\n"); } finally { close(session); } @@ -944,13 +908,12 @@ public void test062QueryUserSubstringFullName() throws Exception { try { String real = getInterpretedQuery(session, UserType.class, new File(TEST_DIR, "query-user-substring-fullName.xml")); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid, u.fullObject\n" + "from\n" + " RUser u\n" + "where\n" + - " lower(u.fullName.norm) like :norm"; - assertEqualsIgnoreWhitespace(expected, real); + " lower(u.fullName.norm) like :norm escape '!'"); } finally { close(session); } @@ -963,13 +926,12 @@ public void test064QueryUserByName() throws Exception { try { String real = getInterpretedQuery(session, UserType.class, new File(TEST_DIR, "query-user-by-name.xml")); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid, u.fullObject\n" + "from\n" + " RUser u\n" + "where\n" + - " u.nameCopy.norm = :norm"; - assertEqualsIgnoreWhitespace(expected, real); + " u.nameCopy.norm = :norm"); } finally { close(session); } @@ -984,14 +946,13 @@ public void test066QuerySubstringMultivalued() throws Exception { .item(UserType.F_EMPLOYEE_TYPE).contains("abc") .build(); String real = getInterpretedQuery(session, ObjectType.class, query); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " o.oid, o.fullObject\n" + "from\n" + " RObject o\n" + " left join o.employeeType e\n" + "where\n" + - " e like :e\n"; - assertEqualsIgnoreWhitespace(expected, real); + " e like :e escape '!'\n"); } finally { close(session); } @@ -1004,13 +965,12 @@ public void test070QueryConnectorByType() throws Exception { try { String real = getInterpretedQuery(session, ConnectorType.class, new File(TEST_DIR, "query-connector-by-type.xml")); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " c.oid, c.fullObject\n" + "from\n" + " RConnector c\n" + "where\n" + - " c.connectorType = :connectorType\n"; - assertEqualsIgnoreWhitespace(expected, real); + " c.connectorType = :connectorType\n"); } finally { close(session); } @@ -1022,7 +982,8 @@ public void test071QueryAccountByAttributesAndResourceRef() throws Exception { try { String real = getInterpretedQuery(session, ShadowType.class, new File(TEST_DIR, "query-account-by-attributes-and-resource-ref.xml")); - String expected = "select\n" + + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " s.oid, s.fullObject\n" + "from\n" + " RShadow s\n" + @@ -1034,8 +995,7 @@ public void test071QueryAccountByAttributesAndResourceRef() throws Exception { " s.resourceRef.relation in (:relation)\n" + " ) and\n" + " s2.value = :value\n" + - " )\n"; - assertEqualsIgnoreWhitespace(expected, real); + " )\n"); } finally { close(session); } @@ -1057,7 +1017,7 @@ public void test073QueryUserAccountRef() throws Exception { String real = getInterpretedQuery(session, UserType.class, query); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid, u.fullObject\n" + "from\n" + " RUser u\n" + @@ -1066,8 +1026,7 @@ public void test073QueryUserAccountRef() throws Exception { " (\n" + " l.targetOid = :targetOid and\n" + " l.relation in (:relation)\n" + - " )\n"; - assertEqualsIgnoreWhitespace(expected, real); + " )\n"); } finally { close(session); } @@ -1081,14 +1040,13 @@ public void test074QueryUserAccountRefNull() throws Exception { .item(UserType.F_LINK_REF).isNull() .build(); String real = getInterpretedQuery(session, UserType.class, query); - String expected = "select\n" + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid, u.fullObject\n" + "from\n" + " RUser u\n" + " left join u.linkRef l\n" + "where\n" - + " l is null"; - assertEqualsIgnoreWhitespace(expected, real); + + " l is null"); } finally { close(session); } @@ -1102,14 +1060,13 @@ public void test075QueryUserAccountRefNotNull() throws Exception { .not().item(UserType.F_LINK_REF).isNull() .build(); String real = getInterpretedQuery(session, UserType.class, query); - String expected = "select\n" + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid, u.fullObject\n" + "from\n" + " RUser u\n" + " left join u.linkRef l\n" + "where\n" - + " not l is null"; - assertEqualsIgnoreWhitespace(expected, real); + + " not l is null"); } finally { close(session); } @@ -1123,7 +1080,7 @@ public void test076QueryUserAccountRefByType() throws Exception { .item(UserType.F_LINK_REF).refType(ShadowType.COMPLEX_TYPE) .build(); String real = getInterpretedQuery(session, UserType.class, query); - String expected = "select\n" + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid,\n" + " u.fullObject\n" + "from\n" @@ -1133,8 +1090,7 @@ public void test076QueryUserAccountRefByType() throws Exception { + " (\n" + " l.relation in (:relation) and\n" + " l.targetType = :targetType\n" - + " )\n"; - assertEqualsIgnoreWhitespace(expected, real); + + " )\n"); } finally { close(session); } @@ -1148,15 +1104,14 @@ public void test077QueryUserAccountRefByRelation() throws Exception { .item(UserType.F_LINK_REF).refRelation(prismContext.getDefaultRelation()) .build(); String real = getInterpretedQuery(session, UserType.class, query); - String expected = "select\n" + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid,\n" + " u.fullObject\n" + "from\n" + " RUser u\n" + " left join u.linkRef l\n" + "where\n" - + " l.relation in (:relation)\n"; - assertEqualsIgnoreWhitespace(expected, real); + + " l.relation in (:relation)\n"); } finally { close(session); } @@ -1172,7 +1127,7 @@ public void test078QueryUserAccountRefComplex() throws Exception { .item(UserType.F_LINK_REF).ref(value1, value2) .build(); String real = getInterpretedQuery(session, UserType.class, query); - String expected = "select\n" + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid,\n" + " u.fullObject\n" + "from\n" @@ -1189,8 +1144,7 @@ public void test078QueryUserAccountRefComplex() throws Exception { + " l.relation in (:relation2) and\n" + " l.targetType = :targetType2\n" + " )\n" - + " )\n"; - assertEqualsIgnoreWhitespace(expected, real); + + " )\n"); } finally { close(session); } @@ -1217,7 +1171,8 @@ public void test080QueryUserAssignmentTargetRef() throws Exception { .build(); RQueryImpl rQuery = (RQueryImpl) getInterpretedQueryWhole(session, UserType.class, query, false, null); String real = rQuery.getQuery().getQueryString(); - String expected = "select\n" + + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid, u.fullObject\n" + "from\n" + " RUser u\n" + @@ -1227,8 +1182,7 @@ public void test080QueryUserAssignmentTargetRef() throws Exception { " a.targetRef.targetOid = :targetOid and\n" + " a.targetRef.relation in (:relation) and\n" + " a.targetRef.targetType = :targetType\n" + - " )\n"; - assertEqualsIgnoreWhitespace(expected, real); + " )\n"); @SuppressWarnings("unchecked") Collection relationParameter = (Collection) rQuery.getQuerySource().getParameters().get("relation").getValue(); @@ -1258,7 +1212,8 @@ public void test082QueryUserAssignmentTargetRefManagerStandardQualified() throws .build(); RQueryImpl rQuery = (RQueryImpl) getInterpretedQueryWhole(session, UserType.class, query, false, null); String real = rQuery.getQuery().getQueryString(); - String expected = "select\n" + + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid, u.fullObject\n" + "from\n" + " RUser u\n" + @@ -1268,8 +1223,7 @@ public void test082QueryUserAssignmentTargetRefManagerStandardQualified() throws " a.targetRef.targetOid = :targetOid and\n" + " a.targetRef.relation in (:relation) and\n" + " a.targetRef.targetType = :targetType\n" + - " )\n"; - assertEqualsIgnoreWhitespace(expected, real); + " )\n"); @SuppressWarnings("unchecked") Collection relationParameter = (Collection) rQuery.getQuerySource().getParameters().get("relation").getValue(); @@ -1298,7 +1252,8 @@ public void test083QueryUserAssignmentTargetRefManagerCustomQualified() throws E .build(); RQueryImpl rQuery = (RQueryImpl) getInterpretedQueryWhole(session, UserType.class, query, false, null); String real = rQuery.getQuery().getQueryString(); - String expected = "select\n" + + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid, u.fullObject\n" + "from\n" + " RUser u\n" + @@ -1308,8 +1263,7 @@ public void test083QueryUserAssignmentTargetRefManagerCustomQualified() throws E " a.targetRef.targetOid = :targetOid and\n" + " a.targetRef.relation = :relation and\n" + " a.targetRef.targetType = :targetType\n" + - " )\n"; - assertEqualsIgnoreWhitespace(expected, real); + " )\n"); String relationParameter = (String) rQuery.getQuerySource().getParameters().get("relation").getValue(); assertEquals("Wrong relation parameter value", RUtil.qnameToString(auditorRelation), relationParameter); @@ -1331,7 +1285,8 @@ public void test084QueryUserAssignmentTargetRefManagerUnqualified() throws Excep .build(); RQueryImpl rQuery = (RQueryImpl) getInterpretedQueryWhole(session, UserType.class, query, false, null); String real = rQuery.getQuery().getQueryString(); - String expected = "select\n" + + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid, u.fullObject\n" + "from\n" + " RUser u\n" + @@ -1341,8 +1296,7 @@ public void test084QueryUserAssignmentTargetRefManagerUnqualified() throws Excep " a.targetRef.targetOid = :targetOid and\n" + " a.targetRef.relation in (:relation) and\n" + " a.targetRef.targetType = :targetType\n" + - " )\n"; - assertEqualsIgnoreWhitespace(expected, real); + " )\n"); @SuppressWarnings("unchecked") Collection relationParameter = (Collection) rQuery.getQuerySource().getParameters().get("relation").getValue(); @@ -1368,15 +1322,13 @@ public void test086QueryTrigger() throws Exception { .build(); String real = getInterpretedQuery(session, ObjectType.class, query); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " o.oid, o.fullObject\n" + "from\n" + " RObject o\n" + " left join o.trigger t\n" + "where\n" + - " t.timestamp <= :timestamp\n"; - - assertEqualsIgnoreWhitespace(expected, real); + " t.timestamp <= :timestamp\n"); } finally { close(session); } @@ -1400,15 +1352,13 @@ public void test088QueryTriggerBeforeAfter() throws Exception { .build(); String real = getInterpretedQuery(session, ObjectType.class, query); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " o.oid, o.fullObject\n" + "from\n" + " RObject o\n" + " left join o.trigger t\n" + "where\n" + - " ( t.timestamp > :timestamp and t.timestamp <= :timestamp2 )\n"; - - assertEqualsIgnoreWhitespace(expected, real); + " ( t.timestamp > :timestamp and t.timestamp <= :timestamp2 )\n"); } finally { close(session); } @@ -1423,15 +1373,13 @@ public void test089QueryAssignmentActivationAdministrativeStatus() throws Except .build(); String real = getInterpretedQuery(session, UserType.class, query); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid, u.fullObject\n" + "from\n" + " RUser u\n" + " left join u.assignments a with a.assignmentOwner = :assignmentOwner\n" + "where\n" + - " a.activation.administrativeStatus = :administrativeStatus\n"; - - assertEqualsIgnoreWhitespace(expected, real); + " a.activation.administrativeStatus = :administrativeStatus\n"); } finally { close(session); } @@ -1454,16 +1402,14 @@ public void test090QueryInducementActivationAdministrativeStatus() throws Except String real = getInterpretedQuery(session, RoleType.class, query); - String expected = "select\n" + + // assignmentOwner = com.evolveum.midpoint.repo.sql.data.common.other.RAssignmentOwner.ABSTRACT_ROLE + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " r.oid, r.fullObject\n" + "from\n" + " RRole r\n" + " left join r.assignments a with a.assignmentOwner = :assignmentOwner\n" + "where\n" + - " a.activation.administrativeStatus = :administrativeStatus\n"; - - // assignmentOwner = com.evolveum.midpoint.repo.sql.data.common.other.RAssignmentOwner.ABSTRACT_ROLE - assertEqualsIgnoreWhitespace(expected, real); + " a.activation.administrativeStatus = :administrativeStatus\n"); } finally { close(session); } @@ -1483,7 +1429,7 @@ public void test092QueryInducementAndAssignmentActivationAdministrativeStatus() .build(); String real = getInterpretedQuery(session, RoleType.class, query); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " r.oid, r.fullObject\n" + "from\n" + " RRole r\n" + @@ -1493,9 +1439,7 @@ public void test092QueryInducementAndAssignmentActivationAdministrativeStatus() " (\n" + " a.activation.administrativeStatus = :administrativeStatus or\n" + " a2.activation.administrativeStatus = :administrativeStatus2\n" + - " )\n"; - - assertEqualsIgnoreWhitespace(expected, real); + " )\n"); } finally { close(session); } @@ -1520,7 +1464,7 @@ public void test094QueryUserByActivationDouble() throws Exception { .build(); String real = getInterpretedQuery(session, UserType.class, query); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid, u.fullObject\n" + "from\n" + " RUser u\n" + @@ -1528,9 +1472,7 @@ public void test094QueryUserByActivationDouble() throws Exception { " (\n" + " u.activation.administrativeStatus = :administrativeStatus and\n" + " u.activation.validFrom = :validFrom\n" + - " )\n"; - - assertEqualsIgnoreWhitespace(expected, real); + " )\n"); } finally { close(session); } @@ -1552,7 +1494,8 @@ public void test096QueryTriggerTimestampDoubleWrong() throws Exception { String real = getInterpretedQuery(session, ObjectType.class, query); // correct translation but the filter is wrong: we need to point to THE SAME timestamp -> i.e. ForValue should be used here - String expected = "select\n" + + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " o.oid, o.fullObject\n" + "from\n" + " RObject o\n" + @@ -1562,9 +1505,7 @@ public void test096QueryTriggerTimestampDoubleWrong() throws Exception { " (\n" + " t.timestamp > :timestamp and\n" + " t2.timestamp < :timestamp2\n" + - " )\n"; - - assertEqualsIgnoreWhitespace(expected, real); + " )\n"); } finally { close(session); } @@ -1580,7 +1521,8 @@ public void test100CountObjectOrderByName() throws Exception { .asc(F_NAME).build(); String real = getInterpretedQuery(session, UserType.class, query, true); - String expected = "select\n" + + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " count(u.oid)\n" + "from\n" + " RUser u\n" + @@ -1588,8 +1530,7 @@ public void test100CountObjectOrderByName() throws Exception { " (\n" + " u.nameCopy.orig = :orig and\n" + " u.nameCopy.norm = :norm\n" + - " )\n"; - assertEqualsIgnoreWhitespace(expected, real); + " )\n"); } finally { close(session); } @@ -1604,11 +1545,12 @@ public void test102CountObjectOrderByNameWithoutFilter() throws Exception { ObjectQuery query = prismContext.queryFactory().createQuery(null, paging); String real = getInterpretedQuery(session, ObjectType.class, query, true); - String expected = "select\n" + + + // ordering does not make sense here + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " count(o.oid)\n" + "from\n" + - " RObject o\n"; // ordering does not make sense here - assertEqualsIgnoreWhitespace(expected, real); + " RObject o\n"); } finally { close(session); } @@ -1627,13 +1569,12 @@ public void test104CountTaskOrderByName() throws Exception { .asc(F_NAME) .build(); String real = getInterpretedQuery(session, TaskType.class, query, true); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " count(t.oid)\n" + "from\n" + " RTask t\n" + "where\n" + - " t.parent is null"; - assertEqualsIgnoreWhitespace(expected, real); + " t.parent is null"); } finally { close(session); } @@ -1647,13 +1588,12 @@ public void test106InOidTest() throws Exception { .id("1", "2").build(); String real = getInterpretedQuery(session, ObjectType.class, query, false); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " o.oid, o.fullObject\n" + "from\n" + " RObject o\n" + "where\n" + - " o.oid in (:oid)\n"; - assertEqualsIgnoreWhitespace(expected, real); + " o.oid in (:oid)\n"); } finally { close(session); } @@ -1699,13 +1639,12 @@ public void test116OwnerInOidTest() throws Exception { .ownerId("1", "2").build(); String real = getInterpretedQuery(session, AccessCertificationCaseType.class, query, false); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " a.ownerOid, a.id, a.fullObject\n" + "from\n" + " RAccessCertificationCase a\n" + "where\n" + - " a.ownerOid in (:ownerOid)"; - assertEqualsIgnoreWhitespace(expected, real); + " a.ownerOid in (:ownerOid)"); } finally { close(session); } @@ -1726,16 +1665,14 @@ public void test118QueryOrgTreeFindOrgs() throws Exception { OperationResult result = new OperationResult("query org structure"); repositoryService.searchObjects(OrgType.class, query, null, result); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " o.oid, o.fullObject\n" + "from\n" + " ROrg o\n" + "where\n" + " o.oid in (select ref.ownerOid from RObjectReference ref where ref.referenceType = 0 and ref.targetOid = :orgOid)\n" + - "order by o.nameCopy.orig asc\n"; - - assertEqualsIgnoreWhitespace(expected, real); + "order by o.nameCopy.orig asc\n"); } finally { close(session); } @@ -1752,15 +1689,14 @@ public void test120QueryOrgTreeFindUsersRelationDefault() throws Exception { RQueryImpl rQuery = (RQueryImpl) getInterpretedQueryWhole(session, UserType.class, query, false, null); String real = rQuery.getQuery().getQueryString(); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid,\n" + " u.fullObject\n" + "from\n" + " RUser u\n" + "where\n" - + " u.oid in (select ref.ownerOid from RObjectReference ref where ref.referenceType = 0 and ref.relation in (:relation) and ref.targetOid = :orgOid)\n"; - - assertEqualsIgnoreWhitespace(expected, real); + + " u.oid in (select ref.ownerOid from RObjectReference ref where ref.referenceType = 0 and ref.relation in (:relation) and ref.targetOid = :orgOid)\n"); @SuppressWarnings("unchecked") Collection relationParameter = (Collection) rQuery.getQuerySource().getParameters().get("relation").getValue(); @@ -1784,15 +1720,14 @@ public void test122QueryOrgTreeFindUsersRelationManager() throws Exception { RQueryImpl rQuery = (RQueryImpl) getInterpretedQueryWhole(session, UserType.class, query, false, null); String real = rQuery.getQuery().getQueryString(); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid,\n" + " u.fullObject\n" + "from\n" + " RUser u\n" + "where\n" - + " u.oid in (select ref.ownerOid from RObjectReference ref where ref.referenceType = 0 and ref.relation in (:relation) and ref.targetOid = :orgOid)\n"; - - assertEqualsIgnoreWhitespace(expected, real); + + " u.oid in (select ref.ownerOid from RObjectReference ref where ref.referenceType = 0 and ref.relation in (:relation) and ref.targetOid = :orgOid)\n"); @SuppressWarnings("unchecked") Collection relationParameter = (Collection) rQuery.getQuerySource().getParameters().get("relation").getValue(); @@ -1822,16 +1757,13 @@ public void test124QueryOrgAllLevels() throws Exception { OperationResult result = new OperationResult("query org structure"); repositoryService.searchObjects(OrgType.class, query, null, result); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " o.oid, o.fullObject\n" + - "from\n" + " ROrg o\n" + "where\n" + " o.oid in (select ref.ownerOid from RObjectReference ref where ref.referenceType = 0 and ref.targetOid in (select descendantOid from ROrgClosure where ancestorOid = :orgOid))\n" + - "order by o.nameCopy.orig asc"; - - assertEqualsIgnoreWhitespace(expected, real); + "order by o.nameCopy.orig asc"); } finally { close(session); } @@ -1848,15 +1780,13 @@ public void test126QueryOrgTreeFindUsersRelationDefault() throws Exception { RQueryImpl rQuery = (RQueryImpl) getInterpretedQueryWhole(session, UserType.class, query, false, null); String real = rQuery.getQuery().getQueryString(); - String expected = "select\n" + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid,\n" + " u.fullObject\n" - + "from\n" + " RUser u\n" + "where\n" - + " u.oid in (select ref.ownerOid from RObjectReference ref where ref.referenceType = 0 and ref.relation in (:relation) and ref.targetOid in (select descendantOid from ROrgClosure where ancestorOid = :orgOid))\n"; - assertEqualsIgnoreWhitespace(expected, real); + + " u.oid in (select ref.ownerOid from RObjectReference ref where ref.referenceType = 0 and ref.relation in (:relation) and ref.targetOid in (select descendantOid from ROrgClosure where ancestorOid = :orgOid))\n"); @SuppressWarnings("unchecked") Collection relationParameter = (Collection) rQuery.getQuerySource().getParameters().get("relation").getValue(); @@ -1880,16 +1810,14 @@ public void test128QueryOrgTreeFindUsersRelationManager() throws Exception { RQueryImpl rQuery = (RQueryImpl) getInterpretedQueryWhole(session, UserType.class, query, false, null); String real = rQuery.getQuery().getQueryString(); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid,\n" + " u.fullObject\n" - + "from\n" + " RUser u\n" + "where\n" - + " u.oid in (select ref.ownerOid from RObjectReference ref where ref.referenceType = 0 and ref.relation in (:relation) and ref.targetOid in (select descendantOid from ROrgClosure where ancestorOid = :orgOid))\n"; - - assertEqualsIgnoreWhitespace(expected, real); + + " u.oid in (select ref.ownerOid from RObjectReference ref where ref.referenceType = 0 and ref.relation in (:relation) and ref.targetOid in (select descendantOid from ROrgClosure where ancestorOid = :orgOid))\n"); @SuppressWarnings("unchecked") Collection relationParameter = (Collection) rQuery.getQuerySource().getParameters().get("relation").getValue(); @@ -1915,15 +1843,16 @@ public void test130QuerySubtreeDistinctCount() throws Exception { .build(); String real = getInterpretedQuery(session, OrgType.class, query, true, distinct()); + // we probably do not need 'distinct' here - String expected = "select\n" + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " count(o.oid)\n" + "from\n" + " ROrg o\n" + "where\n" - + " o.oid in (select ref.ownerOid from RObjectReference ref where ref.referenceType = 0 and ref.targetOid in (select descendantOid from ROrgClosure where ancestorOid = :orgOid))\n"; - - assertEqualsIgnoreWhitespace(expected, real); + + " o.oid in (select ref.ownerOid from RObjectReference ref" + + " where ref.referenceType = 0" + + " and ref.targetOid in (select descendantOid from ROrgClosure where ancestorOid = :orgOid))\n"); } finally { close(session); } @@ -1944,15 +1873,13 @@ public void test135QueryRoots() throws Exception { OperationResult result = new OperationResult("query org structure"); repositoryService.searchObjects(OrgType.class, query, null, result); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " o.oid, o.fullObject\n" + "from\n" + " ROrg o\n" + "where\n" + " o.oid in (select descendantOid from ROrgClosure group by descendantOid having count(descendantOid) = 1)\n" + - "order by o.nameCopy.orig asc"; - - assertEqualsIgnoreWhitespace(expected, real); + "order by o.nameCopy.orig asc"); } finally { close(session); } @@ -1973,7 +1900,8 @@ public void test140ActivationQueryWrong() throws Exception { try { String real = getInterpretedQuery(session, UserType.class, query, false); - String expected = "select\n" + + // correct translation but probably not what the requester wants (use Exists instead) + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid, u.fullObject\n" + "from\n" + " RUser u\n" + @@ -1985,11 +1913,7 @@ public void test140ActivationQueryWrong() throws Exception { " u.activation.validTo <= :validTo or\n" + " a.activation.validFrom <= :validFrom2 or\n" + " a2.activation.validTo <= :validTo2\n" + - " )\n"; - - // correct translation but probably not what the requester wants (use Exists instead) - - assertEqualsIgnoreWhitespace(expected, real); + " )\n"); } finally { close(session); } @@ -2014,7 +1938,8 @@ public void test141ActivationQueryCorrect() throws Exception { try { String real = getInterpretedQuery(session, UserType.class, query, false); - String expected = "select\n" + + // correct translation but probably not what the requester wants (use ForValue instead) + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid, u.fullObject\n" + "from\n" + " RUser u\n" + @@ -2025,11 +1950,7 @@ public void test141ActivationQueryCorrect() throws Exception { " u.activation.validTo <= :validTo or\n" + " ( a.activation.validFrom <= :validFrom2 or\n" + " a.activation.validTo <= :validTo2 )\n" + - " )\n"; - - // correct translation but probably not what the requester wants (use ForValue instead) - - assertEqualsIgnoreWhitespace(expected, real); + " )\n"); } finally { close(session); } @@ -2063,7 +1984,7 @@ public void test142ActivationQueryWrong() throws Exception { try { String real = getInterpretedQuery(session, UserType.class, query, false); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid, u.fullObject\n" + "from\n" + " RUser u\n" + @@ -2089,9 +2010,7 @@ public void test142ActivationQueryWrong() throws Exception { " a3.activation.validTo > :validTo3 and\n" + " a4.activation.validTo <= :validTo4\n" + " )\n" + - " )\n"; - - assertEqualsIgnoreWhitespace(expected, real); + " )\n"); } finally { close(session); } @@ -2127,7 +2046,8 @@ public void test143ActivationQueryCorrect() throws Exception { try { String real = getInterpretedQuery(session, UserType.class, query, false); - String expected = "select\n" + + // TODO rewrite with ForValue + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid, u.fullObject\n" + "from\n" + " RUser u\n" + @@ -2151,10 +2071,7 @@ public void test143ActivationQueryCorrect() throws Exception { " a.activation.validTo <= :validTo4\n" + " )\n" + " )\n" + - " )\n"; - - // TODO rewrite with ForValue - assertEqualsIgnoreWhitespace(expected, real); + " )\n"); } finally { close(session); } @@ -2237,7 +2154,7 @@ public void test151QueryNameAndOrg() throws Exception { .build(); String real = getInterpretedQuery(session, UserType.class, query); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid, u.fullObject\n" + "from\n" + " RUser u\n" + @@ -2251,9 +2168,7 @@ public void test151QueryNameAndOrg() throws Exception { " where ref.referenceType = 0 and " + " ref.targetOid in (select descendantOid from ROrgClosure where ancestorOid = :orgOid))\n" + " )\n" + - "order by u.nameCopy.orig asc\n"; - - assertEqualsIgnoreWhitespace(expected, real); + "order by u.nameCopy.orig asc\n"); } finally { close(session); } @@ -2269,13 +2184,12 @@ public void test153QueryObjectSubstringName() throws Exception { .build(); String real = getInterpretedQuery(session, ObjectType.class, objectQuery); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " o.oid, o.fullObject\n" + "from\n" + " RObject o\n" + "where\n" + - " o.name.orig like :orig\n"; - assertEqualsIgnoreWhitespace(expected, real); + " o.name.orig like :orig escape '!'\n"); OperationResult result = createOperationResult(); int count = repositoryService.countObjects(ObjectType.class, objectQuery, null, result); @@ -2301,14 +2215,13 @@ public void test154queryObjectClassTypeUser() throws Exception { .type(UserType.class) .build(); String real = getInterpretedQuery(session, ObjectType.class, query); - String expected = "select\n" + + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " o.oid, o.fullObject\n" + "from\n" + " RObject o\n" + "where\n" + - " o.objectTypeClass = :objectTypeClass\n"; - - assertEqualsIgnoreWhitespace(expected, real); + " o.objectTypeClass = :objectTypeClass\n"); } finally { close(session); } @@ -2323,14 +2236,13 @@ public void test155queryObjectClassTypeAbstractRole() throws Exception { .type(AbstractRoleType.class) .build(); String real = getInterpretedQuery(session, ObjectType.class, query); - String expected = "select\n" + + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " o.oid, o.fullObject\n" + "from\n" + " RObject o\n" + "where\n" + - " o.objectTypeClass in (:objectTypeClass)"; - - assertEqualsIgnoreWhitespace(expected, real); + " o.objectTypeClass in (:objectTypeClass)"); } finally { close(session); } @@ -2346,14 +2258,13 @@ public void test158queryMetadataTimestamp() throws Exception { .item(ReportDataType.F_METADATA, MetadataType.F_CREATE_TIMESTAMP).le(timeXml) .build(); String real = getInterpretedQuery(session, ReportDataType.class, query); - String expected = "select\n" + + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " r.oid, r.fullObject\n" + "from\n" + " RReportData r\n" + "where\n" + - " r.createTimestamp <= :createTimestamp"; - - assertEqualsIgnoreWhitespace(expected, real); + " r.createTimestamp <= :createTimestamp"); } finally { close(session); } @@ -2369,7 +2280,7 @@ public void test160QueryObjectTypeByTypeUserAndLocality() throws Exception { .build(); String real = getInterpretedQuery(session, ObjectType.class, query); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " o.oid, o.fullObject\n" + "from\n" + " RObject o\n" + // TODO - why not RUser here? we unnecessarily join all of RObject subtypes... @@ -2380,8 +2291,7 @@ public void test160QueryObjectTypeByTypeUserAndLocality() throws Exception { " o.localityFocus.orig = :orig and\n" + " o.localityFocus.norm = :norm\n" + " )\n" + - " )\n"; - assertEqualsIgnoreWhitespace(expected, real); + " )\n"); checkQueryTypeAlias(hqlToSql(real), "m_user", "localityFocus_orig", "localityFocus_norm"); } finally { close(session); @@ -2425,7 +2335,7 @@ public void test162QueryObjectypeByTypeOrgAndLocality() throws Exception { .build(); String real = getInterpretedQuery(session, ObjectType.class, query); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " o.oid, o.fullObject\n" + "from\n" + " RObject o\n" + @@ -2436,8 +2346,7 @@ public void test162QueryObjectypeByTypeOrgAndLocality() throws Exception { " o.localityFocus.orig = :orig and\n" + " o.localityFocus.norm = :norm\n" + " )\n" + - " )\n"; - assertEqualsIgnoreWhitespace(expected, real); + " )\n"); checkQueryTypeAlias(hqlToSql(real), "m_org", "localityFocus_orig", "localityFocus_norm"); } finally { close(session); @@ -2454,17 +2363,17 @@ public void test164QueryObjectypeByTypeAndExtensionAttribute() throws Exception .build(); RQueryImpl realQuery = (RQueryImpl) getInterpretedQueryWhole(session, ObjectType.class, query, false, null); - String expected = "select\n" + - " o.oid, o.fullObject\n" + - "from\n" + - " RObject o\n" + - " left join o.strings s with ( s.ownerType = :ownerType and s.itemId = :itemId )\n" + - "where\n" + - " (\n" + - " o.objectTypeClass = :objectTypeClass and\n" + - " s.value = :value\n" + - " )\n"; - assertEqualsIgnoreWhitespace(expected, realQuery.getQuery().getQueryString()); + Assertions.assertThat(realQuery.getQuery().getQueryString()) + .isEqualToIgnoringWhitespace("select\n" + + " o.oid, o.fullObject\n" + + "from\n" + + " RObject o\n" + + " left join o.strings s with ( s.ownerType = :ownerType and s.itemId = :itemId )\n" + + "where\n" + + " (\n" + + " o.objectTypeClass = :objectTypeClass and\n" + + " s.value = :value\n" + + " )\n"); assertEquals("Wrong property ID for 'weapon'", weaponDefinition.getId(), realQuery.getQuerySource().getParameters().get("itemId").getValue()); } finally { @@ -2482,7 +2391,8 @@ public void test166QueryObjectypeByTypeAndReference() throws Exception { .build(); String real = getInterpretedQuery(session, ObjectType.class, query); - String expected = "select\n" + + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " o.oid, o.fullObject\n" + "from\n" + " RObject o\n" + @@ -2494,9 +2404,7 @@ public void test166QueryObjectypeByTypeAndReference() throws Exception { " l.targetOid = :targetOid and\n" + " l.relation in (:relation)\n" + " )\n" + - " )\n"; - - assertEqualsIgnoreWhitespace(expected, real); + " )\n"); } finally { close(session); } @@ -2519,7 +2427,7 @@ public void test170QueryObjectypeByTypeComplex() throws Exception { .or().type(ReportType.class) .build(); String real = getInterpretedQuery(session, ObjectType.class, query); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " o.oid, o.fullObject\n" + "from\n" + " RObject o\n" + @@ -2544,8 +2452,7 @@ public void test170QueryObjectypeByTypeComplex() throws Exception { " o2 = :o2\n" + " ) or\n" + " o.objectTypeClass = :objectTypeClass3\n" + - " )\n"; - assertEqualsIgnoreWhitespace(expected, real); + " )\n"); } finally { close(session); } @@ -2560,7 +2467,7 @@ public void test171QueryObjectypeByTwoAbstractTypes() throws Exception { .or().type(AbstractRoleType.class).block().endBlock() .build(); String real = getInterpretedQuery(session, ObjectType.class, query); - String expected = "select\n" + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " o.oid, o.fullObject\n" + "from\n" + " RObject o\n" @@ -2568,8 +2475,7 @@ public void test171QueryObjectypeByTwoAbstractTypes() throws Exception { + " (\n" + " o.objectTypeClass in (:objectTypeClass) or\n" + " o.objectTypeClass in (:objectTypeClass2)\n" - + " )\n"; - assertEqualsIgnoreWhitespace(expected, real); + + " )\n"); } finally { close(session); } @@ -2586,7 +2492,8 @@ public void test173QueryObjectTypeByTypeAndReference() throws Exception { .item(roleDef, RoleType.F_ROLE_MEMBERSHIP_REF).ref("c0c010c0-d34d-b33f-f00d-111111111111") .build(); String real = getInterpretedQuery(session, ObjectType.class, query); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " o.oid,\n" + " o.fullObject\n" + "from\n" @@ -2602,9 +2509,7 @@ public void test173QueryObjectTypeByTypeAndReference() throws Exception { + " r.relation in (:relation)\n" + " )\n" + " )\n" - + " )\n"; - - assertEqualsIgnoreWhitespace(expected, real); + + " )\n"); } finally { close(session); } @@ -2628,7 +2533,8 @@ public void test175QueryObjectTypeByTypeAndOwnerRefOverloaded() throws Exception .or().type(TaskType.class).item(taskDef, AccessCertificationDefinitionType.F_OWNER_REF).ref("task-owner-oid") .build(); String real = getInterpretedQuery(session, ObjectType.class, query); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " o.oid,\n" + " o.fullObject\n" + "from\n" @@ -2657,9 +2563,7 @@ public void test175QueryObjectTypeByTypeAndOwnerRefOverloaded() throws Exception + " o.ownerRefTask.relation in (:relation3)\n" + " )\n" + " )\n" - + " )\n"; - - assertEqualsIgnoreWhitespace(expected, real); + + " )\n"); } finally { close(session); } @@ -2689,14 +2593,14 @@ public void test180QueryGenericString() throws Exception { .item(ObjectType.F_EXTENSION, new QName("http://example.com/p", "stringType")).eq("asdf") .build(); String real = getInterpretedQuery(session, GenericObjectType.class, query); - String expected = "select\n" + + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " g.oid, g.fullObject\n" + "from\n" + " RGenericObject g\n" + " left join g.strings s with ( s.ownerType = :ownerType and s.itemId = :itemId )\n" + "where\n" + - " s.value = :value\n"; - assertEqualsIgnoreWhitespace(expected, real); + " s.value = :value\n"); } finally { close(session); } @@ -2712,15 +2616,15 @@ public void test182QueryGenericBoolean() throws Exception { RQueryImpl realQuery = (RQueryImpl) getInterpretedQueryWhole(session, GenericObjectType.class, objectQuery, false, null); - String expected = "select\n" + - " g.oid, g.fullObject\n" + - "from\n" + - " RGenericObject g\n" + - " left join g.booleans b with ( b.ownerType = :ownerType and b.itemId = :itemId )\n" + - "where\n" + - " b.value = :value\n"; - assertEqualsIgnoreWhitespace(expected, realQuery.getQuery().getQueryString()); + Assertions.assertThat(realQuery.getQuery().getQueryString()) + .isEqualToIgnoringWhitespace("select\n" + + " g.oid, g.fullObject\n" + + "from\n" + + " RGenericObject g\n" + + " left join g.booleans b with ( b.ownerType = :ownerType and b.itemId = :itemId )\n" + + "where\n" + + " b.value = :value\n"); assertEquals("Wrong property ID for 'skipAutogeneration'", skipAutogenerationDefinition.getId(), realQuery.getQuerySource().getParameters().get("itemId").getValue()); OperationResult result = new OperationResult("search"); @@ -2757,16 +2661,16 @@ public void test184QueryAssignmentExtensionBoolean() throws Exception { .build(); String real = getInterpretedQuery(session, UserType.class, objectQuery); - String expected = "select\n" + - " u.oid, u.fullObject\n" + - "from\n" + - " RUser u\n" + - " left join u.assignments a with a.assignmentOwner = :assignmentOwner\n" + - " left join a.extension e\n" + - " left join e.booleans b with b.itemId = :itemId\n" + - "where\n" + - " b.value = :value"; - assertEqualsIgnoreWhitespace(expected, real); + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + + " u.oid, u.fullObject\n" + + "from\n" + + " RUser u\n" + + " left join u.assignments a with a.assignmentOwner = :assignmentOwner\n" + + " left join a.extension e\n" + + " left join e.booleans b with b.itemId = :itemId\n" + + "where\n" + + " b.value = :value"); OperationResult result = new OperationResult("search"); List> objects = repositoryService.searchObjects(UserType.class, @@ -2799,7 +2703,8 @@ public void test185QueryExtensionEnum() throws Exception { .build(); RQueryImpl realQuery = (RQueryImpl) getInterpretedQueryWhole(session, UserType.class, query, false, null); String real = realQuery.getQuery().getQueryString(); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid, u.fullObject\n" + "from\n" + " RUser u\n" @@ -2808,8 +2713,7 @@ public void test185QueryExtensionEnum() throws Exception { + " s.itemId = :itemId\n" + ")\n" + "where\n" - + " s.value = :value\n"; - assertEqualsIgnoreWhitespace(expected, real); + + " s.value = :value\n"); assertEquals("Wrong property ID for 'overrideActivation'", overrideActivationDefinition.getId(), realQuery.getQuerySource().getParameters().get("itemId").getValue()); } finally { close(session); @@ -2824,7 +2728,8 @@ public void test186QueryExtensionRef() throws Exception { .item(F_EXTENSION, new QName("referenceType")).ref("123") .build(); String real = getInterpretedQuery(session, GenericObjectType.class, query); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " g.oid,\n" + " g.fullObject\n" + "from\n" @@ -2837,8 +2742,7 @@ public void test186QueryExtensionRef() throws Exception { + " (\n" + " r.value = :value and\n" + " r.relation in (:relation)\n" - + " )\n"; - assertEqualsIgnoreWhitespace(expected, real); + + " )\n"); } finally { close(session); } @@ -2849,11 +2753,11 @@ public void test200QueryCertCaseAll() throws Exception { Session session = open(); try { String real = getInterpretedQuery(session, AccessCertificationCaseType.class, (ObjectQuery) null, false); - String expected = "select\n" + + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " a.ownerOid, a.id, a.fullObject\n" + "from\n" + - " RAccessCertificationCase a\n"; - assertEqualsIgnoreWhitespace(expected, real); + " RAccessCertificationCase a\n"); } finally { close(session); } @@ -2864,13 +2768,13 @@ public void test202QueryCertWorkItemAll() throws Exception { Session session = open(); try { String real = getInterpretedQuery(session, AccessCertificationWorkItemType.class, (ObjectQuery) null, false); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " a.ownerOwnerOid,\n" + " a.ownerId,\n" + " a.id\n" + "from\n" - + " RAccessCertificationWorkItem a\n"; - assertEqualsIgnoreWhitespace(expected, real); + + " RAccessCertificationWorkItem a\n"); } finally { close(session); } @@ -2884,7 +2788,8 @@ public void test204QueryCertWorkItemAllOrderByCampaignName() throws Exception { .asc(PrismConstants.T_PARENT, PrismConstants.T_PARENT, F_NAME) .build(); String real = getInterpretedQuery(session, AccessCertificationWorkItemType.class, q, false); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " a.ownerOwnerOid,\n" + " a.ownerId,\n" + " a.id\n" @@ -2892,8 +2797,7 @@ public void test204QueryCertWorkItemAllOrderByCampaignName() throws Exception { + " RAccessCertificationWorkItem a\n" + " left join a.owner o\n" + " left join o.owner o2\n" - + "order by o2.nameCopy.orig asc\n"; - assertEqualsIgnoreWhitespace(expected, real); + + "order by o2.nameCopy.orig asc\n"); } finally { close(session); } @@ -2907,13 +2811,13 @@ public void test206QueryCertCaseOwner() throws Exception { .ownerId("123456") .build(); String real = getInterpretedQuery(session, AccessCertificationCaseType.class, query, false); - String expected = "select\n" + + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " a.ownerOid, a.id, a.fullObject\n" + "from\n" + " RAccessCertificationCase a\n" + "where\n" + - " a.ownerOid in :ownerOid"; - assertEqualsIgnoreWhitespace(expected, real); + " a.ownerOid in :ownerOid"); } finally { close(session); } @@ -2928,7 +2832,8 @@ public void test208QueryCertCaseOwnerAndTarget() throws Exception { .and().item(AccessCertificationCaseType.F_TARGET_REF).ref("1234567890") .build(); String real = getInterpretedQuery(session, AccessCertificationCaseType.class, query, false); - String expected = "select\n" + + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " a.ownerOid, a.id, a.fullObject\n" + "from\n" + " RAccessCertificationCase a\n" + @@ -2939,8 +2844,7 @@ public void test208QueryCertCaseOwnerAndTarget() throws Exception { " a.targetRef.targetOid = :targetOid and\n" + " a.targetRef.relation in (:relation)\n" + " )\n" + - " )\n"; - assertEqualsIgnoreWhitespace(expected, real); + " )\n"); } finally { close(session); } @@ -2954,7 +2858,8 @@ public void test210QueryCertCaseReviewer() throws Exception { .item(F_WORK_ITEM, F_ASSIGNEE_REF).ref("1234567890") .build(); String real = getInterpretedQuery(session, AccessCertificationCaseType.class, query, false); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " a.ownerOid, a.id, a.fullObject\n" + "from\n" + " RAccessCertificationCase a\n" @@ -2964,8 +2869,7 @@ public void test210QueryCertCaseReviewer() throws Exception { + " (\n" + " a2.targetOid = :targetOid and\n" + " a2.relation in (:relation)\n" - + " )\n"; - assertEqualsIgnoreWhitespace(expected, real); + + " )\n"); } finally { close(session); } @@ -2980,7 +2884,8 @@ public void test212QueryCertWorkItemReviewers() throws Exception { .or().item(F_ASSIGNEE_REF).ref("oid2") .build(); String real = getInterpretedQuery(session, AccessCertificationWorkItemType.class, query, false); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " a.ownerOwnerOid,\n" + " a.ownerId,\n" + " a.id\n" @@ -2998,8 +2903,7 @@ public void test212QueryCertWorkItemReviewers() throws Exception { + " a3.targetOid = :targetOid2 and\n" + " a3.relation in (:relation2)\n" + " )\n" - + " )\n"; - assertEqualsIgnoreWhitespace(expected, real); + + " )\n"); } finally { close(session); } @@ -3019,7 +2923,8 @@ public void test216QueryCertCasesByCampaignOwner() throws Exception { .build(); String real = getInterpretedQuery(session, AccessCertificationCaseType.class, query, false); - String expected = "select\n" + + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " a.ownerOid, a.id, a.fullObject\n" + "from\n" + " RAccessCertificationCase a\n" + @@ -3032,8 +2937,7 @@ public void test216QueryCertCasesByCampaignOwner() throws Exception { " o.ownerRefCampaign.relation in (:relation) and\n" + " o.ownerRefCampaign.targetType = :targetType\n" + " )\n" + - " )\n"; - assertEqualsIgnoreWhitespace(expected, real); + " )\n"); } finally { close(session); } @@ -3050,30 +2954,29 @@ public void test218QueryCertCaseReviewerAndEnabled() throws Exception { .build(); String real = getInterpretedQuery(session, AccessCertificationCaseType.class, query, false); - String expected = - "select\n" + - " a.ownerOid, a.id, a.fullObject\n" + - "from\n" + - " RAccessCertificationCase a\n" + - " left join a.workItems w\n" + - " left join w.assigneeRef a2\n" + - " left join a.owner o\n" + - "where\n" + - " (\n" + - " (\n" + - " a2.targetOid = :targetOid and\n" + - " a2.relation in (:relation) and\n" + - " a2.targetType = :targetType\n" + - " ) and\n" + - " (\n" + - " a.stageNumber = o.stageNumber or\n" + - " (\n" + - " a.stageNumber is null and\n" + - " o.stageNumber is null\n" + - " )\n" + - " )\n" + - " )\n"; - assertEqualsIgnoreWhitespace(expected, real); + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + + " a.ownerOid, a.id, a.fullObject\n" + + "from\n" + + " RAccessCertificationCase a\n" + + " left join a.workItems w\n" + + " left join w.assigneeRef a2\n" + + " left join a.owner o\n" + + "where\n" + + " (\n" + + " (\n" + + " a2.targetOid = :targetOid and\n" + + " a2.relation in (:relation) and\n" + + " a2.targetType = :targetType\n" + + " ) and\n" + + " (\n" + + " a.stageNumber = o.stageNumber or\n" + + " (\n" + + " a.stageNumber is null and\n" + + " o.stageNumber is null\n" + + " )\n" + + " )\n" + + " )\n"); } finally { close(session); } @@ -3087,7 +2990,8 @@ public void test220QueryCertWorkItemReviewersMulti() throws Exception { .item(F_ASSIGNEE_REF).ref("oid1", "oid2") .build(); String real = getInterpretedQuery(session, AccessCertificationWorkItemType.class, query, false); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " a.ownerOwnerOid,\n" + " a.ownerId,\n" + " a.id\n" @@ -3098,8 +3002,7 @@ public void test220QueryCertWorkItemReviewersMulti() throws Exception { + " (\n" + " a2.targetOid in (:targetOid) and\n" + " a2.relation in (:relation)\n" - + " )"; - assertEqualsIgnoreWhitespace(expected, real); + + " )"); } finally { close(session); } @@ -3118,31 +3021,29 @@ public void test230QueryCertCaseReviewerAndEnabledByDeadlineAndOidAsc() throws E .build(); String real = getInterpretedQuery(session, AccessCertificationCaseType.class, query, false); - String expected = - "select\n" + - " a.ownerOid, a.id, a.fullObject\n" + - "from\n" + - " RAccessCertificationCase a\n" + - " left join a.workItems w\n" + - " left join w.assigneeRef a2\n" + - " left join a.owner o\n" + - "where\n" + - " (\n" + - " (\n" + - " a2.targetOid = :targetOid and\n" + - " a2.relation in (:relation) and\n" + - " a2.targetType = :targetType\n" + - " ) and\n" + - " (\n" + - " a.stageNumber = o.stageNumber or\n" + - " (\n" + - " a.stageNumber is null and\n" + - " o.stageNumber is null\n" + - " )\n" + - " )\n" + - " )\n" + - "order by a.reviewDeadline asc, a.id asc\n"; - assertEqualsIgnoreWhitespace(expected, real); + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + + " a.ownerOid, a.id, a.fullObject\n" + + "from\n" + + " RAccessCertificationCase a\n" + + " left join a.workItems w\n" + + " left join w.assigneeRef a2\n" + + " left join a.owner o\n" + + "where\n" + + " (\n" + + " (\n" + + " a2.targetOid = :targetOid and\n" + + " a2.relation in (:relation) and\n" + + " a2.targetType = :targetType\n" + + " ) and\n" + + " (\n" + + " a.stageNumber = o.stageNumber or\n" + + " (\n" + + " a.stageNumber is null and\n" + + " o.stageNumber is null\n" + + " )\n" + + " )\n" + + " )\n" + + "order by a.reviewDeadline asc, a.id asc\n"); } finally { close(session); } @@ -3159,25 +3060,23 @@ public void test232QueryCertWorkItemReviewerAndEnabledByDeadlineAndOidAsc() thro .build(); String real = getInterpretedQuery(session, AccessCertificationWorkItemType.class, query, false); - String expected = - "select\n" - + " a.ownerOwnerOid,\n" - + " a.ownerId,\n" - + " a.id\n" - + "from\n" - + " RAccessCertificationWorkItem a\n" - + " left join a.assigneeRef a2\n" - + " left join a.owner o\n" - + "where\n" - + " (\n" - + " (\n" - + " a2.targetOid in (:targetOid) and\n" - + " a2.relation in (:relation)\n" - + " ) and\n" - + " a.closeTimestamp is null\n" - + " )\n" - + "order by o.reviewDeadline asc, a.id asc\n"; - assertEqualsIgnoreWhitespace(expected, real); + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + + " a.ownerOwnerOid,\n" + + " a.ownerId,\n" + + " a.id\n" + + "from\n" + + " RAccessCertificationWorkItem a\n" + + " left join a.assigneeRef a2\n" + + " left join a.owner o\n" + + "where\n" + + " (\n" + + " (\n" + + " a2.targetOid in (:targetOid) and\n" + + " a2.relation in (:relation)\n" + + " ) and\n" + + " a.closeTimestamp is null\n" + + " )\n" + + "order by o.reviewDeadline asc, a.id asc\n"); } finally { close(session); } @@ -3196,7 +3095,7 @@ public void test234QueryCertCaseReviewerAndEnabledByRequestedDesc() throws Excep .build(); String real = getInterpretedQuery(session, AccessCertificationCaseType.class, query, false); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " a.ownerOid, a.id, a.fullObject\n" + "from\n" + " RAccessCertificationCase a\n" + @@ -3219,8 +3118,7 @@ public void test234QueryCertCaseReviewerAndEnabledByRequestedDesc() throws Excep " ) and\n" + " o.state = :state\n" + " )\n" + - "order by a.reviewRequestedTimestamp desc"; - assertEqualsIgnoreWhitespace(expected, real); + "order by a.reviewRequestedTimestamp desc"); } finally { close(session); } @@ -3238,7 +3136,8 @@ public void test300QueryWorkItemsForCase() throws Exception { .endBlock() .build(); String real = getInterpretedQuery(session, AccessCertificationWorkItemType.class, query, false); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " a.ownerOwnerOid,\n" + " a.ownerId,\n" + " a.id\n" @@ -3249,8 +3148,7 @@ public void test300QueryWorkItemsForCase() throws Exception { + " (\n" + " o.id in :id and\n" + " o.ownerOid in :ownerOid\n" - + " )\n"; - assertEqualsIgnoreWhitespace(expected, real); + + " )\n"); } finally { close(session); } @@ -3265,7 +3163,8 @@ public void test302QueryWorkItemsForCampaign() throws Exception { .ownerId("campaignOid1") .build(); String real = getInterpretedQuery(session, AccessCertificationWorkItemType.class, query, false); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " a.ownerOwnerOid,\n" + " a.ownerId,\n" + " a.id\n" @@ -3273,8 +3172,7 @@ public void test302QueryWorkItemsForCampaign() throws Exception { + " RAccessCertificationWorkItem a\n" + " left join a.owner o\n" + "where\n" - + " o.ownerOid in :ownerOid\n"; - assertEqualsIgnoreWhitespace(expected, real); + + " o.ownerOid in :ownerOid\n"); } finally { close(session); } @@ -3294,7 +3192,7 @@ public void test400DereferenceLink() throws Exception { .build(); String real = getInterpretedQuery(session, UserType.class, query); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid, u.fullObject\n" + "from\n" + " RUser u\n" + @@ -3302,10 +3200,9 @@ public void test400DereferenceLink() throws Exception { " left join l.target t\n" + "where\n" + " (\n" + - " t.nameCopy.orig like :orig and\n" + - " t.nameCopy.norm like :norm\n" + - " )\n"; - assertEqualsIgnoreWhitespace(expected, real); + " t.nameCopy.orig like :orig escape '!' and\n" + + " t.nameCopy.norm like :norm escape '!'\n" + + " )\n"); } finally { close(session); } @@ -3327,7 +3224,7 @@ public void test402DereferenceLinkedResourceName() throws Exception { .build(); String real = getInterpretedQuery(session, UserType.class, query); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid, u.fullObject\n" + "from\n" + " RUser u\n" + @@ -3335,8 +3232,7 @@ public void test402DereferenceLinkedResourceName() throws Exception { " left join l.target t\n" + " left join t.resourceRef.target t2\n" + "where\n" + - " t2.name.norm like :norm\n"; - assertEqualsIgnoreWhitespace(expected, real); + " t2.name.norm like :norm escape '!'\n"); } finally { close(session); @@ -3379,7 +3275,8 @@ public void test420CaseParentFilter() throws Exception { .item(T_PARENT, F_NAME).eq("Campaign 1") .build(); String real = getInterpretedQuery(session, AccessCertificationCaseType.class, query); - String expected = "select\n" + + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " a.ownerOid, a.id, a.fullObject\n" + "from\n" + " RAccessCertificationCase a\n" + @@ -3388,8 +3285,7 @@ public void test420CaseParentFilter() throws Exception { " (\n" + " o.nameCopy.orig = :orig and\n" + " o.nameCopy.norm = :norm\n" + - " )\n"; - assertEqualsIgnoreWhitespace(expected, real); + " )\n"); } finally { close(session); } @@ -3411,12 +3307,11 @@ public void test500OrderBySingleton() throws Exception { ASCENDING)); String real = getInterpretedQuery(session, UserType.class, query); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid, u.fullObject\n" + "from\n" + " RUser u\n" + - "order by u.activation.administrativeStatus asc"; - assertEqualsIgnoreWhitespace(expected, real); + "order by u.activation.administrativeStatus asc"); } finally { close(session); } @@ -3435,14 +3330,13 @@ public void test510OrderByParentCampaignName() throws Exception { prismContext.queryFactory().createPaging(ItemPath.create(T_PARENT, F_NAME), DESCENDING)); String real = getInterpretedQuery(session, AccessCertificationCaseType.class, query); - String expected = "select\n" + + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " a.ownerOid, a.id, a.fullObject\n" + "from\n" + " RAccessCertificationCase a\n" + " left join a.owner o\n" + - "order by o.nameCopy.orig desc\n"; - - assertEqualsIgnoreWhitespace(expected, real); + "order by o.nameCopy.orig desc\n"); } finally { close(session); } @@ -3463,13 +3357,12 @@ public void test520OrderByTargetName() throws Exception { PrismConstants.T_OBJECT_REFERENCE, F_NAME), ASCENDING)); String real = getInterpretedQuery(session, AccessCertificationCaseType.class, query); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " a.ownerOid, a.id, a.fullObject\n" + "from\n" + " RAccessCertificationCase a\n" + " left join a.targetRef.target t\n" + - "order by t.name.orig asc\n"; - assertEqualsIgnoreWhitespace(expected, real); + "order by t.name.orig asc\n"); } finally { close(session); } @@ -3497,7 +3390,6 @@ public void test550EqualsMultivalue() throws Exception { .build(); getInterpretedQuery(session, UserType.class, query); -// assertEqualsIgnoreWhitespace(expected, real); } finally { close(session); } @@ -3515,7 +3407,7 @@ public void test555PreferredLanguageEqualsCostCenter() throws Exception { .item(UserType.F_PREFERRED_LANGUAGE).eq().item(UserType.F_COST_CENTER) .build(); String real = getInterpretedQuery(session, UserType.class, query); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid, u.fullObject\n" + "from\n" + " RUser u\n" + @@ -3526,8 +3418,7 @@ public void test555PreferredLanguageEqualsCostCenter() throws Exception { " u.preferredLanguage is null and\n" + " u.costCenter is null\n" + " )\n" + - " )\n"; - assertEqualsIgnoreWhitespace(expected, real); + " )\n"); } finally { close(session); } @@ -3546,7 +3437,6 @@ public void test557OrganizationEqualsCostCenter() throws Exception { .item(UserType.F_ORGANIZATION).eq(UserType.F_COST_CENTER) .build(); getInterpretedQuery(session, UserType.class, query); -// assertEqualsIgnoreWhitespace(expected, real); } finally { close(session); } @@ -3570,7 +3460,7 @@ public void test560DecisionsNotAnswered() throws Exception { .build(); String real = getInterpretedQuery(session, AccessCertificationCaseType.class, query); - String expected = "select\n" + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " a.ownerOid, a.id, a.fullObject\n" + "from\n" + " RAccessCertificationCase a\n" @@ -3590,8 +3480,7 @@ public void test560DecisionsNotAnswered() throws Exception { + " )\n" + " ) and\n" + " w.outcome is null\n" - + " )\n"; - assertEqualsIgnoreWhitespace(expected, real); + + " )\n"); } finally { close(session); } @@ -3615,7 +3504,7 @@ public void test562DecisionsNotAnsweredOrderBy() throws Exception { .build(); String real = getInterpretedQuery(session, AccessCertificationCaseType.class, query); - String expected = "select\n" + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " a.ownerOid, a.id, a.fullObject\n" + "from\n" + " RAccessCertificationCase a\n" @@ -3637,8 +3526,7 @@ public void test562DecisionsNotAnsweredOrderBy() throws Exception { + " ) and\n" + " w.outcome is null\n" + " )\n" - + "order by o.nameCopy.orig asc, a.id asc, a.ownerOid asc\n"; - assertEqualsIgnoreWhitespace(expected, real); + + "order by o.nameCopy.orig asc, a.id asc, a.ownerOid asc\n"); } finally { close(session); } @@ -3654,7 +3542,7 @@ public void test563ResourceRef() throws Exception { .build(); String real = getInterpretedQuery(session, UserType.class, query); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid, u.fullObject\n" + "from\n" + " RUser u\n" + @@ -3663,8 +3551,7 @@ public void test563ResourceRef() throws Exception { " (\n" + " a.resourceRef.targetOid = :targetOid and\n" + " a.resourceRef.relation in (:relation)\n" + - " )\n"; - assertEqualsIgnoreWhitespace(expected, real); + " )\n"); } finally { close(session); } @@ -3680,7 +3567,7 @@ public void test565CreatorRef() throws Exception { .build(); String real = getInterpretedQuery(session, UserType.class, query); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid, u.fullObject\n" + "from\n" + " RUser u\n" + @@ -3688,8 +3575,7 @@ public void test565CreatorRef() throws Exception { " (\n" + " u.creatorRef.targetOid = :targetOid and\n" + " u.creatorRef.relation in (:relation)\n" + - " )\n"; - assertEqualsIgnoreWhitespace(expected, real); + " )\n"); } finally { close(session); } @@ -3705,7 +3591,7 @@ public void test568CreateApproverRef() throws Exception { .build(); String real = getInterpretedQuery(session, UserType.class, query); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid, u.fullObject\n" + "from\n" + " RUser u\n" + @@ -3714,8 +3600,7 @@ public void test568CreateApproverRef() throws Exception { " (\n" + " c.targetOid = :targetOid and\n" + " c.relation in (:relation)\n" + - " )\n"; - assertEqualsIgnoreWhitespace(expected, real); + " )\n"); } finally { close(session); } @@ -3731,14 +3616,13 @@ public void test570FullTextSimple() throws Exception { .build(); String real = getInterpretedQuery(session, UserType.class, query); - String expected = "select\n" + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid, u.fullObject\n" + "from\n" + " RUser u\n" + " left join u.textInfoItems t\n" + "where\n" - + " t.text like :text"; - assertEqualsIgnoreWhitespace(expected, real); + + " t.text like :text escape '!'"); } finally { close(session); } @@ -3755,14 +3639,13 @@ public void test571FullTextEmpty() throws Exception { .build(); String real = getInterpretedQuery(session, UserType.class, query); - String expected = "select\n" + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid, u.fullObject\n" + "from\n" + " RUser u\n" + " left join u.textInfoItems t\n" + "where\n" - + " t.text like :text"; - assertEqualsIgnoreWhitespace(expected, real); + + " t.text like :text escape '!'"); } finally { close(session); } @@ -3778,7 +3661,7 @@ public void test575FullTextMulti() throws Exception { .build(); String real = getInterpretedQuery(session, UserType.class, query); - String expected = "select\n" + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid,\n" + " u.fullObject\n" + "from\n" @@ -3787,10 +3670,9 @@ public void test575FullTextMulti() throws Exception { + " left join u.textInfoItems t2\n" + "where\n" + " (\n" - + " t.text like :text and\n" - + " t2.text like :text2\n" - + " )"; - assertEqualsIgnoreWhitespace(expected, real); + + " t.text like :text escape '!' and\n" + + " t2.text like :text2 escape '!'\n" + + " )"); } finally { close(session); } @@ -3808,7 +3690,7 @@ public void test580RedundantBlock() throws Exception { .build(); String real = getInterpretedQuery(session, ShadowType.class, query); - String expected = "select\n" + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " s.oid,\n" + " s.fullObject\n" + "from\n" @@ -3817,8 +3699,7 @@ public void test580RedundantBlock() throws Exception { + " (\n" + " s.nameCopy.orig = :orig and\n" + " s.nameCopy.norm = :norm\n" - + " )\n"; - assertEqualsIgnoreWhitespace(expected, real); + + " )\n"); } finally { close(session); } @@ -3838,7 +3719,7 @@ public void test582TwoRedundantBlocks() throws Exception { .build(); String real = getInterpretedQuery(session, ShadowType.class, query); - String expected = "select\n" + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " s.oid,\n" + " s.fullObject\n" + "from\n" @@ -3847,8 +3728,7 @@ public void test582TwoRedundantBlocks() throws Exception { + " (\n" + " s.nameCopy.orig = :orig and\n" + " s.nameCopy.norm = :norm\n" - + " )\n"; - assertEqualsIgnoreWhitespace(expected, real); + + " )\n"); } finally { close(session); } @@ -3868,7 +3748,7 @@ public void test584RedundantBlocksAndExists() throws Exception { .build(); String real = getInterpretedQuery(session, ShadowType.class, query); - String expected = "select\n" + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " s.oid,\n" + " s.fullObject\n" + "from\n" @@ -3880,8 +3760,7 @@ public void test584RedundantBlocksAndExists() throws Exception { + " s.resourceRef.relation in (:relation)\n" + " ) and\n" + " s.pendingOperationCount > :pendingOperationCount\n" - + " )"; - assertEqualsIgnoreWhitespace(expected, real); + + " )"); } finally { close(session); } @@ -3895,13 +3774,12 @@ public void test600AvailabilityStatus() throws Exception { .item(ResourceType.F_OPERATIONAL_STATE, OperationalStateType.F_LAST_AVAILABILITY_STATUS).eq(AvailabilityStatusType.UP) .build(); String real = getInterpretedQuery(session, ResourceType.class, query); - String expected = "select\n" + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " r.oid, r.fullObject\n" + "from\n" + " RResource r\n" + "where\n" - + " r.operationalState.lastAvailabilityStatus = :lastAvailabilityStatus\n"; - assertEqualsIgnoreWhitespace(expected, real); + + " r.operationalState.lastAvailabilityStatus = :lastAvailabilityStatus\n"); } finally { close(session); } @@ -3916,13 +3794,12 @@ public void test602NullRefSingle() throws Exception { .item(ResourceType.F_CONNECTOR_REF).isNull() .build(); String real = getInterpretedQuery(session, ResourceType.class, query); - String expected = "select\n" + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " r.oid, r.fullObject\n" + "from\n" + " RResource r\n" + "where\n" - + " r.connectorRef is null"; - assertEqualsIgnoreWhitespace(expected, real); + + " r.connectorRef is null"); } finally { close(session); } @@ -3937,15 +3814,14 @@ public void test604NullRefMulti() throws Exception { .item(UserType.F_LINK_REF).isNull() .build(); String real = getInterpretedQuery(session, UserType.class, query); - String expected = "select\n" + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid,\n" + " u.fullObject\n" + "from\n" + " RUser u\n" + " left join u.linkRef l\n" + "where\n" - + " l is null\n"; - assertEqualsIgnoreWhitespace(expected, real); + + " l is null\n"); } finally { close(session); } @@ -3959,13 +3835,12 @@ public void test606NullEqSingle() throws Exception { .item(F_EMPLOYEE_NUMBER).isNull() .build(); String real = getInterpretedQuery(session, UserType.class, query); - String expected = "select\n" + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid, u.fullObject\n" + "from\n" + " RUser u\n" + "where\n" - + " u.employeeNumber is null"; - assertEqualsIgnoreWhitespace(expected, real); + + " u.employeeNumber is null"); } finally { close(session); } @@ -3979,15 +3854,14 @@ public void test610NullEqMulti() throws Exception { .item(UserType.F_EMPLOYEE_TYPE).isNull() .build(); String real = getInterpretedQuery(session, UserType.class, query); - String expected = "select\n" + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid,\n" + " u.fullObject\n" + "from\n" + " RUser u\n" + " left join u.employeeType e\n" + "where\n" - + " e is null"; - assertEqualsIgnoreWhitespace(expected, real); + + " e is null"); } finally { close(session); } @@ -4003,7 +3877,7 @@ public void test612AbstractRoleParameters() throws Exception { .and().item(RoleType.F_DISPLAY_NAME).eqPoly("aaa", "aaa").matchingNorm() .build(); String real = getInterpretedQuery(session, RoleType.class, query); - String expected = "select\n" + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " r.oid, r.fullObject\n" + "from\n" + " RRole r\n" @@ -4012,8 +3886,7 @@ public void test612AbstractRoleParameters() throws Exception { + " r.riskLevel = :riskLevel and\n" + " r.identifier = :identifier and\n" + " r.displayName.norm = :norm\n" - + " )\n"; - assertEqualsIgnoreWhitespace(expected, real); + + " )\n"); } finally { close(session); } @@ -4027,14 +3900,13 @@ public void test614ExistsShadowPendingOperation() throws Exception { .exists(ShadowType.F_PENDING_OPERATION) .build(); String real = getInterpretedQuery(session, ShadowType.class, query); - String expected = "select\n" + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " s.oid,\n" + " s.fullObject\n" + "from\n" + " RShadow s\n" + "where\n" - + " s.pendingOperationCount > :pendingOperationCount"; - assertEqualsIgnoreWhitespace(expected, real); + + " s.pendingOperationCount > :pendingOperationCount"); } finally { close(session); } @@ -4049,15 +3921,15 @@ public void test616OperationFatalError() throws Exception { .eq(OperationResultStatusType.FATAL_ERROR) .build(); String real = getInterpretedQuery(session, ShadowType.class, query); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " s.oid,\n" + " s.fullObject\n" + "from\n" + " RShadow s\n" + " left join s.operationExecutions o\n" + "where\n" - + " o.status = :status\n"; - assertEqualsIgnoreWhitespace(expected, real); + + " o.status = :status\n"); } finally { close(session); } @@ -4073,7 +3945,8 @@ public void test618OperationFatalErrorTimestampSort() throws Exception { .desc(F_OPERATION_EXECUTION, OperationExecutionType.F_TIMESTAMP) .build(); String real = getInterpretedQuery(session, ShadowType.class, query); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " s.oid,\n" + " s.fullObject\n" + "from\n" @@ -4081,8 +3954,7 @@ public void test618OperationFatalErrorTimestampSort() throws Exception { + " left join s.operationExecutions o\n" + "where\n" + " o.status = :status\n" - + "order by o.timestamp desc"; - assertEqualsIgnoreWhitespace(expected, real); + + "order by o.timestamp desc"); } finally { close(session); } @@ -4100,7 +3972,8 @@ public void test619OperationSuccessForGivenTask() throws Exception { .endBlock() .build(); String real = getInterpretedQuery(session, ShadowType.class, query); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " s.oid,\n" + " s.fullObject\n" + "from\n" @@ -4113,8 +3986,7 @@ public void test619OperationSuccessForGivenTask() throws Exception { + " o.taskRef.relation in (:relation)\n" + " ) and\n" + " o.status = :status\n" - + " )"; - assertEqualsIgnoreWhitespace(expected, real); + + " )"); } finally { close(session); } @@ -4132,7 +4004,8 @@ public void test620OperationLastFailures() throws Exception { .endBlock() .build(); String real = getInterpretedQuery(session, ShadowType.class, query); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " s.oid,\n" + " s.fullObject\n" + "from\n" @@ -4142,8 +4015,7 @@ public void test620OperationLastFailures() throws Exception { + " (\n" + " o.status = :status and\n" + " o.timestamp <= :timestamp\n" - + " )"; - assertEqualsIgnoreWhitespace(expected, real); + + " )"); } finally { close(session); } @@ -4157,7 +4029,8 @@ public void test621PersonaRef() throws Exception { .item(FocusType.F_PERSONA_REF).ref("123456") .build(); String real = getInterpretedQuery(session, FocusType.class, query); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " f.oid,\n" + " f.fullObject\n" + "from\n" @@ -4167,8 +4040,7 @@ public void test621PersonaRef() throws Exception { + " (\n" + " p.targetOid = :targetOid and\n" + " p.relation in (:relation)\n" - + " )\n"; - assertEqualsIgnoreWhitespace(expected, real); + + " )\n"); } finally { close(session); } @@ -4182,13 +4054,12 @@ public void test622IgnorableDistinctAndOrderBy() throws Exception { .asc(UserType.F_NAME) .build(); String real = getInterpretedQuery(session, UserType.class, query, false, distinct()); - String expected; - expected = "select u.oid,\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select u.oid,\n" + " u.fullObject\n" + "from\n" + " RUser u\n" - + "order by u.nameCopy.orig asc\n"; - assertEqualsIgnoreWhitespace(expected, real); + + "order by u.nameCopy.orig asc\n"); } finally { close(session); } @@ -4225,10 +4096,10 @@ public void test623ApplicableDistinctAndOrderBy() throws Exception { + " u.fullObject,\n" + " u.nameCopy.orig\n" + "from\n" - + " RUser u left join u.employeeType e where e like :e\n" + + " RUser u left join u.employeeType e where e like :e escape '!'\n" + "order by u.nameCopy.orig asc\n"; } - assertEqualsIgnoreWhitespace(expected, real); + Assertions.assertThat(real).isEqualToIgnoringWhitespace(expected); } finally { close(session); } @@ -4284,7 +4155,7 @@ public void test624DistinctUserWithAssignment() throws Exception { + " )\n" + "order by u.nameCopy.orig asc\n"; } - assertEqualsIgnoreWhitespace(expected, real); + Assertions.assertThat(real).isEqualToIgnoringWhitespace(expected); } finally { close(session); } @@ -4302,7 +4173,8 @@ public void test625CampaignEndTimestamp() throws Exception { .build(); query.setFilter(ObjectQueryUtil.simplify(query.getFilter(), prismContext)); // necessary to remove "not oid()" clause String real = getInterpretedQuery(session, AccessCertificationCampaignType.class, query); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " a.oid,\n" + " a.fullObject\n" + "from\n" @@ -4311,8 +4183,7 @@ public void test625CampaignEndTimestamp() throws Exception { + " (\n" + " a.state = :state and\n" + " a.end < :end\n" - + " )\n"; - assertEqualsIgnoreWhitespace(expected, real); + + " )\n"); } finally { close(session); } @@ -4330,7 +4201,8 @@ public void test626CampaignEndTimestamp2() throws Exception { .maxSize(20) .build(); String real = getInterpretedQuery(session, AccessCertificationCampaignType.class, query); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " a.oid,\n" + " a.fullObject\n" + "from\n" @@ -4340,8 +4212,7 @@ public void test626CampaignEndTimestamp2() throws Exception { + " a.state = :state and\n" + " not a.oid in :oid\n" + " )\n" - + "order by a.end desc"; - assertEqualsIgnoreWhitespace(expected, real); + + "order by a.end desc"); } finally { close(session); } @@ -4354,8 +4225,8 @@ public void test627IgnorableDistinctWithCount() throws Exception { ObjectQuery query = prismContext.queryFor(UserType.class) .build(); String real = getInterpretedQuery(session, UserType.class, query, true, distinct()); - String expected = "select count(u.oid) from RUser u"; - assertEqualsIgnoreWhitespace(expected, real); + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select count(u.oid) from RUser u"); } finally { close(session); } @@ -4369,8 +4240,12 @@ public void test628ApplicableDistinctWithCount() throws Exception { .item(UserType.F_EMPLOYEE_TYPE).startsWith("a") .build(); String real = getInterpretedQuery(session, UserType.class, query, true, distinct()); - String expected = "select count(distinct u.oid) from RUser u left join u.employeeType e where e like :e"; - assertEqualsIgnoreWhitespace(expected, real); + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select" + + " count(distinct u.oid)" + + " from RUser u" + + " left join u.employeeType e" + + " where e like :e escape '!'"); } finally { close(session); } @@ -4385,13 +4260,12 @@ public void test630OidEqTest() throws Exception { .build(); String real = getInterpretedQuery(session, ObjectType.class, query, false); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " o.oid, o.fullObject\n" + "from\n" + " RObject o\n" + "where\n" + - " o.oid = :oid\n"; - assertEqualsIgnoreWhitespace(expected, real); + " o.oid = :oid\n"); } finally { close(session); } @@ -4406,13 +4280,12 @@ public void test631OwnerOidEqTest() throws Exception { .build(); String real = getInterpretedQuery(session, AccessCertificationCaseType.class, query, false); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " a.ownerOid, a.id, a.fullObject\n" + "from\n" + " RAccessCertificationCase a\n" + "where\n" + - " a.ownerOid = :ownerOid"; - assertEqualsIgnoreWhitespace(expected, real); + " a.ownerOid = :ownerOid"); } finally { close(session); } @@ -4428,13 +4301,12 @@ public void test632OidGeLtTest() throws Exception { .build(); String real = getInterpretedQuery(session, ObjectType.class, query, false); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " o.oid, o.fullObject\n" + "from\n" + " RObject o\n" + "where\n" + - " ( o.oid >= :oid and o.oid < :oid2 )\n"; - assertEqualsIgnoreWhitespace(expected, real); + " ( o.oid >= :oid and o.oid < :oid2 )\n"); } finally { close(session); } @@ -4447,15 +4319,13 @@ public void test700QueryOrderByNameOrigLimit20() throws Exception { try { ObjectQuery query = prismContext.queryFor(UserType.class).asc(UserType.F_NAME).maxSize(20).build(); - String expected = "select\n" + + String real = getInterpretedQuery(session, UserType.class, query); + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid, u.fullObject\n" + "from\n" + " RUser u\n" + "order by\n" + - "u.nameCopy.orig asc"; - - String real = getInterpretedQuery(session, UserType.class, query); - assertEqualsIgnoreWhitespace(expected, real); + "u.nameCopy.orig asc"); } finally { close(session); } @@ -4468,15 +4338,13 @@ public void test702QueryOrderByNameOrigLimit20() throws Exception { try { ObjectQuery query = prismContext.queryFor(RoleType.class).asc(RoleType.F_NAME).maxSize(20).build(); - String expected = "select\n" + + String real = getInterpretedQuery(session, RoleType.class, query); + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " r.oid, r.fullObject\n" + "from\n" + " RRole r\n" + "order by\n" + - "r.nameCopy.orig asc"; - - String real = getInterpretedQuery(session, RoleType.class, query); - assertEqualsIgnoreWhitespace(expected, real); + "r.nameCopy.orig asc"); } finally { close(session); } @@ -4491,7 +4359,8 @@ public void test704QueryTasksForArchetypeRef() throws Exception { .item(AssignmentHolderType.F_ARCHETYPE_REF).ref("oid1") .build(); - String expected = "select\n" + String real = getInterpretedQuery(session, TaskType.class, query); + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " t.oid,\n" + " t.fullObject\n" + "from\n" @@ -4501,10 +4370,7 @@ public void test704QueryTasksForArchetypeRef() throws Exception { + " (\n" + " a.targetOid = :targetOid and\n" + " a.relation in (:relation)\n" - + " )"; - - String real = getInterpretedQuery(session, TaskType.class, query); - assertEqualsIgnoreWhitespace(expected, real); + + " )"); } finally { close(session); } @@ -4515,14 +4381,12 @@ public void test706QuerySearchForFocusType() throws Exception { Session session = open(); try { - String expected = "select\n" + String real = getInterpretedQuery(session, FocusType.class, (ObjectQuery) null); + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " f.oid,\n" + " f.fullObject\n" + "from\n" - + " RFocus f"; - - String real = getInterpretedQuery(session, FocusType.class, (ObjectQuery) null); - assertEqualsIgnoreWhitespace(expected, real); + + " RFocus f"); } finally { close(session); } @@ -4533,19 +4397,17 @@ public void test708QuerySearchForAssignmentHolderType() throws Exception { Session session = open(); try { - String expected = "select\n" + RQueryImpl rQuery = (RQueryImpl) getInterpretedQueryWhole(session, AssignmentHolderType.class, null, false, null); + String real = rQuery.getQuery().getQueryString(); + System.out.println("Query parameters:\n" + rQuery.getQuerySource().getParameters()); + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " o.oid,\n" + " o.fullObject\n" + "from\n" + " RObject o\n" + "where\n" - + " o.objectTypeClass in (:objectTypeClass)"; - - RQueryImpl rQuery = (RQueryImpl) getInterpretedQueryWhole(session, AssignmentHolderType.class, null, false, null); - String real = rQuery.getQuery().getQueryString(); - System.out.println("Query parameters:\n" + rQuery.getQuerySource().getParameters()); - - assertEqualsIgnoreWhitespace(expected, real); + + " o.objectTypeClass in (:objectTypeClass)"); } finally { close(session); @@ -4557,14 +4419,12 @@ public void test720QuerySearchForObjectType() throws Exception { Session session = open(); try { - String expected = "select\n" + String real = getInterpretedQuery(session, ObjectType.class, (ObjectQuery) null); + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " o.oid,\n" + " o.fullObject\n" + "from\n" - + " RObject o"; - - String real = getInterpretedQuery(session, ObjectType.class, (ObjectQuery) null); - assertEqualsIgnoreWhitespace(expected, real); + + " RObject o"); } finally { close(session); } @@ -4578,15 +4438,13 @@ public void test725QueryNameNormAsString() throws Exception { ObjectQuery query = prismContext.queryFor(UserType.class) .item(F_NAME).eq("asdf").matchingNorm().build(); - String expected = "select\n" + + String real = getInterpretedQuery(session, UserType.class, query); + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid, u.fullObject\n" + "from\n" + " RUser u\n" + "where\n" + - " u.nameCopy.norm = :norm"; - - String real = getInterpretedQuery(session, UserType.class, query); - assertEqualsIgnoreWhitespace(expected, real); + " u.nameCopy.norm = :norm"); } finally { close(session); } @@ -4600,7 +4458,8 @@ public void test730QueryWorkItemsByAssignee() throws Exception { .item(CaseWorkItemType.F_ASSIGNEE_REF).ref("123") .build(); String real = getInterpretedQuery(session, CaseWorkItemType.class, q, false); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " c.ownerOid,\n" + " c.id\n" + "from\n" @@ -4610,8 +4469,7 @@ public void test730QueryWorkItemsByAssignee() throws Exception { + " (\n" + " a.targetOid = :targetOid and\n" + " a.relation in (:relation)\n" - + " )"; - assertEqualsIgnoreWhitespace(expected, real); + + " )"); } finally { close(session); } @@ -4625,7 +4483,8 @@ public void test732QueryWorkItemsByCandidate() throws Exception { .item(CaseWorkItemType.F_CANDIDATE_REF).ref("123") .build(); String real = getInterpretedQuery(session, CaseWorkItemType.class, q, false); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " c.ownerOid,\n" + " c.id\n" + "from\n" @@ -4635,8 +4494,7 @@ public void test732QueryWorkItemsByCandidate() throws Exception { + " (\n" + " c2.targetOid = :targetOid and\n" + " c2.relation in (:relation)\n" - + " )"; - assertEqualsIgnoreWhitespace(expected, real); + + " )"); } finally { close(session); } @@ -4651,14 +4509,14 @@ public void test733QueryNameNull() throws Exception { .item(F_NAME).isNull() .build(); String real = getInterpretedQuery(session, UserType.class, q, false); - String expected = "select\n" + + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid,\n" + " u.fullObject\n" + "from\n" + " RUser u\n" + "where\n" - + " 1=0\n"; - assertEqualsIgnoreWhitespace(expected, real); + + " 1=0\n"); } finally { close(session); } @@ -4690,8 +4548,7 @@ public void test734QueryWithMultiValueItemPathForOrdering() throws Exception { q.setPaging(paging); String real = getInterpretedQuery(session, ObjectType.class, q, false); - String expected = ""; - assertEqualsIgnoreWhitespace(expected, real); + Assertions.assertThat(real).isEqualToIgnoringWhitespace(""); } finally { close(session); } @@ -4707,15 +4564,13 @@ public void test735QueryPasswordCreateTimestamp() throws Exception { PasswordType.F_METADATA, MetadataType.F_CREATE_TIMESTAMP)) .gt(DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar())).build(); - String expected = "select\n" + + String real = getInterpretedQuery(session, UserType.class, query); + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid, u.fullObject\n" + "from\n" + " RUser u\n" + "where\n" + - " u.passwordCreateTimestamp > :passwordCreateTimestamp"; - - String real = getInterpretedQuery(session, UserType.class, query); - assertEqualsIgnoreWhitespace(expected, real); + " u.passwordCreateTimestamp > :passwordCreateTimestamp"); } finally { close(session); } @@ -4730,15 +4585,14 @@ public void test736QueryPolyStringGtOrig() throws Exception { .item(F_NAME).gt("J").matchingOrig() .build(); - String expected = "select\n" + String real = getInterpretedQuery(session, UserType.class, query); + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid,\n" + " u.fullObject\n" + "from\n" + " RUser u\n" + "where\n" - + " u.nameCopy.orig > :orig\n"; - String real = getInterpretedQuery(session, UserType.class, query); - assertEqualsIgnoreWhitespace(expected, real); + + " u.nameCopy.orig > :orig\n"); } finally { close(session); } @@ -4753,15 +4607,14 @@ public void test737QueryPolyStringGtNorm() throws Exception { .item(F_NAME).gt("j").matchingNorm() .build(); - String expected = "select\n" + String real = getInterpretedQuery(session, UserType.class, query); + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid,\n" + " u.fullObject\n" + "from\n" + " RUser u\n" + "where\n" - + " u.nameCopy.norm > :norm"; - String real = getInterpretedQuery(session, UserType.class, query); - assertEqualsIgnoreWhitespace(expected, real); + + " u.nameCopy.norm > :norm"); } finally { close(session); } @@ -4776,7 +4629,8 @@ public void test738QueryPolyStringGtStrict() throws Exception { .item(F_NAME).gt("j").matchingStrict() .build(); - String expected = "select\n" + String real = getInterpretedQuery(session, UserType.class, query); + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid,\n" + " u.fullObject\n" + "from\n" @@ -4785,9 +4639,7 @@ public void test738QueryPolyStringGtStrict() throws Exception { + " (\n" + " u.nameCopy.orig > :orig and\n" + " u.nameCopy.norm > :norm\n" - + " )\n"; - String real = getInterpretedQuery(session, UserType.class, query); - assertEqualsIgnoreWhitespace(expected, real); + + " )\n"); } finally { close(session); } @@ -4803,7 +4655,8 @@ public void test739QueryPolyStringGtDefault() throws Exception { .item(F_NAME).gt("j") .build(); - String expected = "select\n" + String real = getInterpretedQuery(session, UserType.class, query); + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid,\n" + " u.fullObject\n" + "from\n" @@ -4812,9 +4665,7 @@ public void test739QueryPolyStringGtDefault() throws Exception { + " (\n" + " u.nameCopy.orig > :orig and\n" + " u.nameCopy.norm > :norm\n" - + " )\n"; - String real = getInterpretedQuery(session, UserType.class, query); - assertEqualsIgnoreWhitespace(expected, real); + + " )\n"); } finally { close(session); } @@ -4829,15 +4680,14 @@ public void test740QueryStringGtIgnoreCase() throws Exception { .item(F_EMPLOYEE_NUMBER).gt("j").matchingCaseIgnore() .build(); - String expected = "select\n" + String real = getInterpretedQuery(session, UserType.class, query); + Assertions.assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid,\n" + " u.fullObject\n" + "from\n" + " RUser u\n" + "where\n" - + " lower(u.employeeNumber) > :employeeNumber"; - String real = getInterpretedQuery(session, UserType.class, query); - assertEqualsIgnoreWhitespace(expected, real); + + " lower(u.employeeNumber) > :employeeNumber"); } finally { close(session); } @@ -4950,16 +4800,4 @@ private RQuery getInterpretedQueryWhole(Session sessio } return rQuery; } - - private void assertEqualsIgnoreWhitespace(String expected, String real) { - logger.info("exp. query>\n{}\nreal query>\n{}", expected, real); - String expNorm = StringUtils.normalizeSpace(expected); - String realNorm = StringUtils.normalizeSpace(real); - if (!expNorm.equals(realNorm)) { - String m = "Generated query is not correct. Expected:\n" + expected + "\nActual:\n" + real + "\n\nNormalized versions:\n\n" + - "Expected: " + expNorm + "\nActual: " + realNorm + "\n"; - logger.error("{}", m); - throw new AssertionError(m); - } - } } diff --git a/repo/repo-sql-impl/src/main/java/com/evolveum/midpoint/repo/sql/query/hqm/RootHibernateQuery.java b/repo/repo-sql-impl/src/main/java/com/evolveum/midpoint/repo/sql/query/hqm/RootHibernateQuery.java index 26eb55e643e..06b6c46ef33 100644 --- a/repo/repo-sql-impl/src/main/java/com/evolveum/midpoint/repo/sql/query/hqm/RootHibernateQuery.java +++ b/repo/repo-sql-impl/src/main/java/com/evolveum/midpoint/repo/sql/query/hqm/RootHibernateQuery.java @@ -1,10 +1,9 @@ /* - * Copyright (c) 2010-2015 Evolveum and contributors + * Copyright (C) 2010-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. */ - package com.evolveum.midpoint.repo.sql.query.hqm; import java.util.Collection; @@ -12,6 +11,7 @@ import java.util.List; import java.util.Map; +import org.apache.commons.lang3.StringUtils; import org.hibernate.Session; import org.hibernate.criterion.MatchMode; import org.hibernate.query.Query; @@ -72,6 +72,7 @@ private String findFreeName(String prefix) { } } + @SuppressWarnings("rawtypes") public Query getAsHqlQuery(Session session) { String text = getAsHqlText(0, distinct); LOGGER.trace("HQL text generated:\n{}", text); @@ -102,6 +103,7 @@ public Query getAsHqlQuery(Session session) { query.setFirstResult(firstResult); } if (resultTransformer != null) { + //noinspection deprecation query.setResultTransformer(resultTransformer); } return query; @@ -166,7 +168,13 @@ public Condition createSimpleComparisonCondition(String propertyPath, Object val return new SimpleComparisonCondition(this, propertyPath, value, comparatorSymbol, ignoreCase); } + public static final char LIKE_ESCAPE_CHAR = '!'; + private static final String LIKE_ESCAPED_CHARS = "_%" + LIKE_ESCAPE_CHAR; + public Condition createLike(String propertyPath, String value, MatchMode matchMode, boolean ignoreCase) { + if (StringUtils.containsAny(value, LIKE_ESCAPED_CHARS)) { + value = escapeLikeValue(value); + } switch (matchMode) { case ANYWHERE: value = "%" + value + "%"; @@ -183,6 +191,19 @@ public Condition createLike(String propertyPath, String value, MatchMode matchMo return new SimpleComparisonCondition(this, propertyPath, value, "like", ignoreCase); } + private String escapeLikeValue(String value) { + StringBuilder sb = new StringBuilder(value); + for (int i = 0; i < sb.length(); i++) { + if (LIKE_ESCAPED_CHARS.indexOf(sb.charAt(i)) == -1) { + continue; + } + + sb.insert(i, LIKE_ESCAPE_CHAR); + i += 1; + } + return sb.toString(); + } + public AndCondition createAnd(Condition... conditions) { return new AndCondition(this, conditions); } diff --git a/repo/repo-sql-impl/src/main/java/com/evolveum/midpoint/repo/sql/query/hqm/condition/SimpleComparisonCondition.java b/repo/repo-sql-impl/src/main/java/com/evolveum/midpoint/repo/sql/query/hqm/condition/SimpleComparisonCondition.java index 1f3c4460ebc..c97b69bcafe 100644 --- a/repo/repo-sql-impl/src/main/java/com/evolveum/midpoint/repo/sql/query/hqm/condition/SimpleComparisonCondition.java +++ b/repo/repo-sql-impl/src/main/java/com/evolveum/midpoint/repo/sql/query/hqm/condition/SimpleComparisonCondition.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2015 Evolveum and contributors + * Copyright (C) 2010-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. @@ -49,6 +49,12 @@ public void dumpToHql(StringBuilder sb, int indent) { String parameterNamePrefix = createParameterName(propertyPath); String parameterName = rootHibernateQuery.addParameter(parameterNamePrefix, finalPropertyValue); sb.append(finalPropertyPath).append(" ").append(operator).append(" :").append(parameterName); + // See RootHibernateQuery.createLike for the other part of the solution. + // Design note: probably a bit cyclic dependency, but the knowledge about escaping still + // needs to be on both places anyway, so it's less messy than an additional parameter. + if (operator.equals("like")) { + sb.append(" escape '" + RootHibernateQuery.LIKE_ESCAPE_CHAR + '\''); + } } @Override From ce3f1370b362f310fca931a16d64839ddf73fe50 Mon Sep 17 00:00:00 2001 From: lskublik Date: Fri, 18 Sep 2020 10:55:35 +0200 Subject: [PATCH 9/9] using iterator in dashboard service (cleanup code) --- .../model/impl/controller/DashboardServiceImpl.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/controller/DashboardServiceImpl.java b/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/controller/DashboardServiceImpl.java index 07ee54a4c88..f1391df3571 100644 --- a/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/controller/DashboardServiceImpl.java +++ b/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/controller/DashboardServiceImpl.java @@ -601,17 +601,18 @@ public List searchObjectFromCollection(CollectionRefSpecif private List evaluateCondition(ExpressionType condition, List values, Task task, OperationResult result) throws CommunicationException, ObjectNotFoundException, SchemaException, SecurityViolationException, ConfigurationException, ExpressionEvaluationException { - List newValues = new ArrayList(); - for (T value : values) { + Iterator iterator = values.iterator(); + while (iterator.hasNext()) { + T value = iterator.next(); ExpressionVariables variables = new ExpressionVariables(); variables.put(ExpressionConstants.VAR_OBJECT, value, value.getClass()); PrismPropertyValue conditionValue = ExpressionUtil.evaluateCondition(variables, condition, null, expressionFactory, "Evaluate condition", task, result); - if (conditionValue != null && Boolean.TRUE.equals(conditionValue.getRealValue())) { - newValues.add(value); + if (conditionValue == null || Boolean.FALSE.equals(conditionValue.getRealValue())) { + iterator.remove(); } } - return newValues; + return values; } @Override