use of org.apache.kafka.connect.data.SchemaAndValue in project kafka by apache.
the class SimpleHeaderConverterTest method shouldParseStringOfMapWithStringValuesWithWhitespaceAsMap.
@Test
public void shouldParseStringOfMapWithStringValuesWithWhitespaceAsMap() {
SchemaAndValue result = roundTrip(Schema.STRING_SCHEMA, "{ \"foo\" : \"123\", \n\"bar\" : \"baz\" } ");
assertEquals(STRING_MAP_SCHEMA, result.schema());
assertEquals(STRING_MAP, result.value());
}
use of org.apache.kafka.connect.data.SchemaAndValue in project kafka by apache.
the class SimpleHeaderConverterTest method assertRoundTrip.
protected void assertRoundTrip(Schema schema, Object value) {
byte[] serialized = converter.fromConnectHeader(TOPIC, HEADER, schema, value);
SchemaAndValue result = converter.toConnectHeader(TOPIC, HEADER, serialized);
if (value == null) {
assertNull(serialized);
assertNull(result.schema());
assertNull(result.value());
} else {
assertNotNull(serialized);
assertEquals(value, result.value());
assertEquals(schema, result.schema());
byte[] serialized2 = converter.fromConnectHeader(TOPIC, HEADER, result.schema(), result.value());
SchemaAndValue result2 = converter.toConnectHeader(TOPIC, HEADER, serialized2);
assertNotNull(serialized2);
assertEquals(schema, result2.schema());
assertEquals(value, result2.value());
assertEquals(result, result2);
assertArrayEquals(serialized, serialized);
}
}
use of org.apache.kafka.connect.data.SchemaAndValue in project kafka by apache.
the class SimpleHeaderConverterTest method shouldConvertMapWithStringKeysAndMixedValuesToMap.
@Test
public void shouldConvertMapWithStringKeysAndMixedValuesToMap() {
Map<String, Object> map = new LinkedHashMap<>();
map.put("foo", "bar");
map.put("baz", (short) 3456);
SchemaAndValue result = roundTrip(null, map);
assertEquals(Schema.Type.MAP, result.schema().type());
assertEquals(Schema.Type.STRING, result.schema().keySchema().type());
assertNull(result.schema().valueSchema());
assertEquals(map, result.value());
}
use of org.apache.kafka.connect.data.SchemaAndValue in project kafka by apache.
the class StringConverterTest method testBytesToString.
@Test
public void testBytesToString() {
SchemaAndValue data = converter.toConnectData(TOPIC, SAMPLE_STRING.getBytes());
assertEquals(Schema.OPTIONAL_STRING_SCHEMA, data.schema());
assertEquals(SAMPLE_STRING, data.value());
}
use of org.apache.kafka.connect.data.SchemaAndValue in project kafka by apache.
the class StringConverterTest method testBytesToStringNonUtf8Encoding.
@Test
public void testBytesToStringNonUtf8Encoding() {
converter.configure(Collections.singletonMap("converter.encoding", StandardCharsets.UTF_16.name()), true);
SchemaAndValue data = converter.toConnectData(TOPIC, SAMPLE_STRING.getBytes(StandardCharsets.UTF_16));
assertEquals(Schema.OPTIONAL_STRING_SCHEMA, data.schema());
assertEquals(SAMPLE_STRING, data.value());
}
Aggregations