source: trunk/test/integration/gscf/StudyTests.groovy @ 487

Last change on this file since 487 was 487, checked in by roberth, 11 years ago

Added net RELTIME template field type to contain relative times (e.g. 1d 3h). The type has been added as template type, but will probably not be rendered correctly yet.

File size: 2.4 KB
Line 
1package gscf
2
3import grails.test.*
4import dbnp.studycapturing.*
5import dbnp.data.*
6
7/**
8 * Test the creation of a Subject and its TemplateEntity functionality on data model level
9 *
10 * @author keesvb
11 * @since 20100511
12 * @package dbnp.studycapturing
13 *
14 * Revision information:
15 * $Rev$
16 * $Author$
17 * $Date$
18 */
19class StudyTests extends GrailsUnitTestCase {
20
21        final String testStudyName = "Test study"
22        final String testStudyTemplateName = "Academic study"
23        final Date testStudyStartDate = Date.parse('yyyy-MM-dd','2007-12-11')
24        final Date testStudyStartDate2 = Date.parse('yyyy-MM-dd','2008-05-11')
25        final String testStudyStartDateString2 = "11-5-2008"
26        // The following dates do net yet work:
27        //final String testStudyStartDateString2 = "11-05-2010"
28        //final String testStudyStartDateString2 = "Tue Dec 13 00:00:00 EST 2008"
29
30        protected void setUp() {
31                super.setUp()
32
33                // Look up academic template
34                def studyTemplate = Template.findByName(testStudyTemplateName)
35                assert studyTemplate
36
37                def study = new Study(
38                    title: testStudyName,
39                    template: studyTemplate,
40                    startDate: testStudyStartDate
41                )
42
43                if (!study.validate()) {
44                        study.errors.each { println it}
45                }
46                assert study.validate()
47
48
49                assert study.save(flush: true)
50
51        }
52
53        void testSave() {
54                // Try to retrieve the study and make sure it's the same
55                def studyDB = Study.findByTitle(testStudyName)
56                assert studyDB
57                assert studyDB.title.equals(testStudyName)
58                assert studyDB.template.name.equals(testStudyTemplateName)
59                assert studyDB.startDate.equals(testStudyStartDate)
60
61                // A study without a title should not be saveable
62                studyDB.title = null
63                assert !studyDB.validate()
64        }
65
66        void testDomainFields() {
67                def study = Study.findByTitle(testStudyName)
68                assert study
69
70                // Make sure the domain fields exist
71                assert study.fieldExists('title')
72                assert study.fieldExists('startDate')
73
74                // Make sure they are domain fields
75                assert study.isDomainField('title')
76                assert study.isDomainField('startDate')
77               
78        }
79
80        void testSetDate() {
81                def study = Study.findByTitle(testStudyName)
82                assert study
83
84                // Set a new date, using a string, and check whether that is stored correctly
85                study.setFieldValue("startDate",testStudyStartDateString2)
86                assert study.validate()
87                assert study.save(flush:true)
88                assert study.getFieldValue("startDate").equals(testStudyStartDate2) 
89
90        }
91
92        protected void tearDown() {
93                super.tearDown()
94        }
95
96}
Note: See TracBrowser for help on using the repository browser.