AuthenticatedRestTemplate { public <T> T getForObject(String resourcePath, Class<T> responseType) throws RestClientException { return restTemplate.getForObject(getURIForResource(resourcePath), responseType); }  String getURIForResource(String resourcePath); T getForObject(String resourcePath, Class<T> responseType); List<T> getForObjectAsList(String resourcePath, Class<T[]> responseType); List<T> getForObjectAsListWithQueryStringParams(String resourcePath, Class<T[]> responseType, Map<String, ?> queryStringParams); ResponseEntity<T> getForEntity(String resourcePath, Class<T> responseType); ResponseEntity<T> getForEntityWithQueryParams(String resourcePath, ParameterizedTypeReference<T> responseType, Map<String, ?> queryStringParams); T postForObject(String resourcePath, Object request, Class<T> responseType); T putForObject(String resourcePath, Object request, Class<T> responseType); ResponseEntity<T> postForEntity(String resourcePath, Object request, Class<T> responseType); T deleteForObject(String resourcePath, HttpEntity request, Class<T> responseType); void delete(String resourcePath, HttpEntity request); void delete(String resourcePath); void patch(String resourcePath, Object request); void put(String resourcePath, Object request); @VisibleForTesting CookieStoreRestTemplate getRestTemplate();  }
@Test public void testUnPreparedAuthRestTemplateAndSessionTimeoutForGetForObject() { initialAuthenticationMock(); mockCsrfTokenEndpoint(); WireMock.stubFor(WireMock.get(WireMock.urlEqualTo("/session-timeout-endpoint")) .willReturn(WireMock.aResponse() .withStatus(HttpStatus.FOUND.value()) .withHeader("Location", "/login") .withBody(""))); String response = null; try { response = authenticatedRestTemplate.getForObject("session-timeout-endpoint", String.class); } catch (RestClientException e) { logger.debug("Expecting this to fail because the response for /session-timeout-endpoint has been stubbed to be always returning a 302"); Assert.assertEquals("Tried to re-authenticate but the response remains to be unauthenticated", e.getMessage()); } Assert.assertNull("There should have been no response", response); WireMock.verify(2, WireMock.getRequestedFor(WireMock.urlMatching("/login")).withHeader("Accept", WireMock.matching("text/plain.*"))); WireMock.verify(2, WireMock.postRequestedFor(WireMock.urlMatching("/login")).withHeader("Accept", WireMock.matching("text/plain.*"))); WireMock.verify(2, WireMock.getRequestedFor(WireMock.urlMatching("/session-timeout-endpoint")).withHeader("Accept", WireMock.matching("text/plain.*")).withHeader("X-CSRF-TOKEN", WireMock.matching("madeup-csrf-value"))); }