public
Description: sample app used to figure out grails testing plugin
Homepage:
Clone URL: git://github.com/mjhugo/bookstore.git
bookstore / test / unit / AuthorTests.groovy
100644 28 lines (20 sloc) 0.722 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class AuthorTests extends grails.test.GrailsUnitTestCase {
 
    Author author
 
    void setUp() {
        super.setUp()
 
        // in testing-plugin 0.4 you can just do "mockForConstraintsTests(Book)" instead of these two lines
        registerMetaClass(Author)
        grails.test.MockUtils.prepareForConstraintsTests(Author)
 
        author = new Author(firstName: 'Michael', lastName: 'Scott')
        assertTrue author.validate()
    }
 
    void testFirsNameConstraint() {
        author.firstName = null
        assertTrue author.validate()
    }
 
    void testLastNameConstraint() {
        author.lastName = ''
        assertFalse author.validate()
        assertEquals "blank", author.errors["lastName"]
    }
 
}