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