smalltalk
/
osmo-st-all
Archived
1
0
Fork 0
This repository has been archived on 2022-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
osmo-st-all/SoapCoreTests.st

1078 lines
34 KiB
Smalltalk
Raw Normal View History

TestCase subclass: SoapActionTestCase [
<comment: nil>
<category: 'SOAP-TestCases'>
testIntent [
<category: 'testing'>
| act |
act := SoapAction intent: 'urn:targetObjectURI:fooBar'.
self should:
[act printString = ('SOAPAction: ' , '"urn:targetObjectURI:fooBar"'
, (String with: Character cr with: Character lf))]
]
testIntentByRequestURI [
<category: 'testing'>
| act |
act := SoapAction intentByRequestURI.
self should:
[act printString
= ('SOAPAction: ' , '""' , (String with: Character cr with: Character lf))]
]
testNoIntent [
<category: 'testing'>
| act |
act := SoapAction noIntent.
self should:
[act printString
= ('SOAPAction: ' , (String with: Character cr with: Character lf))]
]
]
TestCase subclass: SoapDecoderTestCase [
<comment: nil>
<category: 'SOAP-TestCases'>
arrayOfArrayXML [
<category: 'fixtures'>
^'<m:reverseArray
xmlns:m="http://www.mars.dti.ne.jp/~umejava/smalltalk/soapOpera/rpc/"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENC:Array xsi:type="SOAP-ENC:Array"
SOAP-ENC:arrayType="SOAP-ENC:Array[2]">
<item xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="xsd:anyType[0]">
</item>
<item xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="xsd:anyType[3]">
<item xsi:type="xsd:int">17974494715439249409</item>
<item xsi:type="xsd:string">aV34fTn/QoILMlilPla2Pw==</item>
<item xsi:type="xsd:string">20030913T14:26:28 &#43;200</item>
</item>
</SOAP-ENC:Array>
</m:reverseArray>
'
]
arrayReturnEnvelopeDocumentStyleXML [
<category: 'fixtures'>
^'<?xml version="1.0" encoding="UTF-8" ?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns0="urn:my.test.com">
<env:Body>
<ns0:DataVersionArrayElement>
<ns0:dataVersion>
<ns0:country>US</ns0:country>
<ns0:build>379</ns0:build>
</ns0:dataVersion>
<ns0:dataVersion>
<ns0:country>CA</ns0:country>
<ns0:build>376</ns0:build>
</ns0:dataVersion>
</ns0:DataVersionArrayElement>
</env:Body>
</env:Envelope>'
]
arrayWithEmptyStringXML [
<category: 'fixtures'>
^' <m:reverseArray
xmlns:m="http://www.mars.dti.ne.jp/~umejava/smalltalk/soapOpera/rpc/"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<anArray SOAP-ENC:arrayType="xsd:anyType[3]">
<item xsi:type="xsd:string">Hello</item>
<item xsi:type="xsd:string"></item>
<item xsi:type="xsd:string">Dolphin</item>
</anArray>
</m:reverseArray>
'
]
complexDataXML [
"Google API like complex XML"
<category: 'fixtures'>
^' <return xsi:type="ns1:GoogleSearchResult" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<documentFiltering xsi:type="xsd:boolean">false</documentFiltering>
<estimatedTotalResultsCount xsi:type="xsd:int">1</estimatedTotalResultsCount>
<directoryCategories xmlns:ns2="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns2:Array" ns2:arrayType="ns1:DirectoryCategory[0]"></directoryCategories>
<searchTime xsi:type="xsd:double">0.194871</searchTime>
<resultElements xmlns:ns3="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns3:Array" ns3:arrayType="ns1:ResultElement[1]">
<item xsi:type="ns1:ResultElement">
<cachedSize xsi:type="xsd:string">2k</cachedSize>
<hostName xsi:type="xsd:string">somehost</hostName>
<snippet xsi:type="xsd:string">snippet...</snippet>
<directoryCategory xsi:type="ns1:DirectoryCategory">
<specialEncoding xsi:type="xsd:string"></specialEncoding>
<fullViewableName xsi:type="xsd:string"></fullViewableName>
</directoryCategory>
<relatedInformationPresent xsi:type="xsd:boolean">true</relatedInformationPresent>
<directoryTitle xsi:type="xsd:string"></directoryTitle>
<summary xsi:type="xsd:string"></summary>
<URL xsi:type="xsd:string">http://www.squeak.org</URL>
<title xsi:type="xsd:string">Squeak home page</title>
</item>
</resultElements>
<endIndex xsi:type="xsd:int">1</endIndex>
<searchTips xsi:type="xsd:string"></searchTips>
<searchComments xsi:type="xsd:string"></searchComments>
<startIndex xsi:type="xsd:int">1</startIndex>
<estimateIsExact xsi:type="xsd:boolean">true</estimateIsExact>
<searchQuery xsi:type="xsd:string">squeak</searchQuery>
</return>'
]
dotNetSharedValuesEnvelopeXML [
<category: 'fixtures'>
^'<soap:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:types="urn:WebBookingEngine" xmlns:tns="urn:WebBookingEngine"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<types:FindPropertiesIdByLocationResponse>
<FindPropertiesIdByLocationResult
href="#id1"></FindPropertiesIdByLocationResult>
</types:FindPropertiesIdByLocationResponse>
<soapenc:Array id="id1" soapenc:arrayType="xsd:int[37]">
<Item>22039</Item>
<Item>22933</Item>
<Item>23177</Item>
<Item>23249</Item>
<Item>23393</Item>
</soapenc:Array>
</soap:Body>
</soap:Envelope>'
]
dotNetSharedValuesEnvelopeXML2 [
<category: 'fixtures'>
^'<soap:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:types="http://tempuri.org/" xmlns:tns="http://tempuri.org/"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<types:FindCustomersResponse>
<FindCustomersResult href="#id1"></FindCustomersResult>
</types:FindCustomersResponse>
<soapenc:Array id="id1" soapenc:arrayType="types:Customer[2]">
<Item href="#id2"></Item>
<Item href="#id3"></Item>
</soapenc:Array>
<types:Customer id="id2" xsi:type="types:Customer">
<Name xsi:type="xsd:string">Ume</Name>
<Age xsi:type="xsd:int">36</Age>
<DateOfBirth
xsi:type="xsd:dateTime">1970-11-22T00:00:00.0000000-07:00</DateOfBirth>
</types:Customer>
<types:Customer id="id3" xsi:type="types:Customer">
<Name xsi:type="xsd:string">Ramon</Name>
<Age xsi:type="xsd:int">31</Age>
<DateOfBirth
xsi:type="xsd:dateTime">1995-11-22T00:00:00.0000000-07:00</DateOfBirth>
</types:Customer>
</soap:Body>
</soap:Envelope>
'
]
dotNetSharedValuesEnvelopeXML3 [
<category: 'fixtures'>
^'<soap:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:types="http://tempuri.org/" xmlns:tns="http://tempuri.org/"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<types:GoResponse>
<GoResult href="#id1"></GoResult>
<aSimpleOutParam xsi:type="xsd:int">42</aSimpleOutParam>
<aMultiValOutParam href="#id2"></aMultiValOutParam>
</types:GoResponse>
<soapenc:Array id="id1" soapenc:arrayType="xsd:string[10]">
<Item>632900993212352500</Item>
<Item>632900993212508750</Item>
</soapenc:Array>
<soapenc:Array id="id2" soapenc:arrayType="xsd:int[3]">
<Item>1</Item>
<Item>2</Item>
<Item>3</Item>
</soapenc:Array>
</soap:Body>
</soap:Envelope>'
]
multiReturnEnvelopeDocumentStyleXML [
<category: 'fixtures'>
^'<soapenv:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
</soapenv:Header>
<soapenv:Body>
<ns:sampleResponse xmlns:ns="http://service.spring/xsd">
<ns:return>
<id xmlns="http://bean.spring/xsd">5</id>
<number xmlns="http://bean.spring/xsd">65413</number>
<address1 xmlns="http://bean.spring/xsd">Brno-Chrlice</address1>
<address2 xmlns="http://bean.spring/xsd">Brno-msto</address2>
</ns:return>
<ns:return>
<id xmlns="http://bean.spring/xsd">1</id>
<number xmlns="http://bean.spring/xsd">65384</number>
<address1 xmlns="http://bean.spring/xsd">Liberec</address1>
<address2 xmlns="http://bean.spring/xsd">Chrastava</address2>
</ns:return>
</ns:sampleResponse>
</soapenv:Body>
</soapenv:Envelope>'
]
oneSizeArrayReturnEnvelopeDocumentStyleXML [
<category: 'fixtures'>
^'<?xml version="1.0" encoding="UTF-8" ?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns0="urn:my.test.com">
<env:Body>
<ns0:DataVersionArrayElement>
<ns0:dataVersion>
<ns0:country>US</ns0:country>
<ns0:build>379</ns0:build>
</ns0:dataVersion>
</ns0:DataVersionArrayElement>
</env:Body>
</env:Envelope>'
]
sharedValuesXML [
<category: 'fixtures'>
^'<return xsi:type="e:SearchResult" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<e:Book>
<title>My Life and Work</title>
<author href="#Person-1"/>
</e:Book>
<e:Person id="Person-1">
<name>Henry Ford</name>
<address href="#Address-2"/>
</e:Person>
<e:Address id="Address-2">
<email>mailto:henryford@hotmail.com</email>
<web>http://www.henryford.com</web>
</e:Address>
</return>'
]
singleReturnEnvelopeDocumentStyleXML [
<category: 'fixtures'>
^'<soapenv:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
</soapenv:Header>
<soapenv:Body>
<ns:sampleResponse xmlns:ns="http://service.spring/xsd">
<ns:return>bareString</ns:return>
</ns:sampleResponse>
</soapenv:Body>
</soapenv:Envelope>'
]
testDecodeAnyArray [
<category: 'testing'>
| dec ret |
dec := SoapDecoder new.
ret := dec
decodeXmlElement: (SoapVariable name: 'anyArr1' value: #(1 '2' 3.0))
asXmlElement.
self should: [ret = #(1 '2' 3.0)]
]
testDecodeArrayOfArray [
<category: 'testing'>
| dec arrayElem ret |
dec := SoapDecoder new.
arrayElem := SoapWrapElement fromXml: self arrayOfArrayXML.
ret := dec decodeXmlElement: arrayElem.
self should: [(ret at: 'Array') isKindOf: Array].
self should: [((ret at: 'Array') at: 1) = #()].
self should:
[((ret at: 'Array') at: 2)
= #(17974494715439249409 'aV34fTn/QoILMlilPla2Pw==' '20030913T14:26:28 +200')]
]
testDecodeArrayReturnEnvelopeDocumentStyleXML [
"self debug: #testDecodeArrayReturnEnvelopeDocumentStyleXML"
<category: 'testing'>
| envelopeBuilder returnEnvelope message resp value dict1 dict2 |
SoapDecoder arrayTypeDict at: 'DataVersionArrayElement' put: Array.
envelopeBuilder := SoapEnvelopeBuilder new.
returnEnvelope := envelopeBuilder
buildSoapEnvelopeFromXmlString: self arrayReturnEnvelopeDocumentStyleXML.
message := SoapMessage envelope: returnEnvelope.
resp := SoapResponse fromSoapMessage: message.
resp style: #document.
value := resp returnValue.
SoapDecoder arrayTypeDict removeKey: 'DataVersionArrayElement'.
self should: [value size = 2].
dict1 := value first.
self should: [(dict1 at: 'build') = '379'].
self should: [(dict1 at: 'country') = 'US'].
dict2 := value second.
self should: [(dict2 at: 'build') = '376'].
self should: [(dict2 at: 'country') = 'CA']
]
testDecodeArrayWithEmptyString [
<category: 'testing'>
| dec arrayElem ret |
dec := SoapDecoder new.
arrayElem := SoapWrapElement fromXml: self arrayWithEmptyStringXML.
ret := dec decodeXmlElement: arrayElem.
self should: [(ret at: 'anArray') isKindOf: Array].
self should: [((ret at: 'anArray') at: 2) = '']
]
testDecodeBase64Binary [
<category: 'testing'>
| dec ret bytes |
dec := SoapDecoder new.
bytes := ByteArray
with: 1
with: 2
with: 3
with: 4.
ret := dec
decodeXmlElement: (SoapVariable
name: 'binbin'
value: bytes
type: #ByteArray) asXmlElement.
self should: [ret = bytes]
]
testDecodeBoolean [
"self debug: #testDecodeBoolean"
<category: 'testing'>
| dec ret |
dec := SoapDecoder new.
ret := dec
decodeXmlElement: (SoapVariable
name: 'arg1'
value: 'true'
type: #Boolean) asXmlElement.
self should: [ret = true].
ret := dec
decodeXmlElement: (SoapVariable
name: 'arg1'
value: '1'
type: #Boolean) asXmlElement.
self should: [ret = true].
ret := dec
decodeXmlElement: (SoapVariable
name: 'arg1'
value: 'false'
type: #Boolean) asXmlElement.
self should: [ret = false].
ret := dec
decodeXmlElement: (SoapVariable
name: 'arg1'
value: '0'
type: #Boolean) asXmlElement.
self should: [ret = false]
]
testDecodeComplexData [
<category: 'testing'>
"self debug: #testDecodeComplexData"
| dec complexElem ret resultElements resultElement directoryCategory |
dec := SoapDecoder new.
complexElem := SoapWrapElement fromXml: self complexDataXML.
ret := dec decodeXmlElement: complexElem.
self should: [ret isKindOf: Dictionary].
self should: [(ret at: 'startIndex') = 1].
self should: [(ret at: 'searchTime') = 0.194871].
self should: [(ret at: 'searchQuery') = 'squeak'].
resultElements := ret at: 'resultElements'.
self should: [resultElements isKindOf: Array].
self should: [resultElements size = 1].
resultElement := resultElements first.
self should: [resultElement isKindOf: Dictionary].
self should: [(resultElement at: 'URL') = 'http://www.squeak.org'].
self should: [(resultElement at: 'title') = 'Squeak home page'].
directoryCategory := resultElement at: 'directoryCategory'.
self should: [directoryCategory isKindOf: Dictionary].
self should: [(directoryCategory at: 'fullViewableName') = '']
]
testDecodeDotNetSharedValuesXMLEnvelope [
"self debug: #testDecodeDotNetSharedValuesXMLEnvelope"
<category: 'testing'>
| originalUseDotNetStyleSharedValues envelopeBuilder returnEnvelope message resp value |
[originalUseDotNetStyleSharedValues := SoapResponse
useDotNetStyleSharedValues.
SoapResponse useDotNetStyleSharedValues: true.
envelopeBuilder := SoapEnvelopeBuilder new.
returnEnvelope := envelopeBuilder
buildSoapEnvelopeFromXmlString: self dotNetSharedValuesEnvelopeXML.
message := SoapMessage envelope: returnEnvelope.
resp := SoapResponse fromSoapMessage: message.
value := resp returnValue.
self should:
[value
= #(22039 22933 23177 23249 23393 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil)]]
ensure:
[SoapResponse
useDotNetStyleSharedValues: originalUseDotNetStyleSharedValues]
]
"
testDecodeDotNetSharedValuesXMLEnvelope2 [
<category: 'testing'>
| originalUseDotNetStyleSharedValues envelopeBuilder returnEnvelope message resp value |
self should: [(Smalltalk at: #SoapSampleCustomer ifAbsent: []) ~= nil]
SoapSampleCustomer initialize.
[originalUseDotNetStyleSharedValues := SoapResponse
useDotNetStyleSharedValues.
SoapResponse useDotNetStyleSharedValues: true.
envelopeBuilder := SoapEnvelopeBuilder new.
returnEnvelope := envelopeBuilder
buildSoapEnvelopeFromXmlString: self dotNetSharedValuesEnvelopeXML2.
message := SoapMessage envelope: returnEnvelope.
resp := SoapResponse fromSoapMessage: message.
value := resp returnValue.
self should: [value size = 2].
self should: [value first name = 'Ume'].
self should: [value first age = 36].
self should:
[value first dateOfBirth
= (DateAndTime fromString: '1970-11-22T00:00:00-07:00')].
self should: [value second name = 'Ramon'].
self should: [value second age = 31].
self should:
[value second dateOfBirth
= (DateAndTime fromString: '1995-11-22T00:00:00-07:00')]]
ensure:
[SoapResponse
useDotNetStyleSharedValues: originalUseDotNetStyleSharedValues]
]
"
testDecodeDotNetSharedValuesXMLEnvelope3 [
"self debug: #testDecodeDotNetSharedValuesXMLEnvelope3"
<category: 'testing'>
| originalUseDotNetStyleSharedValues envelopeBuilder returnEnvelope message resp value outparams |
[originalUseDotNetStyleSharedValues := SoapResponse
useDotNetStyleSharedValues.
SoapResponse useDotNetStyleSharedValues: true.
envelopeBuilder := SoapEnvelopeBuilder new.
returnEnvelope := envelopeBuilder
buildSoapEnvelopeFromXmlString: self dotNetSharedValuesEnvelopeXML3.
message := SoapMessage envelope: returnEnvelope.
resp := SoapResponse fromSoapMessage: message.
value := resp returnValue.
self should: [value size = 10].
self should: [value first = '632900993212352500'].
self should: [value second = '632900993212508750'].
outparams := resp outparameters.
self should: [outparams size = 2].
self should: [outparams first = 42].
self should: [outparams second = #(1 2 3)]]
ensure:
[SoapResponse
useDotNetStyleSharedValues: originalUseDotNetStyleSharedValues]
]
testDecodeEmptyString [
<category: 'testing'>
| dec ret |
dec := SoapDecoder new.
ret := dec
decodeXmlElement: (SoapVariable
name: 'arg1'
value: ''
type: #String) asXmlElement.
self should: [ret = '']
]
testDecodeFloatArray [
<category: 'testing'>
| dec ret |
dec := SoapDecoder new.
ret := dec
decodeXmlElement: (SoapVariable name: 'floatArr1'
value: #(1.1 2.2 3.3000000000000003)) asXmlElement.
self should: [ret = #(1.1 2.2 3.3000000000000003)]
]
testDecodeInteger [
<category: 'testing'>
| dec ret |
dec := SoapDecoder new.
ret := dec
decodeXmlElement: (SoapVariable
name: 'arg1'
value: '1234567'
type: #Integer) asXmlElement.
self should: [ret = 1234567]
]
testDecodeIntegerArray [
<category: 'testing'>
| dec ret |
dec := SoapDecoder new.
ret := dec
decodeXmlElement: (SoapVariable
name: 'intArr1'
value: #(1 2 3)
type: #Array) asXmlElement.
self should: [ret = #(1 2 3)]
]
testDecodeIsSafe [
<category: 'testing'>
]
testDecodeMultiReturnEnvelopeDocumentStyleXML [
"self debug: #testDecodeMultiReturnEnvelopeDocumentStyleXML"
<category: 'testing'>
| envelopeBuilder returnEnvelope message resp value dict1 dict2 |
envelopeBuilder := SoapEnvelopeBuilder new.
returnEnvelope := envelopeBuilder
buildSoapEnvelopeFromXmlString: self multiReturnEnvelopeDocumentStyleXML.
message := SoapMessage envelope: returnEnvelope.
resp := SoapResponse fromSoapMessage: message.
resp style: #document.
value := resp returnValue.
self should: [value size = 2].
dict1 := value first.
self should: [(dict1 at: 'id') = '5'].
self should: [(dict1 at: 'number') = '65413'].
self should: [(dict1 at: 'address1') = 'Brno-Chrlice'].
self should: [(dict1 at: 'address2') = 'Brno-msto'].
dict2 := value second.
self should: [(dict2 at: 'id') = '1'].
self should: [(dict2 at: 'number') = '65384'].
self should: [(dict2 at: 'address1') = 'Liberec'].
self should: [(dict2 at: 'address2') = 'Chrastava']
]
testDecodeNil [
"self debug: #testDecodeNil"
<category: 'testing'>
| originalUseNull dec ret |
[originalUseNull := SoapEncoder useXsiNullAttribute.
dec := SoapDecoder new.
SoapEncoder useXsiNullAttribute: true.
ret := dec
decodeXmlElement: (SoapWrapElement fromXml: '<value xsd:null="true" />').
self should: [ret = nil]]
ensure: [SoapEncoder useXsiNullAttribute: originalUseNull]
]
testDecodeOneSizeArrayReturnEnvelopeDocumentStyleXML [
"self debug: #testDecodeOneSizeArrayReturnEnvelopeDocumentStyleXML"
<category: 'testing'>
| envelopeBuilder returnEnvelope message resp value dict1 |
SoapDecoder arrayTypeDict at: 'DataVersionArrayElement' put: Array.
envelopeBuilder := SoapEnvelopeBuilder new.
returnEnvelope := envelopeBuilder buildSoapEnvelopeFromXmlString: self
oneSizeArrayReturnEnvelopeDocumentStyleXML.
message := SoapMessage envelope: returnEnvelope.
resp := SoapResponse fromSoapMessage: message.
resp style: #document.
value := resp returnValue.
SoapDecoder arrayTypeDict removeKey: 'DataVersionArrayElement'.
self should: [value size = 1].
dict1 := value first.
self should: [(dict1 at: 'build') = '379'].
self should: [(dict1 at: 'country') = 'US']
]
testDecodeSharedValues [
"self debug: #testDecodeSharedValues"
<category: 'testing'>
| xml elem dec address book person |
xml := SoapDecoderTestCase new sharedValuesXML.
elem := SoapWrapElement fromXml: xml.
dec := SoapDecoder new.
elem := dec decodeXmlElement: elem.
address := elem at: 'Address'.
book := elem at: 'Book'.
person := elem at: 'Person'.
self should: [(book at: 'author') = person].
self should: [(person at: 'address') = address]
]
testDecodeSingleReturnEnvelopeDocumentStyleXML [
"self debug: #testDecodeSingleReturnEnvelopeDocumentStyleXML"
<category: 'testing'>
| envelopeBuilder returnEnvelope message resp value |
envelopeBuilder := SoapEnvelopeBuilder new.
returnEnvelope := envelopeBuilder
buildSoapEnvelopeFromXmlString: self singleReturnEnvelopeDocumentStyleXML.
message := SoapMessage envelope: returnEnvelope.
resp := SoapResponse fromSoapMessage: message.
resp style: #document.
value := resp returnValue.
self should: [value = 'bareString']
]
testDecodeString [
<category: 'testing'>
| dec ret |
dec := SoapDecoder new.
ret := dec
decodeXmlElement: (SoapVariable
name: 'arg1'
value: 'Smalltalk'
type: #String) asXmlElement.
self should: [ret = 'Smalltalk']
]
testDecodeStringArray [
<category: 'testing'>
| dec ret |
dec := SoapDecoder new.
ret := dec
decodeXmlElement: (SoapVariable
name: 'stringArr1'
value: #('a' 'b' '<c>')
type: #Array) asXmlElement.
self should: [ret = #('a' 'b' '<c>')]
]
testDefaultTypesDecodeIsSafe [
"self debug: #testDefaultTypesDecodeIsSafe"
<category: 'testing'>
| classes |
classes := SoapDecoder typeDict values asSet
collect: [:each | Smalltalk at: each].
classes do:
[:each |
| inst |
inst := [Integer readFrom: '1+2*3'] on: Error do: [:ex | ex "Handled"].
(each isKindOf: Number)
ifTrue: [self assert: (inst = 0 or: [inst isKindOf: Error])]
ifFalse: [self assert: ((inst isKindOf: each) or: [inst isKindOf: Error])].
self deny: inst = 9]
]
]
TestCase subclass: SoapBodyTestCase [
<comment: nil>
<category: 'SOAP-TestCases'>
testAddBodyEntries [
<category: 'testing'>
| body ent1 ent2 |
body := SoapBody new.
ent1 := SoapWrapElement named: 'request1' withPrefix: 'm1'.
ent1 declareNamespace: 'm1' uri: 'urn:request:1'.
body addBodyEntry: ent1.
ent2 := SoapWrapElement named: 'request1' withPrefix: 'm2'.
ent2 declareNamespace: 'm2' uri: 'urn:request:2'.
body addBodyEntry: ent2.
self should: [ent1 parent = body].
self should: [ent2 parent = body].
self should: [(body bodyEntries at: 1) = ent1].
self should: [(body bodyEntries at: 2) = ent2]
]
testIsMustUnderstandEnabled [
<category: 'testing'>
| body |
body := SoapBody new.
self should: [body isMustUnderstandEnabled]
]
testOverrideEncodingStyle [
<category: 'testing'>
| env body ent1 |
env := SoapEnvelope new.
env declareSoapEncEncoding.
self should:
[(env getAttributeNamed: SoapConstants soapEnvPrefix , ':'
, SoapConstants encodingStyle)
= SoapConstants soapEncURI].
self
should: [env encodingStyleURIs = (Array with: SoapConstants soapEncURI)].
body := env addBody.
body declareNamespace: 'b' uri: 'urn:body:1'.
body declareEncodingIn: 'b' uri: 'urn:encoding:1'.
self
shouldnt: [body encodingStyleURIs = (Array with: SoapConstants soapEncURI)].
self should: [body encodingStyleURIs = (Array with: 'urn:encoding:1')].
ent1 := SoapWrapElement named: 'request1' withPrefix: 'm1'.
ent1 declareNamespace: 'm1' uri: 'urn:request:1'.
body declareEncodingIn: 'm1' uri: 'urn:encoding:2'.
body addBodyEntry: ent1.
self should: [ent1 encodingStyleURIs = (Array with: 'urn:encoding:2')]
]
]
TestCase subclass: SoapEncArrayTestCase [
<comment: nil>
<category: 'SOAP-TestCases'>
testArrayItemType [
<category: 'testing'>
| elem1 elem2 |
elem1 := (SoapVariable name: 'arr' value: #(1 2 3)) asXmlElement.
self
should: [elem1 arrayItemType = (SoapConstants xsdPrefixColon , 'integer')].
elem2 := (SoapVariable name: 'arr' value: #(1 'two' 3)) asXmlElement.
self
should: [elem2 arrayItemType = (SoapConstants xsdPrefixColon , 'anyType')]
]
testArraySize [
<category: 'testing'>
| elem1 elem2 |
elem1 := (SoapVariable name: 'arr' value: #(1 nil 3)) asXmlElement.
self should: [elem1 size = 3].
elem2 := (SoapVariable name: 'arr' value: #()) asXmlElement.
self should: [elem2 size = 0]
]
testArrayWithNamespace [
<category: 'testing'>
| elem1 |
elem1 := (SoapVariable
name: 'arr'
value: #(1 2 3)
xsdType: 'ns1:myArrayType'
namespace: 'http://my.com/nm') asXmlElement.
self should: [(elem1 declaredNamespaceURIFor: 'ns1') = 'http://my.com/nm']
]
testIsArrayType [
<category: 'testing'>
| elem1 elem2 |
elem1 := (SoapVariable name: 'arr' value: #(1 2 3)) asXmlElement.
self should: [elem1 isArrayType].
elem2 := (SoapVariable name: 'prim' value: 1) asXmlElement.
self shouldnt: [elem2 isArrayType]
]
]
TestCase subclass: SoapEnvelopeTestCase [
<comment: nil>
<category: 'SOAP-TestCases'>
testEnvelopeMustUnderstand [
<category: 'testing'>
| env |
env := SoapEnvelope new.
self should: [env body isMustUnderstandEnabled].
env addHeader.
env header disableMustUnderstand.
self shouldnt: [env body isMustUnderstandEnabled]
]
testEnvelopeTypicalEncodingStyle [
<category: 'testing'>
| env body |
env := SoapEnvelope new.
env declareSoapEncEncoding.
self should:
[(env getAttributeNamed: SoapConstants soapEnvPrefix , ':'
, SoapConstants encodingStyle)
= SoapConstants soapEncURI].
self
should: [env encodingStyleURIs = (Array with: SoapConstants soapEncURI)].
body := env addBody.
self
should: [body encodingStyleURIs = (Array with: SoapConstants soapEncURI)]
]
]
TestCase subclass: SoapExceptionBuilderTestCase [
<comment: nil>
<category: 'SOAP-TestCases'>
fooBarBazFault [
<category: 'fixtures'>
| soapFault details stErrorClass messageText detail |
soapFault := SoapFault new.
details := SoapWrapElement named: 'details' withPrefix: 'e'.
stErrorClass := details createChildNamed: 'ErrorClass'.
stErrorClass value: 'FooBarBaz'.
messageText := details createChildNamed: 'messageText'.
messageText value: 'invalid not existing class'.
detail := soapFault addDetail.
detail addSubElement: details.
^soapFault
]
messageNotUnderstoodFault [
<category: 'fixtures'>
^[nil add: 1] on: MessageNotUnderstood
do:
[:ex |
| soapFault soapFaultDetailBuilder |
soapFault := SoapFault new.
soapFaultDetailBuilder := SoapFaultDetailBuilder new.
soapFaultDetailBuilder buildSoapFaultDetailOn: soapFault from: ex.
ex return: soapFault]
]
testMessageNotUnderstoodSignal [
<category: 'testing'>
| fault builder exception |
fault := self messageNotUnderstoodFault.
builder := SoapExceptionBuilder new.
exception := builder buildExceptionFrom: fault.
self should: [exception tag = '<<signaled in server>>'].
self should: [exception messageText = 'did not understand #add:'].
self should: [exception signal] raise: MessageNotUnderstood
]
testNotExistErrorClassSignal [
<category: 'testing'>
| fault builder |
fault := self fooBarBazFault.
builder := SoapExceptionBuilder new.
self should: [builder buildExceptionFrom: fault]
raise: SoapNoSuchExceptionClass
]
testZeroDivideSignal [
<category: 'testing'>
| fault builder exception |
fault := self zeroDivideFault.
builder := SoapExceptionBuilder new.
exception := builder buildExceptionFrom: fault.
self should: [exception signal] raise: ZeroDivide
]
zeroDivideFault [
<category: 'fixtures'>
^[1 / 0] on: ZeroDivide
do:
[:ex |
| soapFault soapFaultDetailBuilder |
soapFault := SoapFault new.
soapFaultDetailBuilder := SoapFaultDetailBuilder new.
soapFaultDetailBuilder buildSoapFaultDetailOn: soapFault from: ex.
ex return: soapFault]
]
]
TestCase subclass: SoapFaultTestCase [
<comment: nil>
<category: 'SOAP-TestCases'>
testBasicFault [
<category: 'testing'>
| fault detail |
fault := SoapFault client faultstring: 'Client Error!'.
self should:
[fault faultcode
= (SoapConstants soapEnvPrefixColon , SoapConstants client)].
self should: [fault faultstring = 'Client Error!'].
detail := fault addDetail.
self should: [detail name = 'detail']
]
testDetailedFault [
<category: 'testing'>
| fault detail myErrors myErrors2 message errorcode |
fault := SoapFault client faultstring: 'Client Error!'.
detail := fault addDetail.
myErrors := detail
addSubElement: (SoapWrapElement named: 'myErrors' withPrefix: 'e').
myErrors declareNamespace: 'e'
uri: 'http://www.mars.dti.ne.jp/~umejava/smalltalk/SoapOpera/errors'.
(myErrors createChildNamed: 'message')
value: 'My application didn''t work'.
(myErrors createChildNamed: 'errorcode') value: '1001'.
myErrors2 := fault detail findSubElementNamed: 'e:myErrors'. "##Apparently more work needed##"
message := myErrors2 children at: 1.
errorcode := myErrors2 children at: 2.
self should: [message value = 'My application didn''t work'].
self should: [errorcode value = '1001']
]
testMinorFaultCodes [
<category: 'testing'>
"##OBSOLETE## hierarchical notation is no longer used in SOAP1.2"
| fault |
fault := SoapFault client faultstring: 'Client Error!'.
fault attachMinorFaultCodes: #('Authentication' 'Password' 'Expired').
self should:
[fault faultcode = (SoapConstants soapEnvPrefixColon
, 'Client.Authentication.Password.Expired')]
]
]
TestCase subclass: SoapHeaderTestCase [
<comment: nil>
<category: 'SOAP-TestCases'>
testMustUnderstand [
<category: 'testing'>
| header |
header := SoapHeader new.
self shouldnt: [header isMustUnderstandEnabled].
header enableMustUnderstand.
self should: [header isMustUnderstandEnabled].
header disableMustUnderstand.
self shouldnt: [header isMustUnderstandEnabled]
]
]
TestCase subclass: SoapNullDecoderTestCase [
<comment: nil>
<category: 'SOAP-TestCases'>
testDecodeBoolean [
<category: 'testing'>
| dec ret |
dec := SoapNullDecoder new.
ret := dec decodeXmlElement: ((SoapVariable name: 'arg1' value: true)
encoding: #nullEncoding;
asXmlElement).
self should: [ret = true]
]
testDecodeInteger [
<category: 'testing'>
| dec ret |
dec := SoapNullDecoder new.
ret := dec decodeXmlElement: ((SoapVariable name: 'arg1' value: 1234567)
encoding: #nullEncoding;
asXmlElement).
self should: [ret = 1234567]
]
testDecodeObject [
<category: 'testing'>
| dec ret dict |
dec := SoapNullDecoder new.
dict := Dictionary new.
dict at: #Smalltalk put: #Cool.
dict at: #Java put: #Plain.
ret := dec decodeXmlElement: ((SoapVariable name: 'arg1' value: dict)
encoding: #nullEncoding;
asXmlElement).
self should: [ret = dict]
]
testDecodeString [
<category: 'testing'>
| dec ret |
dec := SoapNullDecoder new.
ret := dec
decodeXmlElement: ((SoapVariable name: 'arg1' value: 'Smalltalk')
encoding: #nullEncoding;
asXmlElement).
self should: [ret = 'Smalltalk']
]
]
TestCase subclass: SoapNullEncoderTestCase [
<comment: nil>
<category: 'SOAP-TestCases'>
testEncodingInteger [
<category: 'testing'>
| enc ret |
enc := SoapNullEncoder new.
ret := enc encodeSoapVariable: (SoapVariable name: 'auau' value: 1).
self
should: [(ret getAttributeNamed: 'xsi:type') = 'Null-ENC:SmallInteger'].
self should: [ret value = 1].
ret := enc encodeSoapVariable: (SoapVariable
name: 'auau'
value: 10000000000
type: #Integer).
self should:
[(ret getAttributeNamed: 'xsi:type') = 'Null-ENC:LargePositiveInteger'].
self should: [ret value = 10000000000]
]
testEncodingNil [
<category: 'testing'>
| enc ret |
enc := SoapNullEncoder new.
ret := enc encodeSoapVariable: (SoapVariable name: 'auau' value: nil).
self should: [ret name = 'auau'].
self
should: [(ret getAttributeNamed: 'xsi:type') = 'Null-ENC:UndefinedObject'].
self should: [ret value isNil]
]
testEncodingObject [
<category: 'testing'>
| enc obj ret |
enc := SoapNullEncoder new.
obj := #(1 2 #(#hello 'Smalltalk') 3).
ret := enc encodeSoapVariable: (SoapVariable name: 'auau' value: obj).
self should: [ret name = 'auau'].
self should: [(ret getAttributeNamed: 'xsi:type') = 'Null-ENC:Array'].
self should: [ret value = obj]
]
testEncodingString [
<category: 'testing'>
| enc ret |
enc := SoapNullEncoder new.
ret := enc
encodeSoapVariable: (SoapVariable name: 'auau' value: 'smalltalk').
self should: [(ret getAttributeNamed: 'xsi:type') = 'Null-ENC:String'].
self should: [ret value = 'smalltalk'].
ret := enc encodeSoapVariable: (SoapVariable
name: 'auau'
value: 'ruby'
type: #String).
self should: [(ret getAttributeNamed: 'xsi:type') = 'Null-ENC:String'].
self should: [ret value = 'ruby']
]
]