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

Last change on this file since 817 was 654, checked in by keesvb, 10 years ago

updated sample and study tests, added belongsTo to Sample (which gives it its parent), tried to write the unique name constraint of Sample and wrote a test for it

  • Property svn:keywords set to Date Author Rev
File size: 2.7 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: 654 $
16 * $Author: keesvb $
17 * $Date: 2010-07-15 12:26:48 +0000 (do, 15 jul 2010) $
18 */
19class StudyTests extends GrailsUnitTestCase {
20
21        final String testStudyName = "Test study"
22        final String testStudyTemplateName = "Academic study"
23        final String testStudyCode = "AAA-Test"
24        final Date testStudyStartDate = Date.parse('yyyy-MM-dd','2007-12-11')
25        final Date testStudyStartDate2 = Date.parse('yyyy-MM-dd','2008-05-11')
26        final String testStudyStartDateString2 = "11-5-2008"
27        // The following dates do net yet work:
28        //final String testStudyStartDateString2 = "11-05-2010"
29        //final String testStudyStartDateString2 = "Tue Dec 13 00:00:00 EST 2008"
30
31        protected void setUp() {
32                super.setUp()
33
34                // Look up academic template
35                def studyTemplate = Template.findByName(testStudyTemplateName)
36                assert studyTemplate
37
38                def study = new Study(
39                        title: testStudyName,
40                        template: studyTemplate,
41                        startDate: testStudyStartDate,
42                        code: testStudyCode
43                )
44
45                if (!study.validate()) {
46                        study.errors.each { println it}
47                }
48                assert study.validate()
49
50
51                assert study.save(flush: true)
52
53        }
54
55        void testSave() {
56                // Try to retrieve the study and make sure it's the same
57                def studyDB = Study.findByCode(testStudyCode)
58                assert studyDB
59                assert studyDB.title.equals(testStudyName)
60                assert studyDB.code.equals(testStudyCode)
61                assert studyDB.template.name.equals(testStudyTemplateName)
62                assert studyDB.startDate.equals(testStudyStartDate)
63
64                // A study without a title should not be saveable
65                studyDB.title = null
66                assert !studyDB.validate()
67        }
68
69        void testDomainFields() {
70                def study = Study.findByCode(testStudyCode)
71                assert study
72
73                // Make sure the domain fields exist
74                assert study.fieldExists('title')
75                assert study.fieldExists('startDate')
76                assert study.fieldExists('code')
77
78
79                // Make sure they are domain fields
80                assert study.isDomainField('title')
81                assert study.isDomainField('startDate')
82                assert study.isDomainField('code')
83               
84        }
85
86        void testSetDate() {
87                def study = Study.findByCode(testStudyCode)
88                assert study
89
90                // Set a new date, using a string, and check whether that is stored correctly
91                study.setFieldValue("startDate",testStudyStartDateString2)
92                assert study.validate()
93                assert study.save(flush:true)
94                assert study.getFieldValue("startDate").equals(testStudyStartDate2) 
95
96        }
97
98        protected void tearDown() {
99
100                // Delete the created study
101                /*def study = Study.findByCode(testStudyCode)
102                assert study
103
104                study.delete()
105                assert Study.findByCode(testStudyCode) == null
106                */
107                super.tearDown()
108        }
109
110}
Note: See TracBrowser for help on using the repository browser.