Example usage for org.apache.solr.client.solrj.impl XMLResponseParser processResponse

List of usage examples for org.apache.solr.client.solrj.impl XMLResponseParser processResponse

Introduction

In this page you can find the example usage for org.apache.solr.client.solrj.impl XMLResponseParser processResponse.

Prototype

private NamedList<Object> processResponse(XMLStreamReader parser) 

Source Link

Document

parse the text into a named list...

Usage

From source file:org.springframework.data.solr.core.convert.MappingSolrConvertDocumentObjectBinderCompatibilityTests.java

License:Apache License

@SuppressWarnings("unchecked")
@Test//from  w  w  w . j av a2  s  .c  o m
public void testSimple() throws Exception {
    XMLResponseParser parser = new XMLResponseParser();
    NamedList<Object> nl = parser.processResponse(new StringReader(xml));
    QueryResponse res = new QueryResponse(nl, null);

    SolrDocumentList solDocList = res.getResults();
    List<Item> l = getBeans(solDocList);
    Assert.assertEquals(solDocList.size(), l.size());
    Assert.assertEquals(solDocList.get(0).getFieldValue("features"), l.get(0).features);

    Item item = new Item();
    item.id = "aaa";
    item.categories = new String[] { "aaa", "bbb", "ccc" };
    SolrInputDocument out = new SolrInputDocument();
    converter.write(item, out);

    Assert.assertEquals(item.id, out.getFieldValue("id"));
    SolrInputField catfield = out.getField("cat");
    Assert.assertEquals(3, catfield.getValueCount());

    List<String> catValues = (List<String>) catfield.getValue();
    Assert.assertEquals("aaa", catValues.get(0));
    Assert.assertEquals("bbb", catValues.get(1));
    Assert.assertEquals("ccc", catValues.get(2));
}

From source file:org.springframework.data.solr.core.convert.MappingSolrConvertDocumentObjectBinderCompatibilityTests.java

License:Apache License

@Test
public void testDynamicFieldBinding() {
    XMLResponseParser parser = new XMLResponseParser();
    NamedList<Object> nl = parser.processResponse(new StringReader(xml));
    QueryResponse res = new QueryResponse(nl, null);

    List<Item> l = getBeans(res.getResults());

    Item item = l.get(3);/*from  w ww . j a  v  a  2 s  . co  m*/

    Assert.assertArrayEquals(new String[] { "Mobile Store", "iPod Store", "CCTV Store" },
            item.getAllSuppliers());
    Assert.assertTrue(item.supplier.containsKey("supplier_1"));
    Assert.assertTrue(item.supplier.containsKey("supplier_2"));
    Assert.assertEquals(2, item.supplier.size());

    List<String> supplierOne = item.supplier.get("supplier_1");
    Assert.assertEquals("Mobile Store", supplierOne.get(0));
    Assert.assertEquals("iPod Store", supplierOne.get(1));

    List<String> supplierTwo = item.supplier.get("supplier_2");
    Assert.assertEquals("CCTV Store", supplierTwo.get(0));
}