DomainClassUnitTestMixin (Grails 3.2.7)
Date: 2017-03-06

Package: grails.test.mixin.domain

## [Groovy] Class DomainClassUnitTestMixin

- grails.test.mixin.domain.DomainClassUnitTestMixin

- A mixin that can be applied to JUnit or Spock tests to add testing support to a users test classes. Can be used in combination with ControllerUnitTestMixin to fully test controller interaction with domains without needing a database

  The majority of GORM features are mocked by this unit test mixin including:

  - Dynamic finders
  - Criteria queries
  - Basic persistence methods
  - Validation
  - Data binding

  Mocking can be applied to any domain class by simply calling the DomainClassUnitTestMixin.mockDomain method

  Authors:
    Graeme Rocher
  Since:
    2.0

- - ### Constructor Summary

    Constructors
    Constructor and description
    `DomainClassUnitTestMixin (java.util.Set<java.lang.String> features)`
    `DomainClassUnitTestMixin ()`

  - ### Methods Summary

    Methods
    Type | Name and description
    --- | ---
    `protected void` | `enhanceSingleEntity(org.grails.datastore.mapping.model.PersistentEntity entity)`
    `protected java.lang.Object` | `getFailOnError()`
    `org.grails.datastore.mapping.simple.SimpleMapDatastore` | `getSimpleDatastore()`
    `org.springframework.transaction.PlatformTransactionManager` | `getTransactionManager()`
    `protected void` | `initialMockDomainSetup()`
    `protected void` | `initializeMappingContext()`
    `java.lang.Object` | `mockDomain(java.lang.Class<?> domainClassToMock, java.util.List domains = [])` Mocks a domain class providing the equivalent GORM behavior but against an in-memory concurrent hash map instead of a database
    `java.lang.Object` | `mockDomains(java.lang.Class<?>... domainClassesToMock)`
    `protected org.springframework.validation.Validator` | `registerDomainClassValidator(GrailsDomainClass domain)`
    `protected GrailsDomainClass` | `registerGrailsDomainClass(java.lang.Class<?> domainClassToMock)`
    `protected void` | `saveDomainList(org.grails.datastore.mapping.model.PersistentEntity entity, java.util.List domains)`

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class GrailsUnitTestMixin` | `defineBeans, getApplicationContext, getConfig, getGrailsApplication, getMainContext, getMessageSource, mockCodec, shouldFail, shouldFail`
    `class TestMixinRuntimeSupport` | `getFeatures, getRuntime, setRuntime, setTestClass`
    `class groovy.lang.GroovyObjectSupport` | `groovy.lang.GroovyObjectSupport#setProperty(java.lang.String, java.lang.Object), groovy.lang.GroovyObjectSupport#getProperty(java.lang.String), groovy.lang.GroovyObjectSupport#getMetaClass(), groovy.lang.GroovyObjectSupport#setMetaClass(groovy.lang.MetaClass), groovy.lang.GroovyObjectSupport#invokeMethod(java.lang.String, java.lang.Object), groovy.lang.GroovyObjectSupport#wait(long, int), groovy.lang.GroovyObjectSupport#wait(long), groovy.lang.GroovyObjectSupport#wait(), groovy.lang.GroovyObjectSupport#equals(java.lang.Object), groovy.lang.GroovyObjectSupport#toString(), groovy.lang.GroovyObjectSupport#hashCode(), groovy.lang.GroovyObjectSupport#getClass(), groovy.lang.GroovyObjectSupport#notify(), groovy.lang.GroovyObjectSupport#notifyAll()`

- - ### Constructor Detail

    - #### DomainClassUnitTestMixin(java.util.Set<java.lang.String> features)

    - #### DomainClassUnitTestMixin()

  - ### Method Detail

    - #### protected void enhanceSingleEntity(org.grails.datastore.mapping.model.PersistentEntity entity)

    - #### protected java.lang.Object getFailOnError()

    - #### org.grails.datastore.mapping.simple.SimpleMapDatastore getSimpleDatastore()

    - #### org.springframework.transaction.PlatformTransactionManager getTransactionManager()

    - #### protected void initialMockDomainSetup()

    - #### protected void initializeMappingContext()

    - #### @groovy.transform.CompileStatic java.lang.Object mockDomain(java.lang.Class<?> domainClassToMock, java.util.List domains = [])

      Mocks a domain class providing the equivalent GORM behavior but against an in-memory concurrent hash map instead of a database

      Parameters:
        `domainClassToMock` - The domain class to mock
      Returns:
        An instance of the mocked domain class

    - #### @groovy.transform.CompileStatic java.lang.Object mockDomains(java.lang.Class<?>... domainClassesToMock)

    - #### protected org.springframework.validation.Validator registerDomainClassValidator(GrailsDomainClass domain)

    - #### @groovy.transform.CompileStatic protected GrailsDomainClass registerGrailsDomainClass(java.lang.Class<?> domainClassToMock)

    - #### protected void saveDomainList(org.grails.datastore.mapping.model.PersistentEntity entity, java.util.List domains)