Skip to content

Commit

Permalink
[P4ADEV-1831] updated IngestionFlowFileRequestDTO
Browse files Browse the repository at this point in the history
  • Loading branch information
mscarsel committed Jan 16, 2025
1 parent 770d5ad commit dd96860
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package it.gov.pagopa.pu.fileshare.connector.processexecutions.client;

import it.gov.pagopa.pu.fileshare.connector.processexecutions.config.ProcessExecutionsApisHolder;
import it.gov.pagopa.pu.p4paprocessexecutions.dto.generated.IngestionFlowFileDTO;
import it.gov.pagopa.pu.p4paprocessexecutions.dto.generated.IngestionFlowFileRequestDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.client.HttpClientErrorException;
Expand All @@ -16,9 +16,9 @@ public IngestionFlowFileClient(
this.processExecutionsApisHolder = processExecutionsApisHolder;
}

public IngestionFlowFileDTO createIngestionFlowFile(IngestionFlowFileDTO ingestionFlowFileDTO, String accessToken) {
public void createIngestionFlowFile(IngestionFlowFileRequestDTO ingestionFlowFileDTO, String accessToken) {
try{
return processExecutionsApisHolder.getIngestionFlowFileControllerApi(accessToken).createIngestionFlowFile(ingestionFlowFileDTO);
processExecutionsApisHolder.getIngestionFlowFileControllerApi(accessToken).createIngestionFlowFile(ingestionFlowFileDTO);
} catch (HttpClientErrorException e) {
log.error("Error creating ingestion flow file", e);
throw e;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
package it.gov.pagopa.pu.fileshare.mapper;

import it.gov.pagopa.pu.p4paprocessexecutions.dto.generated.IngestionFlowFileDTO;
import it.gov.pagopa.pu.p4paprocessexecutions.dto.generated.IngestionFlowFileDTO.StatusEnum;
import it.gov.pagopa.pu.fileshare.dto.generated.IngestionFlowFileType;
import it.gov.pagopa.pu.p4paprocessexecutions.dto.generated.IngestionFlowFileRequestDTO;
import it.gov.pagopa.pu.p4paprocessexecutions.dto.generated.IngestionFlowFileRequestDTO.FlowFileTypeEnum;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

@Component
public class IngestionFlowFileDTOMapper {
public IngestionFlowFileDTO mapToIngestionFlowFileDTO(
MultipartFile ingestionFlowFile, Long organizationId, String filePath) {
return IngestionFlowFileDTO.builder()
public IngestionFlowFileRequestDTO mapToIngestionFlowFileDTO(
MultipartFile ingestionFlowFile, IngestionFlowFileType ingestionFlowFileType, Long organizationId, String filePath) {
return IngestionFlowFileRequestDTO.builder()
.organizationId(organizationId)
.status(StatusEnum.UPLOADED)
.filePath(filePath)
.fileName(ingestionFlowFile.getOriginalFilename())
.filePathName(filePath)
.fileName(StringUtils.defaultString(ingestionFlowFile.getOriginalFilename()))
.fileSize(ingestionFlowFile.getSize())
.flowFileType(FlowFileTypeEnum.valueOf(ingestionFlowFileType.toString()))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void uploadIngestionFlowFile(Long organizationId, IngestionFlowFileType i
foldersPathsConfig.getIngestionFlowFilePath(ingestionFlowFileType));
ingestionFlowFileClient.createIngestionFlowFile(
ingestionFlowFileDTOMapper.mapToIngestionFlowFileDTO(ingestionFlowFile,
organizationId, filePath)
ingestionFlowFileType, organizationId, filePath)
, accessToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import it.gov.pagopa.pu.fileshare.connector.processexecutions.config.ProcessExecutionsApisHolder;
import it.gov.pagopa.pu.p4paprocessexecutions.controller.generated.IngestionFlowFileControllerApi;
import it.gov.pagopa.pu.p4paprocessexecutions.dto.generated.IngestionFlowFileDTO;
import it.gov.pagopa.pu.p4paprocessexecutions.dto.generated.IngestionFlowFileRequestDTO;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -40,34 +40,30 @@ void verifyNoMoreInteractions() {
void whenCreateIngestionFlowFileThenOK() {
// Given
String accessToken = "ACCESSTOKEN";
IngestionFlowFileDTO expectedResult = new IngestionFlowFileDTO();
IngestionFlowFileRequestDTO ingestionFlowFileRequestDTO = new IngestionFlowFileRequestDTO();

Mockito.when(processExecutionsApisHolderMock.getIngestionFlowFileControllerApi(accessToken))
.thenReturn(ingestionFlowFileControllerApiMock);
Mockito.when(ingestionFlowFileControllerApiMock.createIngestionFlowFile(expectedResult))
.thenReturn(expectedResult);

// When
IngestionFlowFileDTO result = ingestionFlowFileClient.createIngestionFlowFile(expectedResult, accessToken);
ingestionFlowFileClient.createIngestionFlowFile(ingestionFlowFileRequestDTO, accessToken);

// Then
Assertions.assertSame(expectedResult, result);
Mockito.verify(ingestionFlowFileControllerApiMock).createIngestionFlowFile(ingestionFlowFileRequestDTO);
}

@Test
void givenGenericHttpExceptionWhenCreateIngestionFlowFileThenThrowIt() {
// Given
String accessToken = "ACCESSTOKEN";
HttpClientErrorException expectedException = new HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR);
IngestionFlowFileDTO ingestionFlowFileDTO = new IngestionFlowFileDTO();
IngestionFlowFileRequestDTO ingestionFlowFileRequestDTO = new IngestionFlowFileRequestDTO();

Mockito.when(processExecutionsApisHolderMock.getIngestionFlowFileControllerApi(accessToken))
.thenReturn(ingestionFlowFileControllerApiMock);
Mockito.when(ingestionFlowFileControllerApiMock.createIngestionFlowFile(ingestionFlowFileDTO))
.thenThrow(expectedException);
Mockito.doThrow(expectedException).when(ingestionFlowFileControllerApiMock).createIngestionFlowFile(ingestionFlowFileRequestDTO);

// When
HttpClientErrorException result = Assertions.assertThrows(expectedException.getClass(), () -> ingestionFlowFileClient.createIngestionFlowFile(ingestionFlowFileDTO, accessToken));
HttpClientErrorException result = Assertions.assertThrows(expectedException.getClass(), () -> ingestionFlowFileClient.createIngestionFlowFile(ingestionFlowFileRequestDTO, accessToken));

// Then
Assertions.assertSame(expectedException, result);
Expand All @@ -78,15 +74,14 @@ void givenGenericExceptionWhenCreateIngestionFlowFileThenThrowIt() {
// Given
String accessToken = "ACCESSTOKEN";
RuntimeException expectedException = new RuntimeException();
IngestionFlowFileDTO ingestionFlowFileDTO = new IngestionFlowFileDTO();
IngestionFlowFileRequestDTO ingestionFlowFileRequestDTO = new IngestionFlowFileRequestDTO();

Mockito.when(processExecutionsApisHolderMock.getIngestionFlowFileControllerApi(accessToken))
.thenReturn(ingestionFlowFileControllerApiMock);
Mockito.when(ingestionFlowFileControllerApiMock.createIngestionFlowFile(ingestionFlowFileDTO))
.thenThrow(expectedException);
Mockito.doThrow(expectedException).when(ingestionFlowFileControllerApiMock).createIngestionFlowFile(ingestionFlowFileRequestDTO);

// When
RuntimeException result = Assertions.assertThrows(expectedException.getClass(), () -> ingestionFlowFileClient.createIngestionFlowFile(ingestionFlowFileDTO, accessToken));
RuntimeException result = Assertions.assertThrows(expectedException.getClass(), () -> ingestionFlowFileClient.createIngestionFlowFile(ingestionFlowFileRequestDTO, accessToken));

// Then
Assertions.assertSame(expectedException, result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import it.gov.pagopa.pu.fileshare.connector.BaseApiHolderTest;
import it.gov.pagopa.pu.p4paprocessexecutions.controller.ApiClient;
import it.gov.pagopa.pu.p4paprocessexecutions.dto.generated.IngestionFlowFileDTO;
import it.gov.pagopa.pu.p4paprocessexecutions.dto.generated.IngestionFlowFileRequestDTO;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -41,9 +41,12 @@ void verifyNoMoreInteractions() {
@Test
void whenGetIngestionFlowFileControllerApiThenAuthenticationShouldBeSetInThreadSafeMode() throws InterruptedException {
assertAuthenticationShouldBeSetInThreadSafeMode(
accessToken -> processExecutionsApisHolder.getIngestionFlowFileControllerApi(accessToken)
.createIngestionFlowFile(new IngestionFlowFileDTO()),
IngestionFlowFileDTO.class,
accessToken ->{
processExecutionsApisHolder.getIngestionFlowFileControllerApi(accessToken)
.createIngestionFlowFile(new IngestionFlowFileRequestDTO());
return null;
},
String.class,
processExecutionsApisHolder::unload);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package it.gov.pagopa.pu.fileshare.enums;

import it.gov.pagopa.pu.fileshare.dto.generated.IngestionFlowFileType;
import it.gov.pagopa.pu.p4paprocessexecutions.dto.generated.IngestionFlowFileRequestDTO;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

class IngestionFlowFileTypeEnumTest {
@Test
void testConversion(){
for (IngestionFlowFileType value : IngestionFlowFileType.values()) {
Assertions.assertDoesNotThrow(() -> IngestionFlowFileRequestDTO.FlowFileTypeEnum.valueOf(value.name()));
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import static org.junit.jupiter.api.Assertions.assertEquals;

import it.gov.pagopa.pu.p4paprocessexecutions.dto.generated.IngestionFlowFileDTO;
import it.gov.pagopa.pu.p4paprocessexecutions.dto.generated.IngestionFlowFileDTO.StatusEnum;
import it.gov.pagopa.pu.fileshare.dto.generated.IngestionFlowFileType;
import it.gov.pagopa.pu.p4paprocessexecutions.dto.generated.IngestionFlowFileRequestDTO;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -26,13 +26,14 @@ void whenMapToIngestionFlowFileDTOThenOK(){
"this is a test file".getBytes()
);

IngestionFlowFileDTO result = mapper.mapToIngestionFlowFileDTO(file,organizationId,filePath);
IngestionFlowFileRequestDTO result = mapper.mapToIngestionFlowFileDTO(file,
IngestionFlowFileType.RECEIPT,organizationId,filePath);

Assertions.assertNotNull(result);
assertEquals(organizationId, result.getOrganizationId());
assertEquals(StatusEnum.UPLOADED, result.getStatus());
assertEquals(filePath, result.getFilePath());
assertEquals(filePath, result.getFilePathName());
assertEquals(file.getOriginalFilename(), result.getFileName());
assertEquals(file.getSize(), result.getFileSize());
assertEquals(IngestionFlowFileRequestDTO.FlowFileTypeEnum.RECEIPT, result.getFlowFileType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import it.gov.pagopa.pu.fileshare.service.FileStorerService;
import it.gov.pagopa.pu.fileshare.service.UserAuthorizationService;
import it.gov.pagopa.pu.fileshare.util.TestUtils;
import it.gov.pagopa.pu.p4paprocessexecutions.dto.generated.IngestionFlowFileDTO;
import it.gov.pagopa.pu.p4paprocessexecutions.dto.generated.IngestionFlowFileRequestDTO;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -54,20 +54,21 @@ void givenAuthorizedUserWhenUploadIngestionFlowFileThenOk(){
MediaType.TEXT_PLAIN_VALUE,
"this is a test file".getBytes()
);
IngestionFlowFileDTO ingestionFlowFileDTO = new IngestionFlowFileDTO();
IngestionFlowFileRequestDTO ingestionFlowFileRequestDTO = new IngestionFlowFileRequestDTO();
Mockito.when(foldersPathsConfigMock.getIngestionFlowFilePath(IngestionFlowFileType.RECEIPT))
.thenReturn(receiptFilePath);
Mockito.when(fileStorerServiceMock.saveToSharedFolder(file,receiptFilePath))
.thenReturn(filePath);
Mockito.when(ingestionFlowFileDTOMapperMock.mapToIngestionFlowFileDTO(file,organizationId,filePath))
.thenReturn(ingestionFlowFileDTO);
Mockito.when(ingestionFlowFileDTOMapperMock.mapToIngestionFlowFileDTO(file,
IngestionFlowFileType.RECEIPT,organizationId,filePath))
.thenReturn(ingestionFlowFileRequestDTO);

ingestionFlowFileService.uploadIngestionFlowFile(organizationId, IngestionFlowFileType.RECEIPT,
file, TestUtils.getSampleUser(),accessToken);

Mockito.verify(userAuthorizationServiceMock).checkUserAuthorization(organizationId,TestUtils.getSampleUser(),accessToken);
Mockito.verify(fileServiceMock).validateFile(file,VALID_FILE_EXTENSION);
Mockito.verify(ingestionFlowFileClientMock).createIngestionFlowFile(ingestionFlowFileDTO,accessToken);
Mockito.verify(ingestionFlowFileClientMock).createIngestionFlowFile(ingestionFlowFileRequestDTO,accessToken);
Mockito.verifyNoMoreInteractions(userAuthorizationServiceMock,fileServiceMock,
foldersPathsConfigMock,fileStorerServiceMock,ingestionFlowFileDTOMapperMock,ingestionFlowFileClientMock);
}
Expand Down

0 comments on commit dd96860

Please sign in to comment.