Forum Discussion

jas_Jas's avatar
jas_Jas
Established Member
5 years ago

How to use properties( either mock service or project) in resource path of mockService?

HI,

 

I  want to use custom properties of mock service or project as variable in mock service resource path. Any way to do it ?

Test Case Endpoint: http://localhost:9100/v1/customers - it send authorization as header which contain token to be used by mock service. Mock service running on : 127.0.0.1:8181/api Mock Service End Point:
/customer/101068577 /customer/101068577/loyalty/relationship

 

I am able to transfer property from project level to mock service, but unable to use mock service property in resource path.

 

Actual:

Mock service unable to read value from mockService custom property.

Expected:

mock service resource url : /customer/${#mockService#Customer_ID_Default} /customer/${#mockService#Customer_ID_Default}/loyalty/relationship

or /customer/${#Project#Customer_ID_Default} /customer/${#Project#Customer_ID_Default}/loyalty/relationship

 

1 Reply

  • JHunt's avatar
    JHunt
    Community Hero

    Create a MockAction for GET with the resource path set to /customers. For Dispatch type, choose "Script". The script will look something like this:

     

    String defaultCustomer= mockOperation.mockService.getPropertyValue('Customer_ID_Default')

    if (mockRequest.path == "/customers/${defaultCustomer}") { return "Response 1" // return the name of the mock response to send
    }