Skip to content

Commit

Permalink
Fixed ownerRef collision (campaign vs role). Reenabled and fixed Quer…
Browse files Browse the repository at this point in the history
…yInterpreter2Test.
  • Loading branch information
mederly committed Mar 1, 2016
1 parent a2b4151 commit f71f924
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 112 deletions.
Expand Up @@ -60,28 +60,7 @@
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SecurityViolationException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentPolicyEnforcementType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AuthorizationDecisionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AuthorizationPhaseType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AuthorizationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.CredentialsPolicyType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.CredentialsType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.MetadataType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectSpecificationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OwnedObjectSpecificationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.PasswordType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityQuestionsCredentialsPolicyType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SpecialObjectSpecificationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType;

import org.springframework.test.annotation.DirtiesContext;
Expand Down Expand Up @@ -651,6 +630,7 @@ public void test201AutzJackSuperuserRole() throws Exception {
assertModifyAllow();
assertDeleteAllow();

assertSearch(AccessCertificationCampaignType.class, null, 2); // 2 campaigns there
assertReadCertCasesAllow();

RoleSelectionSpecification roleSpec = getAssignableRoleSpecification(getUser(USER_JACK_OID));
Expand Down
Expand Up @@ -1377,7 +1377,7 @@ public void test335OwnerInOidTest() throws Exception {

String real = getInterpretedQuery2(session, AccessCertificationCaseType.class, query, false);
String expected = "select\n" +
" a.fullObject\n" +
" a.fullObject, a.ownerOid\n" +
"from\n" +
" RAccessCertificationCase a\n" +
"where\n" +
Expand Down Expand Up @@ -2279,30 +2279,6 @@ public void test590QueryObjectypeByTypeAndReference() throws Exception {
public void test600QueryObjectypeByTypeComplex() throws Exception {
Session session = open();
try {
// Criteria main = session.createCriteria(RObject.class, "o");
// ProjectionList projections = Projections.projectionList();
// addFullObjectProjectionList("o", projections, false);
// main.setProjection(projections);
//
// Conjunction c1 = Restrictions.conjunction();
// c1.add(Restrictions.eq("o." + RObject.F_OBJECT_TYPE_CLASS, RObjectType.USER));
// Criterion e1 = Restrictions.and(Restrictions.eq("o.localityUser.orig", "Caribbean"),
// Restrictions.eq("o.localityUser.norm", "caribbean"));
// Criterion e2 = Restrictions.and(Restrictions.eq("o.localityUser.orig", "Adriatic"),
// Restrictions.eq("o.localityUser.norm", "adriatic"));
// c1.add(Restrictions.or(e1, e2));
//
// Conjunction c2 = Restrictions.conjunction();
// c2.add(Restrictions.eq("o." + RObject.F_OBJECT_TYPE_CLASS, RObjectType.ORG));
// Criteria o1 = main.createCriteria("o.orgType", "o1", JoinType.LEFT_OUTER_JOIN);
// c2.add(Restrictions.eq("o1.elements", "functional"));
//
// Criterion c3 = Restrictions.eq("o." + RObject.F_OBJECT_TYPE_CLASS, RObjectType.REPORT);
//
// main.add(Restrictions.or(c1, c2, c3));
// String expected = HibernateToSqlTranslator.toSql(main);


EqualFilter eq1 = EqualFilter.createEqual(UserType.F_LOCALITY, UserType.class, prismContext,
new PolyString("Caribbean", "caribbean"));
EqualFilter eq2 = EqualFilter.createEqual(UserType.F_LOCALITY, UserType.class, prismContext,
Expand Down Expand Up @@ -2387,6 +2363,55 @@ public void test605QueryObjectypeByTypeAndReference() throws Exception {
}
}

@Test
public void test606QueryObjectypeByTypeAndOwnerRefOverloaded() throws Exception {
Session session = open();
try {
PrismObjectDefinition<RoleType> roleDef =
prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(RoleType.class);
PrismObjectDefinition<AccessCertificationCampaignType> campaignDef =
prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(AccessCertificationCampaignType.class);
ObjectQuery query = QueryBuilder.queryFor(ObjectType.class, prismContext)
.id("c0c010c0-d34d-b33f-f00d-111111111111")
.or().type(RoleType.class).item(roleDef, RoleType.F_OWNER_REF).ref("c0c010c0-d34d-b33f-f00d-111111111111")
.or().type(AccessCertificationCampaignType.class).item(campaignDef, AccessCertificationCampaignType.F_OWNER_REF).ref("c0c010c0-d34d-b33f-f00d-111111111111")
.build();
String real = getInterpretedQuery2(session, ObjectType.class, query);
String expected = "select\n"
+ " o.fullObject,\n"
+ " o.stringsCount,\n"
+ " o.longsCount,\n"
+ " o.datesCount,\n"
+ " o.referencesCount,\n"
+ " o.polysCount,\n"
+ " o.booleansCount\n"
+ "from\n"
+ " RObject o\n"
+ "where\n"
+ " (\n"
+ " o.oid in :oid or\n"
+ " (\n"
+ " o.objectTypeClass = :objectTypeClass and\n"
+ " (\n"
+ " o.ownerRef.targetOid = :targetOid and\n"
+ " o.ownerRef.relation = :relation\n"
+ " )\n"
+ " ) or\n"
+ " (\n"
+ " o.objectTypeClass = :objectTypeClass2 and\n"
+ " (\n"
+ " o.ownerRefCampaign.targetOid = :targetOid2 and\n"
+ " o.ownerRefCampaign.relation = :relation2\n"
+ " )\n"
+ " )\n"
+ " )\n";

assertEqualsIgnoreWhitespace(expected, real);
} finally {
close(session);
}
}

@Test(expectedExceptions = QueryException.class)
public void test610QueryGenericClob() throws Exception {
Session session = open();
Expand Down Expand Up @@ -2588,7 +2613,7 @@ public void test700QueryCertCaseAll() throws Exception {
try {
String real = getInterpretedQuery2(session, AccessCertificationCaseType.class, (ObjectQuery) null, false);
String expected = "select\n" +
" a.fullObject\n" +
" a.fullObject, a.ownerOid\n" +
"from\n" +
" RAccessCertificationCase a\n";
assertEqualsIgnoreWhitespace(expected, real);
Expand All @@ -2605,7 +2630,7 @@ public void test710QueryCertCaseOwner() throws Exception {
ObjectQuery query = ObjectQuery.createObjectQuery(filter);
String real = getInterpretedQuery2(session, AccessCertificationCaseType.class, query, false);
String expected = "select\n" +
" a.fullObject\n" +
" a.fullObject, a.ownerOid\n" +
"from\n" +
" RAccessCertificationCase a\n" +
"where\n" +
Expand All @@ -2628,7 +2653,7 @@ public void test720QueryCertCaseOwnerAndTarget() throws Exception {
ObjectQuery query = ObjectQuery.createObjectQuery(filter);
String real = getInterpretedQuery2(session, AccessCertificationCaseType.class, query, false);
String expected = "select\n" +
" a.fullObject\n" +
" a.fullObject, a.ownerOid\n" +
"from\n" +
" RAccessCertificationCase a\n" +
"where\n" +
Expand All @@ -2655,7 +2680,7 @@ public void test730QueryCertCaseReviewer() throws Exception {
ObjectQuery query = ObjectQuery.createObjectQuery(filter);
String real = getInterpretedQuery2(session, AccessCertificationCaseType.class, query, false);
String expected = "select\n" +
" a.fullObject\n" +
" a.fullObject, a.ownerOid\n" +
"from\n" +
" RAccessCertificationCase a\n" +
" left join a.reviewerRef r\n" +
Expand Down Expand Up @@ -2688,17 +2713,17 @@ public void test740QueryCertCasesByCampaignOwner() throws Exception {

String real = getInterpretedQuery2(session, AccessCertificationCaseType.class, query, false);
String expected = "select\n" +
" a.fullObject\n" +
" a.fullObject, a.ownerOid\n" +
"from\n" +
" RAccessCertificationCase a\n" +
" left join a.owner o\n" +
"where\n" +
" (\n" +
" o.oid in :oid or\n" +
" (\n" +
" o.ownerRef.targetOid = :targetOid and\n" +
" o.ownerRef.relation = :relation and\n" +
" o.ownerRef.type = :type\n" +
" o.ownerRefCampaign.targetOid = :targetOid and\n" +
" o.ownerRefCampaign.relation = :relation and\n" +
" o.ownerRefCampaign.type = :type\n" +
" )\n" +
" )\n";
assertEqualsIgnoreWhitespace(expected, real);
Expand All @@ -2720,7 +2745,7 @@ public void test735QueryCertCaseReviewerAndEnabled() throws Exception {
String real = getInterpretedQuery2(session, AccessCertificationCaseType.class, query, false);
String expected =
"select\n" +
" a.fullObject\n" +
" a.fullObject, a.ownerOid\n" +
"from\n" +
" RAccessCertificationCase a\n" +
" left join a.reviewerRef r\n" +
Expand Down Expand Up @@ -2762,7 +2787,7 @@ public void test745QueryCertCaseReviewerAndEnabledByDeadlineAndOidAsc() throws E
String real = getInterpretedQuery2(session, AccessCertificationCaseType.class, query, false);
String expected =
"select\n" +
" a.fullObject\n" +
" a.fullObject, a.ownerOid\n" +
"from\n" +
" RAccessCertificationCase a\n" +
" left join a.reviewerRef r\n" +
Expand Down Expand Up @@ -2808,7 +2833,7 @@ public void test747QueryCertCaseReviewerAndEnabledByRequestedDesc() throws Excep
String real = getInterpretedQuery2(session, AccessCertificationCaseType.class, query, false);

String expected = "select\n" +
" a.fullObject\n" +
" a.fullObject, a.ownerOid\n" +
"from\n" +
" RAccessCertificationCase a\n" +
" left join a.reviewerRef r\n" +
Expand Down Expand Up @@ -2954,7 +2979,7 @@ public void test770CaseParentFilter() throws Exception {

String real = getInterpretedQuery2(session, AccessCertificationCaseType.class, query);
String expected = "select\n" +
" a.fullObject\n" +
" a.fullObject, a.ownerOid\n" +
"from\n" +
" RAccessCertificationCase a\n" +
" left join a.owner o\n" +
Expand Down Expand Up @@ -3017,7 +3042,7 @@ public void test810OrderByParentCampaignName() throws Exception {

String real = getInterpretedQuery2(session, AccessCertificationCaseType.class, query);
String expected = "select\n" +
" a.fullObject\n" +
" a.fullObject, a.ownerOid\n" +
"from\n" +
" RAccessCertificationCase a\n" +
" left join a.owner o\n" +
Expand Down Expand Up @@ -3045,7 +3070,7 @@ public void test820OrderByTargetName() throws Exception {

String real = getInterpretedQuery2(session, AccessCertificationCaseType.class, query);
String expected = "select\n" +
" a.fullObject\n" +
" a.fullObject, a.ownerOid\n" +
"from\n" +
" RAccessCertificationCase a\n" +
" left join a.targetRef.target t\n" +
Expand Down Expand Up @@ -3157,37 +3182,6 @@ public void test920DecisionsNotAnswered() throws Exception {
/*
* ### AccCertCase: Exists (decision: reviewerRef = XYZ and stage = ../stage and response is null or response = NO_RESPONSE)
*/
ObjectQuery query0 = ObjectQuery.createObjectQuery(
ExistsFilter.createExists(
new ItemPath(F_DECISION),
AccessCertificationCaseType.class,
prismContext,
AndFilter.createAnd(
RefFilter.createReferenceEqual(
AccessCertificationDecisionType.F_REVIEWER_REF,
AccessCertificationCaseType.class,
prismContext,
"123456"),
EqualFilter.createEqual(
new ItemPath(F_STAGE_NUMBER),
AccessCertificationDecisionType.class,
prismContext,
null,
new ItemPath(T_PARENT, F_CURRENT_STAGE_NUMBER)
),
OrFilter.createOr(
EqualFilter.createEqual(
AccessCertificationDecisionType.F_RESPONSE,
AccessCertificationDecisionType.class,
prismContext, null),
EqualFilter.createEqual(
AccessCertificationDecisionType.F_RESPONSE,
AccessCertificationDecisionType.class,
prismContext, NO_RESPONSE)
)
)
)
);
ObjectQuery query = QueryBuilder.queryFor(AccessCertificationCaseType.class, prismContext)
.exists(F_DECISION)
.block()
Expand All @@ -3202,7 +3196,7 @@ public void test920DecisionsNotAnswered() throws Exception {

String real = getInterpretedQuery2(session, AccessCertificationCaseType.class, query);
String expected = "select\n" +
" a.fullObject\n" +
" a.fullObject, a.ownerOid\n" +
"from\n" +
" RAccessCertificationCase a\n" +
" left join a.decision d\n" +
Expand Down Expand Up @@ -3252,7 +3246,7 @@ public void test925DecisionsNotAnsweredOrderBy() throws Exception {

String real = getInterpretedQuery2(session, AccessCertificationCaseType.class, query);
String expected = "select\n" +
" a.fullObject\n" +
" a.fullObject, a.ownerOid\n" +
"from\n" +
" RAccessCertificationCase a\n" +
" left join a.decision d\n" +
Expand Down
2 changes: 1 addition & 1 deletion repo/repo-sql-impl-test/testng-integration.xml
Expand Up @@ -26,7 +26,7 @@
</test>
<test name="Query Add Tests" parallel="false" preserve-order="true" verbose="10" enabled="true">
<classes>
<!--<class name="com.evolveum.midpoint.repo.sql.QueryInterpreter2Test"/>-->
<class name="com.evolveum.midpoint.repo.sql.QueryInterpreter2Test"/>
<class name="com.evolveum.midpoint.repo.sql.DeleteTest"/>
<class name="com.evolveum.midpoint.repo.sql.AddGetObjectTest"/>
<class name="com.evolveum.midpoint.repo.sql.AddOverwriteTest"/>
Expand Down

0 comments on commit f71f924

Please sign in to comment.