step3_controller_test.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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.KerberosWizardStep3Controller', function() {
  21. var controller;
  22. beforeEach(function() {
  23. controller = App.KerberosWizardStep3Controller.create({});
  24. });
  25. describe('#onTestKerberosError', function() {
  26. beforeEach(function(){
  27. sinon.stub(App.ajax, 'defaultErrorHandler', Em.K);
  28. sinon.stub(controller, 'onTaskError', Em.K);
  29. });
  30. afterEach(function(){
  31. App.ajax.defaultErrorHandler.restore();
  32. controller.onTaskError.restore();
  33. });
  34. it('should call App.ajax.defaultErrorHandler and onTaskError', function () {
  35. controller.onTestKerberosError({status: 3}, null, null, {url: 1, type: 2});
  36. expect(App.ajax.defaultErrorHandler.calledWith({status: 3}, 1, 2, 3)).to.be.true;
  37. expect(controller.onTaskError.calledOnce).to.be.true;
  38. });
  39. });
  40. describe("#loadStep()", function () {
  41. beforeEach(function() {
  42. sinon.stub(controller, 'enableDisablePreviousSteps');
  43. });
  44. afterEach(function() {
  45. controller.enableDisablePreviousSteps.restore();
  46. });
  47. it("enableDisablePreviousSteps should be called", function() {
  48. controller.loadStep();
  49. expect(controller.enableDisablePreviousSteps.calledOnce).to.be.true;
  50. });
  51. });
  52. describe("#installKerberos()", function () {
  53. beforeEach(function() {
  54. this.mock = sinon.stub(controller, 'getKerberosClientState');
  55. sinon.stub(controller, 'updateComponent');
  56. });
  57. afterEach(function() {
  58. this.mock.restore();
  59. controller.updateComponent.restore();
  60. });
  61. it("not INIT state", function() {
  62. this.mock.returns({
  63. done: function(callback) {
  64. callback({ServiceComponentInfo: {
  65. state: ""
  66. }});
  67. }
  68. });
  69. App.set('allHostNames', ['host1']);
  70. controller.installKerberos();
  71. expect(controller.updateComponent.calledWith('KERBEROS_CLIENT', ['host1'], "KERBEROS", "Install")).to.be.true;
  72. });
  73. it("INIT state", function() {
  74. this.mock.returns({
  75. done: function(callback) {
  76. callback({ServiceComponentInfo: {
  77. state: "INIT"
  78. }});
  79. }
  80. });
  81. controller.installKerberos();
  82. var args = testHelpers.findAjaxRequest('name', 'common.services.update');
  83. expect(args[0]).to.be.eql({
  84. name: 'common.services.update',
  85. sender: controller,
  86. data: {
  87. context: Em.I18n.t('requestInfo.kerberosService'),
  88. ServiceInfo: {"state": "INSTALLED"},
  89. urlParams: "ServiceInfo/state=INSTALLED&ServiceInfo/service_name=KERBEROS"
  90. },
  91. success: 'startPolling',
  92. error: 'onTaskError'
  93. });
  94. });
  95. });
  96. describe("#getKerberosClientState()", function () {
  97. it("App.ajax.send should be called", function() {
  98. controller.setProperties({
  99. serviceName: 'S1',
  100. componentName: 'C1'
  101. });
  102. controller.getKerberosClientState();
  103. var args = testHelpers.findAjaxRequest('name', 'common.service_component.info');
  104. expect(args[0]).to.be.eql({
  105. name: 'common.service_component.info',
  106. sender: controller,
  107. data: {
  108. serviceName: 'S1',
  109. componentName: 'C1',
  110. urlParams: "fields=ServiceComponentInfo/state"
  111. }
  112. });
  113. });
  114. });
  115. describe("#testKerberos()", function () {
  116. it("App.ajax.send should be called", function() {
  117. controller.testKerberos();
  118. var args = testHelpers.findAjaxRequest('name', 'service.item.smoke');
  119. expect(args[0]).to.exists;
  120. });
  121. });
  122. describe("#onTestKerberosError()", function () {
  123. beforeEach(function() {
  124. sinon.stub(App.ajax, 'defaultErrorHandler');
  125. sinon.stub(controller, 'onTaskError');
  126. controller.onTestKerberosError({status: 's1'}, {}, "error", {type: 't1', url: 'u1'});
  127. });
  128. afterEach(function() {
  129. App.ajax.defaultErrorHandler.restore();
  130. controller.onTaskError.restore();
  131. });
  132. it("App.ajax.defaultErrorHandler should be called", function() {
  133. expect(App.ajax.defaultErrorHandler.calledWith({status: 's1'}, 'u1', 't1', 's1')).to.be.true;
  134. });
  135. it("onTaskError should be called", function() {
  136. expect(controller.onTaskError.calledWith({status: 's1'}, {}, "error", {type: 't1', url: 'u1'})).to.be.true;
  137. });
  138. });
  139. describe("#enableDisablePreviousSteps()", function () {
  140. var mock = {
  141. setStepsEnable: Em.K,
  142. setLowerStepsDisable: Em.K
  143. };
  144. beforeEach(function() {
  145. sinon.stub(App.router, 'get').returns(mock);
  146. sinon.stub(mock, 'setStepsEnable');
  147. sinon.stub(mock, 'setLowerStepsDisable');
  148. });
  149. afterEach(function() {
  150. App.router.get.restore();
  151. mock.setStepsEnable.restore();
  152. mock.setLowerStepsDisable.restore();
  153. });
  154. it("setLowerStepsDisable should be called", function() {
  155. controller.set('tasks', [{
  156. status: 'COMPLETED'
  157. }]);
  158. controller.enableDisablePreviousSteps();
  159. expect(mock.setLowerStepsDisable.calledWith(3)).to.be.true;
  160. });
  161. it("setStepsEnable should be called", function() {
  162. controller.set('tasks', [{
  163. status: 'FAILED'
  164. }]);
  165. controller.enableDisablePreviousSteps();
  166. expect(mock.setStepsEnable.called).to.be.true;
  167. });
  168. });
  169. describe("#ignoreAndProceed()", function () {
  170. it("isSubmitDisabled should be true", function() {
  171. controller.setProperties({
  172. showIgnore: true,
  173. ignore: false
  174. });
  175. controller.ignoreAndProceed();
  176. expect(controller.get('isSubmitDisabled')).to.be.true;
  177. });
  178. it("isSubmitDisabled should be false", function() {
  179. controller.setProperties({
  180. showIgnore: true,
  181. ignore: true
  182. });
  183. controller.ignoreAndProceed();
  184. expect(controller.get('isSubmitDisabled')).to.be.true;
  185. });
  186. it("isSubmitDisabled should not be changed", function() {
  187. controller.setProperties({
  188. showIgnore: false,
  189. ignore: true,
  190. isSubmitDisabled: false
  191. });
  192. controller.ignoreAndProceed();
  193. expect(controller.get('isSubmitDisabled')).to.be.false;
  194. });
  195. });
  196. });