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

Last change on this file since 406 was 406, checked in by keesvb, 11 years ago

added study tests, skip study adds when in test environment in bootstrap, refactored TemplateEntity?

File size: 1.9 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-2010"
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
62        void testSetDate() {
63                def study = Study.findByTitle(testStudyName)
64                assert study
65
66                // Set a new date, using a string, and check whether that is stored correctly
67                study.setFieldValue("startDate",testStudyStartDateString2)
68                assert study.validate()
69                assert study.save(flush:true)
70                assert study.getFieldValue("startDate").equals(testStudyStartDate2) 
71
72        }
73
74        protected void tearDown() {
75                super.tearDown()
76        }
77
78}
Note: See TracBrowser for help on using the repository browser.