Forum Discussion

MeT's avatar
MeT
Occasional Contributor
6 years ago
Solved

ServiceV Pro: Default response unexpectedly replacing the scripted one

First thing first: I'm new to the ServiceV product, just got it few days ago.   I'm creating a virt api where the following path is being used: /api/aicm/v1/subject/{subject_nr}/mandate/{creditor_...
  • MeT's avatar
    MeT
    6 years ago

    Ok, I finally have come to a working way of dealing with scenarios where a TEMPLATE argument at the end of the path is expected but not provided (as in the following paths):

     5. Expected: Custom HTTP 400: /urds/wrd/api/aicm/v1/subject/0303200001/mandate// <<< ServiceV 404 Not Found own bodyless response: INCONSISTENT
     6. Expected: Custom HTTP 400: /urds/wrd/api/aicm/v1/subject/0303200001/mandate/  <<< ServiceV 404 Not Found own bodyless response: INCONSISTENT
     7. Expected: Custom HTTP 400: /urds/wrd/api/aicm/v1/subject/0303200001/mandate   <<< ServiceV 404 Not Found own bodyless response: INCONSISTENT
     8. Expected: Custom HTTP 400: /urds/wrd/api/aicm/v1/subject//mandate// <<< ServiceV 404 Not Found own bodyless response: INCONSISTENT
     9. Expected: Custom HTTP 400: /urds/wrd/api/aicm/v1/subject/mandate//  <<< ServiceV 404 Not Found own bodyless response: INCONSISTENT
    10. Expected: Custom HTTP 400: /urds/wrd/api/aicm/v1/subject/mandate/   <<< ServiceV 404 Not Found own bodyless response: INCONSISTENT
    11. Expected: Custom HTTP 400: /urds/wrd/api/aicm/v1/subject/mandate    <<< ServiceV 404 Not Found own bodyless response: INCONSISTENT

    To be able to dispatch your own custom response, and avoid the default 404 ServiceV (bodyless) response, you'll have first to create a separate resource for the path you wish to mock, in my case:

    /urds/wrd/api/aicm/v1/subject/mandate

    Then, in your script, you'll be checking the path and react accordingly:

    def path = mockRequest.getPath()
    log.info("HTTP request path: ${path}")
    if (path.endsWith("mandate") || path.endsWith("mandate/") || path.endsWith("mandate//")) {
    	log.info("mandate TEMPLATE argument: missing")
    	// return the name of the response you want to dispatch
    	//----------------------------------------------------------------------------------------------
    	return = "GET 400 Missing mandate ID"
    }

    Hope this will help you eventually! :smileyhappy: