Changeset 6904 for metadata/trunk/toolkit/src
- Timestamp:
- 01/13/16 12:37:51 (9 years ago)
- 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 73 73 </xsl:template> 74 74 75 <!-- remove Vocabulary level -->75 <!-- remove Vocabulary level, incl. attributes --> 76 76 <xsl:template match="Vocabulary" priority="1"> 77 77 <xsl:apply-templates select="node()"/> … … 80 80 <!-- turn Attribute child elements into attributes --> 81 81 <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> 98 106 </xsl:template> 99 107 -
metadata/trunk/toolkit/src/main/resources/toolkit/xsd/cmd-component.xsd
r6901 r6904 155 155 <sch:title>Check Vocabulary URI</sch:title> 156 156 <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> 158 158 </sch:rule> 159 159 </sch:pattern> … … 205 205 <xs:annotation> 206 206 <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> 207 213 <sch:pattern id="a_sibs"> 208 214 <sch:title>Check attribute siblings</sch:title> -
metadata/trunk/toolkit/src/test/java/eu/clarin/cmd/toolkit/TestCMDToolkit.java
r6901 r6904 7 7 import java.io.File; 8 8 import java.io.IOException; 9 import java.net.URL; 9 10 import java.nio.file.Paths; 10 11 import java.util.HashMap; … … 45 46 46 47 XsltTransformer upgradeCMDSpec = null; 48 XsltTransformer downgradeCMDSpec = null; 47 49 XsltTransformer upgradeCMDRec = null; 48 50 XsltTransformer transformCMDSpecInXSD = null; 49 51 SchemAnon validateCMDSpec = null; 52 SchemAnon validateCMDoldSpec = null; 50 53 SchemAnon validateCMDEnvelop = null; 51 54 … … 54 57 try { 55 58 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(); 56 60 upgradeCMDRec = SaxonUtils.buildTransformer(CMDToolkit.class.getResource("/toolkit/upgrade/cmd-record-1_1-to-1_2.xsl")).load(); 57 61 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")); 59 65 validateCMDEnvelop = new SchemAnon(CMDToolkit.class.getResource("/toolkit/xsd/cmd-envelop.xsd").toURI().toURL()); 60 66 } catch(Exception e) { … … 116 122 } 117 123 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 118 134 protected Document upgradeCMDRecord(String rec) throws Exception { 119 135 System.out.println("Upgrade CMD spec["+rec+"]"); … … 138 154 } 139 155 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 140 164 protected boolean validateCMDSpec(String spec) throws Exception { 141 165 return validateCMDSpec(spec,new StreamSource(new java.io.File(TestCMDToolkit.class.getResource(spec).toURI()))); … … 194 218 // so there should be no errors 195 219 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)); 196 232 } 197 233 … … 219 255 // the record should be a invalid as it misses a the required CoreVersion attribute 220 256 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)); 221 269 } 222 270 … … 254 302 // so there should be no errors 255 303 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)); 256 316 } 257 317 … … 307 367 // assertions 308 368 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)); 309 381 } 310 382
Note: See TracChangeset
for help on using the changeset viewer.