diff --git a/src/test/java/io/element36/cash36/ebics/EbicsApplicationTests.java b/src/test/java/io/element36/cash36/ebics/EbicsApplicationTests.java index 7453a9f..bb7795b 100644 --- a/src/test/java/io/element36/cash36/ebics/EbicsApplicationTests.java +++ b/src/test/java/io/element36/cash36/ebics/EbicsApplicationTests.java @@ -12,6 +12,6 @@ public class EbicsApplicationTests { @Test public void contextLoads() { // Simple test if spring context are loading - log.debug("Ebics spring context loaded"); + // log.debug("Ebics spring context loaded"); } } diff --git a/src/test/java/io/element36/cash36/ebics/TestTool.java b/src/test/java/io/element36/cash36/ebics/TestTool.java index e41c64f..8b3c1b3 100644 --- a/src/test/java/io/element36/cash36/ebics/TestTool.java +++ b/src/test/java/io/element36/cash36/ebics/TestTool.java @@ -15,211 +15,219 @@ import io.element36.cash36.ebics.dto.TransactionDTO; /** - * Some test tools and test data to generate payments and test methods to check if the - * content of the payments was captured properly by the backend. + * Some test tools and test data to generate payments and test methods to check + * if the + * content of the payments was captured properly by the backend. */ public class TestTool { - /** pp is pretty print; converts an object to String, e.g. for logging and testing */ - public static String pp(Object... objects) { - String result = " "; - if (objects == null) { - result = "..null"; - } else { - for (Object o : objects) result += o + "; "; - } - - System.out.println(result); - return result; - } - - - /** - * Utility function to get a file as a String - */ - public static String readLineByLineJava8(String filePath) throws IOException { - return new String(Files.readAllBytes(Paths.get(filePath))); - } - - - /** Tests statements of a bank acount using its DTO. Overall, this method tests various properties of - * the StatementDTO objects, including balance, IBAN, transaction details, and address lines. - * The assertions ensure that the properties match the expected values, helping to verify the - * correctness of the StatementDTO objects. - * */ - public static void testProxyStatements(List statements) { - // assertThat(statements.size()).isEqualTo(2); - // assertThat(statements.size()).isEqualTo(2); - - StatementDTO statement = statements.get(0); - - // do various test on the data, start with header - pp(statement); - // check from account - assertThat(statement.getBalanceCL()).isEqualTo(new BigDecimal("80097.2")); - assertThat(statement.getIban()).isEqualTo("CH4308307000289537312"); - - // pick first transaction - TransactionDTO tx = statement.getOutgoingTransactions().get(0); - assertThat(tx.getCurrency()).isEqualTo("CHF"); - assertThat(tx.getAmount()).isEqualTo(new BigDecimal("745.25")); - assertThat(tx.getAddrLine().get(0)) - .isEqualTo("VISECA CARD SERVICES SA \nHagenholzstrasse 56 \nPostfach 7007 \n8050 Zuerich"); - - // tx.getAddrLine().get(0) // VISECA CARD SERVICES S.A. - - // pick second transaction. - statement = statements.get(1); - assertThat(statement.getBalanceCL()).isEqualTo(new BigDecimal("110")); - assertThat(statement.getIban()).isEqualTo("CH2108307000289537320"); // pegging account - tx = statement.getIncomingTransactions().get(0); - assertThat(tx.getCurrency()).isEqualTo("CHF"); - assertThat(tx.getAmount()).isEqualTo(new BigDecimal("100")); - assertThat(tx.getAddrLine().get(0)).isEqualTo("element36 AG \nBahnmatt 25 \n6340 Baar"); -} - -/** - * Utility function to replace the .innerHTML of a tag - */ -public static String findAndReplaceTagContent(String tag, String replaceWith, String inputString) { - Pattern p = Pattern.compile("<"+tag+">(.+?)"); - Matcher matcher = p.matcher(inputString); - return matcher.replaceAll("<"+tag+">"+replaceWith+""); -} - -// PAIN file is a payment instruction sent to the bank backend. One is an ingoing, the other an -// outgoing transaction. Both will be sent to the backend for processing. -// We later look if this information is captured in bank statements. -public static final String PAIN1="\n" -+ "\n" -+ " \n" -+ " \n" -+ " 4711\n" -+ " 2021-07-16T14:43:03\n" -+ " 1\n" -+ " 100\n" -+ " \n" -+ " element36 AG\n" -+ " \n" -+ " \n" -+ " \n" -+ " abc\n" -+ " TRF\n" -+ " true\n" -+ " \n" -+ " \n" -+ " SEPA\n" -+ " \n" -+ " \n" -+ " 2021-07-16\n" -+ " \n" -+ " element36 AG\n" -+ " \n" -+ " \n" -+ " \n" -+ " BE71096123456769\n" -+ " \n" -+ " \n" -+ " \n" -+ " \n" -+ " \n" -+ " \n" -+ " \n" -+ " \n" -+ " \n" -+ " INSTRID-4711\n" -+ " E2E-4711\n" -+ " \n" -+ " \n" -+ " 100\n" -+ " \n" -+ " \n" -+ " Test Person\n" -+ " \n" -+ " DE\n" -+ " Rec Street Street-No.\n" -+ " 1000 TestCity\n" -+ " \n" -+ " \n" -+ " \n" -+ " \n" -+ " DE75512108001245126199\n" -+ " \n" -+ " \n" -+ " \n" -+ " Test Purpose\n" -+ " \n" -+ " \n" -+ " \n" -+ " \n" -+ "\n" -+ ""; - - -// PAIN file is a payment instruction sent to the bank backend. We later look if this information -// is captured in bank statements. -public static final String PAIN2="\n" - + "\n" - + " \n" - + " \n" - + " 4711\n" - + " 2021-07-16T15:12:31\n" - + " 1\n" - + " 100\n" - + " \n" - + " element36 AG\n" - + " \n" - + " \n" - + " \n" - + " abc\n" - + " TRF\n" - + " true\n" - + " \n" - + " \n" - + " SEPA\n" - + " \n" - + " \n" - + " 2021-07-16\n" - + " \n" - + " element36 AG\n" - + " \n" - + " \n" - + " \n" - + " BE71096123456769\n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " INSTRID-4711\n" - + " E2E-4711\n" - + " \n" - + " \n" - + " 100\n" - + " \n" - + " \n" - + " Test Person\n" - + " \n" - + " DE\n" - + " Rec Street Street-No.\n" - + " 1000 TestCity\n" - + " \n" - + " \n" - + " \n" - + " \n" - + " DE75512108001245126199\n" - + " \n" - + " \n" - + " \n" - + " Test Purpose\n" - + " \n" - + " \n" - + " \n" - + " \n" - + "\n" - + ""; + /** + * pp is pretty print; converts an object to String, e.g. for logging and + * testing + */ + public static String pp(Object... objects) { + String result = " "; + if (objects == null) { + result = "..null"; + } else { + for (Object o : objects) + result += o + "; "; + } + + System.out.println(result); + return result; + } + + /** + * Utility function to get a file as a String + */ + public static String readLineByLineJava8(String filePath) throws IOException { + return new String(Files.readAllBytes(Paths.get(filePath))); + } + + /** + * Tests statements of a bank acount using its DTO. Overall, this method tests + * various properties of + * the StatementDTO objects, including balance, IBAN, transaction details, and + * address lines. + * The assertions ensure that the properties match the expected values, helping + * to verify the + * correctness of the StatementDTO objects. + */ + public static void testProxyStatements(List statements) { + // assertThat(statements.size()).isEqualTo(2); + // assertThat(statements.size()).isEqualTo(2); + + StatementDTO statement = statements.get(0); + + // do various test on the data, start with header + pp(statement); + // check from account + assertThat(statement.getBalanceCL()).isEqualTo(new BigDecimal("80097.2")); + assertThat(statement.getIban()).isEqualTo("CH4308307000289537312"); + + // pick first transaction + TransactionDTO tx = statement.getOutgoingTransactions().get(0); + assertThat(tx.getCurrency()).isEqualTo("CHF"); + assertThat(tx.getAmount()).isEqualTo(new BigDecimal("745.25")); + assertThat(tx.getAddrLine().get(0)) + .isEqualTo("VISECA CARD SERVICES SA \nHagenholzstrasse 56 \nPostfach 7007 \n8050 Zuerich"); + + // tx.getAddrLine().get(0) // VISECA CARD SERVICES S.A. + + // pick second transaction. + statement = statements.get(1); + assertThat(statement.getBalanceCL()).isEqualTo(new BigDecimal("110")); + assertThat(statement.getIban()).isEqualTo("CH2108307000289537320"); // pegging account + tx = statement.getIncomingTransactions().get(0); + assertThat(tx.getCurrency()).isEqualTo("CHF"); + assertThat(tx.getAmount()).isEqualTo(new BigDecimal("100")); + assertThat(tx.getAddrLine().get(0)).isEqualTo("element36 AG \nBahnmatt 25 \n6340 Baar"); + } + + /** + * Utility function to replace the .innerHTML of a tag + */ + public static String findAndReplaceTagContent(String tag, String replaceWith, String inputString) { + Pattern p = Pattern.compile("<" + tag + ">(.+?)"); + Matcher matcher = p.matcher(inputString); + return matcher.replaceAll("<" + tag + ">" + replaceWith + ""); + } + + // PAIN file is a payment instruction sent to the bank backend. One is an + // ingoing, the other an + // outgoing transaction. Both will be sent to the backend for processing. + // We later look if this information is captured in bank statements. + public static final String PAIN1 = "\n" + + "\n" + + " \n" + + " \n" + + " 4711\n" + + " 2021-07-16T14:43:03\n" + + " 1\n" + + " 100\n" + + " \n" + + " element36 AG\n" + + " \n" + + " \n" + + " \n" + + " abc\n" + + " TRF\n" + + " true\n" + + " \n" + + " \n" + + " SEPA\n" + + " \n" + + " \n" + + " 2021-07-16\n" + + " \n" + + " element36 AG\n" + + " \n" + + " \n" + + " \n" + + " BE71096123456769\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " INSTRID-4711\n" + + " E2E-4711\n" + + " \n" + + " \n" + + " 100\n" + + " \n" + + " \n" + + " Test Person\n" + + " \n" + + " DE\n" + + " Rec Street Street-No.\n" + + " 1000 TestCity\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " DE75512108001245126199\n" + + " \n" + + " \n" + + " \n" + + " Test Purpose\n" + + " \n" + + " \n" + + " \n" + + " \n" + + "\n" + + ""; + + // PAIN file is a payment instruction sent to the bank backend. We later look if + // this information + // is captured in bank statements. + public static final String PAIN2 = "\n" + + "\n" + + " \n" + + " \n" + + " 4711\n" + + " 2021-07-16T15:12:31\n" + + " 1\n" + + " 100\n" + + " \n" + + " element36 AG\n" + + " \n" + + " \n" + + " \n" + + " abc\n" + + " TRF\n" + + " true\n" + + " \n" + + " \n" + + " SEPA\n" + + " \n" + + " \n" + + " 2021-07-16\n" + + " \n" + + " element36 AG\n" + + " \n" + + " \n" + + " \n" + + " BE71096123456769\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " INSTRID-4711\n" + + " E2E-4711\n" + + " \n" + + " \n" + + " 100\n" + + " \n" + + " \n" + + " Test Person\n" + + " \n" + + " DE\n" + + " Rec Street Street-No.\n" + + " 1000 TestCity\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " DE75512108001245126199\n" + + " \n" + + " \n" + + " \n" + + " Test Purpose\n" + + " \n" + + " \n" + + " \n" + + " \n" + + "\n" + + ""; }