[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [libeufin] branch master updated (11bec95 -> da13038)
From: |
gnunet |
Subject: |
[GNUnet-SVN] [libeufin] branch master updated (11bec95 -> da13038) |
Date: |
Thu, 17 Oct 2019 09:23:44 +0200 |
This is an automated email from the git hooks/post-receive script.
marcello pushed a change to branch master
in repository libeufin.
from 11bec95 unit tests
new 4342e9c complete unit tests for JAXB conversion
new da13038 Prefer ".isEmpty()" over "== 0".
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
sandbox/src/main/kotlin/Main.kt | 8 ++--
sandbox/src/main/kotlin/XML.kt | 6 +--
sandbox/src/test/kotlin/JaxbTest.kt | 47 ++++++++++++++++------
.../{DomToJaxbTest.kt => XsiTypeAttributeTest.kt} | 2 +-
4 files changed, 43 insertions(+), 20 deletions(-)
rename sandbox/src/test/kotlin/{DomToJaxbTest.kt => XsiTypeAttributeTest.kt}
(96%)
diff --git a/sandbox/src/main/kotlin/Main.kt b/sandbox/src/main/kotlin/Main.kt
index d9981f0..4a11650 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,14 +232,14 @@ 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
* whether it is given _empty_ or not; will check
explicitly here. FIXME:
* shall the schema be patched to avoid having this
if-block here?
*/
- if (zkey.size == 0) {
+ if (zkey.isEmpty()) {
logger.error("0-length key element given, invalid
request")
respondText(
contentType = ContentType.Application.Xml,
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.
- [GNUnet-SVN] [libeufin] branch master updated (11bec95 -> da13038),
gnunet <=