Skip to content

Commit 92a2ea5

Browse files
committed
feat: presigned url 이미지 업로드 방식 추가
- presigned 이미지 업로드 방식 구현 - 테스트및 검증완료
1 parent 4a985d1 commit 92a2ea5

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

src/main/java/com/somemore/global/imageupload/service/ImageUploadService.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,9 @@ public class ImageUploadService implements ImageUploadUseCase {
3737
@Value("${default.image.url}")
3838
private String defaultImageUrl;
3939

40-
public static final String DEFAULT_IMAGE_URL;
40+
public static final String DEFAULT_IMAGE_URL = "";
4141
private static final Duration GET_URL_EXPIRATION_DURATION = Duration.ofMinutes(3);
4242

43-
static {
44-
DEFAULT_IMAGE_URL = "your-default-image-url"; // defaultImageUrl 값을 설정
45-
}
4643

4744
@Override
4845
public String getPresignedUrl(String filename) {

src/test/java/com/somemore/global/imageupload/service/ImageUploadServiceTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ void testUploadImage_success() {
7979
@DisplayName("이미지 형식이 올바르지 않다면 업로드 할 수 없다.")
8080
@Test
8181
void testUploadImage_failure() throws IOException {
82+
8283
// given
8384
when(multipartFile.getInputStream()).thenThrow(new IOException());
8485

@@ -91,6 +92,7 @@ void testUploadImage_failure() throws IOException {
9192
@DisplayName("이미지 파일이 없다면 기본 이미지 링크를 반환한다.")
9293
@Test
9394
void uploadImageWithEmptyFile() {
95+
9496
// given
9597
MultipartFile emptyFile = new MockMultipartFile("file", new byte[0]);
9698
given(imageUploadValidator.isEmptyFile(emptyFile)).willReturn(true);
@@ -106,13 +108,12 @@ void uploadImageWithEmptyFile() {
106108
@DisplayName("유효한 파일명으로 사전 서명된 URL을 생성할 수 있다.")
107109
@Test
108110
void getPresignedUrl_success() {
111+
109112
// given
110113
String filename = "testImage.jpg";
111114

112-
// Mock the validator to return false (file name is valid)
113115
when(imageUploadValidator.isEmptyFileName(filename)).thenReturn(false);
114116

115-
// Mock the S3Presigner to return a URL
116117
S3Presigner mockPresigner = mock(S3Presigner.class);
117118
ReflectionTestUtils.setField(imageUploadService, "s3Presigner", mockPresigner);
118119

@@ -131,7 +132,6 @@ void getPresignedUrl_success() {
131132
assertTrue(presignedUrl.startsWith("https://test-bucket.s3.amazonaws.com/"));
132133
assertTrue(presignedUrl.endsWith(".jpg"));
133134

134-
// Verify interactions
135135
verify(imageUploadValidator, times(1)).isEmptyFileName(filename);
136136
verify(mockPresigner, times(1)).presignGetObject(any(GetObjectPresignRequest.class));
137137
}
@@ -151,7 +151,6 @@ void getPresignedUrl_invalidFileName() {
151151
// then
152152
assertNull(presignedUrl);
153153

154-
// Verify interactions
155154
verify(imageUploadValidator, times(1)).isEmptyFileName(filename);
156155
}
157156
}

0 commit comments

Comments
 (0)