alert_definition_test.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. require('models/alert_definition');
  20. var model;
  21. describe('App.AlertDefinition', function () {
  22. beforeEach(function () {
  23. model = App.AlertDefinition.createRecord();
  24. });
  25. describe('#status', function () {
  26. Em.A([
  27. {
  28. summary: {OK: {count: 1, maintenanceCount: 0}, UNKNOWN: {count: 1, maintenanceCount: 0}, WARNING: {count: 2, maintenanceCount: 0}, CRITICAL: {count: 0, maintenanceCount: 0}},
  29. m: 'No CRITICAL',
  30. e: '<span class="alert-state-single-host label alert-state-OK">OK (1)</span> ' +
  31. '<span class="alert-state-single-host label alert-state-WARNING">WARN (2)</span> ' +
  32. '<span class="alert-state-single-host label alert-state-UNKNOWN">UNKWN (1)</span>'
  33. },
  34. {
  35. summary: {WARNING: {count: 2, maintenanceCount: 0}, CRITICAL: {count: 3, maintenanceCount: 0}, UNKNOWN: {count: 1, maintenanceCount: 0}, OK: {count: 1, maintenanceCount: 0}},
  36. m: 'All states exists',
  37. e: '<span class="alert-state-single-host label alert-state-OK">OK (1)</span> ' +
  38. '<span class="alert-state-single-host label alert-state-WARNING">WARN (2)</span> ' +
  39. '<span class="alert-state-single-host label alert-state-CRITICAL">CRIT (3)</span> ' +
  40. '<span class="alert-state-single-host label alert-state-UNKNOWN">UNKWN (1)</span>'
  41. },
  42. {
  43. summary: {OK: {count: 1, maintenanceCount: 0}, UNKNOWN: {count: 0, maintenanceCount: 0}, WARNING: {count: 0, maintenanceCount: 0}, CRITICAL: {count: 0, maintenanceCount: 0}},
  44. m: 'Single host',
  45. e: '<span class="alert-state-single-host label alert-state-OK">OK</span>'
  46. },
  47. {
  48. summary: {OK: {count: 0, maintenanceCount: 1}, UNKNOWN: {count: 0, maintenanceCount: 0}, WARNING: {count: 0, maintenanceCount: 0}, CRITICAL: {count: 0, maintenanceCount: 0}},
  49. m: 'Maintenance OK alert',
  50. e: '<span class="alert-state-single-host label alert-state-PENDING"><span class="icon-medkit"></span> OK</span>'
  51. },
  52. {
  53. summary: {},
  54. m: 'Pending',
  55. e: '<span class="alert-state-single-host label alert-state-PENDING">NONE</span>'
  56. }
  57. ]).forEach(function (test) {
  58. it(test.m, function () {
  59. model.set('summary', test.summary);
  60. expect(model.get('status')).to.equal(test.e);
  61. });
  62. });
  63. });
  64. describe('#isCriticalOrWarning', function () {
  65. Em.A([
  66. {summary: {CRITICAL: {count: 1, maintenanceCount: 0}}, e: true},
  67. {summary: {CRITICAL: {count: 0, maintenanceCount: 1}}, e: false},
  68. {summary: {CRITICAL: {count: 1, maintenanceCount: 1}}, e: true},
  69. {summary: {WARNING: {count: 1, maintenanceCount: 0}}, e: true},
  70. {summary: {OK: {count: 1, maintenanceCount: 0}}, e: false},
  71. {summary: {UNKNOWN: {count: 1, maintenanceCount: 0}}, e: false},
  72. {summary: {}, e: false}
  73. ]).forEach(function (test, i) {
  74. it('test ' + (i + 1), function () {
  75. model.set('summary', test.summary);
  76. expect(model.get('isCriticalOrWarning')).to.equal(test.e);
  77. });
  78. });
  79. });
  80. describe('#isCritical', function () {
  81. Em.A([
  82. {summary: {CRITICAL: {count: 1, maintenanceCount: 0}}, e: true},
  83. {summary: {WARNING: {count: 1, maintenanceCount: 0}}, e: false},
  84. {summary: {OK: {count: 1, maintenanceCount: 0}}, e: false},
  85. {summary: {UNKNOWN: {count: 1, maintenanceCount: 0}}, e: false},
  86. {summary: {}, e: false}
  87. ]).forEach(function (test, i) {
  88. it('test ' + (i + 1), function () {
  89. model.set('summary', test.summary);
  90. expect(model.get('isCritical')).to.equal(test.e);
  91. });
  92. });
  93. });
  94. describe('#isWarning', function () {
  95. Em.A([
  96. {summary: {CRITICAL: {count: 1, maintenanceCount: 0}}, e: false},
  97. {summary: {WARNING: {count: 1, maintenanceCount: 0}}, e: true},
  98. {summary: {OK: {count: 1, maintenanceCount: 0}}, e: false},
  99. {summary: {UNKNOWN: {count: 1, maintenanceCount: 0}}, e: false},
  100. {summary: {}, e: false}
  101. ]).forEach(function (test, i) {
  102. it('test ' + (i + 1), function () {
  103. model.set('summary', test.summary);
  104. expect(model.get('isWarning')).to.equal(test.e);
  105. });
  106. });
  107. });
  108. describe('#lastTriggeredAgoFormatted', function () {
  109. it('should be empty', function () {
  110. model.set('lastTriggered', 0);
  111. expect(model.get('lastTriggeredAgoFormatted')).to.equal('');
  112. });
  113. it('should not be empty', function () {
  114. model.set('lastTriggered', new Date().getTime() - 61000);
  115. expect(model.get('lastTriggeredAgoFormatted')).to.equal('about a minute ago');
  116. });
  117. });
  118. describe('#serviceDisplayName', function () {
  119. it('should get name for non-existing service', function () {
  120. model.set('serviceName', 'FOOBAR');
  121. expect(model.get('serviceDisplayName')).to.equal('Foobar');
  122. });
  123. });
  124. describe('#componentNameFormatted', function () {
  125. beforeEach(function () {
  126. sinon.stub(App.format, 'role', function (a) {
  127. return 'role ' + a;
  128. });
  129. });
  130. it('should wrap component name by App.format.role method', function () {
  131. model.set('componentName', 'test');
  132. var result = model.get('componentNameFormatted');
  133. expect(result).to.equal('role test');
  134. });
  135. afterEach(function () {
  136. App.format.role.restore();
  137. });
  138. });
  139. describe('REOPEN', function () {
  140. describe('#getSortDefinitionsByStatus', function () {
  141. Em.A([
  142. {
  143. a: App.AlertDefinition.createRecord({summary: {OK: {count: 1, maintenanceCount: 0}, WARNING: {count: 1, maintenanceCount: 0}}}),
  144. b: App.AlertDefinition.createRecord({summary: {WARNING: {count: 1, maintenanceCount: 0}}}),
  145. order: true,
  146. e: -1
  147. },
  148. {
  149. a: App.AlertDefinition.createRecord({summary: {OK: {count: 1, maintenanceCount: 0}, WARNING: {count: 2, maintenanceCount: 0}}}),
  150. b: App.AlertDefinition.createRecord({summary: {OK: {count: 1, maintenanceCount: 0}, WARNING: {count: 1, maintenanceCount: 0}}}),
  151. order: true,
  152. e: -1
  153. },
  154. {
  155. a: App.AlertDefinition.createRecord({summary: {OK: {count: 1, maintenanceCount: 0}, WARNING: {count: 1, maintenanceCount: 0}}}),
  156. b: App.AlertDefinition.createRecord({summary: {WARNING: {count: 1, maintenanceCount: 0}}}),
  157. order: false,
  158. e: 1
  159. },
  160. {
  161. a: App.AlertDefinition.createRecord({summary: {OK: {count: 1, maintenanceCount: 0}, WARNING: {count: 2, maintenanceCount: 0}}}),
  162. b: App.AlertDefinition.createRecord({summary: {OK: {count: 1, maintenanceCount: 0}, WARNING: {count: 1, maintenanceCount: 0}}}),
  163. order: false,
  164. e: 1
  165. }
  166. ]).forEach(function(test, i) {
  167. it('test #' + (i + 1), function () {
  168. var func = App.AlertDefinition.getSortDefinitionsByStatus(test.order);
  169. expect(func(test.a, test.b)).to.equal(test.e);
  170. });
  171. });
  172. });
  173. });
  174. });