Xspec unit testing

Post here questions and problems related to oXygen frameworks/document types.
DanielCDS
Posts: 7

Xspec unit testing

Tue May 03, 2016 6:06 pm

Does anyone know how to test this simple code using the XSpec in XSLT?

Code: Select all

   <xsl:template match="@NameTitle">      
      <NameTitle Value="{if(. = ('Sir', 'Lady', 'Hon', 'R Hon')) then 'Other' else .}"
          Description="{if(. = ('Sir', 'Lady', 'Hon', 'R Hon')) then . else ''}"/>
   </xsl:template>

       

        <xsl:template match="BusinessChannel/Contact/ContactPerson">
      <PersonName>
         <xsl:apply-templates select="@NameTitle"/>
         <FirstName>
            <xsl:value-of select="@FirstName"/>
         </FirstName>
         <Surname>
            <xsl:value-of select="@Surname"/>
         </Surname>
      </PersonName>
   </xsl:template>

Using Xspec is simple for testing functions from a beginner point of view but for templates that select attributes is not.
DanielCDS
Posts: 7

Re: Xspec unit testing

Thu May 05, 2016 10:18 am

I've done this for solving the problem:

Code: Select all

<x:scenario label="Scenario for testing template with match '@NameTitle' When processing a NameTitle attribute">
        <x:scenario label="NameTitle = 'Sir'">
            <x:context href="Test60%20-%20CAL.xml" select="//@NameTitle[.='Sir']"/>
            <x:expect label="Produce a NameTitle element with the Value='Other' and Description='Sir'">
                <NameTitle Value="Other"
                    Description="Sir"/>
            </x:expect>
        </x:scenario>
        <x:scenario label="NameTitle = 'Lady'">
            <x:context href="Test60%20-%20CAL.xml" select="//@NameTitle[.='Lady']"/>
            <x:expect label="Produce a NameTitle element with the Value='Other' and Description='Lady'">
                <NameTitle Value="Other"
                    Description="Lady"/>
            </x:expect>
        </x:scenario>
        <x:scenario label="NameTitle = 'Hon'">
            <x:context href="Test60%20-%20CAL.xml" select="//@NameTitle[.='Hon']"/>
            <x:expect label="Produce a NameTitle element with the Value='Other' and Description='Hon'">
                <NameTitle Value="Other"
                    Description="Hon"/>
            </x:expect>
        </x:scenario>
        <x:scenario label="NameTitle = 'R Hon'">
            <x:context href="Test60%20-%20CAL.xml" select="//@NameTitle[.='R Hon']"/>
            <x:expect label="Produce a NameTitle element with the Value='Other' and Description='R Hon'">
                <NameTitle Value="Other"
                    Description="R Hon"/>
            </x:expect>
        </x:scenario>
        <!--
        <x:scenario label="NameTitle != ('Sir', 'Lady', 'Hon', 'R Hon')">
            <x:context href="Test60%20-%20CAL.xml" select="//@NameTitle"/>
            <x:expect label="Produce a NameTitle element with the Value !='Other'">
                <NameTitle Value="..."
                    Description=""/>
            </x:expect>
        </x:scenario>-->
    </x:scenario>
alex_jitianu
Posts: 632

Re: Xspec unit testing

Thu May 05, 2016 12:02 pm

Hi Daniel,

Thank you for posting the solution so others might benefit from it. A small tutorial on writing scenarios can be found in the XSpec Wiki. Also, a good place to get in touch with people that have experience with XSpec is on the XSpec discussion list.

Best regards,
Alex

Return to “SDK-API, Frameworks - Document Types”

Who is online

Users browsing this forum: No registered users and 0 guests