Skip to content
Snippets Groups Projects
Select Git revision
  • cbd6057fdda03f4e7c63e08cb55ce0d9957637f0
  • main default protected
  • release
  • OZG-7856_schadcode_scanner
  • ci-pipeline
  • OZG-7526-signatur-nicht-uebernommen
  • OZG-6223-zip-download-bug
  • OZG-7367-tooltip-extension
  • OZG-7023-OZG-6956-E2E-externe-Stellen
  • OZG-6238-npm-durch-pnpm-ersetzen
  • release-admin
  • release-info
  • OZG-6700-admin-feature-toggle
  • E2E-Updates
  • OZG-7047-tooltips
  • OZG-6957-e2e-fachstellen-oe-daten
  • OZG-7006-ZuarbeitAnfragen
  • temp_OZG-7027
  • unit-tests-hotfix
  • OZG-6731-POC-keycloakResourceService-with-multiple-stateResources
  • e2e-add-zufi-version
  • 2.26.0
  • 2.25.0
  • 2.24.2
  • 2.24.1
  • 2.24.0
  • 2.23.0
  • 2.22.0
  • 2.21.0
  • 2.20.0
  • 2.21.0-SNAPSHOT
  • 2.19.0
  • 2.18.0
  • 2.17.1
  • 1.3.0
  • release-admin-1.3.0
  • release-info-1.3.0
  • 2.17.0
  • 2.16.0
  • 2.15.0
  • release-admin-1.1.0
41 results

environment.service.ts

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));
    		}
    	}
    }