1

I have a serveresource method which serves an ajax call. I am trying to write a unit test for this serverresource method using MockResourceRequest and MockResourceResponse. I would really need some help on this if someone has an example to this. Thanks in advance..

Please see the below controller to handle the ajax call which is a serve resource method in JSR 286

[EDIT]

@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*/
   }
}
user525146
  • 3,918
  • 14
  • 60
  • 103
  • Please post some code. What's the signature of the method you are trying to test? How have you been trying to test it and why aren't your efforts working -- is the test not run at all, are you getting an exception, what? – ZeroOne Apr 22 '12 at 21:44
  • @ZeroOne Please see above for my class signature and method. The ResourceMapping is the value I use as a resource url and send the data to above defined controller to handle. I am really confused how to write the unit tests for this controller. – user525146 Apr 23 '12 at 18:51

1 Answers1

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"));
}

or more complicated here UNIT TESTING SPRINGMVC PORTLETS

haste
  • 1
  • 3