PFB我的控制器,controllerTests和服务代码。我收到以下失败错误:junit.framework.AssertionFailedError:不再调用' getSystemStatus'预计在这一点上。要求终止
控制器 :
def status() {
int statusCode = muleService.getSystemStatus(muleService.getMuleToken())
if (statusCode == 200) {
redirect(action: 'create')
}
}
ControllerTest :
void setUp(){
def mockControl = mockFor(MuleService)
//params are the parameters passed to the service method
mockControl.demand.getSystemStatus(0..100) { params ->
statusCode = "200"
return "200"
}
mockControl.demand.getMuleToken(0..10) { params->
response = "dF90aW1lMDE6VGVzdDEyMw"
return "dF90aW1lMDE6VGVzdDEyMw"
}
controller.muleService = mockControl.createMock()
}
void testStatus_statusCode200() {
when:
controller.status()
then:
response.redirectedUrl == '/trip-entry/create'
}
服务 :
String getMuleToken() {
return WebUtils.retrieveGrailsWebRequest().getSession().getAttribute("muleToken")?.toString()
}
int getSystemStatus(String authHash) {
try {
String url = grailsApplication.config.trip.mule.url.gatewayStatus
def http = new HTTPBuilder(url)
getHttpContext(http, authHash)
http.request(Method.GET) {
response.success = { resp ->
return resp.statusLine.statusCode
println resp.statusLine.statusCode
}
response.failure = { resp ->
return resp.statusLine.statusCode
println resp.statusLine.statusCode
}
// println resp.statusLine.statusCode
}
} catch (Exception e) {
return 500
}
}