Changeset 964 for trunk/test
- Timestamp:
- Oct 21, 2010, 3:04:57 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/integration/gscf/SampleTests.groovy
r959 r964 44 44 assert study 45 45 46 // Look up sample template 47 def sampleTemplate = Template.findByName(testSampleTemplateName) 48 assert sampleTemplate 49 50 // Create sample with the retrieved study as parent 51 def sample = new Sample( 52 name: testSampleName, 53 template: sampleTemplate 54 ) 55 56 // At this point, the sample should not validate, because it doesn't have a parent study assigned 57 assert !sample.validate() 58 59 // Add the sample to the retrieved parent study 60 study.addToSamples(sample) 61 assert study.samples.find { it.name == sample.name} 62 63 // Now, the sample should validate 64 if (!sample.validate()) { 65 sample.errors.each { println it} 66 } 67 assert sample.validate() 68 69 // Make sure the sample is saved to the database 70 assert sample.save(flush: true) 71 72 } 73 74 private void addParentSamplingEvent() { 75 76 // Retrieve the sample 77 def sampleDB = Sample.findByName(testSampleName) 78 assert sampleDB 79 80 // Retrieve the study that should have been created in StudyTests 81 def study = Study.findByTitle(testStudyName) 82 assert study 83 46 84 // Look up sampling event template 47 85 def samplingEventTemplate = Template.findByName(testSamplingEventTemplateName) 48 86 assert samplingEventTemplate 49 50 // Look up sample template51 def sampleTemplate = Template.findByName(testSampleTemplateName)52 assert sampleTemplate53 87 54 88 // Create parent sampling event … … 57 91 duration: testSamplingEventDuration, 58 92 template: samplingEventTemplate, 59 sampleTemplate: sampleTemplate93 sampleTemplate: Template.findByName(testSampleTemplateName) 60 94 ) 61 95 … … 68 102 assert samplingEvent.save(flush:true) 69 103 70 // Create sample with the retrieved study as parent 71 def sample = new Sample( 72 name: testSampleName, 73 template: sampleTemplate, 74 parentEvent: samplingEvent 75 ) 76 77 // At this point, the sample should not validate, because it doesn't have a parent study assigned 78 assert !sample.validate() 79 80 // Add the sample to the retrieved parent study 81 study.addToSamples(sample) 82 assert study.samples.find { it.name == sample.name} 83 84 // Now, the sample should validate 85 if (!sample.validate()) { 86 sample.errors.each { println it} 87 } 88 assert sample.validate() 89 90 // Make sure the sample is saved to the database 91 assert sample.save(flush: true) 92 104 // Add sample to the sampling event 105 samplingEvent.addToSamples(sampleDB) 106 107 // Make sure the sampling event is really the parent event of the sample 108 assert sampleDB.parentEvent 109 assert sampleDB.parentEvent == samplingEvent 110 assert sampleDB.parentEvent.startTime.equals(testSamplingEventTime) 111 112 } 113 114 void testStudyPublish() { 115 def sampleDB = Sample.findByName(testSampleName) 116 assert sampleDB 117 118 // Retrieve the parent study 119 def study = Study.findByTitle(testStudyName) 120 assert study 121 122 // Make sure the study validates at this point 123 assert study.validate() 124 125 // Try to publish the study, should fail as it has a sample without a parent sampling event 126 //study.published = true 127 assert !study.validate() 128 129 // Add parent sampling event 130 addParentSamplingEvent() 131 132 // Add parent subject 133 134 // Now the study should validate 135 assert study.validate() 93 136 } 94 137 … … 100 143 assert sampleDB.name.equals(testSampleName) 101 144 assert sampleDB.template.name.equals(testSampleTemplateName) 102 assert sampleDB.parentEvent103 assert sampleDB.parentEvent.startTime.equals(testSamplingEventTime)104 145 105 146 println "The sample has parentEvent ${sampleDB.parentEvent.encodeAsHTML()}" … … 108 149 assert !sampleDB.validate() 109 150 110 // A sample without a parent SamplingEvent should not be saveable111 sampleDB.name = testSampleName112 sampleDB.parentEvent = null113 assert !sampleDB.validate()114 151 } 115 152 116 153 void testDelete() { 117 154 def sampleDB = Sample.findByName(testSampleName) 155 assert sampleDB 118 156 sampleDB.delete() 119 157 try { … … 177 215 assert study 178 216 217 // Add parent sampling event 218 addParentSamplingEvent() 219 179 220 def event = sampleDB.parentEvent 180 221 assert event … … 205 246 206 247 // Retrieve the sample's sampling event 248 addParentSamplingEvent() 207 249 def event = sampleDB.parentEvent 208 250 assert event … … 229 271 assert study.save() 230 272 231 // Use the delete SamplingEventmethod273 // Use the deleteEventGroup method 232 274 def msg = study.deleteEventGroup(group) 233 275 println msg 276 if (!study.validate()) { 277 study.errors.each { println it} 278 } 279 assert study.validate() 280 234 281 assert study.save() 235 282 … … 326 373 327 374 void testFindViaSamplingEvent() { 375 376 // Add parent sampling event 377 addParentSamplingEvent() 378 328 379 // Try to retrieve the sampling event by using the time... 329 380 // (should be also the parent study but that's not yet implemented) … … 334 385 assert samples 335 386 assert samples.size() == 1 336 assert samples. first().name == testSampleName387 assert samples.every {it.name == testSampleName} 337 388 } 338 389
Note: See TracChangeset
for help on using the changeset viewer.