DBZ-759 Testing via SchemaUtil;

* Making RecordWriter private
* Removing quotes around string representation of byte arrays
This commit is contained in:
Gunnar Morling 2018-06-26 12:03:53 +02:00
parent 82bac78ba8
commit b27421ddd0
3 changed files with 64 additions and 56 deletions

View File

@ -119,7 +119,7 @@ public static String asDetailedString(SourceRecord record) {
return new RecordWriter().detailed(true).append(record).toString();
}
public static class RecordWriter {
private static class RecordWriter {
private final StringBuilder sb = new StringBuilder();
private boolean detailed = false;
@ -257,8 +257,7 @@ protected void append(ByteBuffer b) {
}
protected void append(byte[] b) {
String arrayString = Arrays.toString(b);
sb.append('"').append(arrayString).append('"');
sb.append(Arrays.toString(b));
}
protected void appendFirst(String name, Object value) {

View File

@ -1,42 +0,0 @@
/*
* Copyright Debezium Authors.
*
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package io.debezium.data;
import io.debezium.data.SchemaUtil.RecordWriter;
import io.debezium.doc.FixFor;
import java.nio.ByteBuffer;
import org.junit.Test;
import static org.fest.assertions.Assertions.assertThat;
/**
* Test for {@link SchemaUtil.RecordWriter}.
*
* @author Andreas Bergmeier
*
*/
public class RecordWriterTest {
@Test
@FixFor("DBZ-759")
public void correctlySerializesByteArray() {
final RecordWriter recordWriter = new RecordWriter();
recordWriter.append(new byte[]{1, 3, 5, 7});
assertThat(recordWriter.toString()).isEqualTo("\"[1, 3, 5, 7]\"");
}
@Test
@FixFor("DBZ-759")
public void correctlySerializesByteBuffer() {
final RecordWriter recordWriter = new RecordWriter();
final ByteBuffer buffer = ByteBuffer.allocate(3);
buffer.put(new byte[]{11, 13, 17});
recordWriter.append(buffer);
assertThat(recordWriter.toString()).isEqualTo("\"[11, 13, 17]\"");
}
}

View File

@ -0,0 +1,51 @@
/*
* Copyright Debezium Authors.
*
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package io.debezium.data;
import static org.fest.assertions.Assertions.assertThat;
import java.nio.ByteBuffer;
import org.apache.kafka.connect.data.Schema;
import org.apache.kafka.connect.data.SchemaBuilder;
import org.apache.kafka.connect.data.Struct;
import org.junit.Test;
import io.debezium.doc.FixFor;
/**
* Test for {@link SchemaUtil}.
*
* @author Andreas Bergmeier
*
*/
public class SchemaUtilTest {
@Test
@FixFor("DBZ-759")
public void correctlySerializesByteArray() {
assertThat(SchemaUtil.asString(new byte[]{1, 3, 5, 7})).isEqualTo("[1, 3, 5, 7]");
}
@Test
@FixFor("DBZ-759")
public void correctlySerializesByteBuffer() {
final ByteBuffer buffer = ByteBuffer.allocate(3);
buffer.put(new byte[]{11, 13, 17});
assertThat(SchemaUtil.asString(buffer)).isEqualTo("[11, 13, 17]");
}
@Test
@FixFor("DBZ-759")
public void correctlySerializesStructWithByteArray() {
Schema schema = SchemaBuilder.struct()
.field("some_field", SchemaBuilder.bytes().build())
.build();
Struct struct = new Struct(schema).put("some_field", new byte[]{1, 3, 5, 7});
assertThat(SchemaUtil.asString(struct)).isEqualTo("{\"some_field\" : [1, 3, 5, 7]}");
}
}