Changeset 1658


Ignore:
Timestamp:
Mar 22, 2011, 4:33:49 PM (6 years ago)
Author:
t.w.abma@…
Message:
  • importer wizard webtest working
  • native file input HTML element didn't work inside AjaxFlow, so used hidden importfile variable
  • added check for development or test environment in configuration file
  • added webtestfiles folder to web-apps containing Excel files to test
Location:
trunk
Files:
2 added
3 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/conf/Config.groovy

    r1651 r1658  
    133133// Otherwise, it should be given as an absolute path (e.g. '/home/user/sequences')
    134134// The directory should be writable by the webserver user
    135 uploads.uploadDir = (new File("/tmp")?.canWrite()) ? "/tmp" : "fileuploads"
     135if (GrailsUtil.Environment.current == Environment.TEST) {
     136    uploads.uploadDir = "webtestfiles"
     137} else
     138if (GrailsUtil.Environment.current == Environment.DEVELOPMENT) {
     139    uploads.uploadDir = (new File("/tmp")?.canWrite()) ? "/tmp" : "fileuploads"   
     140}
  • trunk/grails-app/controllers/dbnp/importer/ImporterController.groovy

    r1656 r1658  
    66import org.codehaus.groovy.grails.plugins.web.taglib.ValidationTagLib
    77import grails.plugins.springsecurity.Secured
     8import org.codehaus.groovy.grails.commons.ConfigurationHolder
     9import grails.util.GrailsUtil
     10
    811
    912/**
     
    123126                                // that string
    124127                                flash.importer_params.importfile = params.importfile.replace('existing*', '')
    125                 flash.importer_params.importfile = new XmlSlurper().parseText(flash.importer_params.importfile[flash.importer_params.importfile.indexOf('<pre')..-1]).toString()
     128                //flash.importer_params.importfile = new XmlSlurper().parseText(flash.importer_params.importfile[flash.importer_params.importfile.indexOf('<pre')..-1]).toString()
    126129
    127130                                success()
     
    130133                        on("next") {
    131134                                flash.wizardErrors = [:]
     135
    132136                                flash.importer_params = params
    133                                 flash.importer_params.importfile = params.importfile.replace('existing*', '')
    134                 flash.importer_params.importfile = new XmlSlurper().parseText(flash.importer_params.importfile[flash.importer_params.importfile.indexOf('<pre')..-1]).toString()
     137                                flash.importer_params.importfile = params.importfile.replace('existing*', '')               
     138                //flash.importer_params.importfile = new XmlSlurper().parseText(flash.importer_params.importfile[flash.importer_params.importfile.indexOf('<pre')..-1]).toString()
    135139
    136140                                if (params.entity) {
     
    266270
    267271                                // Always delete the uploaded file in the save step to be sure it doesn't reside there anymore
    268                                 fileService.delete(flow.importer_importedfile)
     272                                if (GrailsUtil.environment != "test") fileService.delete(flow.importer_importedfile)
    269273
    270274                                // Save all entities
     
    340344         * @returns boolean true if correctly validated, otherwise false
    341345         */
    342         boolean fileImportPage(flow, flash, params) {
     346        boolean fileImportPage(flow, flash, params) {       
    343347                def importedfile = fileService.get(params['importfile'])
    344348                flow.importer_importedfile = params['importfile']
    345 
    346                 if (importedfile.exists()) {
     349       
     350        if (importedfile.exists()) {
    347351                        try {
    348352                                session.importer_workbook = importerService.getWorkbook(new FileInputStream(importedfile))
  • trunk/grails-app/views/importer/pages/_page_one.gsp

    r1536 r1658  
    2222                Choose your Excel file to import:
    2323            </td>
    24             <td width="100px">
    25                 <af:fileFieldElement name="importfile" value="${importer_params?.importfile}"/>
     24            <td width="100px">         
     25        <g:if env="test">
     26          <input type="hidden" name="importfile" value="NTC_Experiment_test4.xls"/>
     27        </g:if>
     28        <g:elseif env="development">
     29          <af:fileFieldElement name="importfile" value="${importer_params?.importfile}"/>
     30        </g:elseif>
     31
    2632            </td>
    2733        </tr>
  • trunk/test/webtest/gscf/ImportWizardWebTests.groovy

    r1655 r1658  
    33import org.dbnp.gdt.*
    44
    5 class CreateStudyWebTests extends grails.util.WebTest {
     5class ImportWizardWebTests extends grails.util.WebTest {
    66
    77        // Unlike unit tests, functional tests are sometimes sequence dependent.
     
    1010        // e.g. test001XclassNameXListNewDelete
    1111
    12         void testCreateStudy() {
     12        void testImportWizard() {
    1313                // reset Identity to be able to predict identifiers
    1414                Identity.resetIdentifier()
     
    2222                setInputField(description: "Set password field j_password: useR123!", name: "j_password", value: "useR123!")
    2323                clickButton "Login"
    24                 clickLink "Studies"
    25 
    26                 clickLink "Create a new study"
    27                 setSelectField(name: "template", text: "Academic study")
    28                 setInputField(name: "title", value: "Test create study")
    29                 setInputField(name: "description", value: "Test study from CreateStudyWebTests.testCreateStudy()")
    30                 setInputField(name: "code", value: "TESTCREATE")
    31                 setInputField(name: "startdate", value: "01/01/2011")
    32                 clickButton "next »"
    33 
    34                 // Add 10 human subjects
    35                 setSelectField(name: "species", text: "Homo sapiens")
    36                 setSelectField(name: "template", text: "Human")
    37                 setInputField(name: "addNumber", value: "10")
    38                 clickButton "Add"
    39 
    40                 /* Stub code for testing of the template editor
    41                            setSelectField(name: "template", text: "add / modify..")
    42                            clickLink "Create new field"
    43                            setInputField(name: "name", value: "Second Species")
    44                            setSelectField(name: "type", text: "ONTOLOGYTERM")
    45                            setSelectField(name: "ontologies", text: "NCBI organismal classification")
    46                            clickButton "Save"
    47                            clickButton "Close"
    48                            setSelectField(name: "subject_793_second_species", text: "add more...")
    49                            setInputField(name: "term", value: "rat")
    50                            clickLink "Rattus norvegicus (Synonym) from: Rattus norvegicus"
    51                            clickButton "Add term"
    52                            clickButton "Close"   */
    53                 clickButton "next »"
    54 
    55                 // Add some events, sampling events, and groups
    56                 setSelectField(name: "eventTemplate", text: "Compound challenge")
    57                 setSelectField(name: "compound", text: "glucose")
    58                 clickButton "Add"
    59                 clickButton "add a new eventgroup"
    60                 setCheckbox(name: "event_13_group_11") // 51_49
    61                 setCheckbox(name: "event_13_group_14") // 51_52
    62                 setRadioButton(description: "Check radio button eventType: sample", name: "eventType", value: "sample")
    63                 setSelectField(name: "sampleTemplate", text: "Blood extraction")
    64                 setSelectField(name: "sampletemplate", text: "Human blood sample")
    65                 clickButton "Add"
    66                 setSelectField(name: "sampleTemplate", text: "Blood extraction")
    67                 setSelectField(name: "sampletemplate", text: "Human blood sample")
    68                 setInputField(name: "starttime", value: "1w")
    69                 clickButton "Add"
    70                 setCheckbox(name: "event_16_group_11") // 54_49
    71                 setCheckbox(name: "event_17_group_14") // 55_52
    72                 setRadioButton(description: "Check radio button eventType: event", name: "eventType", value: "event")
    73                 setSelectField(name: "eventTemplate", text: "Compound challenge")
    74                 setSelectField(name: "compound", text: "glucose")
    75                 clickButton "Add"
    76                 setCheckbox(name: "event_18_group_11")  // 56_49
    77                 setCheckbox(name: "event_18_group_14")  // 56_52
    78 
    79                 /* stub to test ontology term widget
    80                            setSelectField(name: "event_20_compound", text: "add more...")
    81                            setInputField(name: "term", value: "glu")
    82                            clickLink "L-glutamic acid (Synonym) from: L-glutamic acid"
    83                            clickButton "Add term"
    84                            clickButton "Close"
    85                            setSelectField(name: "event_1648_compound", text: "L-glutamic acid")
    86                            */
    87                 clickButton "next »"
    88 
    89                 // assign subjects to event groups
    90                 setCheckbox(name: "subject_1_group_11") // 39_49
    91                 setCheckbox(name: "subject_2_group_11") // 40_49
    92                 setCheckbox(name: "subject_3_group_11") // 41_49
    93                 setCheckbox(name: "subject_4_group_14") // 42_52
    94                 setCheckbox(name: "subject_5_group_14") // 43_52
    95                 setCheckbox(name: "subject_6_group_14") // 44_52
    96                 clickButton "next »"
    97 
    98                 // accept the generated samples, check if the right names are in place
    99                 /* For some reason enabling this causes the whole webtest to blow. TODO: find out why...
    100            verifyInputField(name: "sample_21_name", value="Subject1_BloodExtraction_Group1_0s")
    101            verifyInputField(name: "sample_22_name", value="Subject2_BloodExtraction_Group1_0s")
    102            verifyInputField(name: "sample_23_name", value="Subject3_BloodExtraction_Group1_0s")
    103            verifyInputField(name: "sample_24_name", value="Subject4_BloodExtraction_Group2_1w")
    104            verifyInputField(name: "sample_25_name", value="Subject5_BloodExtraction_Group2_1w")
    105            verifyInputField(name: "sample_26_name", value="Subject6_BloodExtraction_Group2_1w")
    106 
    107                    and this doesnt work apparently inside textfields: verifyText(text: "Subject1_BloodExtraction_Group1_0s")
    108 
    109                 */
    110                 clickButton "next »"
    111 
    112 
    113                 setSelectField(name: "template", text: "Clinical chemistry assay")
    114                 setInputField(name: "name", value: "test assay")
    115                 clickButton "Add"
    116                 clickButton "next »"
    117 
    118                 setCheckbox(name: "sample_22_assay_25") // 60_63
    119                 clickButton "next »"
    120                 clickButton "next »"
    121 
    122                 // and we should be done, without exceptions
    123                 // verifyText(text:'Done')
    124                 // does not seem to work, also see --> http://grails.1312388.n4.nabble.com/webtest-verifyText-doesn-t-see-AJAX-update-with-easyAjax-td2225674.html
    125 
    126                 // and view the study
    127                 clickLink "view the study"
     24       
     25        clickLink "Studies"
     26        clickLink "Import study data"
     27       
     28        setSelectField(name: "entity", text: "Study")       
     29        clickButton "next »"
     30       
     31        // Set column properties (TemplateFields)
     32        setSelectField(name: "columnproperty.index.0", text: "startDate")
     33        setSelectField(name: "columnproperty.index.1", text: "code (IDENTIFIER)")
     34        setSelectField(name: "columnproperty.index.15", text: "title")
     35        setSelectField(name: "columnproperty.index.16", text: "description")
     36        clickButton "next »"
     37       
     38        // Validate and store
     39        clickButton "next »"
     40       
     41       
    12842        }
    12943
Note: See TracChangeset for help on using the changeset viewer.