Changeset 6901 for metadata/trunk/toolkit/src/test
- Timestamp:
- 01/12/16 14:41:23 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.