(() => {
'use strict';
var Wsdlrdr = require('../src/index.js');
const wsdlUrls = [{
host: 'soaptest.parasoft.com',
wsdl: '/calculator.wsdl'
}, {
host: 'webservices.oorsprong.org',
wsdl: '/websamples.countryinfo/CountryInfoService.wso?WSDL'
}, {
host: 'webservices.daehosting.com',
wsdl: '/services/isbnservice.wso?WSDL'
}, {
host: 'www.dataaccess.com',
wsdl: '/webservicesserver/numberconversion.wso?WSDL'
}, {
host: 'webservices.optimalpayments.com',
wsdl: '/ilsWS/IlsService/v1?wsdl'
}, {
host: 'svn.apache.org',
wsdl: '/repos/asf/airavata/sandbox/xbaya-web/test/Calculator.wsdl'
}, {
host: 'www.pegelonline.wsv.de',
wsdl: '/webservices/version2_4/2009/05/12/PegelonlineWebservice?WSDL'
}];
const wsdlOpts = {
'svn.apache.org': {
failOnWrongContentType: false
}
};
const wsdlFunctions = [];
var test = require('tape');
test('notExistsingWsdlUrl', async (t) => {
try {
await Wsdlrdr.getAllFunctions({
host: 'www.notexist.com',
wsdl: '/wsdl'
});
t.end('has response');
} catch (err) {
t.ok(err, 'wsdl not exists');
t.end();
}
});
test('getNamespaces', async (t) => {
try {
for (let wsdlParams of wsdlUrls) {
t.comment(`=> ${wsdlParams.host}`);
let data = await Wsdlrdr.getNamespaces(wsdlParams, wsdlOpts[wsdlParams.host]);
t.ok(data.length !== 0, `${wsdlParams.host} has ${data.length} namespaces`);
}
t.end();
} catch (err) {
console.trace(err);
t.end(err);
}
});
test('getAllFunctions', async (t) => {
try {
for (let wsdlParams of wsdlUrls) {
t.comment(`=> ${wsdlParams.host}`);
let data = await Wsdlrdr.getAllFunctions(wsdlParams, wsdlOpts[wsdlParams.host]);
t.ok(data.length !== 0, `${wsdlParams.host} has ${data.length} functions`);
// save found functions
wsdlFunctions[wsdlParams.host] = data;
}
t.end();
} catch (err) {
console.trace(err);
t.end(err);
}
});
test('getMethodParamsByName', async (t) => {
try {
for (let wsdlParams of wsdlUrls) {
for (let methodName of wsdlFunctions[wsdlParams.host]) {
let methodParams = await Wsdlrdr.getMethodParamsByName(methodName, wsdlParams, wsdlOpts[wsdlParams.host]);
t.ok(methodParams, `could get params from method "${methodName}"`);
t.ok(methodParams.response, `response available`);
t.ok(methodParams.response.find((responseItem) => responseItem.name === 'parameters'), 'got response parameters');
t.ok(methodParams.request, `request available`);
t.ok(methodParams.request.find((requestItem) => requestItem.name === 'parameters'), 'got request parameters');
for (let responseItem of methodParams.response) {
t.ok(responseItem.params, 'got response params');
}
for (let requestItem of methodParams.request) {
t.ok(requestItem.params, 'got request params');
}
}
}
t.end();
} catch (err) {
console.trace(err);
t.end(err);
}
});
test('getMethodParamsByName.givenMethodNotExists', async (t) => {
try {
var wsdlParams = wsdlUrls[0];
if (!wsdlParams) {
t.end('no wsdlParams');
}
await Wsdlrdr.getMethodParamsByName('notAvailableMethodName', wsdlParams);
t.end('has found method');
} catch (err) {
t.ok(err, 'not found method');
t.end();
}
});
test('getXmlDataAsJson', (t) => {
t.plan(2);
var responseXml = `
123
234
`;
var dataAsJson = Wsdlrdr.getXmlDataAsJson(responseXml);
if (dataAsJson.testResponseItem1) t.pass('testResponseItem1 is available');
if (dataAsJson.testResponseItem2) t.pass('testResponseItem2 is available');
});
test('getXmlDataAsJson.noBody', (t) => {
var xml = `
Leipzig-Schkeuditz, Germany (EDDP) 51-25N 012-14E 149M
from the SE (140 degrees) at 6 MPH (5 KT):0
greater than 7 mile(s):0
mostly cloudy
62 F (17 C)
62 F (17 C)
100%
29.85 in. Hg (1011 hPa)
Success
`;
var dataAsJson = Wsdlrdr.getXmlDataAsJson(xml);
t.ok(dataAsJson.CurrentWeather.length !== 0, 'data available');
t.end();
});
test('getXmlDataAsJson.array', (t) => {
var responseXml = `
header-data1
header-data2
header-data3
1
2
3
`;
var dataAsJson = Wsdlrdr.getXmlDataAsJson(responseXml);
t.ok(dataAsJson.getDataTypeResponse, 'getDataTypeResponse is available');
t.ok(dataAsJson.getDataTypeResponse.testParam2.length === 2, 'testParam2 got 2 items');
t.end();
});
test('getXmlDataAsJson.withAttrValue', (t) => {
t.plan(1);
var responseXml = `
`;
var dataAsJson = Wsdlrdr.getXmlDataAsJson(responseXml);
if (dataAsJson.getDataTypeResponse) t.pass('getDataTypeResponse is available');
});
test('getXmlDataAsJson.withAttrInTopTag', (t) => {
var responseXml = `
`;
var dataAsJson = Wsdlrdr.getXmlDataAsJson(responseXml);
t.ok(dataAsJson.topLevelTag, 'topLevelTag is available');
t.ok(dataAsJson.topLevelTag.attribute1, 'topLevelTag.attribute1 is available');
t.ok(dataAsJson.topLevelTag.attribute2, 'topLevelTag.attribute2 is available');
t.ok(dataAsJson.topLevelTag.lowerLevelTag, 'lowerLevelTag is available');
t.ok(dataAsJson.topLevelTag.lowerLevelTag.attribute1, 'lowerLevelTag.attribute1 is available');
t.ok(dataAsJson.topLevelTag.lowerLevelTag.attribute2, 'lowerLevelTag.attribute2 is available');
t.end();
});
})();