first attempt to remove jaxb from zfv1

This commit is contained in:
Jochen Stärk
2020-06-11 15:22:40 +02:00
parent c28d0cb652
commit 5dbb3a72cc
21 changed files with 594 additions and 5620 deletions

View File

@@ -27,7 +27,7 @@ import java.util.logging.Logger;
/**
* This test utility class is providing usability functions for test file resources
* This test utility class is providing usability functions to test file resources
*/
public class ResourceUtilities {
private static final Logger LOG = Logger.getLogger(ResourceUtilities.class.getName());

View File

@@ -1,173 +0,0 @@
/** **********************************************************************
*
* Copyright 2018 Jochen Staerk
*
* Use is subject to license terms.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*
*********************************************************************** */
package org.mustangproject.ZUGFeRD;
import java.math.BigDecimal;
import java.util.Date;
import java.util.GregorianCalendar;
import javax.xml.bind.JAXBElement;
import org.junit.Test;
import org.mustangproject.ZUGFeRD.model.CrossIndustryDocumentType;
public class ZUGFeRDTransactionModelConverterTest {
@Test
public void convertToModel_convertsMinimalTransactionToValidXml() throws Exception {
// setup
IZUGFeRDExportableTransaction transaction = new IZUGFeRDExportableTransactionImpl()
.setIssueDate(createDate(2000, 1, 1))
.setDeliveryDate(createDate(2000, 1, 2))
.setDueDate(createDate(2000, 1, 3))
.setNumber("num")
.setRecipient(new IZUGFeRDExportableContactImpl()
.setName("recipient name")
.setStreet("recipient street")
.setLocation("recipient city")
.setCountry("recipient country")
)
.setOwnOrganisationName("own org")
.setOwnStreet("own street")
.setOwnCountry("own country")
.setOwnLocation("own city")
.setTradeSettlementPayment(new IZUGFeRDTradeSettlementPaymentImpl().setOwnBankName("own bank"))
.setZFItems(
new IZUGFeRDExportableItemImpl()
.setProduct(new IZUGFeRDExportableProductImpl()
.setVatPercent(new BigDecimal("1.19"))
.setName("product name")
.setDescription("product description")
.setUnit("product unit")
)
.setQuantity(BigDecimal.ONE)
.setPrice(BigDecimal.TEN)
);
// execution
final JAXBElement<CrossIndustryDocumentType> actual =
new ZUGFeRDTransactionModelConverter(transaction).convertToModel();
// evaluation
ZUGFeRDXMLAssert.assertValidZugferd(actual);
}
@Test
public void convertToModel_convertsWithDateFormatToValidXml() throws Exception {
// setup
IZUGFeRDExportableTransaction transaction = new IZUGFeRDExportableTransactionImpl()
.setIssueDate(createDate(2000, 1, 1))
.setZfDeliveryDate(createZfDate(2000, 1, 2, ZUGFeRDDateFormat.DATE)).setDueDate(createDate(2000, 1, 3))
.setNumber("num")
.setRecipient(new IZUGFeRDExportableContactImpl().setName("recipient name")
.setStreet("recipient street").setLocation("recipient city").setCountry("recipient country"))
.setOwnOrganisationName("own org").setOwnStreet("own street").setOwnCountry("own country")
.setOwnLocation("own city")
.setTradeSettlementPayment(new IZUGFeRDTradeSettlementPaymentImpl().setOwnBankName("own bank"))
.setZFItems(new IZUGFeRDExportableItemImpl()
.setProduct(new IZUGFeRDExportableProductImpl().setVatPercent(new BigDecimal("1.19"))
.setName("product name").setDescription("product description").setUnit("product unit"))
.setQuantity(BigDecimal.ONE).setPrice(BigDecimal.TEN));
// execution
final JAXBElement<CrossIndustryDocumentType> actual = new ZUGFeRDTransactionModelConverter(transaction)
.convertToModel();
// evaluation
ZUGFeRDXMLAssert.assertValidZugferd(actual);
}
@Test
public void convertToModel_convertsWithWeekFormatToValidXml() throws Exception {
// setup
IZUGFeRDExportableTransaction transaction = new IZUGFeRDExportableTransactionImpl()
.setIssueDate(createDate(2000, 1, 1))
.setZfDeliveryDate(createZfDate(2000, 1, 2, ZUGFeRDDateFormat.WEEK_OF_YEAR))
.setDueDate(createDate(2000, 1, 3)).setNumber("num")
.setRecipient(new IZUGFeRDExportableContactImpl().setName("recipient name")
.setStreet("recipient street").setLocation("recipient city").setCountry("recipient country"))
.setOwnOrganisationName("own org").setOwnStreet("own street").setOwnCountry("own country")
.setOwnLocation("own city")
.setTradeSettlementPayment(new IZUGFeRDTradeSettlementPaymentImpl().setOwnBankName("own bank"))
.setZFItems(new IZUGFeRDExportableItemImpl()
.setProduct(new IZUGFeRDExportableProductImpl().setVatPercent(new BigDecimal("1.19"))
.setName("product name").setDescription("product description").setUnit("product unit"))
.setQuantity(BigDecimal.ONE).setPrice(BigDecimal.TEN));
// execution
final JAXBElement<CrossIndustryDocumentType> actual = new ZUGFeRDTransactionModelConverter(transaction)
.convertToModel();
// evaluation
ZUGFeRDXMLAssert.assertValidZugferd(actual);
}
@Test
public void convertToModel_convertsWithMonthFormatToValidXml() throws Exception {
// setup
IZUGFeRDExportableTransaction transaction = new IZUGFeRDExportableTransactionImpl()
.setIssueDate(createDate(2000, 1, 1))
.setZfDeliveryDate(createZfDate(2000, 1, 2, ZUGFeRDDateFormat.MONTH_OF_YEAR))
.setDueDate(createDate(2000, 1, 3))
.setNumber("num")
.setRecipient(new IZUGFeRDExportableContactImpl()
.setName("recipient name")
.setStreet("recipient street")
.setLocation("recipient city")
.setCountry("recipient country")
)
.setOwnOrganisationName("own org")
.setOwnStreet("own street")
.setOwnCountry("own country")
.setOwnLocation("own city")
.setTradeSettlementPayment(new IZUGFeRDTradeSettlementPaymentImpl().setOwnBankName("own bank"))
.setZFItems(
new IZUGFeRDExportableItemImpl()
.setProduct(new IZUGFeRDExportableProductImpl()
.setVatPercent(new BigDecimal("1.19"))
.setName("product name")
.setDescription("product description")
.setUnit("product unit")
)
.setQuantity(BigDecimal.ONE)
.setPrice(BigDecimal.TEN)
);
// execution
final JAXBElement<CrossIndustryDocumentType> actual =
new ZUGFeRDTransactionModelConverter(transaction).convertToModel();
// evaluation
ZUGFeRDXMLAssert.assertValidZugferd(actual);
}
private static Date createDate(int year, int month, int day) {
final GregorianCalendar calendar = new GregorianCalendar();
calendar.set(year, month - 1, day);
return calendar.getTime();
}
private static IZUGFeRDDate createZfDate(int year, int month, int day, ZUGFeRDDateFormat format) {
final GregorianCalendar calendar = new GregorianCalendar();
calendar.set(year, month - 1, day);
IZUGFeRDDateImpl date = new IZUGFeRDDateImpl();
date.setDate(calendar.getTime());
date.setFormat(format);
return date;
}
}

View File

@@ -1,56 +0,0 @@
/** **********************************************************************
*
* Copyright 2018 Jochen Staerk
*
* Use is subject to license terms.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*
*********************************************************************** */
package org.mustangproject.ZUGFeRD;
import com.helger.schematron.ISchematronResource;
import com.helger.schematron.pure.SchematronResourcePure;
import org.junit.Assert;
import org.mustangproject.ZUGFeRD.model.CrossIndustryDocumentType;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.parsers.DocumentBuilderFactory;
public class ZUGFeRDXMLAssert {
private static final ISchematronResource SCHEMATRON = loadSchematron();
public static void assertValidZugferd(JAXBElement<CrossIndustryDocumentType> xml) throws Exception {
assertValidZugferd(toDocument(xml));
}
public static void assertValidZugferd(Node xml) throws Exception {
Assert.assertTrue("schema valid", SCHEMATRON.getSchematronValidity(xml, null).isValid());
}
private static Document toDocument(Object jaxbElement) throws Exception {
final Document result = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
JAXBContext.newInstance("org.mustangproject.ZUGFeRD.model").createMarshaller().marshal(jaxbElement, result);
return result;
}
private static SchematronResourcePure loadSchematron() {
final SchematronResourcePure result = SchematronResourcePure.fromClassPath("/ZUGFeRD_1p0.scmt");
if (!result.isValidSchematron()) {
throw new IllegalArgumentException("Invalid Schematron!");
}
return result;
}
}