gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libeufin] branch master updated: camt testing


From: gnunet
Subject: [libeufin] branch master updated: camt testing
Date: Mon, 22 Jun 2020 10:34:43 +0200

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository libeufin.

The following commit(s) were added to refs/heads/master by this push:
     new ca343c1  camt testing
ca343c1 is described below

commit ca343c1241e0cdea1ce18aad87b7f13161f609fd
Author: Florian Dold <florian.dold@gmail.com>
AuthorDate: Mon Jun 22 14:04:35 2020 +0530

    camt testing
---
 nexus/build.gradle                                 |  5 +++--
 .../main/kotlin/tech/libeufin/nexus/Iso20022.kt    | 22 ++++++++++++++++++++--
 nexus/src/test/kotlin/Iso20022Test.kt              | 10 ++++++++--
 3 files changed, 31 insertions(+), 6 deletions(-)

diff --git a/nexus/build.gradle b/nexus/build.gradle
index 069a437..a6ed9f3 100644
--- 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
index e8ad9b0..40460ba 100644
--- 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
index 98e438e..792bb8a 100644
--- 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
+}

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]