Changeset 6904 for metadata


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
Location:
metadata/trunk/toolkit/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • metadata/trunk/toolkit/src/main/resources/toolkit/downgrade/cmd-component-1_2-to-1_1.xsl

    r6902 r6904  
    7373    </xsl:template>
    7474
    75     <!-- remove Vocabulary level -->
     75    <!-- remove Vocabulary level, incl. attributes -->
    7676    <xsl:template match="Vocabulary" priority="1">
    7777        <xsl:apply-templates select="node()"/>
     
    8080    <!-- turn Attribute child elements into attributes -->
    8181    <xsl:template match="Attribute" priority="1">
    82         <Attribute name="{Name}">
    83             <Name>
    84                 <xsl:value-of select="@name"/>
    85             </Name>
    86             <xsl:if test="normalize-space(@ValueScheme)!=''">
    87                 <Type>
    88                     <xsl:value-of select="@ValueScheme"/>
    89                 </Type>
    90             </xsl:if>
    91             <xsl:if test="normalize-space(@ConceptLink)!=''">
    92                 <ConceptLink>
    93                     <xsl:value-of select="@ConceptLink"/>
    94                 </ConceptLink>
    95             </xsl:if>
    96             <xsl:apply-templates select="node()"/>
    97         </Attribute>
     82        <xsl:choose>
     83            <xsl:when test="exists(parent::AttributeList/parent::Component) and Name=('ref','ComponentId')">
     84                <xsl:message>WRN: user-defined ref and ComponentId attributes for a Component are not supported by CMDI 1.1!</xsl:message>
     85            </xsl:when>
     86            <xsl:otherwise>
     87                <Attribute>
     88                    <Name>
     89                        <xsl:value-of select="@name"/>
     90                    </Name>
     91                    <xsl:if test="normalize-space(@ConceptLink)!=''">
     92                        <ConceptLink>
     93                            <xsl:value-of select="@ConceptLink"/>
     94                        </ConceptLink>
     95                    </xsl:if>
     96                    <xsl:if test="normalize-space(@ValueScheme)!=''">
     97                        <Type>
     98                            <xsl:value-of select="@ValueScheme"/>
     99                        </Type>
     100                    </xsl:if>
     101                    <!-- @Required is skipped -->
     102                    <xsl:apply-templates select="node()"/>
     103                </Attribute>
     104            </xsl:otherwise>
     105        </xsl:choose>
    98106    </xsl:template>
    99107   
  • metadata/trunk/toolkit/src/main/resources/toolkit/xsd/cmd-component.xsd

    r6901 r6904  
    155155                    <sch:title>Check Vocabulary URI</sch:title>
    156156                    <sch:rule context="Vocabulary[exists(@URI)]">
    157                         <sch:assert test="exists(@ValueProperty)">When an external vocabulary (identified by the @URI) a @ValueProperty has to be specified!</sch:assert>
     157                        <sch:assert test="exists(@ValueProperty)">When an external vocabulary is used (identified by the @URI) a @ValueProperty has to be specified!</sch:assert>
    158158                    </sch:rule>
    159159                </sch:pattern>
     
    205205                <xs:annotation>
    206206                    <xs:appinfo>
     207                        <sch:pattern id="a_res">
     208                            <sch:title>Check reserved attribute names</sch:title>
     209                            <sch:rule context="Attribute" role="warning">
     210                                <sch:assert test="not(exists(parent::AttributeList/parent::Component) and @name=('ref','ComponentId'))">Attributes with name 'ref' or 'ComponentId' will not be available in a downgrade to CMDI 1.1!</sch:assert>
     211                            </sch:rule>
     212                        </sch:pattern>
    207213                        <sch:pattern id="a_sibs">
    208214                            <sch:title>Check attribute siblings</sch:title>
  • 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.