Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS has been phased out. To see alternatives please check here

Skip to content
Snippets Groups Projects
Commit 5d0e7c68 authored by Marco Amoia's avatar Marco Amoia
Browse files

Merge branch 'release' into 'main'

Release 1.3.0

See merge request !118
parents c1c04afa ffb1a109
No related branches found
No related tags found
2 merge requests!119Update 1.4.0-RC,!118Release 1.3.0
Pipeline #290499 passed with warnings
Showing
with 342 additions and 85 deletions
......@@ -14,3 +14,7 @@ data:
{{- with ((.Values.databaseSeeding).securityAttributeProviderMapping).filePath }}
DATABASESEEDING_SECURITYATTRIBUTEPROVIDERMAPPING_FILEPATH: "{{ . }}"
{{- end }}
{{- if .Values.devMode }}
LOGGING_CONFIG: classpath:log4j2-local.xml
{{- end }}
\ No newline at end of file
......@@ -123,3 +123,5 @@ microservices:
# securityAttributeProviderMapping:
# enabled: true
# filePath: classpath:db.seeding/identityAttributes.default.json
devMode: false
\ No newline at end of file
......@@ -6,7 +6,7 @@ info:
name: European Union Public License (EUPL) 1.2
url: https://interoperable-europe.ec.europa.eu/sites/default/files/custom-page/attachment/eupl_v1.2_en.pdf
title: Security Attributes Provider OpenAPI definition
version: 1.2.0
version: 1.3.0
servers:
- description: securityattributesprovider
url: /v1
......
PROJECT_VERSION_NUMBER="1.2.0"
PROJECT_VERSION_NUMBER="1.3.0"
......@@ -5,12 +5,12 @@
<parent>
<groupId>eu.europa.ec.simpl</groupId>
<artifactId>simpl-parent</artifactId>
<version>1.2.0</version>
<version>1.3.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<artifactId>security-attributes-provider</artifactId>
<version>1.2.0</version>
<version>1.3.0</version>
<name>Security Attributes Provider</name>
<description>Security Attributes Provider Microservice for SIMPL project</description>
......@@ -94,6 +94,10 @@
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<arguments>--add-opens java.base/java.time=ALL-UNNAMED</arguments>
<excludeInfoProperties>
<excludeInfoProperty>group</excludeInfoProperty>
<excludeInfoProperty>artifact</excludeInfoProperty>
</excludeInfoProperties>
</configuration>
<executions>
<execution>
......
sonar.coverage.exclusions=**/test/**/*.*,\
**/controllers/**/*.*,\
**/dto/**/*.*,\
**/exceptions/**/*.*,\
**/mappers/**/*.*,\
**/repositories/**/*.*,\
**/liquibase/*/pojo/*.*
\ No newline at end of file
package eu.europa.ec.simpl.securityattributesprovider.configurations;
import eu.europa.ec.simpl.api.onboarding.v1.exchanges.ParticipantTypesApi;
import eu.europa.ec.simpl.common.argumentresolvers.PageableArgumentResolver;
import eu.europa.ec.simpl.common.argumentresolvers.QueryParamsArgumentResolver;
import eu.europa.ec.simpl.common.exchanges.identityprovider.IdentityProviderParticipantExchange;
import eu.europa.ec.simpl.common.exchanges.onboarding.ParticipantTypeExchange;
import java.net.URI;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestClient;
......@@ -11,13 +13,12 @@ import org.springframework.web.client.support.RestClientAdapter;
import org.springframework.web.service.invoker.HttpServiceProxyFactory;
@Configuration
@RequiredArgsConstructor
public class ClientConfig {
private final MicroserviceProperties microserviceProperties;
private static final String V1_PREFIX = "v1";
public ClientConfig(MicroserviceProperties microserviceProperties) {
this.microserviceProperties = microserviceProperties;
}
private final MicroserviceProperties microserviceProperties;
@Bean
public IdentityProviderParticipantExchange identityProviderParticipantExchange(
......@@ -29,12 +30,14 @@ public class ClientConfig {
}
@Bean
public ParticipantTypeExchange participantTypeExchange(RestClient.Builder restClientBuilder) {
public ParticipantTypesApi participantTypeExchange(RestClient.Builder restClientBuilder) {
return buildExchange(
microserviceProperties.onboarding().url(), restClientBuilder, ParticipantTypeExchange.class);
microserviceProperties.onboarding().url().resolve(V1_PREFIX),
restClientBuilder,
ParticipantTypesApi.class);
}
private <E> E buildExchange(String baseurl, RestClient.Builder restClientBuilder, Class<E> clazz) {
private <E> E buildExchange(URI baseurl, RestClient.Builder restClientBuilder, Class<E> clazz) {
var restClient = restClientBuilder.baseUrl(baseurl).build();
var adapter = RestClientAdapter.create(restClient);
var factory = HttpServiceProxyFactory.builderFor(adapter)
......
package eu.europa.ec.simpl.securityattributesprovider.configurations;
import jakarta.validation.constraints.NotNull;
import java.net.URI;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.validation.annotation.Validated;
@Validated
@ConfigurationProperties(prefix = "microservice")
public record MicroserviceProperties(IdentityProvider identityProvider, Onboarding onboarding) {
public record IdentityProvider(String url) {}
public record IdentityProvider(@NotNull URI url) {}
public record Onboarding(String url) {}
public record Onboarding(@NotNull URI url) {}
}
......@@ -3,7 +3,6 @@ package eu.europa.ec.simpl.securityattributesprovider.controllers;
import eu.europa.ec.simpl.common.exchanges.securityattributeprovider.IdentityAttributeExchange;
import eu.europa.ec.simpl.common.filters.IdentityAttributeFilter;
import eu.europa.ec.simpl.common.model.dto.securityattributesprovider.IdentityAttributeDTO;
import eu.europa.ec.simpl.common.model.validators.UpdateOperation;
import eu.europa.ec.simpl.common.responses.PageResponse;
import eu.europa.ec.simpl.securityattributesprovider.services.IdentityAttributeService;
import java.util.List;
......@@ -12,7 +11,6 @@ import lombok.extern.log4j.Log4j2;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@Log4j2
......@@ -35,8 +33,7 @@ public class IdentityAttributeController implements IdentityAttributeExchange {
}
@Override
public void updateAttributes(
@PathVariable UUID id, @RequestBody @Validated(UpdateOperation.class) IdentityAttributeDTO attribute) {
public void updateAttributes(@PathVariable UUID id, @RequestBody IdentityAttributeDTO attribute) {
attribute.setId(id);
service.update(id, attribute);
}
......
......@@ -4,11 +4,11 @@ import eu.europa.ec.simpl.api.securityattributesprovider.v1.exchanges.IdentityAt
import eu.europa.ec.simpl.api.securityattributesprovider.v1.model.IdentityAttributeDTO;
import eu.europa.ec.simpl.api.securityattributesprovider.v1.model.PageResponseIdentityAttributeDTO;
import eu.europa.ec.simpl.api.securityattributesprovider.v1.model.SearchFilterParameterDTO;
import eu.europa.ec.simpl.common.utils.SortUtil;
import eu.europa.ec.simpl.securityattributesprovider.mappers.IdentityAttributeMapperV1;
import java.util.List;
import java.util.UUID;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......@@ -67,8 +67,7 @@ public class IdentityAttributeControllerV1 implements IdentityAttributesApi {
@Override
public PageResponseIdentityAttributeDTO search(
Integer page, Integer size, List<String> sort, SearchFilterParameterDTO filter) {
return mapper.toV1(controller.search(
mapper.toV0(filter), PageRequest.of(page, size, Sort.by(sort.toArray(String[]::new)))));
return mapper.toV1(controller.search(mapper.toV0(filter), PageRequest.of(page, size, SortUtil.sortBy(sort))));
}
@Override
......
......@@ -61,6 +61,7 @@ public class IdentityAttribute {
@Formula("(select exists(select 1 from participant_identity_attribute pia where pia.identity_attribute_id = id))")
private boolean used;
@ToString.Exclude
@OneToMany(mappedBy = "identityAttribute")
private Set<ParticipantIdentityAttribute> participants = new LinkedHashSet<>();
}
......@@ -3,8 +3,8 @@ package eu.europa.ec.simpl.securityattributesprovider.services;
import eu.europa.ec.simpl.common.filters.IdentityAttributeFilter;
import eu.europa.ec.simpl.common.model.dto.securityattributesprovider.IdentityAttributeDTO;
import eu.europa.ec.simpl.common.model.dto.securityattributesprovider.IdentityAttributeWithOwnershipDTO;
import eu.europa.ec.simpl.common.model.validators.CreateOperation;
import eu.europa.ec.simpl.common.model.validators.UpdateOperation;
import eu.europa.ec.simpl.validation.CreateOperation;
import eu.europa.ec.simpl.validation.UpdateOperation;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import java.util.List;
......@@ -14,6 +14,7 @@ import org.springframework.data.domain.Pageable;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
@Validated
public interface IdentityAttributeService {
@Validated(CreateOperation.class)
IdentityAttributeDTO create(@Valid IdentityAttributeDTO attributeDTO);
......
......@@ -6,8 +6,6 @@ import eu.europa.ec.simpl.common.filters.ParticipantFilter;
import eu.europa.ec.simpl.common.model.dto.identityprovider.ParticipantDTO;
import eu.europa.ec.simpl.common.model.dto.securityattributesprovider.IdentityAttributeDTO;
import eu.europa.ec.simpl.common.model.dto.securityattributesprovider.IdentityAttributeWithOwnershipDTO;
import eu.europa.ec.simpl.common.model.validators.CreateOperation;
import eu.europa.ec.simpl.common.model.validators.UpdateOperation;
import eu.europa.ec.simpl.securityattributesprovider.entities.IdentityAttribute;
import eu.europa.ec.simpl.securityattributesprovider.exceptions.IdentityAttributeAlreadyExistException;
import eu.europa.ec.simpl.securityattributesprovider.exceptions.IdentityAttributeAssignedException;
......@@ -25,12 +23,9 @@ import lombok.extern.log4j.Log4j2;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
@Log4j2
@Service
@Validated
public class IdentityAttributeServiceImpl implements IdentityAttributeService {
private final IdentityAttributeRepository repository;
......@@ -50,7 +45,6 @@ public class IdentityAttributeServiceImpl implements IdentityAttributeService {
}
@Override
@Validated(CreateOperation.class)
public IdentityAttributeDTO create(@Valid IdentityAttributeDTO attributeDTO) {
log.info("create: creating identity attribute [{}]", attributeDTO);
if (repository.existsByCodeOrName(attributeDTO.getCode(), attributeDTO.getName())) {
......@@ -61,8 +55,6 @@ public class IdentityAttributeServiceImpl implements IdentityAttributeService {
}
@Override
@Transactional
@Validated(CreateOperation.class)
public void createBatch(@Valid List<IdentityAttributeDTO> identityAttributes) {
log.info("storing {} identity attributes...", identityAttributes.size());
var saved = doCreate(identityAttributes);
......@@ -93,8 +85,6 @@ public class IdentityAttributeServiceImpl implements IdentityAttributeService {
}
@Override
@Transactional
@Validated(UpdateOperation.class)
public void update(UUID id, @Valid IdentityAttributeDTO attributeDTO) {
log.info("update: updating identity attribute properties [{}]", attributeDTO);
participantTypeService.checkExistingOrThrow(attributeDTO.getParticipantTypes());
......@@ -121,7 +111,6 @@ public class IdentityAttributeServiceImpl implements IdentityAttributeService {
}
@Override
@Transactional
public void updateAssignableParameter(List<UUID> request, boolean value) {
request.stream()
.distinct()
......@@ -151,7 +140,6 @@ public class IdentityAttributeServiceImpl implements IdentityAttributeService {
}
@Override
@Transactional
public void addParticipantType(List<UUID> request, String participantType) {
participantTypeService.checkExistingOrThrow(Set.of(participantType));
......@@ -159,20 +147,17 @@ public class IdentityAttributeServiceImpl implements IdentityAttributeService {
}
@Override
@Transactional
public void unassign(UUID participantId, List<UUID> identityAttributes) {
log.info("ParticipantService.unassign() identity attributes for participant {}", participantId);
repository.unassignIdentityAttribute(participantId, identityAttributes);
}
@Override
@Transactional
public void assign(UUID participantId, List<UUID> identityAttributes) {
log.info("ParticipantService.assign() identity attributes for participant {}", participantId);
repository.assignIdentityAttributes(participantId, identityAttributes.toArray(UUID[]::new));
}
@Transactional
@Override
public void assignLastSnapshot(String participantType, UUID participantId, List<UUID> excludedAttributes) {
var attributesToAssign = repository.retrieveSnapshot(participantType, excludedAttributes);
......
package eu.europa.ec.simpl.securityattributesprovider.services.impl;
import eu.europa.ec.simpl.common.exchanges.onboarding.ParticipantTypeExchange;
import eu.europa.ec.simpl.common.model.dto.onboarding.ParticipantTypeDTO;
import eu.europa.ec.simpl.api.onboarding.v1.exchanges.ParticipantTypesApi;
import eu.europa.ec.simpl.api.onboarding.v1.model.ParticipantTypeDTO;
import eu.europa.ec.simpl.securityattributesprovider.exceptions.ParticipantTypeDoesNotExistException;
import eu.europa.ec.simpl.securityattributesprovider.services.ParticipantTypeService;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;
import lombok.AccessLevel;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;
import org.springframework.stereotype.Service;
@Service
@RequiredArgsConstructor
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
public class ParticipantTypeServiceImpl implements ParticipantTypeService {
private final ParticipantTypeExchange participantTypeExchange;
public ParticipantTypeServiceImpl(ParticipantTypeExchange participantTypeExchange) {
this.participantTypeExchange = participantTypeExchange;
}
ParticipantTypesApi participantTypesApi;
@Override
public void checkExistingOrThrow(@NonNull Set<String> participantTypes) {
......@@ -26,7 +27,7 @@ public class ParticipantTypeServiceImpl implements ParticipantTypeService {
return;
}
var existingParticipantTypes = participantTypeExchange.getParticipantTypes().stream()
var existingParticipantTypes = participantTypesApi.getParticipantTypes().stream()
.map(ParticipantTypeDTO::getValue)
.collect(Collectors.toSet());
......
......@@ -2,8 +2,8 @@ package eu.europa.ec.simpl.securityattributesprovider.services.impl;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.europa.ec.simpl.common.exchanges.onboarding.ParticipantTypeExchange;
import eu.europa.ec.simpl.common.model.dto.onboarding.ParticipantTypeDTO;
import eu.europa.ec.simpl.api.onboarding.v1.exchanges.ParticipantTypesApi;
import eu.europa.ec.simpl.api.onboarding.v1.model.ParticipantTypeDTO;
import eu.europa.ec.simpl.securityattributesprovider.configurations.DBSeedingProperties;
import eu.europa.ec.simpl.securityattributesprovider.dto.SecurityAttributesMappingDTO;
import eu.europa.ec.simpl.securityattributesprovider.exceptions.ParticipantTypeDoesNotExistException;
......@@ -19,35 +19,25 @@ import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;
import lombok.extern.log4j.Log4j2;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Service;
@Log4j2
@Service
@RequiredArgsConstructor
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
public class SecurityAttributeProviderInitializationImpl implements SecurityAttributeProviderInitialization {
private final DBSeedingProperties props;
private final ResourceLoader resourceLoader;
private final Validator validator;
private final IdentityAttributeRepository identityAttributeRepository;
private final IdentityAttributeMapper identityAttributeMapper;
private final ParticipantTypeExchange participantTypeExchange;
public SecurityAttributeProviderInitializationImpl(
DBSeedingProperties props,
ResourceLoader resourceLoader,
Validator validator,
IdentityAttributeRepository identityAttributeRepository,
IdentityAttributeMapper identityAttributeMapper,
ParticipantTypeExchange participantTypeExchange) {
this.props = props;
this.resourceLoader = resourceLoader;
this.validator = validator;
this.identityAttributeRepository = identityAttributeRepository;
this.identityAttributeMapper = identityAttributeMapper;
this.participantTypeExchange = participantTypeExchange;
}
DBSeedingProperties props;
ResourceLoader resourceLoader;
Validator validator;
IdentityAttributeRepository identityAttributeRepository;
IdentityAttributeMapper identityAttributeMapper;
ParticipantTypesApi participantTypesApi;
@PostConstruct
public void init() {
......@@ -73,7 +63,7 @@ public class SecurityAttributeProviderInitializationImpl implements SecurityAttr
private List<String> getParticipantTypesFromOnboarding() {
log.info("Retrieve participantTypes from onboarding microservices");
return participantTypeExchange.getParticipantTypes().stream()
return participantTypesApi.getParticipantTypes().stream()
.map(ParticipantTypeDTO::getValue)
.toList();
}
......
......@@ -7,14 +7,33 @@ spring:
open-in-view: false
hibernate:
ddl-auto: validate
show-sql: true
jackson:
default-property-inclusion: NON_NULL
servlet:
multipart:
max-file-size: 10MB
logging:
level:
sql: debug
http:
enabled: true
excluded:
- method: GET
path: /actuator/health/readiness
- method: GET
path: /actuator/health/liveness
aspect:
component:
enabled: true
level: INFO
controller:
enabled: true
level: INFO
repository:
enabled: true
level: DEBUG
service:
enabled: true
level: INFO
microservice:
identity-provider:
......@@ -28,6 +47,14 @@ management:
enabled: true
build:
enabled: true
endpoints:
web:
exposure:
include: "health,info"
endpoint:
health:
probes:
enabled: true
database-seeding:
securityAttributeProviderMapping:
......
......@@ -15,6 +15,7 @@ import eu.europa.ec.simpl.common.model.dto.securityattributesprovider.IdentityAt
import eu.europa.ec.simpl.common.test.WithMockSecurityContext;
import eu.europa.ec.simpl.securityattributesprovider.services.IdentityAttributeService;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import org.instancio.Instancio;
import org.junit.jupiter.api.BeforeEach;
......@@ -32,6 +33,8 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
@ExtendWith(MockitoExtension.class)
class IdentityAttributeControllerTest {
private static final UUID STATIC_UUID = UUID.fromString("2ecc410a-b1e2-4723-b03b-52bef0ecd2b8");
MockMvc mockMvc;
@Mock
......@@ -127,4 +130,45 @@ class IdentityAttributeControllerTest {
body.stream().map(UUID::toString).toList().containsAll(ids)),
eq(true));
}
@Test
void addParticipantTypeTest() {
var uuids = List.of(STATIC_UUID);
var participantType = "participantType-junit";
identityAttributeController.addParticipantType(uuids, participantType);
verify(identityAttributeService).addParticipantType(uuids, participantType);
}
@Test
void unassignTest() {
var participantId = STATIC_UUID;
var identityAttributes = List.of(STATIC_UUID);
identityAttributeController.unassign(participantId, identityAttributes);
verify(identityAttributeService).unassign(participantId, identityAttributes);
}
@Test
void assignTest() {
var participantId = STATIC_UUID;
var identityAttributes = List.of(STATIC_UUID);
identityAttributeController.assign(participantId, identityAttributes);
verify(identityAttributeService).assign(participantId, identityAttributes);
}
@Test
void assignSnapshotTest() {
var participantType = "participantType-junit";
var participantId = STATIC_UUID;
var excludedAttributes = List.of(STATIC_UUID);
identityAttributeController.assignSnapshot(participantType, participantId, excludedAttributes);
verify(identityAttributeService).assignLastSnapshot(participantType, participantId, excludedAttributes);
}
@Test
void importIdentityAttributesTest() {
var identityAttributeDTO = an(IdentityAttributeDTO.class);
var list = List.of(identityAttributeDTO);
identityAttributeController.importIdentityAttributes(list);
verify(identityAttributeService).createBatch(list);
}
}
package eu.europa.ec.simpl.securityattributesprovider.controllers;
import static eu.europa.ec.simpl.common.test.TestUtil.an;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.verify;
import eu.europa.ec.simpl.api.securityattributesprovider.v1.model.IdentityAttributeDTO;
import eu.europa.ec.simpl.securityattributesprovider.mappers.IdentityAttributeMapperV1Impl;
import eu.europa.ec.simpl.securityattributesprovider.utils.DtoUtils;
import java.util.List;
import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@ExtendWith(SpringExtension.class)
@Import({
IdentityAttributeMapperV1Impl.class,
IdentityAttributeControllerV1.class,
})
public class IdentityAttributeControllerV1Test {
private static final UUID STATIC_UUID = UUID.fromString("2ecc410a-b1e2-4723-b03b-52bef0ecd2b8");
@MockitoBean
private IdentityAttributeController controllerV0;
@Autowired
private IdentityAttributeControllerV1 controllerV1;
@Test
public void addParticipantTypeTest() {
var participantType = "participantType-junit";
var uuids = List.of(STATIC_UUID);
controllerV1.addParticipantType(participantType, uuids);
verify(controllerV0).addParticipantType(uuids, participantType);
}
@Test
public void assignTest() {
var participantId = STATIC_UUID;
var uuids = List.of(STATIC_UUID);
controllerV1.assign(participantId, uuids);
verify(controllerV0).assign(participantId, uuids);
}
@Test
public void assignDeprecatedTest() {
var participantId = STATIC_UUID;
var uuids = List.of(STATIC_UUID);
controllerV1.assignDeprecated(participantId, uuids);
verify(controllerV0).assign(participantId, uuids);
}
@Test
public void assignSnapshotTest() {
var participantType = "participantType-junit";
var participantId = STATIC_UUID;
var uuids = List.of(STATIC_UUID);
controllerV1.assignSnapshot(participantType, participantId, uuids);
verify(controllerV0).assignSnapshot(participantType, participantId, uuids);
}
@Test
public void createTest() {
var identityAttributeDTO = an(IdentityAttributeDTO.class);
var resultV0 = an(eu.europa.ec.simpl.common.model.dto.securityattributesprovider.IdentityAttributeDTO.class);
given(controllerV0.create(argThat(dto -> DtoUtils.jsonCompare(dto, identityAttributeDTO))))
.willReturn(resultV0);
var result = controllerV1.create(identityAttributeDTO);
assertThat(DtoUtils.jsonCompare(resultV0, result)).isTrue();
}
@Test
public void deleteTest() {
var id = STATIC_UUID;
controllerV1.delete(id);
verify(controllerV0).delete(id);
}
@Test
public void findByIdTest() {
var id = STATIC_UUID;
var resultV0 = an(eu.europa.ec.simpl.common.model.dto.securityattributesprovider.IdentityAttributeDTO.class);
given(controllerV0.findById(id)).willReturn(resultV0);
var result = controllerV1.findById(id);
assertThat(DtoUtils.jsonCompare(resultV0, result)).isTrue();
}
@Test
public void importIdentityAttributesTest() {
var identityAttributeDTO = an(IdentityAttributeDTO.class);
var identityAttributeDTOs = List.of(identityAttributeDTO);
controllerV1.importIdentityAttributes(identityAttributeDTOs);
verify(controllerV0).importIdentityAttributes(argThat(dto -> DtoUtils.jsonCompare(dto, identityAttributeDTOs)));
}
@Test
public void unassignTest() {
var participantId = STATIC_UUID;
var uuids = List.of(STATIC_UUID);
controllerV1.unassign(participantId, uuids);
verify(controllerV0).unassign(participantId, uuids);
}
@Test
public void unassignDeprecatedTest() {
var participantId = STATIC_UUID;
var uuids = List.of(STATIC_UUID);
controllerV1.unassignDeprecated(participantId, uuids);
verify(controllerV0).unassign(participantId, uuids);
}
@Test
public void updateAssignableParameterTest() {
var uuids = List.of(STATIC_UUID);
var value = true;
controllerV1.updateAssignableParameter(value, uuids);
verify(controllerV0).updateAssignableParameter(uuids, value);
}
@Test
public void updateAttributesTest() {
var id = STATIC_UUID;
var identityAttributeDTO = an(IdentityAttributeDTO.class);
controllerV1.updateAttributes(id, identityAttributeDTO);
verify(controllerV0).updateAttributes(eq(id), argThat(dto -> DtoUtils.jsonCompare(dto, identityAttributeDTO)));
}
}
package eu.europa.ec.simpl.securityattributesprovider.controllers;
import static eu.europa.ec.simpl.common.test.TestUtil.an;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import eu.europa.ec.simpl.common.model.dto.securityattributesprovider.IdentityAttributeDTO;
import eu.europa.ec.simpl.common.model.dto.securityattributesprovider.IdentityAttributeWithOwnershipDTO;
import eu.europa.ec.simpl.securityattributesprovider.mappers.IdentityAttributeMapperV1Impl;
import eu.europa.ec.simpl.securityattributesprovider.utils.DtoUtils;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@ExtendWith(SpringExtension.class)
@Import({
MtlsControllerV1.class,
IdentityAttributeMapperV1Impl.class,
})
public class MtlsControllerV1Test {
@MockitoBean
private MtlsController controllerV0;
@Autowired
private MtlsControllerV1 controllerV1;
@Test
void getIdentityAttributesByCertificateIdInUriTest() {
var certificateId = "certificateId-junit";
var credentialId = "credentialId-junit";
var identityAttributeDTO = an(IdentityAttributeDTO.class);
var resultV0 = List.of(identityAttributeDTO);
given(controllerV0.getIdentityAttributesByCertificateIdInUri(credentialId))
.willReturn(resultV0);
var result = controllerV1.getIdentityAttributesByCertificateIdInUri(certificateId, credentialId);
assertThat(DtoUtils.jsonCompare(resultV0, result)).isTrue();
}
@Test
void getIdentityAttributesWithOwnershipTest() {
var credentialId = "credentialId-junit";
var identityAttributeWithOwnershipDTO = an(IdentityAttributeWithOwnershipDTO.class);
var resultV0 = List.of(identityAttributeWithOwnershipDTO);
given(controllerV0.getIdentityAttributesWithOwnership(credentialId)).willReturn(resultV0);
var result = controllerV1.getIdentityAttributesWithOwnership(credentialId);
assertThat(DtoUtils.jsonCompare(resultV0, result)).isTrue();
}
}
......@@ -4,11 +4,12 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchException;
import static org.mockito.BDDMockito.*;
import eu.europa.ec.simpl.common.exchanges.onboarding.ParticipantTypeExchange;
import eu.europa.ec.simpl.common.model.dto.onboarding.ParticipantTypeDTO;
import eu.europa.ec.simpl.api.onboarding.v1.exchanges.ParticipantTypesApi;
import eu.europa.ec.simpl.api.onboarding.v1.model.ParticipantTypeDTO;
import eu.europa.ec.simpl.securityattributesprovider.exceptions.ParticipantTypeDoesNotExistException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.instancio.junit.InstancioSource;
import org.junit.jupiter.api.Test;
......@@ -22,17 +23,17 @@ import org.mockito.junit.jupiter.MockitoExtension;
class ParticipantTypeServiceImplTest {
@Mock
ParticipantTypeExchange participantTypeExchange;
ParticipantTypesApi participantTypesApi;
@InjectMocks
ParticipantTypeServiceImpl participantTypeService;
@ParameterizedTest
@InstancioSource
@InstancioSource(samples = 1)
void checkExisting_withExistingOrThrowParticipantTypes_shouldSucceed(
Set<ParticipantTypeDTO> existingParticipantTypes) {
List<ParticipantTypeDTO> existingParticipantTypes) {
// Given
given(participantTypeExchange.getParticipantTypes()).willReturn(existingParticipantTypes);
given(participantTypesApi.getParticipantTypes()).willReturn(existingParticipantTypes);
var givenParticipantTypes = Set.of(existingParticipantTypes.stream()
.map(ParticipantTypeDTO::getValue)
.toList()
......@@ -42,17 +43,17 @@ class ParticipantTypeServiceImplTest {
var ex =
catchException(() -> participantTypeService.checkExistingOrThrow(new HashSet<>(givenParticipantTypes)));
// Then
then(participantTypeExchange).should().getParticipantTypes();
then(participantTypesApi).should().getParticipantTypes();
assertThat(ex).isNull();
}
@ParameterizedTest
@InstancioSource
@InstancioSource(samples = 1)
void checkExisting_withNonExistingOrThrowParticipantTypes_shouldThrow_ParticipantTypeDoesNotExistException(
Set<ParticipantTypeDTO> existingParticipantTypes) {
List<ParticipantTypeDTO> existingParticipantTypes) {
// Given
given(participantTypeExchange.getParticipantTypes()).willReturn(existingParticipantTypes);
given(participantTypesApi.getParticipantTypes()).willReturn(existingParticipantTypes);
var givenParticipantTypes = new ArrayList<>(existingParticipantTypes.stream()
.map(ParticipantTypeDTO::getValue)
.toList());
......@@ -62,7 +63,7 @@ class ParticipantTypeServiceImplTest {
var ex =
catchException(() -> participantTypeService.checkExistingOrThrow(new HashSet<>(givenParticipantTypes)));
// Then
then(participantTypeExchange).should().getParticipantTypes();
then(participantTypesApi).should().getParticipantTypes();
assertThat(ex).isInstanceOf(ParticipantTypeDoesNotExistException.class);
}
......@@ -74,7 +75,7 @@ class ParticipantTypeServiceImplTest {
// Then
assertThat(ex).isNull();
then(participantTypeExchange).shouldHaveNoInteractions();
then(participantTypesApi).shouldHaveNoInteractions();
}
@Test
......@@ -84,6 +85,6 @@ class ParticipantTypeServiceImplTest {
var exception = catchException(() -> participantTypeService.checkExistingOrThrow(null));
// Then
assertThat(exception).isInstanceOf(NullPointerException.class);
then(participantTypeExchange).shouldHaveNoInteractions();
then(participantTypesApi).shouldHaveNoInteractions();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment