Skip to content

Commit 18698c4

Browse files
authoredSep 14, 2016
Merge pull request #10 from strongloop/new-tests
Fixed support for imported wsdl scenario & converted wsdl-test.js to mocha test
2 parents 76bf683 + 1ded3f7 commit 18698c4

File tree

2 files changed

+113
-114
lines changed

2 files changed

+113
-114
lines changed
 

‎src/parser/wsdl/definitions.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ class Definitions extends WSDLElement {
2828
self.messages[child.$name] = child;
2929
}
3030
else if (child.name === 'import') {
31-
self.schemas[child.$namespace] = new Schema(child.$namespace, {});
31+
//create a Schema element for the <import ../>. targetNamespace is the 'namespace' of the <import /> element in the wsdl.
32+
self.schemas[child.$namespace] = new Schema('xs:schema',{targetNamespace: child.$namespace});
3233
self.schemas[child.$namespace].addChild(child);
3334
}
3435
else if (child instanceof PortType) {

‎test/wsdl-test.js

+111-113
Original file line numberDiff line numberDiff line change
@@ -3,133 +3,131 @@
33
var fs = require('fs'),
44
soap = require('..').soap,
55
assert = require('assert'),
6-
should = require('should');
6+
should = require('should'),
7+
request = require('request'),
8+
http = require('http');
79

8-
var wsdlStrictTests = {},
9-
wsdlNonStrictTests = {};
10+
describe('wsdl-tests', function() {
1011

11-
fs.readdirSync(__dirname+'/wsdl/strict').forEach(function(file) {
12-
if (!/.wsdl$/.exec(file)) return;
13-
wsdlStrictTests['should parse and describe '+file] = function(done) {
14-
soap.createClient(__dirname+'/wsdl/strict/'+file, {strict: true}, function(err, client) {
15-
assert.ok(!err);
16-
client.describe();
12+
describe('wsdl parsing test cases', function () {
13+
14+
it('should parse and describe - 1 set of wsdls', function (done) {
15+
fs.readdirSync(__dirname+'/wsdl/strict').forEach(function(file) {
16+
if (!/.wsdl$/.exec(file)) return;
17+
soap.createClient(__dirname+'/wsdl/strict/'+file, {strict: true}, function(err, client) {
18+
assert.ok(!err);
19+
client.describe();
20+
});
21+
});
1722
done();
1823
});
19-
};
20-
});
2124

22-
fs.readdirSync(__dirname+'/wsdl').forEach(function(file) {
23-
if (!/.wsdl$/.exec(file)) return;
24-
wsdlNonStrictTests['should parse and describe '+file] = function(done) {
25-
soap.createClient(__dirname+'/wsdl/'+file, function(err, client) {
26-
assert.ok(!err);
27-
client.describe();
25+
26+
it('should parse and describe - 2nd set of wsdls', function (done) {
27+
fs.readdirSync(__dirname+'/wsdl').forEach(function(file) {
28+
if (!/.wsdl$/.exec(file)) return;
29+
soap.createClient(__dirname+'/wsdl/'+file, function(err, client) {
30+
assert.ok(!err);
31+
client.describe();
32+
});
33+
});
2834
done();
2935
});
30-
};
31-
});
3236

33-
wsdlNonStrictTests['should not parse connection error'] = function(done) {
34-
soap.createClient(__dirname+'/wsdl/connection/econnrefused.wsdl', function(err, client) {
35-
assert.ok(/EADDRNOTAVAIL|ECONNREFUSED/.test(err), err);
36-
done();
37-
});
38-
};
37+
it('should not parse connection error', function (done) {
38+
soap.createClient(__dirname+'/wsdl/connection/econnrefused.wsdl', function(err, client) {
39+
assert.ok(/EADDRNOTAVAIL|ECONNREFUSED/.test(err), err);
40+
done();
41+
});
42+
});
3943

40-
wsdlNonStrictTests['should catch parse error'] = function(done) {
41-
soap.createClient(__dirname+'/wsdl/bad.txt', function(err) {
42-
assert.notEqual(err, null);
43-
done();
44-
});
45-
};
44+
it('should catch parse error', function (done) {
45+
soap.createClient(__dirname+'/wsdl/bad.txt', function(err) {
46+
assert.notEqual(err, null);
47+
done();
48+
});
49+
});
4650

47-
wsdlStrictTests['should catch parse error'] = function(done) {
48-
soap.createClient(__dirname+'/wsdl/bad.txt', {strict: true}, function(err) {
49-
assert.notEqual(err, null);
50-
done();
51-
});
52-
};
53-
54-
wsdlStrictTests['should parse external wsdl'] = function(done) {
55-
soap.createClient(__dirname+'/wsdl/wsdlImport/main.wsdl', {strict: true}, function(err, client){
56-
assert.ok(!err);
57-
assert.deepEqual(Object.keys(client.wsdl.definitions.schemas),
58-
['http://example.com/', 'http://schemas.microsoft.com/2003/10/Serialization/Arrays']);
59-
assert.equal(typeof client.getLatestVersion, 'function');
60-
done();
61-
});
62-
};
63-
64-
wsdlStrictTests['should get the parent namespace when parent namespace is empty string'] = function(done) {
65-
soap.createClient(__dirname+'/wsdl/marketo.wsdl', {strict: true}, function(err, client){
66-
assert.ok(!err);
67-
client.getLeadChanges({
68-
batchSize: 1,
69-
startPosition: {activityCreatedAt: '2014-04-14T22:03:48.587Z'},
70-
activityNameFilter: {stringItem: ['Send Email']}
71-
}, function() {
51+
52+
it('should parse external wsdl', function (done) {
53+
soap.createClient(__dirname+'/wsdl/wsdlImport/main.wsdl', {strict: true}, function(err, client){
54+
assert.ok(!err);
55+
assert.deepEqual(Object.keys(client.wsdl.definitions.schemas),
56+
['http://example.com/', 'http://schemas.microsoft.com/2003/10/Serialization/Arrays']);
57+
assert.equal(typeof client.getLatestVersion, 'function');
7258
done();
7359
});
74-
});
75-
};
76-
77-
wsdlStrictTests['should handle element ref'] = function(done) {
78-
var expectedMsg = '<ns1:fooRq xmlns:ns1="http://example.com/bar/xsd"' +
79-
' xmlns="http://example.com/bar/xsd"><bar1:paymentRq' +
80-
' xmlns:bar1="http://example.com/bar1/xsd">' +
81-
'<bar1:bankSvcRq>' +
82-
'<bar1:requestUID>001</bar1:requestUID></bar1:bankSvcRq>' +
83-
'</bar1:paymentRq></ns1:fooRq>';
84-
soap.createClient(__dirname + '/wsdl/elementref/foo.wsdl', {strict: true}, function(err, client) {
85-
assert.ok(!err);
86-
client.fooOp({paymentRq: {bankSvcRq: {requestUID: '001'}}}, function(err, result) {
87-
assert.equal(client.lastMessage, expectedMsg);
88-
done();
8960
});
90-
});
91-
};
92-
93-
wsdlStrictTests['should handle type ref'] = function(done) {
94-
var expectedMsg = require('./wsdl/typeref/request.xml.js');
95-
var reqJson = require('./wsdl/typeref/request.json');
96-
soap.createClient(__dirname + '/wsdl/typeref/order.wsdl', {strict: true}, function(err, client) {
97-
assert.ok(!err);
98-
client.order(reqJson, function(err, result) {
99-
assert.equal(client.lastMessage, expectedMsg);
100-
done();
61+
62+
it('should get the parent namespace when parent namespace is empty string', function (done) {
63+
soap.createClient(__dirname+'/wsdl/marketo.wsdl', {strict: true}, function(err, client){
64+
assert.ok(!err);
65+
client.getLeadChanges({
66+
batchSize: 1,
67+
startPosition: {activityCreatedAt: '2014-04-14T22:03:48.587Z'},
68+
activityNameFilter: {stringItem: ['Send Email']}
69+
}, function() {
70+
done();
71+
});
72+
});
10173
});
102-
});
103-
};
104-
105-
wsdlStrictTests['should get empty namespace prefix'] = function(done) {
106-
var expectedMsg = '<ns1:fooRq xmlns:ns1="http://example.com/bar/xsd"' +
107-
' xmlns="http://example.com/bar/xsd"><bar1:paymentRq' +
108-
' xmlns:bar1="http://example.com/bar1/xsd">' +
109-
'<bar1:bankSvcRq>' +
110-
'<requestUID>001</requestUID></bar1:bankSvcRq>' +
111-
'</bar1:paymentRq></ns1:fooRq>';
112-
// var expectedMsg = 'gg';
113-
114-
soap.createClient(__dirname + '/wsdl/elementref/foo.wsdl', {strict: true}, function(err, client) {
115-
assert.ok(!err);
116-
client.fooOp({paymentRq: {bankSvcRq: {':requestUID': '001'}}}, function(err, result) {
117-
assert.equal(client.lastMessage, expectedMsg);
118-
done();
74+
75+
it('should handle element ref', function (done) {
76+
var expectedMsg = '<ns1:fooRq xmlns:ns1="http://example.com/bar/xsd"' +
77+
' xmlns="http://example.com/bar/xsd"><bar1:paymentRq' +
78+
' xmlns:bar1="http://example.com/bar1/xsd">' +
79+
'<bar1:bankSvcRq>' +
80+
'<bar1:requestUID>001</bar1:requestUID></bar1:bankSvcRq>' +
81+
'</bar1:paymentRq></ns1:fooRq>';
82+
soap.createClient(__dirname + '/wsdl/elementref/foo.wsdl', {strict: true}, function(err, client) {
83+
assert.ok(!err);
84+
client.fooOp({paymentRq: {bankSvcRq: {requestUID: '001'}}}, function(err, result) {
85+
assert.equal(client.lastMessage, expectedMsg);
86+
done();
87+
});
88+
});
11989
});
90+
91+
it('should handle type ref', function (done) {
92+
var expectedMsg = require('./wsdl/typeref/request.xml.js');
93+
var reqJson = require('./wsdl/typeref/request.json');
94+
soap.createClient(__dirname + '/wsdl/typeref/order.wsdl', {strict: true}, function(err, client) {
95+
assert.ok(!err);
96+
client.order(reqJson, function(err, result) {
97+
assert.equal(client.lastMessage, expectedMsg);
98+
done();
99+
});
100+
});
101+
});
102+
103+
it('should get empty namespace prefix', function (done) {
104+
var expectedMsg = '<ns1:fooRq xmlns:ns1="http://example.com/bar/xsd"' +
105+
' xmlns="http://example.com/bar/xsd"><bar1:paymentRq' +
106+
' xmlns:bar1="http://example.com/bar1/xsd">' +
107+
'<bar1:bankSvcRq>' +
108+
'<requestUID>001</requestUID></bar1:bankSvcRq>' +
109+
'</bar1:paymentRq></ns1:fooRq>';
110+
// var expectedMsg = 'gg';
111+
112+
soap.createClient(__dirname + '/wsdl/elementref/foo.wsdl', {strict: true}, function(err, client) {
113+
assert.ok(!err);
114+
client.fooOp({paymentRq: {bankSvcRq: {':requestUID': '001'}}}, function(err, result) {
115+
assert.equal(client.lastMessage, expectedMsg);
116+
done();
117+
});
118+
});
119+
});
120+
121+
122+
it('should load same namespace from included xsd', function (done) {
123+
var expected = '{"DummyService":{"DummyPortType":{"Dummy":{"input":{"ID":"IdType|xs:string|pattern","Name":"NameType|xs:string|minLength,maxLength"},"output":{"Result":"dummy:DummyList"}}}}}';
124+
soap.createClient(__dirname + '/wsdl/xsdinclude/xsd_include.wsdl', function(err, client) {
125+
assert.ok(!err);
126+
assert.equal(JSON.stringify(client.describe()), expected);
127+
done();
128+
});
129+
});
130+
120131
});
121-
};
122-
123-
wsdlNonStrictTests['should load same namespace from included xsd'] = function(done) {
124-
var expected = '{"DummyService":{"DummyPortType":{"Dummy":{"input":{"ID":"IdType|xs:string|pattern","Name":"NameType|xs:string|minLength,maxLength"},"output":{"Result":"dummy:DummyList"}}}}}';
125-
soap.createClient(__dirname + '/wsdl/xsdinclude/xsd_include.wsdl', function(err, client) {
126-
assert.ok(!err);
127-
assert.equal(JSON.stringify(client.describe()), expected);
128-
done();
129-
});
130-
};
132+
});
131133

132-
module.exports = {
133-
'WSDL Parser (strict)': wsdlStrictTests,
134-
'WSDL Parser (non-strict)': wsdlNonStrictTests
135-
};

0 commit comments

Comments
 (0)
Please sign in to comment.