use of org.drools.compiler.rule.builder.XpathAnalysis in project drools by kiegroup.
the class XpathAnalysisTest method testRelativePathInCondition.
@Test
public void testRelativePathInCondition() {
final String xpath = "/address.street[../city == \"The City\"]/name/";
final XpathAnalysis result = XpathAnalysis.analyze(xpath);
assertEquals("The XPath should be valid.", false, result.hasError());
assertNull(result.getError());
final Iterator<XpathAnalysis.XpathPart> iterator = getNonEmptyIterator(result);
verifyXpathPart(new XpathAnalysis.XpathPart("address", true, false, new ArrayList<String>(), null, -1, 0), iterator.next());
verifyXpathPart(new XpathAnalysis.XpathPart("street", false, false, new ArrayList<String>(Arrays.asList("../city == \"The City\"")), null, -1, 0), iterator.next());
verifyXpathPart(new XpathAnalysis.XpathPart("name", true, false, new ArrayList<String>(), null, -1, 0), iterator.next());
verifyXpathPart(new XpathAnalysis.XpathPart("", true, false, new ArrayList<String>(), null, -1, 0), iterator.next());
assertEquals(false, iterator.hasNext());
}
use of org.drools.compiler.rule.builder.XpathAnalysis in project drools by kiegroup.
the class XpathAnalysisTest method testEmptyInput.
@Test
public void testEmptyInput() {
final String xpath = "";
final XpathAnalysis result = XpathAnalysis.analyze(xpath);
assertEquals("The XPath has to start with '/'.", true, result.hasError());
assertNotNull(result.getError());
assertEquals(false, result.iterator().hasNext());
}
use of org.drools.compiler.rule.builder.XpathAnalysis in project drools by kiegroup.
the class XpathAnalysisTest method testIndexIterate.
@Test
public void testIndexIterate() {
final String xpath = "/address[0]/";
final XpathAnalysis result = XpathAnalysis.analyze(xpath);
assertEquals("The XPath should be valid.", false, result.hasError());
assertNull(result.getError());
final Iterator<XpathAnalysis.XpathPart> iterator = getNonEmptyIterator(result);
verifyXpathPart(new XpathAnalysis.XpathPart("address", true, false, new ArrayList<String>(), null, 0, 0), iterator.next());
verifyXpathPart(new XpathAnalysis.XpathPart("", true, false, new ArrayList<String>(), null, -1, 0), iterator.next());
assertEquals(false, iterator.hasNext());
}
use of org.drools.compiler.rule.builder.XpathAnalysis in project drools by kiegroup.
the class XpathAnalysisTest method testUnicode.
@Test
public void testUnicode() {
final String xpath = "/address.ulička[name == 'ěščřžýáíé']/";
final XpathAnalysis result = XpathAnalysis.analyze(xpath);
assertEquals("The XPath should be valid.", false, result.hasError());
assertNull(result.getError());
final Iterator<XpathAnalysis.XpathPart> iterator = getNonEmptyIterator(result);
verifyXpathPart(new XpathAnalysis.XpathPart("address", true, false, new ArrayList<String>(), null, -1, 0), iterator.next());
verifyXpathPart(new XpathAnalysis.XpathPart("ulička", false, false, new ArrayList<String>(Arrays.asList("name == 'ěščřžýáíé'")), null, -1, 0), iterator.next());
verifyXpathPart(new XpathAnalysis.XpathPart("", true, false, new ArrayList<String>(), null, -1, 0), iterator.next());
assertEquals(false, iterator.hasNext());
}
Aggregations