Hello! I am facing an issue with wiremock matching...
# wiremock-java
s
Hello! I am facing an issue with wiremock matching wrong stubs with the request based on the body. These are the example logs I see from the wiremock:
Copy code
{"RequestItems":{"docstore-test-1":{"Keys":[{"pName":{"S":"JohnMap"}}],"ConsistentRead":false}}}
------------
with actual:
{"TableName":"docstore-test-1","Item":{"b":{"BOOL":true},"s":{"S":"randomStringMap"},"pName":{"S":"JohnMap"},"f":{"N":"12.65999984741211"},"i":{"N":"111"}},"ConditionExpression":"attribute_not_exists(pName)"}

21:28:54.179 [qtp942444738-33] DEBUG n.j.jsonunit.difference.diff - JSON documents are different:
Different keys found in node "", missing: "Key", expected: <{"Key":{"pName":{"S":"TaylorMap"}},"TableName":"docstore-test-1"}> but was: <{"ConditionExpression":"attribute_not_exists(pName)","Item":{"b":{"BOOL":true},"f":{"N":"12.65999984741211"},"i":{"N":"111"},"pName":{"S":"JohnMap"},"s":{"S":"randomStringMap"}},"TableName":"docstore-test-1"}>
21:28:54.179 [qtp942444738-33] DEBUG n.j.jsonunit.difference.values - Comparing expected:
{"TableName":"docstore-test-1","Key":{"pName":{"S":"TaylorMap"}}}
------------
with actual:
{"TableName":"docstore-test-1","Item":{"b":{"BOOL":true},"s":{"S":"randomStringMap"},"pName":{"S":"JohnMap"},"f":{"N":"12.65999984741211"},"i":{"N":"111"}},"ConditionExpression":"attribute_not_exists(pName)"}

21:28:54.180 [qtp942444738-33] DEBUG n.j.jsonunit.difference.diff - JSON documents are different:
Different value found in node "Item.i.N", expected: <"121"> but was: <"111">.
Different value found in node "Item.pName.S", expected: <"TaylorMap"> but was: <"JohnMap">.
Different value found in node "Item.s.S", expected: <"randomString2"> but was: <"randomStringMap">.
21:28:54.180 [qtp942444738-33] DEBUG n.j.jsonunit.difference.values - Comparing expected:
{"TableName":"docstore-test-1","Item":{"b":{"BOOL":true},"s":{"S":"randomString2"},"pName":{"S":"TaylorMap"},"f":{"N":"12.65999984741211"},"i":{"N":"121"}},"ConditionExpression":"attribute_not_exists(pName)"}
------------
with actual:
{"TableName":"docstore-test-1","Item":{"b":{"BOOL":true},"s":{"S":"randomStringMap"},"pName":{"S":"JohnMap"},"f":{"N":"12.65999984741211"},"i":{"N":"111"}},"ConditionExpression":"attribute_not_exists(pName)"}

21:28:54.182 [qtp942444738-33] DEBUG n.j.jsonunit.difference.diff - JSON documents are different:
Different value found in node "Item.i.N", expected: <"121"> but was: <"111">.
Different value found in node "Item.s.S", expected: <"randomString"> but was: <"randomStringMap">.
21:28:54.182 [qtp942444738-33] DEBUG n.j.jsonunit.difference.values - Comparing expected:
{"TableName":"docstore-test-1","Item":{"b":{"BOOL":true},"s":{"S":"randomString"},"pName":{"S":"JohnMap"},"f":{"N":"12.65999984741211"},"i":{"N":"121"}},"ConditionExpression":"attribute_not_exists(pName)"}
------------
with actual:
{"TableName":"docstore-test-1","Item":{"b":{"BOOL":true},"s":{"S":"randomStringMap"},"pName":{"S":"JohnMap"},"f":{"N":"12.65999984741211"},"i":{"N":"111"}},"ConditionExpression":"attribute_not_exists(pName)"}

