0

I am using wiremock to record mappings. I am using proxyBaseUrl, so that when mapping is not there it gets routed to proxy and the request and response is recorded. In my request there are a few timestamp related request object items I want the mapping to ignore. This way when the mapping is created, I already have timestamp wild carded like \"timestamp\": \"${json-unit.any-string}\". My tests create different timestamp, and I want wiremock to ignore those request objects when the mapping is created

When I run tests, there are 100s of mappings created and going through them 1 by 1 and updating them will be painful. So I want to train record-mappings in advance to ignore certain request objects. How can I do it?

{
  "priority": 1000000,
  "request": {
    "method": "POST",
    "url": "/v1/computeserv/execution",
  },
  "response": {
    "proxyBaseUrl": "https://actual.computeserv.com:12345"
  }
}
nilesh
  • 14,131
  • 7
  • 65
  • 79

1 Answers1

0

You'll need to write a StubMappingTransformer to handle automatically modifying your saved requests. You can read more about that in the Transforming Generated Stubs documentation on WireMock.

Additionally, many modern IDEs contain some global find-and-replace functionality, including searching by regex. If you don't anticipate having to constantly record and replace stubs, you might have more success by simply running the recording, generating your stubs with the specific timestamps, and then using the global find-and-replace functionality in your IDE. For example, here's the documentation on VSCode's Search and Replace.

Depends on what regex matching your IDE uses, but I'd imagine it'd be something like

\"timestamp\": \"(.*)\"
agoff
  • 5,818
  • 1
  • 7
  • 20
  • Thank you, do you have more documentation or examples on StubMappingTransformer? Current documentation I am not able to follow – nilesh Feb 25 '21 at 17:30
  • Writing the StubMappingTransformer will be similar to writing other WireMock extensions, except you'd extend `StubMappingTransformer` instead of the examples here: http://wiremock.org/docs/extending-wiremock/. You would register the StubMappingTransformer globally, the same as the extensions in that documentation. You can also look at the StubMappingTransformer class to see what methods will need an override: https://github.com/tomakehurst/wiremock/blob/master/src/main/java/com/github/tomakehurst/wiremock/extension/StubMappingTransformer.java – agoff Feb 25 '21 at 17:40