这是Web服务的基本模拟,其中检查Patient对象的资格。我已经包含了控制台输出以显示测试失败。
当我在groovyConsole中运行此测试时,它会通过。
基础患者班:
class Patient {
String firstName, lastName
Date dateOfBirth
}
创建患者对象:
Patient p1 = new Patient(
firstName: 'Mike', lastName: 'Smith',
dateOfBirth: new GregorianCalendar(1968, Calendar.AUGUST, 23).time
).save(flush: true, failOnError: true)
模拟设置:
此测试通常会查询Web服务。由于防火墙问题,我需要模拟服务。我构建了一个复制服务调用的树。
def eligibilityMock(Patient pat) {
def tree = { -> return [:].withDefault{ tree() } }
def member = tree()
if (pat.firstName == "Mike" && pat.lastName == "Smith") {
member.memberInfo.memberDetails.value.memberFirstName.value = 'Mike'
}
member
}
我打电话给模拟服务
//def memberInfo = eligibilityMock(p1)
def member = humanaEligibilityMock(p1).memberInfo
我希望firstName匹配
assert p1.firstName == memberInfo.memberDetails?.value?.memberFirstName?.value
似乎值匹配,但断言失败。
p1.firstName == memberInfo.memberDetails?.value?.memberFirstName?.value
| | | | | | |
Mike | | | | [value:[:]] [:]
| | | [memberFirstName:[value:[:]]]
| | [value:[memberFirstName:[value:[:]]]]
| [memberInfo:[memberDetails:[value:[memberFirstName:[value:Mike]
false