i want to match output of get-request, and match with manual provided json string, basically copy one json string coming out of whole output and test. Tried lot of ways but its not happening, i can't delete all rows from database to match one string to one, so, i want to match only one json string -- Like this below
{
"instanceName": "",
"read": 1,
"swProduct": "Area 1",
"swProductModule": "Regular 1"
},
Here's, my test code ---
@SpringBootTest(classes = TestApplication.class)
@ActiveProfiles("dev")
@AutoConfigureMockMvc
public class SwStatusCheckTest {
@Autowired
private MockMvc mvc;
@IfProfileValue(name = "spring.profiles.active", values = { "dev" })
@Test
@DisplayName("GET Method /SwCheckStatus check success")
public void testStatusSuccess() throws Exception {
MvcResult result = mvc.perform(get("/status/SwCheckStatus"))
.andDo(print())
.andExpect(status().isOk())
.andReturn();
//.andExpect(content().json("{\"services\":[\"OutboundMessageService\"]}", true));
String actualJson = result.getResponse().getContentAsString();
String expectedJson = "[{\"instanceName\":\"Instance C\", \"read\" : 1, \"swProduct\" : \"Area 3\", \"swProductModule\" : \"Spring Boot 3\"}]";
assertThat(expectedJson).isIn(actualJson);
}
}
Output of whole Postman json result looks like this ---
[
{
"instanceName": "",
"read": 1,
"swProduct": "Area 1",
"swProductModule": "Regular 1"
},
{
"instanceName": "",
"read": 1,
"swProduct": "Area 1",
"swProductModule": "Regular 2"
},
{
"instanceName": "",
"read": 1,
"swProduct": "Area 1",
"swProductModule": "Spring Boot 1"
},
{
"instanceName": "",
"read": 1,
"swProduct": "Area 1",
"swProductModule": "Spring Boot 2"
},
Intellij says -- its expecting and String matches... but test failed -- check attachment --- [enter image description here][1]
Any help of insights to perform the test is greatly appreciated. [1]: https://i.sstatic.net/FE2dT.jpg