Skip to content

Commit a78b0e2

Browse files
authored
fix: Application startup error (#29)
1 parent 2308b15 commit a78b0e2

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/main/java/it/gov/pagopa/pu/fileshare/service/export/ExportFileFacadeServiceImpl.java

+7
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@
1212
import it.gov.pagopa.pu.p4paprocessexecutions.dto.generated.ExportFile;
1313
import java.io.InputStream;
1414
import java.nio.file.Path;
15+
16+
import org.apache.commons.lang3.StringUtils;
1517
import org.springframework.core.io.InputStreamResource;
18+
import org.springframework.stereotype.Service;
1619

20+
@Service
1721
public class ExportFileFacadeServiceImpl implements ExportFileFacadeService {
1822
private final UserAuthorizationService userAuthorizationService;
1923
private final FileStorerService fileStorerService;
@@ -61,6 +65,9 @@ public FileResourceDTO downloadExportFile(Long organizationId,
6165
}
6266

6367
private Path getFilePath(ExportFile exportFile) {
68+
if(StringUtils.isEmpty(exportFile.getFilePathName())){
69+
throw new FileNotFoundException("ExportFile not ready");
70+
}
6471
Path organizationBasePath = fileStorerService.buildOrganizationBasePath(
6572
exportFile.getOrganizationId());
6673

src/test/java/it/gov/pagopa/pu/fileshare/service/export/ExportFileFacadeServiceImplTest.java

+26
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,30 @@ void givenExportFileNotFoundWhenDownloadExportFileThenThrowException() {
185185
Mockito.verify(userAuthorizationServiceMock).checkUserAuthorization(organizationId, user, accessToken);
186186
}
187187

188+
@Test
189+
void givenExportFileNotReadyWhenDownloadExportFileThenThrowException() {
190+
String accessToken = "TOKEN";
191+
Long organizationId = 1L;
192+
Long exportFileId = 10L;
193+
194+
UserOrganizationRoles userTestRole = new UserOrganizationRoles();
195+
userTestRole.setRoles(List.of("TEST", "ADMIN"));
196+
userTestRole.setOrganizationId(organizationId);
197+
UserInfo user = new UserInfo();
198+
user.setOrganizations(List.of(userTestRole));
199+
user.setMappedExternalUserId("TEST");
200+
201+
ExportFile exportFile = new ExportFile();
202+
exportFile.setOrganizationId(organizationId);
203+
exportFile.setStatus(ExportFile.StatusEnum.REQUESTED);
204+
exportFile.setOperatorExternalId("TEST");
205+
206+
Mockito.when(exportFileServiceMock.getExportFile(exportFileId, accessToken)).thenReturn(exportFile);
207+
208+
Executable exec = () -> exportFileService.downloadExportFile(organizationId, exportFileId, user, accessToken);
209+
210+
Assertions.assertThrows(FileNotFoundException.class, exec);
211+
Mockito.verify(userAuthorizationServiceMock).checkUserAuthorization(organizationId, user, accessToken);
212+
}
213+
188214
}

0 commit comments

Comments
 (0)