- Timestamp:
- 01/13/16 12:37:51 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.