Search in sources :

Example 1 with DefaultSageExporterConfig

use of eu.ggnet.dwoss.redtape.ee.sage.DefaultSageExporterConfig in project dwoss by gg-net.

the class SageExporterEngineTest method testExport.

@Test
public void testExport() throws UnsupportedEncodingException {
    UiCustomer cus = new UiCustomer(1, "Herr", "Max", "Müstermann", null, "none", "max@example.com", 0);
    Date date = Date.from(LocalDate.of(2018, 01, 30).atStartOfDay(systemDefault()).toInstant());
    // Prepare some data
    Dossier dos = new Dossier(PaymentMethod.DIRECT_DEBIT, true, 0);
    dos.setIdentifier("DW0001");
    Document doc = new Document(INVOICE, Directive.NONE, new DocumentHistory("Junit", "NoComment"));
    doc.setIdentifier("IN1234");
    doc.setActual(date);
    dos.add(doc);
    doc.append(unit(doc.getTaxType(), new Ledger(1000, "Demo1")));
    doc.append(Position.builder().type(SHIPPING_COST).amount(1).bookingAccount(new Ledger(2000, "Versand")).price(100).tax(doc.getTaxType().getTax()).name("Versandkosten").description("Versandkosten").build());
    Dossier dos2 = new Dossier(PaymentMethod.DIRECT_DEBIT, true, 0);
    dos2.setIdentifier("DW0002");
    Document doc2 = new Document(INVOICE, Directive.NONE, new DocumentHistory("Junit", "NoComment"));
    doc2.setIdentifier("IN4321");
    doc2.setActual(date);
    doc2.setTaxType(REVERSE_CHARGE);
    dos2.add(doc2);
    doc2.append(unit(doc2.getTaxType(), new Ledger(1234, "Demo2")));
    // Comparator is needed for the resulting rowlines. In productive, this is not important, but for an exact string match.
    Map<Document, UiCustomer> content = new TreeMap<>(new Comparator<Document>() {

        @Override
        public int compare(Document t0, Document t1) {
            return t0.getIdentifier().compareTo(t1.getIdentifier());
        }
    });
    content.put(doc, cus);
    content.put(doc2, cus);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    SageExporterEngine engine = new SageExporterEngine(out, content, new DefaultSageExporterConfig(666, false));
    engine.execute(null);
    String result = out.toString("ISO-8859-1");
    // Enable for problemhandling
    // System.out.println(result);
    // System.out.println("---------------");
    // System.out.println(VALID);
    // System.out.println("Diff: " + StringUtils.difference(result, VALID));
    // System.out.println("DiffIndex: " + StringUtils.indexOfDifference(result, VALID));
    assertThat(result).isEqualTo(VALID);
}
Also used : SageExporterEngine(eu.ggnet.dwoss.redtape.ee.sage.SageExporterEngine) Ledger(eu.ggnet.dwoss.mandator.api.value.Ledger) DefaultSageExporterConfig(eu.ggnet.dwoss.redtape.ee.sage.DefaultSageExporterConfig) ByteArrayOutputStream(java.io.ByteArrayOutputStream) LocalDate(java.time.LocalDate) UiCustomer(eu.ggnet.dwoss.customer.opi.UiCustomer) Test(org.junit.Test)

Aggregations

UiCustomer (eu.ggnet.dwoss.customer.opi.UiCustomer)1 Ledger (eu.ggnet.dwoss.mandator.api.value.Ledger)1 DefaultSageExporterConfig (eu.ggnet.dwoss.redtape.ee.sage.DefaultSageExporterConfig)1 SageExporterEngine (eu.ggnet.dwoss.redtape.ee.sage.SageExporterEngine)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 LocalDate (java.time.LocalDate)1 Test (org.junit.Test)1