From a98c2664f88a0027214d4509bf74286971098cb8 Mon Sep 17 00:00:00 2001 From: ElisKina-dev Date: Thu, 30 Jan 2025 16:29:24 +0100 Subject: [PATCH] fix test --- .../pu/fileshare/service/FileStorerServiceTest.java | 10 +++++----- .../ingestion/IngestionFlowFileServiceImplTest.java | 8 +++----- src/test/resources/shared/test.txt | 1 + 3 files changed, 9 insertions(+), 10 deletions(-) create mode 100644 src/test/resources/shared/test.txt diff --git a/src/test/java/it/gov/pagopa/pu/fileshare/service/FileStorerServiceTest.java b/src/test/java/it/gov/pagopa/pu/fileshare/service/FileStorerServiceTest.java index f194195..fee070f 100644 --- a/src/test/java/it/gov/pagopa/pu/fileshare/service/FileStorerServiceTest.java +++ b/src/test/java/it/gov/pagopa/pu/fileshare/service/FileStorerServiceTest.java @@ -172,17 +172,17 @@ void givenInvalidPathWhenSaveToSharedFolderThenInvalidFileException() { @Test void givenExistingFileWhenDecryptFileThenReturnInputStreamResource() throws IOException { - String filePath = "C:/shared/organization"; + /* String filePath = "./shared"; String fileName = "test.txt"; File directory = new File(filePath); File mockFile = new File(directory, fileName); - try (BufferedWriter writer = new BufferedWriter(new FileWriter(mockFile))) { + *//*try (BufferedWriter writer = new BufferedWriter(new FileWriter(mockFile))) { writer.write("Encrypted content"); - } + }*/ - assertTrue(mockFile.exists()); +// assertTrue(mockFile.exists()); InputStream cipherInputStream = new ByteArrayInputStream("Decrypted content".getBytes()); @@ -190,7 +190,7 @@ void givenExistingFileWhenDecryptFileThenReturnInputStreamResource() throws IOEx Mockito.when(AESUtils.decrypt(Mockito.anyString(), Mockito.any(InputStream.class))) .thenReturn(cipherInputStream); - InputStreamResource result = fileStorerService.decryptFile(filePath, fileName); + InputStreamResource result = fileStorerService.decryptFile("src/test/resources/shared", "test.txt"); Assertions.assertNotNull(result); Assertions.assertEquals(cipherInputStream, result.getInputStream()); diff --git a/src/test/java/it/gov/pagopa/pu/fileshare/service/ingestion/IngestionFlowFileServiceImplTest.java b/src/test/java/it/gov/pagopa/pu/fileshare/service/ingestion/IngestionFlowFileServiceImplTest.java index c209f32..4d1e143 100644 --- a/src/test/java/it/gov/pagopa/pu/fileshare/service/ingestion/IngestionFlowFileServiceImplTest.java +++ b/src/test/java/it/gov/pagopa/pu/fileshare/service/ingestion/IngestionFlowFileServiceImplTest.java @@ -21,10 +21,8 @@ import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.core.io.InputStreamResource; -import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.mock.web.MockMultipartFile; -import org.springframework.web.server.ResponseStatusException; import java.io.ByteArrayInputStream; @@ -95,7 +93,7 @@ void givenAuthorizedUserWhenUploadIngestionFlowFileThenOk() { foldersPathsConfigMock, fileStorerServiceMock, ingestionFlowFileDTOMapperMock, ingestionFlowFileClientMock); } - /*@Test + @Test void givenAuthorizedUserWhenDownloadIngestionFlowFileThenReturnFileResource() { String accessToken = "TOKEN"; Long organizationId = 1L; @@ -103,7 +101,7 @@ void givenAuthorizedUserWhenDownloadIngestionFlowFileThenReturnFileResource() { String sharedFolderPath = "/shared"; String filePathName = "examplePath"; String fileName = "testFile.zip"; - String fullFilePath = sharedFolderPath + "/" + organizationId + "/" + filePathName + "/" + fileName; + String fullFilePath = sharedFolderPath + "/" + organizationId + "/" + filePathName + "/" + ARCHIVED_SUB_FOLDER + "/" + fileName; UserInfo user = TestUtils.getSampleUser(); IngestionFlowFile ingestionFlowFile = new IngestionFlowFile(); @@ -126,5 +124,5 @@ void givenAuthorizedUserWhenDownloadIngestionFlowFileThenReturnFileResource() { Mockito.verify(ingestionFlowFileClientMock).getIngestionFlowFile(ingestionFlowFileId, accessToken); Mockito.verify(fileStorerServiceMock).decryptFile(fullFilePath, fileName); } -*/ + } diff --git a/src/test/resources/shared/test.txt b/src/test/resources/shared/test.txt new file mode 100644 index 0000000..c84f1e5 --- /dev/null +++ b/src/test/resources/shared/test.txt @@ -0,0 +1 @@ +add "Encrypted content"