Move the code to aws-module (#14622)
* Deep and Shallow copy - code snippets * removed maven files * Ignore mvn files * Removed application test file * Removed .gitIgnore, additional review comments incorporated. * Incorporate review comments * incorporated review comments * https://jira.baeldung.com/browse/BAEL-6827 - Initial Commit * BAEL-6827 - Unit tests * BAEL-6827 - Tests * BAEL-6827 - Minor issue fixes * Removed deep shalow copy project * BAEL-6827 - BDD naming convention * BAEL-6827 - Test classes end with *UnitTest,.java * BAEL-6827 - Move the code to AWS modules * BAEL-6827 - Post Construct annotation issue fix * BAEL-6827 - Updated aws-java-sdk version * Added s3 update object module to parent pom * https://jira.baeldung.com/browse/BAEL-6827 - Unit test failure fixes
This commit is contained in:
parent
a87c1cce8f
commit
c62680becb
|
@ -2,26 +2,21 @@
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<parent>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
|
||||||
<version>3.1.2</version>
|
|
||||||
<relativePath/> <!-- lookup parent from repository -->
|
|
||||||
</parent>
|
|
||||||
<groupId>com.baeldung</groupId>
|
|
||||||
<artifactId>aws-s3-update-object</artifactId>
|
<artifactId>aws-s3-update-object</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
<name>aws-s3-update-object</name>
|
<name>aws-s3-update-object</name>
|
||||||
<description>Project demonstrating overwriting of S3 objects</description>
|
<description>Project demonstrating overwriting of S3 objects</description>
|
||||||
<properties>
|
<parent>
|
||||||
<java.version>17</java.version>
|
<groupId>com.baeldung</groupId>
|
||||||
</properties>
|
<artifactId>parent-boot-2</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<relativePath>../../parent-boot-2</relativePath>
|
||||||
|
</parent>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
@ -30,10 +25,9 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.amazonaws</groupId>
|
<groupId>com.amazonaws</groupId>
|
||||||
<artifactId>aws-java-sdk</artifactId>
|
<artifactId>aws-java-sdk</artifactId>
|
||||||
<version>1.12.523</version>
|
<version>${aws-java-sdk-version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
@ -42,5 +36,7 @@
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
<properties>
|
||||||
|
<aws-java-sdk-version>1.12.523</aws-java-sdk-version>
|
||||||
|
</properties>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -7,13 +7,13 @@ import com.amazonaws.regions.Regions;
|
||||||
import com.amazonaws.services.s3.AmazonS3;
|
import com.amazonaws.services.s3.AmazonS3;
|
||||||
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
|
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
|
||||||
import com.amazonaws.services.s3.model.*;
|
import com.amazonaws.services.s3.model.*;
|
||||||
import jakarta.annotation.PostConstruct;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
|
@ -11,6 +11,7 @@ import org.springframework.test.web.servlet.MockMvc;
|
||||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
@ -34,28 +35,28 @@ public class FileControllerUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenValidMultipartFile_whenUploadedViaEndpoint_thenCorrectPathIsReturned() throws Exception {
|
public void givenValidMultipartFile_whenUploadedViaEndpoint_thenCorrectPathIsReturned() throws Exception {
|
||||||
MockMultipartFile multipartFile = new MockMultipartFile("multipartFile", "test.txt",
|
MockMultipartFile multipartFile = new MockMultipartFile("file", "test.txt", "text/plain", "sample file content".getBytes());
|
||||||
"text/plain", "test data".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(status().isOk())
|
||||||
.andExpect(content().string("/documents/test.txt"));
|
.andExpect(content().string(expectedResult));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenValidMultipartFileAndExistingPath_whenUpdatedViaEndpoint_thenSamePathIsReturned() throws Exception {
|
public void givenValidMultipartFileAndExistingPath_whenUpdatedViaEndpoint_thenSamePathIsReturned() throws Exception {
|
||||||
MockMultipartFile multipartFile = new MockMultipartFile("multipartFile", "test.txt",
|
MockMultipartFile multipartFile = new MockMultipartFile("file", "test.txt", "text/plain", "updated file content".getBytes());
|
||||||
"text/plain", "test update data".getBytes());
|
String filePath = "some/path/to/file";
|
||||||
String existingFilePath = "/documents/existingFile.txt";
|
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)
|
.file(multipartFile)
|
||||||
.param("exitingFilePath", existingFilePath))
|
.param("filePath", filePath))
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
.andExpect(content().string(existingFilePath));
|
.andExpect(content().string(expectedResult));
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -41,6 +41,7 @@ public class FileServiceUnitTest {
|
||||||
@Test
|
@Test
|
||||||
public void givenValidFile_whenUploaded_thenKeyMatchesDocumentPath() throws Exception {
|
public void givenValidFile_whenUploaded_thenKeyMatchesDocumentPath() throws Exception {
|
||||||
when(multipartFile.getName()).thenReturn("testFile");
|
when(multipartFile.getName()).thenReturn("testFile");
|
||||||
|
when(multipartFile.getOriginalFilename()).thenReturn("testFile");
|
||||||
when(multipartFile.getContentType()).thenReturn("application/pdf");
|
when(multipartFile.getContentType()).thenReturn("application/pdf");
|
||||||
when(multipartFile.getSize()).thenReturn(1024L);
|
when(multipartFile.getSize()).thenReturn(1024L);
|
||||||
when(multipartFile.getInputStream()).thenReturn(mock(InputStream.class));
|
when(multipartFile.getInputStream()).thenReturn(mock(InputStream.class));
|
||||||
|
@ -57,6 +58,7 @@ public class FileServiceUnitTest {
|
||||||
@Test
|
@Test
|
||||||
public void givenValidFile_whenUploadFailsDueToNoBucket_thenExceptionIsThrown() throws Exception {
|
public void givenValidFile_whenUploadFailsDueToNoBucket_thenExceptionIsThrown() throws Exception {
|
||||||
when(multipartFile.getName()).thenReturn("testFile");
|
when(multipartFile.getName()).thenReturn("testFile");
|
||||||
|
when(multipartFile.getOriginalFilename()).thenReturn("testFile");
|
||||||
when(multipartFile.getContentType()).thenReturn("application/pdf");
|
when(multipartFile.getContentType()).thenReturn("application/pdf");
|
||||||
when(multipartFile.getSize()).thenReturn(1024L);
|
when(multipartFile.getSize()).thenReturn(1024L);
|
||||||
when(multipartFile.getInputStream()).thenReturn(mock(InputStream.class));
|
when(multipartFile.getInputStream()).thenReturn(mock(InputStream.class));
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
<module>aws-miscellaneous</module>
|
<module>aws-miscellaneous</module>
|
||||||
<module>aws-reactive</module>
|
<module>aws-reactive</module>
|
||||||
<module>aws-s3</module>
|
<module>aws-s3</module>
|
||||||
|
<module>aws-s3-update-object</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
|
Loading…
Reference in New Issue