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\"}}");
}
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\"]}}}}");
}
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\"]}]}}");
}
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}}}");
}
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");
}
Aggregations