Skip to content
Snippets Groups Projects
Commit fb5d0c65 authored by OZGCloud's avatar OZGCloud
Browse files

Merge pull request 'release-2.10-1' (#136) from release-2.10-1 into master

parents 69cf3208 985066ba
No related branches found
No related tags found
No related merge requests found
......@@ -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);
}
......
......@@ -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;
}
}
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment