Skip to content

Commit

Permalink
MID-2133 test for assignment/extension/boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Apr 4, 2015
1 parent 7023ef8 commit 09db6c9
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 7 deletions.
Expand Up @@ -16,9 +16,7 @@

package com.evolveum.midpoint.repo.sql;

import com.evolveum.midpoint.prism.Objectable;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismObjectDefinition;
import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.match.PolyStringNormMatchingRule;
import com.evolveum.midpoint.prism.match.PolyStringOrigMatchingRule;
import com.evolveum.midpoint.prism.path.ItemPath;
Expand All @@ -40,6 +38,7 @@
import com.evolveum.midpoint.schema.MidPointPrismContextFactory;
import com.evolveum.midpoint.schema.constants.MidPointConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.util.DOMUtil;
import com.evolveum.midpoint.util.PrettyPrinter;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
Expand Down Expand Up @@ -80,6 +79,8 @@ public class QueryInterpreterTest extends BaseSQLRepoTest {
private static final Trace LOGGER = TraceManager.getTrace(QueryInterpreterTest.class);
private static final File TEST_DIR = new File("./src/test/resources/query");

private static final QName SKIP_AUTOGENERATION = new QName("http://example.com/p", "skipAutogeneration");

@BeforeSuite
public void setup() throws SchemaException, SAXException, IOException {
PrettyPrinter.setDefaultNamespacePrefix(MidPointConstants.NS_MIDPOINT_PUBLIC_PREFIX);
Expand Down Expand Up @@ -1004,7 +1005,6 @@ public void asdf() throws Exception {
}
}


@Test
public void test100ActivationQuery() throws Exception {
PrismObjectDefinition<UserType> focusObjectDef = prismContext.getSchemaRegistry()
Expand Down Expand Up @@ -1665,7 +1665,7 @@ public void test430QueryGenericBoolean() throws Exception {
//and
Conjunction c2 = Restrictions.conjunction();
c2.add(Restrictions.eq("b.ownerType", RObjectExtensionType.EXTENSION));
c2.add(Restrictions.eq("b.name", new QName("http://example.com/p", "skipAutogeneration")));
c2.add(Restrictions.eq("b.name", SKIP_AUTOGENERATION));
c2.add(Restrictions.eq("b.value", true));

main.add(c2);
Expand All @@ -1676,7 +1676,7 @@ public void test430QueryGenericBoolean() throws Exception {
String expected = HibernateToSqlTranslator.toSql(main);

EqualFilter eq = EqualFilter.createEqual(
new ItemPath(ObjectType.F_EXTENSION, new QName("http://example.com/p", "skipAutogeneration")),
new ItemPath(ObjectType.F_EXTENSION, SKIP_AUTOGENERATION),
GenericObjectType.class, prismContext, true);

String real = getInterpretedQuery(session, GenericObjectType.class, ObjectQuery.createObjectQuery(eq));
Expand Down Expand Up @@ -1706,4 +1706,61 @@ public void test430QueryGenericBoolean() throws Exception {
close(session);
}
}

@Test(enabled=false)
public void test440queryAssignmentExtensionBoolean() throws Exception {
Session session = open();
try {
Criteria main = session.createCriteria(RUser.class, "u");
Criteria a = main.createCriteria("assignments", "a");
a.add(Restrictions.eq("a.assignmentOwner", RAssignmentOwner.FOCUS));
Criteria e = a.createCriteria("a.extension");

Criteria b = e.createCriteria("booleans", "b");

Conjunction c1 = Restrictions.conjunction();
c1.add(Restrictions.eq("b.extensionType", RAssignmentExtensionType.EXTENSION));
c1.add(Restrictions.eq("b.name", SKIP_AUTOGENERATION));
c1.add(Restrictions.eq("b.value", true));

main.add(c1);
main.setProjection(Projections.property("u.fullObject"));

String expected = HibernateToSqlTranslator.toSql(main);

SchemaRegistry registry = prismContext.getSchemaRegistry();
PrismObjectDefinition userDef = registry.findObjectDefinitionByCompileTimeClass(UserType.class);
PrismContainerDefinition assignmentDef = userDef.findContainerDefinition(UserType.F_ASSIGNMENT);
PrismPropertyDefinition propDef = assignmentDef.createPropertyDefinition(SKIP_AUTOGENERATION, DOMUtil.XSD_BOOLEAN);

EqualFilter eq = EqualFilter.createEqual(
new ItemPath(UserType.F_ASSIGNMENT, AssignmentType.F_EXTENSION, SKIP_AUTOGENERATION),
propDef, null, true);

String real = getInterpretedQuery(session, UserType.class, ObjectQuery.createObjectQuery(eq));

LOGGER.info("exp. query>\n{}\nreal query>\n{}", new Object[]{expected, real});
AssertJUnit.assertEquals(expected, real);

OperationResult result = new OperationResult("search");
List<PrismObject<UserType>> objects = repositoryService.searchObjects(UserType.class,
ObjectQuery.createObjectQuery(eq), null, result);
result.computeStatus();
AssertJUnit.assertTrue(result.isSuccess());

AssertJUnit.assertNotNull(objects);
AssertJUnit.assertEquals(1, objects.size());

PrismObject<UserType> obj = objects.get(0);
AssertJUnit.assertTrue(obj.getCompileTimeClass().equals(UserType.class));

result = new OperationResult("count");
long count = repositoryService.countObjects(UserType.class, ObjectQuery.createObjectQuery(eq), result);
result.computeStatus();
AssertJUnit.assertTrue(result.isSuccess());
AssertJUnit.assertEquals(1, count);
} finally {
close(session);
}
}
}
3 changes: 2 additions & 1 deletion repo/repo-sql-impl-test/src/test/resources/basic/objects.xml
Expand Up @@ -23,6 +23,7 @@
xmlns:icfs="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/resource-schema-3"
xmlns:my="http://myself.me/schemas/whatever"
xmlns:t="http://prism.evolveum.com/xml/ns/public/types-3"
xmlns:p="http://example.com/p"
xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3"
xsi:schemaLocation="http://midpoint.evolveum.com/xml/ns/public/common/common-3 ../../../../../../infra/schema/src/main/resources/xml/ns/public/common/common-3.xsd">

Expand Down Expand Up @@ -52,7 +53,7 @@
<description>Some assignment description</description>
<extension>
<my:dead xsi:type="xsd:int">123</my:dead>
<my:skipAutogeneration xsi:type="xsd:boolean">true</my:skipAutogeneration>
<p:skipAutogeneration xsi:type="xsd:boolean">true</p:skipAutogeneration>
</extension>
<metadata>
<creatorRef oid="dddccccc-cccc-cccc-cccc-000022222222" type="c:UserType"/>
Expand Down

0 comments on commit 09db6c9

Please sign in to comment.