hosts_mapper_test.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. });
  50. var mockedModel = [host];
  51. mockedModel.content = mockedModel;
  52. this.mock.returns(mockedModel);
  53. mapper.setMetrics(data);
  54. expect(host.get('loadOne')).to.be.undefined;
  55. });
  56. it("Host should have updated metrics", function() {
  57. var host = Em.Object.create({
  58. hostName: 'host1'
  59. });
  60. var mockedModel = [host];
  61. mockedModel.content = mockedModel;
  62. this.mock.returns(mockedModel);
  63. mapper.setMetrics(data);
  64. expect(host.get('loadOne')).to.equal(1);
  65. });
  66. });
  67. });