-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e42e8cf
commit 89562bf
Showing
2 changed files
with
61 additions
and
1 deletion.
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
59 changes: 59 additions & 0 deletions
59
be/kiosk/src/test/java/team/five/kiosk/controller/ProductControllerTest.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,59 @@ | ||
package team.five.kiosk.controller; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.ResultActions; | ||
import team.five.kiosk.dto.ResponseProduct; | ||
import team.five.kiosk.service.ProductService; | ||
|
||
import java.util.List; | ||
|
||
import static org.mockito.BDDMockito.*; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | ||
|
||
@WebMvcTest | ||
class ProductControllerTest { | ||
|
||
@Autowired | ||
private MockMvc mockMvc; | ||
|
||
@MockBean | ||
private ProductService productService; | ||
|
||
@Test | ||
public void getProductsTest() throws Exception { | ||
//given | ||
final List<ResponseProduct> responseProducts = List.of( | ||
ResponseProduct.builder().id(1L).name("아메리카노").price(4000).imageUrl("url1").build(), | ||
ResponseProduct.builder().id(2L).name("카페라떼").price(4500).imageUrl("url2").build(), | ||
ResponseProduct.builder().id(3L).name("바닐라라떼").price(4500).imageUrl("url3").build() | ||
); | ||
|
||
given(productService.getProducts(anyString())).willReturn(responseProducts); | ||
|
||
//when | ||
final ResultActions result = mockMvc.perform(get("/api/v1/products") | ||
.queryParam("category", "coffee")) | ||
.andExpect(status().isOk()).andDo(print()); | ||
|
||
//then | ||
result.andExpect(jsonPath("status").isString()); | ||
result.andExpect(jsonPath("status").value(200)); | ||
result.andExpect(jsonPath("message[0].id").value(1L)); | ||
result.andExpect(jsonPath("message[1].id").value(2L)); | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|