reassign_controller_test.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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/cluster');
  20. require('controllers/wizard');
  21. require('controllers/main/service/reassign_controller');
  22. describe('App.ReassignMasterController', function () {
  23. var reassignMasterController;
  24. beforeEach(function () {
  25. reassignMasterController = App.ReassignMasterController.create({});
  26. });
  27. describe('#totalSteps', function () {
  28. var cases = [
  29. {
  30. componentName: 'ZOOKEEPER_SERVER',
  31. result: 4
  32. },
  33. {
  34. componentName: 'RESOURCE_MANAGER',
  35. result: 4
  36. },
  37. {
  38. componentName: 'OOZIE_SERVER',
  39. result: 6
  40. },
  41. {
  42. componentName: 'APP_TIMELINE_SERVER',
  43. result: 6
  44. },
  45. {
  46. componentName: 'NAMENODE',
  47. result: 6
  48. }
  49. ];
  50. cases.forEach(function (c) {
  51. it('check ' + c.componentName, function () {
  52. reassignMasterController.set('content.reassign', {'component_name': c.componentName});
  53. expect(reassignMasterController.get('totalSteps')).to.equal(c.result);
  54. reassignMasterController.set('content.reassign', {service_id:null});
  55. });
  56. });
  57. });
  58. describe('#saveMasterComponentHosts', function () {
  59. var stepController = Em.Object.create({
  60. selectedServicesMasters: [
  61. Em.Object.create({
  62. display_name: 'd0',
  63. component_name: 'c0',
  64. selectedHost: 'h0',
  65. serviceId: 's0'
  66. }),
  67. Em.Object.create({
  68. display_name: 'd1',
  69. component_name: 'c1',
  70. selectedHost: 'h1',
  71. serviceId: 's1'
  72. })
  73. ]
  74. }),
  75. masterComponentHosts = [
  76. {
  77. display_name: 'd0',
  78. component: 'c0',
  79. hostName: 'h0',
  80. serviceId: 's0',
  81. isInstalled: true
  82. },
  83. {
  84. display_name: 'd1',
  85. component: 'c1',
  86. hostName: 'h1',
  87. serviceId: 's1',
  88. isInstalled: true
  89. }
  90. ];
  91. beforeEach(function () {
  92. sinon.stub(App.db, 'setMasterComponentHosts', Em.K);
  93. sinon.stub(reassignMasterController, 'setDBProperty', Em.K);
  94. reassignMasterController.saveMasterComponentHosts(stepController);
  95. });
  96. afterEach(function () {
  97. App.db.setMasterComponentHosts.restore();
  98. reassignMasterController.setDBProperty.restore();
  99. });
  100. it('setMasterComponentHosts is called once', function () {
  101. expect(App.db.setMasterComponentHosts.calledOnce).to.be.true;
  102. });
  103. it('setDBProperty is called once', function () {
  104. expect(reassignMasterController.setDBProperty.calledOnce).to.be.true;
  105. });
  106. it('setMasterComponentHosts is called with valid arguments', function () {
  107. expect(App.db.setMasterComponentHosts.calledWith(masterComponentHosts)).to.be.true;
  108. });
  109. it('setDBProperty is called with valid arguments', function () {
  110. expect(reassignMasterController.setDBProperty.calledWith('masterComponentHosts', masterComponentHosts)).to.be.true;
  111. });
  112. it('masterComponentHosts are equal to ' + JSON.stringify(masterComponentHosts), function () {
  113. expect(reassignMasterController.get('content.masterComponentHosts')).to.eql(masterComponentHosts);
  114. });
  115. });
  116. });