0

I am trying to validate the json response. Have gone through the documentation in wiremock and also tried github example as below syntax.

https://github.com/tomakehurst/wiremock/blob/master/src/test/java/ignored/Examples.java#374

@Test
public void toDoListScenario() {
stubFor(get(urlEqualTo("/todo/items")).inScenario("To do list")
            .whenScenarioStateIs(STARTED)
            .willReturn(aResponse()
                    .withBody("<items>" +
                            "   <item>Buy milk</item>" +
                            "</items>"))); }

How to enter the json response in Body Section.

 {
 employeeDetails : [
   employeeName : ABCDE,
   employeeID : 12345 ]
 }

Is the below representation is correct. Please help me on this.

.withBody("employeeDetails:" +
          "employeeID" : "12345" +
          "employeeName" : "Preethi" + )
Preethi Ravi
  • 91
  • 1
  • 2
  • 10
  • This answer helped me https://stackoverflow.com/questions/76455655/wiremock-how-to-include-request-json-body-into-the-response-body/76470633#76470633 with Junit 5 – Zahid Khan Jul 26 '23 at 06:05

1 Answers1

2

Just format the text as json:

.withBody("{\"employeeDetails\":[" +
      "\"employeeID\" : \"12345\"" +
      "\"employeeName\" : \"Preethi\"]}")

and set the header to

.withHeader("Content-Type", equalTo("application/json"))
Edwin
  • 2,146
  • 20
  • 26