unit testing - Grails PUT request with XML -


I have put a request I'm trying to unit test to create a user object.

Unit Test:

  void testPUTXMLResponse () {def mockUser = new user (user name "Fred", password: Userkencrypt ( "Letmein"), FirstName "Fred", LastName "Flintstone", MiddleName: "T", phone: "555-555-5555", email: 'fred@fred.com', activationDate: new date (), logonFailureCount: 0) mockDomain ( user, [mockUser]) def mockUserXML = mockUser XML mockRequest.method = 'put' mockRequest.contentType = 'text / xml' mockRequest.format = 'xml' as mockRequest.content = mockUserXML.toString (). getBytes () controller.create () def updatedUser = XML.parse (mockResponse.contentAsString) stressed updatedUser.id == 1}  

controller action:

  def = {println If request.xml def user = new user (params.user) (! user.hasErrors () & amp; & amp; user.save ()) {println user.id withFormat {html {/ * (Presenting the scene: "show", [user: user]) * XML} submission to user as XML} Jason (r) as JSON}}} {} format with println user.errors {Html} / {render (see: "create", [User: user]) * /} XML {user as XML. JSON}}}} as an error  

Paramaps map is empty for some reasons if the administrator's action is executed. I have a very similar unit test for POST requests and it works fine.

Grails natively supports rest, Grails applies HTTP specification for PUT and POST. One of the rules of PUT is that it requires a complete URL, which includes the object ID. In this case, when creating a new user, the ID is not known until after the request. Therefore, the full URL is not known and the PUT request fails. POST does not have this restriction For more detailed details of PUT and POST, see


Comments