aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/at/gv/egiz
diff options
context:
space:
mode:
authorChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-07-17 13:17:21 +0200
committerChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-07-17 13:27:40 +0200
commitf2e1263702901581512131ea587fad7a2ba45baa (patch)
treeb92a38f758fecb039de184963116017921d2e314 /src/test/java/at/gv/egiz
parent896195cc9b287a3f41008cc85997b9c2209120b8 (diff)
downloadmoa-zs-f2e1263702901581512131ea587fad7a2ba45baa.tar.gz
moa-zs-f2e1263702901581512131ea587fad7a2ba45baa.tar.bz2
moa-zs-f2e1263702901581512131ea587fad7a2ba45baa.zip
Put MoaZSException on Diet & Handle Edge Cases
Reason: MoaZSException (and: its builder) were used to collect intermediary results while stepping through the delivery request backend. These results were needed to generate meaningful responses towards the sender application in case of error. However, the builder sprawled over too many interfaces (e.g. DeliveryRequestBackend and TNVZHelper) and it became difficult to understand from where intermediary results originated. Solution: Put MoaZSException on diet: - Remove all DeliveryAnswer fields from MoaZSException and refactor code base to ensure that the removed fields get sourced by other means. - Remove Builder since amount of parameters is manageable. Refactor DeliveryRequestBackend: - Instead of passing down the builder and using MoaZSException as the only source for intermediary results, we collect available results at the outermost stack frame (DeliveryRequestBackend.accept) and only retrieve results via exception if those results appear somewhere down the stack frame (E.g. PredviceNoteSent). We collect available results with the "fallbackAnswerBuilder" and switch to the msg client response, once received. Refactor MsgResponseBackend: - Handle cases (response missing, binary response missing) properly. - Integrate changes from MsgResponse.generateError() Refactor TVNZHelper: - Remove MoaZSExceptionBuilder from all interfaces. Refactor MsgResponse.generateError: - Change interface such that it's more intuitive. - Implement NotificationResponse.generateError. - Implement RequestStatusResponse.generateError. Others: - Replace all invocations against MoaZSException.Builder.
Diffstat (limited to 'src/test/java/at/gv/egiz')
-rw-r--r--src/test/java/at/gv/egiz/moazs/DeliveryRequestBackendTest.java28
-rw-r--r--src/test/java/at/gv/egiz/moazs/TnvzHelperTest.java9
2 files changed, 14 insertions, 23 deletions
diff --git a/src/test/java/at/gv/egiz/moazs/DeliveryRequestBackendTest.java b/src/test/java/at/gv/egiz/moazs/DeliveryRequestBackendTest.java
index ed63489..9ae0a14 100644
--- a/src/test/java/at/gv/egiz/moazs/DeliveryRequestBackendTest.java
+++ b/src/test/java/at/gv/egiz/moazs/DeliveryRequestBackendTest.java
@@ -20,7 +20,6 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import static at.gv.egiz.moazs.MoaZSException.moaZSException;
-import static at.gv.egiz.moazs.MoaZSException.moaZSExceptionBuilder;
import static at.gv.egiz.moazs.scheme.RequestStatusResponse.getResponseID;
import static at.gv.zustellung.app2mzs.xsd.ClientType.clientTypeBuilder;
import static at.gv.zustellung.app2mzs.xsd.ConfigType.configTypeBuilder;
@@ -57,11 +56,11 @@ public class DeliveryRequestBackendTest {
private SignatureVerifier verifier;
- private DeliveryRequestBackend pipeline;
+ private DeliveryRequestBackend backend;
@Before
public void setup() {
- pipeline = new DeliveryRequestBackend(
+ backend = new DeliveryRequestBackend(
repository,
tnvzHelper,
converter,
@@ -74,7 +73,7 @@ public class DeliveryRequestBackendTest {
var appDeliveryID = "no-tnvz-request";
var expectedStatus = setupMocks(appDeliveryID, false);
- pipeline.accept(appDeliveryID);
+ backend.accept(appDeliveryID);
verifyZeroInteractions(tnvzHelper);
var response = repository.retrieveResponse(getResponseID(appDeliveryID)).get();
@@ -87,10 +86,10 @@ public class DeliveryRequestBackendTest {
public void rejectDeliveryWhenReceiverIsNotAddressable() {
var appDeliveryID = "not-addressable";
setupMocks(appDeliveryID, true);
- when(tnvzHelper.performQueryPersonRequest(any(), any(), any()))
- .thenThrow(buildMzsException("400", appDeliveryID));
+ when(tnvzHelper.performQueryPersonRequest(any(), any()))
+ .thenThrow(moaZSException("Not addressable", "400"));
- pipeline.accept(appDeliveryID);
+ backend.accept(appDeliveryID);
var responseID = getResponseID(appDeliveryID);
var response = repository.retrieveResponse(responseID).get();
@@ -99,7 +98,7 @@ public class DeliveryRequestBackendTest {
assertThat(actualCode).isEqualTo("400");
verifyZeroInteractions(converter);
- verify(tnvzHelper).performQueryPersonRequest(any(), any(), any());
+ verify(tnvzHelper).performQueryPersonRequest(any(), any());
}
@Test
@@ -107,7 +106,7 @@ public class DeliveryRequestBackendTest {
var appDeliveryID = "tnvz-request";
var expectedStatus = setupMocks(appDeliveryID, true);
- pipeline.accept(appDeliveryID);
+ backend.accept(appDeliveryID);
var response = repository.retrieveResponse(getResponseID(appDeliveryID)).get();
var actualStatus = (DeliveryRequestStatusType) response.getResponse();
@@ -120,7 +119,7 @@ public class DeliveryRequestBackendTest {
setupMocks(appDeliveryID, true);
doThrow(moaZSException("Signature Invalid!")).when(verifier).accept(any());
- pipeline.accept(appDeliveryID);
+ backend.accept(appDeliveryID);
var response = repository.retrieveResponse(getResponseID(appDeliveryID)).get();
var status = (DeliveryRequestStatusType) response.getResponse();
var actualCode = status.getError().getErrorInfo().getCode();
@@ -146,19 +145,12 @@ public class DeliveryRequestBackendTest {
if (tnvzRequest) {
when(clientFactory.create(any(), same(TNVZServicePort.class))).thenReturn(tnvzClient);
- when(tnvzHelper.performQueryPersonRequest(any(), any(), any())).thenReturn(identification);
+ when(tnvzHelper.performQueryPersonRequest(any(), any())).thenReturn(identification);
}
return status;
}
- private MoaZSException buildMzsException(String code, String appDeliveryID) {
- return moaZSExceptionBuilder("")
- .withErrorCode(code)
- .withAppDeliveryID(appDeliveryID)
- .build();
- }
-
private DeliveryRequestStatusType setupStatus(String appDeliveryId) {
var success = successBuilder()
diff --git a/src/test/java/at/gv/egiz/moazs/TnvzHelperTest.java b/src/test/java/at/gv/egiz/moazs/TnvzHelperTest.java
index b58002b..020e270 100644
--- a/src/test/java/at/gv/egiz/moazs/TnvzHelperTest.java
+++ b/src/test/java/at/gv/egiz/moazs/TnvzHelperTest.java
@@ -16,7 +16,6 @@ import org.mockito.junit.MockitoJUnitRunner;
import java.util.List;
-import static at.gv.egiz.moazs.MoaZSException.moaZSExceptionBuilder;
import static at.gv.zustellung.app2mzs.xsd.DeliveryRequestType.Payload.payloadBuilder;
import static at.gv.zustellung.app2mzs.xsd.DeliveryRequestType.Receiver.receiverBuilder;
import static at.gv.zustellung.app2mzs.xsd.DeliveryRequestType.Sender.senderBuilder;
@@ -62,7 +61,7 @@ public class TnvzHelperTest {
var success = tnvzSuccess(acceptedTypes, receiverId);
when(port.queryPerson(any())).thenReturn(success);
- var actual = helper.performQueryPersonRequest(deliveryRequest, port, moaZSExceptionBuilder());
+ var actual = helper.performQueryPersonRequest(deliveryRequest, port);
assertThat(actual).isEqualToComparingFieldByFieldRecursively(receiverId);
}
@@ -75,7 +74,7 @@ public class TnvzHelperTest {
var error = tnvzError("400", "Person not found.");
when(port.queryPerson(any())).thenReturn(error);
- helper.performQueryPersonRequest(deliveryRequest, port, moaZSExceptionBuilder());
+ helper.performQueryPersonRequest(deliveryRequest, port);
}
@Test(expected = MoaZSException.class)
@@ -87,7 +86,7 @@ public class TnvzHelperTest {
var success = tnvzSuccess(acceptedTypes, receiverId);
when(port.queryPerson(any())).thenReturn(success);
- helper.performQueryPersonRequest(deliveryRequest, port, moaZSExceptionBuilder());
+ helper.performQueryPersonRequest(deliveryRequest, port);
}
@Test
@@ -99,7 +98,7 @@ public class TnvzHelperTest {
var success = tnvzSuccess(acceptedTypes, receiverId);
when(port.queryPerson(any())).thenReturn(success);
- var actual = helper.performQueryPersonRequest(deliveryRequest, port, moaZSExceptionBuilder());
+ var actual = helper.performQueryPersonRequest(deliveryRequest, port);
assertThat(actual).isEqualToComparingFieldByFieldRecursively(receiverId);
}