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

OZG-6867 Throw exception instead of logging a warning

parent 555f0ea5
No related branches found
No related tags found
No related merge requests found
...@@ -44,7 +44,7 @@ abstract class GroupMapper { ...@@ -44,7 +44,7 @@ abstract class GroupMapper {
return null; return null;
} }
if (values.size() > 1 && values.stream().distinct().count() > 1) { if (values.size() > 1 && values.stream().distinct().count() > 1) {
LOG.warn("Group contains multiple values for {}. The first one is taken.", keycloakApiProperties.getOrganisationsEinheitIdKey()); throw new GroupRepresentationMappingException("Group contains multiple values for organisationsEinheitId: %s".formatted(values));
} }
return values.getFirst(); return values.getFirst();
} }
......
package de.ozgcloud.admin.keycloak;
public class GroupRepresentationMappingException extends RuntimeException {
public GroupRepresentationMappingException(String message) {
super(message);
}
}
...@@ -235,14 +235,14 @@ class GroupMapperTest { ...@@ -235,14 +235,14 @@ class GroupMapperTest {
} }
@Test @Test
void shouldReturnFirstValueIfMultipleAreAvailable() { void shouldThrowExceptionIfMultipleValuesAreAvailable() {
givenOrganisationsEinheitIdProperty(); givenOrganisationsEinheitIdProperty();
var value = GroupRepresentationTestFactory.ORGANISATIONS_EINHEIT_ID; var value = GroupRepresentationTestFactory.ORGANISATIONS_EINHEIT_ID;
var value2 = UUID.randomUUID().toString(); var value2 = UUID.randomUUID().toString();
var result = mapper.getOrganisationsEinheitId(Map.of(ORGANIZATIONS_EINHEIT_ID_ATTRIBUTE, List.of(value, value2))); assertThatExceptionOfType(GroupRepresentationMappingException.class)
.isThrownBy(() -> mapper.getOrganisationsEinheitId(Map.of(ORGANIZATIONS_EINHEIT_ID_ATTRIBUTE, List.of(value, value2))))
assertThat(result).isEqualTo(value); .withMessage("Group contains multiple values for organisationsEinheitId: %s", List.of(value, value2));
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment