source: trunk/test/integration/gscf/ImporterTests.groovy

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

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

File size: 2.0 KB
Line 
1package gscf
2
3import org.springframework.core.io.*
4import grails.converters.*
5import dbnp.authentication.*
6import org.dbnp.gdt.Template
7
8/**
9 * ImporterTests Test
10 *
11 * Description of my test
12 *
13 * @author  Tjeerd
14 * @since       20110314
15 * @package     gscf
16 *
17 * Revision information:
18 * $Rev$
19 * $Author$
20 * $Date$
21 */
22class ImporterTests extends GroovyTestCase {
23    def importerService
24
25    static final String testStudyExcelFile = "testfiles/NTC_Experiment_test4.xls"
26    static final String testStudyXMLTemplateFile = "testfiles/ntc_tudy_template.xml"
27    static final String testSheetIndex = "0"
28    static final String testHeaderRow = "0"
29    static final String testDatamatrixStart = "0"
30   
31    protected void setUp() {
32        super.setUp()
33    }
34
35    protected void tearDown() {
36        super.tearDown()
37    }
38
39    /**
40    * Try to import an example Excel study and an XML study template
41    */
42    void testImportExcelAndXMLTemplateStudy() {
43        def xmltemplate
44        def user = SecUser.findByUsername( "user" );
45       
46        // Load the files from a subfolder in the integration test folder and setup input streams
47        Resource resourceExcel = new ClassPathResource(testStudyExcelFile, getClass().classLoader)
48        Resource resourceXMLTemplate = new ClassPathResource(testStudyXMLTemplateFile, getClass().classLoader)
49
50        // Create input streams from the resources
51        def fisExcel = new FileInputStream(resourceExcel.getFile())
52        assert fisExcel
53
54        def fisXML = new FileInputStream(resourceXMLTemplate.getFile())
55        assert fisXML
56
57        // Retrieve the input stream as an Excel workbook
58        def wb = importerService.getWorkbook(fisExcel)
59        assert wb
60
61        // Parse XML
62                try {
63                        xmltemplate = XML.parse(fisXML, "UTF-8")
64                } catch( Exception e ) {
65                        println "Parsing failed" + e
66                }
67
68        assert xmltemplate
69
70        xmltemplate.template.each {
71            println it
72        }
73
74        // Parse the XML template
75        def t = Template.parse(xmltemplate.template, user);
76
77        assert t
78    }
79}
Note: See TracBrowser for help on using the repository browser.