-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[2단계 - 웹 자동차 경주] 허브(방대의) 미션 제출합니다. #128
Changes from 8 commits
8217daa
dc8a390
3f180ae
5a5bb8c
687c018
0254c3a
787df6f
c76a89e
9ee855f
8f58fc3
8c84be5
e6dfb73
afe536a
8774a6c
a133140
9dc8c73
b022338
13b849a
29f8189
f2f7d91
c8b5b21
5bde85a
ff564cf
55cdf91
ee97a59
12d6e83
a957c5c
fbd5d7f
9934292
3781e59
446e7e4
9e8e755
8adb76a
f913f4e
57d98cd
4ac2929
04a45cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package racingcar.integration; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.hamcrest.Matchers.hasSize; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.mockito.BDDMockito.given; | ||
import static org.springframework.http.MediaType.APPLICATION_JSON; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import java.util.List; | ||
import org.hamcrest.Matchers; | ||
import org.junit.jupiter.api.DisplayNameGeneration; | ||
import org.junit.jupiter.api.DisplayNameGenerator; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import racingcar.dao.CarDao; | ||
import racingcar.dao.GameDao; | ||
import racingcar.domain.NumberGenerator; | ||
import racingcar.dto.GamePlayRequestDto; | ||
import racingcar.entity.CarEntity; | ||
import racingcar.entity.GameEntity; | ||
|
||
@SpringBootTest | ||
@AutoConfigureMockMvc | ||
@Transactional | ||
@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) | ||
@SuppressWarnings("NonAsciiCharacters") | ||
public class RacingGameIntegrationTest { | ||
Comment on lines
+33
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 요거는 저희 팀에서 관리하는 컨벤션인데요. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 중요도에 의해 순서를 결정하는 부분 좋은 것 같습니다. 확실히 해당 클래스가 어떤 애너테이션에 제일 영향을 많이 받는지 한 눈에 이해할 수 있을 것 같아요! |
||
|
||
@Autowired | ||
private MockMvc mockMvc; | ||
|
||
@Autowired | ||
private ObjectMapper objectMapper; | ||
|
||
@Autowired | ||
private GameDao gameDao; | ||
|
||
@Autowired | ||
private CarDao carDao; | ||
|
||
@MockBean | ||
private NumberGenerator numberGenerator; | ||
|
||
@Test | ||
void 게임을_진행한다() throws Exception { | ||
// given | ||
final GamePlayRequestDto gamePlayRequestDto = new GamePlayRequestDto(List.of("비버", "허브"), 3); | ||
final String request = objectMapper.writeValueAsString(gamePlayRequestDto); | ||
given(numberGenerator.generate()).willReturn(7, 3, 3, 4, 5, 2); | ||
|
||
// expect | ||
mockMvc.perform(post("/plays") | ||
.content(request) | ||
.contentType(APPLICATION_JSON)) | ||
.andExpect(status().isCreated()) | ||
.andExpect(jsonPath("$.winners", Matchers.contains("비버"))) | ||
.andExpect(jsonPath("$.racingCars", hasSize(2))) | ||
.andExpect(jsonPath("$.racingCars[0].name", is("비버"))) | ||
.andExpect(jsonPath("$.racingCars[0].position").value(2)) | ||
.andExpect(jsonPath("$.racingCars[1].name", is("허브"))) | ||
.andExpect(jsonPath("$.racingCars[1].position").value(1)) | ||
.andDo(print()); | ||
assertThat(carDao.findAll()).hasSize(2); | ||
} | ||
|
||
@Test | ||
void 게임_결과를_반환한다() throws Exception { | ||
// given | ||
final Integer gameId = gameDao.saveAndGetId(new GameEntity(9999)).get(); | ||
carDao.saveAll(List.of( | ||
new CarEntity("비버", 5, true, gameId), | ||
new CarEntity("허브", 4, false, gameId) | ||
)); | ||
|
||
// expect | ||
mockMvc.perform(get("/plays") | ||
.contentType(APPLICATION_JSON)) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$[0].winners", Matchers.contains("비버"))) | ||
.andExpect(jsonPath("$[0].racingCars", hasSize(2))) | ||
.andExpect(jsonPath("$[0].racingCars[0].name", is("비버"))) | ||
.andExpect(jsonPath("$[0].racingCars[0].position").value(5)) | ||
.andExpect(jsonPath("$[0].racingCars[1].name", is("허브"))) | ||
.andExpect(jsonPath("$[0].racingCars[1].position").value(4)) | ||
.andDo(print()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
와,,,, 허브 굉장하시네요 👍
지금과 같이 하나의 클러스터를 사용하는 경우에는 영향이 없겠지만 나중에 규모있는 애플리케이션을 작성할 때는 항상 신경써야 하는 부분이에요. 정말 선행학습이 잘 되어있으시네요 👏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
칭찬을 받으니 너무 좋습니다👍🏻 라빈의 기운 받고 꾸준히 정진 하겠습니다!!