source: trunk/test/integration/dbnp/query/SampleSearchTests.groovy @ 1588

Last change on this file since 1588 was 1588, checked in by s.h.sikkema@…, 12 years ago

Fixed tests (except webtests); cleaned up Example{Studies,Templates}.groovy; decapitalized injected services; made 'transactional' properties static

  • Property svn:keywords set to Rev Author Date
File size: 4.0 KB
Line 
1package dbnp.query
2
3import dbnp.authentication.SecUser
4import dbnp.studycapturing.*
5import dbnp.configuration.ExampleStudies
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: 1588 $
18 * $Author: s.h.sikkema@gmail.com $
19 * $Date: 2011-03-04 11:30:52 +0000 (vr, 04 mrt 2011) $
20 */
21class SampleSearchTests extends GroovyTestCase {
22
23    protected void setUp() {
24        super.setUp()
25
26        ExampleStudies.addExampleStudies(SecUser.findByUsername('user'), SecUser.findByUsername('admin'))
27    }
28
29    protected void tearDown() {
30        super.tearDown()
31    }
32
33        void testExecute() {
34
35                List criteria = [
36                        new Criterion( entity: "Sample", field: "name", operator: Operator.contains, value: "B" ),
37                        new Criterion( entity: "Study", field: "code", operator: Operator.equals, value: "PPS3_leptin_module" ),
38                        new Criterion( entity: "Study", field: "code", operator: Operator.equals, value: "PPSH" )
39                ]
40
41                def search = new SampleSearch();
42
43                // Make sure the 'user' is logged in
44                search.user = SecUser.findByUsername('user');
45
46                search.setCriteria( [ criteria[0] ] );
47
48        def a = Sample.findAll()
49
50                search.execute();
51                assert search.getResults().size() >= 2
52
53                assert search.getResults()[0] instanceof Sample
54                assert search.getResults()*.name.contains( "A2_B" );
55                assert search.getResults()*.name.contains( "A4_B" );
56
57                search.setCriteria( [ criteria[0], criteria[1] ] );
58                search.execute();
59                assert search.getResults().size() >= 1
60                assert search.getResults()*.name.contains( "A2_B" );
61
62                search.setCriteria( [ criteria[0], criteria[2] ] );
63                search.execute();
64                assert search.getResults().size() >= 1
65
66                // Conflicting criteria shouldn't return any samples
67                search.setCriteria( [ criteria[2], criteria[1] ] );
68                search.execute();
69                assert search.getResults().size() == 0
70        }
71
72        void testExecuteDifferentCriteria() {
73                List criteria = [
74                        new Criterion( entity: "Study", field: "title", operator: Operator.contains, value: "NuGO PPS3 mouse study" ),
75                        new Criterion( entity: "Subject", field: "species", operator: Operator.equals, value: "Mus musculus" ),
76                        new Criterion( entity: "Sample", field: "name", operator: Operator.contains, value: "A" ),
77                        new Criterion( entity: "Assay", field: "name", operator: Operator.contains, value: "Lipid" ),
78                        //new Criterion( entity: "Event", field: "startTime", operator: Operator.equals, value: "3600" ),
79                        //new Criterion( entity: "SamplingEvent", field: "startTime", operator: Operator.equals, value: 3600 + 7 * 24 * 3600 ),
80                ]
81
82                def search = new SampleSearch();
83
84                // Make sure the 'user' is logged in
85                search.user = SecUser.findByUsername('user');
86
87                // All criteria should result in 1 sample with code 'abc'
88                criteria.each {
89                        println "Criterion " + it
90                        search.setCriteria( [ it ] );
91                        search.execute();
92
93                        def results = search.getResults();
94                        assert results;
95                        assert results.size() >= 2
96                        assert results[0] instanceof Sample;
97                        assert results*.name.contains( "A2_B" );
98                }
99        }
100
101        void testExecuteNonExistingCriteria() {
102                List criteria = [
103                        new Criterion( entity: "Study", field: "title", operator: Operator.contains, value: "This shouldn't exist" ),
104                        new Criterion( entity: "Subject", field: "name", operator: Operator.contains, value: "This shouldn't exist" ),
105                        new Criterion( entity: "Sample", field: "name", operator: Operator.contains, value: "This shouldn't exist" ),
106                        new Criterion( entity: "Assay", field: "name", operator: Operator.contains, value: "This shouldn't exist" ),
107                        new Criterion( entity: "Event", field: "startTime", operator: Operator.equals, value: "481920" ),
108                        new Criterion( entity: "SamplingEvent", field: "startTime", operator: Operator.equals, value: "0192039" ),
109                ]
110
111                def search = new SampleSearch();
112
113                // Make sure the 'user' is logged in
114                search.user = SecUser.findByUsername('user');
115
116                // All criteria should result in 1 study with code 'abc'
117                criteria.each {
118                        println "Criterion " + it
119                        search.setCriteria( [ it ] );
120                        search.execute();
121                        assert search.getResults().size() == 0
122                }
123        }
124
125}
Note: See TracBrowser for help on using the repository browser.