Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
ElisKina-dev committed Jan 30, 2025
1 parent 983e098 commit a98c266
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,25 +172,25 @@ 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());

try (MockedStatic<AESUtils> aesUtilsMockedStatic = Mockito.mockStatic(AESUtils.class)) {
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -95,15 +93,15 @@ void givenAuthorizedUserWhenUploadIngestionFlowFileThenOk() {
foldersPathsConfigMock, fileStorerServiceMock, ingestionFlowFileDTOMapperMock, ingestionFlowFileClientMock);
}

/*@Test
@Test
void givenAuthorizedUserWhenDownloadIngestionFlowFileThenReturnFileResource() {
String accessToken = "TOKEN";
Long organizationId = 1L;
Long ingestionFlowFileId = 10L;
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();
Expand All @@ -126,5 +124,5 @@ void givenAuthorizedUserWhenDownloadIngestionFlowFileThenReturnFileResource() {
Mockito.verify(ingestionFlowFileClientMock).getIngestionFlowFile(ingestionFlowFileId, accessToken);
Mockito.verify(fileStorerServiceMock).decryptFile(fullFilePath, fileName);
}
*/

}
1 change: 1 addition & 0 deletions src/test/resources/shared/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add "Encrypted content"

0 comments on commit a98c266

Please sign in to comment.