Skip to content

Commit

Permalink
Porting test cases from reportstream implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
luis-pabon-tf committed Mar 15, 2024
1 parent 6c3dbf9 commit 2e3217e
Showing 1 changed file with 84 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,55 +1,127 @@
package gov.hhs.cdc.trustedintermediary.external.hapi


import gov.hhs.cdc.trustedintermediary.context.TestApplicationContext
import gov.hhs.cdc.trustedintermediary.wrappers.HapiFhirEngine
import org.hl7.fhir.instance.model.api.IBaseResource
import org.hl7.fhir.r4.model.Bundle
import org.hl7.fhir.r4.utils.FHIRLexer
import spock.lang.Specification

// @todo build actual tests this is a skeleton
class HapiFhirEngineImplementationTest extends Specification {
HapiFhirEngine engine
Bundle bundle

def setup() {
TestApplicationContext.reset()
TestApplicationContext.init()
TestApplicationContext.injectRegisteredImplementations()

engine = new HapiFhirEngineImplementation() as HapiFhirEngine
engine = new HapiFhirEngineImplementation()

bundle = new Bundle()
bundle.id = "abc123"
}

def cleanup() {
}

def "superbasic"() {
def "parsePath returns null on blank"() {
given:
def expectedResult = null
def path = ""

when:
def actualResult = null
def result = engine.parsePath(path)

then:
actualResult === expectedResult
result == null
}

def "parsePath returns null on blank"() {
def "parsePath returns not null on a valid"() {
given:
def expectedResult = null
def path = "Bundle.entry.resource.ofType(MessageHeader)"

when:
def actualResult = engine.parsePath("")
def result = engine.parsePath(path)

then:
actualResult == expectedResult
result != null
}

def "parsePath returns not null on a valid"() {
given:
def expectedResult = null
def path = "%resource.contact.relationship.first().coding.exists()"

when:
def result = engine.parsePath("Bundle.entry.resource.ofType(MessageHeader)")
def result = engine.parsePath(path)

then:
result != null
}

def "parsePath throws FHIRLexerException on fake method"() {
given:
def path = "Bundle.entry.resource.BADMETHOD(MessageHeader)"

when:
engine.parsePath(path)

then:
thrown(FHIRLexer.FHIRLexerException)
}

def "parsePath throws FHIRLexerException on bad syntax"() {
given:
def path = "Bundle...entry.resource.ofType(MessageHeader)"

when:
engine.parsePath(path)

then:
thrown(FHIRLexer.FHIRLexerException)
}

def "evaluateCondition returns true on finding existing value"() {
given:
def path = "Bundle.id.exists()"

when:
def result = engine.evaluateCondition(bundle as IBaseResource, path)

then:
result == true
}

def "evaluateCondition returns false on not finding non-existing value"() {
given:
def path = "Bundle.timestamp.exists()"

when:
def result = engine.evaluateCondition(bundle as IBaseResource, path)

then:
result == false
}

def "evaluateCondition returns false on not finding matching extension"() {
given:
def path = "Bundle.entry[0].resource.extension('blah')"

when:
def result = engine.evaluateCondition(bundle as IBaseResource, path)

then:
result == false
}

def "evaluateCondition returns false on empty string"() {
given:
def path = ""

when:
def result = engine.evaluateCondition(bundle as IBaseResource, path)

then:
result == false
}
}

0 comments on commit 2e3217e

Please sign in to comment.