root/trunk/test/unit/dbnp/query/StudySearchTests.groovy @ 1473

Revision 1473, 5.3 KB (checked in by s.h.sikkema@…, 3 years ago)

Fixed tests and removed obsolete ones so grails test-app works with all tests passed

  • Property svn:keywords set to Rev Author Date
Line 
1package dbnp.query
2
3import dbnp.studycapturing.*
4import grails.test.*
5import org.dbnp.gdt.AssayModule
6
7/**
8 * SearchTests Test
9 *
10 * Description of my test
11 *
12 * @author  your email (+name?)
13 * @since       2010mmdd
14 * @package     ???
15 *
16 * Revision information:
17 * $Rev$
18 * $Author$
19 * $Date$
20 */
21class StudySearchTests extends GrailsUnitTestCase {
22    protected void setUp() {
23        super.setUp()
24               
25                def studies = [ new Study( title: 'Study TNO-1', code: 'abc' ), new Study( title: 'Study TNO-2', code: 'def' ), new Study( title: 'Study NMC-1', code: 'ghi' ), new Study( title: 'Study NMC-2', code: 'jkl' ) ];
26                def subjects = [ new Subject( name: 'Subject 1', parent: studies[0] ), new Subject( name: 'Subject 2', parent: studies[1] ) ]
27                def events = [ new Event( startTime: 3600, parent: studies[0] ), new Event( startTime: 7200, parent: studies[1] ) ]
28                def samplingEvents = [ new SamplingEvent( startTime: 3600, parent: studies[0] ), new SamplingEvent( startTime: 7200, parent: studies[1] ) ]
29                def samples = [
30                                new Sample( name: 'Sample 1', parent: studies[0], parentSubject: subjects[ 0 ], parentEvent: samplingEvents[ 0 ] ),
31                                new Sample( name: 'Sample 2', parent: studies[1], parentSubject: subjects[ 1 ], parentEvent: samplingEvents[ 1 ] )
32                ]
33                def assays = [ new Assay( name: 'Assay 1', parent: studies[0], samples: [samples[0]] ), new Assay( name: 'Assay 2', parent: studies[1], samples: [samples[1]] ) ]
34               
35                mockDomain( Study, studies );
36                mockDomain( Subject, subjects );
37                mockDomain( Sample, samples );
38                mockDomain( Event, events );
39                mockDomain( SamplingEvent, samplingEvents);
40                mockDomain( Assay, assays );
41
42        mockDomain( AssayModule );
43               
44                subjects.each { it.parent.addToSubjects( it ); }
45                samples.each { it.parent.addToSamples( it ); }
46                events.each { it.parent.addToEvents( it ); }
47                samplingEvents.each { it.parent.addToSamplingEvents( it ); }
48                samples.each { it.parent.addToSamples( it ); }
49                assays.each { it.parent.addToAssays( it ); }
50               
51    }
52
53    protected void tearDown() {
54        super.tearDown()
55    }
56
57        void testExecute() {
58
59                List criteria = [
60                        new Criterion( entity: "Study", field: "title", operator: Operator.contains, value: "TNO" ),
61                        new Criterion( entity: "Study", field: "code", operator: Operator.equals, value: "abc" ),
62                        new Criterion( entity: "Study", field: "code", operator: Operator.equals, value: "ghi" )
63                ]
64               
65                def studySearch = new StudySearch();
66
67                // Search without criteria
68                studySearch.setCriteria( );
69                studySearch.execute();
70               
71                assert studySearch.getResults().size() == 4
72                assert studySearch.getResults()[0] instanceof Study
73                assert studySearch.getResults()*.code.contains( "abc" );
74                assert studySearch.getResults()*.code.contains( "def" );
75                assert studySearch.getResults()*.code.contains( "ghi" );
76                assert studySearch.getResults()*.code.contains( "jkl" );
77
78                studySearch.setCriteria( [ criteria[0] ] );
79                studySearch.execute();
80                assert studySearch.getResults().size() == 2
81               
82                assert studySearch.getResults()*.code.contains( "abc" );
83                assert studySearch.getResults()*.code.contains( "def" );
84               
85                studySearch.setCriteria( [ criteria[0], criteria[1] ] );
86                studySearch.execute();
87                assert studySearch.getResults().size() == 1
88                assert studySearch.getResults()[0].code == "abc"
89               
90                studySearch.setCriteria( [ criteria[0], criteria[2] ] );
91                studySearch.execute();
92                assert studySearch.getResults().size() == 0
93
94                studySearch.setCriteria( [ criteria[1], criteria[2] ] );
95                studySearch.execute();
96                assert studySearch.getResults().size() == 0
97        }
98       
99        void testExecuteDifferentCriteria() {
100                List criteria = [
101                        new Criterion( entity: "Study", field: "title", operator: Operator.contains, value: "TNO-1" ),
102                        new Criterion( entity: "Subject", field: "name", operator: Operator.contains, value: "1" ),
103                        new Criterion( entity: "Sample", field: "name", operator: Operator.contains, value: "1" ),
104                        new Criterion( entity: "Assay", field: "name", operator: Operator.contains, value: "1" ),
105                        new Criterion( entity: "Event", field: "startTime", operator: Operator.equals, value: "3600" ),
106                        new Criterion( entity: "SamplingEvent", field: "startTime", operator: Operator.equals, value: "3600" ),
107                ]
108               
109                def studySearch = new StudySearch();
110
111                // All criteria should result in 1 study with code 'abc'
112                criteria.each {
113                        println "Criterion " + it
114                        studySearch.setCriteria( [ it ] );
115                        studySearch.execute();
116                        assert studySearch.getResults().size() == 1
117                        assert studySearch.getResults()[0].code == "abc";
118                }
119        }
120
121        void testExecuteNonExistingCriteria() {
122                List criteria = [
123                        new Criterion( entity: "Study", field: "title", operator: Operator.contains, value: "TNO-3" ),
124                        new Criterion( entity: "Subject", field: "name", operator: Operator.contains, value: "4" ),
125                        new Criterion( entity: "Sample", field: "name", operator: Operator.contains, value: "5" ),
126                        new Criterion( entity: "Assay", field: "name", operator: Operator.contains, value: "6" ),
127                        new Criterion( entity: "Event", field: "startTime", operator: Operator.equals, value: "4800" ),
128                        new Criterion( entity: "SamplingEvent", field: "startTime", operator: Operator.equals, value: "360" ),
129                ]
130               
131                def studySearch = new StudySearch();
132
133                // All criteria should result in 1 study with code 'abc'
134                criteria.each {
135                        println "Criterion " + it
136                        studySearch.setCriteria( [ it ] );
137                        studySearch.execute();
138                        assert studySearch.getResults().size() == 0
139                }
140        }
141}
Note: See TracBrowser for help on using the browser.