Changeset 1504


Ignore:
Timestamp:
Feb 8, 2011, 10:48:41 AM (6 years ago)
Author:
s.h.sikkema@…
Message:

Partially fixed the integration tests

Location:
trunk/test
Files:
5 edited

Legend:

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

    r1456 r1504  
    22
    33import grails.test.*
     4import org.dbnp.bgdt.Ontology
     5import org.dbnp.bgdt.Term
    46
    57/**
     
    191193        public void testAddBioPortalOntology() {
    192194                // Add a new ontology
    193                 def ontology = dbnp.data.Ontology.getBioPortalOntology("1031")
     195                def ontology = Ontology.getBioPortalOntology("1031")
    194196                // Validate and save ontology
    195197                if (!ontology.validate()) { ontology.errors.each { println it} }
     
    199201
    200202                // Make sure that it is not possible to add an ontology twice
    201                 def addAgain = dbnp.data.Ontology.getBioPortalOntology("1031")
     203                def addAgain = Ontology.getBioPortalOntology("1031")
    202204                assert !addAgain.validate()
    203205        }
  • trunk/test/integration/gscf/SampleTests.groovy

    r1456 r1504  
    22
    33import dbnp.studycapturing.*
     4import org.dbnp.gdt.Template
     5import org.dbnp.gdt.TemplateFieldType
    46
    57/**
  • trunk/test/integration/gscf/StudyTests.groovy

    r1430 r1504  
    33import grails.test.*
    44import dbnp.studycapturing.*
    5 import dbnp.data.*
     5import org.dbnp.gdt.Template
    66
    77/**
     
    2222        final String testStudyTemplateName = "Academic study"
    2323        final String testStudyCode = "AAA-Test"
     24    final String testStudyDescription = "Description of Test Study"
    2425        final Date testStudyStartDate = Date.parse('yyyy-MM-dd','2007-12-11')
    2526        final Date testStudyStartDate2 = Date.parse('yyyy-MM-dd','2008-05-11')
     
    4041                        template: studyTemplate,
    4142                        startDate: testStudyStartDate,
    42                         code: testStudyCode
     43                        code: testStudyCode,
     44            description: testStudyDescription
    4345                )
    4446
  • trunk/test/integration/gscf/SubjectTests.groovy

    r1456 r1504  
    22
    33import dbnp.studycapturing.*
     4import org.dbnp.bgdt.Term
     5import org.dbnp.bgdt.Ontology
     6import org.dbnp.gdt.Template
    47
    58/**
  • trunk/test/unit/dbnp/query/StudySearchTests.groovy

    r1498 r1504  
    55import org.dbnp.gdt.AssayModule
    66import org.codehaus.groovy.grails.commons.ApplicationHolder
    7 import dbnp.authentication.*;
     7import dbnp.authentication.*
     8import groovy.mock.interceptor.MockFor;
    89
    910/**
     
    2223 */
    2324class StudySearchTests extends GrailsUnitTestCase {
     25
     26    def mockApplicationHolder
     27
    2428    protected void setUp() {
    2529        super.setUp()
     
    5963                }
    6064
     65        mockApplicationHolder = new MockFor(ApplicationHolder)
     66
    6167        // some mocks to make sure test doesn't break on finding 'moduleCommunicationService'
    62         ApplicationHolder.metaClass.static.getApplication = { [getMainContext:
     68        mockApplicationHolder.demand.getApplication(1..10) { [getMainContext:
    6369                        { [getBean:
    6470                                { what ->
     
    8086        void testExecute() {
    8187
    82                 List criteria = [
    83                         new Criterion( entity: "Study", field: "title", operator: Operator.contains, value: "TNO" ),
    84                         new Criterion( entity: "Study", field: "code", operator: Operator.equals, value: "abc" ),
    85                         new Criterion( entity: "Study", field: "code", operator: Operator.equals, value: "ghi" )
    86                 ]
    87                
    88                 def studySearch = new StudySearch();
     88        mockApplicationHolder.use {
    8989
    90                 // Search without criteria
    91                 studySearch.setCriteria();
    92                 studySearch.execute();
    93                
    94                 assert studySearch.getResults().size() == 4
    95                 assert studySearch.getResults()[0] instanceof Study
    96                 assert studySearch.getResults()*.code.contains( "abc" );
    97                 assert studySearch.getResults()*.code.contains( "def" );
    98                 assert studySearch.getResults()*.code.contains( "ghi" );
    99                 assert studySearch.getResults()*.code.contains( "jkl" );
     90            List criteria = [
     91                new Criterion( entity: "Study", field: "title", operator: Operator.contains, value: "TNO" ),
     92                new Criterion( entity: "Study", field: "code", operator: Operator.equals, value: "abc" ),
     93                new Criterion( entity: "Study", field: "code", operator: Operator.equals, value: "ghi" )
     94            ]
    10095
    101                 studySearch.setCriteria( [ criteria[0] ] );
    102                 studySearch.execute();
    103                 assert studySearch.getResults().size() == 2
    104                
    105                 assert studySearch.getResults()*.code.contains( "abc" );
    106                 assert studySearch.getResults()*.code.contains( "def" );
    107                
    108                 studySearch.setCriteria( [ criteria[0], criteria[1] ] );
    109                 studySearch.execute();
    110                 assert studySearch.getResults().size() == 1
    111                 assert studySearch.getResults()[0].code == "abc"
    112                
    113                 studySearch.setCriteria( [ criteria[0], criteria[2] ] );
    114                 studySearch.execute();
    115                 assert studySearch.getResults().size() == 0
     96            def studySearch = new StudySearch();
    11697
    117                 studySearch.setCriteria( [ criteria[1], criteria[2] ] );
    118                 studySearch.execute();
    119                 assert studySearch.getResults().size() == 0
     98            // Search without criteria
     99            studySearch.setCriteria();
     100            studySearch.execute();
     101
     102            assert studySearch.getResults().size() == 4
     103            assert studySearch.getResults()[0] instanceof Study
     104            assert studySearch.getResults()*.code.contains( "abc" );
     105            assert studySearch.getResults()*.code.contains( "def" );
     106            assert studySearch.getResults()*.code.contains( "ghi" );
     107            assert studySearch.getResults()*.code.contains( "jkl" );
     108
     109            studySearch.setCriteria( [ criteria[0] ] );
     110            studySearch.execute();
     111            assert studySearch.getResults().size() == 2
     112
     113            assert studySearch.getResults()*.code.contains( "abc" );
     114            assert studySearch.getResults()*.code.contains( "def" );
     115
     116            studySearch.setCriteria( [ criteria[0], criteria[1] ] );
     117            studySearch.execute();
     118            assert studySearch.getResults().size() == 1
     119            assert studySearch.getResults()[0].code == "abc"
     120
     121            studySearch.setCriteria( [ criteria[0], criteria[2] ] );
     122            studySearch.execute();
     123            assert studySearch.getResults().size() == 0
     124
     125            studySearch.setCriteria( [ criteria[1], criteria[2] ] );
     126            studySearch.execute();
     127            assert studySearch.getResults().size() == 0
     128        }
    120129        }
    121130       
    122131        void testExecuteDifferentCriteria() {
    123                 List criteria = [
    124                         new Criterion( entity: "Study", field: "title", operator: Operator.contains, value: "TNO-1" ),
    125                         new Criterion( entity: "Subject", field: "name", operator: Operator.contains, value: "1" ),
    126                         new Criterion( entity: "Sample", field: "name", operator: Operator.contains, value: "1" ),
    127                         new Criterion( entity: "Assay", field: "name", operator: Operator.contains, value: "1" ),
    128                         new Criterion( entity: "Event", field: "startTime", operator: Operator.equals, value: "3600" ),
    129                         new Criterion( entity: "SamplingEvent", field: "startTime", operator: Operator.equals, value: "3600" ),
    130                 ]
    131                
    132                 def studySearch = new StudySearch();
    133132
    134                 // All criteria should result in 1 study with code 'abc'
    135                 criteria.each {
    136                         println "Criterion " + it
    137                         studySearch.setCriteria( [ it ] );
    138                         studySearch.execute();
    139                         assert studySearch.getResults().size() == 1
    140                         assert studySearch.getResults()[0].code == "abc";
    141                 }
     133        mockApplicationHolder.use {
     134
     135            List criteria = [
     136                new Criterion( entity: "Study", field: "title", operator: Operator.contains, value: "TNO-1" ),
     137                new Criterion( entity: "Subject", field: "name", operator: Operator.contains, value: "1" ),
     138                new Criterion( entity: "Sample", field: "name", operator: Operator.contains, value: "1" ),
     139                new Criterion( entity: "Assay", field: "name", operator: Operator.contains, value: "1" ),
     140                new Criterion( entity: "Event", field: "startTime", operator: Operator.equals, value: "3600" ),
     141                new Criterion( entity: "SamplingEvent", field: "startTime", operator: Operator.equals, value: "3600" ),
     142            ]
     143
     144            def studySearch = new StudySearch();
     145
     146            // All criteria should result in 1 study with code 'abc'
     147            criteria.each {
     148                println "Criterion " + it
     149                studySearch.setCriteria( [ it ] );
     150                studySearch.execute();
     151                assert studySearch.getResults().size() == 1
     152                assert studySearch.getResults()[0].code == "abc";
     153            }
     154        }
    142155        }
    143156
    144157        void testExecuteNonExistingCriteria() {
    145                 List criteria = [
    146                         new Criterion( entity: "Study", field: "title", operator: Operator.contains, value: "TNO-3" ),
    147                         new Criterion( entity: "Subject", field: "name", operator: Operator.contains, value: "4" ),
    148                         new Criterion( entity: "Sample", field: "name", operator: Operator.contains, value: "5" ),
    149                         new Criterion( entity: "Assay", field: "name", operator: Operator.contains, value: "6" ),
    150                         new Criterion( entity: "Event", field: "startTime", operator: Operator.equals, value: "4800" ),
    151                         new Criterion( entity: "SamplingEvent", field: "startTime", operator: Operator.equals, value: "360" ),
    152                 ]
    153                
    154                 def studySearch = new StudySearch();
    155158
    156                 // All criteria should result in 1 study with code 'abc'
    157                 criteria.each {
    158                         println "Criterion " + it
    159                         studySearch.setCriteria( [ it ] );
    160                         studySearch.execute();
    161                         assert studySearch.getResults().size() == 0
    162                 }
     159        mockApplicationHolder.use {
     160
     161            List criteria = [
     162                new Criterion( entity: "Study", field: "title", operator: Operator.contains, value: "TNO-3" ),
     163                new Criterion( entity: "Subject", field: "name", operator: Operator.contains, value: "4" ),
     164                new Criterion( entity: "Sample", field: "name", operator: Operator.contains, value: "5" ),
     165                new Criterion( entity: "Assay", field: "name", operator: Operator.contains, value: "6" ),
     166                new Criterion( entity: "Event", field: "startTime", operator: Operator.equals, value: "4800" ),
     167                new Criterion( entity: "SamplingEvent", field: "startTime", operator: Operator.equals, value: "360" ),
     168            ]
     169
     170            def studySearch = new StudySearch();
     171
     172            // All criteria should result in 1 study with code 'abc'
     173            criteria.each {
     174                println "Criterion " + it
     175                studySearch.setCriteria( [ it ] );
     176                studySearch.execute();
     177                assert studySearch.getResults().size() == 0
     178            }
     179
     180        }
    163181        }
    164182}
Note: See TracChangeset for help on using the changeset viewer.