HsacAcceptanceTests.SlimTests.UtilityFixtures.XmlFixture


XmlFixture allows checks on XML, similar to what is supported by XmlHttpTest, obtained from other sources than HTTP calls.

script xml fixture
load Hello
show document
<xml>
    <nested>
        <sub_nested a="1">Hello</sub_nested>
    </nested>
</xml>
check xPath //sub_nested/@a 1


script xml fixture
load
<nested xmlns="http://ws.cdyne.com/WeatherWS/"><sub_nested a="1">Hello</sub_nested><sub_nested a="2">Bye</sub_nested></nested>
show document
<nested xmlns="http://ws.cdyne.com/WeatherWS/">
    <sub_nested a="1">Hello</sub_nested>
    <sub_nested a="2">Bye</sub_nested>
</nested>
register prefix ws for namespace http://ws.cdyne.com/WeatherWS/
check xPath //sub_nested/@a null
check xPath //ws:sub_nested/@a 1
show list xPath matches //ws:sub_nested/@a
  1. 1
  2. 2

Validation of xml against a schema file


script xml fixture
load file http://files/xmlTestExamples/valid_shiporder.xml
ensure validate against xsd file http://files/xmlTestExamples/shiporder_schema.xsd
load file http://files/xmlTestExamples/invalid_shiporder.xml
check validate against xsd file http://files/xmlTestExamples/shiporder_schema.xsd /.*Attribute 'orderid' must appear on element 'shiporder'.*/ found in: __EXCEPTION__:nl.hsac.fitnesse.fixture.slim.SlimFixtureException: message:<<XML Validation failed: cvc-complex-type.4: Attribute 'orderid' must appear on element 'shiporder'.>> at nl.hsac.fitnesse.fixture.util.XMLValidator.validateAgainst(XMLValidator.java:88) [file:/home/travis/build/fhoeben/hsac-fitnesse-fixtures/wiki/fixtures/] at nl.hsac.fitnesse.fixture.slim.XmlFixture.validateAgainstXsdFile(XmlFixture.java:100) [file:/home/travis/build/fhoeben/hsac-fitnesse-fixtures/wiki/fixtures/] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0_242] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [rt.jar:1.8.0_242] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.8.0_242] at java.lang.reflect.Method.invoke(Method.java:498) [rt.jar:1.8.0_242] at fitnesse.slim.fixtureInteraction.SimpleInteraction.methodInvoke(SimpleInteraction.java:322) [fitnesse-20200308.jar:20200308] at nl.hsac.fitnesse.fixture.slim.SlimFixture.invoke(SlimFixture.java:61) [file:/home/travis/build/fhoeben/hsac-fitnesse-fixtures/wiki/fixtures/] at nl.hsac.fitnesse.fixture.slim.SlimFixture.aroundSlimInvoke(SlimFixture.java:41) [file:/home/travis/build/fhoeben/hsac-fitnesse-fixtures/wiki/fixtures/] at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source) [n/a] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.8.0_242] at java.lang.reflect.Method.invoke(Method.java:498) [rt.jar:1.8.0_242] at fitnesse.slim.fixtureInteraction.SimpleInteraction.methodInvoke(SimpleInteraction.java:322) [fitnesse-20200308.jar:20200308] at fitnesse.slim.fixtureInteraction.SimpleInteraction.callMethod(SimpleInteraction.java:305) [fitnesse-20200308.jar:20200308] at fitnesse.slim.fixtureInteraction.SimpleInteraction.invokeMethod(SimpleInteraction.java:290) [fitnesse-20200308.jar:20200308] at fitnesse.slim.fixtureInteraction.SimpleInteraction.findAndInvoke(SimpleInteraction.java:217) [fitnesse-20200308.jar:20200308] at fitnesse.slim.MethodExecutor.findAndInvoke(MethodExecutor.java:18) [fitnesse-20200308.jar:20200308] at fitnesse.slim.FixtureMethodExecutor.execute(FixtureMethodExecutor.java:18) [fitnesse-20200308.jar:20200308] at fitnesse.slim.StatementExecutor.getMethodExecutionResult(StatementExecutor.java:139) [fitnesse-20200308.jar:20200308] at fitnesse.slim.StatementExecutor.call(StatementExecutor.java:112) [fitnesse-20200308.jar:20200308] at fitnesse.slim.instructions.CallAndOptionalAssignInstruction.executeInternal(CallAndOptionalAssignInstruction.java:30) [fitnesse-20200308.jar:20200308] at fitnesse.slim.instructions.Instruction.execute(Instruction.java:29) [fitnesse-20200308.jar:20200308] at fitnesse.slim.ListExecutor$Executive.executeStatement(ListExecutor.java:49) [fitnesse-20200308.jar:20200308] at fitnesse.slim.ListExecutor$Executive.executeStatements(ListExecutor.java:43) [fitnesse-20200308.jar:20200308] at fitnesse.slim.ListExecutor.execute(ListExecutor.java:85) [fitnesse-20200308.jar:20200308] at fitnesse.slim.SlimServer.executeInstructions(SlimServer.java:82) [fitnesse-20200308.jar:20200308] at fitnesse.slim.SlimServer.processOneSetOfInstructions(SlimServer.java:75) [fitnesse-20200308.jar:20200308] at fitnesse.slim.SlimServer.tryProcessInstructions(SlimServer.java:62) [fitnesse-20200308.jar:20200308] at fitnesse.slim.SlimServer.serve(SlimServer.java:47) [fitnesse-20200308.jar:20200308] at fitnesse.testsystems.slim.InProcessSlimClient$1.run(InProcessSlimClient.java:55) [fitnesse-20200308.jar:20200308] at java.lang.Thread.run(Thread.java:748) [rt.jar:1.8.0_242]

script file fixture
$xsd_schema<-[
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="shiporder">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="orderperson" type="xs:string"/>
      <xs:element name="shipto">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="name" type="xs:string"/>
            <xs:element name="address" type="xs:string"/>
            <xs:element name="city" type="xs:string"/>
            <xs:element name="country" type="xs:string"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="item" maxOccurs="unbounded">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="title" type="xs:string"/>
            <xs:element name="note" type="xs:string" minOccurs="0"/>
            <xs:element name="quantity" type="xs:positiveInteger"/>
            <xs:element name="price" type="xs:decimal"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
    <xs:attribute name="orderid" type="xs:string" use="required"/>
  </xs:complexType>
</xs:element>

</xs:schema>
]
content of http://files/xmlTestExamples/shiporder_schema.xsd

We can also use a schema from the wiki page


script xml fixture
load file http://files/xmlTestExamples/valid_shiporder.xml
ensure validate against xsd $xsd_schema->[
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="shiporder">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="orderperson" type="xs:string"/>
      <xs:element name="shipto">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="name" type="xs:string"/>
            <xs:element name="address" type="xs:string"/>
            <xs:element name="city" type="xs:string"/>
            <xs:element name="country" type="xs:string"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="item" maxOccurs="unbounded">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="title" type="xs:string"/>
            <xs:element name="note" type="xs:string" minOccurs="0"/>
            <xs:element name="quantity" type="xs:positiveInteger"/>
            <xs:element name="price" type="xs:decimal"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
    <xs:attribute name="orderid" type="xs:string" use="required"/>
  </xs:complexType>
</xs:element>

</xs:schema>
]