Skip to content

Instantly share code, notes, and snippets.

@captain-blue210
Created January 18, 2021 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save captain-blue210/eb4a315d8150efc3177ef448d4ec807b to your computer and use it in GitHub Desktop.
Save captain-blue210/eb4a315d8150efc3177ef448d4ec807b to your computer and use it in GitHub Desktop.
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