21:28:54.186 [qtp942444738-33] DEBUG n.j.jsonunit.difference.diff - JSON documents are different:
Different keys found in node "", missing: "Key", expected: <{"Key":{"pName":{"S":"JohnMap"}},"TableName":"docstore-test-1"}> but was: <{"ConditionExpression":"attribute_not_exists(pName)","Item":{"b":{"BOOL":true},"f":{"N":"12.65999984741211"},"i":{"N":"111"},"pName":{"S":"JohnMap"},"s":{"S":"randomStringMap"}},"TableName":"docstore-test-1"}>
21:28:54.186 [qtp942444738-33] DEBUG n.j.jsonunit.difference.values - Comparing expected:
{"TableName":"docstore-test-1","Key":{"pName":{"S":"JohnMap"}}}
------------
with actual:
{"TableName":"docstore-test-1","Item":{"b":{"BOOL":true},"s":{"S":"randomStringMap"},"pName":{"S":"JohnMap"},"f":{"N":"12.65999984741211"},"i":{"N":"111"}},"ConditionExpression":"attribute_not_exists(pName)"}
It matched stub which with the wrong body when I have the exact match available in the mappings. This is the stub which should have been matched
Copy code
{
  "id": "ecb541f9-28dc-4c66-a4fd-49b2186418cd",
  "name": "",
  "request": {
    "url": "/",
    "method": "POST",
    "bodyPatterns": [
      {
        "equalToJson": "{\"TableName\":\"docstore-test-1\",\"Item\":{\"b\":{\"BOOL\":true},\"s\":{\"S\":\"randomStringMap\"},\"pName\":{\"S\":\"JohnMap\"},\"f\":{\"N\":\"12.65999984741211\"},\"i\":{\"N\":\"111\"}},\"ConditionExpression\":\"attribute_not_exists(pName)\"}",
        "ignoreArrayOrder": true,
        "ignoreExtraElements": true
      }
    ]
  },
  "response": {
    "status": 400,
    "body": "{\"__type\":\"com.amazonaws.dynamodb.v20120810#ConditionalCheckFailedException\",\"message\":\"The conditional request failed\"}",
    "headers": {
      "Server": "Server",
      "x-amzn-RequestId": "5G38FVT00S377LJ9E01MJOTL2FVV4KQNSO5AEMVJF66Q9ASUAAJG",
      "x-amz-crc32": "396270901",
      "Date": "Thu, 13 Feb 2025 19:57:11 GMT",
      "Content-Type": "application/x-amz-json-1.0"
    }
  },
  "uuid": "ecb541f9-28dc-4c66-a4fd-49b2186418cd",
  "persistent": true,
  "insertionIndex": 4
}
whereas it's matching to
Copy code
{
  "id": "b0573d94-8c4e-4516-825c-dd5c284fedbe",
  "name": "",
  "request": {
    "url": "/",
    "method": "POST",
    "bodyPatterns": [
      {
        "equalToJson": "{\"TableName\":\"docstore-test-1\"}",
        "ignoreArrayOrder": true,
        "ignoreExtraElements": true
      }
    ]
  },
  "response": {
    "status": 200,
    "body": "{\"Count\":2,\"Items\":[{\"i\":{\"N\":\"121\"},\"b\":{\"BOOL\":true},\"s\":{\"S\":\"randomString\"},\"f\":{\"N\":\"12.65999984741211\"},\"pName\":{\"S\":\"TaylorMap\"}},{\"i\":{\"N\":\"121\"},\"b\":{\"BOOL\":true},\"s\":{\"S\":\"randomString\"},\"f\":{\"N\":\"12.65999984741211\"},\"pName\":{\"S\":\"JohnMap\"}}],\"ScannedCount\":2}",
    "headers": {
      "Server": "Server",
      "x-amzn-RequestId": "B95F0E6V04TDV1ASIGTJ4UG71JVV4KQNSO5AEMVJF66Q9ASUAAJG",
      "x-amz-crc32": "2243820102",
      "Date": "Thu, 13 Feb 2025 19:57:09 GMT",
      "Content-Type": "application/x-amz-json-1.0"
    }
  },
  "uuid": "b0573d94-8c4e-4516-825c-dd5c284fedbe",
  "persistent": true,
  "scenarioName": "scenario-1-",
  "requiredScenarioState": "scenario-1--2",
  "insertionIndex": 9
}
This is the request body:
Copy code
21:28:54.162 [pool-7-thread-1] DEBUG org.apache.http.wire - http-outgoing-2 >> "{"TableName":"docstore-test-1","Item":{"b":{"BOOL":true},"s":{"S":"randomStringMap"},"pName":{"S":"JohnMap"},"f":{"N":"12.65999984741211"},"i":{"N":"111"}},"ConditionExpression":"attribute_not_exists(pName)"}"
Is this a known bug in the wiremock? I am using version 3.10.0, thanks a lot in advance.
Log to show which stub got matched :
Copy code
Date: Thu, 13 Feb 2025 19:57:09 GMT
Content-Type: application/x-amz-json-1.0
Matched-Stub-Id: b0573d94-8c4e-4516-825c-dd5c284fedbe
Matched-Stub-Name: 
Content-Length: 270
hmm..it seems like if I manually change
ignoreExtraElements
to
false
, it works as expected. But the I don't find a config to set to while while recording these stubs.
nvm, I found the config to set ignoreExtraElements to false.