diff --git a/aws-modules/aws-s3-update-object/pom.xml b/aws-modules/aws-s3-update-object/pom.xml
index b44cdb8c6a..574a63977b 100644
--- a/aws-modules/aws-s3-update-object/pom.xml
+++ b/aws-modules/aws-s3-update-object/pom.xml
@@ -2,26 +2,21 @@
4.0.0
-
- org.springframework.boot
- spring-boot-starter-parent
- 3.1.2
-
-
- com.baeldung
aws-s3-update-object
0.0.1-SNAPSHOT
aws-s3-update-object
Project demonstrating overwriting of S3 objects
-
- 17
-
+
+ com.baeldung
+ parent-boot-2
+ 0.0.1-SNAPSHOT
+ ../../parent-boot-2
+
org.springframework.boot
spring-boot-starter-web
-
org.springframework.boot
spring-boot-starter-test
@@ -30,10 +25,9 @@
com.amazonaws
aws-java-sdk
- 1.12.523
+ ${aws-java-sdk-version}
-
@@ -42,5 +36,7 @@
-
+
+ 1.12.523
+
diff --git a/aws-modules/aws-s3-update-object/src/main/java/com/baeldung/awss3updateobject/service/FileService.java b/aws-modules/aws-s3-update-object/src/main/java/com/baeldung/awss3updateobject/service/FileService.java
index 8f3458d060..23eaad7913 100644
--- a/aws-modules/aws-s3-update-object/src/main/java/com/baeldung/awss3updateobject/service/FileService.java
+++ b/aws-modules/aws-s3-update-object/src/main/java/com/baeldung/awss3updateobject/service/FileService.java
@@ -7,13 +7,13 @@ import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.*;
-import jakarta.annotation.PostConstruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
+import javax.annotation.PostConstruct;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
diff --git a/aws-modules/aws-s3-update-object/src/test/java/com/baeldung/awss3updateobject/controller/FileControllerUnitTest.java b/aws-modules/aws-s3-update-object/src/test/java/com/baeldung/awss3updateobject/controller/FileControllerUnitTest.java
index ec2385f62b..823391c139 100644
--- a/aws-modules/aws-s3-update-object/src/test/java/com/baeldung/awss3updateobject/controller/FileControllerUnitTest.java
+++ b/aws-modules/aws-s3-update-object/src/test/java/com/baeldung/awss3updateobject/controller/FileControllerUnitTest.java
@@ -11,6 +11,7 @@ import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.multipart.MultipartFile;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@@ -34,28 +35,28 @@ public class FileControllerUnitTest {
@Test
public void givenValidMultipartFile_whenUploadedViaEndpoint_thenCorrectPathIsReturned() throws Exception {
- MockMultipartFile multipartFile = new MockMultipartFile("multipartFile", "test.txt",
- "text/plain", "test data".getBytes());
+ MockMultipartFile multipartFile = new MockMultipartFile("file", "test.txt", "text/plain", "sample file content".getBytes());
+ String expectedResult = "File Uploaded Successfully";
- when(fileService.uploadFile(any(MultipartFile.class))).thenReturn("/documents/test.txt");
+ when(fileService.uploadFile(multipartFile)).thenReturn(expectedResult);
- mockMvc.perform(multipart("/file/upload").file(multipartFile))
+ mockMvc.perform(multipart("/api/v1/file/upload").file(multipartFile))
.andExpect(status().isOk())
- .andExpect(content().string("/documents/test.txt"));
+ .andExpect(content().string(expectedResult));
}
@Test
public void givenValidMultipartFileAndExistingPath_whenUpdatedViaEndpoint_thenSamePathIsReturned() throws Exception {
- MockMultipartFile multipartFile = new MockMultipartFile("multipartFile", "test.txt",
- "text/plain", "test update data".getBytes());
- String existingFilePath = "/documents/existingFile.txt";
+ MockMultipartFile multipartFile = new MockMultipartFile("file", "test.txt", "text/plain", "updated file content".getBytes());
+ String filePath = "some/path/to/file";
+ String expectedResult = "File Updated Successfully";
- when(fileService.updateFile(any(MultipartFile.class), eq(existingFilePath))).thenReturn(existingFilePath);
+ when(fileService.updateFile(multipartFile, filePath)).thenReturn(expectedResult);
- mockMvc.perform(multipart("/file/update")
+ mockMvc.perform(multipart("/api/v1/file/update")
.file(multipartFile)
- .param("exitingFilePath", existingFilePath))
+ .param("filePath", filePath))
.andExpect(status().isOk())
- .andExpect(content().string(existingFilePath));
+ .andExpect(content().string(expectedResult));
}
}
\ No newline at end of file
diff --git a/aws-modules/aws-s3-update-object/src/test/java/com/baeldung/awss3updateobject/service/FileServiceUnitTest.java b/aws-modules/aws-s3-update-object/src/test/java/com/baeldung/awss3updateobject/service/FileServiceUnitTest.java
index 3ccd41820e..90ed77b148 100644
--- a/aws-modules/aws-s3-update-object/src/test/java/com/baeldung/awss3updateobject/service/FileServiceUnitTest.java
+++ b/aws-modules/aws-s3-update-object/src/test/java/com/baeldung/awss3updateobject/service/FileServiceUnitTest.java
@@ -41,6 +41,7 @@ public class FileServiceUnitTest {
@Test
public void givenValidFile_whenUploaded_thenKeyMatchesDocumentPath() throws Exception {
when(multipartFile.getName()).thenReturn("testFile");
+ when(multipartFile.getOriginalFilename()).thenReturn("testFile");
when(multipartFile.getContentType()).thenReturn("application/pdf");
when(multipartFile.getSize()).thenReturn(1024L);
when(multipartFile.getInputStream()).thenReturn(mock(InputStream.class));
@@ -57,6 +58,7 @@ public class FileServiceUnitTest {
@Test
public void givenValidFile_whenUploadFailsDueToNoBucket_thenExceptionIsThrown() throws Exception {
when(multipartFile.getName()).thenReturn("testFile");
+ when(multipartFile.getOriginalFilename()).thenReturn("testFile");
when(multipartFile.getContentType()).thenReturn("application/pdf");
when(multipartFile.getSize()).thenReturn(1024L);
when(multipartFile.getInputStream()).thenReturn(mock(InputStream.class));
diff --git a/aws-modules/pom.xml b/aws-modules/pom.xml
index 02473815b5..b94faafa86 100644
--- a/aws-modules/pom.xml
+++ b/aws-modules/pom.xml
@@ -19,6 +19,7 @@
aws-miscellaneous
aws-reactive
aws-s3
+ aws-s3-update-object