Skip to content

Commit 06e331d

Browse files
Added test case for XML mode
1 parent 4c5319c commit 06e331d

File tree

4 files changed

+61
-11
lines changed

4 files changed

+61
-11
lines changed

Diff for: activity/soapclient/activity.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ func New(ctx activity.InitContext) (activity.Activity, error) {
3333
return nil, err
3434
}
3535

36-
if s.UseXMLPassThru == false {
36+
if s.XMLMode == false {
3737
// Set attribure prefix for JSON to XML and XML to JSON conversion
3838
// e.g If the prefix is set to '@', <car electric="true">Tesla</car> will be converted to {"car": {"@electric": "true", "#text": "Tesla"}}
39-
mxj.SetAttrPrefix(s.AttributePrefix)
39+
mxj.SetAttrPrefix(s.XMLAttributePrefix)
4040
}
4141

4242
clientPool := updater_http.NewClientPool()
@@ -90,7 +90,7 @@ func New(ctx activity.InitContext) (activity.Activity, error) {
9090
httpAdapter := soap_http.NewClientAdapter(soap_http.ClientPool(clientPool), soap_http.Timeout(time.Duration(s.Timeout)*time.Second))
9191
act := &Activity{settings: s}
9292
act.clientAdapter = httpAdapter
93-
act.xmlPassThroughMode = s.UseXMLPassThru
93+
act.xmlPassThroughMode = s.XMLMode
9494

9595
return act, nil
9696
}

Diff for: activity/soapclient/activity_test.go

+52-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package soapclient
22

33
import (
4+
"strings"
45
"testing"
56

67
"github.com/project-flogo/core/activity"
@@ -25,7 +26,7 @@ func TestSettings(t *testing.T) {
2526
}
2627

2728
func TestSOAPClientActivity(t *testing.T) {
28-
settings := &Settings{SoapServiceEndpoint: "https://www.dataaccess.com/webservicesserver/NumberConversion.wso", SoapVersion: "1.1", AttributePrefix: "@"}
29+
settings := &Settings{SoapServiceEndpoint: "https://www.dataaccess.com/webservicesserver/NumberConversion.wso", SoapVersion: "1.1", XMLAttributePrefix: "@"}
2930
iCtx := test.NewActivityInitContext(settings, nil)
3031
act, _ := New(iCtx)
3132
tc := test.NewActivityContext(act.Metadata())
@@ -51,7 +52,7 @@ func TestSOAPClientActivity(t *testing.T) {
5152
}
5253

5354
func TestSOAPClientActivityFault(t *testing.T) {
54-
settings := &Settings{SoapServiceEndpoint: "http://www.dneonline.com/calculator.asmx", SoapVersion: "1.1", AttributePrefix: "@"}
55+
settings := &Settings{SoapServiceEndpoint: "http://www.dneonline.com/calculator.asmx", SoapVersion: "1.1", XMLAttributePrefix: "@"}
5556
iCtx := test.NewActivityInitContext(settings, nil)
5657
act, _ := New(iCtx)
5758
tc := test.NewActivityContext(act.Metadata())
@@ -71,3 +72,52 @@ func TestSOAPClientActivityFault(t *testing.T) {
7172
assert.True(t, output.IsFault)
7273
assert.NotNil(t, output.SOAPResponseFault)
7374
}
75+
76+
func TestSOAPClientActivityHttpQueryParams(t *testing.T) {
77+
settings := &Settings{SoapServiceEndpoint: "https://www.crcind.com/csp/samples/SOAP.Demo.cls", SoapVersion: "1.1"}
78+
iCtx := test.NewActivityInitContext(settings, nil)
79+
act, _ := New(iCtx)
80+
tc := test.NewActivityContext(act.Metadata())
81+
82+
//setup attrs
83+
input := &Input{HttpQueryParams: map[string]string{"soap_method": "AddInteger", "Arg1": "20", "Arg2": "30"}}
84+
tc.SetInputObject(input)
85+
86+
done, err := act.Eval(tc)
87+
assert.Nil(t, err)
88+
assert.True(t, done)
89+
90+
output := &Output{}
91+
tc.GetOutputObject(output)
92+
assert.NotNil(t, output)
93+
assert.Equal(t, 200, output.HttpStatus)
94+
assert.False(t, output.IsFault)
95+
assert.NotNil(t, output.SOAPResponsePayload)
96+
res, err1 := coerce.ToObject(output.SOAPResponsePayload)
97+
assert.Nil(t, err1)
98+
resObj := res["AddIntegerResponse"].(map[string]interface{})
99+
assert.Equal(t, "50", resObj["AddIntegerResult"])
100+
}
101+
102+
func TestSOAPClientActivityXMLMode(t *testing.T) {
103+
settings := &Settings{SoapServiceEndpoint: "https://www.dataaccess.com/webservicesserver/NumberConversion.wso", SoapVersion: "1.1", XMLMode: true}
104+
iCtx := test.NewActivityInitContext(settings, nil)
105+
act, _ := New(iCtx)
106+
tc := test.NewActivityContext(act.Metadata())
107+
108+
//setup attrs
109+
input := &Input{SoapAction: "NumberToWords", SOAPRequestBody: `<NumberToWords xmlns="http://www.dataaccess.com/webservicesserver/"><ubiNum>100</ubiNum></NumberToWords>`}
110+
tc.SetInputObject(input)
111+
done, err := act.Eval(tc)
112+
assert.Nil(t, err)
113+
assert.True(t, done)
114+
115+
output := &Output{}
116+
tc.GetOutputObject(output)
117+
assert.NotNil(t, output)
118+
assert.Equal(t, 200, output.HttpStatus)
119+
assert.False(t, output.IsFault)
120+
assert.NotNil(t, output.SOAPResponsePayload)
121+
res := strings.Join(strings.Fields(output.SOAPResponsePayload.(string)), " ")
122+
assert.Equal(t, `<m:NumberToWordsResponse xmlns:m="http://www.dataaccess.com/webservicesserver/"> <m:NumberToWordsResult>one hundred </m:NumberToWordsResult> </m:NumberToWordsResponse>`, res)
123+
}

Diff for: activity/soapclient/descriptor.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,18 @@
3333
}
3434
},
3535
{
36-
"name": "xmlPassthroughMode",
36+
"name": "xmlMode",
3737
"type": "boolean",
3838
"description": "When enabled, you must configure input body and headers as XML string. The output will be in XML string format. When disabled, the input and output will be processed as JSON. You can configure JSON schema equivalent of XML data for input and output. This activity will convert JSON to XML behind the scene.",
3939
"value": false,
4040
"display": {
41-
"name": "Use XML Passthrough Mode"
41+
"name": "XML Mode"
4242
}
4343
},
4444
{
45-
"name": "attributePrefix",
45+
"name": "xmlAttributePrefix",
4646
"type": "string",
47-
"description": "Attribute prefix for JSON to XML conversion. Default is '-'. This is only used when XML Passthrough mode is disabled.",
47+
"description": "Attribute prefix for JSON to XML conversion. Default is '-'. This is only used when XML mode is disabled.",
4848
"value": "-",
4949
"display": {
5050
"name": "XML Attribute Prefix"

Diff for: activity/soapclient/metadata.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ type Settings struct {
77
SoapVersion string `md:"soapVersion"` // The address of the proxy server to be use
88
Timeout int `md:"timeout"` // The request timeout in seconds
99
EnableTLS bool `md:"enableTLS"` // Skip SSL validation
10-
AttributePrefix string `md:"attributePrefix"` // The prefix to use for attributes
11-
UseXMLPassThru bool `md:"xmlPassthroughMode"` // Use XML pass-thru
10+
XMLAttributePrefix string `md:"xmlAttributePrefix"` // The prefix to use for XML attributes while converting XML to JSON
11+
XMLMode bool `md:"xmlMode"` // Configure direct XML input/output
1212
ServerCertificate string `md:"serverCertificate"` // The server certificate
1313
ClientCertificate string `md:"clientCertificate"` // The client certificate
1414
ClientKey string `md:"clientKey"` // The client key

0 commit comments

Comments
 (0)