wizardProgressPageController_test.js 6.2 KB

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