wizardProgressPageController_test.js 5.8 KB

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