diff options
Diffstat (limited to 'src/test/java')
-rw-r--r-- | src/test/java/at/gv/egiz/moazs/ConfigUtilTest.java | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/test/java/at/gv/egiz/moazs/ConfigUtilTest.java b/src/test/java/at/gv/egiz/moazs/ConfigUtilTest.java new file mode 100644 index 0000000..d7ac0a1 --- /dev/null +++ b/src/test/java/at/gv/egiz/moazs/ConfigUtilTest.java @@ -0,0 +1,80 @@ +package at.gv.egiz.moazs; + +import at.gv.egiz.moazs.preprocess.ConfigUtil; +import at.gv.zustellung.app2mzs.xsd.ConfigType; +import org.junit.Before; +import org.junit.Test; + +import java.util.List; +import java.util.Map; + +import static at.gv.zustellung.app2mzs.xsd.ClientType.clientTypeBuilder; +import static at.gv.zustellung.app2mzs.xsd.ConfigType.configTypeBuilder; +import static org.assertj.core.api.Assertions.assertThat; + +public class ConfigUtilTest { + + private ConfigUtil configUtil; + + @Before + public void setup() { + configUtil = new ConfigUtil(); + } + + @Test + public void convertTNVZClientsCustomHttpHeaders() { + var prefix = ConfigUtil.TNVZ_CLIENT_KEY + "." + ConfigUtil.CUSTOM_HTTP_HEADERS_KEY + "."; + var map = Map.of( + prefix + "X-PVP-VERSION", "2.1", + prefix + "X-PVP-BINDING", "http", + prefix + "X-PVP-PARTICIPANT_ID", "AT:L9:MA2412" + ); + + ConfigType config = configUtil.convert(map); + var customHeaderMap = configUtil.convertHeadersToMap(config.getTNVZClient().getCustomHTTPHeader()); + + assertThat(customHeaderMap).containsEntry("X-PVP-VERSION", List.of("2.1")); + assertThat(customHeaderMap).containsEntry("X-PVP-BINDING", List.of("http")); + assertThat(customHeaderMap).containsEntry("X-PVP-PARTICIPANT_ID", List.of("AT:L9:MA2412")); + assertThat(customHeaderMap).hasSize(3); + } + + @Test + public void overrideCustomHeaders() { + + var fallbackConfig = createConfig(Map.of( + "X-header-1", "fallback-value-a", + "X-header-2", "fallback-value-b" + )); + + var primaryConfig = createConfig(Map.of( + "X-header-2", "primary-value-c", + "X-header-3", "primary-value-d" + )); + + ConfigType mergedConfig = configUtil.merge(primaryConfig, fallbackConfig); + var mergedHeaderMap = configUtil.convertHeadersToMap(mergedConfig.getTNVZClient().getCustomHTTPHeader()); + + assertThat(mergedHeaderMap).containsEntry("X-header-1", List.of("fallback-value-a")); + assertThat(mergedHeaderMap).containsEntry("X-header-2", List.of("primary-value-c")); + assertThat(mergedHeaderMap).containsEntry("X-header-3", List.of("primary-value-d")); + assertThat(mergedHeaderMap).hasSize(3); + + } + + private ConfigType createConfig(Map<String, String> headerMap) { + + var headers = configUtil.convertMapToHeaders(headerMap); + + var client = clientTypeBuilder() + .withCustomHTTPHeader(headers) + .build(); + + return configTypeBuilder() + .withTNVZClient(client) + .build(); + } + + + +} |