Changeset 653 for trunk/test
- Timestamp:
- Jul 15, 2010, 1:01:53 PM (13 years ago)
- Location:
- trunk/test/integration/gscf
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/integration/gscf/SampleTests.groovy
r651 r653 1 1 package gscf 2 2 3 import grails.test.* 4 import dbnp.studycapturing.* 5 import dbnp.data.* 3 import dbnp.studycapturing.Study 4 import dbnp.studycapturing.Template 5 import grails.test.GrailsUnitTestCase 6 import dbnp.studycapturing.SamplingEvent 7 import dbnp.studycapturing.Sample 6 8 7 9 /** 8 * Test the creation of a S ubjectand its TemplateEntity functionality on data model level10 * Test the creation of a Sample and its TemplateEntity functionality on data model level 9 11 * 10 12 * @author keesvb … … 17 19 * $Date$ 18 20 */ 19 class StudyTests extends GrailsUnitTestCase {20 21 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" 22 class SampleTests extends StudyTests { 23 24 // This test extends StudyTests, so that we have a test study to assign as a parent study 25 26 final String testSampleName = "Test sample" 27 final String testSampleTemplateName = "Human blood sample" 28 29 final String testSamplingEventName = "Test sampling event" 30 final String testSamplingEventTemplateName = "Blood extraction" 31 final long testSamplingEventTime = 34534534L 32 29 33 30 34 protected void setUp() { 31 35 super.setUp() 32 36 33 // Look up academic template34 def study Template = Template.findByName(testStudyTemplateName)35 assert study Template37 // Retrieve the study that should have been created in StudyTests 38 def study = Study.findByTitle(testStudyName) 39 assert study 36 40 37 def study = new Study( 38 title: testStudyName, 39 template: studyTemplate, 40 startDate: testStudyStartDate 41 // Look up sampling event template 42 def samplingEventTemplate = Template.findByName(testSamplingEventTemplateName) 43 assert samplingEventTemplate 44 45 // Create parent sampling event 46 def samplingEvent = new SamplingEvent( 47 startTime: testSamplingEventTime, 48 endTime: testSamplingEventTime, 49 template: samplingEventTemplate 41 50 ) 42 51 43 if (!s tudy.validate()) {44 s tudy.errors.each { println it}52 if (!samplingEvent.validate()) { 53 samplingEvent.errors.each { println it} 45 54 } 46 assert s tudy.validate()55 assert samplingEvent.validate() 47 56 48 57 49 assert study.save(flush: true) 58 // Look up sample template 59 def sampleTemplate = Template.findByName(testSampleTemplateName) 60 assert sampleTemplate 61 62 // Create sample with the retrieved study as parent 63 def sample = new Sample( 64 name: testSampleName, 65 template: sampleTemplate, 66 parentEvent: samplingEvent 67 ) 68 69 // At this point, the sample should not validate, because it doesn't have a parent study assigned 70 assert !sample.validate() 71 72 // Add the sample to the retrieved parent study 73 study.addToSamples(sample) 74 assert study.samples.find { it.name == sample.name} 75 76 // Now, the sample should validate 77 if (!sample.validate()) { 78 sample.errors.each { println it} 79 } 80 assert sample.validate() 81 82 // Make sure the sample is saved to the database 83 assert sample.save(flush: true) 50 84 51 85 } 52 86 53 87 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) 88 // Try to retrieve the sample and make sure it's the same 89 def sampleDB = Sample.findByName(testSampleName) 90 assert sampleDB 91 assert sampleDB.name.equals(testSampleName) 92 assert sampleDB.template.name.equals(testSampleTemplateName) 93 assert sampleDB.parentEvent 94 assert sampleDB.parentEvent.startTime.equals(testSamplingEventTime) 60 95 61 // A study without a title should not be saveable 62 studyDB.title = null 63 assert !studyDB.validate() 96 // A sample without a name should not be saveable 97 sampleDB.name = null 98 assert !sampleDB.validate() 99 100 // A sample without a parent SamplingEvent should not be saveable 101 sampleDB.name = testSampleName 102 sampleDB.parentEvent = null 103 assert !sampleDB.validate() 104 } 105 106 void testStudyRelation() { 107 // Retrieve the parent study 108 def study = Study.findByTitle(testStudyName) 109 assert study 110 111 // Test giveSamplingEventTemplates 112 def templates = study.giveSamplingEventTemplates() 113 assert templates 114 assert templates.size() == 1 115 assert templates 116 117 // Test if the sample is in the samples collection 118 assert study.samples 119 assert study.samples.size() == 1 120 assert study.samples.first().name == testSampleName 121 } 122 123 void testFindViaSamplingEvent() { 124 // Try to retrieve the sampling event by using the time... 125 // (should be also the parent study but that's not yet implemented) 126 def samplingEventDB = SamplingEvent.findByStartTime(testSamplingEventTime) 127 assert samplingEventDB 128 129 def samples = samplingEventDB.getSamples() 130 assert samples 131 assert samples.size() == 1 132 assert samples.first().name == testSampleName 64 133 } 65 134 66 135 void testDomainFields() { 67 def s tudy = Study.findByTitle(testStudyName)68 assert s tudy136 def sample = Sample.findByName(testStudyName) 137 assert sample 69 138 70 139 // Make sure the domain fields exist 71 assert s tudy.fieldExists('title')72 assert s tudy.fieldExists('startDate')140 assert sample.fieldExists('name') 141 assert sample.fieldExists('material') 73 142 74 143 // 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) 144 assert sample.isDomainField('name') 145 assert sample.isDomainField('material') 89 146 90 147 } -
trunk/test/integration/gscf/StudyTests.groovy
r496 r653 21 21 final String testStudyName = "Test study" 22 22 final String testStudyTemplateName = "Academic study" 23 final String testStudyCode = "AAA-Test" 23 24 final Date testStudyStartDate = Date.parse('yyyy-MM-dd','2007-12-11') 24 25 final Date testStudyStartDate2 = Date.parse('yyyy-MM-dd','2008-05-11') … … 36 37 37 38 def study = new Study( 38 title: testStudyName, 39 template: studyTemplate, 40 startDate: testStudyStartDate 39 title: testStudyName, 40 template: studyTemplate, 41 startDate: testStudyStartDate, 42 code: testStudyCode 41 43 ) 42 44 … … 53 55 void testSave() { 54 56 // Try to retrieve the study and make sure it's the same 55 def studyDB = Study.findBy Title(testStudyName)57 def studyDB = Study.findByCode(testStudyCode) 56 58 assert studyDB 57 59 assert studyDB.title.equals(testStudyName) 60 assert studyDB.code.equals(testStudyCode) 58 61 assert studyDB.template.name.equals(testStudyTemplateName) 59 62 assert studyDB.startDate.equals(testStudyStartDate) … … 65 68 66 69 void testDomainFields() { 67 def study = Study.findBy Title(testStudyName)70 def study = Study.findByCode(testStudyCode) 68 71 assert study 69 72 … … 71 74 assert study.fieldExists('title') 72 75 assert study.fieldExists('startDate') 76 assert study.fieldExists('code') 77 73 78 74 79 // Make sure they are domain fields 75 80 assert study.isDomainField('title') 76 81 assert study.isDomainField('startDate') 82 assert study.isDomainField('code') 77 83 78 84 } 79 85 80 86 void testSetDate() { 81 def study = Study.findBy Title(testStudyName)87 def study = Study.findByCode(testStudyCode) 82 88 assert study 83 89 … … 91 97 92 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 93 107 super.tearDown() 94 108 }
Note: See TracChangeset
for help on using the changeset viewer.