step2_test.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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 Ember = require('ember');
  20. require('controllers/wizard/step2_controller');
  21. require('models/host');
  22. require('models/host_component');
  23. require('messages');
  24. describe('App.WizardStep2Controller', function () {
  25. describe('#updateHostNameArr()', function () {
  26. var controller = App.WizardStep2Controller.create({
  27. hostNames: 'apache.ambari'
  28. });
  29. App.store.load(App.Host, {'host_name': 'apache.ambari', id: '1'});
  30. controller.updateHostNameArr();
  31. it('should push to hostNameArr only new host names', function(){
  32. expect(controller.get('hostNameArr').length).to.equal(0);
  33. })
  34. it('should push to inputtedAgainHostNames already installed host names', function(){
  35. expect(controller.get('inputtedAgainHostNames').length).to.equal(1);
  36. })
  37. })
  38. describe('#isAllHostNamesValid()', function () {
  39. var controller = App.WizardStep2Controller.create({
  40. hostNames: ''
  41. });
  42. it('should return true if all host names are valid', function(){
  43. controller.set('hostNames', 'amache.org ambari.com');
  44. expect(controller.isAllHostNamesValid()).to.equal(true);
  45. })
  46. var tests = [
  47. 'hostname',
  48. '-hostname.com',
  49. 'hostname-.com',
  50. 'host_name.com',
  51. '123.123.123.123',
  52. 'hostnamehostnamehostnamehostnamehostnamehostnamehostnamehostname.hostnamehostnamehostnamehostnamehostnamehostnamehostnamehostname.hostnamehostnamehostnamehostnamehostnamehostnamehostnamehostname.hostnamehostnamehostnamehostnamehostnamehostnamehostnamehostname',
  53. 'hostnamehostnamehostnamehostnamehostnamehostnamehostnamehostnamehostname.hostname'
  54. ];
  55. tests.forEach(function (test) {
  56. it('should return false for invalid host names ' + test + ' ', function () {
  57. controller.set('hostNames', test);
  58. expect(controller.isAllHostNamesValid()).to.equal(false);
  59. });
  60. });
  61. })
  62. describe('#checkHostError()', function () {
  63. var controller = App.WizardStep2Controller.create();
  64. it('should set hostsError if hostNames is ""', function () {
  65. controller.set('content', {'installOptions': {'hostNames': ''}});
  66. controller.checkHostError();
  67. expect(controller.get('hostsError').length).to.be.above(2);
  68. })
  69. /*it('should set hostsError if hostNames is invalid', function () {
  70. controller.set('content', {'installOptions': {'hostNames': '@#$%'}});
  71. controller.checkHostError();
  72. expect(controller.get('hostsError').length).to.be.above(2);
  73. })*/
  74. it('should set hostsError to null if hostNames is valid', function () {
  75. controller.set('content', {'installOptions': {'hostNames': 'ambari'}});
  76. controller.checkHostError();
  77. expect(controller.get('hostsError')).to.equal(null);
  78. })
  79. })
  80. describe('#checkHostAfterSubmitHandler()', function () {
  81. it('should be called after changing hasSubmitted', function (done) {
  82. var controller = App.WizardStep2Controller.create({
  83. checkHostError: function () {
  84. done();
  85. }
  86. });
  87. controller.set('hasSubmitted', true);
  88. })
  89. it('should be called after changing hostNames', function (done) {
  90. var controller = App.WizardStep2Controller.create({
  91. hasSubmitted: true,
  92. checkHostError: function () {
  93. done();
  94. }
  95. });
  96. controller.set('content', {'installOptions': {'hostNames': 'ambari'}});
  97. })
  98. })
  99. describe('#sshKeyError', function () {
  100. var controller = App.WizardStep2Controller.create({
  101. manualInstall: false,
  102. sshKey: '',
  103. hasSubmitted: true
  104. });
  105. it('should return error message if hasSubmitted is true, manualInstall is false and sshKey is ""', function () {
  106. expect(controller.get('sshKeyError').length).to.be.above(2);
  107. })
  108. it('should return null if hasSubmitted is false', function () {
  109. controller.set('hasSubmitted', false);
  110. expect(controller.get('sshKeyError')).to.equal(null);
  111. })
  112. })
  113. describe('#getHostInfo()', function () {
  114. it('should return object with bootStatus, installType and name for every element in hostNameArr', function () {
  115. var controller = App.WizardStep2Controller.create({
  116. hostNameArr: ['apache', 'ambari'],
  117. installType: 'manualDriven'
  118. });
  119. var test = controller.getHostInfo();
  120. expect(test).to.eql({
  121. 'apache':{'name':'apache', 'installType': 'manualDriven', 'bootStatus': 'PENDING'},
  122. 'ambari':{'name':'ambari', 'installType': 'manualDriven', 'bootStatus': 'PENDING'}
  123. });
  124. })
  125. })
  126. describe('#setSshKey()', function () {
  127. it('should set content.installOptions.sshKey', function () {
  128. var controller = App.WizardStep2Controller.create({
  129. content: {'installOptions': {'sshKey': '111'}}
  130. });
  131. controller.setSshKey('222');
  132. expect(controller.get('content.installOptions.sshKey')).to.equal('222');
  133. })
  134. })
  135. describe('#evaluateStep()', function () {
  136. it('should return false if isSubmitDisabled is true', function () {
  137. var controller = App.WizardStep2Controller.create({
  138. hostNames: 'apache.ambari'
  139. });
  140. controller.set('isSubmitDisabled', true);
  141. expect(controller.evaluateStep()).to.equal(false);
  142. })
  143. it('should return false if hostsError is not empty', function () {
  144. var controller = App.WizardStep2Controller.create({
  145. hostNames: 'apache.ambari'
  146. });
  147. controller.set('hostsError', 'error');
  148. expect(controller.evaluateStep()).to.equal(false);
  149. })
  150. it('should return false if sshKeyError is not empty', function () {
  151. var controller = App.WizardStep2Controller.create({
  152. hostNames: 'apache.ambari'
  153. });
  154. controller.set('sshKeyError', 'error');
  155. expect(controller.evaluateStep()).to.equal(false);
  156. })
  157. it('should return false if hostNameArr is empty', function () {
  158. var controller = App.WizardStep2Controller.create({
  159. hostNames: ''
  160. });
  161. expect(controller.evaluateStep()).to.equal(false);
  162. })
  163. it('should return false if isPattern is false', function () {
  164. var controller = App.WizardStep2Controller.create({
  165. hostNames: 'apache.ambari',
  166. isPattern: false
  167. });
  168. expect(controller.evaluateStep()).to.equal(false);
  169. })
  170. })
  171. describe('#patternExpression()', function () {
  172. it('should parse hosts from pattern expression to hostNameArr', function () {
  173. var controller = App.WizardStep2Controller.create({
  174. hostNameArr: ['host[001-011]']
  175. });
  176. controller.patternExpression();
  177. var result = true;
  178. var hosts = controller.get('hostNameArr');
  179. for (var i = 1; i<12; i++) {
  180. var extra = (i.toString().length == 1) ? 0 : '';
  181. if (hosts[i-1] !== 'host0' + extra + i) {
  182. result = false;
  183. }
  184. }
  185. expect(result).to.equal(true);
  186. })
  187. })
  188. describe('#proceedNext()', function () {
  189. it('should call manualInstallPopup if manualInstall is true', function (done) {
  190. var controller = App.WizardStep2Controller.create({
  191. hostNames: '',
  192. manualInstall: true,
  193. manualInstallPopup: function () {
  194. done();
  195. }
  196. });
  197. controller.proceedNext(true);
  198. })
  199. })
  200. describe('#isSubmitDisabled', function () {
  201. var controller = App.WizardStep2Controller.create({
  202. hostsError: '',
  203. sshKeyError: ''
  204. });
  205. it('should return value if hostsError is not empty', function () {
  206. controller.set('hostsError', 'error');
  207. expect(controller.get('isSubmitDisabled').length).to.above(0);
  208. })
  209. it('should return value if sshKeyError is not empty', function () {
  210. controller.set('sshKeyError', 'error');
  211. controller.set('hostsError', '');
  212. expect(controller.get('isSubmitDisabled').length).to.above(0);
  213. })
  214. })
  215. /*describe('#saveHosts()', function () {
  216. var controller = App.WizardStep2Controller.create({
  217. hostNameArr: ['ambari']
  218. });
  219. controller.set('content', Ember.Object.create({'hosts':Ember.Object.create({})}));
  220. App.router = Ember.Object.create({
  221. send:function() {}
  222. });
  223. it('should set content.hosts', function () {
  224. controller.saveHosts();
  225. expect(controller.get('content.hosts')).to.not.be.empty;
  226. })
  227. })*/
  228. })