Search in sources :

Example 1 with AssertConnectRecord.assertSourceRecord

use of com.github.jcustenborder.kafka.connect.utils.AssertConnectRecord.assertSourceRecord in project connect-utils by jcustenborder.

the class SourceRecordSerializationModuleTest method roundtrip.

@Test
public void roundtrip() throws IOException {
    final Schema expectedKeySchema = SchemaBuilder.struct().name("key").field("id", Schema.INT64_SCHEMA).build();
    final Struct expectedKey = new Struct(expectedKeySchema).put("id", 1234L);
    final Schema expectedValueSchema = SchemaBuilder.struct().name("value").field("firstName", Schema.STRING_SCHEMA).field("lastName", Schema.STRING_SCHEMA).build();
    final Struct expectedValue = new Struct(expectedValueSchema).put("firstName", "foo").put("lastName", "bar");
    final SourceRecord expected = new SourceRecord(ImmutableMap.of(), ImmutableMap.of(), "test", 1, expectedKeySchema, expectedKey, expectedValueSchema, expectedValue, 1485910473123L);
    final String temp = ObjectMapperFactory.INSTANCE.writeValueAsString(expected);
    log.trace(temp);
    final SourceRecord actual = ObjectMapperFactory.INSTANCE.readValue(temp, SourceRecord.class);
    AssertConnectRecord.assertSourceRecord(expected, actual);
}
Also used : Schema(org.apache.kafka.connect.data.Schema) SourceRecord(org.apache.kafka.connect.source.SourceRecord) AssertConnectRecord.assertSourceRecord(com.github.jcustenborder.kafka.connect.utils.AssertConnectRecord.assertSourceRecord) Struct(org.apache.kafka.connect.data.Struct) Test(org.junit.jupiter.api.Test)

Aggregations

AssertConnectRecord.assertSourceRecord (com.github.jcustenborder.kafka.connect.utils.AssertConnectRecord.assertSourceRecord)1 Schema (org.apache.kafka.connect.data.Schema)1 Struct (org.apache.kafka.connect.data.Struct)1 SourceRecord (org.apache.kafka.connect.source.SourceRecord)1 Test (org.junit.jupiter.api.Test)1