Select Git revision
UserResourceMapperTest.java
-
OZGCloud authored
https://git.ozg-sh.de/mgm/user-manager into OZG-2653_Usersynchronisation
OZGCloud authoredhttps://git.ozg-sh.de/mgm/user-manager into OZG-2653_Usersynchronisation
UserResourceMapperTest.java 7.13 KiB
package de.itvsh.kop.user;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.keycloak.admin.client.resource.RealmResource;
import org.keycloak.admin.client.resource.RoleMappingResource;
import org.keycloak.admin.client.resource.RoleScopeResource;
import org.keycloak.admin.client.resource.UserResource;
import org.keycloak.representations.idm.ClientMappingsRepresentation;
import org.keycloak.representations.idm.GroupRepresentation;
import org.keycloak.representations.idm.MappingsRepresentation;
import org.keycloak.representations.idm.RoleRepresentation;
import org.mapstruct.factory.Mappers;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import de.itvsh.kop.user.keycloak.KeycloakApiProperties;
class UserResourceMapperTest {
static final String ORGANISATIONS_EINHEIT_ID_KEY = "organisationseinheitId";
static final String ORGANISATIONS_EINHEIT_ID_1 = "0815";
static final String ORGANISATIONS_EINHEIT_ID_2 = "4711";
static final String GROUP_1_PATH = "/group1";
static final String GROUP_2_PATH = "/group2";
static final Map<String, List<String>> ATTRIBUTES_1 = Map.of(ORGANISATIONS_EINHEIT_ID_KEY, List.of(ORGANISATIONS_EINHEIT_ID_1));
static final Map<String, List<String>> ATTRIBUTES_2 = Map.of(ORGANISATIONS_EINHEIT_ID_KEY, List.of(ORGANISATIONS_EINHEIT_ID_2));
@InjectMocks
private UserResourceMapper mapper = Mappers.getMapper(UserResourceMapper.class);
@Mock
private KeycloakApiProperties properties;
@Mock
private RealmResource realm;
@Nested
class TestMapping {
@BeforeEach
void init() {
when(properties.ldapIdKey()).thenReturn("LDAP_ID");
when(properties.organisationsEinheitIdKey()).thenReturn("organisationseinheitId");
when(properties.client()).thenReturn("sh-kiel-dev-goofy");
when(realm.getGroupByPath(GROUP_1_PATH))
.thenReturn(GroupRepresentationTestFactory.createByPathAndOrganisationEinheitId(GROUP_1_PATH, ORGANISATIONS_EINHEIT_ID_1));
when(properties.ldapIdKey()).thenReturn("LDAP_ID");
when(properties.organisationsEinheitIdKey()).thenReturn("organisationseinheitId");
when(properties.client()).thenReturn("sh-kiel-dev-goofy");
}
@Test
void shouldMapToUser() {
User user = mapper.toKopUser(UserResourceTestFactory.create());
assertThat(user).isNotNull();
}
@Test
void shouldMapEmail() {