Skip to content

Commit

Permalink
Update HapiFhirImplementationTest.groovy
Browse files Browse the repository at this point in the history
Add some missing coverage
  • Loading branch information
luis-pabon-tf committed Mar 25, 2024
1 parent 33789b0 commit ada2d47
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ package gov.hhs.cdc.trustedintermediary.external.hapi

import ca.uhn.fhir.fhirpath.FhirPathExecutionException
import gov.hhs.cdc.trustedintermediary.context.TestApplicationContext
import gov.hhs.cdc.trustedintermediary.wrappers.FhirParseException
import org.hl7.fhir.instance.model.api.IBaseResource
import org.hl7.fhir.r4.model.Bundle
import org.hl7.fhir.r4.model.DiagnosticReport
import org.hl7.fhir.r4.model.ServiceRequest
import spock.lang.Specification

import java.nio.file.Files
import java.nio.file.Path

class HapiFhirImplementationTest extends Specification {
Bundle bundle
DiagnosticReport diaReport
Expand Down Expand Up @@ -92,4 +96,31 @@ class HapiFhirImplementationTest extends Specification {
then:
thrown(FhirPathExecutionException)
}

def "parseResource can convert a valid string to Bundle"() {
given:
def fhirBody = Files.readString(Path.of("../examples/Test/Orders/001_OML_O21_short.fhir"))

when:
def parsedBundle = fhir.parseResource(fhirBody, Bundle.class)

then:
parsedBundle.class == Bundle.class
}

def "parseResource throws FhirParseException on an invalid string"() {
when:
fhir.parseResource("badString", Bundle.class)

then:
thrown(FhirParseException)
}

def "encodeResourceToJson successfully converts a Bundle to a string" () {
when:
def encodedBundle = fhir.encodeResourceToJson(bundle)

then:
encodedBundle.class == String.class
}
}

0 comments on commit ada2d47

Please sign in to comment.