mercredi 17 janvier 2018

Wiremock different response for the same request

I have a peculiar situation whereby I have to send a different response for the same request using wiremock.

I am using the "Scenario" feature. The problem I have is a default request which is similar to the request in the scenario. I will explain a bit further.....

Mappings

Default_Up_request.json

{
  "request": {
  "method": "POST",
  "url": "/someservice.asmx",
  "bodyPatterns": [
    {
    "matchesXPath": "//*[name()='status']/*
             [name()='id'][text()='333602']"
    },
    {
    "matchesXPath": "//*[name()='status']/*
             [name()='indicator'][text()='Up']"
    }
  ]
},
"response": {
   "status": 200,
   "bodyFileName": "default_response.xml",
"headers": {
  "Content-Type": "text/xml; charset=utf-8"
  }
 }
}

Scenario_request_1.json

{
  "scenarioName": "ChainedRequests",
  "requiredScenarioState": "Started",
  "newScenarioState": "down",
  "request": {
  "method": "POST",
  "url": "/someservice.asmx",
  "bodyPatterns": [
    {
    "matchesXPath": "//*[name()='status']/*
             [name()='id'][text()='333602']"
    },
    {
    "matchesXPath": "//*[name()='status']/*
             [name()='indicator'][text()='Down']"
    }
  ]
},
"response": {
   "status": 200,
   "bodyFileName": "down_response.xml",
"headers": {
  "Content-Type": "text/xml; charset=utf-8"
  }
 }
}

Scenario_request_2.json

{
  "scenarioName": "ChainedRequests",
  "requiredScenarioState": "down",
  "newScenarioState": "up",
  "request": {
  "method": "POST",
  "url": "/someservice.asmx",
  "bodyPatterns": [
    {
    "matchesXPath": "//*[name()='status']/*
             [name()='id'][text()='333602']"
    },
    {
    "matchesXPath": "//*[name()='status']/*
             [name()='indicator'][text()='Up']"
    }
  ]
},
"response": {
   "status": 200,
   "bodyFileName": "alternate_response.xml",
"headers": {
  "Content-Type": "text/xml; charset=utf-8"
  }
 }
}

__files

default_response.xml

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://ift.tt/sVJIaE">
   <soap:Body>
      <Response mlns="http://ift.tt/2EOzT83">
          <StatusResult>
            <ids/>
            <events>false</events>
            <startTime>false</startTime>
            <activation>false</activation>
            <settles>false</settles>
          </StatusResult>
      </Response>
   </soap:Body>
</soap:Envelope>

alternate_response.xml

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://ift.tt/sVJIaE">
   <soap:Body>
      <Response mlns="http://ift.tt/2EOzT83">
          <StatusResult>
            <ids/>
            <events>true</events>
            <startTime>false</startTime>
            <activation>false</Activation>
            <settles>false</settles>
          </StatusResult>
      </Response>
   </soap:Body>
</soap:Envelope>

request

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://ift.tt/sVJIaE">
   <soap:Body>
      <status xmlns="http://ift.tt/2EOzT83">
        <id>333602</id>
        <indicator>(Up/Down)</indicator>
        <events>false</events>
        <startTime>false</startTime>
        <activation>false</activation>
        <over>false</over>
     </status>
  </soap:Body>
</soap:Envelope>

In the SOAP packet the indicator changes from Up or Down based on what is triggered to the application.

The application sends "Up" requests to the mock the moment it has data in the cache which is fine and I can independently test only the UP request. But there are situations when a "DOWN" request is sent to the mock which is followed by an "UP" request for the same "id". The response for this "UP" request has to be different, but the request is exactly the same as the default UP request.

I have tried several different methods to match the request, but I either get a 404 or the close that I have come is the mock responds incorrectly.

If the question is not clear or need a bit more information, I can clarify.

Any help on how to solve this issue would be appreciated.

Aucun commentaire:

Enregistrer un commentaire