Changeset 860 for trunk/test


Ignore:
Timestamp:
Aug 30, 2010, 3:13:30 PM (10 years ago)
Author:
keesvb
Message:

added test for Sample name uniqueness at the validate() stage

File:
1 edited

Legend:

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

    r817 r860  
    291291        }
    292292
     293        /**
     294         * Test whether it's indeed not possible to add two yet-to-be-saved samples with the same name to a yet-to-be-saved study
     295         */
     296        void testSampleUniqueNameConstraintAtValidate() {
     297                def sample = Sample.findByName(testSampleName)
     298                assert sample
     299
     300                def study = sample.parent
     301                assert study
     302
     303                def sample1 = new Sample(
     304                    name: testSampleName + "-double",
     305                    template: sample.template,
     306                    parentEvent: sample.parentEvent
     307                )
     308
     309                def sample2 = new Sample(
     310                        name: testSampleName + "-double",
     311                    template: sample.template,
     312                    parentEvent: sample.parentEvent
     313                )
     314
     315                // Add the sample to the retrieved parent study
     316                study.addToSamples(sample1)
     317                study.addToSamples(sample2)
     318
     319                // At this point, the sample should not validate or save, because there is already a sample with that name in the study
     320                assert !sample1.validate()
     321                assert !sample1.save(flush:true)
     322
     323                assert !sample2.validate()
     324                assert !sample2.save(flush:true)
     325        }
     326
    293327        void testFindViaSamplingEvent() {
    294328                // Try to retrieve the sampling event by using the time...
Note: See TracChangeset for help on using the changeset viewer.