-
Notifications
You must be signed in to change notification settings - Fork 7
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
[BE/TEST] DTO Validation test #358
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
30970b8
test/#353: @Valid μΆκ°
LJH098 bce1e05
test/#353: CreateFoodRequest Valid test
LJH098 0d3c372
Merge branch 'be' of https://github.com/JNU-econovation/Gaebaljip intβ¦
LJH098 0cf0127
test/#353: LoginRequest Valid
LJH098 43da406
test/#353: OnBoardingRequest Valid
LJH098 3deef0b
test/#353: DTO Validation testλ₯Ό Controller testλ‘ μμ
LJH098 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
309 changes: 309 additions & 0 deletions
309
BE/exceed/src/test/java/com/gaebaljip/exceed/food/CreateFoodIntegrationTest.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,309 @@ | ||
package com.gaebaljip.exceed.food; | ||
|
||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders; | ||
import org.springframework.test.web.servlet.ResultActions; | ||
|
||
import com.gaebaljip.exceed.common.IntegrationTest; | ||
import com.gaebaljip.exceed.common.ValidationMessage; | ||
import com.gaebaljip.exceed.common.WithMockUser; | ||
import com.gaebaljip.exceed.dto.request.CreateFoodRequest; | ||
|
||
class CreateFoodIntegrationTest extends IntegrationTest { | ||
|
||
@Test | ||
@DisplayName("μμ μΆκ° : μ±κ³΅") | ||
@WithMockUser | ||
void createFood() throws Exception { | ||
// given | ||
CreateFoodRequest request = | ||
CreateFoodRequest.builder() | ||
.name("λ―Όμ΄λ§λΌν") | ||
.calorie(1000.0) | ||
.carbohydrate(100.0) | ||
.dietaryFiber(10.0) | ||
.fat(10.0) | ||
.protein(10.0) | ||
.servingSize(1.0) | ||
.sodium(10.0) | ||
.sugars(10.0) | ||
.build(); | ||
// when | ||
ResultActions resultActions = | ||
mockMvc.perform( | ||
RestDocumentationRequestBuilders.post("/v1/food") | ||
.content(om.writeValueAsString(request)) | ||
.contentType(MediaType.APPLICATION_JSON)); | ||
|
||
String responseBody = resultActions.andReturn().getResponse().getContentAsString(); | ||
|
||
// then | ||
resultActions.andExpect(status().isOk()); | ||
} | ||
|
||
@Test | ||
@DisplayName("μμ μΆκ° : μ€ν¨ - μ΄λ¦μ΄ μλ κ²½μ°") | ||
@WithMockUser | ||
void createFoodFail() throws Exception { | ||
// given | ||
CreateFoodRequest request = | ||
CreateFoodRequest.builder() | ||
.calorie(1000.0) | ||
.carbohydrate(100.0) | ||
.dietaryFiber(10.0) | ||
.fat(10.0) | ||
.protein(10.0) | ||
.servingSize(1.0) | ||
.sodium(10.0) | ||
.sugars(10.0) | ||
.build(); | ||
// when | ||
ResultActions resultActions = | ||
mockMvc.perform( | ||
RestDocumentationRequestBuilders.post("/v1/food") | ||
.content(om.writeValueAsString(request)) | ||
.contentType(MediaType.APPLICATION_JSON)); | ||
|
||
// then | ||
resultActions.andExpectAll( | ||
status().isBadRequest(), | ||
jsonPath("$.error.reason").value("μ΄λ¦μ " + ValidationMessage.NOT_BLANK)); | ||
} | ||
|
||
@Test | ||
@DisplayName("μμ μΆκ° : μ€ν¨ - μΉΌλ‘λ¦¬κ° μλ κ²½μ°") | ||
@WithMockUser | ||
void createFoodFail2() throws Exception { | ||
// given | ||
CreateFoodRequest request = | ||
CreateFoodRequest.builder() | ||
.name("λ―Όμ΄λ§λΌν") | ||
.carbohydrate(100.0) | ||
.dietaryFiber(10.0) | ||
.fat(10.0) | ||
.protein(10.0) | ||
.servingSize(1.0) | ||
.sodium(10.0) | ||
.sugars(10.0) | ||
.build(); | ||
// when | ||
ResultActions resultActions = | ||
mockMvc.perform( | ||
RestDocumentationRequestBuilders.post("/v1/food") | ||
.content(om.writeValueAsString(request)) | ||
.contentType(MediaType.APPLICATION_JSON)); | ||
|
||
// then | ||
resultActions.andExpectAll( | ||
status().isBadRequest(), | ||
jsonPath("$.error.reason").value("μΉΌλ‘리λ₯Ό " + ValidationMessage.NOT_NULL)); | ||
} | ||
|
||
@Test | ||
@DisplayName("μμ μΆκ° : μ€ν¨ - νμνλ¬Όμ΄ μλ κ²½μ°") | ||
@WithMockUser | ||
void createFoodFail3() throws Exception { | ||
// given | ||
CreateFoodRequest request = | ||
CreateFoodRequest.builder() | ||
.name("λ―Όμ΄λ§λΌν") | ||
.calorie(1000.0) | ||
.dietaryFiber(10.0) | ||
.fat(10.0) | ||
.protein(10.0) | ||
.servingSize(1.0) | ||
.sodium(10.0) | ||
.sugars(10.0) | ||
.build(); | ||
// when | ||
ResultActions resultActions = | ||
mockMvc.perform( | ||
RestDocumentationRequestBuilders.post("/v1/food") | ||
.content(om.writeValueAsString(request)) | ||
.contentType(MediaType.APPLICATION_JSON)); | ||
|
||
// then | ||
resultActions.andExpectAll( | ||
status().isBadRequest(), | ||
jsonPath("$.error.reason").value("νμνλ¬Όμ " + ValidationMessage.NOT_NULL)); | ||
} | ||
|
||
@Test | ||
@DisplayName("μμ μΆκ° : μ€ν¨ - μμ΄μ¬μ κ° μλ κ²½μ°") | ||
@WithMockUser | ||
void createFoodFail4() throws Exception { | ||
// given | ||
CreateFoodRequest request = | ||
CreateFoodRequest.builder() | ||
.name("λ―Όμ΄λ§λΌν") | ||
.calorie(1000.0) | ||
.carbohydrate(100.0) | ||
.fat(10.0) | ||
.protein(10.0) | ||
.servingSize(1.0) | ||
.sodium(10.0) | ||
.sugars(10.0) | ||
.build(); | ||
// when | ||
ResultActions resultActions = | ||
mockMvc.perform( | ||
RestDocumentationRequestBuilders.post("/v1/food") | ||
.content(om.writeValueAsString(request)) | ||
.contentType(MediaType.APPLICATION_JSON)); | ||
|
||
// then | ||
resultActions.andExpectAll( | ||
status().isBadRequest(), | ||
jsonPath("$.error.reason").value("μμ΄μ¬μ λ₯Ό " + ValidationMessage.NOT_NULL)); | ||
} | ||
|
||
@Test | ||
@DisplayName("μμ μΆκ° : μ€ν¨ - μ§λ°©μ΄ μλ κ²½μ°") | ||
@WithMockUser | ||
void createFoodFail5() throws Exception { | ||
// given | ||
CreateFoodRequest request = | ||
CreateFoodRequest.builder() | ||
.name("λ―Όμ΄λ§λΌν") | ||
.calorie(1000.0) | ||
.carbohydrate(100.0) | ||
.dietaryFiber(10.0) | ||
.protein(10.0) | ||
.servingSize(1.0) | ||
.sodium(10.0) | ||
.sugars(10.0) | ||
.build(); | ||
// when | ||
ResultActions resultActions = | ||
mockMvc.perform( | ||
RestDocumentationRequestBuilders.post("/v1/food") | ||
.content(om.writeValueAsString(request)) | ||
.contentType(MediaType.APPLICATION_JSON)); | ||
|
||
// then | ||
resultActions.andExpectAll( | ||
status().isBadRequest(), | ||
jsonPath("$.error.reason").value("μ§λ°©μ " + ValidationMessage.NOT_NULL)); | ||
} | ||
|
||
@Test | ||
@DisplayName("μμ μΆκ° : μ€ν¨ - λ¨λ°±μ§μ΄ μλ κ²½μ°") | ||
@WithMockUser | ||
void createFoodFail6() throws Exception { | ||
// given | ||
CreateFoodRequest request = | ||
CreateFoodRequest.builder() | ||
.name("λ―Όμ΄λ§λΌν") | ||
.calorie(1000.0) | ||
.carbohydrate(100.0) | ||
.dietaryFiber(10.0) | ||
.fat(10.0) | ||
.servingSize(1.0) | ||
.sodium(10.0) | ||
.sugars(10.0) | ||
.build(); | ||
// when | ||
ResultActions resultActions = | ||
mockMvc.perform( | ||
RestDocumentationRequestBuilders.post("/v1/food") | ||
.content(om.writeValueAsString(request)) | ||
.contentType(MediaType.APPLICATION_JSON)); | ||
|
||
// then | ||
resultActions.andExpectAll( | ||
status().isBadRequest(), | ||
jsonPath("$.error.reason").value("λ¨λ°±μ§μ " + ValidationMessage.NOT_NULL)); | ||
} | ||
|
||
@Test | ||
@DisplayName("μμ μΆκ° : μ€ν¨ - 1ν μ 곡λμ΄ μλ κ²½μ°") | ||
@WithMockUser | ||
void createFoodFail7() throws Exception { | ||
// given | ||
CreateFoodRequest request = | ||
CreateFoodRequest.builder() | ||
.name("λ―Όμ΄λ§λΌν") | ||
.calorie(1000.0) | ||
.carbohydrate(100.0) | ||
.dietaryFiber(10.0) | ||
.fat(10.0) | ||
.protein(10.0) | ||
.sodium(10.0) | ||
.sugars(10.0) | ||
.build(); | ||
// when | ||
ResultActions resultActions = | ||
mockMvc.perform( | ||
RestDocumentationRequestBuilders.post("/v1/food") | ||
.content(om.writeValueAsString(request)) | ||
.contentType(MediaType.APPLICATION_JSON)); | ||
|
||
// then | ||
resultActions.andExpectAll( | ||
status().isBadRequest(), | ||
jsonPath("$.error.reason").value("1ν μ 곡λμ " + ValidationMessage.NOT_NULL)); | ||
} | ||
|
||
@Test | ||
@DisplayName("μμ μΆκ° : μ€ν¨ - λΉμ΄ μλ κ²½μ°") | ||
@WithMockUser | ||
void createFoodFail8() throws Exception { | ||
// given | ||
CreateFoodRequest request = | ||
CreateFoodRequest.builder() | ||
.name("λ―Όμ΄λ§λΌν") | ||
.calorie(1000.0) | ||
.carbohydrate(100.0) | ||
.dietaryFiber(10.0) | ||
.fat(10.0) | ||
.protein(10.0) | ||
.servingSize(1.0) | ||
.sodium(10.0) | ||
.build(); | ||
// when | ||
ResultActions resultActions = | ||
mockMvc.perform( | ||
RestDocumentationRequestBuilders.post("/v1/food") | ||
.content(om.writeValueAsString(request)) | ||
.contentType(MediaType.APPLICATION_JSON)); | ||
|
||
// then | ||
resultActions.andExpectAll( | ||
status().isBadRequest(), | ||
jsonPath("$.error.reason").value("λΉμ " + ValidationMessage.NOT_NULL)); | ||
} | ||
|
||
@Test | ||
@DisplayName("μμ μΆκ° : μ€ν¨ - λνΈλ₯¨μ΄ μλ κ²½μ°") | ||
@WithMockUser | ||
void createFoodFail9() throws Exception { | ||
// given | ||
CreateFoodRequest request = | ||
CreateFoodRequest.builder() | ||
.name("λ―Όμ΄λ§λΌν") | ||
.calorie(1000.0) | ||
.carbohydrate(100.0) | ||
.dietaryFiber(10.0) | ||
.fat(10.0) | ||
.protein(10.0) | ||
.servingSize(1.0) | ||
.sugars(10.0) | ||
.build(); | ||
// when | ||
ResultActions resultActions = | ||
mockMvc.perform( | ||
RestDocumentationRequestBuilders.post("/v1/food") | ||
.content(om.writeValueAsString(request)) | ||
.contentType(MediaType.APPLICATION_JSON)); | ||
|
||
// then | ||
resultActions.andExpectAll( | ||
status().isBadRequest(), | ||
jsonPath("$.error.reason").value("λνΈλ₯¨μ " + ValidationMessage.NOT_NULL)); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
DTO Validation Testκ° λͺ©μ μ΄λ©΄, Controller κ³μΈ΅λ§ ν μ€νΈνλ 건 μ΄λ€κ°μ?
λ§μ½ κ·Έλ λ€λ©΄, ControllerTest ν΄λμ€λ₯Ό μμλ°μΌλ©΄ μ’μ κ² κ°μμ.
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.
κ·Έκ² μ’κ² λ€μ