Skip to content
Snippets Groups Projects
Select Git revision
  • 3b8765b345759a1ad8969c6eb29f7a1ff58ec4f9
  • master default protected
  • dev
  • ckan-2.9
  • refactor-css
  • improve-accessibility
  • fix-get_action-calls
  • summary-collection
  • debug-collections
  • debug-eakte
  • experimental-linked-resources-as-uploads
  • button-text-detail
  • Detailinfo
  • hash
  • URL_Upload
  • URL_Upload_working_BB
  • url_exp
  • ODPSH-550
  • href-for-preview
  • ODPSH-HASH-ALGO
  • Algo
  • v1.61
  • v1.6
  • v1.51
  • v1.5
  • v1.4
  • v1.3
  • v1.2
  • v1.1
  • v1.0
  • v0.1
  • sprint-18
  • sprint11_2
  • sprint10
  • sprint8
  • sprint7
  • sprint6
37 results

action.py

Blame
  • GroupMapperTest.java 3.29 KiB
    package de.ozgcloud.admin.keycloak;
    
    import static org.assertj.core.api.Assertions.*;
    import static org.mockito.Mockito.*;
    
    import java.util.List;
    import java.util.Map;
    import java.util.UUID;
    
    import org.junit.jupiter.api.BeforeEach;
    import org.junit.jupiter.api.Nested;
    import org.junit.jupiter.api.Test;
    import org.keycloak.representations.idm.GroupRepresentation;
    import org.mapstruct.factory.Mappers;
    import org.mockito.Spy;
    
    class GroupMapperTest {
    
    	@Spy
    	private final GroupMapper mapper = Mappers.getMapper(GroupMapper.class);
    
    	@Nested
    	class TestGetOrganisationsEinheitId {
    
    		@Test
    		void shouldReturnNullIfAttributesAreNull() {
    			var result = mapper.getOrganisationsEinheitId(null);
    
    			assertThat(result).isNull();
    		}
    
    		@Test
    		void shouldReturnNullIfAttributeIsAbsent() {
    			var result = mapper.getOrganisationsEinheitId(Map.of("dummy-attribute", List.of("123")));
    
    			assertThat(result).isNull();
    		}
    
    		@Test
    		void shouldReturnOrganisationsEinheitId() {
    			var value = GroupRepresentationTestFactory.ORGANISATIONS_EINHEIT_ID;
    			var result = mapper.getOrganisationsEinheitId(Map.of(GroupMapper.ORGANIZATIONS_EINHEIT_ID_ATTRIBUTE, List.of(value)));
    
    			assertThat(result).isEqualTo(value);
    		}
    
    		@Test
    		void shouldReturnFirstValueIfMultipleAreAvailable() {
    			var value = GroupRepresentationTestFactory.ORGANISATIONS_EINHEIT_ID;
    			var value2 = UUID.randomUUID().toString();
    
    			var result = mapper.getOrganisationsEinheitId(Map.of(GroupMapper.ORGANIZATIONS_EINHEIT_ID_ATTRIBUTE, List.of(value, value2)));
    
    			assertThat(result).isEqualTo(value);
    		}
    	}
    
    	@Nested
    	class TestFromGroupRepresentation {
    
    		private final GroupRepresentation groupRepresentation = GroupRepresentationTestFactory.create();
    
    		@BeforeEach
    		void init() {
    			doReturn(GroupRepresentationTestFactory.ORGANISATIONS_EINHEIT_ID).when(mapper).getOrganisationsEinheitId(groupRepresentation.getAttributes());
    		}
    
    		@Test
    		void shouldGetOrganisationsEinheitId() {
    			callMapper();
    
    			verify(mapper).getOrganisationsEinheitId(groupRepresentation.getAttributes());
    		}
    
    		@Test
    		void shouldSetOrganisationsEinheitId() {
    			var group = callMapper();
    
    			assertThat(group.getOrganisationsEinheitId()).isEqualTo(GroupRepresentationTestFactory.ORGANISATIONS_EINHEIT_ID);
    		}
    
    		@Test
    		void shouldSetName() {
    			var group = callMapper();
    
    			assertThat(group.getName()).isEqualTo(GroupRepresentationTestFactory.NAME);
    		}
    
    		@Test
    		void shouldSetSubGroupsToEmptyList() {
    			var group = callMapper();
    
    			assertThat(group.getSubGroups()).isEmpty();
    		}
    
    		private Group callMapper() {
    			return mapper.fromGroupRepresentation(groupRepresentation);
    		}
    	}
    
    	@Nested
    	class TestFromGroupRepresentations {
    
    		private GroupRepresentation groupRepresentation = GroupRepresentationTestFactory.create();
    		private Group group = GroupTestFactory.createWithEmptySubGroups();
    
    		@BeforeEach
    		void init() {
    			doReturn(group).when(mapper).fromGroupRepresentation(groupRepresentation);
    		}
    
    		@Test
    		void shouldMapFromGroupRepresentation() {
    			callMapper();
    
    			verify(mapper).fromGroupRepresentation(groupRepresentation);
    		}
    
    		@Test
    		void shouldReturnListWithGroupRepresentation() {
    			var groups = callMapper();
    
    			assertThat(groups).containsExactly(group);
    		}
    
    		private List<Group> callMapper() {
    			return mapper.fromGroupRepresentations(List.of(groupRepresentation));
    		}
    	}
    }