wizardProgressPageController_test.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. describe('App.wizardProgressPageControllerMixin', function() {
  20. var mixedObject = Em.Object.extend(App.wizardProgressPageControllerMixin, {});
  21. describe('#createComponent', function() {
  22. var mixedObjectInstance;
  23. beforeEach(function() {
  24. mixedObjectInstance = mixedObject.create({});
  25. sinon.stub(App.ajax, 'send', function(params) {
  26. return $.extend(params,{complete: function(callback){
  27. callback();
  28. }});
  29. });
  30. sinon.stub(require('utils/components'), "updateAndCreateServiceComponent").returns({
  31. done: function(callback) {
  32. return callback();
  33. }
  34. });
  35. sinon.spy(mixedObjectInstance, 'onCreateComponent');
  36. sinon.spy(mixedObjectInstance, 'updateComponent');
  37. sinon.stub(mixedObjectInstance, 'checkInstalledComponents', function(componentName, hostNames) {
  38. var def = $.Deferred();
  39. var data = {
  40. 'ZOOKEEPER_SERVER': {
  41. items: []
  42. },
  43. 'ZOOKEEPER_CLIENT': {
  44. items: [
  45. { HostRoles: { host_name: 'host1' } }
  46. ]
  47. }
  48. };
  49. def.resolve(data[componentName]);
  50. return def.promise();
  51. });
  52. sinon.stub(App.StackServiceComponent, 'find', function(){
  53. return [
  54. Em.Object.create({
  55. componentName: 'ZOOKEEPER_CLIENT',
  56. serviceName: 'ZOOKEEPER'
  57. }),
  58. Em.Object.create({
  59. componentName: 'ZOOKEEPER_SERVER',
  60. serviceName: 'ZOOKEEPER'
  61. })
  62. ];
  63. });
  64. App.serviceComponents = ['ZOOKEEPER_SERVER', 'ZOOKEEPER_CLIENT'];
  65. });
  66. afterEach(function() {
  67. App.ajax.send.restore();
  68. App.StackServiceComponent.find.restore();
  69. require('utils/components').updateAndCreateServiceComponent.restore();
  70. mixedObjectInstance.onCreateComponent.restore();
  71. mixedObjectInstance.updateComponent.restore();
  72. mixedObjectInstance.checkInstalledComponents.restore();
  73. });
  74. it('should call `checkInstalledComponents` method', function() {
  75. mixedObjectInstance.createComponent('ZOOKEEPER_SERVER', 'host1', 'ZOOKEEPER');
  76. expect(mixedObjectInstance.checkInstalledComponents.called).to.be.true;
  77. });
  78. it('should call `checkInstalledComponents` method with host name converted to Array', function() {
  79. mixedObjectInstance.createComponent('ZOOKEEPER_SERVER', 'host1', 'ZOOKEEPER');
  80. expect(mixedObjectInstance.checkInstalledComponents.calledWith('ZOOKEEPER_SERVER', ['host1'])).to.be.true;
  81. });
  82. it('no ZooKeeper Servers installed. install on host1, host2. ajax request should be called with appropriate params', function() {
  83. mixedObjectInstance.createComponent('ZOOKEEPER_SERVER', ['host1', 'host2'], 'ZOOKEEPER');
  84. var args = App.ajax.send.args[0][0];
  85. var queryObject = JSON.parse(args.data.data);
  86. expect(args.data.hostName).to.be.eql(['host1', 'host2']);
  87. expect(queryObject.RequestInfo.query).to.be.eql('Hosts/host_name=host1|Hosts/host_name=host2');
  88. expect(queryObject.Body.host_components[0].HostRoles.component_name).to.be.eql('ZOOKEEPER_SERVER');
  89. expect(args.data.taskNum).to.be.eql(1);
  90. // invoke callback
  91. args.sender[args.success].apply(args.sender, [null, null, args.data]);
  92. expect(mixedObjectInstance.updateComponent.called).to.be.true;
  93. });
  94. it('ZooKeeper Client installed on host1. install on host1, host2. ajax request should be called with appropriate params', function() {
  95. mixedObjectInstance.createComponent('ZOOKEEPER_CLIENT', ['host1', 'host2'], 'ZOOKEEPER');
  96. var args = App.ajax.send.args[0][0];
  97. var queryObject = JSON.parse(args.data.data);
  98. expect(args.data.hostName).to.be.eql(['host1', 'host2']);
  99. expect(queryObject.RequestInfo.query).to.be.eql('Hosts/host_name=host2');
  100. expect(queryObject.Body.host_components[0].HostRoles.component_name).to.be.eql('ZOOKEEPER_CLIENT');
  101. expect(mixedObjectInstance.onCreateComponent.called).to.be.false;
  102. // invoke callback
  103. args.sender[args.success].apply(args.sender, [null, null, args.data]);
  104. expect(mixedObjectInstance.updateComponent.called).to.be.true;
  105. });
  106. });
  107. describe('#updateComponent', function() {
  108. var testsAjax = [
  109. {
  110. callParams: ['ZOOKEEPER_SERVER', 'host1', 'ZOOKEEPER', 'Install', 1],
  111. e: [
  112. { key: 'data.HostRoles.state', value: 'INSTALLED'},
  113. { key: 'data.hostName[0]', value: 'host1'},
  114. { key: 'data.query', value: 'HostRoles/component_name=ZOOKEEPER_SERVER&HostRoles/host_name.in(host1)&HostRoles/maintenance_state=OFF'}
  115. ]
  116. },
  117. {
  118. callParams: ['ZOOKEEPER_SERVER', ['host1', 'host2'], 'ZOOKEEPER', 'start', 1],
  119. e: [
  120. { key: 'data.HostRoles.state', value: 'STARTED'},
  121. { key: 'data.hostName[0]', value: 'host1'},
  122. { key: 'data.hostName[1]', value: 'host2'},
  123. { key: 'data.query', value: 'HostRoles/component_name=ZOOKEEPER_SERVER&HostRoles/host_name.in(host1,host2)&HostRoles/maintenance_state=OFF'}
  124. ]
  125. }
  126. ];
  127. testsAjax.forEach(function(test) {
  128. describe('called with params: ' + JSON.stringify(test.callParams), function() {
  129. before(function() {
  130. sinon.stub(App.ajax, 'send', Em.K);
  131. var mixedObjectInstance = mixedObject.create({});
  132. mixedObjectInstance.updateComponent.apply(mixedObjectInstance, test.callParams);
  133. });
  134. after(function() {
  135. App.ajax.send.restore();
  136. });
  137. test.e.forEach(function(eKey) {
  138. it('key: {0} should have value: {1}'.format(eKey.key, eKey.value), function() {
  139. var args = App.ajax.send.args[0][0];
  140. expect(args).to.have.deep.property(eKey.key, eKey.value);
  141. });
  142. });
  143. });
  144. });
  145. });
  146. });