Skip to content

Commit

Permalink
Fixed failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
basiliskus committed Mar 22, 2024
1 parent 468d98a commit 65248e9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gov.hhs.cdc.trustedintermediary.etor.ruleengine

import gov.hhs.cdc.trustedintermediary.context.TestApplicationContext
import gov.hhs.cdc.trustedintermediary.external.hapi.HapiFhirImplementation
import gov.hhs.cdc.trustedintermediary.external.hapi.HapiFhirResource
import gov.hhs.cdc.trustedintermediary.external.jackson.Jackson
import gov.hhs.cdc.trustedintermediary.wrappers.HapiFhir
import gov.hhs.cdc.trustedintermediary.wrappers.Logger
Expand Down Expand Up @@ -38,7 +39,7 @@ class RuleEngineIntegrationTest extends Specification {
def bundle = fhir.parseResource(fhirBody, Bundle)

when:
engine.validate(bundle)
engine.validate(new HapiFhirResource(bundle))

then:
1 * mockLogger.logWarning(_ as String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package gov.hhs.cdc.trustedintermediary.etor.ruleengine

import gov.hhs.cdc.trustedintermediary.context.TestApplicationContext
import gov.hhs.cdc.trustedintermediary.wrappers.Logger
import org.hl7.fhir.r4.model.Bundle
import spock.lang.Specification

class RuleEngineTest extends Specification {
Expand Down Expand Up @@ -46,7 +45,7 @@ class RuleEngineTest extends Specification {
mockRuleLoader.loadRules(_ as String) >> { throw exception }

when:
ruleEngine.validate(Mock(Bundle))
ruleEngine.validate(Mock(FhirResource))

then:
1 * mockLogger.logError(_ as String, exception)
Expand All @@ -56,7 +55,7 @@ class RuleEngineTest extends Specification {
given:
def ruleViolationMessage = "Rule violation message"
def fullRuleViolationMessage = "Rule violation: " + ruleViolationMessage
def fhirBundle = Mock(Bundle)
def fhirBundle = Mock(FhirResource)
def invalidRule = Mock(Rule)
invalidRule.getViolationMessage() >> ruleViolationMessage
mockRuleLoader.loadRules(_ as String) >> [invalidRule]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package gov.hhs.cdc.trustedintermediary.etor.ruleengine

import gov.hhs.cdc.trustedintermediary.FhirResourceMock
import gov.hhs.cdc.trustedintermediary.context.TestApplicationContext
import gov.hhs.cdc.trustedintermediary.external.hapi.HapiFhirImplementation
import gov.hhs.cdc.trustedintermediary.wrappers.HapiFhir
import gov.hhs.cdc.trustedintermediary.wrappers.Logger
import org.hl7.fhir.instance.model.api.IBaseResource
import org.hl7.fhir.r4.model.Bundle
import spock.lang.Specification

class ValidationRuleTest extends Specification {
Expand Down Expand Up @@ -42,7 +41,7 @@ class ValidationRuleTest extends Specification {
def "appliesTo returns expected boolean depending on conditions"() {
given:
def mockFhir = Mock(HapiFhir)
mockFhir.evaluateCondition(_ as IBaseResource, _ as String) >> true >> conditionResult
mockFhir.evaluateCondition(_ as Object, _ as String) >> true >> conditionResult
TestApplicationContext.register(HapiFhir, mockFhir)

def rule = new ValidationRule(null, null, null, [
Expand All @@ -51,7 +50,7 @@ class ValidationRuleTest extends Specification {
], null)

expect:
rule.appliesTo(new Bundle()) == applies
rule.appliesTo(new FhirResourceMock("resource")) == applies

where:
conditionResult | applies
Expand All @@ -62,13 +61,13 @@ class ValidationRuleTest extends Specification {
def "appliesTo logs an error and returns false if an exception happens when evaluating a condition"() {
given:
def mockFhir = Mock(HapiFhirImplementation)
mockFhir.evaluateCondition(_ as IBaseResource, "condition") >> { throw new Exception() }
mockFhir.evaluateCondition(_ as Object, "condition") >> { throw new Exception() }
TestApplicationContext.register(HapiFhir, mockFhir)

def rule = new ValidationRule(null, null, null, ["condition"], null)

when:
def applies = rule.appliesTo(new Bundle())
def applies = rule.appliesTo(Mock(FhirResource))

then:
1 * mockLogger.logError(_ as String, _ as Exception)
Expand All @@ -78,7 +77,7 @@ class ValidationRuleTest extends Specification {
def "isValid returns expected boolean depending on validations"() {
given:
def mockFhir = Mock(HapiFhir)
mockFhir.evaluateCondition(_ as IBaseResource, _ as String) >> true >> validationResult
mockFhir.evaluateCondition(_ as Object, _ as String) >> true >> validationResult
TestApplicationContext.register(HapiFhir, mockFhir)

def rule = new ValidationRule(null, null, null, null, [
Expand All @@ -87,7 +86,7 @@ class ValidationRuleTest extends Specification {
])

expect:
rule.isValid(new Bundle()) == valid
rule.isValid(new FhirResourceMock("resource")) == valid

where:
validationResult | valid
Expand All @@ -98,13 +97,13 @@ class ValidationRuleTest extends Specification {
def "isValid logs an error and returns false if an exception happens when evaluating a validation"() {
given:
def mockFhir = Mock(HapiFhirImplementation)
mockFhir.evaluateCondition(_ as IBaseResource, "condition") >> { throw new Exception() }
mockFhir.evaluateCondition(_ as Object, "condition") >> { throw new Exception() }
TestApplicationContext.register(HapiFhir, mockFhir)

def rule = new ValidationRule(null, null, null, null, ["validation"])

when:
def valid = rule.isValid(new Bundle())
def valid = rule.isValid(Mock(FhirResource))

then:
1 * mockLogger.logError(_ as String, _ as Exception)
Expand Down

0 comments on commit 65248e9

Please sign in to comment.