Skip to content

Commit

Permalink
Added tests for CDA
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulsom committed Jul 6, 2014
1 parent 707dcc2 commit 26ea3a5
Show file tree
Hide file tree
Showing 4 changed files with 1,766 additions and 11 deletions.
29 changes: 24 additions & 5 deletions src/test/groovy/ihe/iti/ParseAndRewriteSpec.groovy
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package ihe.iti

import com.github.rahulsom.cda.POCDMT000040ClinicalDocument
import ihe.iti.svs._2008.RetrieveValueSetRequestType
import ihe.iti.svs._2008.RetrieveValueSetResponseType
import ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType
import ihe.util.XmlTestHelper
import oasis.names.tc.ebxml_regrep.xsd.lcm._3.SubmitObjectsRequest
import oasis.names.tc.ebxml_regrep.xsd.query._3.AdhocQueryRequest
Expand All @@ -11,19 +11,33 @@ import org.hl7.v3.*
import spock.lang.Specification
import spock.lang.Unroll

import javax.xml.bind.JAXBContext
import javax.xml.bind.JAXBElement

/**
* Created by rahulsomasunderam on 2/27/14.
*/
class ParseAndRewriteSpec extends Specification {

@Unroll
def "CDA: #file can be parsed to #clazz and recreated"() {

expect:
parseCda("${profile}/${file}").class == clazz && !XmlTestHelper.getIrrecoverableDifferences(
parseCda("${profile}/${file}"), "${profile}/${file}", XmlTestHelper.cdaJaxbContext
)

where:
profile || file || clazz
'CDA' | 'PaulWilson-Clinic.ccd.xml' | POCDMT000040ClinicalDocument
}

@Unroll
def "#profile: #file can be parsed to #clazz and recreated"() {

expect:
parse("${profile}/${file}").class == clazz && !XmlTestHelper.getIrrecoverableDifferences(
parse("${profile}/${file}"), "${profile}/${file}"
parseIti("${profile}/${file}").class == clazz && !XmlTestHelper.getIrrecoverableDifferences(
parseIti("${profile}/${file}"), "${profile}/${file}"
)

where:
Expand Down Expand Up @@ -83,8 +97,7 @@ class ParseAndRewriteSpec extends Specification {

}

def parse(String file) {
def jaxbContext = XmlTestHelper.jaxbContext
def parse(String file, JAXBContext jaxbContext) {
def obj = jaxbContext.createUnmarshaller().unmarshal(
this.class.classLoader.getResourceAsStream(file)
)
Expand All @@ -94,4 +107,10 @@ class ParseAndRewriteSpec extends Specification {
obj
}
}
def parseCda(String file) {
parse(file, XmlTestHelper.cdaJaxbContext)
}
def parseIti(String file) {
parse(file, XmlTestHelper.itiJaxbContext)
}
}
2 changes: 1 addition & 1 deletion src/test/groovy/ihe/iti/PdqSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import javax.xml.bind.JAXBElement
class PdqSpec extends Specification {
def "name can be extracted from a PDQ Response"() {
given: "a parser"
def jaxbContext = XmlTestHelper.jaxbContext
def jaxbContext = XmlTestHelper.itiJaxbContext

when: "the message is parsed"
def r = jaxbContext.createUnmarshaller().unmarshal(
Expand Down
13 changes: 8 additions & 5 deletions src/test/groovy/ihe/util/XmlTestHelper.groovy
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ihe.util

import com.github.rahulsom.cda.POCDMT000040ClinicalDocument
import ihe.iti.svs._2008.RetrieveValueSetRequestType
import ihe.iti.xds_b._2007.DocumentRegistryPortType
import ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType
import ihe.iti.xds_b._2007.RetrieveDocumentSetRequestType
import ihe.iti.xds_b._2007.RetrieveDocumentSetResponseType
Expand All @@ -23,20 +23,23 @@ import javax.xml.namespace.QName
class XmlTestHelper {

@Lazy
static jaxbContext = JAXBContext.newInstance(
static itiJaxbContext = JAXBContext.newInstance(
PRPAIN201306UV02,RetrieveValueSetRequestType,
ProvideAndRegisterDocumentSetRequestType, RetrieveDocumentSetRequestType,
AdhocQueryResponse, RegistryResponseType, RetrieveDocumentSetResponseType
)

static <T> List getIrrecoverableDifferences(r, file) {
@Lazy
static cdaJaxbContext = JAXBContext.newInstance(POCDMT000040ClinicalDocument)

static <T> List getIrrecoverableDifferences(T r, String file, JAXBContext theContext = itiJaxbContext) {
def sw = new StringWriter()
try {
jaxbContext.createMarshaller().marshal(r, sw)
theContext.createMarshaller().marshal(r, sw)
} catch (Exception e) {
def j = new JAXBElement(new QName('foo','bar'), r.class, r)
sw = new StringWriter()
jaxbContext.createMarshaller().marshal(j, sw)
theContext.createMarshaller().marshal(j, sw)
}

def inString = XmlTestHelper.classLoader.getResourceAsStream(file).text
Expand Down
Loading

0 comments on commit 26ea3a5

Please sign in to comment.