Search in sources :

Example 16 with Entity

use of org.apache.solr.handler.dataimport.config.Entity 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

Entity (org.apache.solr.handler.dataimport.config.Entity)16 Test (org.junit.Test)11 DIHConfiguration (org.apache.solr.handler.dataimport.config.DIHConfiguration)6 Ignore (org.junit.Ignore)6 SolrException (org.apache.solr.common.SolrException)5 SolrInputDocument (org.apache.solr.common.SolrInputDocument)3 IOException (java.io.IOException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 SystemIdResolver (org.apache.solr.util.SystemIdResolver)1 Document (org.w3c.dom.Document)1