SabClient { public List<String> roles(String userId) { String request = request(userId); ResponseEntity<byte[]> response = restTemplate.exchange(sabEndpoint, HttpMethod.POST, new HttpEntity<> (request), byte[].class); try { List<String> roles = parser.parse(new ByteArrayInputStream(response.getBody())); LOG.debug("Retrieved SAB roles with request: {} and response: {}", request, response); return roles; } catch (Exception e) { throw new RuntimeException(e); } } SabClient(String sabUserName, String sabPassword, String sabEndpoint); List<String> roles(String userId);  }
@Test public void testGetRolesHappyFlow() throws Exception { String response = IOUtils.toString(new ClassPathResource("sab/response_success.xml").getInputStream(), "UTF-8"); stubFor(post(urlEqualTo("/sab")).withHeader("Authorization", equalTo("Basic " + encodeBase64String("user:password".getBytes()))) .willReturn(aResponse().withStatus(200).withBody(response))); List<String> roles = subject.roles("id1"); assertEquals(Arrays.asList( "Superuser", "Instellingsbevoegde", "Infraverantwoordelijke", "OperationeelBeheerder", "Mailverantwoordelijke", "Domeinnamenverantwoordelijke", "DNS-Beheerder", "AAIverantwoordelijke", "Beveiligingsverantwoordelijke"), roles); }
@Test public void testMockSabClient() throws IOException { SabClient sabClient = new SabClientConfig().mockSabClient("user", "password", "http: assertEquals(2, sabClient.roles(URN_COLLAB_PERSON_EXAMPLE_COM_ADMIN).size()); assertEquals(0, sabClient.roles("Nope").size()); }