-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathserver-client-rpc-test.js
279 lines (236 loc) · 8.08 KB
/
server-client-rpc-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
// Copyright IBM Corp. 2016,2017. All Rights Reserved.
// Node module: strong-soap
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
"use strict";
var fs = require('fs'),
soap = require('..').soap,
assert = require('assert'),
http = require('http');
describe('RPC style tests', function() {
describe('RPC Literal', function() {
var test = {};
test.server = null;
test.service = {
StockQuoteServiceRPC: {
StockQuotePortRPC: {
setLastTradePrice: function(args, cb, soapHeader) {
if (args.tradePrice) {
var jsonResponse = {"result": true};
return jsonResponse;
}
}
}
}
};
before(function(done) {
fs.readFile(__dirname + '/wsdl/strict/stockquoterpc.wsdl', 'utf8', function(err, data) {
assert.ok(!err);
test.wsdl = data;
done();
});
});
beforeEach(function(done) {
test.server = http.createServer(function(req, res) {
res.statusCode = 404;
res.end();
});
test.server.listen(15099, null, null, function() {
test.soapServer = soap.listen(test.server, '/stockquoterpc', test.service, test.wsdl);
test.baseUrl =
'http://' + test.server.address().address + ":" + test.server.address().port;
//windows return 0.0.0.0 as address and that is not
//valid to use in a request
if (test.server.address().address === '0.0.0.0' || test.server.address().address === '::') {
test.baseUrl =
'http://127.0.0.1:' + test.server.address().port;
}
done();
});
});
afterEach(function(done) {
test.server.close(function() {
test.server = null;
delete test.soapServer;
test.soapServer = null;
done();
});
});
//rpc/literal with complexType input parameters test
//In case of rpc/literal client request has operation name which in this case is 'setLastTradePrice'
//within it is input parameter.
//reference -> https://www.ibm.com/developerworks/library/ws-whichwsdl/#listing4
//client request - body
/*
<soap:Body>
<setLastTradePrice>
<tradePrice>100</tradePrice>
</setLastTradePrice>
</soap:Body>
*/
//response body
//"WS-I's Basic Profile dictates that in the RPC/literal response message, the name of the child
//of soap:body is has wsdl:operation name suffixed with the string 'Response' which in this test case
//is setLastTradePriceResponse" " Reference --> https://www.ibm.com/developerworks/library/ws-whichwsdl/ under
//'SOAP response messages' section.
/*
<soap:Body>
<setLastTradePriceResponse>
<result>true</result>
</setLastTradePriceResponse>
</soap:Body>
*/
it('RPC Literal with ComplexType test', function(done) {
soap.createClient(test.baseUrl + '/stockquoterpc?wsdl', function(err, client) {
assert.ok(!err);
//pass in the input param which in this case is complexType param tradePrice
client.setLastTradePrice( {tradePrice: 100}, function(err, result, body) {
assert.ok(!err);
assert.ok(result.result);
done();
});
});
});
});
describe('RPC Literal', function() {
var test = {};
test.server = null;
test.service = {
RPCLiteralService: {
RpcLiteralTestPort: {
myMethod: function(args, cb, soapHeader) {
}
}
}
};
before(function(done) {
fs.readFile(__dirname + '/wsdl/strict/rpc_literal_test.wsdl', 'utf8', function(err, data) {
assert.ok(!err);
test.wsdl = data;
done();
});
});
beforeEach(function(done) {
test.server = http.createServer(function(req, res) {
res.statusCode = 404;
res.end();
});
test.server.listen(15099, null, null, function() {
test.soapServer = soap.listen(test.server, '/rpc_literal_test', test.service, test.wsdl);
test.baseUrl =
'http://' + test.server.address().address + ":" + test.server.address().port;
//windows return 0.0.0.0 as address and that is not
//valid to use in a request
if (test.server.address().address === '0.0.0.0' || test.server.address().address === '::') {
test.baseUrl =
'http://127.0.0.1:' + test.server.address().port;
}
done();
});
});
afterEach(function(done) {
test.server.close(function() {
test.server = null;
delete test.soapServer;
test.soapServer = null;
done();
});
});
//rpc/literal with simpleType parameters test
/* In case of rpc/literal client request is wrapped with operation name which in this case is 'myMethod'
//see https://www.ibm.com/developerworks/library/ws-whichwsdl/#listing4
<soap:Body>
<myMethod>
<x>100</x>
<y>10.55</y>
</myMethod>
</soap:Body>
server response
//body="" since this is a one-way request
//result (output param inside the body) is null
*/
it('RPC/Literal Simple type test', function(done) {
soap.createClient(test.baseUrl + '/rpc_literal_test?wsdl', function(err, client) {
assert.ok(!err);
//see wsdl. input message has 2 parts = x=int and y=float which gets passed to client method as params.
client.myMethod( {x: 100, y: 10.55}, function(err, result, body) {
assert.ok(!err);
assert.ok(!result);
done();
});
});
});
});
describe('SOAP Server', function() {
var test = {};
test.server = null;
test.service = {
RPCEncodedService: {
RpcEncodedTestPort: {
myMethod: function(args, cb, soapHeader) {
}
}
}
};
before(function(done) {
fs.readFile(__dirname + '/wsdl/strict/rpc_encoded_test.wsdl', 'utf8', function(err, data) {
assert.ok(!err);
test.wsdl = data;
done();
});
});
beforeEach(function(done) {
test.server = http.createServer(function(req, res) {
res.statusCode = 404;
res.end();
});
test.server.listen(15099, null, null, function() {
test.soapServer = soap.listen(test.server, '/rpc_encoded_test', test.service, test.wsdl);
test.baseUrl =
'http://' + test.server.address().address + ":" + test.server.address().port;
//windows return 0.0.0.0 as address and that is not
//valid to use in a request
if (test.server.address().address === '0.0.0.0' || test.server.address().address === '::') {
test.baseUrl =
'http://127.0.0.1:' + test.server.address().port;
}
done();
});
});
afterEach(function(done) {
test.server.close(function() {
test.server = null;
delete test.soapServer;
test.soapServer = null;
done();
});
});
//RPC/encoded is not supported by the code currently. Revisit and fix the code to enable this test, when time permits.
//What's missing is, in the request/response current code doesn't add xsi:type to x and y parameters in below request.
//There is code already to determine if the binding is RPC/encoded.
//rpc/encoded with simpleType parameters test
/* Expected client request envelope
//reference https://www.ibm.com/developerworks/library/ws-whichwsdl/#listing2
<soap:Body>
<myMethod>
<x xsi:type="xsd:int">100</x>
<y xsi:type="xsd:float">10.55</y>
</myMethod>
</soap:Body>
server response
//body="" since this is a one-way request
//result (data inside the body) is null
*/
it.skip('RPC/Encoded style test', function(done) {
soap.createClient(test.baseUrl + '/rpc_encoded_test?wsdl', function(err, client) {
assert.ok(!err);
//see wsdl. input message has 2 parts = x=int and y=float. Pass them as params.
client.myMethod( {x: 100, y: 10.55}, function(err, result, body) {
assert.ok(!err);
assert.ok(!result);
done();
});
});
});
});
});