HsacExamples.SlimTests.HttpTests.HttpPost3UsingFreemarkerTemplateTest


Body from template


By using a Freemarker template we can have more dynamic body content.

variable defined: ADD_TEMPLATE_NAME=samplePost.ftl.xml

Don't send a second argument element: error


The Freemarker template will not send a arg2 element if no value is supplied (the whole element will be omitted, as can be seen in the request below). The service will not like this.
Omitting the element on a null value could not be done when the body was in the scenario content.

script xml http test
template samplePost.ftl.xml
set value http://tempuri.org/SOAP.Demo.AddInteger for header SOAPAction
set value 10 for arg1
note the following 'post' is prefixed with 'reject' as the fixture will return false when a soap fault is returned
reject post template to http://www.crcind.com/csp/samples/SOAP.Demo.cls
check response status 400
show request
<s11:Envelope xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/">
    <s11:Body/>
</s11:Envelope>
show response Bad Request

Send a second argument element: success


When a second argument value is set the enclosing element is sent by the Freemarker template (as visible in the shown request content below), and the SOAP call will succeed.

script xml http test
template samplePost.ftl.xml
set value http://tempuri.org/SOAP.Demo.AddInteger for header SOAPAction
set value 10 for arg1
set value 30 for arg2
post template to http://www.crcind.com/csp/samples/SOAP.Demo.cls
check response status 200
show request
<s11:Envelope xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/">
    <s11:Body>
        <ns1:AddInteger xmlns:ns1="http://tempuri.org">
            <ns1:Arg1>10</ns1:Arg1>
            <ns1:Arg2>30</ns1:Arg2>
        </ns1:AddInteger>
    </s11:Body>
</s11:Envelope>
show response headers
Cache-Control no-cache
Pragma no-cache
Content-Length 382
Content-Type text/xml; charset=UTF-8
Expires Thu, 29 Oct 1998 17:04:19 GMT
Server Microsoft-IIS/7.5
Set-Cookie [CSPSESSIONID-SP-80-UP-csp-samples-=001000010000WT3DRxxd7B00003GYxVLAg0P2AKyGp6HX3uA--; path=/csp/samples/; httpOnly;, CSPWSERVERID=e7193bb0902d499bc4224b3ddce2e29b8f774043; path=/; httpOnly;]
X-Powered-By ASP.NET
Date Mon, 16 Mar 2020 08:31:18 GMT
show response
<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:s="http://www.w3.org/2001/XMLSchema">
    <SOAP-ENV:Body>
        <AddIntegerResponse xmlns="http://tempuri.org">
            <AddIntegerResult>40</AddIntegerResult>
        </AddIntegerResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
register prefix tempuri for namespace http://tempuri.org
check xPath //tempuri:AddIntegerResult/text() 40