Skip to content

Commit

Permalink
attempt to fix s3 (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
john-tco authored Jan 24, 2024
1 parent 26f9e8a commit 107a3ac
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.amazonaws.AmazonServiceException;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.model.*;
import gov.cabinetoffice.gap.applybackend.config.properties.S3ConfigProperties;
import gov.cabinetoffice.gap.applybackend.model.Submission;
import gov.cabinetoffice.gap.applybackend.config.S3Config;
import gov.cabinetoffice.gap.applybackend.utils.ZipHelper;
Expand All @@ -25,8 +26,7 @@
@Service
public class ZipService {

@Value("${aws.bucket}")
private String s3Bucket;
private final S3ConfigProperties s3Properties;

private static final Logger logger = LoggerFactory.getLogger(ZipService.class);

Expand Down Expand Up @@ -67,7 +67,7 @@ public ByteArrayOutputStream createSubmissionZip(final Submission submission, fi

public List<String> getSubmissionAttachmentFileNames(final String applicationId,
final String submissionId) {
final ListObjectsV2Request req = new ListObjectsV2Request().withBucketName(s3Bucket)
final ListObjectsV2Request req = new ListObjectsV2Request().withBucketName(s3Properties.getBucket())
.withPrefix(applicationId + "/" + submissionId);
final ListObjectsV2Result listing = client.listObjectsV2(req);
final List<S3ObjectSummary> objectSummaries = listing.getObjectSummaries();
Expand All @@ -93,9 +93,9 @@ private List<S3ObjectSummary> getAllFromPrefix(final List<S3ObjectSummary> objec

private void downloadFile(final String fileName, List<S3Object> list) {
try {
list.add(client.getObject(new GetObjectRequest(s3Bucket, fileName)));
list.add(client.getObject(new GetObjectRequest(s3Properties.getBucket(), fileName)));
} catch (AmazonServiceException e) {
logger.error("Could not download file: " + fileName + " from bucket: " + s3Bucket,
logger.error("Could not download file: " + fileName + " from bucket: " + s3Properties.getBucket(),
e);
throw e;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.model.*;
import gov.cabinetoffice.gap.applybackend.config.properties.S3ConfigProperties;
import gov.cabinetoffice.gap.applybackend.model.*;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import org.odftoolkit.odfdom.doc.OdfTextDocument;
Expand All @@ -26,9 +28,12 @@ public class ZipServiceTest {
@InjectMocks
private ZipService serviceUnderTest;

@Mock
private S3ConfigProperties mockS3ConfigProperties;

@BeforeEach
void beforeEach() {
ReflectionTestUtils.setField(serviceUnderTest, "s3Bucket", "mockedValue");
Mockito.lenient().when(mockS3ConfigProperties.getBucket()).thenReturn("mockedValue");
AmazonS3 s3Client = mock(AmazonS3.class);
S3Object s3Obj = mock(S3Object.class);
Mockito.lenient().when(s3Obj.getKey()).thenReturn("mockKey");
Expand Down

0 comments on commit 107a3ac

Please sign in to comment.