Announcement Announcement Module
Collapse
No announcement yet.
mockDomain - problem with composite ID Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • mockDomain - problem with composite ID

    I am trying to test a fairly straightforward show closure in a controller which attempts to get the object to show by supplying an instance of the object populated with the 'key fields' as follows:
    Code:
    def actionInstance = Action.get(new Action(sortOrder:params.sortOrder, actionAlias:params.actionAlias))
    The mapping for the ID is:
    Code:
    id composite:["actionAlias", "sortOrder"], generator:'assigned'
    The test is:
    Code:
        void testShowSuccess()
        {
          Map parameters = [sortOrder:'AAA', actionAlias:'action1',
            dbUtilsAction:'FTP', alias:'alias1', compressFlag:'N']
          mockDomain(Action, [new Action(parameters)])
          controller.params.sortOrder = 'AAA'
          controller.params.actionAlias = 'action1'
    
          def results = controller.show()
    ....
    I am receiving the following error:
    Code:
    Failed to convert value of type 'uk.co.utilisoft.dtcdbutils.Action' to required type 'java.lang.Long'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [uk.co.utilisoft.dtcdbutils.Action] to required type [java.lang.Long]: PropertyEditor [org.springframework.beans.propertyeditors.CustomNumberEditor] returned inappropriate value
    
    org.springframework.beans.TypeMismatchException: Failed to convert value of type 'uk.co.utilisoft.dtcdbutils.Action' to required type 'java.lang.Long'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [uk.co.utilisoft.dtcdbutils.Action] to required type [java.lang.Long]: PropertyEditor [org.springframework.beans.propertyeditors.CustomNumberEditor] returned inappropriate value
    at grails.test.MockUtils.convertToType(MockUtils.groovy:1264)
    at grails.test.MockUtils$_addGetMethods_closure58.doCall(MockUtils.groovy:660)
    at uk.co.utilisoft.dtcdbutils.ActionController$_closure7.doCall(ActionController.groovy:75)
    at uk.co.utilisoft.dtcdbutils.ActionController$_closure7.doCall(ActionController.groovy)
    at uk.co.utilisoft.dtcdbutils.ActionControllerTests.testShowSuccess(ActionControllerTests.groovy:180)
    Caused by: java.lang.IllegalArgumentException: Cannot convert value of type [uk.co.utilisoft.dtcdbutils.Action] to required type [java.lang.Long]: PropertyEditor [org.springframework.beans.propertyeditors.CustomNumberEditor] returned inappropriate value
    at grails.test.MockUtils.convertToType(MockUtils.groovy:1264)
    at grails.test.MockUtils$_addGetMethods_closure58.doCall(MockUtils.groovy:660)
    at uk.co.utilisoft.dtcdbutils.ActionController$_closure7.doCall(ActionController.groovy:75)
    at uk.co.utilisoft.dtcdbutils.ActionController$_closure7.doCall(ActionController.groovy)
    at uk.co.utilisoft.dtcdbutils.ActionControllerTests.testShowSuccess(ActionControllerTests.groovy:180)
    Is this a bug because mockDomain is unable to cope with composite IDs and is expecting a numeric ID or am I missing something?

  • #2
    mockDomain() as it stands is limited and doesn't support composite IDs. You have two options: use integration tests or try the new mocking support described here:

    http://grails.1312388.n4.nabble.com/...td2529895.html

    Comment


    • #3
      Thanks for the information, Peter. I ended up using integration tests, but the new mocking support looks useful, so I'll give that a go the next opportunity I get.

      Comment

      Working...
      X