-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from BbeumbungE/feat/BACK-292
feat: 게시물 및 비전 API 테스트코드 작성, Canvas SSE Initial 이벤트 삭제 [BACK-292]
- Loading branch information
Showing
8 changed files
with
259 additions
and
18 deletions.
There are no files selected for viewing
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
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
18 changes: 18 additions & 0 deletions
18
src/test/java/com/siliconvalley/SiliconValleyApplicationTests.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,18 @@ | ||
package com.siliconvalley; | ||
|
||
import com.siliconvalley.domain.post.service.PostingService; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
@SpringBootTest | ||
class SiliconValleyApplicationTests { | ||
|
||
@Autowired | ||
PostingService postingService; | ||
|
||
@Test | ||
void contextLoads() { | ||
} | ||
|
||
} |
13 changes: 0 additions & 13 deletions
13
src/test/java/com/siliconvalley/SiliconvallyApplicationTests.java
This file was deleted.
Oops, something went wrong.
90 changes: 90 additions & 0 deletions
90
src/test/java/com/siliconvalley/post/PostingServiceTests.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,90 @@ | ||
package com.siliconvalley.post; | ||
|
||
import com.siliconvalley.domain.canvas.dao.CanvasFindDao; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
import com.siliconvalley.domain.canvas.domain.Canvas; | ||
import com.siliconvalley.domain.post.code.PostCode; | ||
import com.siliconvalley.domain.post.dao.PostFindDao; | ||
import com.siliconvalley.domain.post.dao.PostRepository; | ||
import com.siliconvalley.domain.post.domain.Post; | ||
import com.siliconvalley.domain.post.exception.IllegalDeleteException; | ||
import com.siliconvalley.domain.post.service.PostingService; | ||
import com.siliconvalley.domain.profile.domain.Profile; | ||
import com.siliconvalley.global.common.dto.Response; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
@DisplayName(value = "게시물 CRUD 테스트") | ||
public class PostingServiceTests { | ||
|
||
@InjectMocks | ||
private PostingService postingService; | ||
|
||
@Mock | ||
private PostFindDao postFindDao; | ||
|
||
@Mock | ||
private PostRepository postRepository; | ||
|
||
@Mock | ||
private CanvasFindDao canvasFindDao; | ||
|
||
@Test | ||
@DisplayName(value = "그림에 대한 게시물을 작성한다.") | ||
void 게시물작성() { | ||
// Given | ||
Long canvasId = 1L; | ||
Canvas mockCanvas = mock(Canvas.class); | ||
Post mockPost = mock(Post.class); | ||
when(canvasFindDao.findById(canvasId)).thenReturn(mockCanvas); | ||
when(mockCanvas.buildPost()).thenReturn(mockPost); | ||
|
||
// When | ||
Response response = postingService.createPostForCanvas(canvasId); | ||
|
||
// Then | ||
verify(postRepository).save(mockPost); | ||
assertEquals(PostCode.POSTING_SUCCESS.getCode(), response.getStatus().getCode()); | ||
} | ||
|
||
@Test | ||
@DisplayName("게시물을 삭제한다.") | ||
void 게시물삭제() { | ||
// Given | ||
Long postId = 1L; | ||
Profile mockProfile = mock(Profile.class); | ||
Post mockPost = mock(Post.class); | ||
when(mockProfile.getId()).thenReturn(postId); | ||
when(postFindDao.findById(postId)).thenReturn(mockPost); | ||
when(mockPost.getId()).thenReturn(postId); | ||
|
||
// When | ||
Response response = postingService.deletePost(postId, mockProfile); | ||
|
||
// Then | ||
verify(postRepository).delete(mockPost); | ||
assertEquals(PostCode.DELETE_POST_SUCCESS.getCode(), response.getStatus().getCode()); | ||
} | ||
|
||
@Test | ||
@DisplayName(value = "다른 유저의 게시물을 삭제한다.") | ||
void 게시물삭제예외() { | ||
// Given | ||
Long postId = 1L; | ||
Profile mockProfile = mock(Profile.class); | ||
Post mockPost = mock(Post.class); | ||
when(mockProfile.getId()).thenReturn(2L); // Different ID | ||
when(postFindDao.findById(postId)).thenReturn(mockPost); | ||
when(mockPost.getId()).thenReturn(postId); | ||
|
||
// Then | ||
assertThrows(IllegalDeleteException.class, () -> postingService.deletePost(postId, mockProfile)); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/test/java/com/siliconvalley/post/RankingServiceTests.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,15 @@ | ||
package com.siliconvalley.post; | ||
|
||
import com.siliconvalley.domain.post.service.RankCachingService; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class RankingServiceTests { | ||
|
||
@InjectMocks | ||
private RankCachingService rankCachingService; | ||
|
||
|
||
} |
128 changes: 128 additions & 0 deletions
128
src/test/java/com/siliconvalley/vision/VisionDetectingServiceTests.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,128 @@ | ||
package com.siliconvalley.vision; | ||
|
||
import com.siliconvalley.domain.canvas.dao.CanvasFindDao; | ||
import com.siliconvalley.domain.canvas.domain.Canvas; | ||
import com.siliconvalley.domain.google.service.GoogleVisionApiService; | ||
import com.siliconvalley.domain.google.service.VisionDetectingService; | ||
import com.siliconvalley.domain.stage.domain.Score; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import java.util.Map; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.*; | ||
|
||
|
||
@ExtendWith(MockitoExtension.class) | ||
@Slf4j | ||
@DisplayName(value = "점수 측정 테스트") | ||
public class VisionDetectingServiceTests { | ||
|
||
@InjectMocks | ||
private VisionDetectingService visionDetectingService; | ||
|
||
@Mock | ||
private CanvasFindDao canvasFindDao; | ||
|
||
@Mock | ||
private GoogleVisionApiService visionService; | ||
|
||
@Test | ||
@DisplayName(value = "다른 물체만 감지되었을 때 그림의 점수를 LOW(1)로 반환") | ||
void 그림점수_낮음() { | ||
// Given | ||
Long canvasId = 1L; | ||
Canvas mockCanvas = mock(Canvas.class, RETURNS_DEEP_STUBS); | ||
when(canvasFindDao.findById(canvasId)).thenReturn(mockCanvas); | ||
when(mockCanvas.getCanvas()).thenReturn("sampleCanvasData"); | ||
when(visionService.detectObjects("sampleCanvasData")).thenReturn(Map.of("anotherModelName", 0.8f)); // 수정된 점수 | ||
when(mockCanvas.getSubject().getPix2Pix().getModelName()).thenReturn("sampleModelName"); | ||
|
||
// When | ||
Score result = visionDetectingService.calculateCanvasScore(canvasId); | ||
|
||
// Then | ||
assertEquals(Score.LOW, result); | ||
} | ||
|
||
@Test | ||
@DisplayName(value = "목표 물체가 감지 되었을 때 그림의 점수를 MEDIUM(2)로 반환") | ||
void 그림점수_중간() { | ||
// Given | ||
Long canvasId = 1L; | ||
Canvas mockCanvas = mock(Canvas.class, RETURNS_DEEP_STUBS); | ||
when(canvasFindDao.findById(canvasId)).thenReturn(mockCanvas); | ||
when(mockCanvas.getCanvas()).thenReturn("sampleCanvasData"); | ||
when(visionService.detectObjects("sampleCanvasData")).thenReturn(Map.of("sampleModelName", 0.3f)); // 수정된 점수 | ||
when(mockCanvas.getSubject().getPix2Pix().getModelName()).thenReturn("sampleModelName"); | ||
|
||
// When | ||
Score result = visionDetectingService.calculateCanvasScore(canvasId); | ||
|
||
// Then | ||
assertEquals(Score.MEDIUM, result); | ||
} | ||
|
||
@Test | ||
@DisplayName(value = "목표 물체 감지율 80%이상일 때 그림의 점수를 HIGH(3)으로 반환") | ||
void 그림점수_높음() { | ||
// Given | ||
Long canvasId = 1L; | ||
Canvas mockCanvas = mock(Canvas.class, RETURNS_DEEP_STUBS); | ||
when(canvasFindDao.findById(canvasId)).thenReturn(mockCanvas); | ||
when(mockCanvas.getCanvas()).thenReturn("sampleCanvasData"); | ||
when(visionService.detectObjects("sampleCanvasData")).thenReturn(Map.of("sampleModelName", 0.8f)); // 수정된 점수 | ||
when(mockCanvas.getSubject().getPix2Pix().getModelName()).thenReturn("sampleModelName"); | ||
|
||
// When | ||
Score result = visionDetectingService.calculateCanvasScore(canvasId); | ||
|
||
// Then | ||
assertEquals(Score.HIGH, result); | ||
} | ||
|
||
@Test | ||
@DisplayName(value = "감지된 물체가 없을 경우 그림의 점수를 LOW(1)로 반환") | ||
void 물체감지실패_점수낮음() { | ||
// Given | ||
Long canvasId = 1L; | ||
Canvas mockCanvas = mock(Canvas.class, RETURNS_DEEP_STUBS); | ||
when(canvasFindDao.findById(canvasId)).thenReturn(mockCanvas); | ||
when(mockCanvas.getCanvas()).thenReturn("sampleCanvasData"); | ||
|
||
// 탐지된 물체가 없을 경우 빈 Map 반환 | ||
when(visionService.detectObjects("sampleCanvasData")).thenReturn(Map.of()); | ||
|
||
// When | ||
Score result = visionDetectingService.calculateCanvasScore(canvasId); | ||
|
||
// Then | ||
assertEquals(Score.LOW, result); | ||
} | ||
|
||
@Test | ||
@DisplayName(value = "입출력 오류가 발생했을 경우 그림의 점수를 LOW(1)로 반환") | ||
void 입출력오류_점수낮음() { | ||
// Given | ||
Long canvasId = 1L; | ||
Canvas mockCanvas = mock(Canvas.class, RETURNS_DEEP_STUBS); | ||
when(canvasFindDao.findById(canvasId)).thenReturn(mockCanvas); | ||
when(mockCanvas.getCanvas()).thenReturn("sampleCanvasData"); | ||
|
||
// 탐지된 물체가 없을 경우 빈 Map 반환 | ||
when(visionService.detectObjects("sampleCanvasData")).thenReturn(Map.of("Error", -1f)); | ||
|
||
// When | ||
Score result = visionDetectingService.calculateCanvasScore(canvasId); | ||
|
||
// Then | ||
assertEquals(Score.LOW, result); | ||
} | ||
|
||
} |