added testcase for attributes in root

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@777798 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Noble Paul 2009-05-23 05:30:54 +00:00
parent b1447effbe
commit 5a39044cc0
1 changed files with 34 additions and 0 deletions

View File

@ -58,6 +58,40 @@ public class TestXPathRecordReader {
Assert.assertEquals("y1", l.get(1).get("b"));
}
@Test
public void attrInRoot(){
String xml = "<r>\n" +
"<merchantProduct id=\"814636051\" mid=\"189973\">\n" +
" <in_stock type=\"stock-4\" />\n" +
" <condition type=\"cond-0\" />\n" +
" <price>301.46</price>\n" +
"</merchantProduct>\n" +
"<merchantProduct id=\"814636052\" mid=\"189974\">\n" +
" <in_stock type=\"stock-5\" />\n" +
" <condition type=\"cond-1\" />\n" +
" <price>302.46</price>\n" +
"</merchantProduct>\n" +
"\n" +
"</r>";
XPathRecordReader rr = new XPathRecordReader("/r/merchantProduct");
rr.addField("id", "/r/merchantProduct/@id", false);
rr.addField("mid", "/r/merchantProduct/@mid", false);
rr.addField("price", "/r/merchantProduct/price", false);
rr.addField("conditionType", "/r/merchantProduct/condition/@type", false);
List<Map<String, Object>> l = rr.getAllRecords(new StringReader(xml));
Map<String, Object> m = l.get(0);
Assert.assertEquals("814636051", m.get("id"));
Assert.assertEquals("189973", m.get("mid"));
Assert.assertEquals("301.46", m.get("price"));
Assert.assertEquals("cond-0", m.get("conditionType"));
m = l.get(1);
Assert.assertEquals("814636052", m.get("id"));
Assert.assertEquals("189974", m.get("mid"));
Assert.assertEquals("302.46", m.get("price"));
Assert.assertEquals("cond-1", m.get("conditionType"));
}
@Test
public void attributes2Level() {
String xml = "<root>\n" + "<a>\n" + " <b a=\"x0\" b=\"y0\" />\n"