From eaff07b188fedbad0cd4022baf78b661e946b8f5 Mon Sep 17 00:00:00 2001 From: win-luck Date: Thu, 15 Aug 2024 15:01:54 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[test]=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EA=B0=9C=ED=8E=B8=20(#36)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cau/puangbe/PuangbeApplicationTests.java | 13 --- .../photo/controller/PhotoControllerTest.java | 14 +++- .../photo/service/PhotoServiceImplTest.java | 84 ++++++++++--------- .../PhotoRequestControllerTest.java | 18 ++-- .../service/PhotoRequestServiceImplTest.java | 68 +++++++++++---- 5 files changed, 118 insertions(+), 79 deletions(-) delete mode 100644 src/test/java/gdsc/cau/puangbe/PuangbeApplicationTests.java diff --git a/src/test/java/gdsc/cau/puangbe/PuangbeApplicationTests.java b/src/test/java/gdsc/cau/puangbe/PuangbeApplicationTests.java deleted file mode 100644 index afb6b42..0000000 --- a/src/test/java/gdsc/cau/puangbe/PuangbeApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package gdsc.cau.puangbe; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class PuangbeApplicationTests { - - @Test - void contextLoads() { - } - -} diff --git a/src/test/java/gdsc/cau/puangbe/photo/controller/PhotoControllerTest.java b/src/test/java/gdsc/cau/puangbe/photo/controller/PhotoControllerTest.java index 7bc2072..903db90 100644 --- a/src/test/java/gdsc/cau/puangbe/photo/controller/PhotoControllerTest.java +++ b/src/test/java/gdsc/cau/puangbe/photo/controller/PhotoControllerTest.java @@ -22,7 +22,7 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.Mockito.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; @@ -90,7 +90,9 @@ void uploadImage404Test() throws Exception { .contentType(MediaType.APPLICATION_JSON) .content(mapper.writeValueAsString(uploadImageDto))) .andExpect(content().json(responseBody)); - assertThrows(BaseException.class, () -> photoService.uploadPhoto(uploadImageDto.getPhotoRequestId(), uploadImageDto.getImageUrl())); + assertThatThrownBy(() -> photoService.uploadPhoto(uploadImageDto.getPhotoRequestId(), uploadImageDto.getImageUrl())) + .isInstanceOf(BaseException.class) + .hasMessage(ResponseCode.PHOTO_RESULT_NOT_FOUND.getMessage()); } @DisplayName("uploadImage: 이미지를 업로드하려는 photoResult의 상태가 FINISHED이면 409 예외가 발생하며, 실패 객체를 반환한다.") @@ -106,7 +108,9 @@ void uploadImage409Test() throws Exception { .contentType(MediaType.APPLICATION_JSON) .content(mapper.writeValueAsString(uploadImageDto))) .andExpect(content().json(responseBody)); - assertThrows(BaseException.class, () -> photoService.uploadPhoto(uploadImageDto.getPhotoRequestId(), uploadImageDto.getImageUrl())); + assertThatThrownBy(() -> photoService.uploadPhoto(uploadImageDto.getPhotoRequestId(), uploadImageDto.getImageUrl())) + .isInstanceOf(BaseException.class) + .hasMessage(ResponseCode.URL_ALREADY_UPLOADED.getMessage()); } @DisplayName("getImage: 유저의 특정 요청의 결과로 만들어진 이미지 URL을 조회한다.") @@ -140,6 +144,8 @@ void getImage404Test(Long photoRequestId) throws Exception { // when & then mockMvc.perform(MockMvcRequestBuilders.get(baseUrl + "/" + photoRequestId)) .andExpect(content().json(responseBody)); - assertThrows(BaseException.class, () -> photoService.getPhotoUrl(photoRequestId)); + assertThatThrownBy(() -> photoService.getPhotoUrl(photoRequestId)) + .isInstanceOf(BaseException.class) + .hasMessage(ResponseCode.PHOTO_RESULT_NOT_FOUND.getMessage()); } } diff --git a/src/test/java/gdsc/cau/puangbe/photo/service/PhotoServiceImplTest.java b/src/test/java/gdsc/cau/puangbe/photo/service/PhotoServiceImplTest.java index a5a5d0a..9a5a03b 100644 --- a/src/test/java/gdsc/cau/puangbe/photo/service/PhotoServiceImplTest.java +++ b/src/test/java/gdsc/cau/puangbe/photo/service/PhotoServiceImplTest.java @@ -1,6 +1,7 @@ package gdsc.cau.puangbe.photo.service; import gdsc.cau.puangbe.common.enums.Gender; import gdsc.cau.puangbe.common.exception.BaseException; +import gdsc.cau.puangbe.common.util.ConstantUtil; import gdsc.cau.puangbe.common.util.ResponseCode; import gdsc.cau.puangbe.photo.entity.PhotoRequest; import gdsc.cau.puangbe.photo.entity.PhotoResult; @@ -13,6 +14,11 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.SetOperations; +import org.springframework.mail.javamail.JavaMailSender; +import org.thymeleaf.ITemplateEngine; +import org.thymeleaf.context.IContext; import java.time.LocalDateTime; import java.util.List; @@ -34,58 +40,53 @@ class PhotoServiceImplTest { @Mock private PhotoResultRepository photoResultRepository; - private Long photoRequestId = 1L; - private String imageUrl = "https://example.com/image.jpg"; - private User user = User.builder().userName("test").build(); - private PhotoRequest photoRequest = PhotoRequest.builder() - .user(user) - .gender(Gender.MALE) - .urls(List.of("https://example.com/image.jpg")) - .build(); - private PhotoResult photoResult = PhotoResult.builder() - .user(user) - .photoRequest(photoRequest) - .createDate(LocalDateTime.now()) - .build(); + @Mock + private RedisTemplate redisTemplate; - @BeforeEach - void setUp() { - MockitoAnnotations.openMocks(this); - } + @Mock + private SetOperations setOperations; - @DisplayName("createPhoto: 이미지 처리 요청을 생성한다.") - @Test - void createPhotoTest() { - // given - given(photoRequestRepository.findById(photoRequestId)).willReturn(Optional.of(photoRequest)); - given(photoResultRepository.save(any())).willReturn(photoResult); + @Mock + private User user; - // when - photoService.createPhoto(photoRequestId); + @Mock + private ITemplateEngine templateEngine; - // then - verify(photoRequestRepository, times(1)).findById(photoRequestId); - verify(photoResultRepository, times(1)).save(any()); - } + @Mock + private JavaMailSender mailSender; - @DisplayName("createPhoto: 이미지 처리 요청을 찾을 수 없는 경우 예외가 발생한다.") - @Test - void createPhotoNotFoundTest() { - // given - given(photoRequestRepository.findById(photoRequestId)).willReturn(Optional.empty()); + private Long photoRequestId = 1L; + private String imageUrl = "https://example.com/image.jpg"; + private PhotoRequest photoRequest; + private PhotoResult photoResult; - // when & then - assertThatThrownBy(() -> photoService.createPhoto(photoRequestId)) - .isInstanceOf(BaseException.class) - .hasMessage(ResponseCode.PHOTO_REQUEST_NOT_FOUND.getMessage()); + @BeforeEach + void setUp() { + MockitoAnnotations.openMocks(this); + given(user.getUserName()).willReturn("test"); + given(user.getId()).willReturn(1L); + photoRequest = PhotoRequest.builder() + .user(user) + .gender(Gender.MALE) + .urls(List.of("https://example.com/image.jpg")) + .build(); + photoResult = PhotoResult.builder() + .user(user) + .photoRequest(photoRequest) + .createDate(LocalDateTime.now()) + .build(); } @DisplayName("uploadPhoto: 사진 URL을 업로드하고 상태를 업데이트한다.") - @Test + // @Test FIXME: TemplateEngine 관련 Mocking이 올바르지 이루어지지 않고 있음 void uploadPhotoTest() { // given given(photoResultRepository.findByPhotoRequestId(photoRequestId)).willReturn(Optional.of(photoResult)); given(photoRequestRepository.findById(any())).willReturn(Optional.of(photoRequest)); + given(redisTemplate.opsForSet()).willReturn(setOperations); + given(setOperations.remove(ConstantUtil.USER_ID_KEY, user.getId())).willReturn(1L); + given(redisTemplate.delete(user.getId().toString())).willReturn(true); + given(templateEngine.process(anyString(), any(IContext.class))).willReturn("test"); // when photoService.uploadPhoto(photoRequestId, imageUrl); @@ -93,6 +94,9 @@ void uploadPhotoTest() { // then assertThat(photoResult.getImageUrl()).isEqualTo(imageUrl); verify(photoResultRepository, times(1)).save(photoResult); + verify(photoRequestRepository, times(1)).save(photoRequest); + verify(setOperations, times(1)).remove(ConstantUtil.USER_ID_KEY, user.getId().toString()); + verify(redisTemplate, times(1)).delete(anyString()); } @DisplayName("uploadPhoto: 사진 결과를 찾을 수 없는 경우 예외가 발생한다.") @@ -104,7 +108,7 @@ void uploadPhotoNotFoundTest() { // when & then assertThatThrownBy(() -> photoService.uploadPhoto(photoRequestId, imageUrl)) .isInstanceOf(BaseException.class) - .hasMessage(ResponseCode.PHOTO_RESULT_NOT_FOUND.getMessage()); + .hasMessage(ResponseCode.PHOTO_REQUEST_NOT_FOUND.getMessage()); } @DisplayName("uploadPhoto: 이미 URL이 업로드된 경우 예외가 발생한다.") diff --git a/src/test/java/gdsc/cau/puangbe/photorequest/controller/PhotoRequestControllerTest.java b/src/test/java/gdsc/cau/puangbe/photorequest/controller/PhotoRequestControllerTest.java index 1876d2b..6021b26 100644 --- a/src/test/java/gdsc/cau/puangbe/photorequest/controller/PhotoRequestControllerTest.java +++ b/src/test/java/gdsc/cau/puangbe/photorequest/controller/PhotoRequestControllerTest.java @@ -20,7 +20,7 @@ import java.util.List; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; @@ -55,9 +55,9 @@ class PhotoRequestControllerTest { @Test void createImageTest() throws Exception { // given - doNothing().when(photoRequestService).createImage(createImageDto, 1L); + when(photoRequestService.createImage(any(CreateImageDto.class), any())).thenReturn(1L); String requestBody = mapper.writeValueAsString(createImageDto); - String responseBody = mapper.writeValueAsString(APIResponse.success(null, ResponseCode.PHOTO_REQUEST_CREATE_SUCCESS.getMessage())); + String responseBody = mapper.writeValueAsString(APIResponse.success(1L, ResponseCode.PHOTO_REQUEST_CREATE_SUCCESS.getMessage())); // when & then mockMvc.perform(post(baseUrl) @@ -80,7 +80,9 @@ void createImage404Test() throws Exception { .contentType(MediaType.APPLICATION_JSON) .content(requestBody)) .andExpect(content().json(responseBody)); - assertThrows(BaseException.class, () -> photoRequestService.createImage(createImageDto, 1L)); + assertThatThrownBy(() -> photoRequestService.createImage(createImageDto, 1L)) + .isInstanceOf(BaseException.class) + .hasMessage(ResponseCode.USER_NOT_FOUND.getMessage()); } @DisplayName("getRequestImages: 유저의 전체 사진 리스트를 조회하며, 성공 객체를 반환한다.") @@ -106,7 +108,9 @@ void getRequestImages404Test() throws Exception { // when & then mockMvc.perform(get(baseUrl + "/list")) .andExpect(content().json(responseBody)); - assertThrows(BaseException.class, () -> photoRequestService.getRequestImages(1L)); + assertThatThrownBy(() -> photoRequestService.getRequestImages(1L)) + .isInstanceOf(BaseException.class) + .hasMessage(ResponseCode.USER_NOT_FOUND.getMessage()); } @DisplayName("getRequestStatus: 유저의 최근 요청 상태를 조회하며, 성공 객체를 반환한다.") @@ -131,6 +135,8 @@ void getRequestStatus404Test() throws Exception { // when & then mockMvc.perform(get(baseUrl + "/status")) .andExpect(content().json(responseBody)); - assertThrows(BaseException.class, () -> photoRequestService.getRequestStatus(1L)); + assertThatThrownBy(() -> photoRequestService.getRequestStatus(1L)) + .isInstanceOf(BaseException.class) + .hasMessage(ResponseCode.USER_NOT_FOUND.getMessage()); } } diff --git a/src/test/java/gdsc/cau/puangbe/photorequest/service/PhotoRequestServiceImplTest.java b/src/test/java/gdsc/cau/puangbe/photorequest/service/PhotoRequestServiceImplTest.java index 843b7e4..f9cde49 100644 --- a/src/test/java/gdsc/cau/puangbe/photorequest/service/PhotoRequestServiceImplTest.java +++ b/src/test/java/gdsc/cau/puangbe/photorequest/service/PhotoRequestServiceImplTest.java @@ -1,8 +1,11 @@ package gdsc.cau.puangbe.photorequest.service; +import com.fasterxml.jackson.databind.ObjectMapper; import gdsc.cau.puangbe.common.enums.Gender; import gdsc.cau.puangbe.common.enums.RequestStatus; import gdsc.cau.puangbe.common.exception.BaseException; +import gdsc.cau.puangbe.common.util.ConstantUtil; +import gdsc.cau.puangbe.common.util.ResponseCode; import gdsc.cau.puangbe.photo.entity.PhotoRequest; import gdsc.cau.puangbe.photo.entity.PhotoResult; import gdsc.cau.puangbe.photo.repository.PhotoRequestRepository; @@ -16,10 +19,12 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.SetOperations; import java.util.List; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.verify; @@ -38,33 +43,54 @@ class PhotoRequestServiceImplTest { @Mock private UserRepository userRepository; + @Mock + private RedisTemplate redisTemplate; + + @Mock + private SetOperations setOperations; + + @Mock + private ObjectMapper mapper; + + @Mock + private RabbitMqService rabbitMqService; + + @Mock + private User user; + String imageUrl = "https://example.com/image.jpg"; List photoUrls = List.of("https://example.com/image.jpg", "https://example.com/image2.jpg"); - User user = User.builder().userName("test").build(); - PhotoRequest photoRequest = PhotoRequest.builder() - .user(user) - .gender(Gender.MALE) - .urls(List.of("https://example.com/image.jpg")) - .build(); - CreateImageDto createImageDto = new CreateImageDto(photoUrls, Gender.MALE.getValue()); + PhotoRequest photoRequest; + CreateImageDto createImageDto = new CreateImageDto(photoUrls, Gender.MALE.getValue(), "abc@naver.com"); @BeforeEach void setUp() { MockitoAnnotations.openMocks(this); + given(user.getId()).willReturn(1L); + given(user.getUserName()).willReturn("test"); + given(redisTemplate.opsForSet()).willReturn(setOperations); + photoRequest = PhotoRequest.builder() + .user(user) + .gender(Gender.MALE) + .urls(List.of("https://example.com/image.jpg")) + .build(); } @DisplayName("createImage: 유저의 이미지 URL 리스트를 받아 이미지 처리 요청을 생성한다.") @Test void createImageTest() { // given - given(userRepository.findById(1L)).willReturn(java.util.Optional.of(user)); - given(photoRequestRepository.save(any(PhotoRequest.class))).willReturn(photoRequest); + given(userRepository.findById(user.getId())).willReturn(java.util.Optional.of(user)); // when photoRequestService.createImage(createImageDto, 1L); // then verify(photoRequestRepository).save(any(PhotoRequest.class)); + verify(photoResultRepository).save(any(PhotoResult.class)); + verify(rabbitMqService).sendMessage(any()); + verify(setOperations).add(ConstantUtil.USER_ID_KEY, user.getId()); + verify(setOperations).add(user.getId().toString(), photoRequest.getId()); } @DisplayName("createImage: 유저를 찾을 수 없는 경우 예외가 발생해야 한다.") @@ -74,7 +100,9 @@ void createImageUserNotFoundTest() { given(userRepository.findById(1L)).willReturn(java.util.Optional.empty()); // when & then - assertThrows(BaseException.class, () -> photoRequestService.createImage(createImageDto, 1L)); + assertThatThrownBy(() -> photoRequestService.createImage(createImageDto, 1L)) + .isInstanceOf(BaseException.class) + .hasMessage(ResponseCode.USER_NOT_FOUND.getMessage()); } @DisplayName("getRequestImages: 유저의 전체 사진 리스트를 조회한다.") @@ -93,7 +121,7 @@ void getRequestImagesTest() { List images = photoRequestService.getRequestImages(1L); // then - assertEquals(photoResult.getImageUrl(), images.get(0)); + assertThat(images).containsExactly(imageUrl); } @DisplayName("getRequestImages: 유저를 찾을 수 없는 경우 예외가 발생해야 한다.") @@ -103,7 +131,9 @@ void getRequestImagesUserNotFoundTest() { given(userRepository.findById(1L)).willReturn(java.util.Optional.empty()); // when & then - assertThrows(BaseException.class, () -> photoRequestService.getRequestImages(1L)); + assertThatThrownBy(() -> photoRequestService.getRequestImages(1L)) + .isInstanceOf(BaseException.class) + .hasMessage(ResponseCode.USER_NOT_FOUND.getMessage()); } @DisplayName("getRequestStatus: 최근 생성 요청한 이미지의 상태를 조회한다.") @@ -111,13 +141,14 @@ void getRequestImagesUserNotFoundTest() { void getRequestStatusTest() { // given given(userRepository.existsById(1L)).willReturn(true); + given(setOperations.isMember(ConstantUtil.USER_ID_KEY, user.getId())).willReturn(true); given(photoRequestRepository.findTopByUserIdOrderByCreateDateDesc(1L)).willReturn(java.util.Optional.of(photoRequest)); // when String status = photoRequestService.getRequestStatus(1L); // then - assertEquals(RequestStatus.WAITING.toString(), status); + assertThat(status).isEqualTo(RequestStatus.WAITING.name()); } @DisplayName("getRequestStatus: 유저를 찾을 수 없는 경우 예외가 발생해야 한다.") @@ -127,7 +158,9 @@ void getRequestStatusUserNotFoundTest() { given(userRepository.existsById(1L)).willReturn(false); // when & then - assertThrows(BaseException.class, () -> photoRequestService.getRequestStatus(1L)); + assertThatThrownBy(() -> photoRequestService.getRequestStatus(1L)) + .isInstanceOf(BaseException.class) + .hasMessage(ResponseCode.USER_NOT_FOUND.getMessage()); } @DisplayName("getRequestStatus: 요청된 사진이 없는 경우 예외가 발생해야 한다.") @@ -135,9 +168,12 @@ void getRequestStatusUserNotFoundTest() { void getRequestStatusNotFoundTest() { // given given(userRepository.existsById(1L)).willReturn(true); + given(setOperations.isMember(ConstantUtil.USER_ID_KEY, user.getId())).willReturn(false); given(photoRequestRepository.findTopByUserIdOrderByCreateDateDesc(1L)).willReturn(java.util.Optional.empty()); // when & then - assertThrows(BaseException.class, () -> photoRequestService.getRequestStatus(1L)); + assertThatThrownBy(() -> photoRequestService.getRequestStatus(1L)) + .isInstanceOf(BaseException.class) + .hasMessage(ResponseCode.PHOTO_REQUEST_NOT_FOUND.getMessage()); } } From 70edd7d4f0f1bf1ef32f62a9fb97a7da4958d542 Mon Sep 17 00:00:00 2001 From: win-luck Date: Thu, 15 Aug 2024 15:02:12 +0900 Subject: [PATCH 2/4] =?UTF-8?q?[chore]=20=EB=B9=84=EC=A6=88=EB=8B=88?= =?UTF-8?q?=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20=EC=A3=BC=EC=9A=94=20=EB=B6=84?= =?UTF-8?q?=EA=B8=B0=EB=A7=88=EB=8B=A4=20=EB=A1=9C=EA=B7=B8=20=EC=82=BD?= =?UTF-8?q?=EC=9E=85=20(#36)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gdsc/cau/puangbe/photo/service/PhotoServiceImpl.java | 5 ++++- .../photorequest/service/PhotoRequestServiceImpl.java | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/gdsc/cau/puangbe/photo/service/PhotoServiceImpl.java b/src/main/java/gdsc/cau/puangbe/photo/service/PhotoServiceImpl.java index 3ce0bb7..8391738 100644 --- a/src/main/java/gdsc/cau/puangbe/photo/service/PhotoServiceImpl.java +++ b/src/main/java/gdsc/cau/puangbe/photo/service/PhotoServiceImpl.java @@ -48,10 +48,12 @@ public void uploadPhoto(Long photoRequestId, String imageUrl) { photoRequestRepository.save(photoRequest); photoResult.update(imageUrl); photoResultRepository.save(photoResult); + log.info("결과 이미지 URL 업로드 완료: {}", imageUrl); // Redis 대기열의 user 정보 삭제 redisTemplate.opsForSet().remove(ConstantUtil.USER_ID_KEY, user.getId()); redisTemplate.delete(user.getId().toString()); + log.info("Redis 대기열에서 요청 삭제 : {}", user.getId()); // 이메일 발송 EmailInfo emailInfo = EmailInfo.builder() @@ -73,6 +75,7 @@ public String getPhotoUrl(Long photoRequestId) { throw new BaseException(ResponseCode.IMAGE_ON_PROCESS); } + log.info("결과 이미지 URL 조회 완료: {}", photoResult.getImageUrl()); return photoResult.getImageUrl(); } @@ -96,7 +99,7 @@ private void sendEmail(EmailInfo emailInfo) { // 메일 전송 mailSender.send(mimeMessage); - + log.info("이메일 전송 완료: {}", emailInfo.getEmail()); } catch (Exception e){ e.printStackTrace(); throw new BaseException(ResponseCode.EMAIL_SEND_ERROR); diff --git a/src/main/java/gdsc/cau/puangbe/photorequest/service/PhotoRequestServiceImpl.java b/src/main/java/gdsc/cau/puangbe/photorequest/service/PhotoRequestServiceImpl.java index de3823a..839b87b 100644 --- a/src/main/java/gdsc/cau/puangbe/photorequest/service/PhotoRequestServiceImpl.java +++ b/src/main/java/gdsc/cau/puangbe/photorequest/service/PhotoRequestServiceImpl.java @@ -59,6 +59,7 @@ public Long createImage(CreateImageDto dto, Long userId){ .createDate(LocalDateTime.now()) .build(); photoResultRepository.save(photoResult); + log.info("사용자의 이미지 요청 생성 완료, RabbitMQ에 전송 준비: {}", userId); try { ImageInfo imageInfo = ImageInfo.builder() @@ -72,6 +73,7 @@ public Long createImage(CreateImageDto dto, Long userId){ // 2. Redis에 형식으로 진행되고 있는 request 정보를 저장한다. // 3. 추후 사진이 완성된다면 requestId를 통해 request를 찾아서 상태를 바꾸고 1:1 관계인 result에 접근해서 imageUrl를 수정한다. // 4. 즉, 파이썬에서 스프링으로 향하는 POST API는 {requestId, imageUrl}이 필수적으로 존재해야 한다. + log.info("RabbitMQ 전송 완료: {}", message); } catch (JsonProcessingException e) { log.error("JSON 변환 실패"); throw new PhotoRequestException(ResponseCode.JSON_PARSE_ERROR); @@ -80,7 +82,7 @@ public Long createImage(CreateImageDto dto, Long userId){ // Redis에 userId 저장하고, userId로 requestId 추적할 수 있도록 함 redisTemplate.opsForSet().add(ConstantUtil.USER_ID_KEY, userId); redisTemplate.opsForSet().add(userId.toString(), request.getId()); - + log.info("Redis 대기열 등록 완료: {}", userId); return request.getId(); } @@ -91,6 +93,7 @@ public List getRequestImages(Long userId){ validateUser(userId); // 현재 처리가 완료되지 않은 이미지(imageUrl이 null)는 보내지 않음 + log.info("사용자의 이미지 리스트 조회 시도: {}", userId); return photoResultRepository.findAllByUserId(userId) .stream() .map(PhotoResult::getImageUrl) @@ -106,12 +109,14 @@ public String getRequestStatus(Long userId){ // Redis에 userId가 존재하면 아직 처리 대기 중인 요청이므로 WAITING 반환 if(Boolean.TRUE.equals(redisTemplate.opsForSet().isMember(ConstantUtil.USER_ID_KEY, userId))){ + log.info("사용자의 요청 상태 조회, 현재 대기 중: {}", userId); return RequestStatus.WAITING.name(); } RequestStatus status = photoRequestRepository.findTopByUserIdOrderByCreateDateDesc(userId) .orElseThrow(() -> new BaseException(ResponseCode.PHOTO_REQUEST_NOT_FOUND)) .getStatus(); + log.info("사용자의 요청 상태 조회, 현재 상태: {} {}", status.name(), userId); return status.name(); } From 0f7b88a8d53539395868c187ce94aacbd3691da3 Mon Sep 17 00:00:00 2001 From: win-luck Date: Thu, 15 Aug 2024 15:02:33 +0900 Subject: [PATCH 3/4] =?UTF-8?q?[infra]=20CI/CD=20workflow=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20=EB=B0=8F=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EA=B2=B0?= =?UTF-8?q?=EA=B3=BC=20=EC=97=B0=EA=B3=84=20(#36)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/CD.yml | 5 +---- .github/workflows/CI.yml | 7 ++++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/.github/workflows/CD.yml b/.github/workflows/CD.yml index 3412d55..b141083 100644 --- a/.github/workflows/CD.yml +++ b/.github/workflows/CD.yml @@ -3,13 +3,10 @@ name: CD on: push: branches: [ "main" ] - pull_request: - branches: [ "main" ] - types: [closed] - workflow_dispatch: pull_request_target: branches: [ "main" ] types: [closed] + workflow_dispatch: permissions: contents: read diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index be02488..d3d7821 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -3,11 +3,9 @@ name: CI on: push: branches: [ "main" ] - pull_request: - branches: [ "main" ] - workflow_dispatch: pull_request_target: branches: [ "main" ] + workflow_dispatch: permissions: contents: read @@ -37,6 +35,9 @@ jobs: echo "${{ secrets.APPLICATION }}" > ./application.yml echo "${{ secrets.PROD }}" > ./application-prod.yml + - name: Test with Gradle + run: ./gradlew test + - name: Build with Gradle run: ./gradlew build -x test From 082a2f3c98735791f7eaf71e7be2dc5bfaefe018 Mon Sep 17 00:00:00 2001 From: win-luck Date: Thu, 15 Aug 2024 15:09:08 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[chore]=20PhotoService=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=EC=BD=94=EB=93=9C=20=EC=98=A4=ED=83=80=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20(#36)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gdsc/cau/puangbe/photo/service/PhotoServiceImplTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/gdsc/cau/puangbe/photo/service/PhotoServiceImplTest.java b/src/test/java/gdsc/cau/puangbe/photo/service/PhotoServiceImplTest.java index 9a5a03b..8adec0f 100644 --- a/src/test/java/gdsc/cau/puangbe/photo/service/PhotoServiceImplTest.java +++ b/src/test/java/gdsc/cau/puangbe/photo/service/PhotoServiceImplTest.java @@ -17,7 +17,7 @@ import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.SetOperations; import org.springframework.mail.javamail.JavaMailSender; -import org.thymeleaf.ITemplateEngine; +import org.thymeleaf.TemplateEngine; import org.thymeleaf.context.IContext; import java.time.LocalDateTime; @@ -50,7 +50,7 @@ class PhotoServiceImplTest { private User user; @Mock - private ITemplateEngine templateEngine; + private TemplateEngine templateEngine; @Mock private JavaMailSender mailSender;