objects) {
return this.excuteAction("POST", url, port, objects);
}
/**
* Simulate Request to URL appoint by MockHttpServletRequest.
*
* @param method
* POST/GET
* @param url
* requestURL
* @param port
* int
* @param objects
* parameters
* @return ModelAndView
*/
public final ModelAndView excuteAction(final String method, final String url, final int port,
final Object[]... objects) {
MockHttpServletRequest request = new MockHttpServletRequest(method, url);
MockHttpServletResponse response = new MockHttpServletResponse();
request.setServerPort(port);
request.setLocalPort(port);
if (objects != null) {
for (Object[] object : objects) {
if (object != null && object.length == 2) {
request.addParameter(object[0].toString(), object[1].toString());
}
}
}
MockHttpSession session = new MockHttpSession();
request.setSession(session);
try {
return this.excuteAction(request, response);
} catch (Exception e) {
e.printStackTrace();
InfoLogUtil.error(e.toString());
}
return null;
}
}
测试类
[java]
public class LocationInfoTest extends JUnitActionBase {
/**
* TODO: write description for this method.
*/
@Test
public void testKeepAlive() {
Map paramMap = new HashMap();
paramMap.put("ACTION", "KEEP_ALIVE");
this.excuteAction("/IBEFacade", 8080, paramMap);
}
/**
* TODO: write description for this method.
*/
@Test
public void testLocationInfo() {
this.excuteAction("/IBEFacade", 8080, new Object[]{"ACTION", "LOCATION_INFO"});
}
}
另外还可以配合easymock/powermock框架来测试