unit testing - junit.framework.AssertionFailedError: No more calls to 'getSystemStatus' expected at this point. End of demands -
pfb controller, controllertests , service code. getting below failure error: junit.framework.assertionfailederror: no more calls 'getsystemstatus' expected @ point. end of demands
controller:
def status() { int statuscode = muleservice.getsystemstatus(muleservice.getmuletoken()) if (statuscode == 200) { redirect(action: 'create') } }
controllertest:
void setup(){ def mockcontrol = mockfor(muleservice) //params parameters passed 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' }
service:
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 } }
Comments
Post a Comment