Untitled

 avatar
vas
plain_text
2 months ago
924 B
3
Indexable
@Test
void testDownloadFile_BucketIsEmpty() throws Exception {
    // Mock the return of getSecrets
    JsonNode mockSecrets = new ObjectMapper().readTree(AppTestConstants.JSON_CONTENT);
    when(awsS3ClientBuilderService.createAwsS3Client(anyString(), anyString(), any(Regions.class))).thenReturn(s3Client);

    // Simulate bucketIsEmpty logic by mocking listObjectsV2
    ListObjectsV2Result mockResult = mock(ListObjectsV2Result.class);
    when(mockResult.getObjectSummaries()).thenReturn(Collections.emptyList());
    when(s3Client.listObjectsV2(anyString())).thenReturn(mockResult);

    try {
        fileMgmtService.downloadFile(AppTestConstants.BUCKET, AppTestConstants.FILENAME);
    } catch (FileDownloadException e) {
        assertEquals(AppTestConstants.BUCKET_EMPTY_ERROR_STR, e.getMessage());
    }

    // Verify that the S3 client was shut down
    verify(awsS3ClientBuilderService).shutdown(s3Client);
}
Editor is loading...
Leave a Comment