Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 15 additions & 20 deletions src/test/java/io/aiven/kafka/connect/transforms/HashTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,20 @@ void noFieldName_NullValue_Skip() {
assertEquals(originalRecord, result);
}

@ParameterizedTest
@ValueSource(strings = {"md5", "sha1", "sha256"})
void nullSchema(final String hashFunction) {
@Test
void nullSchema() {
final SinkRecord originalRecord = record(null, null);
final Throwable e = assertThrows(DataException.class,
() -> transformation(FIELD, true, hashFunction).apply(originalRecord));
() -> transformation(FIELD, true, DEFAULT_HASH_FUNCTION).apply(originalRecord));
assertEquals(dataPlace() + " schema can't be null: " + originalRecord, e.getMessage());
}

@ParameterizedTest
@ValueSource(strings = {"md5", "sha1", "sha256"})
void noFieldName_UnsupportedType(final String hashFunction) {
@Test
void noFieldName_UnsupportedType() {
final Schema schema = SchemaBuilder.struct().build();
final SinkRecord originalRecord = record(schema, new Struct(schema));
final Throwable e = assertThrows(DataException.class,
() -> transformation(null, true, hashFunction).apply(originalRecord));
() -> transformation(null, true, DEFAULT_HASH_FUNCTION).apply(originalRecord));
assertEquals(dataPlace()
+ " schema type must be STRING if field name is not specified: "
+ originalRecord,
Expand Down Expand Up @@ -153,41 +151,38 @@ void fieldName_MissingValue_Skip() {
assertEquals(originalRecord, result);
}

@ParameterizedTest
@ValueSource(strings = {"md5", "sha1", "sha256"})
void fieldName_NonStruct(final String hashFunction) {
@Test
void fieldName_NonStruct() {
final SinkRecord originalRecord = record(SchemaBuilder.INT8_SCHEMA, "some");
final Throwable e = assertThrows(DataException.class,
() -> transformation(FIELD, true, hashFunction).apply(originalRecord));
() -> transformation(FIELD, true, DEFAULT_HASH_FUNCTION).apply(originalRecord));
assertEquals(dataPlace() + " schema type must be STRUCT if field name is specified: "
+ originalRecord,
e.getMessage());
}

@ParameterizedTest
@ValueSource(strings = {"md5", "sha1", "sha256"})
void fieldName_NullStruct(final String hashFunction) {
@Test
void fieldName_NullStruct() {
final Schema schema = SchemaBuilder.struct()
.field(FIELD, SchemaBuilder.STRING_SCHEMA)
.schema();
final SinkRecord originalRecord = record(schema, null);
final Throwable e = assertThrows(DataException.class,
() -> transformation(FIELD, true, hashFunction).apply(originalRecord));
() -> transformation(FIELD, true, DEFAULT_HASH_FUNCTION).apply(originalRecord));
assertEquals(dataPlace() + " can't be null if field name is specified: " + originalRecord,
e.getMessage());
}

@ParameterizedTest
@ValueSource(strings = {"md5", "sha1", "sha256"})
void fieldName_UnsupportedTypeInField(final String hashFunction) {
@Test
void fieldName_UnsupportedTypeInField() {
final Schema innerSchema = SchemaBuilder.struct().build();
final Schema schema = SchemaBuilder.struct()
.field(FIELD, innerSchema)
.schema();
final SinkRecord originalRecord = record(
schema, new Struct(schema).put(FIELD, new Struct(innerSchema)));
final Throwable e = assertThrows(DataException.class,
() -> transformation(FIELD, true, hashFunction).apply(originalRecord));
() -> transformation(FIELD, true, DEFAULT_HASH_FUNCTION).apply(originalRecord));
assertEquals(FIELD + " schema type in " + dataPlace() + " must be STRING: "
+ originalRecord,
e.getMessage());
Expand Down