Notice
Recent Posts
Recent Comments
Link
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

WON.dev

BoardControllerTests.java 본문

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()
	            );
	
	}
}

'SPRING > chapter04_MVC' 카테고리의 다른 글

BoardMapperTests.java  (0) 2023.07.18
BoardAttachMapperTests.java  (0) 2023.07.18
log4jdbc.log4j2.properties  (0) 2023.07.18
log4j.xml  (0) 2023.07.18
ReplyMapper.xml  (0) 2023.07.18