use of org.drools.compiler.rule.builder.XpathAnalysis in project drools by kiegroup.
the class XpathAnalysisTest method testAttributeDereferenceMixed.
@Test
public void testAttributeDereferenceMixed() {
final String xpath = "/address.street/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>(), null, -1, 0), iterator.next());
verifyXpathPart(new XpathAnalysis.XpathPart("name", 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 testNotAnXPath.
@Test
public void testNotAnXPath() {
final String xpath = "someAttribute";
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 testAttributeDereferenceDot.
@Test
public void testAttributeDereferenceDot() {
final String xpath = "/address.";
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("", false, 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 testIndex.
@Test
public void testIndex() {
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());
assertEquals(false, iterator.hasNext());
}
use of org.drools.compiler.rule.builder.XpathAnalysis in project drools by kiegroup.
the class XpathAnalysisTest method testThreeConditions.
@Test
public void testThreeConditions() {
final String xpath = "/address/street[name == \"Elm\", length <= 10, code == \"Something, \\\"and\\\" other thing\"]";
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", true, false, new ArrayList<String>(Arrays.asList("name == \"Elm\"", "length <= 10", "code == \"Something, \\\"and\\\" other thing\"")), null, -1, 0), iterator.next());
assertEquals(false, iterator.hasNext());
}
Aggregations