티스토리 뷰
UI 플랫폼으로 WebSquare 사용 시 Test Code
WebSquare View 단에서 Submisson 시 dataList 또는 dataMap 의 key 값을 Test Code에서 임의로 생성하여 Test 진행
Submisson 의 ref: 'data:json,' 으로 처리하므로 Gson 혹인 Jackson을 이용하여 Json String으로 변환하여 post로 전달
인코딩 설정 과 WebSquare 설정 파일 경로 설정 추가
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 kr.co.cwit.common.security; | |
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | |
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; | |
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; | |
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | |
import java.util.HashMap; | |
import org.junit.Before; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.http.MediaType; | |
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.setup.MockMvcBuilders; | |
import org.springframework.web.context.WebApplicationContext; | |
import com.fasterxml.jackson.databind.ObjectMapper; | |
@RunWith(SpringJUnit4ClassRunner.class) | |
@ContextConfiguration(locations = {"file:src/test/resources/spring/*-context.xml", "file:src/test/resources/mybatis/*-context.xml"}) | |
@WebAppConfiguration | |
public class LoginTest { | |
@Autowired | |
private WebApplicationContext wac; | |
private MockMvc mockMvc; | |
@Before | |
public void setup() { | |
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); | |
} | |
@Test | |
public void testConroller() throws Exception { | |
HashMap<String, Object> objMap = new HashMap<>(); | |
HashMap<String, String> tempMap = new HashMap<>(); | |
tempMap.put("USERID", "test"); | |
tempMap.put("USERPW", "test"); | |
objMap.put("dma_login", tempMap); | |
ObjectMapper mapper = new ObjectMapper(); | |
String json = mapper.writeValueAsString(objMap); | |
mockMvc.perform(post("/loginProcess.do").contentType(MediaType.APPLICATION_JSON).content(json).accept(MediaType.parseMediaType("application/json;charset=UTF-8"))) | |
.andExpect(status().isOk()) | |
.andExpect(content().contentType("application/json")) | |
.andDo(print()); | |
} | |
} |
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
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-surefire-plugin</artifactId> | |
<version>2.19.1</version> | |
<configuration> | |
<argLine>-Dfile.encoding=UTF-8 -DWEBSQUARE_HOME=${websquare_home}</argLine> | |
<skipTests>${skipTests}</skipTests> | |
</configuration> | |
</plugin> |
'IT > Spring' 카테고리의 다른 글
Spring Security 4.2 sessionInformationExpiredStrategy 사용 (0) | 2017.02.21 |
---|---|
logback 설정 예 (0) | 2017.02.01 |
Quartz Schedule 사용 시 parameter 전달 xml에 설정하는 방법 (0) | 2016.11.30 |
Spring Security 4.2 Released (0) | 2016.11.15 |
annotation-driven 설정 없이 @ControllerAdvice 사용 설정 (0) | 2016.08.24 |