Search in sources :

Example 1 with Values

use of org.xbib.elasticsearch.common.util.Values in project elasticsearch-jdbc by jprante.

the class StandardSourceTests method testSimpleNullInteger.

@Test
@Parameters({ "sql3" })
public void testSimpleNullInteger(String sql) throws Exception {
    List<Object> params = new LinkedList<Object>();
    Sink sink = new MockSink() {

        @Override
        public void index(IndexableObject object, boolean create) throws IOException {
            if (object == null || object.source() == null) {
                throw new IllegalArgumentException("object missing");
            }
            Values o = (Values) object.source().get("amount");
            if (o == null) {
                // hsqldb is uppercase
                o = (Values) object.source().get("AMOUNT");
            }
            if (!o.isNull()) {
                throw new IllegalArgumentException("amount not null??? " + o.getClass().getName());
            }
        }
    };
    PreparedStatement statement = source.prepareQuery(sql);
    source.bind(statement, params);
    ResultSet results = source.executeQuery(statement);
    StringKeyValueStreamListener listener = new StringKeyValueStreamListener().output(sink);
    long rows = 0L;
    source.beforeRows(results, listener);
    if (source.nextRow(results, listener)) {
        // only one row
        rows++;
    }
    source.afterRows(results, listener);
    assertEquals(rows, 1);
    source.close(results);
    source.close(statement);
}
Also used : Sink(org.xbib.elasticsearch.jdbc.strategy.Sink) MockSink(org.xbib.elasticsearch.jdbc.strategy.mock.MockSink) MockSink(org.xbib.elasticsearch.jdbc.strategy.mock.MockSink) StringKeyValueStreamListener(org.xbib.elasticsearch.common.util.StringKeyValueStreamListener) Values(org.xbib.elasticsearch.common.util.Values) ResultSet(java.sql.ResultSet) IndexableObject(org.xbib.elasticsearch.common.util.IndexableObject) PreparedStatement(java.sql.PreparedStatement) IndexableObject(org.xbib.elasticsearch.common.util.IndexableObject) LinkedList(java.util.LinkedList) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Aggregations

PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 LinkedList (java.util.LinkedList)1 Parameters (org.testng.annotations.Parameters)1 Test (org.testng.annotations.Test)1 IndexableObject (org.xbib.elasticsearch.common.util.IndexableObject)1 StringKeyValueStreamListener (org.xbib.elasticsearch.common.util.StringKeyValueStreamListener)1 Values (org.xbib.elasticsearch.common.util.Values)1 Sink (org.xbib.elasticsearch.jdbc.strategy.Sink)1 MockSink (org.xbib.elasticsearch.jdbc.strategy.mock.MockSink)1