Skip to content

Commit

Permalink
Added additional tests to TestFilterExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
tonydamage committed Mar 28, 2022
1 parent 6e40d46 commit 5d64e83
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.evolveum.midpoint.prism.query.PrismQueryExpressionFactory;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.TunnelException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ConstExpressionEvaluatorType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ScriptExpressionEvaluatorType;
import com.evolveum.prism.xml.ns._public.types_3.ItemPathType;
Expand All @@ -24,6 +25,8 @@ public class PrismQueryExpressionSupport implements PrismQueryExpressionFactory
private static final QName EXPRESSION = SchemaConstantsGenerated.C_EXPRESSION;
private static final QName PATH = SchemaConstantsGenerated.C_PATH;
private static final String YAML = "yaml";
private static final String CONST = "const";



@Override
Expand All @@ -33,6 +36,9 @@ public ExpressionWrapper parseScript(Map<String, String> namespaceContext, Strin
if (YAML.equals(language)) {
return parseYamlScript(script, namespaceContext);
}
if (CONST.equals(language)) {
return parseConstScript(script, namespaceContext);
}

if (!Strings.isNullOrEmpty(language)) {
scriptValue.setLanguage(language);
Expand All @@ -42,6 +48,14 @@ public ExpressionWrapper parseScript(Map<String, String> namespaceContext, Strin
return new ExpressionWrapper(EXPRESSION, expressionT);
}

private ExpressionWrapper parseConstScript(String constant, Map<String, String> namespaceContext) {
ExpressionType expressionT = new ExpressionType();
var expr = new ConstExpressionEvaluatorType();
expr.setValue(constant);
expressionT.expressionEvaluator(new JAXBElement<>(SchemaConstantsGenerated.C_CONST, ConstExpressionEvaluatorType.class, expr));
return new ExpressionWrapper(EXPRESSION, expressionT);
}

private ExpressionWrapper parseYamlScript(String script, Map<String, String> namespaceContext) {
ItemDefinition<?> expression = PrismContext.get().getSchemaRegistry().findItemDefinitionByElementName(EXPRESSION);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,21 @@ public void test140EvaluateExpressionEmployeeTypeEmptyFilter() throws Exception
executeFilter(filter, 4, task, result);
}

@Test
public void test145EvaluateConstantFilter() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();

ObjectFilter filter = evaluateExpressionAssertFilter("expression-aql-constant-filter.xml",
null, EqualFilter.class, task, result);

EqualFilter equalFilter = (EqualFilter) filter;
AssertJUnit.assertNotNull("Expected 1 value in filter", equalFilter.getValues());

executeFilter(filter, 1, task, result);
}

@Test
public void test150EvaluateExpressionEmployeeTypeDefaultsNull() throws Exception {
// GIVEN
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<!--
~ Copyright (c) 2010-2017 Evolveum and contributors
~
~ This work is dual-licensed under the Apache License 2.0
~ and European Union Public License. See LICENSE file for details.
-->

<filter xmlns="http://prism.evolveum.com/xml/ns/public/query-3" xmlns:c='http://midpoint.evolveum.com/xml/ns/public/common/common-3'>
<text>extension/tales = @blabla</text>
</filter>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<!--
~ Copyright (c) 2010-2017 Evolveum and contributors
~
~ This work is dual-licensed under the Apache License 2.0
~ and European Union Public License. See LICENSE file for details.
-->

<filter xmlns="http://prism.evolveum.com/xml/ns/public/query-3" xmlns:c='http://midpoint.evolveum.com/xml/ns/public/common/common-3'>
<text>subtype = yaml```
queryInterpretationOfNoValue: filterNone
path: $input
```
</text>
</filter>

0 comments on commit 5d64e83

Please sign in to comment.