title: How do populate valid params in a grails test
body: <p>Kinda new here in groovy and grails. I tried to run <code>grails install-templates</code> and saw the generated test.groovy which looks like this...</p>
  
  <pre><code>`&lt;%=packageName ? "package ${packageName}\n\n" : ''%&gt;
  
  import org.junit.*
  import grails.test.mixin.*
  
  @TestFor(${className}Controller)
  @Mock(${className})
  class ${className}ControllerTests {
  
  
      def populateValidParams(params) {
        assert params != null
        // TODO: Populate valid properties like...
        //params["name"] = 'someValidName'
      }
  
      void testIndex() {
          controller.index()
          assert "/$propertyName/list" == response.redirectedUrl
      }
  
      void testList() {
  
          def model = controller.list()
  
          assert model.${propertyName}InstanceList.size() == 0
          assert model.${propertyName}InstanceTotal == 0
      }
  
      void testCreate() {
         def model = controller.create()
  
         assert model.${propertyName}Instance != null
      }
  
      void testSave() {
          controller.save()
  
          assert model.${propertyName}Instance != null
          assert view == '/${propertyName}/create'
  
          response.reset()
  
          populateValidParams(params)
          controller.save()
  
          assert response.redirectedUrl == '/${propertyName}/show/1'
          assert controller.flash.message != null
          assert ${className}.count() == 1
      }
  
      void testShow() {
          controller.show()
  
          assert flash.message != null
          assert response.redirectedUrl == '/${propertyName}/list'
  
  
          populateValidParams(params)
          def ${propertyName} = new ${className}(params)
  
          assert ${propertyName}.save() != null
  
          params.id = ${propertyName}.id
  
          def model = controller.show()
  
          assert model.${propertyName}Instance == ${propertyName}
      }
  
      void testEdit() {
          controller.edit()
  
          assert flash.message != null
          assert response.redirectedUrl == '/${propertyName}/list'
  
  
          populateValidParams(params)
          def ${propertyName} = new ${className}(params)
  
          assert ${propertyName}.save() != null
  
          params.id = ${propertyName}.id
  
          def model = controller.edit()
  
          assert model.${propertyName}Instance == ${propertyName}
      }
  
      void testUpdate() {
          controller.update()
  
          assert flash.message != null
          assert response.redirectedUrl == '/${propertyName}/list'
  
          response.reset()
  
  
          populateValidParams(params)
          def ${propertyName} = new ${className}(params)
  
          assert ${propertyName}.save() != null
  
          // test invalid parameters in update
          params.id = ${propertyName}.id
          //TODO: add invalid values to params object
  
          controller.update()
  
          assert view == "/${propertyName}/edit"
          assert model.${propertyName}Instance != null
  
          ${propertyName}.clearErrors()
  
          populateValidParams(params)
          controller.update()
  
          assert response.redirectedUrl == "/${propertyName}/show/\$${propertyName}.id"
          assert flash.message != null
  
          //test outdated version number
          response.reset()
          ${propertyName}.clearErrors()
  
          populateValidParams(params)
          params.id = ${propertyName}.id
          params.version = -1
          controller.update()
  
          assert view == "/${propertyName}/edit"
          assert model.${propertyName}Instance != null
          assert model.${propertyName}Instance.errors.getFieldError('version')
          assert flash.message != null
      }
  
      void testDelete() {
          controller.delete()
          assert flash.message != null
          assert response.redirectedUrl == '/${propertyName}/list'
  
          response.reset()
  
          populateValidParams(params)
          def ${propertyName} = new ${className}(params)
  
          assert ${propertyName}.save() != null
          assert ${className}.count() == 1
  
          params.id = ${propertyName}.id
  
          controller.delete()
  
          assert ${className}.count() == 0
          assert ${className}.get(${propertyName}.id) == null
          assert response.redirectedUrl == '/${propertyName}/list'
      }
  }`
  </code></pre>
  
  <p>So I copied it to the appropriate controller test and changed all the ${propertyName} and ${className} as such. testIndex() testList() and testCreate() passed, but testSave(), testUpdate(), testDelete() and testEdit() failed. I suppose that I need to fill in this part:</p>
  
  <pre><code>def populateValidParams(params) {
        assert params != null
        // TODO: Populate valid properties like...
        //params["name"] = 'someValidName'
      }
  </code></pre>
  
  <p>So I did and the method looks like this:</p>
  
  <pre><code>def populateValidParams(params) {
    assert params != null
    // TODO: Populate valid properties like...
    //params["name"] = 'someValidName'
  
    params["company"] = 'someCompany'
    params["position"] = 'somePosition'
    params["responsibilities"] = 'someResponsibility'
    params["startDate"] = new Date ('2007/01/01')
    params["endDate"] = new Date ('2010/01/01')
  
  }
  </code></pre>
  
  <p>but still the test fails.. Am I doing something wrong? I think I'm doing it wrong with the params.. I'm a bit unfamiliar with that kind of groovy type..
  This is the stacktrace for save</p>
  
  <pre><code>    junit.framework.AssertionFailedError: Assertion failed: 
  
  assert response.redirectedUrl == '/employmentHistory/show/1'
         |        |             |
         |        null          false
         org.codehaus.groovy.grails.plugins.testing.GrailsMockHttpServletResponse@737611
  
      at com.someapp.controller.EmploymentHistoryControllerTests.testSave(EmploymentHistoryControllerTests.groovy:63)
  </code></pre>
  
  <p>for show:</p>
  
  <pre><code>    junit.framework.AssertionFailedError: Assertion failed: 
  
  assert employmentHistory.save() != null
         |                 |      |
         |                 null   false
         com.someapp.domain.EmploymentHistory : null
  
      at com.someapp.controller.EmploymentHistoryControllerTests.testShow(EmploymentHistoryControllerTests.groovy:78)
  </code></pre>
  
  <p>for edit:</p>
  
  <pre><code>    junit.framework.AssertionFailedError: Assertion failed: 
  
  assert employmentHistory.save() != null
         |                 |      |
         |                 null   false
         com.someapp.domain.EmploymentHistory : null
  
      at com.someapp.controller.EmploymentHistoryControllerTests.testEdit(EmploymentHistoryControllerTests.groovy:97)
  </code></pre>