Created
January 18, 2021 11:58
-
-
Save captain-blue210/eb4a315d8150efc3177ef448d4ec807b to your computer and use it in GitHub Desktop.
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
package captain.blue210.studyfornetsuperbackend.presentation.api.controller.goods; | |
import captain.blue210.studyfornetsuperbackend.domain.model.goods.Goods; | |
import org.junit.jupiter.api.DisplayName; | |
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.security.test.context.support.WithMockUser; | |
import org.springframework.test.web.servlet.MockMvc; | |
import java.util.ArrayList; | |
import java.util.List; | |
import static org.hamcrest.CoreMatchers.is; | |
import static org.hamcrest.Matchers.hasSize; | |
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | |
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | |
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | |
@WebMvcTest | |
class GoodsControllerTest { | |
@Autowired private MockMvc mock; | |
@Test | |
@WithMockUser("spring") | |
@DisplayName("get all items") | |
void testGetAllItems() throws Exception { | |
Goods goods1 = new Goods(1, "test", goodsBranddName); | |
List<Goods> goodsList = new ArrayList<>(); | |
goodsList.add(goods1); | |
mock.perform(get("/api/items")) | |
.andExpect(status().isOk()) | |
.andExpect(jsonPath("$", hasSize(1))) | |
.andExpect(jsonPath("$[0].goodsName", is(goods1.getGoodsName()))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment