Changeset 6901
- Timestamp:
- 01/12/16 14:41:23 (9 years ago)
- Location:
- metadata/trunk/toolkit
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
metadata/trunk/toolkit/pom.xml
r6256 r6901 33 33 <id>cmdi.clarin.repository</id> 34 34 <name>Clarin Repository</name> 35 <url>http ://catalog.clarin.eu/ds/nexus/content/groups/public/</url>35 <url>https://nexus.clarin.eu/content/repositories/Clarin</url> 36 36 </repository> 37 37 </repositories> -
metadata/trunk/toolkit/src/main/resources/toolkit/xsd/cmd-component.xsd
r6859 r6901 1 1 <?xml version="1.0" encoding="UTF-8"?> 2 <!-- 3 $Revision$ 4 $Date$ 2 <!-- 3 $Revision$ 4 $Date$ 5 5 --> 6 6 7 7 <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:sch="http://purl.oclc.org/dsdl/schematron" 8 8 xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" vc:minVersion="1.0" vc:maxVersion="1.1"> 9 9 10 10 <xs:import namespace="http://www.w3.org/XML/1998/namespace" 11 11 schemaLocation="http://www.w3.org/2005/08/xml.xsd"/> … … 92 92 <!-- from small (attribute) to big (component) --> 93 93 <xs:element name="AttributeList" type="AttributeList_type" minOccurs="0" maxOccurs="1"/> 94 <xs:element name="Element" type="Element_type" minOccurs="0" maxOccurs="unbounded"/> 94 <xs:element name="Element" type="Element_type" minOccurs="0" maxOccurs="unbounded"/> 95 95 <xs:element name="Component" type="Component_type" minOccurs="0" maxOccurs="unbounded"/> 96 96 </xs:sequence> … … 117 117 </xs:simpleContent> 118 118 </xs:complexType> 119 119 120 120 <xs:complexType name="Element_type"> 121 121 <xs:annotation> … … 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">210 <sch:assert test="not(@name=('ref','ComponentId'))">Attribute name shouldn't be 'ref' or 'ComponentId', as these are used internally by CMD!</sch:assert>211 </sch:rule>212 </sch:pattern>213 207 <sch:pattern id="a_sibs"> 214 208 <sch:title>Check attribute siblings</sch:title> … … 273 267 <xs:anyAttribute namespace="http://www.clarin.eu/cmdi/cues/1" processContents="lax"/> 274 268 </xs:attributeGroup> 275 269 276 270 <xs:attributeGroup name="element_attributes"> 277 271 <xs:attribute name="name" type="xs:Name" use="required"> … … 361 355 8 unbounded number NOK 362 356 9 unbounded unbounded OK 363 357 364 358 UNK can be either a missing attribute or an empty value, both can be detected with normalize-space(@...)='' 365 359 366 360 default CardinalityMin is 1 (based on the XSD minOccurs default value) 367 361 default CardinalityMax is 1 (based on the XSD maxOccurs default value) 368 362 369 363 If a basic XSLT 2.0 engine, like Saxon HE, is used for Schematron validation we can't cast to xs:nonNegativeInteger. 370 364 So we cast to xs:integer. The XSD validator should have already validated that the values are valid cardinality_types. … … 455 449 </sch:rule> 456 450 </sch:pattern> 457 </xs:appinfo> 451 </xs:appinfo> 458 452 </xs:annotation> 459 453 <xs:simpleContent> -
metadata/trunk/toolkit/src/test/java/eu/clarin/cmd/toolkit/TestCMDToolkit.java
r6855 r6901 47 47 XsltTransformer upgradeCMDRec = null; 48 48 XsltTransformer transformCMDSpecInXSD = null; 49 SchemAnon validateCMDSpec = null; 50 SchemAnon validateCMDEnvelop = null; 49 SchemAnon validateCMDSpec = null; 50 SchemAnon validateCMDEnvelop = null; 51 51 52 52 @Before … … 56 56 upgradeCMDRec = SaxonUtils.buildTransformer(CMDToolkit.class.getResource("/toolkit/upgrade/cmd-record-1_1-to-1_2.xsl")).load(); 57 57 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()); 59 validateCMDEnvelop = new SchemAnon(CMDToolkit.class.getResource("/toolkit/xsd/cmd-envelop.xsd").toURI().toURL()); 58 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()); 60 60 } catch(Exception e) { 61 61 System.err.println("!ERR: couldn't setup the testing environment!"); … … 68 68 public void tearDown() { 69 69 } 70 70 71 71 protected Document transform(XsltTransformer trans,Source src) throws Exception { 72 72 try { … … 87 87 } 88 88 } 89 89 90 90 protected boolean xpath(Document doc,String xpath) throws Exception { 91 91 XPathCompiler xpc = SaxonUtils.getProcessor().newXPathCompiler(); … … 96 96 return xps.effectiveBooleanValue(); 97 97 } 98 98 99 99 protected void printMessages(SchemAnon anon) throws Exception { 100 100 for (Message msg : anon.getMessages()) { … … 103 103 } 104 104 } 105 105 106 106 protected int countErrors(SchemAnon anon) throws Exception { 107 107 int cnt = 0; … … 110 110 return cnt; 111 111 } 112 112 113 113 protected Document upgradeCMDSpec(String spec) throws Exception { 114 114 System.out.println("Upgrade CMD spec["+spec+"]"); … … 120 120 return transform(upgradeCMDRec,new javax.xml.transform.stream.StreamSource(new java.io.File(TestCMDToolkit.class.getResource(rec).toURI()))); 121 121 } 122 123 protected Document transformCMDSpecInXSD(String spec,Source src) throws Exception { 122 123 protected Document transformCMDSpecInXSD(String spec,Source src) throws Exception { 124 124 System.out.println("Transform CMD spec["+spec+"] into XSD"); 125 125 return transform(transformCMDSpecInXSD,src); 126 126 } 127 127 128 128 protected Document transformCMDSpecInXSD(String spec) throws Exception { 129 129 return transformCMDSpecInXSD(spec,new javax.xml.transform.stream.StreamSource(new java.io.File(TestCMDToolkit.class.getResource(spec).toURI()))); 130 130 } 131 131 132 132 protected boolean validateCMDSpec(String spec,Source src) throws Exception { 133 133 System.out.println("Validate CMD spec["+spec+"]"); … … 137 137 return res; 138 138 } 139 139 140 140 protected boolean validateCMDSpec(String spec) throws Exception { 141 141 return validateCMDSpec(spec,new StreamSource(new java.io.File(TestCMDToolkit.class.getResource(spec).toURI()))); 142 142 } 143 143 144 144 protected boolean validateCMDRecord(String spec,SchemAnon anon,String rec,Source src) throws Exception { 145 145 System.out.println("Validate CMD record["+rec+"] against spec["+spec+"]"); … … 149 149 return res; 150 150 } 151 151 152 152 protected boolean validateCMDEnvelop(String rec,Source src) throws Exception { 153 153 System.out.println("Validate envelop CMD rec["+rec+"]"); … … 157 157 return res; 158 158 } 159 159 160 160 protected boolean validateCMDEnvelop(String rec) throws Exception { 161 161 return validateCMDEnvelop(rec,new StreamSource(new java.io.File(TestCMDToolkit.class.getResource(rec).toURI()))); 162 162 } 163 163 164 164 @Test 165 165 public void testAdelheid() throws Exception { 166 166 String profile = "/toolkit/Adelheid/profiles/clarin.eu:cr1:p_1311927752306.xml"; 167 167 String record = "/toolkit/Adelheid/records/Adelheid.cmdi"; 168 168 169 169 // upgrade the profile from 1.1 to 1.2 170 170 Document upgradedProfile = upgradeCMDSpec(profile); 171 171 172 172 // validate the 1.2 profile 173 173 boolean validProfile = validateCMDSpec(profile+" (upgraded)",new DOMSource(upgradedProfile)); 174 174 175 175 // assertions 176 176 // the upgraded profile should be a valid CMDI 1.2 profile … … 178 178 // so there should be no errors 179 179 assertEquals(0, countErrors(validateCMDSpec)); 180 180 181 181 // transform the 1.2 profile into a XSD 182 182 Document profileSchema = transformCMDSpecInXSD(profile+" (upgraded)",new DOMSource(upgradedProfile)); 183 183 SchemAnon profileAnon = new SchemAnon(new DOMSource(profileSchema)); 184 184 185 185 // upgrade the record from 1.1 to 1.2 186 186 Document upgradedRecord = upgradeCMDRecord(record); 187 187 188 188 // validate the 1.2 record 189 189 boolean validRecord = validateCMDRecord(profile+" (upgraded)",profileAnon,record+" (upgraded)",new DOMSource(upgradedRecord)); 190 190 191 191 // assertions 192 192 // the upgraded record should be a valid CMDI 1.2 record … … 200 200 String profile = "/toolkit/Adelheid/profiles/clarin.eu:cr1:p_1311927752306_1_2.xml"; 201 201 String record = "/toolkit/Adelheid/records/Adelheid_1_2-invalid.cmdi"; 202 202 203 203 // validate the 1.2 profile 204 204 boolean validProfile = validateCMDSpec(profile,new javax.xml.transform.stream.StreamSource(new java.io.File(TestCMDToolkit.class.getResource(profile).toURI()))); 205 205 206 206 // assertions 207 207 // the upgraded profile should be a valid CMDI 1.2 profile … … 209 209 // so there should be no errors 210 210 assertEquals(0, countErrors(validateCMDSpec)); 211 211 212 212 Document profileSchema = transformCMDSpecInXSD(profile,new javax.xml.transform.stream.StreamSource(new java.io.File(TestCMDToolkit.class.getResource(profile).toURI()))); 213 213 SchemAnon profileAnon = new SchemAnon(new DOMSource(profileSchema)); 214 214 215 215 // validate the 1.2 record 216 216 boolean validRecord = validateCMDRecord(profile,profileAnon,record,new javax.xml.transform.stream.StreamSource(new java.io.File(TestCMDToolkit.class.getResource(record).toURI()))); 217 217 218 218 // assertions 219 219 // the record should be a invalid as it misses a the required CoreVersion attribute … … 222 222 223 223 @Test 224 public void testSundhed() throws Exception { 225 String profile = "/toolkit/TEI/profiles/clarin.eu:cr1:p_1380106710826.xml"; 226 String record = "/toolkit/TEI/records/sundhed_dsn.teiHeader.ref.xml"; 227 228 // upgrade the profile from 1.1 to 1.2 229 Document upgradedProfile = upgradeCMDSpec(profile); 230 231 // validate the 1.2 profile 232 boolean validProfile = validateCMDSpec(profile+" (upgraded)",new DOMSource(upgradedProfile)); 233 234 // assertions 235 // the upgraded profile should be a valid CMDI 1.2 profile and 'ref' named Attributes should validate 236 assertTrue(validProfile); 237 // so there should be no errors 238 assertEquals(0, countErrors(validateCMDSpec)); 239 240 // transform the 1.2 profile into a XSD 241 Document profileSchema = transformCMDSpecInXSD(profile+" (upgraded)",new DOMSource(upgradedProfile)); 242 SchemAnon profileAnon = new SchemAnon(new DOMSource(profileSchema)); 243 244 // upgrade the record from 1.1 to 1.2 245 Document upgradedRecord = upgradeCMDRecord(record); 246 247 // validate the 1.2 record 248 boolean validRecord = validateCMDRecord(profile+" (upgraded)", profileAnon, record+" (upgraded)", new DOMSource(upgradedRecord)); 249 250 // assertions 251 // the upgraded record should be a valid CMDI 1.2 record 252 assertTrue(validRecord); 253 254 // so there should be no errors 255 assertEquals(0, countErrors(profileAnon)); 256 } 257 258 @Test 224 259 public void testTEI() throws Exception { 225 260 String record = "/toolkit/TEI/records/sundhed_dsn.teiHeader.ref.xml"; … … 227 262 // upgrade the record from 1.1 to 1.2 228 263 Document upgradedRecord = upgradeCMDRecord(record); 229 264 230 265 // assertions 231 266 // the @ref attributes on the elements should stay as they are … … 247 282 String profile = "/toolkit/OLAC/profiles/OLAC-DcmiTerms.xml"; 248 283 String record = "/toolkit/OLAC/records/org_rosettaproject-record.xml"; 249 284 250 285 // upgrade the profile from 1.1 to 1.2 251 286 Document upgradedProfile = upgradeCMDSpec(profile); 252 287 253 288 // validate the 1.2 profile 254 289 boolean validProfile = validateCMDSpec(profile+" (upgraded)",new DOMSource(upgradedProfile)); 255 290 256 291 // assertions 257 292 // the upgraded profile should be a valid CMDI 1.2 profile … … 259 294 // so there should be no errors 260 295 assertEquals(0, countErrors(validateCMDSpec)); 261 296 262 297 // transform the 1.2 profile into a XSD 263 298 Document profileSchema = transformCMDSpecInXSD(profile+" (upgraded)",new DOMSource(upgradedProfile)); 264 299 SchemAnon profileAnon = new SchemAnon(new DOMSource(profileSchema)); 265 300 266 301 // upgrade the record from 1.1 to 1.2 267 302 Document upgradedRecord = upgradeCMDRecord(record); 268 303 269 304 // validate the 1.2 record 270 305 boolean validRecord = validateCMDRecord(profile+" (upgraded)",profileAnon,record+" (upgraded)",new DOMSource(upgradedRecord)); … … 284 319 assertFalse(validProfile); 285 320 } 321 322 286 323 }
Note: See TracChangeset
for help on using the changeset viewer.