package cn.sunjie.component.auth;
import org.junit.Before;
import org.junit.Ignore;
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.ContextHierarchy;
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.MvcResult;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import javax.servlet.http.Cookie;
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration(value = "src/test/webapp")
@ContextHierarchy({
@ContextConfiguration(name = "parent", locations = "/spring/applicationContext.xml"),
@ContextConfiguration(name = "child", locations = "/spring/applicationContext-dispatch.xml")
})
public class TestAuth {
@Autowired
private WebApplicationContext wac;
private MockMvc mockMvc;
@Before
public void setUp() {
mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
}
@Test
public void testWxInterceptor() throws Exception {
Cookie cookie = new Cookie("auth_wx_costa", "1");
cookie.setPath("/");
cookie.setMaxAge(60);
MvcResult result = mockMvc.perform(MockMvcRequestBuilders.get("/api/auth/1").
header("user-agent","Mozilla/5.0 (Linux; Android 6.0; 1503-M02 Build/MRA58K) " +
"AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/37.0.0.0 Mobile" +
" MQQBrowser/6.2 TBS/036558 Safari/537.36 MicroMessenger/6.3.25.861 NetType/WIFI Language/zh_CN").cookie(cookie))
.andDo(MockMvcResultHandlers.print())
.andReturn();
}
}
SpringWeb项目测试模版
最新推荐文章于 2024-06-05 16:56:23 发布