Changeset 6901


Ignore:
Timestamp:
01/12/16 14:41:23 (8 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
Location:
metadata/trunk/toolkit
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • metadata/trunk/toolkit/pom.xml

    r6256 r6901  
    3333            <id>cmdi.clarin.repository</id>
    3434            <name>Clarin Repository</name>
    35             <url>http://catalog.clarin.eu/ds/nexus/content/groups/public/</url>
     35            <url>https://nexus.clarin.eu/content/repositories/Clarin</url>
    3636        </repository>                                                   
    3737    </repositories>
  • metadata/trunk/toolkit/src/main/resources/toolkit/xsd/cmd-component.xsd

    r6859 r6901  
    11<?xml version="1.0" encoding="UTF-8"?>
    2 <!-- 
    3     $Revision$ 
    4     $Date$ 
     2<!--
     3    $Revision$
     4    $Date$
    55-->
    66
    77<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:sch="http://purl.oclc.org/dsdl/schematron"
    88    xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" vc:minVersion="1.0" vc:maxVersion="1.1">
    9    
     9
    1010    <xs:import namespace="http://www.w3.org/XML/1998/namespace"
    1111        schemaLocation="http://www.w3.org/2005/08/xml.xsd"/>
     
    9292            <!-- from small (attribute) to big (component) -->
    9393            <xs:element name="AttributeList" type="AttributeList_type" minOccurs="0" maxOccurs="1"/>
    94             <xs:element name="Element" type="Element_type" minOccurs="0" maxOccurs="unbounded"/> 
     94            <xs:element name="Element" type="Element_type" minOccurs="0" maxOccurs="unbounded"/>
    9595            <xs:element name="Component" type="Component_type" minOccurs="0" maxOccurs="unbounded"/>
    9696        </xs:sequence>
     
    117117        </xs:simpleContent>
    118118    </xs:complexType>
    119    
     119
    120120    <xs:complexType name="Element_type">
    121121        <xs:annotation>
     
    205205                <xs:annotation>
    206206                    <xs:appinfo>
    207                         <sch:pattern id="a_res">
    208                             <sch:title>Check reserved attribute names</sch:title>
    209                             <sch:rule context="Attribute">
    210                                 <sch:assert test="not(@name=('ref','ComponentId'))">Attribute name shouldn't be 'ref' or 'ComponentId', as these are used internally by CMD!</sch:assert>
    211                             </sch:rule>
    212                         </sch:pattern>
    213207                        <sch:pattern id="a_sibs">
    214208                            <sch:title>Check attribute siblings</sch:title>
     
    273267        <xs:anyAttribute namespace="http://www.clarin.eu/cmdi/cues/1" processContents="lax"/>
    274268    </xs:attributeGroup>
    275    
     269
    276270    <xs:attributeGroup name="element_attributes">
    277271        <xs:attribute name="name" type="xs:Name" use="required">
     
    361355                        8    unbounded number    NOK
    362356                        9    unbounded unbounded OK
    363                        
     357
    364358                        UNK can be either a missing attribute or an empty value, both can be detected with normalize-space(@...)=''
    365                        
     359
    366360                        default CardinalityMin is 1 (based on the XSD minOccurs default value)
    367361                        default CardinalityMax is 1 (based on the XSD maxOccurs default value)
    368                        
     362
    369363                        If a basic XSLT 2.0 engine, like Saxon HE, is used for Schematron validation we can't cast to xs:nonNegativeInteger.
    370364                        So we cast to xs:integer. The XSD validator should have already validated that the values are valid cardinality_types.
     
    455449                    </sch:rule>
    456450                </sch:pattern>
    457             </xs:appinfo>           
     451            </xs:appinfo>
    458452        </xs:annotation>
    459453        <xs:simpleContent>
  • 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.