Changeset 6262


Ignore:
Timestamp:
06/02/15 10:33:02 (9 years ago)
Author:
Menzo Windhouwer
Message:

M toolkit/src/test/java/eu/clarin/cmd/toolkit/TestCMDToolkit.java

  • added more tests

A toolkit/src/test/resources/toolkit/OLAC

  • test based on an invalid OLAC CMD record
Location:
metadata/trunk/toolkit
Files:
5 added
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • metadata/trunk/toolkit

    • Property svn:ignore set to
      target
  • metadata/trunk/toolkit/src/main/resources/toolkit/upgrade/cmd-record-1_1-to-1_2.xsl

    r6255 r6262  
    146146   
    147147    <!-- move CMD attributes to the CMD namespace -->
     148    <!-- TODO: @ref is allowed on elements, how to know if this is a element or a component with no children? -->
     149    <!--<xsl:template match="cmd0:Components//*[exists(*)]/@ref">-->
    148150    <xsl:template match="cmd0:Components//@ref">
    149151        <xsl:attribute name="cmd:ref" select="."/>
  • metadata/trunk/toolkit/src/test/java/eu/clarin/cmd/toolkit/TestCMDToolkit.java

    r6255 r6262  
    2222import net.sf.saxon.s9api.DOMDestination;
    2323import net.sf.saxon.s9api.QName;
     24import net.sf.saxon.s9api.XPathCompiler;
     25import net.sf.saxon.s9api.XPathExecutable;
     26import net.sf.saxon.s9api.XPathSelector;
    2427import net.sf.saxon.s9api.XdmAtomicValue;
    2528import net.sf.saxon.s9api.XdmDestination;
     
    4548    XsltTransformer transformCMDSpecInXSD = null;
    4649    SchemAnon validateCMDSpec = null;
     50    SchemAnon validateCMDEnvelop = null;
    4751
    4852    @Before
     
    5357            transformCMDSpecInXSD = SaxonUtils.buildTransformer(CMDToolkit.class.getResource("/toolkit/xslt/comp2schema.xsl")).load();
    5458            validateCMDSpec = new SchemAnon(CMDToolkit.class.getResource("/toolkit/xsd/cmd-component.xsd").toURI().toURL());
     59            validateCMDEnvelop = new SchemAnon(CMDToolkit.class.getResource("/toolkit/xsd/cmd-envelop.xsd").toURI().toURL());
    5560        } catch(Exception e) {
    5661            System.err.println("!ERR: couldn't setup the testing environment!");
     
    8388    }
    8489   
     90    protected boolean xpath(Document doc,String xpath) throws Exception {
     91        XPathCompiler xpc   = SaxonUtils.getProcessor().newXPathCompiler();
     92        xpc.declareNamespace("cmd","http://www.clarin.eu/cmd/1");
     93        XPathExecutable xpe = xpc.compile(xpath);
     94        XPathSelector xps   = xpe.load();
     95        xps.setContextItem(SaxonUtils.getProcessor().newDocumentBuilder().wrap(doc));
     96        return xps.effectiveBooleanValue();
     97    }
     98   
    8599    protected void printMessages(SchemAnon anon) throws Exception {
    86100        for (Message msg : anon.getMessages()) {
     
    118132    protected boolean validateCMDSpec(String spec,Source src) throws Exception {
    119133        System.out.println("Validate CMD spec["+spec+"]");
    120         return validateCMDSpec.validate(src);
     134        boolean res = validateCMDSpec.validate(src);
     135        System.out.println("CMD spec["+spec+"]: "+(res?"VALID":"INVALID"));
     136        printMessages(validateCMDSpec);
     137        return res;
     138    }
     139   
     140    protected boolean validateCMDSpec(String spec) throws Exception {
     141        return validateCMDSpec(spec,new StreamSource(new java.io.File(TestCMDToolkit.class.getResource(spec).toURI())));
    121142    }
    122143   
    123144    protected boolean validateCMDRecord(String spec,SchemAnon anon,String rec,Source src) throws Exception {
    124145        System.out.println("Validate CMD record["+rec+"] against spec["+spec+"]");
    125         return anon.validate(src);
    126     }
    127 
    128     @Test
    129     public void valid_Adelheid() throws Exception {
    130         System.out.println("DBG: current working directory["+Paths.get("").toAbsolutePath().toString()+"]");
    131        
     146        boolean res = anon.validate(src);
     147        System.out.println("CMD record["+rec+"]: "+(res?"VALID":"INVALID"));
     148        printMessages(anon);
     149        return res;
     150    }
     151   
     152    protected boolean validateCMDEnvelop(String rec,Source src) throws Exception {
     153        System.out.println("Validate envelop CMD rec["+rec+"]");
     154        boolean res = validateCMDEnvelop.validate(src);
     155        System.out.println("CMD rec["+rec+"] evelop: "+(res?"VALID":"INVALID"));
     156        printMessages(validateCMDEnvelop);
     157        return res;
     158    }
     159   
     160    protected boolean validateCMDEnvelop(String rec) throws Exception {
     161        return validateCMDEnvelop(rec,new StreamSource(new java.io.File(TestCMDToolkit.class.getResource(rec).toURI())));
     162    }
     163   
     164    @Test
     165    public void testAdelheid() throws Exception {
    132166        String profile = "/toolkit/Adelheid/profiles/clarin.eu:cr1:p_1311927752306.xml";
    133167        String record  = "/toolkit/Adelheid/records/Adelheid.cmdi";
     
    138172        // validate the 1.2 profile
    139173        boolean validProfile = validateCMDSpec(profile+" (upgraded)",new DOMSource(upgradedProfile));
    140         System.out.println("Upgraded CMD profile["+profile+"]: "+(validProfile?"VALID":"INVALID"));
    141         printMessages(validateCMDSpec);
    142        
    143         // assertions
     174       
     175        // assertions
     176        // the upgraded profile should be a valid CMDI 1.2 profile
    144177        assertTrue(validProfile);
     178        // so there should be no errors
    145179        assertEquals(0, countErrors(validateCMDSpec));
    146180       
     
    154188        // validate the 1.2 record
    155189        boolean validRecord = validateCMDRecord(profile+" (upgraded)",profileAnon,record+" (upgraded)",new DOMSource(upgradedRecord));
    156         System.out.println("Upgraded CMD record["+record+"]: "+(validRecord?"VALID":"INVALID"));
    157         printMessages(profileAnon);
    158        
    159         // assertions
     190       
     191        // assertions
     192        // the upgraded record should be a valid CMDI 1.2 record
    160193        assertTrue(validRecord);
     194        // so there should be no errors
    161195        assertEquals(0, countErrors(profileAnon));
    162196    }
     197
     198    @Test
     199    public void testTEI() throws Exception {
     200        String record  = "/toolkit/TEI/records/sundhed_dsn.teiHeader.ref.xml";
     201
     202        // upgrade the record from 1.1 to 1.2
     203        Document upgradedRecord = upgradeCMDRecord(record);
     204       
     205        // assertions
     206        // the @ref attributes on the elements should stay as they are
     207        assertTrue(xpath(upgradedRecord,"//*:author/*:name/@ref"));
     208    }
     209
     210    @Test
     211    public void testSuccessor() throws Exception {
     212        String validRecord  = "/toolkit/successor/profiles/successor-valid.xml";
     213        String invalidRecord  = "/toolkit/successor/profiles/successor-invalid.xml";
     214
     215        // assertions
     216        assertTrue(validateCMDSpec(validRecord));
     217        assertFalse(validateCMDSpec(invalidRecord));
     218    }
     219
     220    @Test
     221    public void testOLAC() throws Exception {
     222        String profile = "/toolkit/OLAC/profiles/OLAC-DcmiTerms.xml";
     223        String record  = "/toolkit/OLAC/records/org_rosettaproject-record.xml";
     224       
     225        // upgrade the profile from 1.1 to 1.2
     226        Document upgradedProfile = upgradeCMDSpec(profile);
     227       
     228        // validate the 1.2 profile
     229        boolean validProfile = validateCMDSpec(profile+" (upgraded)",new DOMSource(upgradedProfile));
     230       
     231        // assertions
     232        // the upgraded profile should be a valid CMDI 1.2 profile
     233        assertTrue(validProfile);
     234        // so there should be no errors
     235        assertEquals(0, countErrors(validateCMDSpec));
     236       
     237        // transform the 1.2 profile into a XSD
     238        Document profileSchema = transformCMDSpecInXSD(profile+" (upgraded)",new DOMSource(upgradedProfile));
     239        SchemAnon profileAnon = new SchemAnon(new DOMSource(profileSchema));
     240       
     241        // upgrade the record from 1.1 to 1.2
     242        Document upgradedRecord = upgradeCMDRecord(record);
     243       
     244        // validate the 1.2 record
     245        boolean validRecord = validateCMDRecord(profile+" (upgraded)",profileAnon,record+" (upgraded)",new DOMSource(upgradedRecord));
     246
     247        // assertions
     248        assertFalse(validRecord);
     249    }
    163250}
  • metadata/trunk/toolkit/src/test/resources/toolkit/successor/profiles/successor-valid.xml

    r6255 r6262  
    88        <Description>Description of a tool and/or service(s)
    99(adapted from the AnnotationTool profile)</Description>
    10         <Status>production</Status>
     10        <Status>deprecated</Status>
    1111        <Successor>hdl:123</Successor>
    1212    </Header>
Note: See TracChangeset for help on using the changeset viewer.