source: metadata/trunk/toolkit/src/test/java/eu/clarin/cmd/toolkit/TestCMDToolkit.java @ 6930

Last change on this file since 6930 was 6930, checked in by Menzo Windhouwer, 8 years ago

M toolkit/src/test/java/eu/clarin/cmd/toolkit/TestCMDToolkit.java
M toolkit/src/main/resources/toolkit/upgrade/cmd-record-1_1-to-1_2.xsl

  • default parameter values now match the CR, so the test environment needs to overwrite these

A toolkit/src/test/resources/toolkit/vocabs
A + toolkit/src/main/resources/toolkit/xslt/clavas2enum.xsl

  • turn a CLAVAS vocabulary into an CMD profile spec value scheme enum
File size: 24.0 KB
Line 
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5package eu.clarin.cmd.toolkit;
6
7import java.io.File;
8import java.io.IOException;
9import java.net.URL;
10import java.nio.file.Paths;
11import java.util.HashMap;
12import java.util.List;
13import java.util.Map;
14import javax.xml.XMLConstants;
15import javax.xml.parsers.DocumentBuilder;
16import javax.xml.parsers.DocumentBuilderFactory;
17import javax.xml.transform.Source;
18import javax.xml.transform.dom.DOMSource;
19import javax.xml.transform.stream.StreamSource;
20import javax.xml.validation.Schema;
21import javax.xml.validation.SchemaFactory;
22import javax.xml.validation.Validator;
23import net.sf.saxon.s9api.DOMDestination;
24import net.sf.saxon.s9api.QName;
25import net.sf.saxon.s9api.XPathCompiler;
26import net.sf.saxon.s9api.XPathExecutable;
27import net.sf.saxon.s9api.XPathSelector;
28import net.sf.saxon.s9api.XdmAtomicValue;
29import net.sf.saxon.s9api.XdmDestination;
30import net.sf.saxon.s9api.XdmNode;
31import net.sf.saxon.s9api.XdmValue;
32import net.sf.saxon.s9api.XsltTransformer;
33import nl.mpi.tla.schemanon.Message;
34import nl.mpi.tla.schemanon.SaxonUtils;
35import nl.mpi.tla.schemanon.SchemAnon;
36import org.junit.*;
37
38import static org.junit.Assert.*;
39import org.w3c.dom.Document;
40
41/**
42 *
43 * @author menwin
44 */
45public class TestCMDToolkit {
46
47    XsltTransformer upgradeCMDSpec = null;
48    XsltTransformer downgradeCMDSpec = null;
49    XsltTransformer upgradeCMDRec = null;
50    XsltTransformer transformCMDSpecInXSD = null;
51    XsltTransformer transformCMDoldSpecInXSD = null;
52    SchemAnon validateCMDSpec = null;
53    SchemAnon validateCMDoldSpec = null;
54    SchemAnon validateCMDEnvelop = null;
55
56    @Before
57    public void setUp() {
58        try {
59            upgradeCMDSpec = SaxonUtils.buildTransformer(CMDToolkit.class.getResource("/toolkit/upgrade/cmd-component-1_1-to-1_2.xsl")).load();
60            downgradeCMDSpec = SaxonUtils.buildTransformer(CMDToolkit.class.getResource("/toolkit/downgrade/cmd-component-1_2-to-1_1.xsl")).load();
61            upgradeCMDRec = SaxonUtils.buildTransformer(CMDToolkit.class.getResource("/toolkit/upgrade/cmd-record-1_1-to-1_2.xsl")).load();
62            transformCMDSpecInXSD = SaxonUtils.buildTransformer(CMDToolkit.class.getResource("/toolkit/xslt/comp2schema.xsl")).load();
63            validateCMDSpec = new SchemAnon(CMDToolkit.class.getResource("/toolkit/xsd/cmd-component.xsd").toURI().toURL());
64            validateCMDEnvelop = new SchemAnon(CMDToolkit.class.getResource("/toolkit/xsd/cmd-envelop.xsd").toURI().toURL());
65            //validateCMDoldSpec = new SchemAnon(new URL("http://infra.clarin.eu/cmd/general-component-schema.xsd"));
66            validateCMDoldSpec = new SchemAnon(TestCMDToolkit.class.getResource("/temp/general-component-schema.xsd").toURI().toURL());
67            transformCMDoldSpecInXSD = SaxonUtils.buildTransformer(new URL("http://infra.clarin.eu/cmd/xslt/comp2schema-v2/comp2schema.xsl")).load();
68        } catch(Exception e) {
69            System.err.println("!ERR: couldn't setup the testing environment!");
70            System.err.println(""+e);
71            e.printStackTrace(System.err);
72        }
73    }
74
75    @After
76    public void tearDown() {
77    }
78
79    protected Document transform(XsltTransformer trans,Source src,Map<String,XdmValue> params) throws Exception {
80        try {
81            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
82            DocumentBuilder builder = factory.newDocumentBuilder();
83            Document doc = builder.newDocument();
84            DOMDestination dest = new DOMDestination(doc);
85            trans.setSource(src);
86            trans.setDestination(dest);
87            // always set cmd-toolkit to the current working directory, which is expected to be where pom.xml lives
88            trans.setParameter(new QName("cmd-toolkit"),new XdmAtomicValue(Paths.get("").toAbsolutePath().toString()+"/src/main/resources/toolkit"));
89            if (params!=null)
90                for(String param:params.keySet())
91                    trans.setParameter(new QName(param),params.get(param));
92            trans.transform();
93            return doc;
94        } catch (Exception e) {
95            System.out.println("!ERR: failed transform: "+e);
96            e.printStackTrace(System.out);
97            throw e;
98        }
99    }
100
101    protected Document transform(XsltTransformer trans,Source src) throws Exception {
102        return transform(trans,src,null);
103    }
104
105    protected boolean xpath(Document doc,String xpath) throws Exception {
106        XPathCompiler xpc   = SaxonUtils.getProcessor().newXPathCompiler();
107        xpc.declareNamespace("cmd","http://www.clarin.eu/cmd/1");
108        XPathExecutable xpe = xpc.compile(xpath);
109        XPathSelector xps   = xpe.load();
110        xps.setContextItem(SaxonUtils.getProcessor().newDocumentBuilder().wrap(doc));
111        return xps.effectiveBooleanValue();
112    }
113
114    protected void printMessages(SchemAnon anon) throws Exception {
115        for (Message msg : anon.getMessages()) {
116            System.out.println("" + (msg.isError() ? "ERROR" : "WARNING") + (msg.getLocation() != null ? " at " + msg.getLocation() : ""));
117            System.out.println("  " + msg.getText());
118        }
119    }
120
121    protected int countErrors(SchemAnon anon) throws Exception {
122        int cnt = 0;
123        for (Message msg : anon.getMessages())
124            cnt += (msg.isError()?1:0);
125        return cnt;
126    }
127
128    protected Document upgradeCMDSpec(String spec) throws Exception {
129        System.out.println("Upgrade CMD spec["+spec+"]");
130        return transform(upgradeCMDSpec,new javax.xml.transform.stream.StreamSource(new java.io.File(TestCMDToolkit.class.getResource(spec).toURI())));
131    }
132
133    protected Document upgradeCMDSpec(String spec,Source src) throws Exception {
134        System.out.println("Upgrade CMD spec["+spec+"]");
135        return transform(upgradeCMDSpec,src);
136    }
137
138    protected Document downgradeCMDSpec(String spec) throws Exception {
139        System.out.println("Downgrade CMD spec["+spec+"]");
140        return transform(downgradeCMDSpec,new javax.xml.transform.stream.StreamSource(new java.io.File(TestCMDToolkit.class.getResource(spec).toURI())));
141    }
142
143    protected Document downgradeCMDSpec(String spec,Source src) throws Exception {
144        System.out.println("Downgrade CMD spec["+spec+"]");
145        return transform(downgradeCMDSpec,src);
146    }
147
148    protected Document upgradeCMDRecord(String rec,XdmNode prof) throws Exception {
149        System.out.println("Upgrade CMD spec["+rec+"]");
150        Map<String,XdmValue> params = new HashMap<String,XdmValue>();
151        params.put("cmd-profile", prof);
152        params.put("cr-uri", new XdmAtomicValue(".."));
153        params.put("cr-extension-xsd", new XdmAtomicValue("-1_2.xsd"));
154        params.put("cr-roundtrip-extension-xsd", new XdmAtomicValue("-1-1-1_2.xsd"));
155        params.put("cr-extension-xml", new XdmAtomicValue("-1.2.xml"));
156        return transform(upgradeCMDRec,new javax.xml.transform.stream.StreamSource(new java.io.File(TestCMDToolkit.class.getResource(rec).toURI())),params);
157    }
158
159    protected Document upgradeCMDRecord(String rec,Document prof) throws Exception {
160        return upgradeCMDRecord(rec,SaxonUtils.getProcessor().newDocumentBuilder().wrap(prof));
161    }
162
163    protected Document transformCMDSpecInXSD(String spec,Source src) throws Exception {
164        System.out.println("Transform CMD spec["+spec+"] into XSD");
165        return transform(transformCMDSpecInXSD,src);
166    }
167
168    protected Document transformCMDSpecInXSD(String spec) throws Exception {
169        return transformCMDSpecInXSD(spec,new javax.xml.transform.stream.StreamSource(new java.io.File(TestCMDToolkit.class.getResource(spec).toURI())));
170    }
171
172    protected boolean validateCMDSpec(String spec,Source src) throws Exception {
173        System.out.println("Validate CMD spec["+spec+"]");
174        boolean res = validateCMDSpec.validate(src);
175        System.out.println("CMD spec["+spec+"]: "+(res?"VALID":"INVALID"));
176        printMessages(validateCMDSpec);
177        return res;
178    }
179
180    protected boolean validateCMDSpec(String spec) throws Exception {
181        return validateCMDSpec(spec,new StreamSource(new java.io.File(TestCMDToolkit.class.getResource(spec).toURI())));
182    }
183
184    protected boolean validateCMDRecord(String spec,SchemAnon anon,String rec,Source src) throws Exception {
185        System.out.println("Validate CMD record["+rec+"] against spec["+spec+"]");
186        boolean res = anon.validate(src);
187        System.out.println("CMD record["+rec+"]: "+(res?"VALID":"INVALID"));
188        printMessages(anon);
189        return res;
190    }
191
192    protected boolean validateCMDEnvelop(String rec,Source src) throws Exception {
193        System.out.println("Validate envelop CMD rec["+rec+"]");
194        boolean res = validateCMDEnvelop.validate(src);
195        System.out.println("CMD rec["+rec+"] evelop: "+(res?"VALID":"INVALID"));
196        printMessages(validateCMDEnvelop);
197        return res;
198    }
199
200    protected boolean validateCMDEnvelop(String rec) throws Exception {
201        return validateCMDEnvelop(rec,new StreamSource(new java.io.File(TestCMDToolkit.class.getResource(rec).toURI())));
202    }
203   
204    protected boolean validateCMDoldSpec(String spec,Source src) throws Exception {
205        System.out.println("Validate CMD 1.1 spec["+spec+"]");
206        boolean res = validateCMDoldSpec.validate(src);
207        System.out.println("CMD old spec["+spec+"]: "+(res?"VALID":"INVALID"));
208        printMessages(validateCMDoldSpec);
209        return res;
210    }
211
212    protected Document transformCMDoldSpecInXSD(String spec,Source src) throws Exception {
213        System.out.println("Transform CMD 1.1 spec["+spec+"] into XSD");
214        return transform(transformCMDoldSpecInXSD,src);
215    }
216
217    protected Document transformCMDoldSpecInXSD(String spec) throws Exception {
218        return transformCMDoldSpecInXSD(spec,new javax.xml.transform.stream.StreamSource(new java.io.File(TestCMDToolkit.class.getResource(spec).toURI())));
219    }
220
221    protected boolean validateOldCMDRecord(String spec,SchemAnon anon,String rec,Source src) throws Exception {
222        System.out.println("Validate CMD 1.1 record["+rec+"] against spec["+spec+"]");
223        boolean res = anon.validate(src);
224        System.out.println("CMD 1.1 record["+rec+"]: "+(res?"VALID":"INVALID"));
225        printMessages(anon);
226        return res;
227    }
228
229    @Test
230    public void testAdelheid() throws Exception {
231        System.out.println("* BEGIN: Adelheid tests (valid)");
232       
233        String profile = "/toolkit/Adelheid/profiles/clarin.eu:cr1:p_1311927752306.xml";
234        String record  = "/toolkit/Adelheid/records/Adelheid.cmdi";
235
236        // upgrade the profile from 1.1 to 1.2
237        System.out.println("- upgrade profile from 1.1 to 1.2");
238        Document upgradedProfile = upgradeCMDSpec(profile);
239
240        // validate the 1.2 profile
241        boolean validProfile = validateCMDSpec(profile+" (upgraded)",new DOMSource(upgradedProfile));
242
243        // assertions
244        // the upgraded profile should be a valid CMDI 1.2 profile
245        assertTrue(validProfile);
246        // so there should be no errors
247        assertEquals(0, countErrors(validateCMDSpec));
248
249        // transform the 1.2 profile into a XSD
250        Document profileSchema = transformCMDSpecInXSD(profile+" (upgraded)",new DOMSource(upgradedProfile));
251        SchemAnon profileAnon = new SchemAnon(new DOMSource(profileSchema));
252
253        // upgrade the record from 1.1 to 1.2
254        System.out.println("- upgrade record from 1.1 to 1.2");
255        Document upgradedRecord = upgradeCMDRecord(record,upgradedProfile);
256
257        // validate the 1.2 record
258        boolean validRecord = validateCMDRecord(profile+" (upgraded)",profileAnon,record+" (upgraded)",new DOMSource(upgradedRecord));
259
260        // assertions
261        // the upgraded record should be a valid CMDI 1.2 record
262        assertTrue(validRecord);
263        // so there should be no errors
264        assertEquals(0, countErrors(profileAnon));
265       
266        // downgrade the 1.2 profile to 1.1
267        System.out.println("- downgrade profile from 1.2 to 1.1");
268        Document oldProfile = downgradeCMDSpec(profile+" (upgraded)",new DOMSource(upgradedProfile));
269       
270        // validate the 1.1 profile
271        boolean validOldProfile = validateCMDoldSpec(profile+" (downgraded)",new DOMSource(oldProfile));
272
273        // assertions
274        // the downgraded profile should be a valid CMDI 1.1 profile
275        assertTrue(validOldProfile);
276        // so there should be no errors
277        assertEquals(0, countErrors(validateCMDoldSpec));       
278
279        System.out.println("*  END : Adelheid tests");
280    }
281
282    @Test
283    public void testAdelheid2() throws Exception {
284        System.out.println("* BEGIN: Adelheid 2 tests (invalid)");
285
286        String profile = "/toolkit/Adelheid/profiles/clarin.eu:cr1:p_1311927752306_1_2.xml";
287        String record  = "/toolkit/Adelheid/records/Adelheid_1_2-invalid.cmdi";
288
289        // validate the 1.2 profile
290        boolean validProfile = validateCMDSpec(profile,new javax.xml.transform.stream.StreamSource(new java.io.File(TestCMDToolkit.class.getResource(profile).toURI())));
291
292        // assertions
293        // the upgraded profile should be a valid CMDI 1.2 profile
294        assertTrue(validProfile);
295        // so there should be no errors
296        assertEquals(0, countErrors(validateCMDSpec));
297
298        Document profileSchema = transformCMDSpecInXSD(profile,new javax.xml.transform.stream.StreamSource(new java.io.File(TestCMDToolkit.class.getResource(profile).toURI())));
299        SchemAnon profileAnon = new SchemAnon(new DOMSource(profileSchema));
300
301        // validate the 1.2 record
302        boolean validRecord = validateCMDRecord(profile,profileAnon,record,new javax.xml.transform.stream.StreamSource(new java.io.File(TestCMDToolkit.class.getResource(record).toURI())));
303
304        // assertions
305        // the record should be a invalid as it misses a the required CoreVersion attribute
306        assertFalse(validRecord);
307
308        // downgrade the 1.2 profile to 1.1
309        Document oldProfile = downgradeCMDSpec(profile);
310       
311        // validate the 1.1 profile
312        boolean validOldProfile = validateCMDoldSpec(profile+" (downgraded)",new DOMSource(oldProfile));
313
314        // assertions
315        // the downgraded profile should be a valid CMDI 1.1 profile
316        assertTrue(validOldProfile);
317        // so there should be no errors
318        assertEquals(0, countErrors(validateCMDoldSpec));   
319       
320        System.out.println("*  END : Adelheid 2 tests");
321    }
322
323    @Test
324    public void testSundhed() throws Exception {
325        System.out.println("* BEGIN: Sundhed tests (valid)");
326       
327        String profile = "/toolkit/TEI/profiles/clarin.eu:cr1:p_1380106710826.xml";
328        String record  = "/toolkit/TEI/records/sundhed_dsn.teiHeader.ref.xml";
329
330        // upgrade the profile from 1.1 to 1.2
331        Document upgradedProfile = upgradeCMDSpec(profile);
332
333        // validate the 1.2 profile
334        boolean validProfile = validateCMDSpec(profile+" (upgraded)",new DOMSource(upgradedProfile));
335
336        // assertions
337        // the upgraded profile should be a valid CMDI 1.2 profile and 'ref' named Attributes should validate
338        assertTrue(validProfile);
339        // so there should be no errors
340        assertEquals(0, countErrors(validateCMDSpec));
341
342        // transform the 1.2 profile into a XSD
343        Document profileSchema = transformCMDSpecInXSD(profile+" (upgraded)",new DOMSource(upgradedProfile));
344        SchemAnon profileAnon = new SchemAnon(new DOMSource(profileSchema));
345
346        // upgrade the record from 1.1 to 1.2
347        Document upgradedRecord = upgradeCMDRecord(record,upgradedProfile);
348
349        // validate the 1.2 record
350        boolean validRecord = validateCMDRecord(profile+" (upgraded)", profileAnon, record+" (upgraded)", new DOMSource(upgradedRecord));
351
352        // assertions
353        // the upgraded record should be a valid CMDI 1.2 record
354        assertTrue(validRecord);
355
356        // so there should be no errors
357        assertEquals(0, countErrors(profileAnon));
358       
359        // downgrade the 1.2 profile to 1.1
360        Document oldProfile = downgradeCMDSpec(profile+" (upgraded)",new DOMSource(upgradedProfile));
361       
362        // validate the 1.1 profile
363        boolean validOldProfile = validateCMDoldSpec(profile+" (downgraded)",new DOMSource(oldProfile));
364
365        // assertions
366        // the downgraded profile should be a valid CMDI 1.1 profile
367        assertTrue(validOldProfile);
368        // so there should be no errors
369        assertEquals(0, countErrors(validateCMDoldSpec));       
370
371        System.out.println("*  END : Sundhed tests");
372    }
373
374    @Test
375    public void testTEI() throws Exception {
376        System.out.println("* BEGIN: TEI tests (valid)");
377
378        String profile = "/toolkit/TEI/profiles/clarin.eu:cr1:p_1380106710826.xml";
379        String record  = "/toolkit/TEI/records/sundhed_dsn.teiHeader.ref.xml";
380
381        // upgrade the profile from 1.1 to 1.2
382        Document upgradedProfile = upgradeCMDSpec(profile);
383
384        // upgrade the record from 1.1 to 1.2
385        Document upgradedRecord = upgradeCMDRecord(record,upgradedProfile);
386
387        // assertions
388        // the @ref attributes on the elements should stay as they are
389        assertTrue(xpath(upgradedRecord,"//*:author/*:name/@ref"));
390
391        System.out.println("*  END : TEI tests");
392    }
393
394    @Test
395    public void testSuccessor() throws Exception {
396        System.out.println("* BEGIN: successor tests (valid+invalid)");
397       
398        String validRecord  = "/toolkit/successor/profiles/successor-valid.xml";
399        String invalidRecord  = "/toolkit/successor/profiles/successor-invalid.xml";
400
401        // assertions
402        assertTrue(validateCMDSpec(validRecord));
403        assertFalse(validateCMDSpec(invalidRecord));
404       
405        System.out.println("*  END : successor tests");
406    }
407
408    @Test
409    public void testOLAC() throws Exception {
410        System.out.println("* BEGIN: OLAC tests (invalid)");
411       
412        String profile = "/toolkit/OLAC/profiles/OLAC-DcmiTerms.xml";
413        String record  = "/toolkit/OLAC/records/org_rosettaproject-record.xml";
414
415        // upgrade the profile from 1.1 to 1.2
416        Document upgradedProfile = upgradeCMDSpec(profile);
417
418        // validate the 1.2 profile
419        boolean validProfile = validateCMDSpec(profile+" (upgraded)",new DOMSource(upgradedProfile));
420
421        // assertions
422        // the upgraded profile should be a valid CMDI 1.2 profile
423        assertTrue(validProfile);
424        // so there should be no errors
425        assertEquals(0, countErrors(validateCMDSpec));
426       
427        // transform the 1.2 profile into a XSD
428        Document profileSchema = transformCMDSpecInXSD(profile+" (upgraded)",new DOMSource(upgradedProfile));
429        SchemAnon profileAnon = new SchemAnon(new DOMSource(profileSchema));
430
431        // upgrade the record from 1.1 to 1.2
432        Document upgradedRecord = upgradeCMDRecord(record,upgradedProfile);
433
434        // validate the 1.2 record
435        boolean validRecord = validateCMDRecord(profile+" (upgraded)",profileAnon,record+" (upgraded)",new DOMSource(upgradedRecord));
436
437        // assertions
438        assertFalse(validRecord);
439
440        // downgrade the 1.2 profile to 1.1
441        Document oldProfile = downgradeCMDSpec(profile+" (upgraded)",new DOMSource(upgradedProfile));
442       
443        // validate the 1.1 profile
444        boolean validOldProfile = validateCMDoldSpec(profile+" (downgraded)",new DOMSource(oldProfile));
445
446        // assertions
447        // the downgraded profile should be a valid CMDI 1.1 profile
448        assertTrue(validOldProfile);
449        // so there should be no errors
450        assertEquals(0, countErrors(validateCMDoldSpec));
451       
452        System.out.println("*  END : OLAC tests");
453    }
454
455    @Test
456    public void testCMD() throws Exception {
457        System.out.println("* BEGIN: CMD tests (invalid)");
458       
459        String profile = "/toolkit/CMD/profiles/components-invalid.xml";
460
461        // validate the 1.2 profile
462        boolean validProfile = validateCMDSpec(profile,new javax.xml.transform.stream.StreamSource(new java.io.File(TestCMDToolkit.class.getResource(profile).toURI())));
463
464        // assertions
465        assertFalse(validProfile);
466
467        System.out.println("*  END : CMD tests");
468    }
469   
470    @Test
471    public void testDownUpgrade() throws Exception {
472        System.out.println("* BEGIN: downgrade/upgrade tests");
473       
474        String profile = "/toolkit/downgrade/profiles/test.xml";
475        String record  = "/toolkit/downgrade/records/test.xml";
476       
477        // validate the 1.2 profile
478        boolean validProfile = validateCMDSpec(profile);
479       
480        // assertions
481        // the profile should be a valid CMDI 1.2 profile
482        assertTrue(validProfile);
483        // so there should be no errors
484        assertEquals(0, countErrors(validateCMDSpec));
485       
486        // downgrade the 1.2 profile to 1.1
487        Document oldProfile = downgradeCMDSpec(profile);
488       
489        // validate the 1.1 profile
490        boolean validOldProfile = validateCMDoldSpec(profile+" (downgraded)",new DOMSource(oldProfile));
491       
492        // assertions
493        // the downgraded profile should be a valid CMDI 1.1 profile
494        assertTrue(validOldProfile);
495        // so there should be no errors
496        assertEquals(0, countErrors(validateCMDoldSpec));
497       
498        // transform the 1.1 profile into a XSD
499        Document profileSchema = transformCMDoldSpecInXSD(profile+" (downgraded)",new DOMSource(oldProfile));
500        SchemAnon profileAnon = new SchemAnon(new DOMSource(profileSchema));
501       
502        // validate the 1.1 record
503        boolean validRecord = validateOldCMDRecord(profile+" (downgraded)",profileAnon,record,new javax.xml.transform.stream.StreamSource(new java.io.File(TestCMDToolkit.class.getResource(record).toURI())));
504
505        // assertions
506        // the record should be valid against the downgraded profile
507        assertTrue(validRecord);
508       
509        // upgrade the 1.1 record to 1.2
510        Document upgradedRecord = upgradeCMDRecord(record,SaxonUtils.buildDocument(new javax.xml.transform.stream.StreamSource(new java.io.File(TestCMDToolkit.class.getResource(profile).toURI()))));
511       
512        // transform the 1.2 profile into a XSD
513        profileSchema = transformCMDSpecInXSD(profile);
514        profileAnon = new SchemAnon(new DOMSource(profileSchema));
515
516        // validate the 1.2 record
517        validRecord = validateCMDRecord(profile,profileAnon,record+" (upgraded)",new DOMSource(upgradedRecord));
518
519        // assertions
520        // the upgraded 1.1 record should be invalid against the original 1.2 profile
521        assertFalse(validRecord);
522         // the upgraded 1.1 record should refer to 1.2/1.1/1.2 profile XSD
523        assertTrue(xpath(upgradedRecord,"ends-with(/*:CMD/@*:schemaLocation,'-1-1-1_2.xsd')"));
524       
525        // upgrade the 1.1 profile to 1.2
526        Document oldNewProfile = upgradeCMDSpec(profile+" (downgraded)",new DOMSource(oldProfile));
527       
528        // validate the 1.2 profile
529        validProfile = validateCMDSpec(profile+" (downgraded/upgraded)",new DOMSource(oldNewProfile));
530
531        // assertions
532        assertTrue(validProfile);
533       
534        // transform the 1.2 profile into a XSD
535        profileSchema = transformCMDSpecInXSD(profile+" (downgraded/upgraded)",new DOMSource(oldNewProfile));
536        profileAnon = new SchemAnon(new DOMSource(profileSchema));
537
538        // validate the 1.2 record
539        validRecord = validateCMDRecord(profile,profileAnon,record+" (upgraded)",new DOMSource(upgradedRecord));
540
541        // assertions
542        // the upgraded 1.1 record should be valid against the downgraded/upgraded 1.2/1.1/1.2 profile
543        assertTrue(validRecord);
544
545        System.out.println("*  END : downgrade/upgrade tests");
546    }
547
548
549}
Note: See TracBrowser for help on using the repository browser.