Changeset 774 for trunk/test
- Timestamp:
- Aug 4, 2010, 4:12:38 PM (13 years ago)
- Location:
- trunk/test/integration/gscf
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/integration/gscf/OntologyTests.groovy
r552 r774 152 152 * Add all OLS ontologies to the database via the Ontocat framework 153 153 */ 154 void testOntocatOLSOntologies() {154 private void testOntocatOLSOntologies() { 155 155 // Instantiate EBI OLS service 156 156 uk.ac.ebi.ontocat.OntologyService os = new uk.ac.ebi.ontocat.ols.OlsOntologyService() … … 161 161 * Add all BioPortal ontologies to the database via the Ontocat framework 162 162 */ 163 void testOntocatBioPortalOntologies() {163 private void testOntocatBioPortalOntologies() { 164 164 // Instantiate BioPortal service 165 165 uk.ac.ebi.ontocat.OntologyService os = new uk.ac.ebi.ontocat.bioportal.BioportalOntologyService() -
trunk/test/integration/gscf/SampleTests.groovy
r737 r774 7 7 import dbnp.studycapturing.Sample 8 8 import dbnp.studycapturing.TemplateFieldType 9 import dbnp.studycapturing.Subject 9 10 10 11 /** … … 54 55 samplingEvent.errors.each { println it} 55 56 } 57 // The SamplingEvent should not validate at this point because it doesn't have a parent study 58 assert !samplingEvent.validate() 59 60 study.addToSamplingEvents(samplingEvent) 61 // It should do fine now 56 62 assert samplingEvent.validate() 57 58 63 assert samplingEvent.save(flush:true) 59 64 … … 125 130 // Make sure the sample doesn't exist anymore at this point 126 131 assert !Sample.findByName(testSampleName) 132 assert Sample.count() == 0 127 133 assert study.samples.size() == 0 134 } 135 136 void testDeleteViaParentSubject() { 137 138 def sampleDB = Sample.findByName(testSampleName) 139 assert sampleDB 140 141 // Retrieve the parent study 142 def study = Study.findByTitle(testStudyName) 143 assert study 144 145 def subject = SubjectTests.createSubject(study) 146 assert subject 147 148 sampleDB.parentSubject = subject 149 assert sampleDB.validate() 150 assert sampleDB.save() 151 152 // Use the deleteSubject method 153 def msg = study.deleteSubject(subject) 154 println msg 155 assert study.save() 156 157 assert !study.subjects.contains(subject) 158 159 assert !Subject.findByName(testSampleName) 160 assert !Sample.findByName(testSampleName) 161 162 assert Subject.count() == 0 163 assert Sample.count() == 0 164 128 165 } 129 166 -
trunk/test/integration/gscf/SubjectTests.groovy
r496 r774 19 19 * $Date$ 20 20 */ 21 class SubjectTests extends GrailsUnitTestCase{22 23 final String testSubjectName = "Test subject"24 final String testSubjectTemplateName = "Human"25 final String testSubjectSpeciesTerm = "Homo sapiens"26 final String testSubjectBMITemplateFieldName = "BMI"27 final double testSubjectBMI = 25.3228 final String testSubjectGenderTemplateFieldName = "Gender"29 final String testSubjectGender = "female"30 final String testSubjectGenderDBName = "Female"21 class SubjectTests extends StudyTests { 22 23 static final String testSubjectName = "Test subject" 24 static final String testSubjectTemplateName = "Human" 25 static final String testSubjectSpeciesTerm = "Homo sapiens" 26 static final String testSubjectBMITemplateFieldName = "BMI" 27 static final double testSubjectBMI = 25.32 28 static final String testSubjectGenderTemplateFieldName = "Gender" 29 static final String testSubjectGender = "female" 30 static final String testSubjectGenderDBName = "Female" 31 31 32 32 /** … … 35 35 protected void setUp() { 36 36 super.setUp() 37 38 // Retrieve the study that should have been created in StudyTests 39 def study = Study.findByTitle(testStudyName) 40 assert study 41 42 createSubject(study) 43 } 44 45 public static Subject createSubject(Study parentStudy) { 37 46 38 47 // Look up human template … … 40 49 assert humanTemplate 41 50 42 def humanTerm = Term.findByName(testSubjectSpeciesTerm) 51 def speciesOntology = Ontology.getOrCreateOntologyByNcboId(1132) 52 def humanTerm = new Term( 53 name: 'Homo sapiens', 54 ontology: speciesOntology, 55 accession: '9606') 56 57 assert humanTerm.validate() 58 assert humanTerm.save(flush:true) 43 59 assert humanTerm 44 60 … … 49 65 ) 50 66 51 assert subject.save(flush:true) 67 // At this point, the sample should not validate, because it doesn't have a parent study assigned 68 assert !subject.validate() 69 70 // Add the subject to the retrieved parent study 71 parentStudy.addToSubjects(subject) 72 assert parentStudy.subjects.find { it.name == subject.name} 73 74 // Now, the subject should validate 75 if (!subject.validate()) { 76 subject.errors.each { println it} 77 } 78 assert subject.validate() 79 80 // Make sure the subject is saved to the database 81 assert subject.save(flush: true) 82 83 return subject 84 52 85 } 53 86 … … 60 93 assert subjectDB.species.name.equals(testSubjectSpeciesTerm) 61 94 } 95 96 void testDelete() { 97 def subjectDB = Subject.findByName(testSubjectName) 98 subjectDB.delete() 99 try { 100 subjectDB.save() 101 assert false // The save should not succeed since the subject is referenced by a study 102 } 103 catch(org.springframework.dao.InvalidDataAccessApiUsageException e) { 104 subjectDB.discard() 105 assert true // OK, correct exception (at least for the in-mem db, for PostgreSQL it's probably a different one...) 106 } 107 108 // Now, delete the subject from the study subjects collection, and then the delete action should be cascaded to the subject itself 109 def study = Study.findByTitle(testStudyName) 110 assert study 111 study.removeFromSubjects subjectDB 112 113 // Make sure the subject doesn't exist anymore at this point 114 assert !Subject.findByName(testSubjectName) 115 assert Subject.count() == 0 116 assert study.subjects.size() == 0 117 } 118 62 119 63 120 void testValidators() { … … 74 131 75 132 subject.species = Term.findByName(testSubjectSpeciesTerm) 76 assert subject.validate() 77 78 // TODO: Set study and change name to already existing name, should fail within one study 79 // subject.name = testSubjectName 80 // assert !subject.validate() 133 // Still, no parent study assigned 134 assert !subject.validate() 135 136 def study = Study.findByTitle(testStudyName) 137 assert study 138 study.addToSubjects subject 139 140 // Now, the new subject should validate 141 assert subject.validate() 142 assert subject.save() 143 144 // If the subject has the same name as another subject within the same study, it should not validate or save 145 subject.name = testSubjectName 146 assert !subject.validate() 147 assert !subject.save() 81 148 } 82 149
Note: See TracChangeset
for help on using the changeset viewer.