aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-05-15 09:16:04 +0200
committerChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-05-15 09:16:04 +0200
commit87f4be0b8834e6090137f2db2154bf50bcfcf646 (patch)
tree31a8e0183f94f231adba381a655b54a3b48039f2 /src/test/java
parente70ec39488c0688d8144fa529d58d60ae9564fbd (diff)
downloadmoa-zs-87f4be0b8834e6090137f2db2154bf50bcfcf646.tar.gz
moa-zs-87f4be0b8834e6090137f2db2154bf50bcfcf646.tar.bz2
moa-zs-87f4be0b8834e6090137f2db2154bf50bcfcf646.zip
Integrate Config Profiles + Refactoring
Config Profile Integration: - Merge generated Configs from ConfigProfileGenerator with the default Config; Reason: Merging profile Configs with default Config asap ensures that profile Configs are "as complete as possible" while allowing profile Configs to "on-demand"-override values from the default Config. - Adapt Augmenter to work with Config profiles: Select a Config on the basis of on msg:DeliveryRequest/Config/ProfileId, fall back to 'default' Config. - Schema change: Make ProfileID optional. Refactoring: - Move Config-merging code from Augmenter into dedicated 'ConfigProfileMerger' class. - ConfigProfileGenerator: Clarify stream pipeline and comply with coding standard w.r.t. constant members. - Add Augmenter test cases for profile selection.
Diffstat (limited to 'src/test/java')
-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();
}