hosts_mapper_test.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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/host');
  20. require('models/host_component');
  21. require('mappers/server_data_mapper');
  22. require('mappers/hosts_mapper');
  23. describe('App.hostsMapper', function () {
  24. var mapper = App.hostsMapper;
  25. describe("#setMetrics()", function() {
  26. var data = {
  27. items: [
  28. {
  29. Hosts: {
  30. host_name: 'host1'
  31. },
  32. metrics: {
  33. load: {
  34. load_one: 1
  35. }
  36. }
  37. }
  38. ]
  39. };
  40. beforeEach(function(){
  41. this.mock = sinon.stub(App.Host, 'find')
  42. });
  43. afterEach(function(){
  44. this.mock.restore();
  45. });
  46. it("Host not in the model", function() {
  47. var host = Em.Object.create({
  48. hostName: 'host2',
  49. isRequested: true
  50. });
  51. this.mock.returns([host]);
  52. mapper.setMetrics(data);
  53. expect(host.get('loadOne')).to.be.undefined;
  54. });
  55. it("Host not in the filter", function() {
  56. var host = Em.Object.create({
  57. hostName: 'host1',
  58. isRequested: false
  59. });
  60. this.mock.returns([host]);
  61. mapper.setMetrics(data);
  62. expect(host.get('loadOne')).to.be.undefined;
  63. });
  64. it("Host should have updated metrics", function() {
  65. var host = Em.Object.create({
  66. hostName: 'host1',
  67. isRequested: true
  68. });
  69. this.mock.returns([host]);
  70. mapper.setMetrics(data);
  71. expect(host.get('loadOne')).to.equal(1);
  72. });
  73. });
  74. });