Ignore:
Timestamp:
01/13/16 12:37:51 (8 years ago)
Author:
Menzo Windhouwer
Message:

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

  • added downgrade tests

M toolkit/src/main/resources/toolkit/xsd/cmd-component.xsd

  • readded a_res Schematron rule to warn that @ref and @ComponentId? wont survive a downgrade to 1.1

M toolkit/src/main/resources/toolkit/downgrade/cmd-component-1_2-to-1_1.xsl

  • fixes around Attributes
File:
1 edited

Legend:

Unmodified
Added
Removed
  • metadata/trunk/toolkit/src/test/java/eu/clarin/cmd/toolkit/TestCMDToolkit.java

    r6901 r6904  
    77import java.io.File;
    88import java.io.IOException;
     9import java.net.URL;
    910import java.nio.file.Paths;
    1011import java.util.HashMap;
     
    4546
    4647    XsltTransformer upgradeCMDSpec = null;
     48    XsltTransformer downgradeCMDSpec = null;
    4749    XsltTransformer upgradeCMDRec = null;
    4850    XsltTransformer transformCMDSpecInXSD = null;
    4951    SchemAnon validateCMDSpec = null;
     52    SchemAnon validateCMDoldSpec = null;
    5053    SchemAnon validateCMDEnvelop = null;
    5154
     
    5457        try {
    5558            upgradeCMDSpec = SaxonUtils.buildTransformer(CMDToolkit.class.getResource("/toolkit/upgrade/cmd-component-1_1-to-1_2.xsl")).load();
     59            downgradeCMDSpec = SaxonUtils.buildTransformer(CMDToolkit.class.getResource("/toolkit/downgrade/cmd-component-1_2-to-1_1.xsl")).load();
    5660            upgradeCMDRec = SaxonUtils.buildTransformer(CMDToolkit.class.getResource("/toolkit/upgrade/cmd-record-1_1-to-1_2.xsl")).load();
    5761            transformCMDSpecInXSD = SaxonUtils.buildTransformer(CMDToolkit.class.getResource("/toolkit/xslt/comp2schema.xsl")).load();
    58             validateCMDSpec = new SchemAnon(CMDToolkit.class.getResource("/toolkit/xsd/cmd-component.xsd").toURI().toURL());
     62            validateCMDSpec = new SchemAnon(CMDToolkit.class.getResource("/toolkit/xsd/cmd-component.xsd").toURI().toURL());           
     63            validateCMDoldSpec = new SchemAnon(new URL("http://infra.clarin.eu/cmd/general-component-schema.xsd"));
     64//            validateCMDoldSpec = new SchemAnon(new URL("file:///Users/menzowi/Documents/Projects/CLARIN/CMDI/CMDI-1.1/src/toolkit/general-component-schema.xsd"));
    5965            validateCMDEnvelop = new SchemAnon(CMDToolkit.class.getResource("/toolkit/xsd/cmd-envelop.xsd").toURI().toURL());
    6066        } catch(Exception e) {
     
    116122    }
    117123
     124    protected Document downgradeCMDSpec(String spec) throws Exception {
     125        System.out.println("Downgrade CMD spec["+spec+"]");
     126        return transform(downgradeCMDSpec,new javax.xml.transform.stream.StreamSource(new java.io.File(TestCMDToolkit.class.getResource(spec).toURI())));
     127    }
     128
     129    protected Document downgradeCMDSpec(String spec,Source src) throws Exception {
     130        System.out.println("Downgrade CMD spec["+spec+"]");
     131        return transform(downgradeCMDSpec,src);
     132    }
     133
    118134    protected Document upgradeCMDRecord(String rec) throws Exception {
    119135        System.out.println("Upgrade CMD spec["+rec+"]");
     
    138154    }
    139155
     156    protected boolean validateCMDoldSpec(String spec,Source src) throws Exception {
     157        System.out.println("Validate CMD 1.1 spec["+spec+"]");
     158        boolean res = validateCMDoldSpec.validate(src);
     159        System.out.println("CMD old spec["+spec+"]: "+(res?"VALID":"INVALID"));
     160        printMessages(validateCMDoldSpec);
     161        return res;
     162    }
     163
    140164    protected boolean validateCMDSpec(String spec) throws Exception {
    141165        return validateCMDSpec(spec,new StreamSource(new java.io.File(TestCMDToolkit.class.getResource(spec).toURI())));
     
    194218        // so there should be no errors
    195219        assertEquals(0, countErrors(profileAnon));
     220       
     221        // downgrade the 1.2 profile to 1.1
     222        Document oldProfile = downgradeCMDSpec(profile+" (upgraded)",new DOMSource(upgradedProfile));
     223       
     224        // validate the 1.1 profile
     225        boolean validOldProfile = validateCMDoldSpec(profile+" (downgraded)",new DOMSource(oldProfile));
     226
     227        // assertions
     228        // the downgraded profile should be a valid CMDI 1.1 profile
     229        assertTrue(validOldProfile);
     230        // so there should be no errors
     231        assertEquals(0, countErrors(validateCMDoldSpec));       
    196232    }
    197233
     
    219255        // the record should be a invalid as it misses a the required CoreVersion attribute
    220256        assertFalse(validRecord);
     257
     258        // downgrade the 1.2 profile to 1.1
     259        Document oldProfile = downgradeCMDSpec(profile);
     260       
     261        // validate the 1.1 profile
     262        boolean validOldProfile = validateCMDoldSpec(profile+" (downgraded)",new DOMSource(oldProfile));
     263
     264        // assertions
     265        // the downgraded profile should be a valid CMDI 1.1 profile
     266        assertTrue(validOldProfile);
     267        // so there should be no errors
     268        assertEquals(0, countErrors(validateCMDoldSpec));       
    221269    }
    222270
     
    254302        // so there should be no errors
    255303        assertEquals(0, countErrors(profileAnon));
     304       
     305        // downgrade the 1.2 profile to 1.1
     306        Document oldProfile = downgradeCMDSpec(profile+" (upgraded)",new DOMSource(upgradedProfile));
     307       
     308        // validate the 1.1 profile
     309        boolean validOldProfile = validateCMDoldSpec(profile+" (downgraded)",new DOMSource(oldProfile));
     310
     311        // assertions
     312        // the downgraded profile should be a valid CMDI 1.1 profile
     313        assertTrue(validOldProfile);
     314        // so there should be no errors
     315        assertEquals(0, countErrors(validateCMDoldSpec));       
    256316    }
    257317
     
    307367        // assertions
    308368        assertFalse(validRecord);
     369
     370        // downgrade the 1.2 profile to 1.1
     371        Document oldProfile = downgradeCMDSpec(profile+" (upgraded)",new DOMSource(upgradedProfile));
     372       
     373        // validate the 1.1 profile
     374        boolean validOldProfile = validateCMDoldSpec(profile+" (downgraded)",new DOMSource(oldProfile));
     375
     376        // assertions
     377        // the downgraded profile should be a valid CMDI 1.1 profile
     378        assertTrue(validOldProfile);
     379        // so there should be no errors
     380        assertEquals(0, countErrors(validateCMDoldSpec));       
    309381    }
    310382
Note: See TracChangeset for help on using the changeset viewer.