|
10 | 10 | import org.springframework.test.context.junit.jupiter.SpringExtension;
|
11 | 11 | import org.springframework.web.multipart.MultipartFile;
|
12 | 12 |
|
13 |
| -import static org.junit.jupiter.api.Assertions.assertEquals; |
| 13 | +import org.apache.commons.logging.Log; |
| 14 | +import org.apache.commons.logging.LogFactory; |
| 15 | + |
| 16 | +import java.io.File; |
| 17 | +import java.io.IOException; |
| 18 | + |
| 19 | +import static org.junit.jupiter.api.Assertions.*; |
14 | 20 | import static org.mockito.ArgumentMatchers.anyString;
|
| 21 | +import static org.mockito.ArgumentMatchers.eq; |
15 | 22 | import static org.mockito.Mockito.when;
|
16 | 23 |
|
17 | 24 | @ExtendWith(SpringExtension.class)
|
@@ -49,4 +56,32 @@ public void storeHappyPath() {
|
49 | 56 | when(resourceTypeService.getDirectoryForResourceType(anyString())).thenReturn(dir);
|
50 | 57 | storageService.store(resourceType, file, filename);
|
51 | 58 | }
|
| 59 | + |
| 60 | + @Test |
| 61 | + public void isFileExistingHappyPath() throws IOException { |
| 62 | + String resourceType = "testResourceType"; |
| 63 | + String filename = "testFile.txt"; |
| 64 | + String directoryPath = System.getProperty("java.io.tmpdir") + File.separator + "testFiles"; |
| 65 | + |
| 66 | + // Create the directory if it doesn't exist |
| 67 | + File directory = new File(directoryPath); |
| 68 | + directory.mkdirs(); |
| 69 | + |
| 70 | + // Create a temporary file in the specified directory |
| 71 | + File tempFile = new File(directory, filename); |
| 72 | + tempFile.createNewFile(); |
| 73 | + |
| 74 | + when(resourceTypeService.getDirectoryForResourceType(anyString())).thenReturn(directoryPath); |
| 75 | + |
| 76 | + try { |
| 77 | + long result = storageService.isFileExisting(resourceType, filename); |
| 78 | + assertTrue(result > 0); |
| 79 | + } finally { |
| 80 | + // Clean up: Delete the temporary file |
| 81 | + tempFile.delete(); |
| 82 | + |
| 83 | + // Clean up: Delete the temporary directory |
| 84 | + directory.delete(); |
| 85 | + } |
| 86 | + } |
52 | 87 | }
|
0 commit comments