wizardProgressPageController_test.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. var testHelpers = require('test/helpers');
  20. describe('App.wizardProgressPageControllerMixin', function() {
  21. var mixedObject = Em.Object.extend(App.wizardProgressPageControllerMixin, {});
  22. describe('#createComponent', function() {
  23. var mixedObjectInstance;
  24. beforeEach(function() {
  25. mixedObjectInstance = mixedObject.create({});
  26. sinon.stub(mixedObjectInstance, "updateAndCreateServiceComponent").returns({
  27. done: Em.clb
  28. });
  29. sinon.spy(mixedObjectInstance, 'onCreateComponent');
  30. sinon.spy(mixedObjectInstance, 'updateComponent');
  31. sinon.stub(mixedObjectInstance, 'checkInstalledComponents', function(componentName) {
  32. var def = $.Deferred();
  33. var data = {
  34. 'ZOOKEEPER_SERVER': {
  35. items: []
  36. },
  37. 'ZOOKEEPER_CLIENT': {
  38. items: [
  39. { HostRoles: { host_name: 'host1' } }
  40. ]
  41. }
  42. };
  43. def.resolve(data[componentName]);
  44. return def.promise();
  45. });
  46. sinon.stub(App.StackServiceComponent, 'find', function(){
  47. return [
  48. Em.Object.create({
  49. componentName: 'ZOOKEEPER_CLIENT',
  50. serviceName: 'ZOOKEEPER'
  51. }),
  52. Em.Object.create({
  53. componentName: 'ZOOKEEPER_SERVER',
  54. serviceName: 'ZOOKEEPER'
  55. })
  56. ];
  57. });
  58. App.serviceComponents = ['ZOOKEEPER_SERVER', 'ZOOKEEPER_CLIENT'];
  59. });
  60. afterEach(function() {
  61. App.StackServiceComponent.find.restore();
  62. mixedObjectInstance.updateAndCreateServiceComponent.restore();
  63. mixedObjectInstance.onCreateComponent.restore();
  64. mixedObjectInstance.updateComponent.restore();
  65. mixedObjectInstance.checkInstalledComponents.restore();
  66. });
  67. it('should call `checkInstalledComponents` method', function() {
  68. mixedObjectInstance.createComponent('ZOOKEEPER_SERVER', 'host1', 'ZOOKEEPER');
  69. expect(mixedObjectInstance.checkInstalledComponents.called).to.be.true;
  70. });
  71. it('should call `checkInstalledComponents` method with host name converted to Array', function() {
  72. mixedObjectInstance.createComponent('ZOOKEEPER_SERVER', 'host1', 'ZOOKEEPER');
  73. expect(mixedObjectInstance.checkInstalledComponents.calledWith('ZOOKEEPER_SERVER', ['host1'])).to.be.true;
  74. });
  75. describe('no ZooKeeper Servers installed. install on host1, host2. ajax request should be called with appropriate params', function() {
  76. beforeEach(function () {
  77. mixedObjectInstance.createComponent('ZOOKEEPER_SERVER', ['host1', 'host2'], 'ZOOKEEPER');
  78. this.args = testHelpers.findAjaxRequest('name', 'wizard.step8.register_host_to_component')[0];
  79. this.queryObject = JSON.parse(this.args.data.data);
  80. });
  81. it('hostName is valid array', function () {
  82. expect(this.args.data.hostName).to.be.eql(['host1', 'host2']);
  83. });
  84. it('RequestInfo.query is valid', function () {
  85. expect(this.queryObject.RequestInfo.query).to.be.equal('Hosts/host_name=host1|Hosts/host_name=host2');
  86. });
  87. it('affected component is valid', function () {
  88. expect(this.queryObject.Body.host_components[0].HostRoles.component_name).to.be.equal('ZOOKEEPER_SERVER');
  89. });
  90. it('taskNum = 1', function () {
  91. expect(this.args.data.taskNum).to.be.equal(1);
  92. });
  93. it('updateComponent is called', function () {
  94. // invoke callback
  95. this.args.sender[this.args.success](null, null, this.args.data);
  96. expect(mixedObjectInstance.updateComponent.called).to.be.true;
  97. });
  98. });
  99. describe('ZooKeeper Client installed on host1. install on host1, host2. ajax request should be called with appropriate params', function() {
  100. beforeEach(function () {
  101. mixedObjectInstance.createComponent('ZOOKEEPER_CLIENT', ['host1', 'host2'], 'ZOOKEEPER');
  102. this.args = testHelpers.findAjaxRequest('name', 'wizard.step8.register_host_to_component')[0];
  103. this.queryObject = JSON.parse(this.args.data.data);
  104. });
  105. it('hostName is valid array', function () {
  106. expect(this.args.data.hostName).to.be.eql(['host1', 'host2']);
  107. });
  108. it('RequestInfo.query is valid', function () {
  109. expect(this.queryObject.RequestInfo.query).to.be.equal('Hosts/host_name=host2');
  110. });
  111. it('affected component is valid', function () {
  112. expect(this.queryObject.Body.host_components[0].HostRoles.component_name).to.be.equal('ZOOKEEPER_CLIENT');
  113. });
  114. it('onCreateComponent is not called', function () {
  115. expect(mixedObjectInstance.onCreateComponent.called).to.be.false;
  116. });
  117. it('updateComponent is called', function () {
  118. // invoke callback
  119. this.args.sender[this.args.success](null, null, this.args.data);
  120. expect(mixedObjectInstance.updateComponent.called).to.be.true;
  121. });
  122. });
  123. });
  124. describe('#updateComponent', function() {
  125. var testsAjax = [
  126. {
  127. callParams: ['ZOOKEEPER_SERVER', 'host1', 'ZOOKEEPER', 'Install', 1],
  128. e: [
  129. { key: 'data.HostRoles.state', value: 'INSTALLED'},
  130. { key: 'data.hostName[0]', value: 'host1'},
  131. { key: 'data.query', value: 'HostRoles/component_name=ZOOKEEPER_SERVER&HostRoles/host_name.in(host1)&HostRoles/maintenance_state=OFF'}
  132. ]
  133. },
  134. {
  135. callParams: ['ZOOKEEPER_SERVER', ['host1', 'host2'], 'ZOOKEEPER', 'start', 1],
  136. e: [
  137. { key: 'data.HostRoles.state', value: 'STARTED'},
  138. { key: 'data.hostName[0]', value: 'host1'},
  139. { key: 'data.hostName[1]', value: 'host2'},
  140. { key: 'data.query', value: 'HostRoles/component_name=ZOOKEEPER_SERVER&HostRoles/host_name.in(host1,host2)&HostRoles/maintenance_state=OFF'}
  141. ]
  142. }
  143. ];
  144. testsAjax.forEach(function(test) {
  145. describe('called with params: ' + JSON.stringify(test.callParams), function() {
  146. beforeEach(function() {
  147. var mixedObjectInstance = mixedObject.create({});
  148. mixedObjectInstance.updateComponent.apply(mixedObjectInstance, test.callParams);
  149. });
  150. test.e.forEach(function(eKey) {
  151. it('key: {0} should have value: {1}'.format(eKey.key, eKey.value), function() {
  152. var args = testHelpers.findAjaxRequest('name', 'common.host_components.update')[0];
  153. expect(args).to.have.deep.property(eKey.key, eKey.value);
  154. });
  155. });
  156. });
  157. });
  158. });
  159. describe('#createInstallComponentTask', function() {
  160. var mixedObjectInstance;
  161. beforeEach(function() {
  162. mixedObjectInstance = mixedObject.create({});
  163. sinon.stub(mixedObjectInstance, 'createComponent', Em.K);
  164. sinon.stub(mixedObjectInstance, 'onTaskError', Em.K);
  165. this.KDCStub = sinon.stub(App, 'get').withArgs('router.mainAdminKerberosController');
  166. });
  167. afterEach(function() {
  168. mixedObjectInstance.createComponent.restore();
  169. mixedObjectInstance.onTaskError.restore();
  170. mixedObjectInstance.destroy();
  171. mixedObjectInstance = null;
  172. App.get.restore();
  173. this.KDCStub = null;
  174. });
  175. it('when credentials are ok, createComponent method called', function() {
  176. this.KDCStub.returns({
  177. getKDCSessionState: Em.clb
  178. });
  179. mixedObjectInstance.createInstallComponentTask('componentName', 'hostName', 'serviceName');
  180. assert.isTrue(mixedObjectInstance.createComponent.calledOnce, 'createComponent should be called');
  181. assert.equal(JSON.stringify(mixedObjectInstance.createComponent.args[0]), JSON.stringify(['componentName', 'hostName', 'serviceName']), 'passed argument order should be the same');
  182. });
  183. it('when credentials are expired and KDC dialog cancelled task status should be changed to failed', function() {
  184. this.KDCStub.returns({
  185. getKDCSessionState: function(sCallback, eCallback) {
  186. eCallback();
  187. }
  188. });
  189. mixedObjectInstance.createInstallComponentTask('componentName', 'hostName', 'serviceName');
  190. assert.isFalse(mixedObjectInstance.createComponent.calledOnce, 'createComponent should not be called');
  191. assert.isTrue(mixedObjectInstance.onTaskError.called, 'onTaskError handler called');
  192. });
  193. });
  194. });