SPRING/chapter04_MVC
BoardControllerTests.java
GAWON
2023. 7. 18. 09:37
package org.joonzis.controller;
import org.joonzis.domain.BoardVO;
import org.joonzis.mapper.BoardMapperTests;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import lombok.Setter;
import lombok.extern.log4j.Log4j;
@Log4j
@WebAppConfiguration//서블릿을 사용하기위해 필요하다
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"file:src/main/webapp/WEB-INF/spring/root-context.xml",
"file:src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml"})//서비스를 사용하기위해
public class BoardControllerTests {
@Setter(onMethod_ = @Autowired)
private WebApplicationContext ctx;
//가짜 mvc (가상으로 URL과 파라미터 등을 브라우저에서 사용하는 것처럼 실행가능)
private MockMvc mockMvc;
@Before //JUnit
public void setup() {
this.mockMvc = MockMvcBuilders.webAppContextSetup(ctx).build();
}
/*
@Test
public void testList() throws Exception{
log.info(mockMvc.perform(MockMvcRequestBuilders.get("/board/list")).
andReturn().
getModelAndView().getModelMap()
);
}
*/
/*
@Test
public void testRegister() throws Exception{
String result = mockMvc.perform(MockMvcRequestBuilders.post("/board/register")
.param("title", "테스트새글")
.param("content", "테스트내용")
.param("writer", "테스터")).andReturn().getModelAndView().getViewName();
log.info(result);
}
*/
/*
@Test
public void testget() throws Exception{
String result = mockMvc.perform(MockMvcRequestBuilders.get("/board/get")
.param("bno", "2")).andReturn().getModelAndView().getViewName();
log.info(result);
}
*/
/*
@Test
public void testmodify() throws Exception{
String result = mockMvc.perform(MockMvcRequestBuilders.post("/board/modify")
.param("title","테스트 제목 수정" )
.param("content", "테스트 내용 수정")
.param("writer", "테스터 수정")
.param("bno","2"))
.andReturn().getModelAndView().getViewName();
log.info(result);
}
*/
@Test
public void testRemove() throws Exception{
log.info(mockMvc.perform(MockMvcRequestBuilders.post("/board/remove")
.param("bno", "25"))
.andReturn().getModelAndView().getViewName()
);
}
}