The response for the http://localhost:8080/welcome-with-parameter/name/Buddy URL is as follows:
{"message":"Hello World, Buddy!"}
The integration test for the preceding method is very simple and is as follows:
@Test
public void welcomeWithParameter() throws Exception {
ResponseEntity < String > response =
template.getForEntity("/welcome-with-parameter/name/Buddy", String.class);
assertThat(response.getBody(),
containsString("Hello World, Buddy"));
}
Please note the following:
- "/welcome-with-parameter/name/Buddy": This matches against the variable template in the URI. We are passing in the name, Buddy.
- assertThat(response.getBody(), containsString("Hello World, Buddy”)): We expect the response to contain the message with the name.