Integration testing

The integration test we wrote for the service earlier will start failing because of invalid credentials. We will now update the integration test to supply basic authentication credentials:

    private TestRestTemplate template = new TestRestTemplate();    HttpHeaders headers = createHeaders("user-name", "user-password");    HttpHeaders createHeaders(String username, String password) {      return new HttpHeaders() {       {         String auth = username + ":" + password;         byte[] encodedAuth = Base64.getEncoder().encode         (auth.getBytes(Charset.forName("US-ASCII")));         String authHeader = "Basic " + new String(encodedAuth);         set("Authorization", authHeader);        }      };     }    @Test    public void retrieveTodos() throws Exception {      String expected = "[" + "{id:1,user:Jack,desc:\"Learn ...

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.