Changeset 6262
- Timestamp:
- 06/02/15 10:33:02 (9 years ago)
- Location:
- metadata/trunk/toolkit
- Files:
-
- 5 added
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
metadata/trunk/toolkit
-
Property
svn:ignore
set to
target
-
Property
svn:ignore
set to
-
metadata/trunk/toolkit/src/main/resources/toolkit/upgrade/cmd-record-1_1-to-1_2.xsl
r6255 r6262 146 146 147 147 <!-- 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">--> 148 150 <xsl:template match="cmd0:Components//@ref"> 149 151 <xsl:attribute name="cmd:ref" select="."/> -
metadata/trunk/toolkit/src/test/java/eu/clarin/cmd/toolkit/TestCMDToolkit.java
r6255 r6262 22 22 import net.sf.saxon.s9api.DOMDestination; 23 23 import net.sf.saxon.s9api.QName; 24 import net.sf.saxon.s9api.XPathCompiler; 25 import net.sf.saxon.s9api.XPathExecutable; 26 import net.sf.saxon.s9api.XPathSelector; 24 27 import net.sf.saxon.s9api.XdmAtomicValue; 25 28 import net.sf.saxon.s9api.XdmDestination; … … 45 48 XsltTransformer transformCMDSpecInXSD = null; 46 49 SchemAnon validateCMDSpec = null; 50 SchemAnon validateCMDEnvelop = null; 47 51 48 52 @Before … … 53 57 transformCMDSpecInXSD = SaxonUtils.buildTransformer(CMDToolkit.class.getResource("/toolkit/xslt/comp2schema.xsl")).load(); 54 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()); 55 60 } catch(Exception e) { 56 61 System.err.println("!ERR: couldn't setup the testing environment!"); … … 83 88 } 84 89 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 85 99 protected void printMessages(SchemAnon anon) throws Exception { 86 100 for (Message msg : anon.getMessages()) { … … 118 132 protected boolean validateCMDSpec(String spec,Source src) throws Exception { 119 133 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()))); 121 142 } 122 143 123 144 protected boolean validateCMDRecord(String spec,SchemAnon anon,String rec,Source src) throws Exception { 124 145 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 { 132 166 String profile = "/toolkit/Adelheid/profiles/clarin.eu:cr1:p_1311927752306.xml"; 133 167 String record = "/toolkit/Adelheid/records/Adelheid.cmdi"; … … 138 172 // validate the 1.2 profile 139 173 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 144 177 assertTrue(validProfile); 178 // so there should be no errors 145 179 assertEquals(0, countErrors(validateCMDSpec)); 146 180 … … 154 188 // validate the 1.2 record 155 189 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 160 193 assertTrue(validRecord); 194 // so there should be no errors 161 195 assertEquals(0, countErrors(profileAnon)); 162 196 } 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 } 163 250 } -
metadata/trunk/toolkit/src/test/resources/toolkit/successor/profiles/successor-valid.xml
r6255 r6262 8 8 <Description>Description of a tool and/or service(s) 9 9 (adapted from the AnnotationTool profile)</Description> 10 <Status> production</Status>10 <Status>deprecated</Status> 11 11 <Successor>hdl:123</Successor> 12 12 </Header>
Note: See TracChangeset
for help on using the changeset viewer.