diff --git a/pom.xml b/pom.xml index f2e7668d2a41a4fb9a285cedb4233364e35e9ac7..bbb5fc5741d964917d8a154031b44ca8e95d4ce4 100644 --- a/pom.xml +++ b/pom.xml @@ -35,7 +35,7 @@ <modelVersion>4.0.0</modelVersion> <groupId>de.ozgcloud.user</groupId> <artifactId>user-manager</artifactId> - <version>2.10.0</version> + <version>2.10.1-SNAPSHOT</version> <name>OZG-Cloud User Manager</name> <packaging>pom</packaging> diff --git a/user-manager-interface/pom.xml b/user-manager-interface/pom.xml index d76c8cc5ac688bc95e1e5d64b379ac7dcf682968..aac04468ee3251be087b21b0dd97d147a96d04a6 100644 --- a/user-manager-interface/pom.xml +++ b/user-manager-interface/pom.xml @@ -30,7 +30,7 @@ <parent> <groupId>de.ozgcloud.user</groupId> <artifactId>user-manager</artifactId> - <version>2.10.0</version> + <version>2.10.1-SNAPSHOT</version> </parent> <artifactId>user-manager-interface</artifactId> diff --git a/user-manager-server/pom.xml b/user-manager-server/pom.xml index c09d80016d859559d2cdfe98e6839bf0cc920aa7..24a81624984fc8d32792fafa30b26d04fef03edd 100644 --- a/user-manager-server/pom.xml +++ b/user-manager-server/pom.xml @@ -30,7 +30,7 @@ <parent> <groupId>de.ozgcloud.user</groupId> <artifactId>user-manager</artifactId> - <version>2.10.0</version> + <version>2.10.1-SNAPSHOT</version> </parent> <artifactId>user-manager-server</artifactId> diff --git a/user-manager-server/src/main/java/de/ozgcloud/user/UserResourceMapper.java b/user-manager-server/src/main/java/de/ozgcloud/user/UserResourceMapper.java index f9f2486ea48654c5493876af69f760f9b1367daf..6dfc125640d0f379e2153d96f9c07ed511e7278b 100644 --- a/user-manager-server/src/main/java/de/ozgcloud/user/UserResourceMapper.java +++ b/user-manager-server/src/main/java/de/ozgcloud/user/UserResourceMapper.java @@ -93,6 +93,7 @@ public abstract class UserResourceMapper { .map(this::mapGroup) .filter(Objects::nonNull) .map(attributeMap -> attributeMap.get(properties.organisationsEinheitIdKey())) + .filter(Objects::nonNull) .flatMap(Collection::stream); } diff --git a/user-manager-server/src/test/java/de/ozgcloud/user/GroupRepresentationTestFactory.java b/user-manager-server/src/test/java/de/ozgcloud/user/GroupRepresentationTestFactory.java index ef6f392a0ca35993bd50422df19a42ac3a69367b..8be817f43c5f957db4e55ba5c1959b42ff75a07b 100644 --- a/user-manager-server/src/test/java/de/ozgcloud/user/GroupRepresentationTestFactory.java +++ b/user-manager-server/src/test/java/de/ozgcloud/user/GroupRepresentationTestFactory.java @@ -36,11 +36,15 @@ class GroupRepresentationTestFactory { } public static GroupRepresentation createByPathAndOrganisationEinheitIds(String groupPath, String... organisationEinheitIds) { + return createWithPathAndAttributes(groupPath, Map.of(UserResourceMapperTest.ORGANISATIONS_EINHEIT_ID_KEY, + List.of(organisationEinheitIds))); + } + + public static GroupRepresentation createWithPathAndAttributes(String groupPath, Map<String, List<String>> attributes) { var groupRepresentation = new GroupRepresentation(); groupRepresentation.setName(groupPath); groupRepresentation.setPath(groupPath); - groupRepresentation.setAttributes(Map.of(UserResourceMapperTest.ORGANISATIONS_EINHEIT_ID_KEY, - List.of(organisationEinheitIds))); + groupRepresentation.setAttributes(attributes); return groupRepresentation; } } diff --git a/user-manager-server/src/test/java/de/ozgcloud/user/UserResourceMapperTest.java b/user-manager-server/src/test/java/de/ozgcloud/user/UserResourceMapperTest.java index effcd75641189d1acd52922498cabd394175d55f..beb45ba1b47c07cd6933a005b8bb07f446d0c624 100644 --- a/user-manager-server/src/test/java/de/ozgcloud/user/UserResourceMapperTest.java +++ b/user-manager-server/src/test/java/de/ozgcloud/user/UserResourceMapperTest.java @@ -56,6 +56,7 @@ class UserResourceMapperTest { static final String ORGANISATIONS_EINHEIT_ID_2 = "4711"; static final String GROUP_1_PATH = "/group1"; static final String GROUP_2_PATH = "/group2"; + static final String GROUP_3_PATH = "/group3"; @Spy @InjectMocks @@ -186,12 +187,25 @@ class UserResourceMapperTest { GROUP_1_PATH, ORGANISATIONS_EINHEIT_ID_1, ORGANISATIONS_EINHEIT_ID_3); private final GroupRepresentation group2 = GroupRepresentationTestFactory.createByPathAndOrganisationEinheitIds( GROUP_2_PATH, ORGANISATIONS_EINHEIT_ID_2); + private final GroupRepresentation group3 = GroupRepresentationTestFactory.createWithPathAndAttributes( + GROUP_3_PATH, Map.of()); @BeforeEach void beforeEach() { when(properties.organisationsEinheitIdKey()).thenReturn(ORGANISATIONS_EINHEIT_ID_KEY); } + @DisplayName("should map no organisations einheit id if group has none") + @Test + void shouldMapNoOrganisationsEinheitIdIfGroupHasNone() { + when(realm.getGroupByPath(GROUP_3_PATH)).thenReturn(group3); + var userResource = UserResourceTestFactory.createWithGroups(group3); + + var result = mapper.mapOrganisationsEinheitIds(userResource); + + assertThat(result).isEmpty(); + } + @Test void shouldMapOrganisationsEinheitIdsFromSingleGroup() { var userResource = UserResourceTestFactory.createWithGroups(group1); @@ -204,9 +218,10 @@ class UserResourceMapperTest { @Test void shouldMapOrganisationsEinheitIdsFromGroups() { - var userResource = UserResourceTestFactory.createWithGroups(group1, group2); + var userResource = UserResourceTestFactory.createWithGroups(group1, group2, group3); when(realm.getGroupByPath(GROUP_1_PATH)).thenReturn(group1); when(realm.getGroupByPath(GROUP_2_PATH)).thenReturn(group2); + when(realm.getGroupByPath(GROUP_3_PATH)).thenReturn(group3); var result = mapper.mapOrganisationsEinheitIds(userResource);