Changeset 737


Ignore:
Timestamp:
Jul 27, 2010, 5:22:45 PM (13 years ago)
Author:
keesvb
Message:

added a test that confirms the cascaded deletion of a Sample in case it is removed from a Study

File:
1 edited

Legend:

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

    r663 r737  
    2525        // This test extends StudyTests, so that we have a test study to assign as a parent study
    2626
    27         final String testSampleName = "Test sample"
     27        final String testSampleName = "Test sample @XYZ!"
    2828        final String testSampleTemplateName = "Human blood sample"
    2929
     
    106106        }
    107107
     108        void testDelete() {
     109                def sampleDB = Sample.findByName(testSampleName)
     110                sampleDB.delete()
     111                try {
     112                        sampleDB.save()
     113                        assert false // The save should not succeed since the sample is referenced by a study
     114                }
     115                catch(org.springframework.dao.InvalidDataAccessApiUsageException e) {
     116                        sampleDB.discard()
     117                        assert true // OK, correct exception (at least for the in-mem db, for PostgreSQL it's probably a different one...)
     118                }
     119
     120                // Now, delete the sample from the study samples collection, and then the delete action should be cascaded to the sample itself
     121                def study = Study.findByTitle(testStudyName)
     122                assert study
     123                study.removeFromSamples sampleDB
     124
     125                // Make sure the sample doesn't exist anymore at this point
     126                assert !Sample.findByName(testSampleName)
     127                assert study.samples.size() == 0
     128        }
     129
    108130        void testStudyRelation() {
    109131                // Retrieve the parent study
Note: See TracChangeset for help on using the changeset viewer.