From 4b6ce58f339d69c70ef746ceecae78bf7ed0f0ba Mon Sep 17 00:00:00 2001 From: Christof Rabensteiner Date: Tue, 2 Jul 2019 16:42:43 +0200 Subject: Handle tnvz Query Edge Cases by Improving Validation TnvzHelper Fixes - Handle additional edge cases. - Mzs:Schema Change: Eliminate PreAdviceNote redundancy by removing it from mzs:DeliveryRequest/TnvzMetaData; PreadviceNote is already in the Receiver element. Update TnvzHelper accordingly. - Implement and integrate tnvz completeness check into DeliveryRequestAugmenter to ensure that, after augmentation, tnvz can be performed. Refactor mzs:DeliveryRequest Validation: - Before: Validating, merging and generatig ConfigType in ConfigUtil. - Change: Need to add validation of DeliveryRequest (Reason: For performing Tnvz Requests, the DeliveryRequest needs to be in a consistent state). - Problem: DeliveryRequest validation does not fit into ConfigUtil. - Solution: Put validation of DeliveryRequest and Config into new Component "MzsValidation". --- .../java/at/gv/egiz/moazs/ConfigProfileGeneratorTest.java | 11 ++++++++--- .../java/at/gv/egiz/moazs/DeliveryRequestAugmenterTest.java | 12 ++++++++---- 2 files changed, 16 insertions(+), 7 deletions(-) (limited to 'src/test/java/at/gv/egiz') diff --git a/src/test/java/at/gv/egiz/moazs/ConfigProfileGeneratorTest.java b/src/test/java/at/gv/egiz/moazs/ConfigProfileGeneratorTest.java index 95cccd1..3157447 100644 --- a/src/test/java/at/gv/egiz/moazs/ConfigProfileGeneratorTest.java +++ b/src/test/java/at/gv/egiz/moazs/ConfigProfileGeneratorTest.java @@ -1,5 +1,6 @@ package at.gv.egiz.moazs; +import at.gv.egiz.moazs.mzs.MzsValidator; import at.gv.egiz.moazs.preprocess.*; import org.junit.Test; import org.junit.runner.RunWith; @@ -23,6 +24,9 @@ public class ConfigProfileGeneratorTest { @Mock private ConfigUtil util; + @Mock + private MzsValidator validator; + @Mock private SpringPropertiesFacade properties; @@ -87,7 +91,7 @@ public class ConfigProfileGeneratorTest { public void cancelAtIncompleteDefaultProfile() { var propMap = Map.of(PREFIX + "." + DEFAULT + ".property-a", "value-a"); var generator = setupMocksAndBuilder(propMap).build(); - when(util.isComplete(any())).thenReturn(false); + when(validator.isConfigProfileComplete(any())).thenReturn(false); generator.generate(); } @@ -96,7 +100,7 @@ public class ConfigProfileGeneratorTest { public void continueAtIncompleteDefaultWhenVerificationDisabled() { var propMap = Map.of(PREFIX + "." + DEFAULT + ".property-a", "value-a"); - when(util.isComplete(any())).thenReturn(false); + when(validator.isConfigProfileComplete(any())).thenReturn(false); var generator = setupMocksAndBuilder(propMap) .withVerifyCompletenessOfDefaultConfiguration(false) @@ -112,14 +116,15 @@ public class ConfigProfileGeneratorTest { when(properties.getPropertyNames()).thenReturn(propMap.keySet().stream()); when(properties.getProperty(any())).thenAnswer(i -> propMap.get(i.getArgument(0))); when(util.merge(any(), any())).thenAnswer(i -> i.getArgument(0)); - when(util.isComplete(any())).thenReturn(true); when(util.convert(any())).thenReturn(configTypeBuilder().build()); + when(validator.isConfigProfileComplete(any())).thenReturn(true); return configProfileGeneratorBuilder() .withProperties(properties) .withConfigUtil(util) .withDefaultConfigKey(DEFAULT) .withProfilePrefix(PREFIX) + .withValidator(validator) .withVerifyCompletenessOfDefaultConfiguration(true); } diff --git a/src/test/java/at/gv/egiz/moazs/DeliveryRequestAugmenterTest.java b/src/test/java/at/gv/egiz/moazs/DeliveryRequestAugmenterTest.java index 4bd64ef..424dce1 100644 --- a/src/test/java/at/gv/egiz/moazs/DeliveryRequestAugmenterTest.java +++ b/src/test/java/at/gv/egiz/moazs/DeliveryRequestAugmenterTest.java @@ -1,5 +1,6 @@ package at.gv.egiz.moazs; +import at.gv.egiz.moazs.mzs.MzsValidator; import at.gv.egiz.moazs.preprocess.ConfigUtil; import at.gv.egiz.moazs.preprocess.DeliveryRequestAugmenter; import at.gv.zustellung.app2mzs.xsd.ConfigType; @@ -8,7 +9,6 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; import java.util.Map; @@ -28,9 +28,13 @@ public class DeliveryRequestAugmenterTest { @Mock private ConfigUtil configUtil; + @Mock + private MzsValidator validator; + @Before public void setupMock() { - when(configUtil.isComplete(Mockito.any())).thenReturn(true); + when(validator.isConfigProfileComplete(any())).thenReturn(true); + when(validator.isTnvzComplete(any())).thenReturn(true); when(configUtil.merge(any(), any())).thenCallRealMethod(); } @@ -105,11 +109,11 @@ public class DeliveryRequestAugmenterTest { } private DeliveryRequestAugmenter createAugmenter(ConfigType fallback) { - return new DeliveryRequestAugmenter(Map.of("default", fallback), configUtil); + return new DeliveryRequestAugmenter(Map.of("default", fallback), configUtil, validator); } private DeliveryRequestAugmenter createAugmenter(Map profiles) { - return new DeliveryRequestAugmenter(profiles, configUtil); + return new DeliveryRequestAugmenter(profiles, configUtil, validator); } private ConfigType createConfig(String url, Boolean performTnvz) { -- cgit v1.2.3