Changeset 1559 for trunk/test


Ignore:
Timestamp:
Feb 24, 2011, 5:14:08 PM (10 years ago)
Author:
s.h.sikkema@…
Message:

Assay export functionality

Location:
trunk/test/unit/dbnp/studycapturing
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/dbnp/studycapturing/AssayControllerTests.groovy

    r1455 r1559  
    2626
    2727    void testWrongAssayID() {
    28         mockParams.assayId = 3
     28        mockFlash.assayId = 3
    2929
    30         controller.exportAssayAsExcel()
     30        controller.compileExportData()
    3131
    3232        assertEquals 'Redirected action should match', [action: 'selectAssay'], redirectArgs
    33         assertEquals 'Error message', 'No assay found with id: 3.', mockFlash.errorMessage
     33        assertEquals 'Error message', 'No assay found with id: 3', mockFlash.errorMessage
    3434    }
    3535
    3636    void testExceptionHandling() {
    37         mockParams.assayId = 1
     37        mockFlash.assayId = 1
    3838
    3939        controller.metaClass.'grailsApplication' = [
     
    4343        controller.assayService = [
    4444
    45                 collectAssayData:                   {a, b -> throw new Exception('msg1') },
    46                 exportColumnWiseDataToExcelFile:    {a, b -> throw new Exception('msg2') }
     45                collectAssayData:               {a, b, c -> throw new Exception('msg1') },
     46                convertColumnToRowStructure:    {a -> throw new Exception('msg2')},
     47                exportRowWiseDataToExcelFile:   {a, b -> throw new Exception('msg3') }
    4748
    4849        ]
    4950
    50         controller.exportAssayAsExcel()
     51        controller.compileExportData()
    5152
    5253        assertEquals 'Redirected action should match', [action: 'selectAssay'], redirectArgs
    5354        assertEquals 'Error message', 'msg1', mockFlash.errorMessage
    5455
    55         controller.assayService.collectAssayData = {a, b -> true}
    56         controller.exportAssayAsExcel()
     56        controller.assayService.collectAssayData = {a, b, c -> true}
     57        controller.compileExportData()
    5758
    5859        assertEquals 'Redirected action should match', [action: 'selectAssay'], redirectArgs
    5960        assertEquals 'Error message', 'msg2', mockFlash.errorMessage
    6061
     62        controller.doExport()
     63
     64        assertEquals 'Redirected action should match', [action: 'selectAssay'], redirectArgs
     65        assertEquals 'Error message', 'msg3', mockFlash.errorMessage
     66
    6167    }
    6268
  • trunk/test/unit/dbnp/studycapturing/AssayServiceTests.groovy

    r1545 r1559  
    77import grails.converters.JSON
    88import org.dbnp.gdt.*
     9import org.dbnp.gdt.AssayModule
     10import org.dbnp.gdt.TemplateEntity
     11import groovy.mock.interceptor.MockFor
     12import org.dbnp.gdt.GdtService
     13import org.dbnp.gdt.TemplateStringField
    914
    1015/**
     
    3742                                    new Template(id: 2, fields: [TemplateField.get(3)])])
    3843
    39         mockDomain(Subject,       [ new Subject(id: 1, name:'subject1', template: Template.get(1), species: Term.get(1)),
    40                                     new Subject(id: 2, name:'subject2', template: Template.get(2), species: Term.get(1))])
     44        def mockGdtService = [getTemplateFieldTypeByCasedName: { a -> TemplateStringField }]
     45        def mockLog = [ info:{a->println a},error:{a->println "Error: $a"}]
     46
     47        mockDomain(Subject,       [ new Subject(gdtService: mockGdtService, id: 1, name:'subject1', template: Template.get(1), species: Term.get(1)),
     48                                    new Subject(gdtService: mockGdtService, id: 2, name:'subject2', template: Template.get(2), species: Term.get(1))])
    4149
    4250        mockDomain(SamplingEvent, [ new SamplingEvent(id:1, startTime: 2, duration: 5, sampleTemplate: new Template()),
     
    5159                                    new Sample(id: 2, name:'sample2', parentSubject: Subject.get(2), parentEvent: SamplingEvent.get(2), parentEventGroup: EventGroup.get(2))])
    5260
    53         mockDomain(Assay,         [ new Assay(id: 1, externalAssayID: 'assay1', samples:[Sample.get(1),Sample.get(2)]),
    54                                     new Assay(id: 2, externalAssayID: 'assay1', samples:[])])
     61        mockDomain(AssayModule,   [ new AssayModule(id: 1, url: 'http://www.example.com') ])
     62
     63        mockDomain(Assay,         [ new Assay(id: 1, externalAssayID: 'assay1', module: AssayModule.get(1), samples: [Sample.get(1),Sample.get(2)]),
     64                                    new Assay(id: 2, externalAssayID: 'assay1', module: AssayModule.get(1), samples: [])])
     65
     66        Subject.get(1).metaClass.static.log = mockLog
    5567
    5668        Subject.get(1).setFieldValue('tf1', 'tfv1')
     
    186198        def assay = Assay.get(1)
    187199
    188         def consumer = 'http://metabolomics.nmcdsp.nl'
    189 
    190 //        // mock URL's getText to be able to mock a http request
    191 //        URL.metaClass.getText = {
    192 //            new JSON ([['sample1', 'sample2', 'sample3'],
    193 //              ['measurement1','measurement2','measurement3','measurement4'],
    194 //              [1,2,3,4,5,6,7,8,9,10,11,12] ]).toString()
    195 //        }
    196 
    197         def assayData = service.collectAssayData(assay, consumer)
    198 
    199         println assayData
     200
     201//        collectAssayData(assay, fieldMap, measurementTokens)
     202
     203        def fieldMap = [
     204                'Subject Data':['tf1','tf2','tf3','species','name'],
     205                'Sampling Event Data':['startTime','duration'],
     206                'Sample Data':['name'],
     207                'Event Group':['name']
     208        ]
     209
     210        def measurementTokens = [[name:'measurement1'], [name:'measurement2'], [name:'measurement3'], [name:'measurement4']]
     211
     212        String.metaClass.'encodeAsURL' = {delegate}
     213
     214        def assayData = service.collectAssayData(assay, fieldMap, measurementTokens)
    200215
    201216        def sample1index = assayData.'Sample Data'.'name'.findIndexOf{it == 'sample1'}
     
    210225        assertEquals 'Sampling event template fields', [2,12], assayData.'Sampling Event Data'.startTime[sample1index, sample2index]
    211226        assertEquals 'Sampling event template fields', [5,15], assayData.'Sampling Event Data'.duration[sample1index, sample2index]
    212         assertEquals 'Sampling event template fields', '[null, null]', assayData.'Sampling Event Data'.sampleTemplate.toString()
     227//        assertEquals 'Sampling event template fields', '[null, null]', assayData.'Sampling Event Data'.sampleTemplate.toString()
    213228        assertEquals 'Sample template fields', ['sample1', 'sample2'], assayData.'Sample Data'.name[sample1index, sample2index]
    214229
Note: See TracChangeset for help on using the changeset viewer.