0

I'm trying to create a controller test with payload in xml, using MockMvc, But when I run the test the following error appears:

org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; [Fatal Error]: 1: 1: Premature end of file.

My test method

@Test
public void newTransaction() throws Exception {

    String payload = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
            + "<Transaction>"
                + "<transAmt>20059</transAmt>"
                + "<merchId>687555537877464</merchId>"
                + "<merchNameLoc>Best</merchNameLoc>"
                + "<transDate>12312010</transDate>"
                + "<retCd>0</retCd>"
            + "</Transaction>";

    mockMvc.perform(post("/rtm/transaction")
            .content(payload)
            .accept(MediaType.APPLICATION_XML)
            .contentType(MediaType.APPLICATION_XML))
            .andExpect(xpath("//transactionId").exists())
            .andExpect(status().isCreated());
}

And my controller

@RequestMapping(value = "/transaction", consumes = MediaType.APPLICATION_XML_VALUE)
@ResponseBody
public ResponseEntity<Transaction> newTransaction(@RequestBody NotificationCommand command){
    return null;
}
Tiago Costa
  • 1,004
  • 4
  • 17
  • 31

1 Answers1

0

What is the value for this MediaType.APPLICATION_XML_VALUE ? Is it same as application/xml ?

johncena
  • 102
  • 6