Skip to content

Commit

Permalink
Implement unit tests for selected functions and templates, minor impr…
Browse files Browse the repository at this point in the history
…ovements in code and fixes in test data

Scope of the changes:
* Added unit tests for 2 functions and 5 templates
* made specification of `f:normaliseURI` function more precise and added a safeguard for unsupported values
* Introducced a new test file with a global variable overwritten for the included test purposes
* Removed trailing spaces in test data (as this was causing some code to fail)
* Fixed a typo
  • Loading branch information
gkostkowski committed Sep 16, 2024
1 parent 41e00bd commit c0e9bb0
Show file tree
Hide file tree
Showing 11 changed files with 266 additions and 25 deletions.
14 changes: 12 additions & 2 deletions src/common/utils.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -408,18 +408,28 @@


<xd:doc>
<xd:desc>Normalise URI from prefix:localSegment to prefix-localSegment</xd:desc>
<xd:desc>Normalise compact URI from prefix:localSegment to prefix-localSegment.
Regular URI is not supported.
</xd:desc>
<xd:param name="uri"/>
</xd:doc>
<xsl:function name="f:normaliseURI">
<xsl:param name="uri"/>
<xsl:if test="fn:matches($uri, '^http([s]*)://(.+)$')">
<xsl:sequence
select="fn:error(
xs:QName('unsupported-uri'),
'The function supports only a compact URI',
($uri)
)" />
</xsl:if>
<xsl:sequence select="replace($uri, ':', '-')"/>
</xsl:function>



