UNPKG

@itentialopensource/adapter-nokia_nsp_device_configurator

Version:

This adapter integrates with system described as: 22.11Modeled-deviceConfiguratorRestconfApis.

1,122 lines (1,055 loc) 40.2 kB
/* @copyright Itential, LLC 2019 (pre-modifications) */ // Set globals /* global describe it log pronghornProps */ /* eslint no-unused-vars: warn */ /* eslint no-underscore-dangle: warn */ /* eslint import/no-dynamic-require:warn */ // include required items for testing & logging const assert = require('assert'); const fs = require('fs'); const path = require('path'); const util = require('util'); const mocha = require('mocha'); const winston = require('winston'); const { expect } = require('chai'); const { use } = require('chai'); const td = require('testdouble'); const log = require('../../utils/logger'); const anything = td.matchers.anything(); // stub and attemptTimeout are used throughout the code so set them here const isRapidFail = false; const isSaveMockData = false; // read in the properties from the sampleProperties files let adaptdir = __dirname; if (adaptdir.endsWith('/test/integration')) { adaptdir = adaptdir.substring(0, adaptdir.length - 17); } else if (adaptdir.endsWith('/test/unit')) { adaptdir = adaptdir.substring(0, adaptdir.length - 10); } const samProps = require(`${adaptdir}/sampleProperties.json`).properties; // these variables can be changed to run in integrated mode so easier to set them here // always check these in with bogus data!!! samProps.stub = true; // uncomment if connecting // samProps.host = 'replace.hostorip.here'; // samProps.authentication.username = 'username'; // samProps.authentication.password = 'password'; // samProps.authentication.token = 'password'; // samProps.protocol = 'http'; // samProps.port = 80; // samProps.ssl.enabled = false; // samProps.ssl.accept_invalid_cert = false; if (samProps.request.attempt_timeout < 30000) { samProps.request.attempt_timeout = 30000; } samProps.devicebroker.enabled = true; const attemptTimeout = samProps.request.attempt_timeout; const { stub } = samProps; // these are the adapter properties. You generally should not need to alter // any of these after they are initially set up global.pronghornProps = { pathProps: { encrypted: false }, adapterProps: { adapters: [{ id: 'Test-nokia_nsp_device_configurator', type: 'NokiaNspDeviceConfigurator', properties: samProps }] } }; global.$HOME = `${__dirname}/../..`; /** * Runs the common asserts for test */ function runCommonAsserts(data, error) { assert.equal(undefined, error); assert.notEqual(undefined, data); assert.notEqual(null, data); assert.notEqual(undefined, data.response); assert.notEqual(null, data.response); } /** * Runs the error asserts for the test */ function runErrorAsserts(data, error, code, origin, displayStr) { assert.equal(null, data); assert.notEqual(undefined, error); assert.notEqual(null, error); assert.notEqual(undefined, error.IAPerror); assert.notEqual(null, error.IAPerror); assert.notEqual(undefined, error.IAPerror.displayString); assert.notEqual(null, error.IAPerror.displayString); assert.equal(code, error.icode); assert.equal(origin, error.IAPerror.origin); assert.equal(displayStr, error.IAPerror.displayString); } /** * @function saveMockData * Attempts to take data from responses and place them in MockDataFiles to help create Mockdata. * Note, this was built based on entity file structure for Adapter-Engine 1.6.x * @param {string} entityName - Name of the entity saving mock data for * @param {string} actionName - Name of the action saving mock data for * @param {string} descriptor - Something to describe this test (used as a type) * @param {string or object} responseData - The data to put in the mock file. */ function saveMockData(entityName, actionName, descriptor, responseData) { // do not need to save mockdata if we are running in stub mode (already has mock data) or if told not to save if (stub || !isSaveMockData) { return false; } // must have a response in order to store the response if (responseData && responseData.response) { let data = responseData.response; // if there was a raw response that one is better as it is untranslated if (responseData.raw) { data = responseData.raw; try { const temp = JSON.parse(data); data = temp; } catch (pex) { // do not care if it did not parse as we will just use data } } try { const base = path.join(__dirname, `../../entities/${entityName}/`); const mockdatafolder = 'mockdatafiles'; const filename = `mockdatafiles/${actionName}-${descriptor}.json`; if (!fs.existsSync(base + mockdatafolder)) { fs.mkdirSync(base + mockdatafolder); } // write the data we retrieved fs.writeFile(base + filename, JSON.stringify(data, null, 2), 'utf8', (errWritingMock) => { if (errWritingMock) throw errWritingMock; // update the action file to reflect the changes. Note: We're replacing the default object for now! fs.readFile(`${base}action.json`, (errRead, content) => { if (errRead) throw errRead; // parse the action file into JSON const parsedJson = JSON.parse(content); // The object update we'll write in. const responseObj = { type: descriptor, key: '', mockFile: filename }; // get the object for method we're trying to change. const currentMethodAction = parsedJson.actions.find((obj) => obj.name === actionName); // if the method was not found - should never happen but... if (!currentMethodAction) { throw Error('Can\'t find an action for this method in the provided entity.'); } // if there is a response object, we want to replace the Response object. Otherwise we'll create one. const actionResponseObj = currentMethodAction.responseObjects.find((obj) => obj.type === descriptor); // Add the action responseObj back into the array of response objects. if (!actionResponseObj) { // if there is a default response object, we want to get the key. const defaultResponseObj = currentMethodAction.responseObjects.find((obj) => obj.type === 'default'); // save the default key into the new response object if (defaultResponseObj) { responseObj.key = defaultResponseObj.key; } // save the new response object currentMethodAction.responseObjects = [responseObj]; } else { // update the location of the mock data file actionResponseObj.mockFile = responseObj.mockFile; } // Save results fs.writeFile(`${base}action.json`, JSON.stringify(parsedJson, null, 2), (err) => { if (err) throw err; }); }); }); } catch (e) { log.debug(`Failed to save mock data for ${actionName}. ${e.message}`); return false; } } // no response to save log.debug(`No data passed to save into mockdata for ${actionName}`); return false; } // require the adapter that we are going to be using const NokiaNspDeviceConfigurator = require('../../adapter'); // begin the testing - these should be pretty well defined between the describe and the it! describe('[integration] Nokia_nsp_device_configurator Adapter Test', () => { describe('NokiaNspDeviceConfigurator Class Tests', () => { const a = new NokiaNspDeviceConfigurator( pronghornProps.adapterProps.adapters[0].id, pronghornProps.adapterProps.adapters[0].properties ); if (isRapidFail) { const state = {}; state.passed = true; mocha.afterEach(function x() { state.passed = state.passed && (this.currentTest.state === 'passed'); }); mocha.beforeEach(function x() { if (!state.passed) { return this.currentTest.skip(); } return true; }); } describe('#class instance created', () => { it('should be a class with properties', (done) => { try { assert.notEqual(null, a); assert.notEqual(undefined, a); const checkId = global.pronghornProps.adapterProps.adapters[0].id; assert.equal(checkId, a.id); assert.notEqual(null, a.allProps); const check = global.pronghornProps.adapterProps.adapters[0].properties.healthcheck.type; assert.equal(check, a.healthcheckType); done(); } catch (error) { log.error(`Test Failure: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#connect', () => { it('should get connected - no healthcheck', (done) => { try { a.healthcheckType = 'none'; a.connect(); try { assert.equal(true, a.alive); done(); } catch (error) { log.error(`Test Failure: ${error}`); done(error); } } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }); it('should get connected - startup healthcheck', (done) => { try { a.healthcheckType = 'startup'; a.connect(); try { assert.equal(true, a.alive); done(); } catch (error) { log.error(`Test Failure: ${error}`); done(error); } } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }); }); describe('#healthCheck', () => { it('should be healthy', (done) => { try { a.healthCheck(null, (data) => { try { assert.equal(true, a.healthy); saveMockData('system', 'healthcheck', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); // broker tests describe('#getDevicesFiltered - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { const opts = { filter: { name: 'deviceName' } }; a.getDevicesFiltered(opts, (data, error) => { try { if (stub) { if (samProps.devicebroker.getDevicesFiltered[0].handleFailure === 'ignore') { assert.equal(null, error); assert.notEqual(undefined, data); assert.notEqual(null, data); assert.equal(0, data.total); assert.equal(0, data.list.length); } else { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-nokia_nsp_device_configurator-connectorRest-handleEndResponse', displayE); } } else { runCommonAsserts(data, error); } done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#iapGetDeviceCount - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { const opts = { filter: { name: 'deviceName' } }; a.iapGetDeviceCount((data, error) => { try { if (stub) { if (samProps.devicebroker.getDevicesFiltered[0].handleFailure === 'ignore') { assert.equal(null, error); assert.notEqual(undefined, data); assert.notEqual(null, data); assert.equal(0, data.count); } else { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-nokia_nsp_device_configurator-connectorRest-handleEndResponse', displayE); } } else { runCommonAsserts(data, error); } done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); // exposed cache tests describe('#iapPopulateEntityCache - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.iapPopulateEntityCache('Device', (data, error) => { try { if (stub) { assert.equal(null, data); assert.notEqual(undefined, error); assert.notEqual(null, error); done(); } else { assert.equal(undefined, error); assert.equal('success', data[0]); done(); } } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#iapRetrieveEntitiesCache - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.iapRetrieveEntitiesCache('Device', {}, (data, error) => { try { if (stub) { assert.equal(null, data); assert.notEqual(null, error); assert.notEqual(undefined, error); } else { assert.equal(undefined, error); assert.notEqual(null, data); assert.notEqual(undefined, data); } done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); /* ----------------------------------------------------------------------- ----------------------------------------------------------------------- *** All code above this comment will be replaced during a migration *** ******************* DO NOT REMOVE THIS COMMENT BLOCK ****************** ----------------------------------------------------------------------- ----------------------------------------------------------------------- */ const getBearerTokenGetAuthBearerTokenBodyParam = { grant_type: 'client_credentials' }; describe('#getAuthBearerToken - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.getAuthBearerToken(getBearerTokenGetAuthBearerTokenBodyParam, (data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal('VEtOLWFkbWluYjcxY2RiMzMtYWZkMS00ZGY2LWFlMDktMDBiNmQ5OTYwNGQ5', data.response.access_token); assert.equal('UkVUS04tYWRtaW41M2I3YWUwOS1iYzRlLTQ2N2UtOWEwYy0wMDljOTc0YjQ2YWY=', data.response.refresh_token); assert.equal('Bearer', data.response.token_type); assert.equal(3600, data.response.expires_in); } else { runCommonAsserts(data, error); } saveMockData('GetBearerToken', 'getAuthBearerToken', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#gettheRESTCONFRoot - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.gettheRESTCONFRoot((data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal(true, Array.isArray(data.response.links)); } else { runCommonAsserts(data, error); } saveMockData('BasicRESTCONFFlow', 'gettheRESTCONFRoot', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#getthedatastore - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.getthedatastore((data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal('object', typeof data.response['ietf-restconf:restconf']); } else { runCommonAsserts(data, error); } saveMockData('BasicRESTCONFFlow', 'getthedatastore', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#gettheyangLibrary - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.gettheyangLibrary((data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal('object', typeof data.response['ietf-yang-library:yang-library']); } else { runCommonAsserts(data, error); } saveMockData('BasicRESTCONFFlow', 'gettheyangLibrary', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#gettheschemamounts - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.gettheschemamounts((data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal('object', typeof data.response['ietf-yang-schema-mounts:schema-mounts']); } else { runCommonAsserts(data, error); } saveMockData('BasicRESTCONFFlow', 'gettheschemamounts', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#getallthenetworkdevices - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.getallthenetworkdevices((data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal('object', typeof data.response['network-device-mgr:network-devices']); } else { runCommonAsserts(data, error); } saveMockData('BasicRESTCONFFlow', 'getallthenetworkdevices', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const basicRESTCONFFlowNeId = 'fakedata'; describe('#getagivennetworkdevice - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.getagivennetworkdevice(basicRESTCONFFlowNeId, (data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal(true, Array.isArray(data.response['network-device-mgr:network-device'])); } else { runCommonAsserts(data, error); } saveMockData('BasicRESTCONFFlow', 'getagivennetworkdevice', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const createConfigureAndDeleteNeId = 'fakedata'; const createConfigureAndDeleteCardId = 'fakedata'; const createConfigureAndDeleteCreateMDABodyParam = { 'nokia-conf:mda': [ { 'mda-slot': 1, 'mda-type': 'imm24-1gb-xp-tx' } ] }; describe('#createMDA - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.createMDA(createConfigureAndDeleteNeId, createConfigureAndDeleteCardId, createConfigureAndDeleteCreateMDABodyParam, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-nokia_nsp_device_configurator-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('CreateConfigureAndDelete', 'createMDA', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const createConfigureAndDeleteMdaId = 'fakedata'; const createConfigureAndDeleteConfigureMDABodyParam = { 'nokia-conf:slot': [ { 'mda-slot': 1, 'mda-type': 'imm24-1gb-xp-tx', 'fail-on-error': false } ] }; describe('#configureMDA - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.configureMDA(createConfigureAndDeleteNeId, createConfigureAndDeleteCardId, createConfigureAndDeleteMdaId, createConfigureAndDeleteConfigureMDABodyParam, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-nokia_nsp_device_configurator-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('CreateConfigureAndDelete', 'configureMDA', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const plainPatchNeId = 'fakedata'; const plainPatchRouter = 'fakedata'; const plainPatchPatchMultipleinterfacesBodyParam = { 'nokia-conf:router': [ { 'router-name': 'Base', interface: [ { 'interface-name': 'plain_patch_1', ipv4: { primary: { 'prefix-length': 28 } } }, { 'interface-name': 'plain_patch_2', ipv4: { primary: { 'prefix-length': 29 } } } ] } ] }; describe('#patchMultipleinterfaces - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.patchMultipleinterfaces(plainPatchNeId, plainPatchRouter, plainPatchPatchMultipleinterfacesBodyParam, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-nokia_nsp_device_configurator-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('PlainPatch', 'patchMultipleinterfaces', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#verifyyangDataJsoninAcceptPatchheader - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.verifyyangDataJsoninAcceptPatchheader(plainPatchNeId, plainPatchRouter, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-nokia_nsp_device_configurator-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('PlainPatch', 'verifyyangDataJsoninAcceptPatchheader', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#getthelistofinterfaces - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.getthelistofinterfaces(plainPatchNeId, plainPatchRouter, (data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal(true, Array.isArray(data.response['nokia-conf:interface'])); } else { runCommonAsserts(data, error); } saveMockData('PlainPatch', 'getthelistofinterfaces', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const plainPatchInterfaceParam = 'fakedata'; const plainPatchCreateInterfaceBodyParam = { 'nokia-conf:interface': [ { 'interface-name': 'plain_patch_1', description: 'To be modified by plain patch', ipv4: { primary: { address: '10.18.1.1', 'prefix-length': 24 } } } ] }; describe('#createInterface - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.createInterface(plainPatchNeId, plainPatchRouter, plainPatchInterfaceParam, plainPatchCreateInterfaceBodyParam, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-nokia_nsp_device_configurator-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('PlainPatch', 'createInterface', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const patchForLeafTypeEmptyJneId = 'fakedata'; const patchForLeafTypeEmptyInterfaceParam = 'fakedata'; const patchForLeafTypeEmptyAddEmptytypeBodyParam = { 'configuration:interface': [ { name: 'ge-1/0/2', disable: '' } ] }; describe('#addEmptytype - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.addEmptytype(patchForLeafTypeEmptyJneId, patchForLeafTypeEmptyInterfaceParam, patchForLeafTypeEmptyAddEmptytypeBodyParam, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-nokia_nsp_device_configurator-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('PatchForLeafTypeEmpty', 'addEmptytype', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const searchFields = 'fakedata'; const searchNeId = 'fakedata'; const searchCardId = 'fakedata'; describe('#fieldquerywithsubSelectorsofanodeunderthetargetresource - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.fieldquerywithsubSelectorsofanodeunderthetargetresource(searchFields, searchNeId, searchCardId, (data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal(true, Array.isArray(data.response['nokia-conf:card'])); } else { runCommonAsserts(data, error); } saveMockData('Search', 'fieldquerywithsubSelectorsofanodeunderthetargetresource', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#fieldquerytoselectmultiplefieldsunderthetargetresource - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.fieldquerytoselectmultiplefieldsunderthetargetresource(searchFields, searchNeId, (data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal(true, Array.isArray(data.response['nokia-conf:port'])); } else { runCommonAsserts(data, error); } saveMockData('Search', 'fieldquerytoselectmultiplefieldsunderthetargetresource', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const searchPort = 'fakedata'; describe('#fieldQueryToRetrieveASingleChildNodeUnderTheTargetResource - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.fieldQueryToRetrieveASingleChildNodeUnderTheTargetResource(searchFields, searchNeId, searchPort, (data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal(true, Array.isArray(data.response['nokia-conf:port'])); } else { runCommonAsserts(data, error); } saveMockData('Search', 'fieldQueryToRetrieveASingleChildNodeUnderTheTargetResource', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const qOSPolicyGetCreateEditCreateQOSPolicyBodyParam = { 'nokia-conf:sap-egress': [ { 'sap-egress-policy-name': 'Engress6_Test', description: 'Egress QoS 6-Test', 'policy-id': 6 } ] }; const qosNeId = 'fakedata'; describe('#createQOSPolicy - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.createQOSPolicy(qosNeId, qOSPolicyGetCreateEditCreateQOSPolicyBodyParam, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-nokia_nsp_device_configurator-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('QOSPolicyGetCreateEdit', 'createQOSPolicy', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const qOSPolicyGetCreateEditNetworkDevice = 'fakedata'; describe('#getQoS - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.getQoS(qOSPolicyGetCreateEditNetworkDevice, (data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal('object', typeof data.response['nokia-conf:qos']); } else { runCommonAsserts(data, error); } saveMockData('QOSPolicyGetCreateEdit', 'getQoS', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const qOSPolicyGetCreateEditEditQOSPolicyCopyBodyParam = { 'nokia-conf:sap-egress': [ { 'sap-egress-policy-name': 'Engress6_Test', description: 'Egress QoS 6-Test New', 'policy-id': 7 } ] }; describe('#editQOSPolicy - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.editQOSPolicy(qosNeId, qOSPolicyGetCreateEditEditQOSPolicyCopyBodyParam, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-nokia_nsp_device_configurator-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('QOSPolicyGetCreateEdit', 'editQOSPolicy', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#getQOSSAPEgressPolicy - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.getQOSSAPEgressPolicy(qOSPolicyGetCreateEditNetworkDevice, (data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal(true, Array.isArray(data.response['nokia-conf:sap-egress'])); } else { runCommonAsserts(data, error); } saveMockData('QOSPolicyGetCreateEdit', 'getQOSSAPEgressPolicy', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#deleteMDA - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.deleteMDA(createConfigureAndDeleteNeId, createConfigureAndDeleteCardId, createConfigureAndDeleteMdaId, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-nokia_nsp_device_configurator-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('CreateConfigureAndDelete', 'deleteMDA', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#removeEmptytype - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.removeEmptytype(patchForLeafTypeEmptyJneId, patchForLeafTypeEmptyInterfaceParam, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-nokia_nsp_device_configurator-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('PatchForLeafTypeEmpty', 'removeEmptytype', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); }); });