generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Porting test cases from reportstream implementation
- Loading branch information
1 parent
6c3dbf9
commit 2e3217e
Showing
1 changed file
with
84 additions
and
12 deletions.
There are no files selected for viewing
96 changes: 84 additions & 12 deletions
96
...ovy/gov/hhs/cdc/trustedintermediary/external/hapi/HapiFhirEngineImplementationTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |