Skip to content
Snippets Groups Projects
Select Git revision
  • main default protected
  • release
  • master-interface-proto4
  • ozg-5634-ozgcloud-ingress
  • OZG-3322_connect_to_mongodb_over_tls
  • 2.18.0
  • 2.17.0
  • 2.16.0
  • 2.15.0
  • 2.14.0
  • 2.13.0
  • 2.12.0
  • 2.11.0
  • 2.10.1
  • 2.10.0
  • 2.9.0
  • 2.8.0
  • 2.7.1
  • 2.7.0
  • 2.6.0
  • 2.5.1
  • 2.5.0
  • 2.4.0
  • 2.3.0
  • 2.2.0
25 results

UserResourceMapperTest.java

Blame
  • 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() {