@Test
  public void testGroups() throws Exception {
    String groupsJson =
        IOUtils.toString(
            new ClassPathResource("mocks/oauth-client-credentials.json").getInputStream());
    String oauthJson =
        IOUtils.toString(new ClassPathResource("mocks/voot-groups.json").getInputStream());

    stubFor(
        post(urlEqualTo("/oauth/token"))
            .willReturn(
                aResponse()
                    .withStatus(200)
                    .withHeader("Content-Type", "application/json")
                    .withBody(groupsJson)));
    stubFor(
        get(urlEqualTo("/internal/external-groups/" + personId))
            .willReturn(
                aResponse()
                    .withStatus(200)
                    .withHeader("Content-Type", "application/json")
                    .withBody(oauthJson)));

    List<ExternalGroup> groups = client.groups(personId);
    assertEquals(2, groups.size());

    ExternalGroup group = groups.get(0);
    assertEquals("urn:collab:group:foo:go", group.getIdentifier());
    assertEquals("go", group.getName());
    assertEquals("Go description", group.getDescription());
    assertEquals("foo", group.getGroupProvider().getIdentifier());
  }
Пример #2
0
 @Test
 public void testHasAccess() throws Exception {
   String response =
       StreamUtils.copyToString(
           new ClassPathResource("voot/groups.json").getInputStream(), Charset.forName("UTF-8"));
   stubFor(
       get(urlEqualTo("/internal/groups/id1"))
           .willReturn(
               aResponse()
                   .withStatus(200)
                   .withHeader("Content-Type", "application/json")
                   .withBody(response)));
   List<String> groups = subject.groups("id1");
   assertEquals(14, groups.size());
   assertTrue(groups.stream().allMatch(group -> StringUtils.hasText(group)));
 }