Search in sources :

Example 11 with DIHConfiguration

use of org.apache.solr.handler.dataimport.config.DIHConfiguration in project lucene-solr by apache.

the class TestDocBuilder method singleEntityOneRow.

@Test
public void singleEntityOneRow() {
    DataImporter di = new DataImporter();
    di.loadAndInit(dc_singleEntity);
    DIHConfiguration cfg = di.getConfig();
    Entity ent = cfg.getEntities().get(0);
    List<Map<String, Object>> l = new ArrayList<>();
    l.add(createMap("id", 1, "desc", "one"));
    MockDataSource.setIterator("select * from x", l.iterator());
    RequestInfo rp = new RequestInfo(null, createMap("command", "full-import"), null);
    SolrWriterImpl swi = new SolrWriterImpl();
    di.runCmd(rp, swi);
    assertEquals(Boolean.TRUE, swi.deleteAllCalled);
    assertEquals(Boolean.TRUE, swi.commitCalled);
    assertEquals(Boolean.TRUE, swi.finishCalled);
    assertEquals(1, swi.docs.size());
    assertEquals(1, di.getDocBuilder().importStatistics.queryCount.get());
    assertEquals(1, di.getDocBuilder().importStatistics.docCount.get());
    assertEquals(1, di.getDocBuilder().importStatistics.rowsCount.get());
    for (int i = 0; i < l.size(); i++) {
        Map<String, Object> map = l.get(i);
        SolrInputDocument doc = swi.docs.get(i);
        for (Map.Entry<String, Object> entry : map.entrySet()) {
            assertEquals(entry.getValue(), doc.getFieldValue(entry.getKey()));
        }
    }
}
Also used : Entity(org.apache.solr.handler.dataimport.config.Entity) DIHConfiguration(org.apache.solr.handler.dataimport.config.DIHConfiguration) SolrInputDocument(org.apache.solr.common.SolrInputDocument) Test(org.junit.Test)

Aggregations

DIHConfiguration (org.apache.solr.handler.dataimport.config.DIHConfiguration)11 Test (org.junit.Test)9 Entity (org.apache.solr.handler.dataimport.config.Entity)6 SolrInputDocument (org.apache.solr.common.SolrInputDocument)4 Document (org.w3c.dom.Document)4 StringReader (java.io.StringReader)3 DocumentBuilder (javax.xml.parsers.DocumentBuilder)3 InputSource (org.xml.sax.InputSource)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 SolrException (org.apache.solr.common.SolrException)1 PropertyWriter (org.apache.solr.handler.dataimport.config.PropertyWriter)1 Script (org.apache.solr.handler.dataimport.config.Script)1 SystemIdResolver (org.apache.solr.util.SystemIdResolver)1 Element (org.w3c.dom.Element)1