Writing an integration test for the Hello World API with a path parameter

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.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset