Apache Lucene open-source search software
added an extra testcase
Noble Paul3f6164c76e2f
diff --git a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestPlainTextEntityProcessor.java b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestPlainTextEntityProcessor.javaindex 82b757e6db6..a286d841c91 100644--- a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestPlainTextEntityProcessor.java+++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestPlainTextEntityProcessor.java@@ -16,12 +16,23 @@*/package org.apache.solr.handler.dataimport;+import java.io.ByteArrayInputStream;import java.io.IOException;+import java.io.InputStream;+import java.io.OutputStream;import java.io.StringReader;+import java.nio.charset.StandardCharsets;+import java.sql.Blob;+import java.sql.SQLException;+import java.util.Arrays;+import java.util.Collections;import java.util.Properties;+import org.apache.solr.common.util.Utils;import org.junit.Test;+import static java.nio.charset.StandardCharsets.UTF_8;+/*** Test for PlainTextEntityProcessor*@@ -42,6 +53,103 @@ public class TestPlainTextEntityProcessor extends AbstractDataImportHandlerTestCassertEquals(DS.s, sw.docs.get(0).getFieldValue("x"));}+ static class BlobImpl implements Blob{+ private final byte[] bytes;++ BlobImpl(byte[] bytes) {+ this.bytes = bytes;+ }++ @Override+ public long length() throws SQLException {+ return 0;+ }++ @Override+ public byte[] getBytes(long pos, int length) throws SQLException {+ return bytes;+ }++ @Override+ public InputStream getBinaryStream() throws SQLException {+ return new ByteArrayInputStream(bytes);+ }++ @Override+ public long position(byte[] pattern, long start) throws SQLException {+ return 0;+ }++ @Override+ public long position(Blob pattern, long start) throws SQLException {+ return 0;+ }++ @Override+ public int setBytes(long pos, byte[] bytes) throws SQLException {+ return 0;+ }++ @Override+ public int setBytes(long pos, byte[] bytes, int offset, int len) throws SQLException {+ return 0;+ }++ @Override+ public OutputStream setBinaryStream(long pos) throws SQLException {+ return null;+ }++ @Override+ public void truncate(long len) throws SQLException {++ }++ @Override+ public void free() throws SQLException {++ }++ @Override+ public InputStream getBinaryStream(long pos, long length) throws SQLException {+ return new ByteArrayInputStream(bytes);+ }+ }++ @Test+ public void testSimple2() throws IOException {+ DataImporter di = new DataImporter();+ MockDataSource.setIterator("select id, name, blob_field from lw_table4", Collections.singletonList(Utils.makeMap("blob_field",new BlobImpl(DS.s.getBytes(UTF_8)) ) ).iterator());++ String dc =++ " <dataConfig>" ++ "<dataSource name=\"ds1\" type=\"MockDataSource\"/>\n" ++ " <!-- dataSource for FieldReaderDataSource -->\n" ++ " <dataSource dataField=\"root.blob_field\" name=\"fr\" type=\"FieldReaderDataSource\"/>\n" ++ "\n" ++ " <document name=\"items\">\n" ++ " <entity dataSource=\"ds1\" name=\"root\" pk=\"id\" query=\"select id, name, blob_field from lw_table4\" transformer=\"TemplateTransformer\">\n" ++ " <field column=\"id\" name=\"id\"/>\n" ++ "\n" ++ " <entity dataField=\"root.blob_field\" dataSource=\"fr\" format=\"text\" name=\"n1\" processor=\"PlainTextEntityProcessor\" url=\"blob_field\">\n" ++ " <field column=\"plainText\" name=\"plainText\"/>\n" ++ " </entity>\n" ++ "\n" ++ " </entity>\n" ++ " </document>\n" ++ "</dataConfig>";+ System.out.println(dc);+ di.loadAndInit(dc);+ redirectTempProperties(di);++ TestDocBuilder.SolrWriterImpl sw = new TestDocBuilder.SolrWriterImpl();+ RequestInfo rp = new RequestInfo(null, createMap("command", "full-import"), null);+ di.runCmd(rp, sw);+ assertEquals(DS.s, sw.docs.get(0).getFieldValue("plainText"));+ }++public static class DS extends DataSource {static String s = "hello world";