Integration testing

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

   @Test   fun `GET welcome-with-parameter returns "Hello World"`() {     // When     val body = restTemplate.getForObject(     "/welcome-with-parameter/name/Buddy",      WelcomeBean::class.java)     // Then    assertThat(body.message,     containsString("Hello World, Buddy"));   }

A few important things to note are as follows:

  • restTemplate.getForObject("/welcome-with-parameter/name/Buddy", WelcomeBean::class.java): 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, ...

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.