Integration testing

The integration test for the preceding method is very simple. Take a look at the following test method:

    @Test    public void welcomeWithParameter() throws Exception {      ResponseEntity<String> response =       template.getForEntity(      createURL("/welcome-with-parameter/name/Buddy"), String.class);      assertThat(response.getBody(),       containsString("Hello World, Buddy"));    }

A few important things to note are as follows:

  • createURL("/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.

In this section, we looked at the basics of creating ...

Get Mastering Spring 5.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.