Ignore:
Timestamp:
01/12/16 14:41:23 (9 years ago)
Author:
Mitchell Seaton
Message:

M pom.xml

  • updated repository url

M src/main/resources/toolkit/xsd/cmd-component.xsd

  • Removed Schematron rule for Attribute name values not longer required due to 1.2 namespaces changes

M src/test/java/eu/clarin/cmd/toolkit/TestCMDToolkit.java

  • Added unit test for CMDI profile schema containing 'ref' named Attributes
File:
1 edited

Legend:

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

    r6855 r6901  
    4747    XsltTransformer upgradeCMDRec = null;
    4848    XsltTransformer transformCMDSpecInXSD = null;
    49     SchemAnon validateCMDSpec = null; 
    50     SchemAnon validateCMDEnvelop = null; 
     49    SchemAnon validateCMDSpec = null;
     50    SchemAnon validateCMDEnvelop = null;
    5151
    5252    @Before
     
    5656            upgradeCMDRec = SaxonUtils.buildTransformer(CMDToolkit.class.getResource("/toolkit/upgrade/cmd-record-1_1-to-1_2.xsl")).load();
    5757            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());
    6060        } catch(Exception e) {
    6161            System.err.println("!ERR: couldn't setup the testing environment!");
     
    6868    public void tearDown() {
    6969    }
    70    
     70
    7171    protected Document transform(XsltTransformer trans,Source src) throws Exception {
    7272        try {
     
    8787        }
    8888    }
    89    
     89
    9090    protected boolean xpath(Document doc,String xpath) throws Exception {
    9191        XPathCompiler xpc   = SaxonUtils.getProcessor().newXPathCompiler();
     
    9696        return xps.effectiveBooleanValue();
    9797    }
    98    
     98
    9999    protected void printMessages(SchemAnon anon) throws Exception {
    100100        for (Message msg : anon.getMessages()) {
     
    103103        }
    104104    }
    105    
     105
    106106    protected int countErrors(SchemAnon anon) throws Exception {
    107107        int cnt = 0;
     
    110110        return cnt;
    111111    }
    112    
     112
    113113    protected Document upgradeCMDSpec(String spec) throws Exception {
    114114        System.out.println("Upgrade CMD spec["+spec+"]");
     
    120120        return transform(upgradeCMDRec,new javax.xml.transform.stream.StreamSource(new java.io.File(TestCMDToolkit.class.getResource(rec).toURI())));
    121121    }
    122    
    123     protected Document transformCMDSpecInXSD(String spec,Source src) throws Exception { 
     122
     123    protected Document transformCMDSpecInXSD(String spec,Source src) throws Exception {
    124124        System.out.println("Transform CMD spec["+spec+"] into XSD");
    125125        return transform(transformCMDSpecInXSD,src);
    126126    }
    127    
     127
    128128    protected Document transformCMDSpecInXSD(String spec) throws Exception {
    129129        return transformCMDSpecInXSD(spec,new javax.xml.transform.stream.StreamSource(new java.io.File(TestCMDToolkit.class.getResource(spec).toURI())));
    130130    }
    131    
     131
    132132    protected boolean validateCMDSpec(String spec,Source src) throws Exception {
    133133        System.out.println("Validate CMD spec["+spec+"]");
     
    137137        return res;
    138138    }
    139    
     139
    140140    protected boolean validateCMDSpec(String spec) throws Exception {
    141141        return validateCMDSpec(spec,new StreamSource(new java.io.File(TestCMDToolkit.class.getResource(spec).toURI())));
    142142    }
    143    
     143
    144144    protected boolean validateCMDRecord(String spec,SchemAnon anon,String rec,Source src) throws Exception {
    145145        System.out.println("Validate CMD record["+rec+"] against spec["+spec+"]");
     
    149149        return res;
    150150    }
    151    
     151
    152152    protected boolean validateCMDEnvelop(String rec,Source src) throws Exception {
    153153        System.out.println("Validate envelop CMD rec["+rec+"]");
     
    157157        return res;
    158158    }
    159    
     159
    160160    protected boolean validateCMDEnvelop(String rec) throws Exception {
    161161        return validateCMDEnvelop(rec,new StreamSource(new java.io.File(TestCMDToolkit.class.getResource(rec).toURI())));
    162162    }
    163    
     163
    164164    @Test
    165165    public void testAdelheid() throws Exception {
    166166        String profile = "/toolkit/Adelheid/profiles/clarin.eu:cr1:p_1311927752306.xml";
    167167        String record  = "/toolkit/Adelheid/records/Adelheid.cmdi";
    168        
     168
    169169        // upgrade the profile from 1.1 to 1.2
    170170        Document upgradedProfile = upgradeCMDSpec(profile);
    171        
     171
    172172        // validate the 1.2 profile
    173173        boolean validProfile = validateCMDSpec(profile+" (upgraded)",new DOMSource(upgradedProfile));
    174        
     174
    175175        // assertions
    176176        // the upgraded profile should be a valid CMDI 1.2 profile
     
    178178        // so there should be no errors
    179179        assertEquals(0, countErrors(validateCMDSpec));
    180        
     180
    181181        // transform the 1.2 profile into a XSD
    182182        Document profileSchema = transformCMDSpecInXSD(profile+" (upgraded)",new DOMSource(upgradedProfile));
    183183        SchemAnon profileAnon = new SchemAnon(new DOMSource(profileSchema));
    184        
     184
    185185        // upgrade the record from 1.1 to 1.2
    186186        Document upgradedRecord = upgradeCMDRecord(record);
    187        
     187
    188188        // validate the 1.2 record
    189189        boolean validRecord = validateCMDRecord(profile+" (upgraded)",profileAnon,record+" (upgraded)",new DOMSource(upgradedRecord));
    190        
     190
    191191        // assertions
    192192        // the upgraded record should be a valid CMDI 1.2 record
     
    200200        String profile = "/toolkit/Adelheid/profiles/clarin.eu:cr1:p_1311927752306_1_2.xml";
    201201        String record  = "/toolkit/Adelheid/records/Adelheid_1_2-invalid.cmdi";
    202        
     202
    203203        // validate the 1.2 profile
    204204        boolean validProfile = validateCMDSpec(profile,new javax.xml.transform.stream.StreamSource(new java.io.File(TestCMDToolkit.class.getResource(profile).toURI())));
    205        
     205
    206206        // assertions
    207207        // the upgraded profile should be a valid CMDI 1.2 profile
     
    209209        // so there should be no errors
    210210        assertEquals(0, countErrors(validateCMDSpec));
    211        
     211
    212212        Document profileSchema = transformCMDSpecInXSD(profile,new javax.xml.transform.stream.StreamSource(new java.io.File(TestCMDToolkit.class.getResource(profile).toURI())));
    213213        SchemAnon profileAnon = new SchemAnon(new DOMSource(profileSchema));
    214        
     214
    215215        // validate the 1.2 record
    216216        boolean validRecord = validateCMDRecord(profile,profileAnon,record,new javax.xml.transform.stream.StreamSource(new java.io.File(TestCMDToolkit.class.getResource(record).toURI())));
    217        
     217
    218218        // assertions
    219219        // the record should be a invalid as it misses a the required CoreVersion attribute
     
    222222
    223223    @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
    224259    public void testTEI() throws Exception {
    225260        String record  = "/toolkit/TEI/records/sundhed_dsn.teiHeader.ref.xml";
     
    227262        // upgrade the record from 1.1 to 1.2
    228263        Document upgradedRecord = upgradeCMDRecord(record);
    229        
     264
    230265        // assertions
    231266        // the @ref attributes on the elements should stay as they are
     
    247282        String profile = "/toolkit/OLAC/profiles/OLAC-DcmiTerms.xml";
    248283        String record  = "/toolkit/OLAC/records/org_rosettaproject-record.xml";
    249        
     284
    250285        // upgrade the profile from 1.1 to 1.2
    251286        Document upgradedProfile = upgradeCMDSpec(profile);
    252        
     287
    253288        // validate the 1.2 profile
    254289        boolean validProfile = validateCMDSpec(profile+" (upgraded)",new DOMSource(upgradedProfile));
    255        
     290
    256291        // assertions
    257292        // the upgraded profile should be a valid CMDI 1.2 profile
     
    259294        // so there should be no errors
    260295        assertEquals(0, countErrors(validateCMDSpec));
    261        
     296
    262297        // transform the 1.2 profile into a XSD
    263298        Document profileSchema = transformCMDSpecInXSD(profile+" (upgraded)",new DOMSource(upgradedProfile));
    264299        SchemAnon profileAnon = new SchemAnon(new DOMSource(profileSchema));
    265        
     300
    266301        // upgrade the record from 1.1 to 1.2
    267302        Document upgradedRecord = upgradeCMDRecord(record);
    268        
     303
    269304        // validate the 1.2 record
    270305        boolean validRecord = validateCMDRecord(profile+" (upgraded)",profileAnon,record+" (upgraded)",new DOMSource(upgradedRecord));
     
    284319        assertFalse(validProfile);
    285320    }
     321
     322
    286323}
Note: See TracChangeset for help on using the changeset viewer.