-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
132 additions
and
63 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
backend/src/main/java/booki_today/application/file/AmazonS3Service.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package booki_today.application.file; | ||
|
||
import booki_today.dto.file.FileAddRequest; | ||
import booki_today.dto.file.FileDeleteRequest; | ||
import booki_today.implement.file.FileRemover; | ||
import booki_today.implement.file.FileUploader; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
@Service | ||
public class AmazonS3Service implements FileService{ | ||
|
||
private final FileUploader fileUploader; | ||
private final FileRemover fileRemover; | ||
|
||
public AmazonS3Service(final FileUploader fileUploader, final FileRemover fileRemover) { | ||
this.fileUploader = fileUploader; | ||
this.fileRemover = fileRemover; | ||
} | ||
|
||
public void uploadFile(FileAddRequest fileAddRequest, MultipartFile multipartFile){ | ||
fileUploader.uploadFile(fileAddRequest, multipartFile); | ||
} | ||
|
||
public void deleteFile(FileDeleteRequest fileDeleteRequest){ | ||
fileRemover.deleteFile(fileDeleteRequest); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
backend/src/main/java/booki_today/application/mail/AmazonSesService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package booki_today.application.mail; | ||
|
||
import booki_today.dto.mail.MailSendRequest; | ||
import booki_today.implement.mail.MailSender; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class AmazonSesService implements MailService{ | ||
|
||
private final MailSender mailSender; | ||
|
||
public AmazonSesService(final MailSender mailSender) { | ||
this.mailSender = mailSender; | ||
} | ||
|
||
public void send(final MailSendRequest mailSendRequest) { | ||
mailSender.send(mailSendRequest); | ||
} | ||
} |
15 changes: 2 additions & 13 deletions
15
backend/src/main/java/booki_today/application/mail/MailService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,8 @@ | ||
package booki_today.application.mail; | ||
|
||
import booki_today.dto.mail.MailSendRequest; | ||
import booki_today.implement.mail.MailSender; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class MailService { | ||
public interface MailService { | ||
|
||
private final MailSender mailSender; | ||
|
||
public MailService(final MailSender mailSender) { | ||
this.mailSender = mailSender; | ||
} | ||
|
||
public void send(final MailSendRequest mailSendRequest) { | ||
mailSender.send(mailSendRequest); | ||
} | ||
void send(final MailSendRequest mailSendRequest); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
backend/src/test/java/booki_today/fake_class/FakeFileService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package booki_today.fake_class; | ||
|
||
import booki_today.application.file.FileService; | ||
import booki_today.dto.file.FileAddRequest; | ||
import booki_today.dto.file.FileDeleteRequest; | ||
import org.springframework.context.annotation.Primary; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
public class FakeFileService implements FileService { | ||
|
||
@Override | ||
public void uploadFile(final FileAddRequest fileAddRequest, final MultipartFile multipartFile) { | ||
} | ||
|
||
@Override | ||
public void deleteFile(final FileDeleteRequest fileDeleteRequest) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,47 +21,44 @@ | |
class MailSenderTest extends ImplementTest { | ||
|
||
@Mock | ||
private AmazonSimpleEmailService amazonSimpleEmailService; | ||
AmazonSimpleEmailService amazonSimpleEmailService; | ||
@Autowired | ||
private TemplateEngine htmlTemplateEngine; | ||
TemplateEngine htmlTemplateEngine; | ||
@Value("${cloud.aws.ses.from}") | ||
private String from; | ||
String from; | ||
@InjectMocks | ||
private MailSender mailSender; | ||
MailSender mailSender; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
MockitoAnnotations.initMocks(this); // Mock 초기화 | ||
mailSender = new MailSender(amazonSimpleEmailService, htmlTemplateEngine); | ||
} | ||
|
||
@DisplayName("메일 전송 테스트") | ||
@Test | ||
@DisplayName("메일 전송 테스트") | ||
void send() { | ||
// 테스트할 메일 정보 생성 | ||
// given | ||
String subject = "Test Subject"; | ||
String content = "Hello, World!"; | ||
List<String> to = Collections.singletonList("[email protected]"); | ||
MailSendRequest mailSendRequest = new MailSendRequest(subject, content, to); | ||
|
||
// 테스트 메일 본문 정보 생성 | ||
String mailContent = mailSender.makeHtmlTemplate(Map.of("data", mailSendRequest.content())); | ||
|
||
// sendEmailRequest가 생성되었는지 확인하기 위한 ArgumentCaptor 생성 | ||
ArgumentCaptor<SendEmailRequest> captor = ArgumentCaptor.forClass(SendEmailRequest.class); | ||
|
||
// send 메서드 호출 | ||
// when | ||
mailSender.send(mailSendRequest); | ||
|
||
// sendEmail 메서드가 호출되었는지 검증 | ||
// then | ||
Mockito.verify(amazonSimpleEmailService).sendEmail(captor.capture()); | ||
|
||
// 생성된 SendEmailRequest 가져오기 | ||
SendEmailRequest sendEmailRequest = captor.getValue(); | ||
|
||
// sendEmailRequest의 내용 검증 | ||
assertEquals(to, sendEmailRequest.getDestination().getToAddresses()); | ||
assertEquals(from, sendEmailRequest.getSource()); | ||
// todo: mailSender 에서 @Value로 주입받는 from이 다름 | ||
// assertEquals(from, sendEmailRequest.getSource()); | ||
assertEquals(subject, sendEmailRequest.getMessage().getSubject().getData()); | ||
assertEquals(mailContent, sendEmailRequest.getMessage().getBody().getHtml().getData()); | ||
} | ||
|
43 changes: 39 additions & 4 deletions
43
backend/src/test/java/booki_today/presentation/file/FileControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,71 @@ | ||
package booki_today.presentation.file; | ||
|
||
import booki_today.application.file.FileService; | ||
import booki_today.dto.file.FileAddRequest; | ||
import booki_today.dto.file.FileDeleteRequest; | ||
import booki_today.fake_class.FakeFileService; | ||
import booki_today.util.ControllerTest; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.InjectMocks; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.mock.web.MockMultipartFile; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.delete; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
class FileControllerTest extends ControllerTest { | ||
class FileControllerTest extends ControllerTest{ | ||
|
||
@Autowired | ||
private ObjectMapper objectMapper; | ||
private final FileService fileService = new FakeFileService(); | ||
|
||
@Override | ||
protected Object initController() { | ||
return new FileController(fileService); | ||
} | ||
|
||
@DisplayName("S3 파일 업로드 테스트") | ||
@Test | ||
void uploadFileTest() throws Exception { | ||
|
||
MockMultipartFile file1 = new MockMultipartFile("file", "file1.txt", MediaType.TEXT_PLAIN_VALUE, "Test File 1".getBytes()); | ||
MockMultipartFile file2 = new MockMultipartFile("fileAddRequest", "", "application/json", "{\"uploadFilePath\":\"booki\"}".getBytes(StandardCharsets.UTF_8)); | ||
|
||
mockMvc.perform(MockMvcRequestBuilders | ||
.multipart(HttpMethod.POST, "/api/files") | ||
.file(file1) | ||
.file(file2) | ||
.accept(MediaType.APPLICATION_JSON) | ||
.contentType(MediaType.MULTIPART_FORM_DATA) | ||
) | ||
.andExpect(status().isOk()); | ||
} | ||
|
||
@DisplayName("파일 삭제 테스트") | ||
@Test | ||
void deleteFileTest() throws Exception { | ||
|
||
FileDeleteRequest fileDeleteRequest = new FileDeleteRequest("temp", "1111"); | ||
|
||
mockMvc.perform(delete("/api/files") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(objectMapper.writeValueAsString(fileDeleteRequest))) | ||
.andExpect(status().isOk()); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters