Changeset 812 for trunk/test


Ignore:
Timestamp:
Aug 16, 2010, 6:04:00 PM (10 years ago)
Author:
keesvb
Message:

added Sample tests for deleting samples via parent sampling event and event group, corrected some small errors, updated BootStrap? to find out why Sample.parentEvent gets serialized into the db, still no luck...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/integration/gscf/SampleTests.groovy

    r774 r812  
    88import dbnp.studycapturing.TemplateFieldType
    99import dbnp.studycapturing.Subject
     10import dbnp.studycapturing.EventGroup
    1011
    1112/**
     
    3233        final String testSamplingEventTemplateName = "Blood extraction"
    3334        final long testSamplingEventTime = 34534534L
     35        final long testSamplingEventDuration = 1000L
     36        final String testEventGroupName = "Test Group"
    3437
    3538
     
    4548                assert samplingEventTemplate
    4649
     50                // Look up sample template
     51                def sampleTemplate = Template.findByName(testSampleTemplateName)
     52                assert sampleTemplate
     53
    4754                // Create parent sampling event
    4855                def samplingEvent = new SamplingEvent(
    4956                        startTime: testSamplingEventTime,
    50                         endTime: testSamplingEventTime,
    51                         template: samplingEventTemplate
     57                        duration: testSamplingEventDuration,
     58                        template: samplingEventTemplate,
     59                        sampleTemplate: sampleTemplate
    5260                )
    5361
     
    6270                assert samplingEvent.validate()
    6371                assert samplingEvent.save(flush:true)
    64 
    65                 // Look up sample template
    66                 def sampleTemplate = Template.findByName(testSampleTemplateName)
    67                 assert sampleTemplate
    6872
    6973                // Create sample with the retrieved study as parent
     
    9397
    9498        void testSave() {
     99
    95100                // Try to retrieve the sample and make sure it's the same
    96101                def sampleDB = Sample.findByName(testSampleName)
     
    101106                assert sampleDB.parentEvent.startTime.equals(testSamplingEventTime)
    102107
     108                println "The sample has parentEvent ${sampleDB.parentEvent.encodeAsHTML()}"
    103109                // A sample without a name should not be saveable
    104110                sampleDB.name = null
     
    157163                assert !study.subjects.contains(subject)
    158164
    159                 assert !Subject.findByName(testSampleName)
     165                assert !Subject.findByName(subject.name)
    160166                assert !Sample.findByName(testSampleName)
    161167
    162168                assert Subject.count() == 0
     169                assert Sample.count() == 0
     170
     171        }
     172
     173        void testDeleteViaParentSamplingEvent() {
     174
     175                def sampleDB = Sample.findByName(testSampleName)
     176                assert sampleDB
     177
     178                // Retrieve the parent study
     179                def study = Study.findByTitle(testStudyName)
     180                assert study
     181
     182                def event = sampleDB.parentEvent
     183                assert event
     184
     185                // Use the deleteSamplingEvent method
     186                def msg = study.deleteSamplingEvent(event)
     187                println msg
     188                assert study.save()
     189
     190                assert !study.samplingEvents.contains(event)
     191
     192                assert !SamplingEvent.findByStartTime(testSamplingEventTime)
     193                assert !Sample.findByName(testSampleName)
     194
     195                assert SamplingEvent.count() == 0
     196                assert Sample.count() == 0
     197
     198        }
     199
     200        void testDeleteViaParentEventGroup() {
     201
     202                def sampleDB = Sample.findByName(testSampleName)
     203                assert sampleDB
     204
     205                // Retrieve the parent study
     206                def study = Study.findByTitle(testStudyName)
     207                assert study
     208
     209                // Retrieve the sample's sampling event
     210                def event = sampleDB.parentEvent
     211                assert event
     212
     213                // Create a subject and add it at the sample's parent
     214                def subject = SubjectTests.createSubject(study)
     215                assert subject
     216                sampleDB.parentSubject = subject
     217                assert sampleDB.validate()
     218                assert sampleDB.save()
     219
     220                // Create an event group in this study with the sample's sampling event
     221                def group = new EventGroup(
     222                    name: testEventGroupName
     223                )
     224                study.addToEventGroups(group)
     225                group.addToSubjects(subject)
     226                group.addToSamplingEvents(event)
     227                assert study.eventGroups.find { it.name == group.name}
     228                assert group.validate()
     229                assert study.save()
     230
     231                // Use the deleteSamplingEvent method
     232                def msg = study.deleteEventGroup(group)
     233                println msg
     234                assert study.save()
     235
     236                assert !study.eventGroups.contains(group)
     237                assert !EventGroup.findByName(testEventGroupName)
     238                assert !Sample.findByName(testSampleName)
     239
     240                assert EventGroup.count() == 0
    163241                assert Sample.count() == 0
    164242
Note: See TracChangeset for help on using the changeset viewer.