1

我有一个服务于 ajax 调用的 serveresource 方法。我正在尝试使用 MockResourceRequest 和 MockResourceResponse 为这个 serverresource 方法编写一个单元测试。如果有人对此有一个例子,我真的需要一些帮助。提前致谢..

请参阅下面的控制器来处理 ajax 调用,这是 JSR 286 中的一种服务资源方法

[编辑]

@Controller
@RequestMapping("VIEW")
public class Controller {


@ResourceMapping(value = "") 
public String addMethod(ResourceRequest request, ResourceResponse response){
      /* My logic to send the request attributes to Web Service and then push
      the results to the JSP page*/
   }
}
4

1 回答 1

0
@Autowired
Controller controller;

@Test
public void addMethod(){
    MockResourceResponse response = new MockResourceResponse();
    MockResourceRequest request = new MockResourceRequest();
    controller.addMethod(requesr,response);
    assertThat(response.getContentAsString(), equalTo("my xml content"));
}

或更复杂的单元测试 SPRINGMVC PORTLETS

于 2015-02-01T08:33:33.647 回答