aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/at/gv/egiz
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/at/gv/egiz')
-rw-r--r--src/test/java/at/gv/egiz/moazs/DeliveryRequestAugmenterTest.java130
1 files changed, 86 insertions, 44 deletions
diff --git a/src/test/java/at/gv/egiz/moazs/DeliveryRequestAugmenterTest.java b/src/test/java/at/gv/egiz/moazs/DeliveryRequestAugmenterTest.java
index a555bb9..a79efaf 100644
--- a/src/test/java/at/gv/egiz/moazs/DeliveryRequestAugmenterTest.java
+++ b/src/test/java/at/gv/egiz/moazs/DeliveryRequestAugmenterTest.java
@@ -1,10 +1,13 @@
package at.gv.egiz.moazs;
+import at.gv.egiz.moazs.preprocess.ConfigProfileMerger;
import at.gv.egiz.moazs.preprocess.DeliveryRequestAugmenter;
import at.gv.zustellung.app2mzs.xsd.ConfigType;
import at.gv.zustellung.app2mzs.xsd.DeliveryRequestType;
import org.junit.Test;
+import java.util.Map;
+
import static at.gv.zustellung.app2mzs.xsd.ConfigType.configTypeBuilder;
import static at.gv.zustellung.app2mzs.xsd.DeliveryRequestType.deliveryRequestTypeBuilder;
import static at.gv.zustellung.app2mzs.xsd.ServerType.serverTypeBuilder;
@@ -14,52 +17,90 @@ public class DeliveryRequestAugmenterTest {
private final String msgUrl = "http://mzs";
-// @Test
-// public void augmentPrimaryWithoutConfig() {
-// var fallback = createConfig(msgUrl, false);
-// var augmenter = new DeliveryRequestAugmenter(fallback, mzsMarshaller, deliveryRequestConfigs);
-//
-// var actual = augmenter.augment(createRequest(null)).getConfig();
-//
-// assertThat(actual).isEqualToComparingFieldByFieldRecursively(fallback);
-// }
-//
-// @Test
-// public void augmentPrimaryWithEmptyConfig() {
-// var fallback = createConfig(msgUrl, false);
-// var augmenter = new DeliveryRequestAugmenter(fallback, mzsMarshaller, deliveryRequestConfigs);
-// var primary = createConfig(null, null);
-//
-// var actual = augmenter.augment(createRequest(primary)).getConfig();
-//
-// assertThat(actual).isEqualToComparingFieldByFieldRecursively(fallback);
-// }
-//
-// @Test
-// public void overrideFallbacksUrlWithPrimary() {
-// var fallback = createConfig("http://fallback.url", false);
-// var primary = createConfig("http://primary.url", null);
-// var augmenter = new DeliveryRequestAugmenter(fallback, mzsMarshaller, deliveryRequestConfigs);
-//
-// var actual = augmenter.augment(createRequest(primary)).getConfig();
-//
-// var expected = createConfig("http://primary.url", false);
-// assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
-// }
-//
-// @Test
-// public void overrideFallbacksTvnzQueryWithPrimary() {
-// var fallback = createConfig(msgUrl, false);
-// var primary = createConfig(null, true);
-// var augmenter = new DeliveryRequestAugmenter(fallback, mzsMarshaller, deliveryRequestConfigs);
-//
-// var actual = augmenter.augment(createRequest(primary)).getConfig();
-//
-// var expected = createConfig(msgUrl, true);
-// assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
-// }
+ @Test
+ public void augmentPrimaryWithoutConfig() {
+ var fallback = createConfig(msgUrl, false);
+ var augmenter = createAugmenter(fallback);
+
+ var actual = augmenter.augment(createRequest(null)).getConfig();
+
+ assertThat(actual).isEqualToComparingFieldByFieldRecursively(fallback);
+ }
+
+ @Test
+ public void augmentPrimaryWithEmptyConfig() {
+ var fallback = createConfig(msgUrl, false);
+ var augmenter = createAugmenter(fallback);
+ var primary = createConfig(null, null);
+
+ var actual = augmenter.augment(createRequest(primary)).getConfig();
+
+ assertThat(actual).isEqualToComparingFieldByFieldRecursively(fallback);
+ }
+
+ @Test
+ public void overrideUrlWithPrimary() {
+ var fallback = createConfig("http://fallback.url", false);
+ var primary = createConfig("http://primary.url", null);
+ var augmenter = createAugmenter(fallback);
+
+ var actual = augmenter.augment(createRequest(primary)).getConfig();
+
+ var expected = createConfig("http://primary.url", false);
+ assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
+ }
+
+ @Test
+ public void overrideTvnzQueryWithPrimary() {
+ var fallback = createConfig(msgUrl, false);
+ var primary = createConfig(null, true);
+ var augmenter = createAugmenter(fallback);
+
+ var actual = augmenter.augment(createRequest(primary)).getConfig();
+
+ var expected = createConfig(msgUrl, true);
+ assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
+ }
+
+ @Test
+ public void selectConfigByProfileId() {
+ var defaultConfig = createConfig("http://default.url" , false);
+ var selectableConfig = createConfig("http://selected.url", false);
+ var augmenter = createAugmenter(Map.of("default", defaultConfig, "selectable-profile-id", selectableConfig));
+
+ var requestConfig = createConfig(null, null, "selectable-profile-id");
+ var actual = augmenter.augment(createRequest(requestConfig)).getConfig();
+
+ assertThat(actual).isEqualToComparingFieldByFieldRecursively(selectableConfig);
+ }
+
+ @Test
+ public void selectConfigByProfileIdAndOverrideMsgUrl() {
+ var defaultConfig = createConfig("http://default.url" , false);
+ var selectableConfig = createConfig("http://selected.url", true);
+ var augmenter = createAugmenter(Map.of("default", defaultConfig, "selectable-profile-id", selectableConfig));
+
+ var requestConfig = createConfig("http://override.url", null, "selectable-profile-id");
+ var actual = augmenter.augment(createRequest(requestConfig)).getConfig();
+
+ var expected = createConfig("http://override.url", true);
+ assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
+ }
+
+ private DeliveryRequestAugmenter createAugmenter(ConfigType fallback) {
+ return new DeliveryRequestAugmenter(Map.of("default", fallback), new ConfigProfileMerger());
+ }
+
+ private DeliveryRequestAugmenter createAugmenter(Map<String, ConfigType> profiles) {
+ return new DeliveryRequestAugmenter(profiles, new ConfigProfileMerger());
+ }
+
private ConfigType createConfig(String url, Boolean performTnvz) {
+ return createConfig(url, performTnvz, null);
+ }
+
+ private ConfigType createConfig(String url, Boolean performTnvz, String profileId) {
var server = serverTypeBuilder()
.withZUSEUrlID(url)
@@ -68,6 +109,7 @@ public class DeliveryRequestAugmenterTest {
return configTypeBuilder()
.withServer(server)
.withPerformQueryPersonRequest(performTnvz)
+ .withProfileID(profileId)
.build();
}