DomainClassUnitTestMixin (Grails 2.3.8)
Date: 2014-04-24

Overview | Package | Class | Deprecated | Index | Help
| Groovy Documentation
| FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | PROPERTY | CONSTR | METHOD | DETAIL: FIELD | PROPERTY | CONSTR | METHOD

## grails.test.mixin.domain
[Groovy] Class DomainClassUnitTestMixin

    java.lang.Object
      grails.test.mixin.support.GrailsUnitTestMixin
          grails.test.mixin.domain.DomainClassUnitTestMixin

    class DomainClassUnitTestMixin
    extends GrailsUnitTestMixin

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

Field Summary
`protected org.grails.datastore.mapping.core.Session` | `currentSession`

Property Summary
`static org.grails.datastore.mapping.simple.SimpleMapDatastore` | `simpleDatastore`
`static org.springframework.transaction.PlatformTransactionManager` | `transactionManager`

Method Summary
`static void` | `cleanupDatastore()`
`void` | `connectDatastore()`
`protected void` | `enhanceSingleEntity(org.grails.datastore.mapping.model.PersistentEntity entity)`
`protected java.lang.Object` | `getFailOnError()`
`protected void` | `initialMockDomainSetup()`
`static void` | `initializeDatastoreImplementation()`
`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)`
`void` | `shutdownDatastoreImplementation()`

Methods inherited from class GrailsUnitTestMixin
cleanupModifiedMetaClasses, defineBeans, deregisterMetaClassCleaner, initGrailsApplication, mockCodec, mockFor, mockForConstraintsTests, registerBeans, registerMetaClassRegistryWatcher, resetGrailsApplication, shouldFail, shouldFail, shutdownApplicationContext

Methods inherited from class java.lang.Object
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()

Field Detail

### currentSession

    protected org.grails.datastore.mapping.core.Session currentSession

Property Detail

### simpleDatastore

    static org.grails.datastore.mapping.simple.SimpleMapDatastore simpleDatastore

### transactionManager

    static org.springframework.transaction.PlatformTransactionManager transactionManager

Method Detail

### cleanupDatastore

    @org.junit.AfterClass
    static void cleanupDatastore()

### connectDatastore

    @org.junit.Before
    void connectDatastore()

### enhanceSingleEntity

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

### getFailOnError

    protected java.lang.Object getFailOnError()

### initialMockDomainSetup

    protected void initialMockDomainSetup()

### initializeDatastoreImplementation

    @org.junit.BeforeClass
    static void initializeDatastoreImplementation()

### initializeMappingContext

    protected void initializeMappingContext()

### mockDomain

    @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

### mockDomains

    @groovy.transform.CompileStatic
    java.lang.Object mockDomains(java.lang.Class... domainClassesToMock)

### registerDomainClassValidator

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

### registerGrailsDomainClass

    @groovy.transform.CompileStatic
    protected GrailsDomainClass registerGrailsDomainClass(java.lang.Class domainClassToMock)

### saveDomainList

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

### shutdownDatastoreImplementation

    @org.junit.After
    void shutdownDatastoreImplementation()

Groovy Documentation