From 5e432d4ff2664a7dfac6f3d6725fcbf70d594083 Mon Sep 17 00:00:00 2001 From: Okke Harsta Date: Mon, 27 Nov 2023 14:11:14 +0100 Subject: [PATCH] Return unique groups and members based on the urn's --- pom.xml | 4 +- src/main/java/voot/ExternalGroupsService.java | 4 +- src/main/java/voot/api/VootController.java | 4 +- src/main/java/voot/model/Group.java | 2 +- src/main/java/voot/model/Member.java | 2 +- .../voot/provider/EduIDGuestProvider.java | 21 +++++------ .../java/voot/provider/OpenSocialClient.java | 15 +++----- .../provider/OpenSocialMembersClient.java | 11 +++--- src/main/java/voot/provider/Provider.java | 10 ++--- .../java/voot/provider/TeamsProvider.java | 6 +-- .../voot/provider/TeamsProviderClient.java | 37 +++++++++---------- .../java/voot/provider/Voot2Provider.java | 25 ++++++------- ...ExternalGroupsServiceLinkedGroupsTest.java | 10 ++--- .../java/voot/ExternalGroupsServiceTest.java | 4 +- src/test/java/voot/MockProvider.java | 20 +++++----- src/test/java/voot/VootControllerTest.java | 2 +- .../voot/provider/EduIDGuestProviderTest.java | 3 +- .../voot/provider/OpenSocialClientTest.java | 13 ++++--- .../provider/OpenSocialMembersClientTest.java | 3 +- .../provider/TeamsProviderClientTest.java | 11 +++--- .../java/voot/provider/Voot2ProviderTest.java | 7 ++-- .../resources/json/voot2/voot2_groups.json | 8 ++++ 22 files changed, 113 insertions(+), 109 deletions(-) diff --git a/pom.xml b/pom.xml index c54b6cc..6991d94 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.openconext voot-service - 5.0.0 + 5.0.1 jar voot-service @@ -15,7 +15,7 @@ org.springframework.boot spring-boot-starter-parent - 2.6.3 + 2.7.17 diff --git a/src/main/java/voot/ExternalGroupsService.java b/src/main/java/voot/ExternalGroupsService.java index ec32c11..ed797d0 100644 --- a/src/main/java/voot/ExternalGroupsService.java +++ b/src/main/java/voot/ExternalGroupsService.java @@ -49,7 +49,7 @@ public Set getMyGroups(String uid, String schacHomeOrganization) { .map(group -> group.id) .collect(toList()); if (!externalGroupIds.isEmpty()) { - List linkedGroups = teamsProvider.linkedLocalTeamsGroup(externalGroupIds); + Set linkedGroups = teamsProvider.linkedLocalTeamsGroup(externalGroupIds); groups.addAll(linkedGroups); } } @@ -95,7 +95,7 @@ private Optional doGetMyGroupById(String uid, String groupId, boolean try if (teamsProvider.isTeamsGroup(groupId)) { String localGroupId = extractLocalGroupId(groupId); - List externalGroupIds = teamsProvider.linkedExternalGroupIds(localGroupId); + Set externalGroupIds = teamsProvider.linkedExternalGroupIds(localGroupId); List> externalGroups = externalGroupIds.stream() .map(externalGroupId -> doGetMyGroupById(uid, externalGroupId, false)) .collect(toList()); diff --git a/src/main/java/voot/api/VootController.java b/src/main/java/voot/api/VootController.java index 37aea99..344b465 100644 --- a/src/main/java/voot/api/VootController.java +++ b/src/main/java/voot/api/VootController.java @@ -23,9 +23,9 @@ @RestController public class VootController { - private static Logger LOG = LoggerFactory.getLogger(VootController.class); + private static final Logger LOG = LoggerFactory.getLogger(VootController.class); - private ExternalGroupsService externalGroupsService; + private final ExternalGroupsService externalGroupsService; @Autowired public VootController(ExternalGroupsService externalGroupsService) { diff --git a/src/main/java/voot/model/Group.java b/src/main/java/voot/model/Group.java index 3b7ba54..808b7b3 100644 --- a/src/main/java/voot/model/Group.java +++ b/src/main/java/voot/model/Group.java @@ -4,7 +4,7 @@ import lombok.ToString; @ToString -@EqualsAndHashCode +@EqualsAndHashCode(of = {"id"}) public class Group { public final String id; diff --git a/src/main/java/voot/model/Member.java b/src/main/java/voot/model/Member.java index cd76f51..9b8044c 100644 --- a/src/main/java/voot/model/Member.java +++ b/src/main/java/voot/model/Member.java @@ -4,7 +4,7 @@ import lombok.ToString; @ToString -@EqualsAndHashCode +@EqualsAndHashCode(of = {"id"}) public class Member { public final String id; diff --git a/src/main/java/voot/provider/EduIDGuestProvider.java b/src/main/java/voot/provider/EduIDGuestProvider.java index 4f2b615..af36a3f 100644 --- a/src/main/java/voot/provider/EduIDGuestProvider.java +++ b/src/main/java/voot/provider/EduIDGuestProvider.java @@ -9,10 +9,7 @@ import voot.model.Membership; import java.net.URI; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; import java.util.stream.Collectors; public class EduIDGuestProvider extends AbstractProvider { @@ -30,11 +27,11 @@ public boolean shouldBeQueriedForMemberships(String schacHomeOrganization) { } @Override - public List getGroupMemberships(String uid) { + public Set getGroupMemberships(String uid) { RequestEntity requestEntity = new RequestEntity(HttpMethod.GET, URI.create(String.format(groupMembershipsUrlTemplate, configuration.url, uid))); ResponseEntity>> responseEntity = restTemplate.exchange(requestEntity, new ParameterizedTypeReference>>() { }); - return responseEntity.getBody().stream().map(this::parseGroup).collect(Collectors.toList()); + return responseEntity.getBody().stream().map(this::parseGroup).collect(Collectors.toSet()); } private Group parseGroup(Map map) { @@ -43,8 +40,8 @@ private Group parseGroup(Map map) { } @Override - public List getAllGroups() { - return Collections.emptyList(); + public Set getAllGroups() { + return Collections.emptySet(); } @Override @@ -53,12 +50,12 @@ public Optional getGroupMembership(String uid, String groupId) { } @Override - public List getMembers(String groupId) { - return Collections.emptyList(); + public Set getMembers(String groupId) { + return Collections.emptySet(); } @Override - public List getMembers(String personId, String groupId) { - return Collections.emptyList(); + public Set getMembers(String personId, String groupId) { + return Collections.emptySet(); } } diff --git a/src/main/java/voot/provider/OpenSocialClient.java b/src/main/java/voot/provider/OpenSocialClient.java index 6c53c2f..2bdf3e5 100644 --- a/src/main/java/voot/provider/OpenSocialClient.java +++ b/src/main/java/voot/provider/OpenSocialClient.java @@ -4,10 +4,7 @@ import voot.model.Group; import voot.model.Membership; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; import java.util.stream.Collectors; public class OpenSocialClient extends Voot2Provider { @@ -19,11 +16,11 @@ public OpenSocialClient(Configuration configuration) { } @Override - protected List parseGroups(String response) { + protected Set parseGroups(String response) { @SuppressWarnings("unchecked") List> groups = (List) parseJson(response, Map.class).get("entry"); if (CollectionUtils.isEmpty(groups)) { - return new ArrayList<>(); + return Collections.emptySet(); } return groups.stream().map(map -> { Object idHolder = map.get("id"); @@ -35,13 +32,13 @@ protected List parseGroups(String response) { (String) map.get("description"), configuration.name, new Membership((String) map.getOrDefault("voot_membership_role", "member"))); - }).collect(Collectors.toList()); + }).collect(Collectors.toSet()); } @Override protected Optional parseSingleGroup(String response) { - List groups = parseGroups(response); - return groups.isEmpty() ? Optional.empty() : Optional.of(groups.get(0)); + Set groups = parseGroups(response); + return groups.isEmpty() ? Optional.empty() : Optional.of(groups.iterator().next()); } } diff --git a/src/main/java/voot/provider/OpenSocialMembersClient.java b/src/main/java/voot/provider/OpenSocialMembersClient.java index 0ecb6ae..ad4c0bb 100644 --- a/src/main/java/voot/provider/OpenSocialMembersClient.java +++ b/src/main/java/voot/provider/OpenSocialMembersClient.java @@ -6,9 +6,10 @@ import java.util.List; import java.util.Map; +import java.util.Set; import java.util.stream.Collectors; -import static java.util.Collections.emptyList; +import static java.util.Collections.emptySet; @SuppressWarnings("unchecked") public class OpenSocialMembersClient extends OpenSocialClient { @@ -26,7 +27,7 @@ public boolean shouldBeQueriedForMembers(String groupId) { } @Override - public List getMembers(String personId, String groupId) { + public Set getMembers(String personId, String groupId) { LOG.debug("Querying getMembers for personId: {} and groupId: {}", personId, groupId); String localGroupId = UrnUtils.extractLocalGroupId(groupId); @@ -35,17 +36,17 @@ public List getMembers(String personId, String groupId) { ResponseEntity response = restTemplate.getForEntity(url, String.class, localPersonId, localGroupId); - return handleResponse(response, this::parseMembers, "getMembers", emptyList()); + return handleResponse(response, this::parseMembers, "getMembers", emptySet()); } - private List parseMembers(String body) { + private Set parseMembers(String body) { List> entries = (List>) ((Map) parseJson(body, Map.class).get("result")).get("entry"); return entries.stream().map(map -> { String id = (String) map.get("id"); String name = ((Map) map.get("name")).get("formatted"); List emails = (List) map.get("emails"); return new Member(id, name, emails != null && !emails.isEmpty() ? emails.get(0) : null); - }).collect(Collectors.toList()); + }).collect(Collectors.toSet()); } diff --git a/src/main/java/voot/provider/Provider.java b/src/main/java/voot/provider/Provider.java index c8e33f5..cb32edf 100644 --- a/src/main/java/voot/provider/Provider.java +++ b/src/main/java/voot/provider/Provider.java @@ -3,8 +3,8 @@ import voot.model.Group; import voot.model.Member; -import java.util.List; import java.util.Optional; +import java.util.Set; public interface Provider { @@ -32,12 +32,12 @@ public interface Provider { /** * @param uid the fully qualified uid */ - List getGroupMemberships(String uid); + Set getGroupMemberships(String uid); /** * All groups */ - List getAllGroups(); + Set getAllGroups(); /** * @param uid the fully qualified uid @@ -52,7 +52,7 @@ public interface Provider { * @param groupId the fully qualified uid groupId * @return all Members */ - List getMembers(String groupId); + Set getMembers(String groupId); /** * Get all members of a group @@ -61,7 +61,7 @@ public interface Provider { * @param groupId the fully qualified uid groupId * @return all Members */ - List getMembers(String personId, String groupId); + Set getMembers(String personId, String groupId); /** * Tells us if it is worthwhile calling this client when returning all members of a group diff --git a/src/main/java/voot/provider/TeamsProvider.java b/src/main/java/voot/provider/TeamsProvider.java index 127833d..b20770d 100644 --- a/src/main/java/voot/provider/TeamsProvider.java +++ b/src/main/java/voot/provider/TeamsProvider.java @@ -3,8 +3,8 @@ import voot.model.Group; import java.util.Collection; -import java.util.List; import java.util.Optional; +import java.util.Set; public interface TeamsProvider extends Provider { @@ -12,8 +12,8 @@ public interface TeamsProvider extends Provider { Optional findByLocalGroupId(String localGroupId); - List linkedLocalTeamsGroup(Collection fullyQualifiedExternalGroupIds); + Set linkedLocalTeamsGroup(Collection fullyQualifiedExternalGroupIds); - List linkedExternalGroupIds(String localGroupId); + Set linkedExternalGroupIds(String localGroupId); } diff --git a/src/main/java/voot/provider/TeamsProviderClient.java b/src/main/java/voot/provider/TeamsProviderClient.java index c9cfa03..41f9b28 100644 --- a/src/main/java/voot/provider/TeamsProviderClient.java +++ b/src/main/java/voot/provider/TeamsProviderClient.java @@ -7,14 +7,11 @@ import voot.util.UrnUtils; import java.net.URI; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; import java.util.regex.Matcher; +import java.util.stream.Collectors; -import static java.util.Collections.emptyList; -import static java.util.stream.Collectors.toList; +import static java.util.Collections.emptySet; public class TeamsProviderClient extends Voot2Provider implements TeamsProvider { @@ -42,41 +39,43 @@ public Optional findByLocalGroupId(String localGroupId) { } @Override - public List linkedLocalTeamsGroup(Collection fullyQualifiedExternalGroupIds) { + public Set linkedLocalTeamsGroup(Collection fullyQualifiedExternalGroupIds) { + //Make the externalGroupIdentifiers unique + HashSet uniqueGroupIds = new HashSet<>(fullyQualifiedExternalGroupIds); URI uri = UriComponentsBuilder.fromHttpUrl(String.format("%s/linked-locals", configuration.url)) - .queryParam("externalGroupIds", String.join(",", fullyQualifiedExternalGroupIds)) + .queryParam("externalGroupIds", String.join(",", uniqueGroupIds)) .build().encode().toUri(); ResponseEntity response = restTemplate.getForEntity(uri, String.class); - return handleResponse(response, this::parseGroups, "findByLocalGroupId", emptyList()); + return handleResponse(response, this::parseGroups, "findByLocalGroupId", emptySet()); } @Override @SuppressWarnings("unchecked") - public List linkedExternalGroupIds(String localGroupId) { + public Set linkedExternalGroupIds(String localGroupId) { URI uri = UriComponentsBuilder.fromHttpUrl(String.format("%s/linked-externals", configuration.url)) .queryParam("teamId", localGroupId) .build().encode().toUri(); - ResponseEntity response = restTemplate.getForEntity(uri, List.class); - return handleResponse(response, s -> s, "findByLocalGroupId", emptyList()); + ResponseEntity response = restTemplate.getForEntity(uri, Set.class); + return handleResponse(response, s -> s, "findByLocalGroupId", emptySet()); } @Override - public List getMembers(String personId, String groupId) { + public Set getMembers(String personId, String groupId) { return getMembers(groupId); } @Override - public List getMembers(String groupId) { + public Set getMembers(String groupId) { String uri = String.format("%s/members/{groupId}", configuration.url); ResponseEntity response = restTemplate.getForEntity(uri, String.class, groupId); - return handleResponse(response, this::parseMembers, "getMembers", emptyList()); + return handleResponse(response, this::parseMembers, "getMembers", emptySet()); } @Override - public List getAllGroups() { + public Set getAllGroups() { String uri = String.format("%s/groups", configuration.url); ResponseEntity response = restTemplate.getForEntity(uri, String.class); - return handleResponse(response, this::parseGroups, "getAllGroups", emptyList()); + return handleResponse(response, this::parseGroups, "getAllGroups", emptySet()); } /** @@ -88,9 +87,9 @@ protected String personUrnFromFullyQualifiedUrn(String uid) { } @SuppressWarnings("unchecked") - private List parseMembers(String response) { + private Set parseMembers(String response) { List> maps = parseJson(response, List.class); - return maps.stream().map(map -> new Member(map.get("id"), map.get("name"), map.get("email"))).collect(toList()); + return maps.stream().map(map -> new Member(map.get("id"), map.get("name"), map.get("email"))).collect(Collectors.toSet()); } } diff --git a/src/main/java/voot/provider/Voot2Provider.java b/src/main/java/voot/provider/Voot2Provider.java index 51ecb7a..a3ca339 100644 --- a/src/main/java/voot/provider/Voot2Provider.java +++ b/src/main/java/voot/provider/Voot2Provider.java @@ -8,13 +8,10 @@ import voot.model.Membership; import voot.util.UrnUtils; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; -import static java.util.Collections.emptyList; -import static java.util.stream.Collectors.toList; +import static java.util.Collections.emptySet; +import static java.util.stream.Collectors.toSet; public class Voot2Provider extends AbstractProvider { @@ -32,16 +29,16 @@ public boolean shouldBeQueriedForMemberships(String schacHomeOrganization) { } @Override - public List getGroupMemberships(final String uid) { + public Set getGroupMemberships(final String uid) { LOG.debug("Querying getGroupMemberships for subjectId: {} and name: {}", uid, configuration.schacHomeOrganization); String localUid = personUrnFromFullyQualifiedUrn(uid); ResponseEntity response = restTemplate.getForEntity(String.format(allMembershipsUrlTemplate, configuration.url), String.class, localUid); - return handleResponse(response, this::parseGroups, "getGroupMemberships", emptyList()); + return handleResponse(response, this::parseGroups, "getGroupMemberships", emptySet()); } @Override - public List getAllGroups() { - return Collections.emptyList(); + public Set getAllGroups() { + return Collections.emptySet(); } @Override @@ -68,19 +65,19 @@ protected String personUrnFromFullyQualifiedUrn(String uid) { } @Override - public List getMembers(String groupId) { + public Set getMembers(String groupId) { throw new IllegalArgumentException("Voot2Providers do not support getting members"); } @Override - public List getMembers(String personId, String groupId) { + public Set getMembers(String personId, String groupId) { return getMembers(groupId); } @SuppressWarnings("unchecked") - protected List parseGroups(String response) { + protected Set parseGroups(String response) { List> maps = parseJson(response, List.class); - return maps.stream().map(this::parseGroup).collect(toList()); + return maps.stream().map(this::parseGroup).collect(toSet()); } @SuppressWarnings("unchecked") diff --git a/src/test/java/voot/ExternalGroupsServiceLinkedGroupsTest.java b/src/test/java/voot/ExternalGroupsServiceLinkedGroupsTest.java index 80c571b..c901d81 100644 --- a/src/test/java/voot/ExternalGroupsServiceLinkedGroupsTest.java +++ b/src/test/java/voot/ExternalGroupsServiceLinkedGroupsTest.java @@ -61,14 +61,14 @@ void before() { when(teamsProvider.isTeamsGroup(admins)).thenReturn(true); when(teamsProvider.isTeamsGroup(teachers)).thenReturn(false); when(teamsProvider.findByLocalGroupId(adminGrouperId)).thenReturn(Optional.of(group(admins))); - when(teamsProvider.getGroupMemberships("Joe")).thenReturn(asList(group(admins))); - when(teamsProvider.getGroupMemberships("Mary")).thenReturn(Collections.emptyList()); - when(teamsProvider.linkedLocalTeamsGroup(Collections.singletonList(teachers))).thenReturn(asList(group(admins))); - when(teamsProvider.linkedExternalGroupIds("Admins")).thenReturn(asList(teachers)); + when(teamsProvider.getGroupMemberships("Joe")).thenReturn(Set.of((group(admins)))); + when(teamsProvider.getGroupMemberships("Mary")).thenReturn(Collections.emptySet()); + when(teamsProvider.linkedLocalTeamsGroup(Collections.singletonList(teachers))).thenReturn(Set.of((group(admins)))); + when(teamsProvider.linkedExternalGroupIds("Admins")).thenReturn(Set.of((teachers))); when(externalGroupProvider.getGroupMembership("Mary", teachers)).thenReturn(Optional.of(group(teachers))); when(externalGroupProvider.getGroupMembership(eq("Joe"), anyString())).thenReturn(Optional.empty()); - when(externalGroupProvider.getGroupMemberships("Mary")).thenReturn(asList(group(teachers))); + when(externalGroupProvider.getGroupMemberships("Mary")).thenReturn(Set.of((group(teachers)))); when(teamsProvider.getGroupMembership("Joe", admins)).thenReturn(Optional.of(group(admins))); when(teamsProvider.getGroupMembership("Mary", admins)).thenReturn(Optional.empty()); diff --git a/src/test/java/voot/ExternalGroupsServiceTest.java b/src/test/java/voot/ExternalGroupsServiceTest.java index d66c801..34b3cb9 100644 --- a/src/test/java/voot/ExternalGroupsServiceTest.java +++ b/src/test/java/voot/ExternalGroupsServiceTest.java @@ -84,8 +84,8 @@ void testGetMembers() throws Exception { ExternalGroupsService externalGroupsService = externalGroupService(providers); Set members = externalGroupsService.getMembers("urn:collab:group:example.org:nl:surfnet:diensten:apachecon"); - assertEquals(2, members.size()); - assertEquals("urn:collab:person:example.com:admin", members.stream().findFirst().get().id); + assertEquals(1, members.size()); + assertEquals("urn:collab:person:example.com:admin", members.iterator().next().id); } @Test diff --git a/src/test/java/voot/MockProvider.java b/src/test/java/voot/MockProvider.java index e9fec01..0fcab26 100644 --- a/src/test/java/voot/MockProvider.java +++ b/src/test/java/voot/MockProvider.java @@ -11,8 +11,8 @@ import voot.util.UrnUtils; import java.util.Collections; -import java.util.List; import java.util.Optional; +import java.util.Set; import java.util.UUID; public class MockProvider extends AbstractProvider { @@ -54,13 +54,13 @@ public boolean shouldBeQueriedForMembers(String groupId) { } @Override - public List getGroupMemberships(String uid) { + public Set getGroupMemberships(String uid) { return getResult(defaultGroup("id")); } @Override - public List getAllGroups() { - return Collections.singletonList(defaultGroup("id")); + public Set getAllGroups() { + return Collections.singleton(defaultGroup("id")); } @@ -70,16 +70,16 @@ public Optional getGroupMembership(String uid, String groupId) { } @Override - public List getMembers(String groupId) { + public Set getMembers(String groupId) { return getResult(defaultMember()); } @Override - public List getMembers(String personId, String groupId) { + public Set getMembers(String personId, String groupId) { return getResult(defaultMember()); } - private List getResult(T result) { + private Set getResult(T result) { switch (this.simulationMode) { case Timeout: try { @@ -87,14 +87,14 @@ private List getResult(T result) { } catch (InterruptedException e) { } LOG.debug("timed out"); - return Collections.emptyList(); + return Collections.emptySet(); case Error: throw new RuntimeException("failed!"); case Empty: - return Collections.emptyList(); + return Collections.emptySet(); default: // Success LOG.debug("got result"); - return Collections.singletonList(result); + return Collections.singleton(result); } } diff --git a/src/test/java/voot/VootControllerTest.java b/src/test/java/voot/VootControllerTest.java index b5ee1a0..e2b7303 100644 --- a/src/test/java/voot/VootControllerTest.java +++ b/src/test/java/voot/VootControllerTest.java @@ -17,7 +17,7 @@ public class VootControllerTest extends AbstractTest { void testGroupsMe() throws IOException { super.stubCallVoot2("user/admin/groups", "json/voot2/voot2_groups.json"); super.stubCallTeams("user/urn:collab:person:example.com:admin/groups", "json/voot2/voot2_groups.json"); - super.stubCallTeams("linked-locals?externalGroupIds=urn:collab:group:surfteams.nl:id1,urn:collab:group:surfteams.nl:id2", + super.stubCallTeams("linked-locals?externalGroupIds=urn:collab:group:surfteams.nl:id2,urn:collab:group:surfteams.nl:id1", "json/voot2/voot2_group.json"); List results = given() .when() diff --git a/src/test/java/voot/provider/EduIDGuestProviderTest.java b/src/test/java/voot/provider/EduIDGuestProviderTest.java index 8716dcd..c821c6f 100644 --- a/src/test/java/voot/provider/EduIDGuestProviderTest.java +++ b/src/test/java/voot/provider/EduIDGuestProviderTest.java @@ -8,6 +8,7 @@ import java.io.IOException; import java.util.List; +import java.util.Set; import static com.github.tomakehurst.wiremock.client.WireMock.*; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -30,7 +31,7 @@ void getGroupMemberships() throws IOException { .withStatus(200) .withHeader("Content-type", "application/json"). withBody(json))); - List groupMemberships = subject.getGroupMemberships(urn); + Set groupMemberships = subject.getGroupMemberships(urn); assertEquals(2, groupMemberships.size()); } diff --git a/src/test/java/voot/provider/OpenSocialClientTest.java b/src/test/java/voot/provider/OpenSocialClientTest.java index 8c5bae1..788013e 100644 --- a/src/test/java/voot/provider/OpenSocialClientTest.java +++ b/src/test/java/voot/provider/OpenSocialClientTest.java @@ -7,6 +7,7 @@ import java.util.List; import java.util.Optional; +import java.util.Set; import static org.junit.jupiter.api.Assertions.*; @@ -25,7 +26,7 @@ class OpenSocialClientTest extends AbstractTest { @Test void testGetMemberships() throws Exception { stubCallVoot2("groups/" + UID, "json/opensocial/open_social_groups.json"); - final List memberships = subject.getGroupMemberships(USER_URN); + Set memberships = subject.getGroupMemberships(USER_URN); assertGroups(memberships); } @@ -33,7 +34,7 @@ void testGetMemberships() throws Exception { @Test void testGetEmptyMemberships() throws Exception { stubCallVoot2("groups/" + UID, "json/opensocial/open_social_groups_empty.json"); - final List memberships = subject.getGroupMemberships(USER_URN); + final Set memberships = subject.getGroupMemberships(USER_URN); assertTrue(memberships.isEmpty()); } @@ -41,7 +42,7 @@ void testGetEmptyMemberships() throws Exception { @Test void testGetMembershipsDeprecatedCompoundId() throws Exception { stubCallVoot2("groups/admin", "json/opensocial/open_social_deprecated_groups.json"); - final List memberships = subject.getGroupMemberships(USER_URN); + Set memberships = subject.getGroupMemberships(USER_URN); assertGroups(memberships); } @@ -79,13 +80,13 @@ void testGetMembershipWithoutEntry() throws Exception { assertFalse(group.isPresent()); } - private void assertGroups(List memberships) { + private void assertGroups(Set memberships) { assertEquals(2, memberships.size()); - Group group1 = memberships.get(0); + Group group1 = memberships.stream().filter(group -> group.id.equals("urn:collab:group:example.org:etc:sysadmingroup") ).findFirst().get(); assertAdminGroup(group1); - Group group2 = memberships.get(1); + Group group2 = memberships.stream().filter(group -> group.id.equals("urn:collab:group:example.org:nl:surfnet:diensten:test") ).findFirst().get(); assertEquals("urn:collab:group:example.org:nl:surfnet:diensten:test", group2.id); assertEquals("test title", group2.displayName); assertEquals("test description", group2.description); diff --git a/src/test/java/voot/provider/OpenSocialMembersClientTest.java b/src/test/java/voot/provider/OpenSocialMembersClientTest.java index 714e638..10e0e0b 100644 --- a/src/test/java/voot/provider/OpenSocialMembersClientTest.java +++ b/src/test/java/voot/provider/OpenSocialMembersClientTest.java @@ -5,6 +5,7 @@ import voot.model.Member; import java.util.List; +import java.util.Set; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -18,7 +19,7 @@ class OpenSocialMembersClientTest extends AbstractTest { @Test void testGetMembers() throws Exception { stubCallVoot2("people/" + UID + "/" + GROUP_ID, "json/members/external_members.json"); - List members = subject.getMembers(USER_URN, GROUP_URN); + Set members = subject.getMembers(USER_URN, GROUP_URN); assertEquals(4, members.size()); members.forEach(this::assertMember); diff --git a/src/test/java/voot/provider/TeamsProviderClientTest.java b/src/test/java/voot/provider/TeamsProviderClientTest.java index a9f023e..957c9c6 100644 --- a/src/test/java/voot/provider/TeamsProviderClientTest.java +++ b/src/test/java/voot/provider/TeamsProviderClientTest.java @@ -14,6 +14,7 @@ import java.util.Arrays; import java.util.List; import java.util.Optional; +import java.util.Set; import static com.github.tomakehurst.wiremock.client.WireMock.*; import static org.junit.jupiter.api.Assertions.*; @@ -57,35 +58,35 @@ public void findByLocalGroupId404() throws Exception { @Test public void linkedLocalTeamsGroup() throws Exception { stubResponse("/linked-locals", "json/voot2/voot2_groups.json"); - List groups = subject.linkedLocalTeamsGroup(Arrays.asList("urn:collab:group:avans:test-team", "urn:collab:group:avans:test-team-2")); + Set groups = subject.linkedLocalTeamsGroup(Set.of("urn:collab:group:avans:test-team", "urn:collab:group:avans:test-team-2")); assertEquals(2, groups.size()); } @Test public void linkedExternalGroupIds() throws Exception { stubResponse("/linked-externals", "json/teams/external_team_ids.json"); - List externalGroupIds = subject.linkedExternalGroupIds("urn:collab:group:avans:test-team"); + Set externalGroupIds = subject.linkedExternalGroupIds("urn:collab:group:avans:test-team"); assertEquals(2, externalGroupIds.size()); } @Test public void getAllGroups() throws Exception { stubResponse("/groups", "json/voot2/voot2_groups.json"); - List groups = subject.getAllGroups(); + Set groups = subject.getAllGroups(); assertEquals(2, groups.size()); } @Test public void getMembers() throws Exception { stubResponse("/members/nl:surfnet:diensten:test-team", "json/teams/members.json"); - List members = subject.getMembers("nl:surfnet:diensten:test-team"); + Set members = subject.getMembers("nl:surfnet:diensten:test-team"); assertEquals(2, members.size()); } @Test public void getMembersWithMemberId() throws Exception { stubResponse("/members/nl:surfnet:diensten:test-team", "json/teams/members.json"); - List members = subject.getMembers("totally-ignored", "nl:surfnet:diensten:test-team"); + Set members = subject.getMembers("totally-ignored", "nl:surfnet:diensten:test-team"); assertEquals(2, members.size()); } diff --git a/src/test/java/voot/provider/Voot2ProviderTest.java b/src/test/java/voot/provider/Voot2ProviderTest.java index a9bf0c5..3002a4e 100644 --- a/src/test/java/voot/provider/Voot2ProviderTest.java +++ b/src/test/java/voot/provider/Voot2ProviderTest.java @@ -8,6 +8,7 @@ import java.util.List; import java.util.Optional; +import java.util.Set; import static com.github.tomakehurst.wiremock.client.WireMock.*; import static org.junit.jupiter.api.Assertions.*; @@ -42,14 +43,14 @@ void testShouldBeQueriedForGroup() throws Exception { @Test void testGetMemberships() throws Exception { stubCallVoot2("user/" + UID + "/groups", "json/voot2/voot2_groups.json"); - List groups = subject.getGroupMemberships(USER_URN); + Set groups = subject.getGroupMemberships(USER_URN); assertTrue(groups.size() > 0); } @Test void testGetEmptyMemberships() throws Exception { stubCallVoot2("user/" + UID + "/groups", "json/voot2/voot2_groups_empty.json"); - List memberships = subject.getGroupMemberships(USER_URN); + Set memberships = subject.getGroupMemberships(USER_URN); assertTrue(memberships.isEmpty()); } @@ -57,7 +58,7 @@ void testGetEmptyMemberships() throws Exception { @Test void testGetEmptyMembershipsBecauseOfVootException() throws Exception { stubFor(get(urlEqualTo("/" + "user/" + UID + "/groups")).willReturn(aResponse().withStatus(304))); - List memberships = subject.getGroupMemberships(USER_URN); + Set memberships = subject.getGroupMemberships(USER_URN); assertTrue(memberships.isEmpty()); } diff --git a/src/test/resources/json/voot2/voot2_groups.json b/src/test/resources/json/voot2/voot2_groups.json index d16d025..d41c24f 100644 --- a/src/test/resources/json/voot2/voot2_groups.json +++ b/src/test/resources/json/voot2/voot2_groups.json @@ -14,5 +14,13 @@ "basic": "member" }, "description": "description...2" + }, + { + "id": "id2", + "displayName": "duplicate", + "membership": { + "basic": "member" + }, + "description": "duplicate...2" } ]