alert_instances_mapper_test.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with this
  4. * work for additional information regarding copyright ownership. The ASF
  5. * licenses this file to you under the Apache License, Version 2.0 (the
  6. * "License"); you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  14. * License for the specific language governing permissions and limitations under
  15. * the License.
  16. */
  17. var App = require('app');
  18. require('mappers/alert_instances_mapper');
  19. var testHelpers = require('test/helpers');
  20. describe('App.alertInstanceMapper', function () {
  21. var alertInstances = [
  22. {id: 1},
  23. {id: 2},
  24. {id: 3},
  25. {id: 4}
  26. ],
  27. json = {
  28. "items" : [
  29. {
  30. "Alert" : {
  31. "component_name" : "AMBARI_AGENT",
  32. "host_name" : "c6401.ambari.apache.org",
  33. "id" : 2,
  34. "instance" : null,
  35. "label" : "Ambari Agent Disk Usage",
  36. "latest_timestamp" : 1415224354954,
  37. "maintenance_state" : "OFF",
  38. "name" : "ambari_agent_disk_usage",
  39. "original_timestamp" : 1414695835400,
  40. "scope" : "HOST",
  41. "service_name" : "AMBARI",
  42. "state" : "OK",
  43. "text" : "Capacity Used: [1.26%, 6.6 GB], Capacity Total: [525.3 GB]"
  44. }
  45. },
  46. {
  47. "Alert" : {
  48. "component_name" : null,
  49. "host_name" : null,
  50. "id" : 3,
  51. "instance" : null,
  52. "label" : "Percent DataNodes Available",
  53. "latest_timestamp" : 1415224362617,
  54. "maintenance_state" : "OFF",
  55. "name" : "datanode_process_percent",
  56. "original_timestamp" : 1414695787466,
  57. "scope" : "SERVICE",
  58. "service_name" : "HDFS",
  59. "state" : "CRITICAL",
  60. "text" : "affected: [1], total: [1]"
  61. }
  62. }
  63. ]
  64. };
  65. beforeEach(function () {
  66. sinon.stub(App.alertInstanceMapper, 'deleteRecord', Em.K);
  67. sinon.stub(App.store, 'loadMany', function (type, content) {
  68. type.content = content;
  69. });
  70. App.alertInstanceMapper.model = {
  71. find: function () {
  72. if (arguments.length) {
  73. return alertInstances.findProperty('id', arguments[0]);
  74. }
  75. return alertInstances;
  76. }
  77. };
  78. });
  79. afterEach(function () {
  80. App.alertInstanceMapper.deleteRecord.restore();
  81. App.alertInstanceMapper.model = App.AlertInstance;
  82. App.store.loadMany.restore();
  83. });
  84. it('should delete not existing models', function () {
  85. App.alertInstanceMapper.map(json);
  86. expect(App.alertInstanceMapper.deleteRecord.calledTwice).to.be.true;
  87. expect(App.alertInstanceMapper.deleteRecord.args[0][0].id).to.equal(1);
  88. expect(App.alertInstanceMapper.deleteRecord.args[1][0].id).to.equal(4);
  89. });
  90. it('should map alert instances', function () {
  91. var expected = [
  92. {
  93. "id": 2,
  94. "label": "Ambari Agent Disk Usage",
  95. "service_id": "AMBARI",
  96. "component_name": "AMBARI_AGENT",
  97. "host_id": "c6401.ambari.apache.org",
  98. "scope": "HOST",
  99. "original_timestamp": 1414695835400,
  100. "latest_timestamp": 1415224354954,
  101. "maintenance_state": "OFF",
  102. "instance": null,
  103. "state": "OK",
  104. "text": "Capacity Used: [1.26%, 6.6 GB], Capacity Total: [525.3 GB]"
  105. },
  106. {
  107. "id": 3,
  108. "label": "Percent DataNodes Available",
  109. "service_id": "HDFS",
  110. "component_name": null,
  111. "host_id": null,
  112. "scope": "SERVICE",
  113. "original_timestamp": 1414695787466,
  114. "latest_timestamp": 1415224362617,
  115. "maintenance_state": "OFF",
  116. "instance": null,
  117. "state": "CRITICAL",
  118. "text": "affected: [1], total: [1]"
  119. }
  120. ];
  121. App.alertInstanceMapper.map(json);
  122. testHelpers.nestedExpect(expected, App.alertInstanceMapper.model.content);
  123. });
  124. });