DBZ-5530 Improve test cases

This commit is contained in:
Jiri Pechanec 2022-10-19 09:27:40 +02:00
parent 9072ea404f
commit c6babedbdf
3 changed files with 13 additions and 5 deletions

View File

@ -97,9 +97,10 @@ record = t.apply(record);
return record;
}
private static Transformation<SourceRecord> createPredicateTransformation(
boolean negate, Predicate<SourceRecord> predicate,
private static Transformation<SourceRecord> createPredicateTransformation(boolean negate,
Predicate<SourceRecord> predicate,
Transformation<SourceRecord> transformation) {
return new Transformation<>() {
@Override
public SourceRecord apply(SourceRecord sourceRecord) {
@ -127,7 +128,6 @@ public void close() {
@Override
public void configure(Map<String, ?> map) {
}
};
}

View File

@ -84,7 +84,9 @@ public void configure(Map<String, ?> configs) {
@Override
public SourceRecord apply(SourceRecord record) {
return ((String) record.value()).equals("Generated line number 1") ? null : record;
final String payload = (String) record.value();
return payload.equals("Generated line number 1") || payload.equals("Generated line number 2") ? null
: record;
}
@Override

View File

@ -7,6 +7,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import java.io.IOException;
import java.util.Collections;
@ -46,7 +47,6 @@ public void test() throws IOException {
properties.setProperty("transforms.b.value.literal", "b");
properties.setProperty("transforms.b.predicate", "hasheader");
properties.setProperty("transforms.b.negate", "true");
properties.setProperty("transforms.b.predicate", "hasheader");
Configuration configuration = Configuration.from(properties);
SourceRecord updated;
@ -60,6 +60,12 @@ public void test() throws IOException {
assertNotNull(updated.headers().lastWithName("h1"));
assertEquals("a", updated.headers().lastWithName("h1").value());
// record does not have header, transformation not applied
a = transformations.getTransformation("a");
updated = a.apply(new SourceRecord(Collections.emptyMap(), Collections.emptyMap(), "t1", 1, null, "key", null, "value", System.currentTimeMillis(),
new ConnectHeaders()));
assertNull(updated.headers().lastWithName("h1"));
// record does not have header, but transformation will still apply due to negation
Transformation<SourceRecord> b = transformations.getTransformation("b");
updated = b.apply(new SourceRecord(Collections.emptyMap(), Collections.emptyMap(), "t1", 1, null, "key", null, "value", System.currentTimeMillis(),