Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding some coverage of the listeners and fixing JSON syntax error in oneview-configuration.json.
- Loading branch information
Daniel Reed
committed
Nov 7, 2017
1 parent
f7538ba
commit 717f015
Showing
10 changed files
with
588 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
/* | ||
(c) Copyright 2016-2017 Hewlett Packard Enterprise Development LP | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
*/ | ||
const AlertsListener = require('../../src/listener/alerts-listener'); | ||
const OneViewBrain = require('../../src/middleware/ov-brain'); | ||
const OVClient = require('../../src/oneview-sdk/ov-client'); | ||
const ResourceTransforms = require('../../src/listener/utils/resource-transforms'); | ||
|
||
const chai = require('chai'); | ||
const sinon = require('sinon'); | ||
const Bluebird = require('bluebird'); | ||
|
||
chai.should(); | ||
const assert = chai.assert; | ||
|
||
describe('AlertsListener', () => { | ||
|
||
const robot = {adapterName: 'shell', on: function () { }, listen: function () {}, respond: function () {}, listenerMiddleware: function() {}, logger: {debug: function () {}, error: function () {}, info: function () {}}}; | ||
|
||
const oneviewConfig = { | ||
hosts: [] | ||
}; | ||
const oVClient = new OVClient(oneviewConfig, robot); | ||
|
||
sinon.stub(oVClient.ServerHardware, 'getAllServerHardware').returns(Bluebird.resolve([])); | ||
sinon.stub(oVClient.ServerProfiles, 'getAllServerProfiles').returns(Bluebird.resolve([])); | ||
sinon.stub(oVClient.ServerProfileTemplates, 'getAllServerProfileTemplates').returns(Bluebird.resolve([])); | ||
sinon.stub(oVClient.LogicalInterconnects, 'getAllLogicalInterconnects').returns(Bluebird.resolve([])); | ||
|
||
const brain = new OneViewBrain(oVClient, robot, {}); | ||
const transform = new ResourceTransforms(robot, brain); | ||
|
||
const alertResponse = { | ||
members: [ | ||
{ | ||
type: "AlertResourceV3", | ||
uri: "/rest/alerts/476", | ||
category: "alerts", | ||
associatedEventUris: [ | ||
"/rest/events/1774" | ||
], | ||
resourceID: null, | ||
correctiveAction: "", | ||
description: "The backup has not been...", | ||
alertTypeID: "Backup", | ||
urgency: "Medium", | ||
healthCategory: "backups", | ||
lifeCycle: false, | ||
associatedResource: { | ||
resourceName: "Backup.", | ||
resourceUri: "/rest/backups", | ||
resourceCategory: "backups", | ||
associationType: "HAS_A", | ||
resourceHyperlink: "https://0.0.0.0/#//rest/backups?s_sid=NjA2ODA" | ||
}, | ||
severity: "Warning", | ||
alertState: "Locked", | ||
physicalResourceType: "backups", | ||
resourceUri: "/rest/backups", | ||
hyperlink: "https://0.0.0.0/#/activity/r/rest/alerts/476?s_sid=NjA2ODA", | ||
resourceHyperlink: "https://0.0.0.0/#//rest/backups?s_sid=NjA2ODA" | ||
} | ||
] | ||
}; | ||
|
||
const err = { | ||
error: { | ||
errorCode: 'OOPS' | ||
} | ||
}; | ||
|
||
it('list alerts by number', (done) => { | ||
let stub = sinon.stub(oVClient.Alerts, 'getNumberOfAlerts').returns(Bluebird.resolve(alertResponse)); | ||
const alertsListener = new AlertsListener(robot, oVClient, transform); | ||
|
||
let msg = { | ||
robot: {}, | ||
message: {TextMessage: {user: '', text: '@bot show last 1 alerts.'}}, | ||
count: 1, | ||
send: function () {} | ||
}; | ||
sinon.spy(msg, "send"); | ||
|
||
alertsListener.ListNumberOfAlerts(msg); | ||
|
||
const expectedJsonResults = JSON.stringify(alertResponse, null, ' '); | ||
//sleep a momemt to wait for results | ||
setTimeout(() => { | ||
assert(msg.send.callCount === 2); | ||
'Here are the last 1 alerts.'.should.equal(msg.send.args[0][0]); | ||
expectedJsonResults.should.equal(msg.send.args[1][0]); | ||
stub.restore(); | ||
done(); | ||
}, 100); | ||
}); | ||
|
||
it('list alerts by filter', (done) => { | ||
let stub = sinon.stub(oVClient.Alerts, 'getFilteredAlerts').returns(Bluebird.resolve(alertResponse)); | ||
const alertsListener = new AlertsListener(robot, oVClient, transform); | ||
|
||
let msg = { | ||
robot: {}, | ||
message: {TextMessage: {user: '', text: '@bot show all active warning alerts from today.'}}, | ||
count: 1, | ||
status: 'warning', | ||
state: 'active', | ||
time: 'today', | ||
send: function () {} | ||
}; | ||
sinon.spy(msg, "send"); | ||
|
||
alertsListener.ListFilteredAlerts(msg); | ||
|
||
const expectedJsonResults = JSON.stringify(alertResponse, null, ' '); | ||
//sleep a momemt to wait for results | ||
setTimeout(() => { | ||
assert(msg.send.callCount === 2); | ||
'I found the following alerts.'.should.equal(msg.send.args[0][0]); | ||
expectedJsonResults.should.equal(msg.send.args[1][0]); | ||
stub.restore(); | ||
done(); | ||
}, 100); | ||
}); | ||
|
||
it('list alerts by number error', (done) => { | ||
let stub = sinon.stub(oVClient.Alerts, 'getNumberOfAlerts').returns(Bluebird.reject(err)); | ||
const alertsListener = new AlertsListener(robot, oVClient, transform); | ||
|
||
let msg = { | ||
robot: {}, | ||
message: {TextMessage: {user: '', text: '@bot show last 1 alerts.'}}, | ||
count: 1, | ||
send: function () {} | ||
}; | ||
sinon.spy(msg, "send"); | ||
|
||
alertsListener.ListNumberOfAlerts(msg); | ||
|
||
//sleep a momemt to wait for results | ||
setTimeout(() => { | ||
assert(msg.send.callCount === 1); | ||
'Oops there was a problem.\n\nOneView error code: OOPS\n'.should.equal(msg.send.args[0][0]); | ||
stub.restore(); | ||
done(); | ||
}, 100); | ||
}); | ||
|
||
it('list alerts by filter error', (done) => { | ||
let stub = sinon.stub(oVClient.Alerts, 'getFilteredAlerts').returns(Bluebird.reject(err)); | ||
const alertsListener = new AlertsListener(robot, oVClient, transform); | ||
|
||
let msg = { | ||
robot: {}, | ||
message: {TextMessage: {user: '', text: '@bot show all active warning alerts from today.'}}, | ||
count: 1, | ||
status: 'warning', | ||
state: 'active', | ||
time: 'today', | ||
send: function () {} | ||
}; | ||
sinon.spy(msg, "send"); | ||
|
||
alertsListener.ListFilteredAlerts(msg); | ||
|
||
//sleep a momemt to wait for results | ||
setTimeout(() => { | ||
assert(msg.send.callCount === 1); | ||
'Oops there was a problem.\n\nOneView error code: OOPS\n'.should.equal(msg.send.args[0][0]); | ||
stub.restore(); | ||
done(); | ||
}, 100); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
/* | ||
(c) Copyright 2016-2017 Hewlett Packard Enterprise Development LP | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
*/ | ||
const DashboardListener = require('../../src/listener/dashboard-listener'); | ||
const OneViewBrain = require('../../src/middleware/ov-brain'); | ||
const OVClient = require('../../src/oneview-sdk/ov-client'); | ||
const ResourceTransforms = require('../../src/listener/utils/resource-transforms'); | ||
|
||
const chai = require('chai'); | ||
const sinon = require('sinon'); | ||
const Bluebird = require('bluebird'); | ||
|
||
chai.should(); | ||
const assert = chai.assert; | ||
|
||
describe('DashboardListener', () => { | ||
|
||
const robot = {adapterName: 'shell', on: function () { }, listen: function () {}, respond: function () {}, listenerMiddleware: function() {}, logger: {debug: function () {}, error: function () {}, info: function () {}}}; | ||
|
||
const oneviewConfig = { | ||
hosts: [] | ||
}; | ||
const oVClient = new OVClient(oneviewConfig, robot); | ||
|
||
sinon.stub(oVClient.ServerHardware, 'getAllServerHardware').returns(Bluebird.resolve([])); | ||
sinon.stub(oVClient.ServerProfiles, 'getAllServerProfiles').returns(Bluebird.resolve([])); | ||
sinon.stub(oVClient.ServerProfileTemplates, 'getAllServerProfileTemplates').returns(Bluebird.resolve([])); | ||
sinon.stub(oVClient.LogicalInterconnects, 'getAllLogicalInterconnects').returns(Bluebird.resolve([])); | ||
|
||
const brain = new OneViewBrain(oVClient, robot, {}); | ||
const transform = new ResourceTransforms(robot, brain); | ||
|
||
const serverHardwareResponse = { | ||
members: [{ attribute: 'status', | ||
counts: [{ value: 'OK', count: 7 }, { value: 'Critical', count: 1 }]}, | ||
{ attribute: 'status', counts: [ { value: 'OK', count: 21 }]}]}; | ||
|
||
const serverProfilesResponse = { | ||
members: [{ attribute: 'state', | ||
counts: [{ value: 'NoProfileApplied', count: 7 }, | ||
{value: 'ProfileApplied', count: 1 }]}, | ||
{attribute: 'state', | ||
counts: [{ value: 'NoProfileApplied', count: 19 }, | ||
{value: 'ProfileApplied', count: 2 }]}]}; | ||
|
||
const alertsResponse = { | ||
members: [{ attribute: 'status', | ||
counts: [{ value: 'Critical', count: 1 }, | ||
{value: 'Warning', count: 1 } ]}, | ||
{attribute: 'status', | ||
counts: [ { value: 'OK', count: 719 }, { value: 'Warning', count: 1 } ]}]}; | ||
|
||
const serversWithProfilesResponse = { | ||
members: [{ attribute: 'status', counts: [ { value: 'OK', count: 1 }]}, | ||
{attribute: 'status', counts: [ { value: 'OK', count: 2 }]}]}; | ||
|
||
const err = { | ||
error: { | ||
errorCode: 'OOPS' | ||
} | ||
}; | ||
|
||
it('show', (done) => { | ||
let stub1 = sinon.stub(oVClient.Dashboard, 'getAggregatedAlerts').returns(Bluebird.resolve(alertsResponse)); | ||
let stub2 = sinon.stub(oVClient.Dashboard, 'getAggregatedServerProfiles').returns(Bluebird.resolve(serverProfilesResponse)); | ||
let stub3 = sinon.stub(oVClient.Dashboard, 'getAggregatedServerHardware').returns(Bluebird.resolve(serverHardwareResponse)); | ||
let stub4 = sinon.stub(oVClient.Dashboard, 'getAggregatedServersWithProfiles').returns(Bluebird.resolve(serversWithProfilesResponse)); | ||
|
||
const dashboardListener = new DashboardListener(robot, oVClient, transform); | ||
|
||
let msg = { | ||
robot: {}, | ||
message: {TextMessage: {user: '', text: '@bot show dashboard.'}}, | ||
count: 1, | ||
send: function () {}, | ||
message: {user: {name: 'name'}} | ||
}; | ||
sinon.spy(msg, "send"); | ||
|
||
dashboardListener.ShowOneViewDashboard(msg); | ||
|
||
//sleep a momemt to wait for results | ||
setTimeout(() => { | ||
assert(msg.send.callCount === 1); | ||
'Ok name, I am going to generate your dashboard. This might take a little while.\nFor a more comprehensive view, see Dashboard.'.should.equal(msg.send.args[0][0]); | ||
stub1.restore(); | ||
stub2.restore(); | ||
stub3.restore(); | ||
stub4.restore(); | ||
done(); | ||
}, 100); | ||
}); | ||
|
||
it('show error', (done) => { | ||
let stub1 = sinon.stub(oVClient.Dashboard, 'getAggregatedAlerts').returns(Bluebird.reject(err)); | ||
let stub2 = sinon.stub(oVClient.Dashboard, 'getAggregatedServerProfiles').returns(Bluebird.resolve(serverProfilesResponse)); | ||
let stub3 = sinon.stub(oVClient.Dashboard, 'getAggregatedServerHardware').returns(Bluebird.resolve(serverHardwareResponse)); | ||
let stub4 = sinon.stub(oVClient.Dashboard, 'getAggregatedServersWithProfiles').returns(Bluebird.resolve(serversWithProfilesResponse)); | ||
|
||
const dashboardListener = new DashboardListener(robot, oVClient, transform); | ||
|
||
let msg = { | ||
robot: {}, | ||
message: {TextMessage: {user: '', text: '@bot show dashboard.'}}, | ||
count: 1, | ||
send: function () {}, | ||
message: {user: {name: 'name'}} | ||
}; | ||
sinon.spy(msg, "send"); | ||
|
||
dashboardListener.ShowOneViewDashboard(msg); | ||
|
||
//sleep a momemt to wait for results | ||
setTimeout(() => { | ||
assert(msg.send.callCount === 2); | ||
'Ok name, I am going to generate your dashboard. This might take a little while.\nFor a more comprehensive view, see Dashboard.'.should.equal(msg.send.args[0][0]); | ||
'Oops there was a problem.\n\nOneView error code: OOPS\n'.should.equal(msg.send.args[1][0]); | ||
stub1.restore(); | ||
stub2.restore(); | ||
stub3.restore(); | ||
stub4.restore(); | ||
done(); | ||
}, 100); | ||
}); | ||
}); |
Oops, something went wrong.