Iso20022Test.kt (5046B)
1 /* 2 * This file is part of LibEuFin. 3 * Copyright (C) 2024-2025 Taler Systems S.A. 4 5 * LibEuFin is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU Affero General Public License as 7 * published by the Free Software Foundation; either version 3, or 8 * (at your option) any later version. 9 10 * LibEuFin is distributed in the hope that it will be useful, but 11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General 13 * Public License for more details. 14 15 * You should have received a copy of the GNU Affero General Public 16 * License along with LibEuFin; see the file COPYING. If not, see 17 * <http://www.gnu.org/licenses/> 18 */ 19 20 import org.junit.Test 21 import tech.libeufin.nexus.* 22 import tech.libeufin.nexus.iso20022.* 23 import tech.libeufin.ebics.* 24 import java.nio.file.Files 25 import java.nio.file.Path 26 import kotlin.io.path.Path 27 import kotlin.io.path.exists 28 import kotlin.io.path.isDirectory 29 import kotlin.io.path.listDirectoryEntries 30 31 class Iso20022Test { 32 @Test 33 fun sample() { 34 for (sample in Path("sample").listDirectoryEntries()) { 35 if (sample.isDirectory()) { 36 for (case in sample.listDirectoryEntries()) { 37 val content = Files.newInputStream(case) 38 val name = case.toString() 39 println(name) 40 if (name.contains("HAC")) { 41 parseCustomerAck(content) 42 } else if (name.contains("pain.002") || name.contains("pain002") ) { 43 parseCustomerPaymentStatusReport(content) 44 } else { 45 parseTx(content) 46 } 47 } 48 49 } else { 50 val content = Files.newInputStream(sample) 51 val name = sample.toString() 52 println(name) 53 if (name.contains("HAC")) { 54 parseCustomerAck(content) 55 } else if (name.contains("pain.002") || name.contains("pain002") ) { 56 parseCustomerPaymentStatusReport(content) 57 } else { 58 parseTx(content) 59 } 60 } 61 } 62 } 63 64 @Test 65 fun logs() { 66 val root = Path("test") 67 if (!root.exists()) return 68 for (platform in root.listDirectoryEntries()) { 69 if (!platform.isDirectory() || platform.fileName.toString() == "platform") continue 70 71 // List logs 72 var logs = mutableListOf<Path>() 73 for (file in platform.listDirectoryEntries()) { 74 if (!file.isDirectory()) continue 75 when (file.fileName.toString()) { 76 "fetch" -> for (transaction in file.listDirectoryEntries()) { 77 if (transaction.isDirectory()) { 78 logs.addAll(transaction.listDirectoryEntries()) 79 } 80 } 81 "submit" -> {} 82 else -> for (transaction in file.listDirectoryEntries()) { 83 when (transaction.fileName.toString()) { 84 "fetch" -> logs.addAll(transaction.listDirectoryEntries()) 85 "submit" -> {} 86 else -> { 87 var payload = transaction.resolve("payload") 88 if (payload.exists()) { 89 logs.addAll(payload.listDirectoryEntries()) 90 continue 91 } 92 payload = transaction.resolve("payload.xml") 93 if (payload.exists()) { 94 logs.add(payload) 95 } 96 } 97 } 98 } 99 } 100 } 101 102 // Load config 103 val cfg = nexusConfig(root.resolve("platform").resolve("${platform.fileName}.conf")) 104 val currency = cfg.currency 105 val dialect = cfg.ebics.dialect 106 // Parse logs 107 for (log in logs) { 108 val content = Files.newInputStream(log) 109 val name = log.toString() 110 println(name) 111 if (name.contains("wssparam") || name.endsWith(".txt")) { 112 // Skip 113 } else if (name.contains("HAC")) { 114 parseCustomerAck(content) 115 } else if (name.contains("HAA")) { 116 EbicsAdministrative.parseHAA(content) 117 } else if (name.contains("HKD")) { 118 EbicsAdministrative.parseHKD(content) 119 } else if (name.contains("pain.002")) { 120 parseCustomerPaymentStatusReport(content) 121 } else { 122 parseTx(content) 123 } 124 } 125 } 126 } 127 }