1、HttpClient模拟请求,需要打开服务器

 

/*
Map<String,String>param=newHashMap<String,String>();
param.put("businesstype","1006");
param.put("trade_no","123123123");
param.put("orderid","123456");
GetMethodmethod=getMethod(URL,param);
client.executeMethod(method);
if(method.getStatusCode()!=200){
fail("未正确响应");
return;
}
Stringresponse=method.getResponseBodyAsString();
System.err.println(response);
PayStatusResponsepayStatus=newPayStatusResponse();
payStatus.setBusinessType(1006);
payStatus.setOrderId("");
payStatus.setResultStatus(1);
StringpayStatusJson=JsonUtil.toJson(payStatus);
System.err.println(payStatusJson);
assertEquals(payStatusJson,response);
*/

    json和对象之间转换用jackson框架
 

  2、springmvc可以使用mockMvc
  staticimports:

 

MockMvcBuilders.*,MockMvcRequestBuilders.*,MockMvcResultMatchers.*
WebApplicationContextwac=...;
MockMvcmockMvc=webAppContextSetup(wac).configureWarRootDir("src/main/webapp",false).build()
mockMvc.perform(get("/form"))
.andExpect(status().isOk())
.andExpect(content().mimeType("text/html"))
.andExpect(forwardedUrl("/WEB-INF/layouts/main.jsp"));