Hi @all I am stuck in a problem, where I am unable...
# general
z
Hi @all I am stuck in a problem, where I am unable to render the request's json part into the response. What I have achieved so far? I'm using WireMock with Spring Boot Application using the JUNIT 5. I am stubbing the
test
endpoint with the custom Request and Response JSON payload: My REQUEST PAYLOAD:
Copy code
{
    "merchantId": "xxxx",
    "data": [
        {
            "id": "unique-id-1",
            "sensitiveData": "xxxxxx",
        },
      ...
      ...
   ]
}
My RESPONSE PAYLOAD:
Copy code
{
    "status": "SUCCESS",
    "tokens": [
        {
            "id": "unique-id-1",
            "token": "xxxxxxxxxx",
        },
           ...
           ...  

   ]
}
What I'm trying to achieve? Since my JSON Request payload is dynamic. I want to create a dynamic JSON Payload in response as well where JSON tokens values are static but the id's value in JSON is dynamic based on the request payload's id value. CODE:
Copy code
@SpringBatchTest
class FileTest{
   private WireMockServer wireMockServer;

   BeforeEach
   void setUp() {
       wireMockServer =
         new WireMockServer(options().extensions(new          
             ResponseTemplateTransformer(true)).port(PORT));

       WireMock.configureFor("localhost", PORT);
       wireMockServer.start();
  }

  @AfterEach
  void tearDown() {
       wireMockServer.stop();
  

@Test
  void testEndToEndFlowForSpringBatch() {
       final String body = ResponsePayload.getResponseJsonPayload();
       wireMockServer.addStubMapping(
        stubFor(
            post(urlPathMatching("/test"))
                .willReturn(
                    aResponse()
                        .withBody(body)
                        .withStatus(200)
                        .withTransformers("response-template"))));
       //morecode
}
ResponsePayload.getResponseJsonPayload() contains below value:
Copy code
{
    "response": "SUCCESS",
    "tokens": [
        {
            "id": "{{jsonPath request.body '$.data[0].id'}}",
            "token": "xxxxxx",
        },
        {
            "id": "{{jsonPath request.body '$.data[1].id'}}",
            "token": "xxxxxxx",
        },
                  ..
    ]
}
What is not working? When I am debugging the program I can see the stub is throwing the following error:
Copy code
<p>Problem accessing /test. Reason:
<pre>    wiremock.com.github.jknack.handlebars.HandlebarsException: inline@1e0c0274:5:21: could not find helper: &apos;jsonPath&apos;
            &quot;id&quot;: &quot;{{jsonPath request.body &apos;$.merchantId&apos;}}&quot;,
                     ^
</pre></p>
<hr /><i><small>Powered by Jetty://</small></i>
t
Are you running the latest version of WireMock? Seems odd that it can’t find that helper, since it’s spelled correctly.
z
Hi @Tom <dependency> <groupId>com.github.tomakehurst</groupId> <artifactId>wiremock-standalone</artifactId> <version>2.6.0</version> <scope>test</scope> </dependency>
I am using 2.6.0
t
That’s very old. Suggest upgrading ideally to 3.0.0-beta-9, or failing that 2.35.0.
125 Views