gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [libeufin] 01/02: complete unit tests for JAXB conversion


From: gnunet
Subject: [GNUnet-SVN] [libeufin] 01/02: complete unit tests for JAXB conversion
Date: Thu, 17 Oct 2019 09:23:45 +0200

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

marcello pushed a commit to branch master
in repository libeufin.

commit 4342e9c79e12e1e51b6fb2458fe9107f3c3454bf
Author: Marcello Stanisci <address@hidden>
AuthorDate: Wed Oct 16 18:11:56 2019 +0200

    complete unit tests for JAXB conversion
---
 sandbox/src/main/kotlin/Main.kt                    |  6 +--
 sandbox/src/main/kotlin/XML.kt                     |  6 +--
 sandbox/src/test/kotlin/JaxbTest.kt                | 47 ++++++++++++++++------
 .../{DomToJaxbTest.kt => XsiTypeAttributeTest.kt}  |  2 +-
 4 files changed, 42 insertions(+), 19 deletions(-)

diff --git a/sandbox/src/main/kotlin/Main.kt b/sandbox/src/main/kotlin/Main.kt
index d9981f0..fcbf51d 100644
--- a/sandbox/src/main/kotlin/Main.kt
+++ b/sandbox/src/main/kotlin/Main.kt
@@ -221,9 +221,9 @@ private suspend fun ApplicationCall.ebicsweb() {
                 )
             )
 
-            logger.info("Serving a 
${bodyJaxb.header.static.orderDetails.orderType} request")
+            logger.info("Serving a 
${bodyJaxb.value.header.static.orderDetails.orderType} request")
 
-            when (bodyJaxb.header.static.orderDetails.orderType) {
+            when (bodyJaxb.value.header.static.orderDetails.orderType) {
 
                 "INI" -> {
 
@@ -232,7 +232,7 @@ private suspend fun ApplicationCall.ebicsweb() {
                      * the Base64 string into its byte[] form _at the same 
time_ it instantiates
                      * the object; in other words, there is no need to perform 
here the decoding.
                      */
-                    val zkey = bodyJaxb.body.dataTransfer.orderData.value
+                    val zkey = bodyJaxb.value.body.dataTransfer.orderData.value
 
                     /**
                      * The validation enforces zkey to be a base64 value, but 
does not check
diff --git a/sandbox/src/main/kotlin/XML.kt b/sandbox/src/main/kotlin/XML.kt
index f2aa666..75faa21 100644
--- a/sandbox/src/main/kotlin/XML.kt
+++ b/sandbox/src/main/kotlin/XML.kt
@@ -175,13 +175,13 @@ class XML {
      * @param document the document to convert into JAXB.
      * @return the JAXB object reflecting the original XML document.
      */
-    fun <T>convertDomToJaxb(finalType: Class<T>, document: Document) : T {
+    fun <T>convertDomToJaxb(finalType: Class<T>, document: Document) : 
JAXBElement<T> {
 
         val jc = JAXBContext.newInstance(finalType)
 
         /* Marshalling the object into the document.  */
         val m = jc.createUnmarshaller()
-        return m.unmarshal(document) as T // document "went" into Jaxb
+        return m.unmarshal(document, finalType) // document "went" into Jaxb
     }
 
     /**
@@ -213,7 +213,7 @@ class XML {
      *               has already got its setters called.
      * @return the DOM Document, or null (if errors occur).
      */
-    fun convertJaxbToDom(obj: JAXBElement<Unit>): Document? {
+    fun <T>convertJaxbToDom(obj: JAXBElement<T>): Document? {
 
         try {
             val jc = JAXBContext.newInstance(obj.declaredType)
diff --git a/sandbox/src/test/kotlin/JaxbTest.kt 
b/sandbox/src/test/kotlin/JaxbTest.kt
index e217ed4..e34d550 100644
--- a/sandbox/src/test/kotlin/JaxbTest.kt
+++ b/sandbox/src/test/kotlin/JaxbTest.kt
@@ -13,6 +13,14 @@ class JaxbTest {
 
     val processor = tech.libeufin.sandbox.XML()
     val classLoader = ClassLoader.getSystemClassLoader()
+    val hevResponseJaxb = HEVResponse(
+        "000000",
+        "EBICS_OK",
+        arrayOf(
+            ProtocolAndVersion("H003", "02.40"),
+            ProtocolAndVersion("H004", "02.50")
+        )
+    ).makeHEVResponse()
 
 
     /**
@@ -36,7 +44,7 @@ class JaxbTest {
     }
 
     /**
-     * Test the JAXB instantiation of a XmlRoot document.
+     * Test string -> JAXB
      */
     @Test
     fun stringToJaxb() {
@@ -54,21 +62,36 @@ class JaxbTest {
         )
     }
 
+    /**
+     * Test JAXB -> string
+     */
     @Test
     fun jaxbToString() {
 
-        val hevResponse = HEVResponse(
-            "000000",
-            "EBICS_OK",
-            arrayOf(
-                ProtocolAndVersion("H003", "02.40"),
-                ProtocolAndVersion("H004", "02.50")
-            )
-        )
+        processor.getStringFromJaxb(hevResponseJaxb)
+    }
+
+    /**
+     * Test JAXB -> DOM
+     */
+    @Test
+    fun jaxbToDom() {
+        processor.convertJaxbToDom(hevResponseJaxb)
+    }
+
 
-        processor.getStringFromJaxb(hevResponse.makeHEVResponse())
+    /**
+     * Test DOM -> JAXB
+     */
+    @Test
+    fun domToJaxb() {
 
-        // just checking that no exceptions were raised before
-        assertTrue(true)
+        val ini = 
classLoader.getResource("ebics_ini_request_sample_patched.xml")
+        val iniDom = processor.parseStringIntoDom(ini.readText())
+        processor.convertDomToJaxb<EbicsUnsecuredRequest>(
+            EbicsUnsecuredRequest::class.java,
+            iniDom!!)
     }
+
+
 }
\ No newline at end of file
diff --git a/sandbox/src/test/kotlin/DomToJaxbTest.kt 
b/sandbox/src/test/kotlin/XsiTypeAttributeTest.kt
similarity index 96%
rename from sandbox/src/test/kotlin/DomToJaxbTest.kt
rename to sandbox/src/test/kotlin/XsiTypeAttributeTest.kt
index 05ecaec..73c4811 100644
--- a/sandbox/src/test/kotlin/DomToJaxbTest.kt
+++ b/sandbox/src/test/kotlin/XsiTypeAttributeTest.kt
@@ -6,7 +6,7 @@ import 
tech.libeufin.messages.ebics.keyrequest.EbicsUnsecuredRequest
 import tech.libeufin.messages.ebics.keyrequest.OrderDetailsType
 import tech.libeufin.messages.ebics.keyrequest.UnsecuredReqOrderDetailsType
 
-class DomToJaxbTest {
+class XsiTypeAttributeTest {
 
     @Test
     fun domToJaxb() {

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

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