use of org.apache.commons.jexl3.parser.ASTJexlScript in project datawave by NationalSecurityAgency.
the class JexlASTHelperTest method testGetLiteralValueThrowsNSEE.
@Test(expected = NoSuchElementException.class)
public void testGetLiteralValueThrowsNSEE() throws Exception {
ASTJexlScript query = JexlASTHelper.parseJexlQuery("FOO == FOO2");
assertNull(JexlASTHelper.getLiteralValue(query));
}
use of org.apache.commons.jexl3.parser.ASTJexlScript in project datawave by NationalSecurityAgency.
the class JexlASTHelperTest method testFindDelayedRange.
@Test
public void testFindDelayedRange() throws Exception {
ASTJexlScript script = JexlASTHelper.parseJexlQuery("((_Delayed_ = true) && ((_Bounded_ = true) && (A < 'b' && A > 'a'))) && !(FOO == 'bar')");
LiteralRange range = JexlASTHelper.findRange().getRange(script.jjtGetChild(0));
Assert.assertNull(range);
script = JexlASTHelper.parseJexlQuery("((_Delayed_ = true) && ((_Bounded_ = true) && (A < 'b' && A > 'a')))");
range = JexlASTHelper.findRange().getRange(script.jjtGetChild(0));
Assert.assertNotNull(range);
Assert.assertNotNull(range.getLowerNode());
Assert.assertNotNull(range.getUpperNode());
Assert.assertEquals("a", range.getLower());
Assert.assertEquals("b", range.getUpper());
Assert.assertFalse(range.isLowerInclusive());
Assert.assertFalse(range.isUpperInclusive());
}
use of org.apache.commons.jexl3.parser.ASTJexlScript in project datawave by NationalSecurityAgency.
the class JexlASTHelperTest method testDereferenceMarkerNodeSafely.
// dereference marked node while preserving the final wrapper layer
@Test
public void testDereferenceMarkerNodeSafely() throws ParseException {
String query = "(((((_Value_ = true) && (FOO =~ 'a.*')))))";
ASTJexlScript script = JexlASTHelper.parseJexlQuery(query);
JexlNode child = script.jjtGetChild(0);
JexlNode test = JexlASTHelper.dereferenceSafely(child);
Assert.assertEquals("((_Value_ = true) && (FOO =~ 'a.*'))", JexlStringBuildingVisitor.buildQueryWithoutParse(test));
}
use of org.apache.commons.jexl3.parser.ASTJexlScript in project datawave by NationalSecurityAgency.
the class JexlASTHelperTest method testFindIndexedRange.
@Test
public void testFindIndexedRange() throws Exception {
MockMetadataHelper helper = new MockMetadataHelper();
helper.setIndexedFields(Collections.singleton("A"));
ASTJexlScript script = JexlASTHelper.parseJexlQuery("((_Bounded_ = true) && (A < 'b' && A > 'a'))");
LiteralRange range = JexlASTHelper.findRange().indexedOnly(null, helper).getRange(script.jjtGetChild(0));
Assert.assertNotNull(range);
Assert.assertNotNull(range.getLowerNode());
Assert.assertNotNull(range.getUpperNode());
Assert.assertEquals("a", range.getLower());
Assert.assertEquals("b", range.getUpper());
Assert.assertFalse(range.isLowerInclusive());
Assert.assertFalse(range.isUpperInclusive());
script = JexlASTHelper.parseJexlQuery("B < 5 && B > 1");
range = JexlASTHelper.findRange().indexedOnly(null, helper).getRange(script.jjtGetChild(0));
Assert.assertNull(range);
}
use of org.apache.commons.jexl3.parser.ASTJexlScript in project datawave by NationalSecurityAgency.
the class JexlASTHelperTest method testIdentifierParse.
private void testIdentifierParse(String query, Set<String> expectedIdentifiers) {
try {
ASTJexlScript script = JexlASTHelper.parseJexlQuery(query);
Set<String> fields = JexlASTHelper.getIdentifierNames(script);
assertEquals("Expected fields but was", expectedIdentifiers, fields);
} catch (ParseException e) {
e.printStackTrace();
}
}
Aggregations