/******************************************************************************* * Copyright 2019 Graz University of Technology * MOA ZS has been developed in a cooperation between EGIZ * and Graz University of Technology. * Licensed under the EUPL, Version 1.2 or - as soon they will be approved by * the European Commission - subsequent versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: * https://joinup.ec.europa.eu/news/understanding-eupl-v12 * * Unless required by applicable law or agreed to in writing, software * distributed under the Licence is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and * limitations under the Licence. * * This product combines work with different licenses. See the "NOTICE" text * file for details on the various modules and licenses. * The "NOTICE" text file is part of the distribution. Any derivative works * that you distribute must include a readable copy of the "NOTICE" text file. *******************************************************************************/ package at.gv.egiz.moazs; import at.gv.egiz.moazs.scheme.Marshaller; import at.gv.egiz.moazs.scheme.Mzs2MsgConverter; import at.gv.zustellung.app2mzs.xsd.DeliveryRequestType; import at.gv.zustellung.msg.xsd.ObjectFactory; import at.gv.zustellung.msg.xsd.persondata.IdentificationType; import org.junit.Before; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.xml.bind.JAXBElement; import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io.IOException; import static at.gv.zustellung.msg.xsd.persondata.IdentificationType.Value.valueBuilder; import static at.gv.zustellung.msg.xsd.persondata.IdentificationType.identificationTypeBuilder; import static org.assertj.core.api.Assertions.assertThat; /** * @author Christof Rabensteiner * */ public class Mzs2MsgConverterTest { private final String basePath = "src/test/resources/at/gv/egiz/moazs/Mzs2MsgConverterTest/"; private final static Logger logger = LoggerFactory.getLogger(Mzs2MsgConverterTest.class); private Mzs2MsgConverter converter; private Marshaller mzsMarshaller; private Marshaller msgMarshaller; @Before public void setUp() { converter = new Mzs2MsgConverter(); mzsMarshaller = new Marshaller(true); msgMarshaller = new Marshaller(false); } @Test public void testCanConvertValidMzsRequestToMsgRequest() throws IOException { var fileName = basePath + "/validMzsDeliveryRequest.xml"; try (var inputStream = new BufferedInputStream(new FileInputStream(fileName))) { JAXBElement mzsRequest = mzsMarshaller.unmarshallXml(inputStream); var msgRequest = converter.convert(mzsRequest.getValue()); var jaxbMsgRequest = new ObjectFactory().createDeliveryRequest(msgRequest); String msgRequestXML = msgMarshaller.marshallXml(jaxbMsgRequest); logger.info(msgRequestXML); assertThat(msgRequestXML).contains("valid-delivery-request-id"); } } @Test public void testCanConvertValidMzsRequestToMsgRequestWithIdentificationFromTNVZ() throws IOException { var fileName = basePath + "/validMzsDeliveryRequest.xml"; var idFromTNVZ = identificationTypeBuilder() .withType("some-id-type") .withValue(valueBuilder().withValue("some-id-value").build()) .build(); try (var inputStream = new BufferedInputStream(new FileInputStream(fileName))) { JAXBElement mzsRequest = mzsMarshaller.unmarshallXml(inputStream); var msgRequest = converter.convert(mzsRequest.getValue(), idFromTNVZ); var jaxbMsgRequest = new ObjectFactory().createDeliveryRequest(msgRequest); String msgRequestXML = msgMarshaller.marshallXml(jaxbMsgRequest); logger.info(msgRequestXML); assertThat(msgRequestXML) .contains("valid-delivery-request-id") .contains("some-id-type") .contains("some-id-value") .doesNotContain("Mustermann1") .doesNotContain("Maxi"); } } }