step7_controller_test.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. App = require('app');
  19. require('controllers/main/service/reassign/step7_controller');
  20. var controller;
  21. describe('App.ReassignMasterWizardStep7Controller', function () {
  22. beforeEach(function () {
  23. sinon.stub(App.ajax, 'send', Em.K);
  24. controller = App.ReassignMasterWizardStep7Controller.create({
  25. content: Em.Object.create({
  26. reassign: Em.Object.create(),
  27. reassignHosts: Em.Object.create()
  28. })
  29. });
  30. });
  31. afterEach(function () {
  32. App.ajax.send.restore();
  33. });
  34. describe('#initializeTasks()', function () {
  35. it('should set isLoaded to true', function () {
  36. controller.set('isLoaded', false);
  37. controller.initializeTasks();
  38. expect(controller.get('isLoaded')).to.be.true;
  39. });
  40. });
  41. describe("#putHostComponentsInMaintenanceMode()", function() {
  42. it("no host-components", function() {
  43. controller.set('hostComponents', []);
  44. controller.putHostComponentsInMaintenanceMode();
  45. expect(App.ajax.send.called).to.be.false;
  46. expect(controller.get('multiTaskCounter')).to.equal(0);
  47. });
  48. it("one host-component", function() {
  49. controller.set('hostComponents', ['C1']);
  50. controller.set('content.reassignHosts.target', 'host1');
  51. controller.putHostComponentsInMaintenanceMode();
  52. expect(App.ajax.send.calledWith({
  53. name: 'common.host.host_component.passive',
  54. sender: controller,
  55. data: {
  56. hostName: 'host1',
  57. passive_state: "ON",
  58. componentName: 'C1'
  59. },
  60. success: 'onComponentsTasksSuccess',
  61. error: 'onTaskError'
  62. })).to.be.true;
  63. expect(controller.get('multiTaskCounter')).to.equal(0);
  64. });
  65. it("two host-components", function() {
  66. controller.set('hostComponents', ['C1', 'C2']);
  67. controller.putHostComponentsInMaintenanceMode();
  68. expect(App.ajax.send.calledTwice).to.be.true;
  69. expect(controller.get('multiTaskCounter')).to.equal(0);
  70. });
  71. });
  72. describe("#deleteHostComponents()", function() {
  73. it("no host-components", function() {
  74. controller.set('hostComponents', []);
  75. controller.deleteHostComponents();
  76. expect(App.ajax.send.called).to.be.false;
  77. expect(controller.get('multiTaskCounter')).to.equal(0);
  78. });
  79. it("one host-component", function() {
  80. controller.set('hostComponents', ['C1']);
  81. controller.set('content.reassignHosts.target', 'host1');
  82. controller.deleteHostComponents();
  83. expect(App.ajax.send.calledWith({
  84. name: 'common.delete.host_component',
  85. sender: controller,
  86. data: {
  87. hostName: 'host1',
  88. componentName: 'C1'
  89. },
  90. success: 'onComponentsTasksSuccess',
  91. error: 'onDeleteHostComponentsError'
  92. })).to.be.true;
  93. expect(controller.get('multiTaskCounter')).to.equal(0);
  94. });
  95. it("two host-components", function() {
  96. controller.set('hostComponents', ['C1', 'C2']);
  97. controller.deleteHostComponents();
  98. expect(App.ajax.send.calledTwice).to.be.true;
  99. expect(controller.get('multiTaskCounter')).to.equal(0);
  100. });
  101. });
  102. });