From 8ebd184723b8993d99d93a1c3392355513d1450c Mon Sep 17 00:00:00 2001
From: jgunnCO <135321532+jgunnCO@users.noreply.github.com>
Date: Fri, 24 Nov 2023 11:34:49 +0000
Subject: [PATCH] support generating presigned url on demand (#91)
* support generating presigned url on demand
* cleanup
* fix tests
* add AWS_REGION for tests in CI
---
.github/workflows/feature.yml | 2 +-
pom.xml | 5 ++
.../controllers/SubmissionsController.java | 27 +++++--
...gSignedUrlDTO.java => S3ObjectKeyDTO.java} | 4 +-
.../gap/adminbackend/dtos/UrlDTO.java | 14 ++++
.../dtos/submission/SubmissionExportsDTO.java | 2 +-
.../repositories/GrantExportRepository.java | 4 +-
.../gap/adminbackend/services/S3Service.java | 34 ++++++++
.../services/SubmissionsService.java | 6 +-
.../SubmissionsControllerTest.java | 48 +++++++++---
.../adminbackend/services/S3ServiceTest.java | 77 +++++++++++++++++++
.../services/SubmissionsServiceTest.java | 15 ++--
.../generators/RandomSubmissionGenerator.java | 2 +-
13 files changed, 205 insertions(+), 35 deletions(-)
rename src/main/java/gov/cabinetoffice/gap/adminbackend/dtos/{AddingSignedUrlDTO.java => S3ObjectKeyDTO.java} (74%)
create mode 100644 src/main/java/gov/cabinetoffice/gap/adminbackend/dtos/UrlDTO.java
create mode 100644 src/main/java/gov/cabinetoffice/gap/adminbackend/services/S3Service.java
create mode 100644 src/test/java/gov/cabinetoffice/gap/adminbackend/services/S3ServiceTest.java
diff --git a/.github/workflows/feature.yml b/.github/workflows/feature.yml
index 3e5a8635..ae3fab7d 100644
--- a/.github/workflows/feature.yml
+++ b/.github/workflows/feature.yml
@@ -23,7 +23,7 @@ jobs:
cache: maven
- name: Build with Maven
- run: mvn -B package --file pom.xml
+ run: AWS_REGION="ew-west-2" mvn -B package --file pom.xml
- name: DependencyCheck
uses: dependency-check/Dependency-Check_Action@main
diff --git a/pom.xml b/pom.xml
index 571f1308..1340c9a6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -154,6 +154,11 @@
aws-java-sdk-sqs
1.12.315
+
+ com.amazonaws
+ aws-java-sdk-s3
+ 1.12.310
+
com.fasterxml.jackson.datatype
jackson-datatype-jsr310
diff --git a/src/main/java/gov/cabinetoffice/gap/adminbackend/controllers/SubmissionsController.java b/src/main/java/gov/cabinetoffice/gap/adminbackend/controllers/SubmissionsController.java
index 38ffb76c..abb06d39 100644
--- a/src/main/java/gov/cabinetoffice/gap/adminbackend/controllers/SubmissionsController.java
+++ b/src/main/java/gov/cabinetoffice/gap/adminbackend/controllers/SubmissionsController.java
@@ -1,6 +1,7 @@
package gov.cabinetoffice.gap.adminbackend.controllers;
-import gov.cabinetoffice.gap.adminbackend.dtos.AddingSignedUrlDTO;
+import gov.cabinetoffice.gap.adminbackend.dtos.S3ObjectKeyDTO;
+import gov.cabinetoffice.gap.adminbackend.dtos.UrlDTO;
import gov.cabinetoffice.gap.adminbackend.dtos.submission.LambdaSubmissionDefinition;
import gov.cabinetoffice.gap.adminbackend.dtos.submission.SubmissionExportsDTO;
import gov.cabinetoffice.gap.adminbackend.enums.GrantExportStatus;
@@ -8,6 +9,7 @@
import gov.cabinetoffice.gap.adminbackend.services.FileService;
import gov.cabinetoffice.gap.adminbackend.services.SecretAuthService;
import gov.cabinetoffice.gap.adminbackend.services.SubmissionsService;
+import gov.cabinetoffice.gap.adminbackend.services.S3Service;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
@@ -37,6 +39,8 @@ public class SubmissionsController {
private final SubmissionsService submissionsService;
+ private final S3Service s3Service;
+
private final SecretAuthService secretAuthService;
private final FileService fileService;
@@ -129,20 +133,29 @@ public ResponseEntity updateExportRecordStatus(@PathVariable String batchExportI
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
- @PatchMapping("/{submissionId}/export-batch/{batchExportId}/signedUrl")
- @Operation(summary = "Add AWS signed url to batch export for download")
+ @PostMapping("/signed-url")
+ @Operation(summary = "Get presigned link for S3 object key")
+ public ResponseEntity getPresignedUrl(@RequestBody S3ObjectKeyDTO s3ObjectKeyDTO) {
+ final String objectKey = s3ObjectKeyDTO.getS3ObjectKey();
+ final String presignedUrl = s3Service.generateExportDocSignedUrl(objectKey);
+ return ResponseEntity.ok(new UrlDTO(presignedUrl));
+ }
+
+ @PatchMapping("/{submissionId}/export-batch/{batchExportId}/s3-object-key")
+ @Operation(summary = "Add AWS S3 object key to batch export for download")
@ApiResponses(value = {
- @ApiResponse(responseCode = "204", description = "Successfully added signed url",
+ @ApiResponse(responseCode = "204", description = "Successfully added S3 key",
content = @Content(mediaType = "application/json")),
@ApiResponse(responseCode = "400",
description = "Required path variables and body not provided in expected format",
content = @Content(mediaType = "application/json")),
- @ApiResponse(responseCode = "500", description = "Something went wrong while updating signed url",
+ @ApiResponse(responseCode = "500", description = "Something went wrong while updating S3 key",
content = @Content(mediaType = "application/json")) })
public ResponseEntity updateExportRecordLocation(@PathVariable UUID batchExportId, @PathVariable UUID submissionId,
- @RequestBody AddingSignedUrlDTO signedUrlDTO, @RequestHeader(HttpHeaders.AUTHORIZATION) String authHeader) {
+ @RequestBody S3ObjectKeyDTO s3ObjectKeyDTO, @RequestHeader(HttpHeaders.AUTHORIZATION) String authHeader) {
secretAuthService.authenticateSecret(authHeader);
- submissionsService.addSignedUrlToSubmissionExport(submissionId, batchExportId, signedUrlDTO.getSignedUrl());
+ submissionsService.addS3ObjectKeyToSubmissionExport(submissionId, batchExportId,
+ s3ObjectKeyDTO.getS3ObjectKey());
return ResponseEntity.noContent().build();
}
diff --git a/src/main/java/gov/cabinetoffice/gap/adminbackend/dtos/AddingSignedUrlDTO.java b/src/main/java/gov/cabinetoffice/gap/adminbackend/dtos/S3ObjectKeyDTO.java
similarity index 74%
rename from src/main/java/gov/cabinetoffice/gap/adminbackend/dtos/AddingSignedUrlDTO.java
rename to src/main/java/gov/cabinetoffice/gap/adminbackend/dtos/S3ObjectKeyDTO.java
index 33f89af5..11d04373 100644
--- a/src/main/java/gov/cabinetoffice/gap/adminbackend/dtos/AddingSignedUrlDTO.java
+++ b/src/main/java/gov/cabinetoffice/gap/adminbackend/dtos/S3ObjectKeyDTO.java
@@ -7,8 +7,8 @@
@Data
@AllArgsConstructor
@NoArgsConstructor
-public class AddingSignedUrlDTO {
+public class S3ObjectKeyDTO {
- private String signedUrl;
+ private String s3ObjectKey;
}
diff --git a/src/main/java/gov/cabinetoffice/gap/adminbackend/dtos/UrlDTO.java b/src/main/java/gov/cabinetoffice/gap/adminbackend/dtos/UrlDTO.java
new file mode 100644
index 00000000..91dc615e
--- /dev/null
+++ b/src/main/java/gov/cabinetoffice/gap/adminbackend/dtos/UrlDTO.java
@@ -0,0 +1,14 @@
+package gov.cabinetoffice.gap.adminbackend.dtos;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class UrlDTO {
+
+ private String url;
+
+}
diff --git a/src/main/java/gov/cabinetoffice/gap/adminbackend/dtos/submission/SubmissionExportsDTO.java b/src/main/java/gov/cabinetoffice/gap/adminbackend/dtos/submission/SubmissionExportsDTO.java
index f1e96d16..5a82369e 100644
--- a/src/main/java/gov/cabinetoffice/gap/adminbackend/dtos/submission/SubmissionExportsDTO.java
+++ b/src/main/java/gov/cabinetoffice/gap/adminbackend/dtos/submission/SubmissionExportsDTO.java
@@ -9,6 +9,6 @@ public class SubmissionExportsDTO {
private String label;
- private String url;
+ private String s3key;
}
diff --git a/src/main/java/gov/cabinetoffice/gap/adminbackend/repositories/GrantExportRepository.java b/src/main/java/gov/cabinetoffice/gap/adminbackend/repositories/GrantExportRepository.java
index b2bd3af1..79e21888 100644
--- a/src/main/java/gov/cabinetoffice/gap/adminbackend/repositories/GrantExportRepository.java
+++ b/src/main/java/gov/cabinetoffice/gap/adminbackend/repositories/GrantExportRepository.java
@@ -32,9 +32,9 @@ Integer updateExportRecordStatus(@Param("submissionId") String submissionId,
@Transactional
@Modifying
- @Query("UPDATE GrantExportEntity e SET e.location = :signedUrl WHERE e.id.exportBatchId = :exportBatchId AND e.id.submissionId = :submissionId")
+ @Query("UPDATE GrantExportEntity e SET e.location = :s3ObjectKey WHERE e.id.exportBatchId = :exportBatchId AND e.id.submissionId = :submissionId")
void updateExportRecordLocation(@Param("submissionId") UUID submissionId,
- @Param("exportBatchId") UUID exportBatchId, @Param("signedUrl") String signedUrl);
+ @Param("exportBatchId") UUID exportBatchId, @Param("s3ObjectKey") String s3ObjectKey);
Long countByIdExportBatchIdAndStatusNot(UUID exportGrantId, GrantExportStatus status);
diff --git a/src/main/java/gov/cabinetoffice/gap/adminbackend/services/S3Service.java b/src/main/java/gov/cabinetoffice/gap/adminbackend/services/S3Service.java
new file mode 100644
index 00000000..ec4e6af1
--- /dev/null
+++ b/src/main/java/gov/cabinetoffice/gap/adminbackend/services/S3Service.java
@@ -0,0 +1,34 @@
+package gov.cabinetoffice.gap.adminbackend.services;
+
+import com.amazonaws.HttpMethod;
+import com.amazonaws.services.s3.AmazonS3;
+import com.amazonaws.services.s3.AmazonS3ClientBuilder;
+import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest;
+import lombok.RequiredArgsConstructor;
+import org.springframework.beans.factory.annotation.Value;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+import java.time.Instant;
+import java.util.Date;
+
+@Service
+@RequiredArgsConstructor
+@Slf4j
+public class S3Service {
+
+ @Value("${cloud.aws.s3.submissions-export-bucket-name}")
+ private String attachmentsBucket;
+
+ private final AmazonS3 s3Client = AmazonS3ClientBuilder.defaultClient();
+
+ public String generateExportDocSignedUrl(String objectKey) {
+ int linkTimeoutDuration = 604800;
+ GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(attachmentsBucket,
+ objectKey).withMethod(HttpMethod.GET)
+ .withExpiration(Date.from(Instant.now().plusSeconds(linkTimeoutDuration)));
+
+ return s3Client.generatePresignedUrl(generatePresignedUrlRequest).toExternalForm();
+ }
+
+}
diff --git a/src/main/java/gov/cabinetoffice/gap/adminbackend/services/SubmissionsService.java b/src/main/java/gov/cabinetoffice/gap/adminbackend/services/SubmissionsService.java
index c423e972..7646a76d 100644
--- a/src/main/java/gov/cabinetoffice/gap/adminbackend/services/SubmissionsService.java
+++ b/src/main/java/gov/cabinetoffice/gap/adminbackend/services/SubmissionsService.java
@@ -274,7 +274,7 @@ public List getCompletedSubmissionExportsForBatch(UUID exp
List exports = grantExportRepository.findAllByIdExportBatchIdAndStatusAndCreatedBy(
exportBatchId, GrantExportStatus.COMPLETE, adminSession.getGrantAdminId());
- return exports.stream().map(entity -> SubmissionExportsDTO.builder().url(entity.getLocation())
+ return exports.stream().map(entity -> SubmissionExportsDTO.builder().s3key(entity.getLocation())
.label(getFilenameFromExportsSignedUrl(entity)).build()).toList();
}
@@ -346,8 +346,8 @@ public void updateExportStatus(String submissionId, String batchExportId, GrantE
}
}
- public void addSignedUrlToSubmissionExport(UUID submissionId, UUID exportId, String signedUrl) {
- grantExportRepository.updateExportRecordLocation(submissionId, exportId, signedUrl);
+ public void addS3ObjectKeyToSubmissionExport(UUID submissionId, UUID exportId, String s3ObjectKey) {
+ grantExportRepository.updateExportRecordLocation(submissionId, exportId, s3ObjectKey);
}
}
diff --git a/src/test/java/gov/cabinetoffice/gap/adminbackend/controllers/SubmissionsControllerTest.java b/src/test/java/gov/cabinetoffice/gap/adminbackend/controllers/SubmissionsControllerTest.java
index 934ebd74..6e9cbabd 100644
--- a/src/test/java/gov/cabinetoffice/gap/adminbackend/controllers/SubmissionsControllerTest.java
+++ b/src/test/java/gov/cabinetoffice/gap/adminbackend/controllers/SubmissionsControllerTest.java
@@ -1,6 +1,7 @@
package gov.cabinetoffice.gap.adminbackend.controllers;
-import gov.cabinetoffice.gap.adminbackend.dtos.AddingSignedUrlDTO;
+import gov.cabinetoffice.gap.adminbackend.dtos.S3ObjectKeyDTO;
+import gov.cabinetoffice.gap.adminbackend.dtos.UrlDTO;
import gov.cabinetoffice.gap.adminbackend.dtos.submission.LambdaSubmissionDefinition;
import gov.cabinetoffice.gap.adminbackend.dtos.submission.SubmissionExportsDTO;
import gov.cabinetoffice.gap.adminbackend.enums.GrantExportStatus;
@@ -53,6 +54,9 @@ class SubmissionsControllerTest {
@MockBean
private SubmissionsService submissionsService;
+ @MockBean
+ private S3Service s3Service;
+
@MockBean
private ApplicationFormService applicationFormService;
@@ -282,12 +286,12 @@ void updateExportRecordStatus_UnexpectedErrorOccurred() throws Exception {
@Test
void updateExportRecordLocation_SuccessfullyUpdate() throws Exception {
- AddingSignedUrlDTO mockRequest = new AddingSignedUrlDTO("link_to_aws.com/path/filename.zip");
+ S3ObjectKeyDTO mockRequest = new S3ObjectKeyDTO("link_to_aws.com/path/filename.zip");
- doNothing().when(submissionsService).addSignedUrlToSubmissionExport(any(), any(), anyString());
+ doNothing().when(submissionsService).addS3ObjectKeyToSubmissionExport(any(), any(), anyString());
MvcResult res = mockMvc.perform(
- patch("/submissions/" + UUID.randomUUID() + "/export-batch/" + UUID.randomUUID() + "/signedUrl")
+ patch("/submissions/" + UUID.randomUUID() + "/export-batch/" + UUID.randomUUID() + "/s3-object-key")
.contentType(MediaType.APPLICATION_JSON).content(HelperUtils.asJsonString(mockRequest))
.header(HttpHeaders.AUTHORIZATION, LAMBDA_AUTH_HEADER))
.andExpect(status().isNoContent()).andReturn();
@@ -297,6 +301,28 @@ void updateExportRecordLocation_SuccessfullyUpdate() throws Exception {
}
+ @Nested
+ class getPresignedUrl {
+
+ void getPresignedUrl_HappyPath() throws Exception {
+ doReturn("www.fakeamazon.com/test_file_name").when(s3Service)
+ .generateExportDocSignedUrl("path/filename.zip");
+ S3ObjectKeyDTO mockRequest = new S3ObjectKeyDTO("path/filename.zip");
+ UrlDTO mockResponse = new UrlDTO("www.fakeamazon.com/test_file_name");
+
+ mockMvc.perform(post("/submissions/signed-url").contentType(MediaType.APPLICATION_JSON)
+ .content(HelperUtils.asJsonString(mockRequest))).andExpect(status().isOk())
+ .andExpect(content().json(HelperUtils.asJsonString(mockResponse)));
+ }
+
+ void getPresignedUrl_BadRequest_Body() throws Exception {
+ UrlDTO mockRequest = new UrlDTO("www.doesntmatter.com");
+ mockMvc.perform(post("/submissions/signed-url").contentType(MediaType.APPLICATION_JSON)
+ .content(HelperUtils.asJsonString(mockRequest))).andExpect(status().isBadRequest());
+ }
+
+ }
+
@Nested
class updateExportRecordLocation {
@@ -307,29 +333,29 @@ void beforeEach() {
@Test
void updateExportRecordLocation_BadRequest_PathVariables() throws Exception {
- AddingSignedUrlDTO mockRequest = new AddingSignedUrlDTO("link_to_aws.com/path/filename.zip");
+ S3ObjectKeyDTO mockRequest = new S3ObjectKeyDTO("path/filename.zip");
- mockMvc.perform(patch("/submissions/1234/export-batch/12345/signedUrl")
+ mockMvc.perform(patch("/submissions/1234/export-batch/12345/s3-object-key")
.contentType(MediaType.APPLICATION_JSON).content(HelperUtils.asJsonString(mockRequest))
.header(HttpHeaders.AUTHORIZATION, LAMBDA_AUTH_HEADER)).andExpect(status().isBadRequest());
}
@Test
void updateExportRecordLocation_BadRequest_RequestBody() throws Exception {
- mockMvc.perform(patch("/submissions/1234/export-batch/12345/signedUrl")
+ mockMvc.perform(patch("/submissions/1234/export-batch/12345/s3-object-key")
.contentType(MediaType.APPLICATION_JSON).content("\"link_to_aws.com/path/filename.zip\"")
.header(HttpHeaders.AUTHORIZATION, LAMBDA_AUTH_HEADER)).andExpect(status().isBadRequest());
}
@Test
- void updateExportRecordLocation_UnexpectedErrorOccures() throws Exception {
- AddingSignedUrlDTO mockRequest = new AddingSignedUrlDTO("link_to_aws.com/path/filename.zip");
+ void updateExportRecordLocation_UnexpectedErrorOccurs() throws Exception {
+ S3ObjectKeyDTO mockRequest = new S3ObjectKeyDTO("path/filename.zip");
- doThrow(new RuntimeException()).when(submissionsService).addSignedUrlToSubmissionExport(any(), any(),
+ doThrow(new RuntimeException()).when(submissionsService).addS3ObjectKeyToSubmissionExport(any(), any(),
anyString());
mockMvc.perform(
- patch("/submissions/" + UUID.randomUUID() + "/export-batch/" + UUID.randomUUID() + "/signedUrl")
+ patch("/submissions/" + UUID.randomUUID() + "/export-batch/" + UUID.randomUUID() + "/s3-object-key")
.contentType(MediaType.APPLICATION_JSON).content(HelperUtils.asJsonString(mockRequest))
.header(HttpHeaders.AUTHORIZATION, LAMBDA_AUTH_HEADER))
.andExpect(status().isInternalServerError());
diff --git a/src/test/java/gov/cabinetoffice/gap/adminbackend/services/S3ServiceTest.java b/src/test/java/gov/cabinetoffice/gap/adminbackend/services/S3ServiceTest.java
new file mode 100644
index 00000000..0858e2d9
--- /dev/null
+++ b/src/test/java/gov/cabinetoffice/gap/adminbackend/services/S3ServiceTest.java
@@ -0,0 +1,77 @@
+package gov.cabinetoffice.gap.adminbackend.services;
+
+import com.amazonaws.HttpMethod;
+import com.amazonaws.SdkClientException;
+import com.amazonaws.services.s3.AmazonS3;
+import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.MockedStatic;
+import org.springframework.test.util.ReflectionTestUtils;
+
+import java.net.URL;
+import java.time.Instant;
+import java.util.Date;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.*;
+
+public class S3ServiceTest {
+
+ private static S3Service s3Service;
+
+ private static AmazonS3 mockS3Client;
+
+ ArgumentCaptor presignedUrlRequestCaptor = ArgumentCaptor
+ .forClass(GeneratePresignedUrlRequest.class);
+
+ @BeforeAll
+ static void beforeAll() {
+ s3Service = new S3Service();
+ mockS3Client = mock(AmazonS3.class);
+ ReflectionTestUtils.setField(s3Service, "s3Client", mockS3Client);
+ }
+
+ @BeforeEach
+ void resetMocks() {
+ reset(mockS3Client);
+ }
+
+ @Test
+ void successfullyGenerateExportSignedURL() throws Exception {
+
+ URL mockUrl = new URL("https://mock_url.co.uk/object_path");
+
+ when(mockS3Client.generatePresignedUrl(any())).thenReturn(mockUrl);
+
+ Instant currentInstant = Instant.now();
+ Date mockExpiryDate = Date.from(currentInstant.plusSeconds(604800));
+
+ try (MockedStatic mockedInstant = mockStatic(Date.class)) {
+ mockedInstant.when(() -> Date.from(any())).thenReturn(mockExpiryDate);
+
+ String response = s3Service.generateExportDocSignedUrl("object_path");
+
+ verify(mockS3Client).generatePresignedUrl(presignedUrlRequestCaptor.capture());
+ GeneratePresignedUrlRequest capturedValues = presignedUrlRequestCaptor.getValue();
+
+ assertEquals(mockUrl.toExternalForm(), response);
+ assertEquals(mockExpiryDate, capturedValues.getExpiration());
+ assertEquals(HttpMethod.GET, capturedValues.getMethod());
+
+ }
+
+ }
+
+ @Test
+ void unableToGenerateSignedURL() throws Exception {
+ when(mockS3Client.generatePresignedUrl(any())).thenThrow(SdkClientException.class);
+
+ assertThrows(SdkClientException.class, () -> s3Service.generateExportDocSignedUrl("object_path"));
+ }
+
+}
\ No newline at end of file
diff --git a/src/test/java/gov/cabinetoffice/gap/adminbackend/services/SubmissionsServiceTest.java b/src/test/java/gov/cabinetoffice/gap/adminbackend/services/SubmissionsServiceTest.java
index a8b44f45..10afe7d8 100644
--- a/src/test/java/gov/cabinetoffice/gap/adminbackend/services/SubmissionsServiceTest.java
+++ b/src/test/java/gov/cabinetoffice/gap/adminbackend/services/SubmissionsServiceTest.java
@@ -26,6 +26,7 @@
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
@@ -518,7 +519,7 @@ void getCompletedSubmissionExports() {
assertEquals(mockEntityList.size(), submissionExports.size());
assertEquals("filename.zip", submissionExports.get(0).getLabel());
- assertEquals(urlToTest, submissionExports.get(0).getUrl());
+ assertEquals(urlToTest, submissionExports.get(0).getS3key());
}
@@ -539,7 +540,7 @@ void getCompletedSubmissionExportsWithDecodedLabels() {
assertEquals(mockEntityList.size(), submissionExports.size());
assertEquals("file name.zip", submissionExports.get(0).getLabel());
- assertEquals(urlToTest, submissionExports.get(0).getUrl());
+ assertEquals(urlToTest, submissionExports.get(0).getS3key());
}
@@ -563,7 +564,7 @@ void getLabelFallbackWhenInvalidURLIsFound() {
assertEquals(mockEntityList.size(), submissionExports.size());
assertEquals(submissionId, submissionExports.get(0).getLabel());
- assertEquals(urlToTest, submissionExports.get(0).getUrl());
+ assertEquals(urlToTest, submissionExports.get(0).getS3key());
}
@@ -577,7 +578,7 @@ void getNoCompletedSubmissionExports() {
List submissionExports = submissionsService
.getCompletedSubmissionExportsForBatch(testUUID);
- assertTrue(submissionExports.isEmpty());
+ Assertions.assertTrue(submissionExports.isEmpty());
}
@@ -626,12 +627,12 @@ void successfullyAddSignedUrlToExport() {
doNothing().when(grantExportRepository).updateExportRecordLocation(mockSubmissionId, mockBatchId,
mockLocation);
- submissionsService.addSignedUrlToSubmissionExport(mockSubmissionId, mockBatchId, mockLocation);
+ submissionsService.addS3ObjectKeyToSubmissionExport(mockSubmissionId, mockBatchId, mockLocation);
verify(grantExportRepository).updateExportRecordLocation(mockSubmissionId, mockBatchId, mockLocation);
}
@Test
- void errorOccuresWhileAddingLocation() {
+ void errorOccursWhileAddingLocation() {
UUID mockSubmissionId = UUID.randomUUID();
UUID mockBatchId = UUID.randomUUID();
String mockLocation = "aws_domain.com/path_to/filename.zip";
@@ -639,7 +640,7 @@ void errorOccuresWhileAddingLocation() {
doThrow(new RuntimeException()).when(grantExportRepository).updateExportRecordLocation(mockSubmissionId,
mockBatchId, mockLocation);
- assertThatThrownBy(() -> submissionsService.addSignedUrlToSubmissionExport(mockSubmissionId, mockBatchId,
+ assertThatThrownBy(() -> submissionsService.addS3ObjectKeyToSubmissionExport(mockSubmissionId, mockBatchId,
mockLocation)).isInstanceOf(RuntimeException.class);
}
diff --git a/src/test/java/gov/cabinetoffice/gap/adminbackend/testdata/generators/RandomSubmissionGenerator.java b/src/test/java/gov/cabinetoffice/gap/adminbackend/testdata/generators/RandomSubmissionGenerator.java
index 216d1cca..829c2b98 100644
--- a/src/test/java/gov/cabinetoffice/gap/adminbackend/testdata/generators/RandomSubmissionGenerator.java
+++ b/src/test/java/gov/cabinetoffice/gap/adminbackend/testdata/generators/RandomSubmissionGenerator.java
@@ -70,7 +70,7 @@ public static SubmissionQuestion.SubmissionQuestionBuilder randomSubmissionQuest
}
public static SubmissionExportsDTO.SubmissionExportsDTOBuilder randomSubmissionDTOBuilder() {
- return SubmissionExportsDTO.builder().label("test_file.zip").url("/test/path_to/s3_location/");
+ return SubmissionExportsDTO.builder().label("test_file.zip").s3key("/test/path_to/s3_location/");
}
}