diff options
Diffstat (limited to 'src/test/java/at/gv/egiz/moazs')
-rw-r--r-- | src/test/java/at/gv/egiz/moazs/JaxbMarshallerTest.java | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/src/test/java/at/gv/egiz/moazs/JaxbMarshallerTest.java b/src/test/java/at/gv/egiz/moazs/JaxbMarshallerTest.java new file mode 100644 index 0000000..e85a5ba --- /dev/null +++ b/src/test/java/at/gv/egiz/moazs/JaxbMarshallerTest.java @@ -0,0 +1,101 @@ +package at.gv.egiz.moazs; + +import at.gv.e_government.reference.namespace.zustellung.mzs.app2mzs_.DeliveryRequestType; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; +import javax.xml.datatype.DatatypeConfigurationException; +import javax.xml.datatype.DatatypeFactory; +import java.math.BigInteger; +import java.nio.charset.Charset; +import java.util.GregorianCalendar; + +public class JaxbMarshallerTest { + + private static final Logger logger = LoggerFactory.getLogger(JaxbMarshallerTest.class); + + private Marshaller createMarshaller() throws JAXBException { + JAXBContext context = JAXBContext.newInstance( + at.gv.e_government.reference.namespace.zustellung.mzs.persondata_.ObjectFactory.class, + at.gv.e_government.reference.namespace.zustellung.mzs.app2mzs_.ObjectFactory.class, + at.gv.e_government.reference.namespace.zustellung.msg.phase2._20181206_.ObjectFactory.class, + at.gv.e_government.reference.namespace.persondata.phase2._20181206_.ObjectFactory.class); + + var m = context.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); + return m; + + } + + private JAXBElement<DeliveryRequestType> generateSampleRequest() throws DatatypeConfigurationException { + var pof = new at.gv.e_government.reference.namespace.zustellung.mzs.persondata_.ObjectFactory(); + var mzsof = new at.gv.e_government.reference.namespace.zustellung.mzs.app2mzs_.ObjectFactory(); + var msgof = new at.gv.e_government.reference.namespace.zustellung.msg.phase2._20181206_.ObjectFactory(); + + var deliveryRequest = new DeliveryRequestType(); + + var sender = mzsof.createDeliveryRequestTypeSender(); + var corporateBody = pof.createCorporateBodyType(); + corporateBody.setFullName("Bundesministerium für Testzwecke"); + sender.setPerson(pof.createCorporateBody(corporateBody)); + deliveryRequest.setSender(sender); + + var receiver = mzsof.createDeliveryRequestTypeReceiver(); + var physicalPerson = pof.createPhysicalPersonType(); + var name = pof.createPersonNameType(); + name.setGivenName("Maxi"); + var familyName = pof.createPersonNameTypeFamilyName(); + familyName.setValue("Mustermann1"); + name.setFamilyName(familyName); + physicalPerson.setName(name); + var cal = new GregorianCalendar(1984, 1, 24); + var xmlDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal); + physicalPerson.setDateOfBirth(pof.createDateOfBirth(xmlDate).getValue()); + receiver.setPerson(pof.createPhysicalPerson(physicalPerson)); + var postal = pof.createPostalAddressType(); + postal.setCountryCode("AT"); + postal.setPostalCode("1010"); + postal.setMunicipality("Wien"); + var deliveryAddress = pof.createPostalAddressTypeDeliveryAddress(); + deliveryAddress.setStreetName("Musterstraße"); + deliveryAddress.setBuildingNumber("10"); + postal.setDeliveryAddress(deliveryAddress); + receiver.getAddress().add(pof.createAddress(postal)); + deliveryRequest.setReceiver(receiver); + + var metadata = msgof.createMetaData(); + metadata.setAppDeliveryID("asd"); + metadata.setSubject("Wichtige Mitteilung!"); + metadata.setDeliveryQuality("RSa"); + deliveryRequest.setMetaData(metadata); + + var payload = mzsof.createDeliveryRequestTypePayload(); + payload.setDocumentReference("https://authority.gv.at/files/73bdf969781ba41fa07df1ff8439cf685c0db1c3"); + payload.setFileName("brief.xml"); + payload.setMIMEType("text/xml"); + payload.setSize(BigInteger.valueOf(123401)); + var checksum = msgof.createCheckSumType(); + checksum.setAlgorithmID("SHA1"); + checksum.setValue("random".getBytes(Charset.forName("UTF-8"))); + payload.setCheckSum(checksum); + deliveryRequest.getPayload().add(payload); + + return mzsof.createDeliveryRequest(deliveryRequest); + } + + @Test + public void testMarshalling() throws JAXBException, DatatypeConfigurationException { + + logger.info("test marshalling...."); + var request = generateSampleRequest(); + var m = createMarshaller(); + m.marshal(request, System.out); + + } + +} |