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

Last change on this file since 1588 was 1588, checked in by s.h.sikkema@…, 11 years ago

Fixed tests (except webtests); cleaned up Example{Studies,Templates}.groovy; decapitalized injected services; made 'transactional' properties static

  • Property svn:keywords set to Rev Author Date
File size: 2.4 KB
Line 
1package gscf
2
3import grails.test.*
4import dbnp.studycapturing.*
5import org.dbnp.gdt.Template
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: 1588 $
16 * $Author: s.h.sikkema@gmail.com $
17 * $Date: 2011-03-04 11:30:52 +0000 (vr, 04 mrt 2011) $
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 String testStudyDescription = "Description of Test Study"
25        final Date testStudyStartDate = Date.parse('yyyy-MM-dd','2007-12-11')
26        final Date testStudyStartDate2 = Date.parse('yyyy-MM-dd','2008-05-11')
27        final String testStudyStartDateString2 = "11-5-2008"
28        // The following dates do net yet work:
29        //final String testStudyStartDateString2 = "11-05-2010"
30        //final String testStudyStartDateString2 = "Tue Dec 13 00:00:00 EST 2008"
31
32        protected void setUp() {
33                super.setUp()
34
35                // Look up academic template
36                def studyTemplate = Template.findByName(testStudyTemplateName)
37                assert studyTemplate
38
39        dbnp.configuration.ExampleStudies.addTestStudies()
40
41        }
42
43        void testSave() {
44                // Try to retrieve the study and make sure it's the same
45                def studyDB = Study.findByCode(testStudyCode)
46                assert studyDB
47                assert studyDB.title.equals(testStudyName)
48                assert studyDB.code.equals(testStudyCode)
49                assert studyDB.template.name.equals(testStudyTemplateName)
50                assert studyDB.startDate.equals(testStudyStartDate)
51
52                // A study without a title should not be saveable
53                studyDB.title = null
54                assert !studyDB.validate()
55        }
56
57        void testDomainFields() {
58                def study = Study.findByCode(testStudyCode)
59                assert study
60
61                // Make sure the domain fields exist
62                assert study.fieldExists('title')
63                assert study.fieldExists('startDate')
64                assert study.fieldExists('code')
65
66
67                // Make sure they are domain fields
68                assert study.isDomainField('title')
69                assert study.isDomainField('startDate')
70                assert study.isDomainField('code')
71
72        }
73
74        void testSetDate() {
75                def study = Study.findByCode(testStudyCode)
76                assert study
77
78                // Set a new date, using a string, and check whether that is stored correctly
79                study.setFieldValue("startDate",testStudyStartDateString2)
80                assert study.validate()
81                assert study.save(flush:true)
82                assert study.getFieldValue("startDate").equals(testStudyStartDate2)
83
84        }
85
86        protected void tearDown() {
87
88                super.tearDown()
89        }
90
91}
Note: See TracBrowser for help on using the repository browser.