<xd:doc>
<xd:desc>This function is used to combine 2 URIs to build the property shape URI
<xd:desc>This function is used to combine 2 compact URIs to build the property shape URI
shape-base-uri:{SourceClassURI}-{PropertyOrAttributeURI} Example: Class URI -
prefix:Procedure Attribute URI - prefix:hasScope Result will be
http://base.uri/data-shape/prefix-Procedure-prefix-hasScope</xd:desc>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
()
else
if (fn:boolean($datatypeValues)) then
f:generateFormattedWarningMessage(fn:concat('The attribute ', $attributeName, ' is has different datatypes in reuse contexts.',
f:generateFormattedWarningMessage(fn:concat('The attribute ', $attributeName, ' has different datatypes in reuse contexts.',
'When a property is reused in multiple contexts, the data-type is expected to be the same.',
'In this case, multiple data-types are found: '), $datatypeWithAnnotations,
'//elements/element/attributes',
Expand Down
1 change: 1 addition & 0 deletions test/ePO-default-config/namespaces.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

<prefix name="epo" value="http://data.europa.eu/a4g/ontology#"/>
<prefix name="epo-cat" value="http://data.europa.eu/a4g/ontology#"/>
<prefix name="epo-ecat" value="http://data.europa.eu/a4g/ontology#"/>
<prefix name="epo-con" value="http://data.europa.eu/a4g/ontology#"/>
<prefix name="epo-ord" value="http://data.europa.eu/a4g/ontology#"/>
<prefix name="epo-not" value="http://data.europa.eu/a4g/ontology#"/>
Expand Down
20 changes: 10 additions & 10 deletions test/testData/ePO-CM-v2.0.1-2022-04-29_test.eap.xmi

Large diffs are not rendered by default.

43 changes: 43 additions & 0 deletions test/unitTests/test-common/test-utils.xspec
Original file line number Diff line number Diff line change
Expand Up @@ -311,4 +311,47 @@
</x:call>
<x:expect label="result" select="fn:true()"/>
</x:scenario>


<x:scenario label="Scenario for testing function buildPropertyShapeURI">
<x:scenario label="valid CURIE">
<x:call function="f:buildPropertyShapeURI">
<x:param name="firstUri" select="'prefix:Procedure'"/>
<x:param name="secondUri" select="'prefix:hasScope'"/>
</x:call>
<x:expect label="result"
select="'http://data.europa.eu/a4g/data-shape#prefix-Procedure-prefix-hasScope'"/>
</x:scenario>

<x:scenario catch="yes" label="unsupported URI">
<x:call function="f:buildPropertyShapeURI">
<x:param name="firstUri" select="'http://dummy.org/Procedure'"/>
<x:param name="secondUri" select="'http://dummy.org/hasScope'"/>
</x:call>
<x:expect label="err:code" test="$x:result?err?code"
select="xs:QName('unsupported-uri')" />
<x:expect label="err:description" test="$x:result?err?description"
select="'The function supports only a compact URI'" />
</x:scenario>
</x:scenario>


<x:scenario label="Scenario for testing function normaliseURI">
<x:scenario label="valid CURIE">
<x:call function="f:normaliseURI">
<x:param name="uri" select="'prefix:Procedure'"/>
</x:call>
<x:expect label="result" select="'prefix-Procedure'"/>
</x:scenario>

<x:scenario catch="yes" label="unsupported URI">
<x:call function="f:normaliseURI">
<x:param name="uri" select="'http://dummy.org/Procedure'"/>
</x:call>
<x:expect label="err:code" test="$x:result?err?code"
select="xs:QName('unsupported-uri')" />
<x:expect label="err:description" test="$x:result?err?description"
select="'The function supports only a compact URI'" />
</x:scenario>
</x:scenario>
</x:description>
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,104 @@
<x:expect label="expect to find a warning" test="/dd/@class = 'filter warnings'"/>

</x:scenario>

<x:scenario label="classAttributesWithSameName">
<x:scenario label="correct input">
<x:context>
<xmi:XMI>
<xmi:Extension>
<element xmi:idref="id1" xmi:type="uml:Class" name="epo:Person">
<attributes>
<attribute xmi:idref="id2" name="epo:name">
<documentation value="The complete name of a person."/>
<properties type="rdfs:Literal"/>
<bounds lower="1" upper="1"/>
</attribute>
<attribute xmi:idref="id3" name="epo:address">
<documentation value="A place of residence."/>
<properties type="rdfs:Literal"/>
<bounds lower="1" upper="*"/>
</attribute>
</attributes>
</element>
<element xmi:idref="id1" xmi:type="uml:Class" name="epo:Contractor">
<attributes>
<attribute xmi:idref="id4" name="epo:name">
<documentation value="The complete name of a person."/>
<properties type="rdfs:Literal"/>
<bounds lower="1" upper="1"/>
</attribute>
<attribute xmi:idref="id5" name="epo:address">
<documentation value="A place of residence."/>
<properties type="rdfs:Literal"/>
<bounds lower="1" upper="*"/>
</attribute>
</attributes>
</element>
</xmi:Extension>
</xmi:XMI>
</x:context>
<x:call template="classAttributesWithSameName">
</x:call>
<x:expect label="empty section">
<h1 id="classAttributesUsage">Class attributes with multiple usages</h1>
</x:expect>
</x:scenario>

<x:scenario label="all possible violations captured">
<x:context>
<xmi:XMI>
<xmi:Extension>
<element xmi:idref="id1" xmi:type="uml:Class" name="epo:Person">
<attributes>
<attribute xmi:idref="id2" name="epo:name">
<documentation value="The complete name of a person."/>
<properties type="rdfs:Literal"/>
<bounds lower="1" upper="1"/>
</attribute>
<attribute xmi:idref="id3" name="epo:address">
<documentation value="A place of residence."/>
<properties type="rdfs:Literal"/>
<bounds lower="1" upper="*"/>
</attribute>
</attributes>
</element>
<element xmi:idref="id1" xmi:type="uml:Class" name="epo:Contractor">
<attributes>
<attribute xmi:idref="id4" name="epo:name">
<documentation value="Names (first and alternative) of a person."/>
<properties type="rdfs:Literal"/>
<bounds lower="1" upper="*"/>
</attribute>
<attribute xmi:idref="id5" name="epo:surname">
<documentation value="The complete name of a person."/>
<properties type="rdfs:Literal"/>
<bounds lower="1" upper="1"/>
</attribute>
<attribute xmi:idref="id6" name="epo:address">
<documentation value="A place of residence."/>
<properties type="dct:Address"/>
<bounds lower="1" upper="*"/>
</attribute>
</attributes>
</element>
</xmi:Extension>
</xmi:XMI>
</x:context>
<x:call template="classAttributesWithSameName">
</x:call>
<x:expect label="different datatypes"
test="contains(/dl[@id='attribute-epo:address-usage']/dd[@class='filter warnings']/text(), 'The attribute epo:address has different datatypes in reuse contexts')"/>
<x:expect label="different multiplicities"
test="some $genMsg in /dl[@id='attribute-epo:name-usage']/dd[@class='filter warnings']/text()
satisfies contains($genMsg, 'The attribute epo:name has different multiplicities in reuse contexts')"
/>
<x:expect label="different definitions"
test="some $genMsg in /dl[@id='attribute-epo:name-usage']/dd[@class='filter warnings']/text()
satisfies contains($genMsg, 'The attribute epo:name is defined differently in reuse contexts')"
/>
</x:scenario>
</x:scenario>


</x:description>
49 changes: 49 additions & 0 deletions test/unitTests/test-owl-core-lib/test-connectors-owl-core.xspec
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,53 @@
<x:expect label="skos:inScheme" test="boolean(/skos:Concept/skos:inScheme)"/>
</x:scenario>


<x:scenario label="Scenario for testing connectorsOwlCore template">
<x:context>
<xmi:XMI>
<xmi:Extension>
<connectors>
<connector xmi:idref="id1">
<source xmi:idref="id2">
<model type="Class" name="epo:AwardDecision"/>
<role visibility="Public" targetScope="instance"/>
<type aggregation="none" containment="Unspecified"/>
</source>
<target xmi:idref="id3">
<model type="Class" name="epo:LotAwardOutcome"/>
<role name="epo:comprisesLotAwardOutcome" visibility="Public" targetScope="instance"/>
<type multiplicity="1..*" aggregation="none" containment="Unspecified"/>
</target>
<model ea_localid="2833"/>
<properties ea_type="Association" direction="Source -&gt; Destination"/>
<documentation value="Incorporates LotAwardOutcome."/>
<labels rb="1..*" rt="+epo:comprisesLotAwardOutcome"/>
</connector>
<connector xmi:idref="id4">
<source xmi:idref="id5">
<model type="Object" name="epo:result"/>
<role visibility="Public" targetScope="instance"/>
<type aggregation="none" containment="Unspecified"/>
</source>
<target xmi:idref="id6">
<model type="Enumeration" name="at-voc:form-type"/>
<role visibility="Public" targetScope="instance"/>
<type aggregation="none" containment="Unspecified"/>
</target>
<properties ea_type="Realisation" direction="Source -&gt; Destination"/>
</connector>
</connectors>
</xmi:Extension>
</xmi:XMI>
</x:context>
<x:variable name="testedPropUri" as="xs:string" select="'http://data.europa.eu/a4g/ontology#comprisesLotAwardOutcome'"/>
<x:call template="connectorsOwlCore"/>

<x:expect label="has only one owl:ObjectProperty defined" test="count(/owl:ObjectProperty) = 1"/>
<x:expect label="is owl:ObjectProperty defined" test="/owl:ObjectProperty/@rdf:about=$testedPropUri"/>
<x:expect label="correct skos:prefLabel" test="/rdf:Description[@rdf:about = $testedPropUri]/skos:prefLabel[@xml:lang='en']/text() = 'Comprises lot award outcome'"/>
<x:expect label="has skos:definition" test="boolean(/rdf:Description[@rdf:about=$testedPropUri]/skos:definition[@xml:lang='en'])"/>
<x:expect label="is linked to the ontology" test="/rdf:Description[@rdf:about = $testedPropUri]/rdfs:isDefinedBy/@rdf:resource = 'http://data.europa.eu/a4g/ontology#core'"/>
</x:scenario>

</x:description>
12 changes: 0 additions & 12 deletions test/unitTests/test-owl-core-lib/test-elements-owl-core.xspec
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,6 @@
</x:scenario>


<!-- <x:scenario
label="Scenario for testing template with match 'element[@xmi:type = 'uml:Enumeration']">
<x:context href="../../testData/ePO-CM_v2.0.1_test.eap.xmi"
select="/xmi:XMI/xmi:Extension[1]/elements[1]/element[144]"/>
<x:expect label="there is a skos:ConceptScheme" test="boolean(/skos:ConceptScheme)"/>
<x:expect label="there is a skos:prefLabel" test="boolean(/skos:ConceptScheme/skos:prefLabel)"/>
<x:expect label="there is a correct URI"
test="/skos:ConceptScheme/@rdf:about = 'http://data.europa.eu/a4g/ontology#CriterionGroupPropertyType' "
/>
</x:scenario>-->


<x:scenario
label="Scenario for testing template with match 'element[@xmi:type = 'uml:DataType']">
<x:context href="../../testData/ePO-CM_v2.0.1_test.eap.xmi"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<x:description
xmlns:x="http://www.jenitennison.com/xslt/xspec"
xmlns:uml="http://www.omg.org/spec/UML/20131001"
xmlns:xmi="http://www.omg.org/spec/XMI/20131001"
xmlns:umldi="http://www.omg.org/spec/UML/20131001/UMLDI"
xmlns:dc="http://www.omg.org/spec/UML/20131001/UMLDC"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:dct="http://purl.org/dc/terms/"
xmlns:skos="http://www.w3.org/2004/02/skos/core#"
stylesheet="../../../src/owl-core-lib/elements-owl-core.xsl">

<x:param name="enableGenerationOfConceptSchemes" select="true()"/>

<x:scenario
label="Scenario for testing template with match 'element[@xmi:type = 'uml:Enumeration']">
<x:context href="../../testData/ePO-CM-v2.0.1-2022-04-29_test.eap.xmi"
select="/xmi:XMI/xmi:Extension[1]/elements[1]/element[298]"/>
<x:variable name="testedEnum" as="xs:string" select="'http://www.w3.org/2006/time#TemporalUnit'"/>

<x:expect label="there is a skos:ConceptScheme" test="/skos:ConceptScheme/@rdf:about = $testedEnum"/>
<x:expect label="there is a skos:prefLabel" test="/rdf:Description[@rdf:about = $testedEnum]/skos:prefLabel[@xml:lang='en']/text() = 'Temporal unit'"/>
</x:scenario>

</x:description>
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@
<x:expect label="result" test="boolean(/rdf:Description/rdf:type[@rdf:resource='http://www.w3.org/2002/07/owl#AllDisjointClasses'])"/>
</x:scenario>


<x:scenario label="Test distinctConnectorsNamesInReasoningLayer">
<x:context href="../../testData/ePO-CM-v2.0.1-2022-04-29_test.eap.xmi" />
<x:call template="distinctConnectorsNamesInReasoningLayer"/>
<x:expect label="class to enumeration connector" test="/rdf:Description[@rdf:about='http://data.europa.eu/a4g/ontology#hasNotificationContentType']/rdfs:domain/@rdf:resource = 'http://data.europa.eu/a4g/ontology#Notice'"/>
<x:expect label="epo class to epo-cat class: domain" test="/rdf:Description[@rdf:about='http://data.europa.eu/a4g/ontology#hasPriceValidity']/rdfs:domain/@rdf:resource = 'http://data.europa.eu/a4g/ontology#eCatalogueLine'"/>
<x:expect label="epo class to epo-cat class: range" test="/rdf:Description[@rdf:about='http://data.europa.eu/a4g/ontology#hasPriceValidity']/rdfs:range/@rdf:resource = 'http://data.europa.eu/a4g/ontology#Period'"/>
</x:scenario>


<x:scenario
label="Scenario for testing template with match 'connector[./properties/@ea_type = 'Association']">
<x:context href="../../testData/ePO-CM_v.3.0.1.eap.xmi"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,19 @@


</x:scenario>

<x:scenario label="Scenario for testing template with match element[@xmi:type = 'uml:Class']/attributes/attribute" >
<x:context href="../../testData/ePO_core_with_tags.xml" select="/xmi:XMI/xmi:Extension[1]/elements[1]/element[146]/attributes[1]/attribute[1]"/>
<x:variable name="testedPropShapeUri"
as="xs:string"
select="'http://data.europa.eu/a4g/data-shape#epo-FrameworkAgreementTerm-epo-hasMaximumParticipantsNumber'"/>
<x:expect label="correct node-property shapes link" test="boolean(/rdf:Description[@rdf:about='http://data.europa.eu/a4g/data-shape#epo-FrameworkAgreementTerm']/sh:property[@rdf:resource=$testedPropShapeUri])"/>
<x:expect label="property shape: correct name" test="/rdf:Description[@rdf:about=$testedPropShapeUri]/sh:name/text() = 'Has maximum participants number'"/>
<x:expect label="property shape: correct datatype" test="boolean(/rdf:Description[@rdf:about=$testedPropShapeUri]/sh:datatype[@rdf:resource='http://www.w3.org/2001/XMLSchema#integer'])"/>
<x:expect label="property shape: correct maxCount" test="/rdf:Description[@rdf:about=$testedPropShapeUri]/sh:maxCount = 1"/>
<x:expect label="property shape: correct description" test="boolean(/rdf:Description[@rdf:about=$testedPropShapeUri]/sh:description)"/>
<x:expect label="is property shape defined" test="boolean(/sh:PropertyShape[@rdf:about=$testedPropShapeUri]/sh:path[@rdf:resource='http://data.europa.eu/a4g/ontology#hasMaximumParticipantsNumber'])"/>
</x:scenario>


<x:scenario label="Scenario for testing template with match 'ownedComment[@xmi:type='uml:Comment']">
Expand Down

0 comments on commit c0e9bb0

Please sign in to comment.