aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/at/gv/egiz/moazs
diff options
context:
space:
mode:
authorChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-08-20 11:13:28 +0200
committerChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-08-20 11:13:28 +0200
commit2b8a7df25878f546ace25373f44baeb026cf6d2b (patch)
tree8b236fdc42bc66beb16cc59b86258a7794285420 /src/test/java/at/gv/egiz/moazs
parent488ecf8632b7204b5da218643eb1631e2d3386ff (diff)
downloadmoa-zs-2b8a7df25878f546ace25373f44baeb026cf6d2b.tar.gz
moa-zs-2b8a7df25878f546ace25373f44baeb026cf6d2b.tar.bz2
moa-zs-2b8a7df25878f546ace25373f44baeb026cf6d2b.zip
Add Custom Http Headers to HTTP Clients
- Change app2mzs schema: Add Custom Headers to ClientType Element. - Set custom headers in ClientFactory. - Parse custom headers from spring environment. - Merge custom headers from two different profiles. - Add example to application.yaml. - Test conversion of custom headers from spring profile - Test merging and overriding custom headers.
Diffstat (limited to 'src/test/java/at/gv/egiz/moazs')
-rw-r--r--src/test/java/at/gv/egiz/moazs/ConfigUtilTest.java80
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();
+ }
+
+
+
+}