UNPKG

@itentialopensource/adapter-sevone

Version:
1,555 lines (1,414 loc) 466 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-sevone', type: 'SevOne', 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 SevOne = require('../../adapter'); // begin the testing - these should be pretty well defined between the describe and the it! describe('[integration] SevOne Adapter Test', () => { describe('SevOne Class Tests', () => { const a = new SevOne( 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-sevone-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-sevone-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 ****************** ----------------------------------------------------------------------- ----------------------------------------------------------------------- */ // define data used throughout the test const randExt = `${Math.random()}`; const now = new Date().getTime(); let deviceId = 1245; const deviceNm = `test${randExt}`; const deviceIP = '10.10.10.1'; const device = { name: deviceNm, ipAddress: deviceIP }; const deviceFilterObj = { disablePolling: false }; const udevice = { id: deviceId, name: deviceNm, ipAddress: deviceIP, description: 'changed description' }; let deviceGrpId = 2; const deviceGrpNm = `test grp${randExt}`; const deviceGrp = { name: deviceGrpNm, parentId: 2 }; const udeviceGrp = { id: deviceGrpId, name: `changed ${deviceGrpNm}`, parentId: 2 }; let deviceCompId = 1234; let deviceCompNm = `test comp${randExt}`; const deviceCompFilterObj = { isEnabled: true }; const deviceComp = { name: deviceCompNm, description: 'test blah', pluginId: 12, pluginObjectTypeId: 9 }; const udeviceComp = { name: deviceCompNm, description: 'changed description of blah', pluginId: 1, pluginObjectTypeId: 1, indicators: [ { id: 1, evaluationOrder: 1, format: 'GAUGE', isBaselining: true, lastInvalidationTime: 1, maxValue: 1, pluginIndicatorTypeId: 1, syntheticExpression: 'string', extendedInfo: {}, isDeleted: true, isEnabled: true } ] }; let componentGrpId = 3; const componentGrpNm = `test grp${randExt}`; const componentGrp = { name: componentGrpNm, parentId: 4 }; const ucomponentGrp = { id: componentGrpId, name: `changed ${componentGrpNm}`, parentId: 4 }; const indicatorId = (stub) ? 9876 : 1; const indicator = { deviceId, componentId: deviceCompId, indicatorData: [{ indicatorId, value: 5 }] }; let mapId = 1; let mapNm = `test map${randExt}`; const mapObj = { name: mapNm, imageId: 11 }; const umapObj = { id: mapId, name: `changed ${mapNm}`, imageId: 11 }; let mapNodeAId = 1; let mapNodeANm = `test map A${randExt}`; let mapNodeBId = 1; let mapNodeBNm = `test map B${randExt}`; const mapNodeAObj = { name: mapNodeANm, type: 'Device', x: 1, y: 1, elements: [{ deviceId, elementId: 1 }] }; const mapNodeBObj = { name: mapNodeBNm, type: 'Device', x: 1, y: 1, elements: [{ elementId: 1 }] }; const umapNodeObj = { id: mapNodeAId, name: `changed ${mapNodeANm}`, type: 'Device', x: 1, y: 1, elements: [{ deviceId, elementId: 1 }] }; let mapConnId = 1; const mapConnObj = { nodeASide: mapNodeAId, nodeBSide: mapNodeBId, type: 'Device', elements: [{ elementId: 1 }] }; const umapConnObj = { id: mapConnId, nodeASide: mapNodeAId, nodeBSide: mapNodeBId, type: 'Object', elements: [{ elementId: 1, deviceId, pluginId: 4 }] }; let alertId = 1; const alertMsg = `failed blah${randExt}`; const alertOrigin = 'trap'; let alertCreated = false; let getAlertCount = 0; const alertFilterObj = { message: alertMsg }; const alertObj = { message: alertMsg, origin: alertOrigin, deviceId, componentId: deviceCompId, severity: 3, startTime: now }; let updAlertCount = 0; const ualertObj = { id: alertId, message: `changed ${alertMsg}`, origin: alertOrigin, deviceId }; /** * Runs the common asserts for alert counts in stub mode */ function runAlertCountAsserts(data, ccnt, ecnt, acnt) { assert.equal('critical', data.response.counts[2].name); assert.equal(ccnt, data.response.counts[2].count); assert.equal('error', data.response.counts[3].name); assert.equal(ecnt, data.response.counts[3].count); assert.equal(acnt, data.response.alerts.length); assert.equal(alertId, data.response.alerts[0].id); } describe('#createDevice', () => { it('should create a new device', (done) => { try { a.createDevice(device, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal(deviceId, data.response.id); } else { assert.notEqual(undefined, data.response.id); assert.notEqual('', data.response.id); } deviceId = data.response.id; umapConnObj.elements = [{ elementId: 1, deviceId, pluginId: 4 }]; alertObj.deviceId = data.response.id; ualertObj.deviceId = data.response.id; done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#getDevices', () => { it('should get the devices', (done) => { try { a.getDevices(null, null, null, null, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal(2, data.response.length); assert.equal(deviceId, data.response[0].id); } else { assert.notEqual(0, data.response.length); } done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); it('should get device by id', (done) => { try { a.getDevices(deviceId, null, null, null, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal(deviceId, data.response.id); } else { assert.equal(deviceId, data.response.id); } done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); it('should get device by name', (done) => { try { a.getDevices(null, deviceNm, null, null, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal(2, data.response.length); assert.equal(deviceId, data.response[0].id); } else { assert.equal(deviceId, data.response[0].id); } done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); it('should get device by ip', (done) => { try { a.getDevices(null, null, deviceIP, null, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal(2, data.response.length); assert.equal(deviceId, data.response[0].id); } else { assert.notEqual(0, data.response.length); } done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); it('should get device error', (done) => { try { a.getDevices('error', null, null, null, (data, error) => { try { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-sevone-connectorRest-handleEndResponse', displayE); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#getDevicesById', () => { it('should get the devices by id', (done) => { try { a.getDevicesById(deviceId, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal(deviceId, data.response.id); } else { assert.equal(deviceId, data.response.id); } done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#getDevicesByName', () => { it('should get the devices by name', (done) => { try { a.getDevicesByName(deviceNm, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal(2, data.response.length); assert.equal(deviceId, data.response[0].id); } else { assert.equal(deviceId, data.response[0].id); } done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#getDevicesByIp', () => { it('should get the devices by ip', (done) => { try { a.getDevicesByIp(deviceIP, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal(2, data.response.length); assert.equal(deviceId, data.response[0].id); } else { assert.notEqual(0, data.response.length); } done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#getSevDevicesFiltered', () => { it('should get the filtered devices', (done) => { try { a.getSevDevicesFiltered(deviceFilterObj, null, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal(2, data.response.length); assert.equal(deviceId, data.response[0].id); } else { assert.notEqual(0, data.response.length); } done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#getDevicesForNameorIP', () => { it('should get the device by name', (done) => { try { a.getDevicesForNameorIP(deviceNm, null, null, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal(2, data.response.length); assert.equal(deviceId, data.response[0].id); } else { assert.notEqual(0, data.response.length); } done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); it('should get the device by ip', (done) => { try { a.getDevicesForNameorIP(null, deviceIP, null, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal(2, data.response.length); assert.equal(deviceId, data.response[0].id); } else { assert.notEqual(0, data.response.length); } done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#updateDevice', () => { it('should update a device', (done) => { try { a.updateDevice(deviceId, udevice, (data, error) => { try { runCommonAsserts(data, error); assert.equal('success', data.response); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#createDeviceGroup', () => { it('should create a new device group', (done) => { try { a.createDeviceGroup(deviceGrp, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal(deviceGrpId, data.response.id); } else { assert.notEqual(undefined, data.response.id); assert.notEqual('', data.response.id); } deviceGrpId = data.response.id; done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#addDeviceToGroup', () => { it('should add a device to a group', (done) => { try { a.addDeviceToGroup(deviceId, deviceGrpId, (data, error) => { try { runCommonAsserts(data, error); assert.equal('success', data.response); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#getDeviceGroups', () => { it('should get the device groups', (done) => { try { a.getDeviceGroups(null, null, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal(5, data.response.length); assert.equal(deviceGrpId, data.response[0].id); } else { assert.notEqual(0, data.response.length); } done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); it('should get device group by id', (done) => { try { a.getDeviceGroups(deviceGrpId, null, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal(deviceGrpId, data.response.id); } else { assert.equal(deviceGrpId, data.response.id); } done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#getDeviceGroupsById', () => { it('should get device group by id', (done) => { try { a.getDeviceGroupsById(deviceGrpId, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal(deviceGrpId, data.response.id); } else { assert.equal(deviceGrpId, data.response.id); } done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#updateDeviceGroup', () => { it('should update a device group', (done) => { try { a.updateDeviceGroup(deviceGrpId, udeviceGrp, (data, error) => { try { runCommonAsserts(data, error); assert.equal('success', data.response); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#createDeviceComponent', () => { it('should create a new device component', (done) => { try { a.createDeviceComponent(deviceId, deviceComp, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal(deviceCompId, data.response.id); } else { assert.notEqual(undefined, data.response.id); assert.notEqual('', data.response.id); } deviceCompId = data.response.id; deviceCompNm = data.response.name; alertObj.componentId = data.response.id; done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#getDeviceComponents', () => { it('should get the device components', (done) => { try { a.getDeviceComponents(1, null, null, null, null, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal(1, data.response.length); assert.equal(deviceCompId, data.response[0].id); } else { assert.notEqual(0, data.response.length); } done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); it('should get device component by id', (done) => { try { a.getDeviceComponents(deviceId, null, deviceCompId, null, null, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal(deviceCompId, data.response.id); } else { assert.equal(deviceCompId, data.response.id); } done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); it('should get device component by id/name', (done) => { try { a.getDeviceComponents(deviceId, null, null, deviceCompNm, null, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal(deviceCompId, data.response.id); } else { assert.equal(deviceCompId, data.response.id); } done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); it('should get device component by id/name - not able to find', (done) => { try { a.getDeviceComponents(deviceId, null, null, 'BadComponent', null, (data, error) => { try { const displayE = `Could not find component BadComponent on device ${deviceId}`; runErrorAsserts(data, error, 'AD.999', 'Test-sevone-adapter-getDeviceComponents', displayE); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); it('should get device component by name/id', (done) => { try { a.getDeviceComponents(null, deviceNm, deviceCompId, null, null, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal(deviceCompId, data.response.id); } else { assert.equal(deviceCompId, data.response.id); } done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); it('should get device component by name', (done) => { try { a.getDeviceComponents(null, deviceNm, null, deviceCompNm, null, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal(deviceCompId, data.response.id); } else { assert.equal(deviceCompId, data.response.id); } done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); it('should get device component by name - not able to find', (done) => { try { a.getDeviceComponents(null, deviceNm, null, 'BadComponent', null, (data, error) => { try { const displayE = `Could not find component BadComponent on device ${deviceNm}`; runErrorAsserts(data, error, 'AD.999', 'Test-sevone-adapter-getDeviceComponents', displayE); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#getDeviceComponentsById', () => { it('should get device component by id', (done) => { try { a.getDeviceComponentsById(deviceId, deviceCompId, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal(deviceCompId, data.response.id); } else { assert.equal(deviceCompId, data.response.id); } done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#getDeviceComponentsByName', () => { it('should get device component by name', (done) => { try { a.getDeviceComponentsByName(deviceNm, deviceCompNm, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal(deviceCompId, data.response.id); } else { assert.equal(deviceCompId, data.response.id); } done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#getDeviceComponentsFiltered', () => { it('should get the filtered device components', (done) => { try { a.getDeviceComponentsFiltered(deviceCompFilterObj, null, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal(1, data.response.length); assert.equal(deviceCompId, data.response[0].id); } else { assert.notEqual(0, data.response.length); } done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#getDeviceComponentId', () => { it('should get the device component id - by names', (done) => { try { a.getDeviceComponentId(null, deviceNm, deviceCompNm, null, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal(deviceCompId, data.response.id); } else { assert.equal(deviceCompId, data.response.id); } done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); it('should get device component - by names - not able to find', (done) => { try { a.getDeviceComponentId(null, deviceNm, 'BadComponent', null, (data, error) => { try { const displayE = `Could not find component BadComponent on device ${deviceNm}`; runErrorAsserts(data, error, 'AD.999', 'Test-sevone-adapter-getDeviceComponentId', displayE); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); it('should get the device components - by id/name', (done) => { try { a.getDeviceComponentId(deviceId, null, deviceCompNm, null, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal(deviceCompId, data.response.id); } else { assert.equal(deviceCompId, data.response.id); } done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); it('should get device component - by id/name - not able to find', (done) => { try { a.getDeviceComponentId(deviceId, null, 'BadComponent', null, (data, error) => { try { const displayE = `Could not find component BadComponent on device ${deviceId}`; runErrorAsserts(data, error, 'AD.999', 'Test-sevone-adapter-getDeviceComponentId', displayE); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#updateDeviceComponent', () => { it('should update a device component', (done) => { try { a.updateDeviceComponent(deviceId, deviceCompId, udeviceComp, (data, error) => { try { runCommonAsserts(data, error); assert.equal('success', data.response); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#createComponentGroup', () => { it('should create a new component group', (done) => { try { a.createComponentGroup(componentGrp, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal(componentGrpId, data.response.id); } else { assert.notEqual(undefined, data.response.id); assert.notEqual('', data.response.id); } componentGrpId = data.response.id; done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#addDeviceComponentToGroup', () => { it('should add a device component to a group', (done) => { try { a.addDeviceComponentToGroup(deviceId, deviceCompId, componentGrpId, (data, error) => { try { runCommonAsserts(data, error); assert.equal('success', data.response); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#getComponentGroups', () => { it('should get the component groups', (done) => { try { a.getComponentGroups(null, null, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal(20, data.response.length); assert.equal(componentGrpId, data.response[0].id); } else { assert.notEqual(0, data.response.length); } done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); it('should get component group by id', (done) => { try { a.getComponentGroups(componentGrpId, null, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal(componentGrpId, data.response.id); } else { assert.equal(componentGrpId, data.response.id); } done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#getComponentGroupsById', () => { it('should get component group by id', (done) => { try { a.getComponentGroupsById(componentGrpId, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal(componentGrpId, data.response.id); } else { assert.equal(componentGrpId, data.response.id); } done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#updateComponentGroup', () => { it('should update a component group', (done) => { try { a.updateComponentGroup(componentGrpId, ucomponentGrp, (data, error) => { try { runCommonAsserts(data, error); assert.equal('success', data.response); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#createIndicatorData', () => { it('should create indicator data', (done) => { try { a.createIndicatorData(indicator, (data, error) => { try { runCommonAsserts(data, error); assert.equal('success', data.response); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); // NEED TO ONLY RUNIN STUB MODE AS INDICATOR IS NOT ON COMPONENT PROPERLY // NOT SURE IF SEVONE ISSUE OR TESTING DATA ISSUE if (stub) { describe('#getIndicators', () => { it('should get the indicators', (done) => { const p = new Promise((reso