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;
}
}
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;
}
}
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());
}
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());
}
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());
}
Aggregations