Search in sources :

Example 16 with MockSink

use of org.xbib.elasticsearch.jdbc.strategy.mock.MockSink in project elasticsearch-jdbc by jprante.

the class ValueListenerTests method testIgnoreNull.

@Test
public void testIgnoreNull() throws Exception {
    List<String> columns = Arrays.asList("_id", "col1", "col2");
    List<Object> row1 = new LinkedList<Object>();
    row1.add("1");
    row1.add("Hello World");
    row1.add(null);
    List<Object> row2 = new LinkedList<Object>();
    row2.add("1");
    row2.add(null);
    row2.add("Hello World");
    MockSink output = new MockSink();
    new SinkKeyValueStreamListener<String, Object>().shouldIgnoreNull(true).output(output).begin().keys(columns).values(row1).values(row2).end();
    assertEquals(output.data().toString(), "{[null/null/null/1]->{col1=\"Hello World\", col2=\"Hello World\"}={\"col1\":\"Hello World\",\"col2\":\"Hello World\"}}");
}
Also used : MockSink(org.xbib.elasticsearch.jdbc.strategy.mock.MockSink) LinkedList(java.util.LinkedList) Test(org.testng.annotations.Test)

Example 17 with MockSink

use of org.xbib.elasticsearch.jdbc.strategy.mock.MockSink in project elasticsearch-jdbc by jprante.

the class ValueListenerTests method testMultipleValues.

@Test
public void testMultipleValues() throws Exception {
    List<String> columns = Arrays.asList("_id", "person.salary", "person.name", "person.position.name", "person.position.since");
    List<String> row1 = Arrays.asList("1", "$1000", "Joe Doe", "Worker", "2012-06-12");
    List<String> row2 = Arrays.asList("1", "$1000", "Joe Doe", "Worker", "2012-06-13");
    MockSink output = new MockSink();
    new StringKeyValueStreamListener().output(output).begin().keys(columns).values(row1).values(row2).end();
    assertEquals(output.data().toString(), "{[null/null/null/1]->{person={salary=\"$1000\", name=\"Joe Doe\", position={name=\"Worker\", since=[\"2012-06-12\",\"2012-06-13\"]}}}={\"person\":{\"salary\":\"$1000\",\"name\":\"Joe Doe\",\"position\":{\"name\":\"Worker\",\"since\":[\"2012-06-12\",\"2012-06-13\"]}}}}");
}
Also used : MockSink(org.xbib.elasticsearch.jdbc.strategy.mock.MockSink) Test(org.testng.annotations.Test)

Example 18 with MockSink

use of org.xbib.elasticsearch.jdbc.strategy.mock.MockSink in project elasticsearch-jdbc by jprante.

the class ValueListenerTests method testJSONWithNull.

@Test
public void testJSONWithNull() throws Exception {
    List<String> columns = Arrays.asList("_optype", "_id", "message", "person", "person.attributes");
    List<String> row1 = Arrays.asList("index", "1", "{\"Hello\":\"World\"}", "{\"name\":[\"Joe\",\"John\"]}", "{\"haircolor\":\"blue\"}");
    List<String> row2 = Arrays.asList("index", "1", null, "{\"name\":[\"Joe\",\"John\"]}", "{\"haircolor\":\"blue\"}");
    MockSink output = new MockSink();
    new StringKeyValueStreamListener().output(output).begin().keys(columns).values(row1).values(row2).end();
    assertEquals(output.data().toString(), "{[index/null/null/1]->{message=\"{Hello=World}\", person=[\"{name=[Joe, John], attributes=\"{haircolor=blue}\"}\",\"{name=[Joe, John]}\"]}={\"message\":{\"Hello\":\"World\"},\"person\":[{\"name\":[\"Joe\",\"John\"],\"attributes\":{\"haircolor\":\"blue\"}},{\"name\":[\"Joe\",\"John\"]}]}}");
}
Also used : MockSink(org.xbib.elasticsearch.jdbc.strategy.mock.MockSink) Test(org.testng.annotations.Test)

Example 19 with MockSink

use of org.xbib.elasticsearch.jdbc.strategy.mock.MockSink in project elasticsearch-jdbc by jprante.

the class ValueListenerTests method testIgnoreNullObject2.

@Test
public void testIgnoreNullObject2() throws Exception {
    List<String> columns = Arrays.asList("_id", "movie.event", "movie.title", "movie.overview", "movie.test");
    List<Object> row1 = new LinkedList<Object>();
    row1.add(0);
    row1.add(null);
    row1.add(null);
    row1.add(null);
    row1.add(null);
    List<Object> row2 = new LinkedList<Object>();
    row2.add(1);
    row2.add(21);
    row2.add("ABC");
    row2.add("DEF");
    row2.add(1212);
    MockSink output = new MockSink();
    new SinkKeyValueStreamListener<String, Object>().shouldIgnoreNull(true).output(output).begin().keys(columns).values(row1).values(row2).end();
    assertEquals(output.data().toString(), "{[null/null/null/0]->{movie={event=null, title=null, overview=null, test=null}}={\"movie\":{}}, [null/null/null/1]->{movie={event=21, title=\"ABC\", overview=\"DEF\", test=1212}}={\"movie\":{\"event\":21,\"title\":\"ABC\",\"overview\":\"DEF\",\"test\":1212}}}");
}
Also used : MockSink(org.xbib.elasticsearch.jdbc.strategy.mock.MockSink) LinkedList(java.util.LinkedList) Test(org.testng.annotations.Test)

Example 20 with MockSink

use of org.xbib.elasticsearch.jdbc.strategy.mock.MockSink in project elasticsearch-jdbc by jprante.

the class ValueListenerTests method testOptype.

@Test
public void testOptype() throws Exception {
    List<String> columns = Arrays.asList("_optype", "_id", "label");
    List<String> row1 = Arrays.asList("index", "1", "label1");
    List<String> row2 = Arrays.asList("create", "2", "label2");
    List<String> row3 = Arrays.asList("delete", "3", "label3");
    List<String> row4 = Arrays.asList("index", "4", "label4");
    MockSink output = new MockSink();
    new StringKeyValueStreamListener().output(output).begin().keys(columns).values(row1).values(row2).values(row3).values(row4).end();
    assertEquals(output.data().size(), 3, "number of objects");
}
Also used : MockSink(org.xbib.elasticsearch.jdbc.strategy.mock.MockSink) Test(org.testng.annotations.Test)

Aggregations

MockSink (org.xbib.elasticsearch.jdbc.strategy.mock.MockSink)25 Test (org.testng.annotations.Test)23 LinkedList (java.util.LinkedList)7 Parameters (org.testng.annotations.Parameters)6 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 IndexableObject (org.xbib.elasticsearch.common.util.IndexableObject)3 StringKeyValueStreamListener (org.xbib.elasticsearch.common.util.StringKeyValueStreamListener)3 Sink (org.xbib.elasticsearch.jdbc.strategy.Sink)3 Settings (org.elasticsearch.common.settings.Settings)2 MockJDBCSource (org.xbib.elasticsearch.jdbc.strategy.mock.MockJDBCSource)2 DateTime (org.joda.time.DateTime)1 Values (org.xbib.elasticsearch.common.util.Values)1