Changeset 6928 for metadata


Ignore:
Timestamp:
01/27/16 13:35:30 (8 years ago)
Author:
Menzo Windhouwer
Message:

M toolkit/src/test/java/eu/clarin/cmd/toolkit/TestCMDToolkit.java
A toolkit/src/test/resources/toolkit/downgrade

  • added test for the downgrade of a 1.2 profile to 1.1
  • validation of a 1.1 record agains a downgraded 1.2 profile
  • validation of a upgraded 1.1 record agains a 1.2 profile
  • validation of a upgraded 1.1 record agains a downgraded and upgraded (1.2 -> 1.1 -> 1.2) profile
Location:
metadata/trunk/toolkit/src/test
Files:
5 added
1 edited

Legend:

Unmodified
Added
Removed
  • metadata/trunk/toolkit/src/test/java/eu/clarin/cmd/toolkit/TestCMDToolkit.java

    r6926 r6928  
    4949    XsltTransformer upgradeCMDRec = null;
    5050    XsltTransformer transformCMDSpecInXSD = null;
     51    XsltTransformer transformCMDoldSpecInXSD = null;
    5152    SchemAnon validateCMDSpec = null;
    5253    SchemAnon validateCMDoldSpec = null;
     
    6162            transformCMDSpecInXSD = SaxonUtils.buildTransformer(CMDToolkit.class.getResource("/toolkit/xslt/comp2schema.xsl")).load();
    6263            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());
    6365            //validateCMDoldSpec = new SchemAnon(new URL("http://infra.clarin.eu/cmd/general-component-schema.xsd"));
    6466            validateCMDoldSpec = new SchemAnon(TestCMDToolkit.class.getResource("/temp/general-component-schema.xsd").toURI().toURL());
    65             validateCMDEnvelop = new SchemAnon(CMDToolkit.class.getResource("/toolkit/xsd/cmd-envelop.xsd").toURI().toURL());
     67            transformCMDoldSpecInXSD = SaxonUtils.buildTransformer(new URL("http://infra.clarin.eu/cmd/xslt/comp2schema-v2/comp2schema.xsl")).load();
    6668        } catch(Exception e) {
    6769            System.err.println("!ERR: couldn't setup the testing environment!");
     
    129131    }
    130132
     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
    131138    protected Document downgradeCMDSpec(String spec) throws Exception {
    132139        System.out.println("Downgrade CMD spec["+spec+"]");
     
    139146    }
    140147
    141     protected Document upgradeCMDRecord(String rec,Document prof) throws Exception {
     148    protected Document upgradeCMDRecord(String rec,XdmNode prof) throws Exception {
    142149        System.out.println("Upgrade CMD spec["+rec+"]");
    143150        Map<String,XdmValue> params = new HashMap<String,XdmValue>();
    144         params.put("cmd-profile", SaxonUtils.getProcessor().newDocumentBuilder().wrap(prof));
     151        params.put("cmd-profile", prof);
    145152        return transform(upgradeCMDRec,new javax.xml.transform.stream.StreamSource(new java.io.File(TestCMDToolkit.class.getResource(rec).toURI())),params);
     153    }
     154
     155    protected Document upgradeCMDRecord(String rec,Document prof) throws Exception {
     156        return upgradeCMDRecord(rec,SaxonUtils.getProcessor().newDocumentBuilder().wrap(prof));
    146157    }
    147158
     
    163174    }
    164175
     176    protected boolean validateCMDSpec(String spec) throws Exception {
     177        return validateCMDSpec(spec,new StreamSource(new java.io.File(TestCMDToolkit.class.getResource(spec).toURI())));
     178    }
     179
     180    protected boolean validateCMDRecord(String spec,SchemAnon anon,String rec,Source src) throws Exception {
     181        System.out.println("Validate CMD record["+rec+"] against spec["+spec+"]");
     182        boolean res = anon.validate(src);
     183        System.out.println("CMD record["+rec+"]: "+(res?"VALID":"INVALID"));
     184        printMessages(anon);
     185        return res;
     186    }
     187
     188    protected boolean validateCMDEnvelop(String rec,Source src) throws Exception {
     189        System.out.println("Validate envelop CMD rec["+rec+"]");
     190        boolean res = validateCMDEnvelop.validate(src);
     191        System.out.println("CMD rec["+rec+"] evelop: "+(res?"VALID":"INVALID"));
     192        printMessages(validateCMDEnvelop);
     193        return res;
     194    }
     195
     196    protected boolean validateCMDEnvelop(String rec) throws Exception {
     197        return validateCMDEnvelop(rec,new StreamSource(new java.io.File(TestCMDToolkit.class.getResource(rec).toURI())));
     198    }
     199   
    165200    protected boolean validateCMDoldSpec(String spec,Source src) throws Exception {
    166201        System.out.println("Validate CMD 1.1 spec["+spec+"]");
     
    171206    }
    172207
    173     protected boolean validateCMDSpec(String spec) throws Exception {
    174         return validateCMDSpec(spec,new StreamSource(new java.io.File(TestCMDToolkit.class.getResource(spec).toURI())));
    175     }
    176 
    177     protected boolean validateCMDRecord(String spec,SchemAnon anon,String rec,Source src) throws Exception {
    178         System.out.println("Validate CMD record["+rec+"] against spec["+spec+"]");
     208    protected Document transformCMDoldSpecInXSD(String spec,Source src) throws Exception {
     209        System.out.println("Transform CMD 1.1 spec["+spec+"] into XSD");
     210        return transform(transformCMDoldSpecInXSD,src);
     211    }
     212
     213    protected Document transformCMDoldSpecInXSD(String spec) throws Exception {
     214        return transformCMDoldSpecInXSD(spec,new javax.xml.transform.stream.StreamSource(new java.io.File(TestCMDToolkit.class.getResource(spec).toURI())));
     215    }
     216
     217    protected boolean validateOldCMDRecord(String spec,SchemAnon anon,String rec,Source src) throws Exception {
     218        System.out.println("Validate CMD 1.1 record["+rec+"] against spec["+spec+"]");
    179219        boolean res = anon.validate(src);
    180         System.out.println("CMD record["+rec+"]: "+(res?"VALID":"INVALID"));
     220        System.out.println("CMD 1.1 record["+rec+"]: "+(res?"VALID":"INVALID"));
    181221        printMessages(anon);
    182222        return res;
    183223    }
    184224
    185     protected boolean validateCMDEnvelop(String rec,Source src) throws Exception {
    186         System.out.println("Validate envelop CMD rec["+rec+"]");
    187         boolean res = validateCMDEnvelop.validate(src);
    188         System.out.println("CMD rec["+rec+"] evelop: "+(res?"VALID":"INVALID"));
    189         printMessages(validateCMDEnvelop);
    190         return res;
    191     }
    192 
    193     protected boolean validateCMDEnvelop(String rec) throws Exception {
    194         return validateCMDEnvelop(rec,new StreamSource(new java.io.File(TestCMDToolkit.class.getResource(rec).toURI())));
    195     }
    196    
    197225    @Test
    198226    public void testAdelheid() throws Exception {
     
    435463        System.out.println("*  END : CMD tests");
    436464    }
     465   
     466    @Test
     467    public void testDownUpgrade() throws Exception {
     468        System.out.println("* BEGIN: downgrade/upgrade tests");
     469       
     470        String profile = "/toolkit/downgrade/profiles/test.xml";
     471        String record  = "/toolkit/downgrade/records/test.xml";
     472       
     473        // validate the 1.2 profile
     474        boolean validProfile = validateCMDSpec(profile);
     475       
     476        // assertions
     477        // the profile should be a valid CMDI 1.2 profile
     478        assertTrue(validProfile);
     479        // so there should be no errors
     480        assertEquals(0, countErrors(validateCMDSpec));
     481       
     482        // downgrade the 1.2 profile to 1.1
     483        Document oldProfile = downgradeCMDSpec(profile);
     484       
     485        // validate the 1.1 profile
     486        boolean validOldProfile = validateCMDoldSpec(profile+" (downgraded)",new DOMSource(oldProfile));
     487       
     488        // assertions
     489        // the downgraded profile should be a valid CMDI 1.1 profile
     490        assertTrue(validOldProfile);
     491        // so there should be no errors
     492        assertEquals(0, countErrors(validateCMDoldSpec));
     493       
     494        // transform the 1.1 profile into a XSD
     495        Document profileSchema = transformCMDoldSpecInXSD(profile+" (downgraded)",new DOMSource(oldProfile));
     496        SchemAnon profileAnon = new SchemAnon(new DOMSource(profileSchema));
     497       
     498        // validate the 1.1 record
     499        boolean validRecord = validateOldCMDRecord(profile+" (downgraded)",profileAnon,record,new javax.xml.transform.stream.StreamSource(new java.io.File(TestCMDToolkit.class.getResource(record).toURI())));
     500
     501        // assertions
     502        // the record should be valid against the downgraded profile
     503        assertTrue(validRecord);
     504       
     505        // upgrade the 1.1 record to 1.2
     506        Document upgradedRecord = upgradeCMDRecord(record,SaxonUtils.buildDocument(new javax.xml.transform.stream.StreamSource(new java.io.File(TestCMDToolkit.class.getResource(profile).toURI()))));
     507       
     508        // transform the 1.2 profile into a XSD
     509        profileSchema = transformCMDSpecInXSD(profile);
     510        profileAnon = new SchemAnon(new DOMSource(profileSchema));
     511
     512        // validate the 1.2 record
     513        validRecord = validateCMDRecord(profile,profileAnon,record+" (upgraded)",new DOMSource(upgradedRecord));
     514
     515        // assertions
     516        // the upgraded 1.1 record should be invalid against the original 1.2 profile
     517        assertFalse(validRecord);
     518       
     519        // upgrade the 1.1 profile to 1.2
     520        Document oldNewProfile = upgradeCMDSpec(profile+" (downgraded)",new DOMSource(oldProfile));
     521       
     522        // validate the 1.2 profile
     523        validProfile = validateCMDSpec(profile+" (downgraded/upgraded)",new DOMSource(oldNewProfile));
     524
     525        // assertions
     526        assertTrue(validProfile);
     527       
     528        // transform the 1.2 profile into a XSD
     529        profileSchema = transformCMDSpecInXSD(profile+" (downgraded/upgraded)",new DOMSource(oldNewProfile));
     530        profileAnon = new SchemAnon(new DOMSource(profileSchema));
     531
     532        // validate the 1.2 record
     533        validRecord = validateCMDRecord(profile,profileAnon,record+" (upgraded)",new DOMSource(upgradedRecord));
     534
     535        // assertions
     536        // the upgraded 1.1 record should be valid against the downgraded/upgraded 1.2/1.1/1.2 profile
     537        assertTrue(validRecord);
     538
     539        System.out.println("*  END : downgrade/upgrade tests");
     540    }
    437541
    438542
Note: See TracChangeset for help on using the changeset viewer.