title: Spring Boot's TestRestTemplate with HATEOAS PagedResources
body: <p>I'm trying to use the TestRestTemplate in my Spring Boot Application's Integration-Test, to make a request to a Spring Data REST Repository.</p>
  
  <p>The response in the browser has the form:</p>
  
  <pre><code>{
  "links": [
      {
          "rel": "self",
          "href": "http://localhost:8080/apiv1/data/users"
      },
      {
          "rel": "profile",
          "href": "http://localhost:8080/apiv1/data/profile/users"
      },
      {
          "rel": "search",
          "href": "http://localhost:8080/apiv1/data/users/search"
      }
  ],
  "content": [
      {
          "username": "admin",
          "enabled": true,
          "firstName": null,
          "lastName": null,
          "permissions": [ ],
          "authorities": [
              "ROLE_ADMIN"
          ],
          "accountNonExpired": true,
          "accountNonLocked": true,
          "credentialsNonExpired": true,
          "content": [ ],
          "links": [
              {
                  "rel": "self",
                  "href": "http://localhost:8080/apiv1/data/users/1"
              },
              {
                  "rel": "myUser",
                  "href": "http://localhost:8080/apiv1/data/users/1"
              },
              {
                  "rel": "mandant",
                  "href": "http://localhost:8080/apiv1/data/users/1/mandant"
              }
          ]
      },
      {
          "username": "dba",
          "enabled": true,
          "firstName": null,
          "lastName": null,
          "permissions": [ ],
          "authorities": [
              "ROLE_DBA"
          ],
          "accountNonExpired": true,
          "accountNonLocked": true,
          "credentialsNonExpired": true,
          "content": [ ],
          "links": [
              {
                  "rel": "self",
                  "href": "http://localhost:8080/apiv1/data/users/2"
              },
              {
                  "rel": "myUser",
                  "href": "http://localhost:8080/apiv1/data/users/2"
              },
              {
                  "rel": "mandant",
                  "href": "http://localhost:8080/apiv1/data/users/2/mandant"
              }
          ]
      },
      {
          "username": "user",
          "enabled": true,
          "firstName": null,
          "lastName": null,
          "permissions": [ ],
          "authorities": [
              "ROLE_USER"
          ],
          "accountNonExpired": true,
          "accountNonLocked": true,
          "credentialsNonExpired": true,
          "content": [ ],
          "links": [
              {
                  "rel": "self",
                  "href": "http://localhost:8080/apiv1/data/users/3"
              },
              {
                  "rel": "myUser",
                  "href": "http://localhost:8080/apiv1/data/users/3"
              },
              {
                  "rel": "mandant",
                  "href": "http://localhost:8080/apiv1/data/users/3/mandant"
              }
          ]
      }
  ],
  "page": {
      "size": 20,
      "totalElements": 3,
      "totalPages": 1,
      "number": 0
  }
  }
  </code></pre>
  
  <p>This is the test:</p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
  @ActiveProfiles("unittest")
  public class MyUserRepositoryIntegrationTest {
    private static Logger logger = LoggerFactory.getLogger(MyUserRepositoryIntegrationTest.class);
    private static final int NUM_USERS = 4;
    private static final String USER_URL = "/apiv1/data/users";
  
    @Autowired
    private TestRestTemplate restTemplate;
  
    @Test
    public void listUsers() {
      ResponseEntity&lt;PagedResources&lt;MyUser&gt;&gt; response = restTemplate.withBasicAuth("user", "user").exchange(USER_URL,
          HttpMethod.GET, null, new ParameterizedTypeReference&lt;PagedResources&lt;MyUser&gt;&gt;() {
          });
      assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
      logger.debug("Res : " + response.getBody().toString());
      assertThat(response.getBody().getContent().size()).isEqualTo(NUM_USERS);
    }
  
    @TestConfiguration
    public static class MyTestConfig {
      @Autowired
      @Qualifier("halJacksonHttpMessageConverter")
      private TypeConstrainedMappingJackson2HttpMessageConverter halJacksonHttpMessageConverter;
  
      @Bean
      public RestTemplateBuilder restTemplateBuilder() {
        return new RestTemplateBuilder().messageConverters(halJacksonHttpMessageConverter);
      }
    }
  }
  </code></pre>
  
  <p>The Problem is, that I don't get the content. Interestingly, the Metadata (paging-info) is there.</p>
  
  <p>My TestConfig gets detected, but I think it's not using the 'halJacksonHttpMessageConverter' (which I got from here: <a href="https://github.com/bijukunjummen/hateoas-sample/blob/master/src/test/java/univ/HALRestTemplateIntegrationTests.java" rel="nofollow noreferrer">https://github.com/bijukunjummen/hateoas-sample/blob/master/src/test/java/univ/HALRestTemplateIntegrationTests.java</a>). That's why I used "messageConverters()" and not "additionalMessageConverters()" (to no avail).</p>
  
  <p>Here's the log:</p>
  
  <pre><code>m.m.a.RequestResponseBodyMethodProcessor : Written [PagedResource { content: [Resource { content: at.mycompany.myapp.auth.MyUser@7773211c, links: [&lt;http://localhost:51708/apiv1/data/users/1&gt;;rel="self", &lt;http://localhost:51708/apiv1/data/users/1&gt;;rel="logisUser"] }, Resource { content: at.mycompany.myapp.auth.MyUser@2c96fdee, links: [&lt;http://localhost:51708/apiv1/data/users/2&gt;;rel="self", &lt;http://localhost:51708/apiv1/data/users/2&gt;;rel="logisUser"] }, Resource { content: at.mycompany.myapp.auth.MyUser@1ddfd104, links: [&lt;http://localhost:51708/apiv1/data/users/3&gt;;rel="self", &lt;http://localhost:51708/apiv1/data/users/3&gt;;rel="logisUser"] }, Resource { content: at.mycompany.myapp.auth.MyUser@55d71419, links: [&lt;http://localhost:51708/apiv1/data/users/4&gt;;rel="self", &lt;http://localhost:51708/apiv1/data/users/4&gt;;rel="logisUser"] }], metadata: Metadata { number: 0, total pages: 1, total elements: 4, size: 20 }, links: [&lt;http://localhost:51708/apiv1/data/users&gt;;rel="self", &lt;http://localhost:51708/apiv1/data/profile/users&gt;;rel="profile", &lt;http://localhost:51708/apiv1/data/users/search&gt;;rel="search"] }] as "application/hal+json" using [org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration$ResourceSupportHttpMessageConverter@2f58f492]
  o.s.web.servlet.DispatcherServlet        : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
  o.s.web.client.RestTemplate              : GET request for "http://localhost:51708/apiv1/data/users" resulted in 200 (null)
  o.s.web.servlet.DispatcherServlet        : Successfully completed request
  o.s.web.client.RestTemplate              : Reading [org.springframework.hateoas.PagedResources&lt;at.mycompany.myapp.auth.MyUser&gt;] as "application/hal+json;charset=UTF-8" using [org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration$ResourceSupportHttpMessageConverter@10ad95cd]
  o.s.b.w.f.OrderedRequestContextFilter    : Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@76e257e2
  d.l.a.MyUserRepositoryIntegrationTest : Res : PagedResource { content: [], metadata: Metadata { number: 0, total pages: 1, total elements: 4, size: 20 }, links: [] }
  </code></pre>
  
  <p>The idea of overriding the restTemplate Bean comes from the docs: <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-testing.html#boot-features-rest-templates-test-utility" rel="nofollow noreferrer">https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-testing.html#boot-features-rest-templates-test-utility</a></p>
  
  <p>Any Ideas how I can simply make some REST calls and get the answer as an Object for my tests?</p>