1

please help me with xspec syntax. I want to compare the values in the test file with constant: Test file:

<?xml version='1.0' encoding='ISO-8859-5'?>
<List>
    <M_INSDES>
        <S_UNH>
            <D_0062>3600</D_0062>
            <C_S009>
                <D_0065>INSDES</D_0065>
                <D_0052>D</D_0052>
                <D_0054>96A</D_0054>
                <D_0051>UN</D_0051>
                <D_0057>EAN001</D_0057>
            </C_S009>
        </S_UNH>
    </M_INSDES>
</List>

Following scenario works as expected:

    <x:scenario label="Scenario for testing an EDIFACT document type">
        <x:context href="test.xml" select="/List/M_INSDES/S_UNH/C_S009/D_0065">
        </x:context>        
        <x:expect label="The result of testing EDIFACT document type">INSDES</x:expect>                 
    </x:scenario>

Successful test

But scenario with multiply values fails:

<x:scenario label="Scenario for testing an EDIFACT document type for inbound file">
    <x:context href="test.xml" select="/List/M_INSDES/S_UNH/C_S009">
    </x:context>        
    <x:expect label="Message type identifier" test="D_0065 = 'INSDES'"></x:expect> 
    <x:expect label="Message type version number" test="D_0052 = 'D'"></x:expect>            
    <x:expect label="Message type release number" test="D_0054 = '96A'"></x:expect>                     
</x:scenario>

Failed test

How can I check three values of the node C_S009 using <x:expect test = ""/> ?

UPD.: added the xsl stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:my="myfunctions"
    exclude-result-prefixes="xs"
    version="2.0">
    <xsl:template match="/">
        <xsl:copy-of select="."/> 
    </xsl:template>
</xsl:stylesheet>
Andrey Davydenko
  • 341
  • 2
  • 18

2 Answers2

2

I think you are doing it all correct, but the context of your relative xpaths is wrong. Try using absolute paths in the expect elements like this and selecting the root element:

<x:scenario label="Scenario for testing an EDIFACT document type for inbound file">
    <x:context href="testdata.xml" select="/">
    </x:context>        
    <x:expect label="Message type identifier" test="/List/M_INSDES/S_UNH/C_S009/D_0065 = 'INSDES'"></x:expect> 
    <x:expect label="Message type version number" test="/List/M_INSDES/S_UNH/C_S009/D_0052 = 'D'"></x:expect>            
    <x:expect label="Message type release number" test="/List/M_INSDES/S_UNH/C_S009/D_0054 = '96A'"></x:expect>                     
</x:scenario>

I think relative paths do not work because your stylesheet just copies the complete document when matching the root element. In the XSpec report with the errors you can see that the result of the tests with relative paths is just the string values of the elements.

Before you posted your stylesheet, I used a stylesheet with a recursive "copy-all-nodes" template.

<xsl:template match="node() | @*">
    <xsl:copy>
        <xsl:apply-templates select="node() | @*"/>
    </xsl:copy>
</xsl:template>

With this stylesheet the relative paths work fine.

<x:scenario label="Scenario for testing an EDIFACT document type for inbound file">
    <x:context href="testdata.xml" select="/List/M_INSDES/S_UNH/C_S009">
    </x:context>        
    <x:expect label="Message type identifier" test="C_S009/D_0065 = 'INSDES'"></x:expect> 
    <x:expect label="Message type version number" test="C_S009/D_0052 = 'D'"></x:expect>            
    <x:expect label="Message type release number" test="C_S009/D_0054 = '96A'"></x:expect>                     
</x:scenario>
burki
  • 6,741
  • 1
  • 15
  • 31
2

Could you post the XSLT code you are testing with the XSpec test? It is difficult to reproduce it without the XSLT.

If you are testing an atomic value (i.e. a string in your case) you may be interested in using the select attribute of x:expect element as described in the XSpec documentation.

cirulls
  • 66
  • 1
  • 5
  • I added an xsl stylesheet in the question. But I don't understand how xslt stylesheet is used in this case, because I directly test the value C_S009/D_0065 from the href file without transformation. – Andrey Davydenko May 10 '18 at 07:39
  • XSpec is a kind of unit testing framework for XSL stylesheets. If you don't do transformations why would you use XSpec? – burki May 10 '18 at 17:41