Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DBZ-7090 Add unittests for ConfigMapping class #22

Merged
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
101 changes: 101 additions & 0 deletions src/test/java/io/debezium/operator/config/ConfigMappingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,19 @@
package io.debezium.operator.config;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.jupiter.api.Test;

import io.debezium.operator.model.ConfigProperties;
import io.debezium.operator.model.Predicate;
import io.debezium.operator.model.Transformation;

public class ConfigMappingTest {

@Test
Expand All @@ -20,4 +30,95 @@ void shouldNotAddNullValue() {
assertThat(config.getAsMap()).isEmpty();
assertThat(config.getAsString()).isEmpty();
}

@Test
void shouldAddRootValue() {
var config = ConfigMapping.empty();
config.rootValue("json");

assertThat(config.getAsMap()).containsEntry("", "json");
assertThat(config.getAsString()).isEqualTo("=json");
}

@Test
void shouldAddKeyAndValue() {
var config = ConfigMapping.empty();
config.put("key", "value");

assertThat(config.getAsMap()).containsEntry("key", "value");
assertThat(config.getAsString()).isEqualTo("key=value");
}

@Test
void shouldAddValuesFromMap() {
Map<String, String> properties = new HashMap<>();
properties.put("key1", "value1");
properties.put("key2", "value2");

var config = ConfigMapping.empty();
config.putAll(properties);

assertThat(config.getAsMap()).contains(entry("key1", "value1"), entry("key2", "value2"));
assertThat(config.getAsString()).isEqualTo("key1=value1\nkey2=value2");
}

@Test
void shouldAddList() {
var config = ConfigMapping.empty();

List<Map<String, Object>> configDataList = List.of(
Map.of("type", "io.debezium.transforms.ByLogicalTableRouter", "negate", false),
Map.of("type", "io.debezium.transforms.ByLogicalTableRouter", "negate", true));

List<Transformation> transformations = new ArrayList<>();

for (Map<String, Object> configData : configDataList) {
ConfigProperties configProperties = new ConfigProperties();
Transformation transformation = new Transformation();
transformation.setType((String) configData.get("type"));
transformation.setNegate((Boolean) configData.get("negate"));
transformation.setConfig(configProperties);
transformations.add(transformation);
}

config.putList("transforms", transformations, "Reroute");

assertThat(config.getAsMap()).containsEntry("transforms", "");
assertThat(config.getAsMap()).containsEntry("transforms.Reroute0.type", "io.debezium.transforms.ByLogicalTableRouter");
assertThat(config.getAsMap()).containsEntry("transforms.Reroute0.negate", "false");
assertThat(config.getAsMap()).containsEntry("transforms.Reroute1.type", "io.debezium.transforms.ByLogicalTableRouter");
assertThat(config.getAsMap()).containsEntry("transforms.Reroute1.negate", "true");

assertThat(config.getAsString()).isEqualTo("transforms.Reroute0.negate=false\n" +
"transforms.Reroute0.type=io.debezium.transforms.ByLogicalTableRouter\n" +
"transforms.Reroute1.negate=true\n" +
"transforms.Reroute1.type=io.debezium.transforms.ByLogicalTableRouter\n" +
"transforms=");
}

@Test
void shouldAddMap() {
var config = ConfigMapping.empty();
ConfigProperties configProperties = new ConfigProperties();
Predicate predicate = new Predicate();
predicate.setType("IsOutboxTable");
predicate.setConfig(configProperties);

Map<String, Predicate> predicateMap = Map.of("predicates", predicate);
config.putMap("map", predicateMap);

assertThat(config.getAsMap()).containsEntry("map", "predicates");
assertThat(config.getAsMap()).containsEntry("map.predicates.type", "IsOutboxTable");
assertThat(config.getAsString()).isEqualTo("map.predicates.type=IsOutboxTable\n" +
"map=predicates");
}

@Test
void shouldCalculateMD5Sum() {
var config = ConfigMapping.empty();
config.put("key1", "value1");
String md5Sum = config.md5Sum();

assertThat(md5Sum).isEqualTo("9767c4972ba72e87ab553bad2afde741");
}
}