????spring???????????????

????????????

public class CaseControllerTest {
 private static final Log logger = LogFactory.getLog(CaseControllerTest.class);
 private CaseController controller = null;
 private XmlWebApplicationContext ctx;

 
 @Before
 public void setUp() throws Exception {
  String[] paths = {"spring-servlet-test.xml" };
  ctx = new XmlWebApplicationContext();
  ctx.setConfigLocations(paths);
  ctx.setServletContext(new MockServletContext(""));
  ctx.refresh();
  controller = (CaseController) ctx.getBean("caseController");
 }

 
 @After
 public void tearDown() throws Exception {
  ctx.close();
 }

 
 @Test
 public void testListJson() {
  logger.info("*****testListJson start**********");
  MockHttpServletResponse response = new MockHttpServletResponse();
  MockHttpServletRequest request = new MockHttpServletRequest("POST"?? "");
  request.setRequestURI("/case/listJson");
  request.addParameter("name"?? "name");
  List<String> result = controller.listJson(request?? response);
  logger.info("*****result:" + result);
  Assert.assertTrue("result is empty"?? !result.isEmpty());

  logger.info("*****testListJson end**********");
 }
 
 @Test
 public void testList() {
  logger.info("*****testList start**********");
  MockHttpServletResponse response = new MockHttpServletResponse();
  MockHttpServletRequest request = new MockHttpServletRequest("POST"?? "");
  request.setRequestURI("/case/list");
  request.addParameter("name"?? "name");
  String returnStr = controller.list(request?? response);
  List<String> result = (List<String>) request.getAttribute("result");
  logger.info("*****result:" + result);
  logger.info("*****returnStr:" + returnStr);
  logger.info("*****testList end**********");
 }
}

????????

1.spring-servlet-test.xml??????????;
2.controller??bean???????Сд??caseController;
3.???????request response?????????????????request.getAttribute("result");