use of org.apache.commons.jexl2.parser.ParseException in project datawave by NationalSecurityAgency.
the class QueryModelVisitorTest method assertResult.
private ASTJexlScript assertResult(String original, String expected) throws ParseException {
ASTJexlScript originalScript = JexlASTHelper.parseJexlQuery(original);
ASTJexlScript actualScript = QueryModelVisitor.applyModel(originalScript, model, allFields);
// Verify the resulting script is as expected with a valid lineage.
JexlNodeAssert.assertThat(actualScript).isEqualTo(expected).hasValidLineage();
// Verify the original script was not modified, and has a valid lineage.
JexlNodeAssert.assertThat(originalScript).isEqualTo(original).hasValidLineage();
return actualScript;
}
use of org.apache.commons.jexl2.parser.ParseException in project datawave by NationalSecurityAgency.
the class QueryModelVisitorTest method testNoExpansion.
private void testNoExpansion(String query, String expected, QueryModel model, Set<String> expectedFields) {
try {
Set<String> allFields = new HashSet<>();
allFields.addAll(model.getForwardQueryMapping().keySet());
allFields.addAll(model.getForwardQueryMapping().values());
ASTJexlScript script = JexlASTHelper.parseJexlQuery(query);
NoExpansionFunctionVisitor.VisitResult result = NoExpansionFunctionVisitor.findNoExpansionFields(script);
JexlNodeAssert.assertThat(script).isNotEqualTo(result.script);
Assert.assertEquals(expectedFields, result.noExpansionFields);
ASTJexlScript applied;
if (result.noExpansionFields.size() > 0) {
applied = QueryModelVisitor.applyModel(result.script, model, allFields, result.noExpansionFields);
} else {
applied = QueryModelVisitor.applyModel(result.script, model, allFields);
}
if (log.isTraceEnabled()) {
log.trace("expected: " + expected);
log.trace("actual : " + JexlStringBuildingVisitor.buildQueryWithoutParse(applied));
}
ASTJexlScript expectedScript = JexlASTHelper.parseAndFlattenJexlQuery(expected);
assertTrue(TreeEqualityVisitor.checkEquality(expectedScript, applied).isEqual());
} catch (ParseException e) {
fail("Error testing query: " + query);
}
}
use of org.apache.commons.jexl2.parser.ParseException in project datawave by NationalSecurityAgency.
the class QueryPropertyMarkerSourceConsolidatorTest method assertResult.
private void assertResult(String original, String expected) throws ParseException {
ASTJexlScript originalScript = JexlASTHelper.parseJexlQuery(original);
ASTJexlScript actual = QueryPropertyMarkerSourceConsolidator.consolidate(originalScript);
JexlNodeAssert.assertThat(actual).isEqualTo(expected).hasValidLineage();
JexlNodeAssert.assertThat(originalScript).hasExactQueryString(original).hasValidLineage();
}
use of org.apache.commons.jexl2.parser.ParseException in project datawave by NationalSecurityAgency.
the class QueryPropertyMarkerVisitorTest method givenNode.
private void givenNode(String query) throws ParseException {
JexlNode node = JexlASTHelper.parseJexlQuery(query);
PrintingVisitor.printQuery(node);
instance = QueryPropertyMarkerVisitor.getInstance(node);
}
use of org.apache.commons.jexl2.parser.ParseException in project datawave by NationalSecurityAgency.
the class QueryPruningVisitorTest method orFalseTest.
@Test
public void orFalseTest() throws ParseException {
String query = "false || _NOFIELD_ == 'z'";
ASTJexlScript script = JexlASTHelper.parseJexlQuery(query);
Assert.assertEquals(QueryPruningVisitor.TruthState.FALSE, QueryPruningVisitor.getState(script));
Assert.assertEquals(0, logAppender.getMessages().size(), logAppender.getMessages().size());
}
Aggregations