aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/at/gv/egiz/moazs/mzs/MzsValidator.java6
-rw-r--r--src/main/java/at/gv/egiz/moazs/scheme/Mzs2MsgConverter.java2
-rw-r--r--src/main/java/at/gv/egiz/moazs/tnvz/TnvzHelper.java11
-rw-r--r--src/test/java/at/gv/egiz/moazs/TnvzHelperTest.java202
4 files changed, 211 insertions, 10 deletions
diff --git a/src/main/java/at/gv/egiz/moazs/mzs/MzsValidator.java b/src/main/java/at/gv/egiz/moazs/mzs/MzsValidator.java
index c5b73bb..26ea7dc 100644
--- a/src/main/java/at/gv/egiz/moazs/mzs/MzsValidator.java
+++ b/src/main/java/at/gv/egiz/moazs/mzs/MzsValidator.java
@@ -16,7 +16,11 @@ public class MzsValidator {
* @return true if mandatory fields are present.
*/
public boolean isTnvzComplete(DeliveryRequestType request) {
- return (!request.getConfig().isPerformQueryPersonRequest()) || request.getTnvzMetaData() != null;
+ return !request.getConfig().isPerformQueryPersonRequest() ||
+ (request.getTnvzMetaData() != null
+ && request.getSender().getCorporateBody() != null);
+
+
}
/**
diff --git a/src/main/java/at/gv/egiz/moazs/scheme/Mzs2MsgConverter.java b/src/main/java/at/gv/egiz/moazs/scheme/Mzs2MsgConverter.java
index fdb2ab8..6976738 100644
--- a/src/main/java/at/gv/egiz/moazs/scheme/Mzs2MsgConverter.java
+++ b/src/main/java/at/gv/egiz/moazs/scheme/Mzs2MsgConverter.java
@@ -61,7 +61,7 @@ public class Mzs2MsgConverter {
//------------- SENDER ------------------
- public Sender convert(at.gv.zustellung.app2mzs.xsd.DeliveryRequestType.Sender sender) {
+ private Sender convert(at.gv.zustellung.app2mzs.xsd.DeliveryRequestType.Sender sender) {
return senderBuilder()
.withSenderPerson(extractSenderPerson(sender))
.withLogo(sender.getLogo())
diff --git a/src/main/java/at/gv/egiz/moazs/tnvz/TnvzHelper.java b/src/main/java/at/gv/egiz/moazs/tnvz/TnvzHelper.java
index 3599362..f71b992 100644
--- a/src/main/java/at/gv/egiz/moazs/tnvz/TnvzHelper.java
+++ b/src/main/java/at/gv/egiz/moazs/tnvz/TnvzHelper.java
@@ -115,11 +115,6 @@ public class TnvzHelper {
private Sender extractSender(DeliveryRequestType.Sender sender) {
var corporateBody = sender.getCorporateBody();
- if (corporateBody == null) {
- //todo! implement this case
- throw MoaZSException.moaZSException("Not Implemented.");
- }
-
var mzsIdentification = corporateBody.getIdentification().get(0);
var msgIdentification = converter.convert(mzsIdentification);
@@ -135,9 +130,7 @@ public class TnvzHelper {
var builder = receiverBuilder();
- if (receiver.getIdentification() != null) {
- builder.withIdentification(converter.convert(receiver.getIdentification()));
- } else {
+ if (receiver.getIdentification() == null) {
builder
.withPerson(converter.convert(receiver.getPerson()))
.withAustrianAddressesOnly(receiver.getAustrianAddressesOnly());
@@ -149,6 +142,8 @@ public class TnvzHelper {
if (receiver.getPreAdviceNote() != null) {
builder.withNotificationAddressList(receiver.getPreAdviceNote().getNotificationAddressList());
}
+ } else {
+ builder.withIdentification(converter.convert(receiver.getIdentification()));
}
return builder.build();
diff --git a/src/test/java/at/gv/egiz/moazs/TnvzHelperTest.java b/src/test/java/at/gv/egiz/moazs/TnvzHelperTest.java
new file mode 100644
index 0000000..4425297
--- /dev/null
+++ b/src/test/java/at/gv/egiz/moazs/TnvzHelperTest.java
@@ -0,0 +1,202 @@
+package at.gv.egiz.moazs;
+
+
+import at.gv.egiz.moazs.scheme.Mzs2MsgConverter;
+import at.gv.egiz.moazs.tnvz.TnvzHelper;
+import at.gv.zustellung.app2mzs.xsd.DeliveryRequestType;
+import at.gv.zustellung.app2mzs.xsd.persondata.IdentificationType;
+import at.gv.zustellung.tnvz.xsd.MimeTypeList;
+import at.gv.zustellung.tnvz.xsd.QueryPersonResponse;
+import at.gv.zustellung.tnvz.xsd.TNVZServicePort;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+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;
+import static at.gv.zustellung.app2mzs.xsd.DeliveryRequestType.deliveryRequestTypeBuilder;
+import static at.gv.zustellung.app2mzs.xsd.TnvzMetaDataType.tnvzMetaDataTypeBuilder;
+import static at.gv.zustellung.app2mzs.xsd.persondata.CorporateBodyType.corporateBodyTypeBuilder;
+import static at.gv.zustellung.app2mzs.xsd.persondata.IdentificationType.Value.valueBuilder;
+import static at.gv.zustellung.app2mzs.xsd.persondata.IdentificationType.identificationTypeBuilder;
+import static at.gv.zustellung.msg.xsd.ErrorInfoType.errorInfoTypeBuilder;
+import static at.gv.zustellung.tnvz.xsd.MimeTypeList.mimeTypeListBuilder;
+import static at.gv.zustellung.tnvz.xsd.PersonResultSuccessType.personResultSuccessTypeBuilder;
+import static at.gv.zustellung.tnvz.xsd.PersonResultType.Error.errorBuilder;
+import static at.gv.zustellung.tnvz.xsd.PersonResultType.personResultTypeBuilder;
+import static at.gv.zustellung.tnvz.xsd.QueryPersonResponse.QueryResultList.queryResultListBuilder;
+import static at.gv.zustellung.tnvz.xsd.QueryPersonResponse.queryPersonResponseBuilder;
+import static java.util.stream.Collectors.toList;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public class TnvzHelperTest {
+
+ private TnvzHelper helper;
+
+ @Mock
+ private TNVZServicePort port;
+
+ private Mzs2MsgConverter converter;
+
+ @Before
+ public void setup() {
+ converter = new Mzs2MsgConverter();
+ helper = new TnvzHelper(converter);
+ }
+
+ @Test
+ public void acceptWildcardMimetype() {
+ List<String> acceptedTypes = List.of("*/*");
+ List<String> attachedTypes = List.of("pdf", "xml", "html", "random/attachedtype");
+ var receiverId = identification("zbpk", "receiver-id-value");
+ var deliveryRequest = deliveryRequest(attachedTypes, receiverId);
+ var success = tnvzSuccess(acceptedTypes, receiverId);
+ when(port.queryPerson(any())).thenReturn(success);
+
+ var actual = helper.performQueryPersonRequest(deliveryRequest, port, moaZSExceptionBuilder());
+
+ assertThat(actual).isEqualToComparingFieldByFieldRecursively(receiverId);
+ }
+
+ @Test(expected = MoaZSException.class)
+ public void rejectWhenNotAddressable() {
+ List<String> attachedTypes = List.of("*/*");
+ var receiverId = identification("zbpk", "receiver-id-value");
+ var deliveryRequest = deliveryRequest(attachedTypes, receiverId);
+ var error = tnvzError("400", "Person not found.");
+ when(port.queryPerson(any())).thenReturn(error);
+
+ helper.performQueryPersonRequest(deliveryRequest, port, moaZSExceptionBuilder());
+ }
+
+ @Test(expected = MoaZSException.class)
+ public void rejectMismatchedMimeTypes() {
+ List<String> acceptedTypes = List.of("xml");
+ List<String> attachedTypes = List.of("pdf", "xml", "html", "random/attachedtype");
+ var receiverId = identification("zbpk", "receiver-id-value");
+ var deliveryRequest = deliveryRequest(attachedTypes, receiverId);
+ var success = tnvzSuccess(acceptedTypes, receiverId);
+ when(port.queryPerson(any())).thenReturn(success);
+
+ helper.performQueryPersonRequest(deliveryRequest, port, moaZSExceptionBuilder());
+ }
+
+ @Test
+ public void acceptSpecificMimeType() {
+ List<String> acceptedTypes = List.of("pdf", "xml", "html");
+ List<String> attachedTypes = List.of("pdf", "xml");
+ var receiverId = identification("zbpk", "receiver-id-value");
+ var deliveryRequest = deliveryRequest(attachedTypes, receiverId);
+ var success = tnvzSuccess(acceptedTypes, receiverId);
+ when(port.queryPerson(any())).thenReturn(success);
+
+ var actual = helper.performQueryPersonRequest(deliveryRequest, port, moaZSExceptionBuilder());
+
+ assertThat(actual).isEqualToComparingFieldByFieldRecursively(receiverId);
+ }
+
+
+ private DeliveryRequestType deliveryRequest(List<String> mzsMimeTypes, IdentificationType receiverId) {
+
+ var corporateBody = corporateBodyTypeBuilder()
+ .withFullName("Corporate Sender GmbH")
+ .withIdentification(List.of(identification("zbpk", "deadbeef")))
+ .build();
+
+ var sender = senderBuilder()
+ .withCorporateBody(corporateBody)
+ .build();
+
+ var receiver = receiverBuilder()
+ .withIdentification(receiverId)
+ .build();
+
+ var metadata = tnvzMetaDataTypeBuilder()
+ .build();
+
+ return deliveryRequestTypeBuilder()
+ .withSender(sender)
+ .withReceiver(receiver)
+ .withTnvzMetaData(metadata)
+ .withPayload(payload(mzsMimeTypes))
+ .build();
+ }
+
+ private IdentificationType identification(String id, String value) {
+
+ var receiverIdValue = valueBuilder()
+ .withValue(value)
+ .build();
+
+ return identificationTypeBuilder()
+ .withId(id)
+ .withValue(receiverIdValue)
+ .build();
+ }
+
+ private List<DeliveryRequestType.Payload> payload(List<String> mimeTypes) {
+ return mimeTypes.stream()
+ .map((mtype) -> payloadBuilder().withMIMEType(mtype).build())
+ .collect(toList());
+ }
+
+ private QueryPersonResponse tnvzSuccess(List<String> mimeTypes, IdentificationType receiverId) {
+
+ var success = personResultSuccessTypeBuilder()
+ .withMimeTypeList(setupMimeTypeList(mimeTypes))
+ .withIdentification(converter.convert(receiverId))
+ .build();
+
+ var personResult = personResultTypeBuilder()
+ .withSuccess(success)
+ .build();
+
+ var queryResultList = queryResultListBuilder()
+ .withQueryResult(List.of(personResult))
+ .build();
+
+ return queryPersonResponseBuilder()
+ .withQueryResultList(queryResultList)
+ .build();
+ }
+
+ private QueryPersonResponse tnvzError(String code, String text) {
+
+ var info = errorInfoTypeBuilder()
+ .withCode(code)
+ .withText(text)
+ .build();
+
+ var error = errorBuilder()
+ .withErrorInfo(info)
+ .build();
+
+ var result = personResultTypeBuilder()
+ .withError(error)
+ .build();
+
+ var queryResultList = queryResultListBuilder()
+ .withQueryResult(List.of(result))
+ .build();
+
+ return queryPersonResponseBuilder()
+ .withQueryResultList(queryResultList)
+ .build();
+ }
+
+
+ private MimeTypeList setupMimeTypeList(List<String> mimeTypes) {
+ return mimeTypeListBuilder().withMimeType(mimeTypes).build();
+ }
+
+
+}