commit ca343c1241e0cdea1ce18aad87b7f13161f609fd
parent c473f2f5934ed395f939764103736b26456df293
Author: Florian Dold <florian.dold@gmail.com>
Date: Mon, 22 Jun 2020 14:04:35 +0530
camt testing
Diffstat:
3 files changed, 31 insertions(+), 8 deletions(-)
diff --git a/nexus/build.gradle b/nexus/build.gradle
@@ -51,7 +51,6 @@ compileTestKotlin {
}
}
-
def ktor_version = "1.3.2"
def exposed_version = "0.25.1"
@@ -102,7 +101,9 @@ dependencies {
implementation "com.cronutils:cron-utils:9.0.2"
// Unit testing
- testImplementation group: 'junit', name: 'junit', version: '4.12'
+ testImplementation 'junit:junit:4.12'
+ testImplementation 'org.jetbrains.kotlin:kotlin-test:1.3.50'
+ testImplementation 'org.jetbrains.kotlin:kotlin-test-junit:1.3.50'
}
application {
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Iso20022.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Iso20022.kt
@@ -25,6 +25,7 @@ package tech.libeufin.nexus
import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.annotation.JsonSubTypes
import com.fasterxml.jackson.annotation.JsonTypeInfo
+import com.fasterxml.jackson.annotation.JsonValue
import org.w3c.dom.Document
import tech.libeufin.util.*
import java.time.Instant
@@ -53,6 +54,10 @@ enum class TransactionStatus {
INFO,
}
+enum class CashManagementResponseType(@get:JsonValue val jsonname: String) {
+ Report("report"), Statement("statement"), Notification("notification")
+}
+
/**
* Schemes to identify a transaction within an account.
* An identifier from such a scheme will be used to reconcile transactions
@@ -516,6 +521,10 @@ private fun XmlElementDestructor.extractInnerTransactions(): List<BankTransactio
data class CamtParseResult(
val transactions: List<BankTransaction>,
val messageId: String,
+ /**
+ * Message type in form of the ISO 20022 message name.
+ */
+ val messageType: CashManagementResponseType,
val creationDateTime: String
)
@@ -553,7 +562,16 @@ fun parseCamtMessage(doc: Document): CamtParseResult {
requireUniqueChildNamed("CreDtTm") { it.textContent }
}
}
- CamtParseResult(transactions, messageId, creationDateTime)
+ val messageType = requireOnlyChild {
+ when (it.localName) {
+ "BkToCstmrAcctRpt" -> CashManagementResponseType.Report
+ "BkToCstmrStmt" -> CashManagementResponseType.Statement
+ else -> {
+ throw CamtParsingError("expected statement or report")
+ }
+ }
+ }
+ CamtParseResult(transactions, messageId, messageType, creationDateTime)
}
}
-}
-\ No newline at end of file
+}
diff --git a/nexus/src/test/kotlin/Iso20022Test.kt b/nexus/src/test/kotlin/Iso20022Test.kt
@@ -3,7 +3,7 @@ import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import org.junit.Test
import org.w3c.dom.Document
import tech.libeufin.util.XMLUtil
-
+import kotlin.test.assertEquals
fun loadXmlResource(name: String): Document {
val classLoader = ClassLoader.getSystemClassLoader()
@@ -19,10 +19,16 @@ class Iso20022Test {
fun testTransactionsImport() {
val camt53 = loadXmlResource("iso20022-samples/camt.053.001.02.gesamtbeispiel.xml")
val r = parseCamtMessage(camt53)
+ assertEquals(r.messageId, "27632364572")
+ assertEquals(r.creationDateTime, "2016-05-11T19:30:47.0+01:00")
+ assertEquals(r.messageType, CashManagementResponseType.Statement)
for (tx in r.transactions) {
+ // Make sure that roundtripping works
val txStr = jacksonObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(tx)
println(txStr)
val tx2 = jacksonObjectMapper().readValue(txStr, BankTransaction::class.java)
+ val tx2Str = jacksonObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(tx2)
+ assertEquals(jacksonObjectMapper().readTree(txStr), jacksonObjectMapper().readTree(tx2Str))
}
}
-}
-\ No newline at end of file
+}