Changeset 1588 for trunk/test/integration/dbnp
- Timestamp:
- Mar 4, 2011, 12:30:52 PM (11 years ago)
- Location:
- trunk/test/integration/dbnp
- Files:
-
- 1 deleted
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/integration/dbnp/query/SampleSearchTests.groovy
r1521 r1588 3 3 import dbnp.authentication.SecUser 4 4 import dbnp.studycapturing.* 5 import dbnp.configuration. *5 import dbnp.configuration.ExampleStudies 6 6 7 7 /** … … 23 23 protected void setUp() { 24 24 super.setUp() 25 // 26 // def owner = SecUser.findByUsername( "user" ); 27 // 28 // // Look up the used ontologies which should be in the database by now 29 // def speciesOntology = Ontology.getOrCreateOntologyByNcboId(1132) 30 // 31 // // Look up the used templates which should also be in the database by now 32 // def studyTemplate = Template.findByName("Academic study") 33 // def mouseTemplate = Template.findByName("Mouse") 34 // def dietTreatmentTemplate = Template.findByName("Diet treatment") 35 // def liverSamplingEventTemplate = Template.findByName("Liver extraction") 36 // def humanTissueSampleTemplate = Template.findByName("Human tissue sample") 37 // def ccAssayTemplate = Template.findByName("Clinical chemistry assay") 38 // 39 // // Add terms manually, to avoid having to do many HTTP requests to the BioPortal website 40 // def mouseTerm = Term.findByName( "Mus musculus" ); 41 // 42 // // Add example mouse study 43 // def testStudy = new Study( 44 // template : studyTemplate, 45 // title : "TestStudy 1", 46 // description : "C57Bl/6 mice were fed a high fat (45 en%) or low fat (10 en%) diet after a four week run-in on low fat diet.", 47 // code : "TESTPPS3_leptin_module", 48 // researchQuestion: "Leptin etc.", 49 // ecCode : "2007117.c", 50 // startDate : Date.parse('yyyy-MM-dd', '2008-01-02'), 51 // owner : owner 52 // ).with { if (!validate()) { errors.each { println it} } else save()} 53 // 54 // 55 // def evLF = new Event( 56 // startTime : 3600, 57 // endTime : 3600 + 7 * 24 * 3600, 58 // template : dietTreatmentTemplate 59 // ).setFieldValue('Diet', 'low fat') 60 // 61 // def evS = new SamplingEvent( 62 // startTime : 3600, 63 // template : liverSamplingEventTemplate, 64 // sampleTemplate: humanTissueSampleTemplate).setFieldValue('Sample weight', 5F) 65 // 66 // // Add events to study 67 // testStudy.addToEvents(evLF).addToSamplingEvents(evS).with { if (!validate()) { errors.each { println it} } else save()} 68 // 69 // // Extra check if the SamplingEvents are saved correctly 70 // evS.with { if (!validate()) { errors.each { println it} } else save()} 71 // evLF.with { if (!validate()) { errors.each { println it} } else save()} 72 // 73 // 74 // def LFBV1 = new EventGroup(name: "10% fat + vehicle for 1 week").addToEvents(evLF).addToSamplingEvents(evS) 75 // 76 // // Add subjects and samples and compose EventGroups 77 // def x = 1 78 // 5.times { 79 // def currentSubject = new Subject( 80 // name: "TestA" + x++, 81 // species: mouseTerm, 82 // template: mouseTemplate, 83 // ).setFieldValue("Gender", "Male") 84 // 85 // // We have to save the subject first, otherwise the parentEvent property of the sample cannot be set 86 // // (this is possibly a Grails or Hibernate bug) 87 // testStudy.addToSubjects(currentSubject) 88 // currentSubject.with { if (!validate()) { errors.each { println it} } else save()} 89 // 90 // // Add subject to appropriate EventGroup 91 // LFBV1.addToSubjects(currentSubject).with { if (!validate()) { errors.each { println it} } else save()} 92 // 93 // // Create sample 94 // def currentSample = new Sample( 95 // name: currentSubject.name + '_B', 96 // material: mouseTerm, 97 // template: humanTissueSampleTemplate, 98 // parentSubject: currentSubject, 99 // parentEvent: evS 100 // ); 101 // testStudy.addToSamples(currentSample) 102 // currentSample.setFieldValue("Text on vial", "T" + (Math.random() * 100L)) 103 // currentSample.with { if (!validate()) { errors.each { println it} } else save()} 104 // } 105 // 106 // // Add EventGroups to study 107 // testStudy.addToEventGroups(LFBV1) 108 // LFBV1.with { if (!validate()) { errors.each { println it} } else save()} 109 // testStudy.with { if (!validate()) { errors.each { println it} } else save(flush:true)} 110 // 111 // testStudy.save(flush:true) 112 // 113 // //assert Sample.list()*.name.contains( "TestA2_B" ); 114 // 115 // // Make sure session is kept open 116 // Session session = SessionFactoryUtils.getSession(sessionFactory, true) 117 // session.flush(); 118 // session.clear(); 119 120 BootStrapTemplates.initTemplateOntologies(); 121 BootStrapTemplates.initTemplates() 122 BootStrapStudies.addExampleStudies(SecUser.findByUsername('user'), SecUser.findByUsername('admin')) 25 26 ExampleStudies.addExampleStudies(SecUser.findByUsername('user'), SecUser.findByUsername('admin')) 123 27 } 124 28 … … 134 38 new Criterion( entity: "Study", field: "code", operator: Operator.equals, value: "PPSH" ) 135 39 ] 136 40 137 41 def search = new SampleSearch(); 138 42 139 43 // Make sure the 'user' is logged in 140 44 search.user = SecUser.findByUsername('user'); 141 45 142 46 search.setCriteria( [ criteria[0] ] ); 47 48 def a = Sample.findAll() 49 143 50 search.execute(); 144 51 assert search.getResults().size() >= 2 145 52 146 53 assert search.getResults()[0] instanceof Sample 147 54 assert search.getResults()*.name.contains( "A2_B" ); 148 55 assert search.getResults()*.name.contains( "A4_B" ); 149 56 150 57 search.setCriteria( [ criteria[0], criteria[1] ] ); 151 58 search.execute(); 152 59 assert search.getResults().size() >= 1 153 60 assert search.getResults()*.name.contains( "A2_B" ); 154 61 155 62 search.setCriteria( [ criteria[0], criteria[2] ] ); 156 63 search.execute(); 157 64 assert search.getResults().size() >= 1 158 65 159 66 // Conflicting criteria shouldn't return any samples 160 67 search.setCriteria( [ criteria[2], criteria[1] ] ); … … 162 69 assert search.getResults().size() == 0 163 70 } 164 71 165 72 void testExecuteDifferentCriteria() { 166 73 List criteria = [ … … 172 79 //new Criterion( entity: "SamplingEvent", field: "startTime", operator: Operator.equals, value: 3600 + 7 * 24 * 3600 ), 173 80 ] 174 81 175 82 def search = new SampleSearch(); 176 83 … … 183 90 search.setCriteria( [ it ] ); 184 91 search.execute(); 185 92 186 93 def results = search.getResults(); 187 94 assert results; … … 201 108 new Criterion( entity: "SamplingEvent", field: "startTime", operator: Operator.equals, value: "0192039" ), 202 109 ] 203 110 204 111 def search = new SampleSearch(); 205 112 206 113 // Make sure the 'user' is logged in 207 114 search.user = SecUser.findByUsername('user'); 208 115 209 116 // All criteria should result in 1 study with code 'abc' 210 117 criteria.each {
Note: See TracChangeset
for help on using the changeset viewer.