Search in sources :

Example 1 with DIHConfiguration

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

the class TestScriptTransformer method testCheckScript.

@Test
public void testCheckScript() throws Exception {
    try {
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document document = builder.parse(new InputSource(new StringReader(xml)));
        DataImporter di = new DataImporter();
        DIHConfiguration dc = di.readFromXml(document);
        Context c = getContext("checkNextToken", dc.getScript().getText());
        Map map = new HashMap();
        map.put("nextToken", "hello");
        EntityProcessorWrapper sep = new EntityProcessorWrapper(new SqlEntityProcessor(), null, null);
        sep.init(c);
        sep.applyTransformer(map);
        assertEquals("true", map.get("$hasMore"));
        map = new HashMap();
        map.put("nextToken", "");
        sep.applyTransformer(map);
        assertNull(map.get("$hasMore"));
    } catch (DataImportHandlerException e) {
        assumeFalse("This JVM does not have JavaScript installed.  Test Skipped.", e.getMessage().startsWith("Cannot load Script Engine for language"));
        throw e;
    }
}
Also used : DIHConfiguration(org.apache.solr.handler.dataimport.config.DIHConfiguration) InputSource(org.xml.sax.InputSource) DocumentBuilder(javax.xml.parsers.DocumentBuilder) HashMap(java.util.HashMap) StringReader(java.io.StringReader) Document(org.w3c.dom.Document) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 2 with DIHConfiguration

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

the class TestScriptTransformer method testReadScriptTag.

@Test
public void testReadScriptTag() throws Exception {
    try {
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document document = builder.parse(new InputSource(new StringReader(xml)));
        DataImporter di = new DataImporter();
        DIHConfiguration dc = di.readFromXml(document);
        assertTrue(dc.getScript().getText().indexOf("checkNextToken") > -1);
    } catch (DataImportHandlerException e) {
        assumeFalse("This JVM does not have JavaScript installed.  Test Skipped.", e.getMessage().startsWith("Cannot load Script Engine for language"));
        throw e;
    }
}
Also used : DIHConfiguration(org.apache.solr.handler.dataimport.config.DIHConfiguration) InputSource(org.xml.sax.InputSource) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StringReader(java.io.StringReader) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 3 with DIHConfiguration

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

the class TestDataConfig method testBasic.

@Test
public void testBasic() throws Exception {
    javax.xml.parsers.DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document doc = builder.parse(new InputSource(new StringReader(xml)));
    DataImporter di = new DataImporter();
    DIHConfiguration dc = di.readFromXml(doc);
    assertEquals("atrimlisting", dc.getEntities().get(0).getName());
}
Also used : DIHConfiguration(org.apache.solr.handler.dataimport.config.DIHConfiguration) InputSource(org.xml.sax.InputSource) StringReader(java.io.StringReader) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 4 with DIHConfiguration

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

the class TestDocBuilder method singleEntityMultipleRows.

@Test
public void singleEntityMultipleRows() {
    DataImporter di = new DataImporter();
    di.loadAndInit(dc_singleEntity);
    DIHConfiguration cfg = di.getConfig();
    Entity ent = cfg.getEntities().get(0);
    RequestInfo rp = new RequestInfo(null, createMap("command", "full-import"), null);
    List<Map<String, Object>> l = new ArrayList<>();
    l.add(createMap("id", 1, "desc", "one"));
    l.add(createMap("id", 2, "desc", "two"));
    l.add(createMap("id", 3, "desc", "three"));
    MockDataSource.setIterator("select * from x", l.iterator());
    SolrWriterImpl swi = new SolrWriterImpl();
    di.runCmd(rp, swi);
    assertEquals(Boolean.TRUE, swi.deleteAllCalled);
    assertEquals(Boolean.TRUE, swi.commitCalled);
    assertEquals(Boolean.TRUE, swi.finishCalled);
    assertEquals(3, swi.docs.size());
    for (int i = 0; i < l.size(); i++) {
        Map<String, Object> map = (Map<String, Object>) l.get(i);
        SolrInputDocument doc = swi.docs.get(i);
        for (Map.Entry<String, Object> entry : map.entrySet()) {
            assertEquals(entry.getValue(), doc.getFieldValue(entry.getKey()));
        }
        assertEquals(map.get("desc"), doc.getFieldValue("desc_s"));
    }
    assertEquals(1, di.getDocBuilder().importStatistics.queryCount.get());
    assertEquals(3, di.getDocBuilder().importStatistics.docCount.get());
    assertEquals(3, di.getDocBuilder().importStatistics.rowsCount.get());
}
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)

Example 5 with DIHConfiguration

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

the class TestDocBuilder method singleEntityNoRows.

@Test
public void singleEntityNoRows() {
    DataImporter di = new DataImporter();
    di.loadAndInit(dc_singleEntity);
    DIHConfiguration cfg = di.getConfig();
    Entity ent = cfg.getEntities().get(0);
    MockDataSource.setIterator("select * from x", new ArrayList<Map<String, Object>>().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(0, swi.docs.size());
    assertEquals(1, di.getDocBuilder().importStatistics.queryCount.get());
    assertEquals(0, di.getDocBuilder().importStatistics.docCount.get());
    assertEquals(0, di.getDocBuilder().importStatistics.rowsCount.get());
}
Also used : DIHConfiguration(org.apache.solr.handler.dataimport.config.DIHConfiguration) Entity(org.apache.solr.handler.dataimport.config.Entity) 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