mirror of https://github.com/apache/lucene.git
SOLR-13657: fix unsupported xpath test in TestXPathRecordReader
* use expectThrows to verify the exception and the message * fix NPE in the test
This commit is contained in:
parent
b8289abeeb
commit
1d303cee7f
|
@ -360,19 +360,13 @@ public class TestXPathRecordReader extends AbstractDataImportHandlerTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnsupported_Xpaths() {
|
public void testUnsupportedXPaths() {
|
||||||
String xml = "<root><b><a x=\"a/b\" h=\"hello-A\"/> </b></root>";
|
RuntimeException ex = expectThrows(RuntimeException.class, () -> new XPathRecordReader("//b"));
|
||||||
XPathRecordReader rr=null;
|
assertEquals("forEach cannot start with '//': //b", ex.getMessage());
|
||||||
try {
|
|
||||||
rr = new XPathRecordReader("//b");
|
XPathRecordReader rr = new XPathRecordReader("/anyd/contenido");
|
||||||
fail("A RuntimeException was expected: //b forEach cannot begin with '//'.");
|
ex = expectThrows(RuntimeException.class, () -> rr.addField("bold", "b", false));
|
||||||
}
|
assertEquals("xpath must start with '/' : b", ex.getMessage());
|
||||||
catch (RuntimeException ex) { }
|
|
||||||
try {
|
|
||||||
rr.addField("bold" ,"b", false);
|
|
||||||
fail("A RuntimeException was expected: 'b' xpaths must begin with '/'.");
|
|
||||||
}
|
|
||||||
catch (RuntimeException ex) { }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -590,9 +584,7 @@ public class TestXPathRecordReader extends AbstractDataImportHandlerTestCase {
|
||||||
XPathRecordReader rr = new XPathRecordReader("/root/node");
|
XPathRecordReader rr = new XPathRecordReader("/root/node");
|
||||||
rr.addField("id", "/root/node/id", true);
|
rr.addField("id", "/root/node/id", true);
|
||||||
rr.addField("desc", "/root/node/desc", true);
|
rr.addField("desc", "/root/node/desc", true);
|
||||||
try {
|
RuntimeException e = expectThrows(RuntimeException.class, () -> rr.getAllRecords(new StringReader(malformedXml)));
|
||||||
rr.getAllRecords(new StringReader(malformedXml));
|
assertTrue(e.getMessage().contains("Unexpected close tag </id>"));
|
||||||
fail("A RuntimeException was expected: the input XML is invalid.");
|
|
||||||
} catch (Exception e) { }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue