Assuming you're on Spring 3.2+
you could use the Spring MVC Test Framework (before 3.2 it was a standalone project, available on github). To adapt the example from the official documentation:
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration("test-servlet-context.xml")
public class AccountIntegrationTests {
@Autowired
private WebApplicationContext wac;
private MockMvc mockMvc;
@Before
public void setup() {
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
}
@Test
public void getAccount() throws Exception {
Integer accountId = 42;
this.mockMvc.perform(get("/balance.xml")
.param("accountId", accountId.toString())
.accept("application/json;charset=UTF-8"))
.andExpect(status().isOk())
.andExpect(content().contentType("application/xml"));
.andExpect(content().xml("<points>(your XML goes here)</points>"));
}
}
Verifying the contents of the XML file itself would be a matter of reading it from the response content.
EDIT: Re: getting XML contents
content()
returns an instance of ContentResultMatchers, which has several convenience methods for testing the content itself, depending on type. Updated example above to show how to verify contents of XML response (please note: according to the documentation this method needs XMLUnit to work)