alert_instances_mapper_test.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. describe('App.alertInstanceMapper', function () {
  20. var json = {
  21. "items": [
  22. {
  23. "Alert": {
  24. "component_name": "AMBARI_AGENT",
  25. "host_name": "c6401.ambari.apache.org",
  26. "id": 2,
  27. "instance": null,
  28. "label": "Host Disk Usage",
  29. "latest_timestamp": 1415224354954,
  30. "maintenance_state": "OFF",
  31. "name": "ambari_agent_disk_usage",
  32. "original_timestamp": 1414695835400,
  33. "scope": "HOST",
  34. "service_name": "AMBARI",
  35. "state": "OK",
  36. "text": "Capacity Used: [1.26%, 6.6 GB], Capacity Total: [525.3 GB]"
  37. }
  38. },
  39. {
  40. "Alert": {
  41. "component_name": null,
  42. "host_name": null,
  43. "id": 3,
  44. "instance": null,
  45. "label": "Percent DataNodes Available",
  46. "latest_timestamp": 1415224362617,
  47. "maintenance_state": "OFF",
  48. "name": "datanode_process_percent",
  49. "original_timestamp": 1414695787466,
  50. "scope": "SERVICE",
  51. "service_name": "HDFS",
  52. "state": "CRITICAL",
  53. "text": "affected: [1], total: [1]"
  54. }
  55. }
  56. ]
  57. };
  58. it('load new records', function () {
  59. App.alertInstanceMapper.map(json);
  60. expect(App.AlertInstance.find().content.length).to.equal(2);
  61. });
  62. it('delete inexistent record', function () {
  63. App.alertInstanceMapper.map({
  64. items: [
  65. json.items[0]
  66. ]
  67. });
  68. expect(App.AlertInstance.find().content.length).to.equal(1);
  69. });
  70. it('model should be empty', function () {
  71. App.alertInstanceMapper.map({items: []});
  72. expect(App.AlertInstance.find().content).to.be.empty;
  73. });
  74. });