step2_test.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  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. var c;
  25. describe('App.WizardStep2Controller', function () {
  26. var userErrorTests = Em.A([
  27. {
  28. manualInstall: false,
  29. user: '',
  30. sshPort:'',
  31. e: ''
  32. },
  33. {
  34. manualInstall: true,
  35. user: '',
  36. sshPort:'',
  37. e: null
  38. },
  39. {
  40. manualInstall: true,
  41. user: 'nobody',
  42. sshPort:'123',
  43. e: null
  44. },
  45. {
  46. manualInstall: false,
  47. user: 'nobody',
  48. sshPort:'123',
  49. e: null
  50. }
  51. ]);
  52. beforeEach(function() {
  53. c = App.WizardStep2Controller.create();
  54. });
  55. describe('#isInstaller', function() {
  56. it('true if controllerName is installerController', function() {
  57. var controller = App.WizardStep2Controller.create({content: {controllerName: 'installerController'}});
  58. expect(controller.get('isInstaller')).to.equal(true);
  59. });
  60. it('false if controllerName isn\'t installerController', function() {
  61. var controller = App.WizardStep2Controller.create({content: {controllerName: 'addServiceController'}});
  62. expect(controller.get('isInstaller')).to.equal(false);
  63. });
  64. });
  65. describe('#manualInstall', function() {
  66. it('should be equal to content.installOptions.manualInstall', function() {
  67. var controller = App.WizardStep2Controller.create({content: {installOptions: {manualInstall: true}}});
  68. expect(controller.get('manualInstall')).to.equal(true);
  69. controller.toggleProperty('content.installOptions.manualInstall');
  70. expect(controller.get('manualInstall')).to.equal(false);
  71. });
  72. });
  73. describe('#hostNames', function() {
  74. it('should be equal to content.installOptions.hostNames', function() {
  75. var controller = App.WizardStep2Controller.create({content: {installOptions: {hostNames: 'A,b,C'}}});
  76. expect(controller.get('hostNames')).to.equal('a,b,c');
  77. controller.set('content.installOptions.hostNames', 'a,B');
  78. expect(controller.get('hostNames')).to.equal('a,b');
  79. });
  80. });
  81. describe('#sshKey', function() {
  82. it('should be equal to content.installOptions.sshKey', function() {
  83. var controller = App.WizardStep2Controller.create({content: {installOptions: {sshKey: '123'}}});
  84. expect(controller.get('sshKey')).to.equal('123');
  85. controller.set('content.installOptions.sshKey', '321');
  86. expect(controller.get('sshKey')).to.equal('321');
  87. });
  88. });
  89. describe('#sshUser', function() {
  90. it('should be equal to content.installOptions.sshUser', function() {
  91. var controller = App.WizardStep2Controller.create({content: {installOptions: {sshUser: '123'}}});
  92. expect(controller.get('sshUser')).to.equal('123');
  93. controller.set('content.installOptions.sshUser', '321');
  94. expect(controller.get('sshUser')).to.equal('321');
  95. });
  96. });
  97. describe('#sshPort', function() {
  98. it('should be equal to content.installOptions.sshPort', function() {
  99. var controller = App.WizardStep2Controller.create({content: {installOptions: {sshPort: '123'}}});
  100. expect(controller.get('sshPort')).to.equal('123');
  101. controller.set('content.installOptions.sshPort', '321');
  102. expect(controller.get('sshPort')).to.equal('321');
  103. });
  104. });
  105. describe('#agentUser', function() {
  106. it('should be equal to content.installOptions.agentUser', function() {
  107. var controller = App.WizardStep2Controller.create({content: {installOptions: {agentUser: '123'}}});
  108. expect(controller.get('agentUser')).to.equal('123');
  109. controller.set('content.installOptions.agentUser', '321');
  110. expect(controller.get('agentUser')).to.equal('321');
  111. });
  112. });
  113. describe('#installType', function() {
  114. it('should be manualDriven if manualInstall is selected', function() {
  115. var controller = App.WizardStep2Controller.create({content: {installOptions: {manualInstall: true}}});
  116. expect(controller.get('installType')).to.equal('manualDriven');
  117. });
  118. it('should be ambariDriven if manualInstall isn\'t selected', function() {
  119. var controller = App.WizardStep2Controller.create({content: {installOptions: {manualInstall: false}}});
  120. expect(controller.get('installType')).to.equal('ambariDriven');
  121. });
  122. });
  123. describe('#updateHostNameArr()', function () {
  124. var controller = App.WizardStep2Controller.create({
  125. hostNames: 'apache.ambari'
  126. });
  127. controller.updateHostNameArr();
  128. it('should push to hostNameArr only new host names', function(){
  129. expect(controller.get('hostNameArr').length).to.equal(1);
  130. });
  131. it('should push to inputtedAgainHostNames already installed host names', function(){
  132. expect(controller.get('inputtedAgainHostNames').length).to.equal(0);
  133. })
  134. });
  135. describe('#isAllHostNamesValid()', function () {
  136. var controller = App.WizardStep2Controller.create({
  137. hostNames: ''
  138. });
  139. it('should return true if all host names are valid', function(){
  140. controller.set('hostNames', 'amache.org ambari.com');
  141. expect(controller.isAllHostNamesValid()).to.equal(true);
  142. });
  143. var tests = Em.A([
  144. 'hostname',
  145. '-hostname.com',
  146. 'hostname-.com',
  147. 'host_name.com',
  148. '123.123.123.123',
  149. 'hostnamehostnamehostnamehostnamehostnamehostnamehostnamehostname.hostnamehostnamehostnamehostnamehostnamehostnamehostnamehostname.hostnamehostnamehostnamehostnamehostnamehostnamehostnamehostname.hostnamehostnamehostnamehostnamehostnamehostnamehostnamehostname',
  150. 'hostnamehostnamehostnamehostnamehostnamehostnamehostnamehostnamehostname.hostname'
  151. ]);
  152. tests.forEach(function (test) {
  153. it('should return false for invalid host names ' + test + ' ', function () {
  154. controller.set('hostNames', test);
  155. expect(controller.isAllHostNamesValid()).to.equal(false);
  156. });
  157. });
  158. });
  159. describe('#checkHostError()', function () {
  160. var controller = App.WizardStep2Controller.create();
  161. it('should set hostsError if hostNames is ""', function () {
  162. controller.set('content', {'installOptions': {'hostNames': ''}});
  163. controller.checkHostError();
  164. expect(controller.get('hostsError').length).to.be.above(2);
  165. });
  166. it('should set hostsError to null if hostNames is valid', function () {
  167. controller.set('content', {'installOptions': {'hostNames': 'ambari'}});
  168. controller.checkHostError();
  169. expect(controller.get('hostsError')).to.equal(null);
  170. })
  171. });
  172. describe('#checkHostAfterSubmitHandler()', function () {
  173. it('should be called after changing hasSubmitted', function (done) {
  174. var controller = App.WizardStep2Controller.create({
  175. checkHostError: function () {
  176. done();
  177. }
  178. });
  179. controller.set('hasSubmitted', true);
  180. });
  181. it('should be called after changing hostNames', function (done) {
  182. var controller = App.WizardStep2Controller.create({
  183. hasSubmitted: true,
  184. checkHostError: function () {
  185. done();
  186. }
  187. });
  188. controller.set('content', {'installOptions': {'hostNames': 'ambari'}});
  189. })
  190. });
  191. describe('#sshKeyError', function () {
  192. var tests = Em.A([
  193. {
  194. manualInstall: false,
  195. sshKey: '',
  196. hasSubmitted: false,
  197. e: null
  198. },
  199. {
  200. manualInstall: true,
  201. sshKey: '',
  202. hasSubmitted: false,
  203. e: null
  204. },
  205. {
  206. manualInstall: true,
  207. sshKey: 'nobody',
  208. hasSubmitted: false,
  209. e: null
  210. },
  211. {
  212. manualInstall: false,
  213. sshKey: 'nobody',
  214. hasSubmitted: false,
  215. e: null
  216. },
  217. {
  218. manualInstall: false,
  219. sshKey: '',
  220. hasSubmitted: true,
  221. e: null
  222. },
  223. {
  224. manualInstall: true,
  225. sshKey: '',
  226. hasSubmitted: true,
  227. e: null
  228. },
  229. {
  230. manualInstall: true,
  231. sshKey: 'nobody',
  232. hasSubmitted: true,
  233. e: null
  234. },
  235. {
  236. manualInstall: false,
  237. sshKey: 'nobody',
  238. hasSubmitted: true,
  239. e: null
  240. }
  241. ]);
  242. tests.forEach(function(test) {
  243. it(test.sshKey + ' ' + test.manualInstall.toString() + ' ' + test.hasSubmitted.toString(), function() {
  244. var controller = App.WizardStep2Controller.create({content: {installOptions: {manualInstall: test.manualInstall, sshKey: test.sshKey}}});
  245. if(Em.isNone(test.e)) {
  246. expect(controller.get('sshKeyError')).to.equal(null);
  247. }
  248. else {
  249. expect(controller.get('sshKeyError').length).to.be.above(2);
  250. }
  251. });
  252. });
  253. });
  254. describe('#sshUserError', function () {
  255. userErrorTests.forEach(function(test) {
  256. it('', function() {
  257. var controller = App.WizardStep2Controller.create({content: {installOptions: {manualInstall: test.manualInstall, sshUser: test.user}}});
  258. if(Em.isNone(test.e)) {
  259. expect(controller.get('sshUserError')).to.equal(null);
  260. }
  261. else {
  262. expect(controller.get('sshUserError').length).to.be.above(2);
  263. }
  264. });
  265. });
  266. });
  267. describe('#sshPortError', function () {
  268. userErrorTests.forEach(function(test) {
  269. it('', function() {
  270. var controller = App.WizardStep2Controller.create({content: {installOptions: {manualInstall: test.manualInstall, sshPort: test.sshPort}}});
  271. if(Em.isNone(test.e)) {
  272. expect(controller.get('sshPortError')).to.equal(null);
  273. }
  274. else {
  275. expect(controller.get('sshPortError').length).to.be.above(2);
  276. }
  277. });
  278. });
  279. });
  280. describe('#agentUserError', function () {
  281. afterEach(function () {
  282. App.get.restore();
  283. });
  284. userErrorTests.forEach(function(test) {
  285. it('Ambari Agent user account customize enabled', function() {
  286. sinon.stub(App, 'get').withArgs('supports.customizeAgentUserAccount').returns(true);
  287. var controller = App.WizardStep2Controller.create({content: {installOptions: {manualInstall: test.manualInstall, agentUser: test.user}}});
  288. if(Em.isNone(test.e)) {
  289. expect(controller.get('agentUserError')).to.be.null;
  290. }
  291. else {
  292. expect(controller.get('agentUserError').length).to.be.above(2);
  293. }
  294. });
  295. });
  296. userErrorTests.forEach(function(test) {
  297. it('Ambari Agent user account customize disabled', function() {
  298. sinon.stub(App, 'get').withArgs('supports.customizeAgentUserAccount').returns(false);
  299. var controller = App.WizardStep2Controller.create({content: {installOptions: {manualInstall: test.manualInstall, agentUser: test.user}}});
  300. expect(controller.get('agentUserError')).to.be.null;
  301. });
  302. });
  303. });
  304. describe('#getHostInfo()', function () {
  305. it('should return object with bootStatus, installType and name for every element in hostNameArr', function () {
  306. var controller = App.WizardStep2Controller.create({
  307. hostNameArr: ['apache', 'ambari'],
  308. installType: 'manualDriven'
  309. });
  310. var test = controller.getHostInfo();
  311. expect(test).to.eql({
  312. 'apache':{'name':'apache', 'installType': 'manualDriven', 'bootStatus': 'PENDING', isInstalled: false},
  313. 'ambari':{'name':'ambari', 'installType': 'manualDriven', 'bootStatus': 'PENDING', isInstalled: false}
  314. });
  315. })
  316. });
  317. describe('#setSshKey()', function () {
  318. it('should set content.installOptions.sshKey', function () {
  319. var controller = App.WizardStep2Controller.create({
  320. content: {'installOptions': {'sshKey': '111'}}
  321. });
  322. controller.setSshKey('222');
  323. expect(controller.get('content.installOptions.sshKey')).to.equal('222');
  324. })
  325. });
  326. describe('#evaluateStep()', function () {
  327. it('should return false if isSubmitDisabled is true', function () {
  328. var controller = App.WizardStep2Controller.create({
  329. hostNames: 'apache.ambari',
  330. parseHostNamesAsPatternExpression: Em.K
  331. });
  332. controller.reopen({isSubmitDisabled: true});
  333. expect(controller.evaluateStep()).to.equal(false);
  334. });
  335. it('should return false if hostsError is not empty', function () {
  336. var controller = App.WizardStep2Controller.create({
  337. hostNames: 'apache.ambari',
  338. parseHostNamesAsPatternExpression: Em.K
  339. });
  340. controller.set('hostsError', 'error');
  341. expect(controller.evaluateStep()).to.equal(false);
  342. });
  343. it('should return false if sshKeyError is not empty', function () {
  344. var controller = App.WizardStep2Controller.create({
  345. hostNames: 'apache.ambari',
  346. parseHostNamesAsPatternExpression: Em.K
  347. });
  348. controller.reopen({sshKeyError: 'error'});
  349. expect(controller.evaluateStep()).to.equal(false);
  350. });
  351. it('should return false if sshUserError is not empty', function () {
  352. var controller = App.WizardStep2Controller.create({
  353. hostNames: 'apache.ambari',
  354. parseHostNamesAsPatternExpression: Em.K
  355. });
  356. controller.reopen({sshUserError: 'error'});
  357. expect(controller.evaluateStep()).to.equal(false);
  358. });
  359. it('should return false if sshPortError is not empty', function () {
  360. var controller = App.WizardStep2Controller.create({
  361. hostNames: 'apache.ambari',
  362. parseHostNamesAsPatternExpression: Em.K
  363. });
  364. controller.reopen({sshPortError: 'error'});
  365. expect(controller.evaluateStep()).to.equal(false);
  366. });
  367. it('should return false if agentUserError is not empty', function () {
  368. var controller = App.WizardStep2Controller.create({
  369. hostNames: 'apache.ambari',
  370. parseHostNamesAsPatternExpression: Em.K
  371. });
  372. controller.reopen({agentUserError: 'error'});
  373. expect(controller.evaluateStep()).to.equal(false);
  374. });
  375. it('should return false if hostNameArr is empty', function () {
  376. var controller = App.WizardStep2Controller.create({
  377. hostNames: '',
  378. parseHostNamesAsPatternExpression: Em.K
  379. });
  380. expect(controller.evaluateStep()).to.equal(false);
  381. });
  382. it('should return false if isPattern is true', function () {
  383. var controller = App.WizardStep2Controller.create({
  384. hostNames: 'apache.ambari',
  385. isPattern: true,
  386. parseHostNamesAsPatternExpression: Em.K
  387. });
  388. expect(controller.evaluateStep()).to.equal(false);
  389. })
  390. });
  391. describe('#parseHostNamesAsPatternExpression()', function () {
  392. it('should parse hosts from pattern expression to hostNameArr', function () {
  393. var controller = App.WizardStep2Controller.create({
  394. hostNameArr: ['host[001-011]']
  395. });
  396. controller.parseHostNamesAsPatternExpression();
  397. var result = true;
  398. var hosts = controller.get('hostNameArr');
  399. for (var i = 1; i<12; i++) {
  400. var extra = (i.toString().length == 1) ? 0 : '';
  401. if (hosts[i-1] !== 'host0' + extra + i) {
  402. result = false;
  403. }
  404. }
  405. expect(result).to.equal(true);
  406. });
  407. it('should skip duplicates', function () {
  408. var controller = App.WizardStep2Controller.create({
  409. hostNameArr: ['host[1-3]', 'host2']
  410. });
  411. controller.parseHostNamesAsPatternExpression();
  412. expect(controller.get('hostNameArr')).to.eql(['host1', 'host2', 'host3']);
  413. });
  414. });
  415. describe('#proceedNext()', function () {
  416. it('should call warningPopup if not isAllHostNamesValid and no warningConfirmed', function() {
  417. c.reopen({
  418. isAllHostNamesValid: function() {
  419. return false;
  420. },
  421. warningPopup: Em.K
  422. });
  423. sinon.spy(c, 'warningPopup');
  424. var r = c.proceedNext(false);
  425. expect(r).to.equal(false);
  426. expect(c.warningPopup.calledOnce).to.equal(true);
  427. });
  428. it('should call manualInstallPopup if manualInstall is true', function () {
  429. c.reopen({
  430. hostNames: '',
  431. manualInstall: true,
  432. manualInstallPopup: Em.K
  433. });
  434. sinon.spy(c, 'manualInstallPopup');
  435. var r = c.proceedNext(true);
  436. expect(r).to.equal(false);
  437. expect(c.manualInstallPopup.calledOnce).to.equal(true);
  438. });
  439. it ('should save hosts and proceed next if manualInstall is false', function() {
  440. sinon.stub(App.router, 'send', Em.K);
  441. c.reopen({
  442. hostNameArr: ['h1'],
  443. manualInstall: false,
  444. isAllHostNamesValid: function() {return true;},
  445. content: {
  446. installOptions: {},
  447. hosts: null
  448. }
  449. });
  450. var r = c.proceedNext();
  451. expect(r).to.equal(true);
  452. expect(Em.keys(c.get('content.hosts'))).to.eql(['h1']);
  453. expect(App.router.send.calledWith('next')).to.equal(true);
  454. App.router.send.restore();
  455. });
  456. });
  457. describe('#isSubmitDisabled', function () {
  458. var controller = App.WizardStep2Controller.create({
  459. hostsError: '',
  460. sshKeyError: '',
  461. sshUserError: '',
  462. sshPortError: '',
  463. agentUserError: ''
  464. });
  465. it('should return value if hostsError is not empty', function () {
  466. controller.set('hostsError', 'error');
  467. expect(controller.get('isSubmitDisabled').length).to.above(0);
  468. });
  469. it('should return value if sshKeyError is not empty', function () {
  470. controller.set('sshKeyError', 'error');
  471. controller.set('hostsError', '');
  472. expect(controller.get('isSubmitDisabled').length).to.above(0);
  473. });
  474. it('should return value if sshUserError is not empty', function () {
  475. controller.set('sshUserError', 'error');
  476. controller.set('sshKeyError', '');
  477. expect(controller.get('isSubmitDisabled').length).to.above(0);
  478. });
  479. it('should return value if agentUserError is not empty', function () {
  480. controller.set('agentUserError', 'error');
  481. controller.set('sshUserError', '');
  482. expect(controller.get('isSubmitDisabled').length).to.above(0);
  483. });
  484. it('should return value if sshPortError is not empty', function () {
  485. controller.set('sshPortError', 'error');
  486. controller.set('agentUserError', '');
  487. expect(controller.get('isSubmitDisabled').length).to.above(0);
  488. });
  489. });
  490. describe('#installedHostsPopup', function() {
  491. beforeEach(function() {
  492. sinon.spy(App.ModalPopup, 'show');
  493. sinon.stub(c, 'proceedNext', Em.K);
  494. });
  495. afterEach(function() {
  496. App.ModalPopup.show.restore();
  497. c.proceedNext.restore();
  498. });
  499. it('should call App.ModalPopup.show', function() {
  500. c.installedHostsPopup();
  501. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  502. });
  503. it('should proceed next on primary', function() {
  504. c.installedHostsPopup().onPrimary();
  505. expect(c.proceedNext.calledOnce).to.equal(true);
  506. });
  507. });
  508. describe('#warningPopup', function() {
  509. beforeEach(function() {
  510. sinon.spy(App.ModalPopup, 'show');
  511. sinon.stub(c, 'proceedNext', Em.K);
  512. });
  513. afterEach(function() {
  514. App.ModalPopup.show.restore();
  515. c.proceedNext.restore();
  516. });
  517. it('should call App.ModalPopup.show', function() {
  518. c.warningPopup();
  519. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  520. });
  521. it('should proceed next on primary', function() {
  522. c.warningPopup().onPrimary();
  523. expect(c.proceedNext.calledWith(true)).to.equal(true);
  524. });
  525. });
  526. describe('#hostNamePatternPopup', function() {
  527. beforeEach(function() {
  528. sinon.spy(App.ModalPopup, 'show');
  529. sinon.stub(c, 'proceedNext', Em.K);
  530. });
  531. afterEach(function() {
  532. App.ModalPopup.show.restore();
  533. c.proceedNext.restore();
  534. });
  535. it('should call App.ModalPopup.show', function() {
  536. c.hostNamePatternPopup();
  537. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  538. });
  539. it('should proceed next on primary', function() {
  540. c.hostNamePatternPopup().onPrimary();
  541. expect(c.proceedNext.calledOnce).to.equal(true);
  542. });
  543. });
  544. describe('#manualInstallPopup', function() {
  545. beforeEach(function() {
  546. sinon.spy(App.ModalPopup, 'show');
  547. sinon.stub(App.router, 'send', Em.K);
  548. sinon.stub(c, 'saveHosts', Em.K);
  549. });
  550. afterEach(function() {
  551. App.ModalPopup.show.restore();
  552. App.router.send.restore();
  553. c.saveHosts.restore();
  554. });
  555. it('should call App.ModalPopup.show', function() {
  556. c.manualInstallPopup();
  557. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  558. });
  559. it('should save hosts and go next on primary', function() {
  560. c.manualInstallPopup().onPrimary();
  561. expect(c.saveHosts.calledOnce).to.equal(true);
  562. expect(App.router.send.calledWith('next')).to.equal(true);
  563. });
  564. });
  565. describe('#manualInstallWarningPopup', function() {
  566. beforeEach(function() {
  567. sinon.spy(App.ModalPopup, 'show');
  568. });
  569. afterEach(function() {
  570. App.ModalPopup.show.restore();
  571. });
  572. it('should call App.ModalPopup.show if content.installOptions.useSsh is false', function() {
  573. var controller = App.WizardStep2Controller.create({content: {installOptions: {useSsh: false}}});
  574. controller.manualInstallWarningPopup();
  575. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  576. });
  577. it('shouldn\'t call App.ModalPopup.show if content.installOptions.useSsh is true', function() {
  578. var controller = App.WizardStep2Controller.create({content: {installOptions: {useSsh: true}}});
  579. controller.manualInstallWarningPopup();
  580. expect(App.ModalPopup.show.called).to.equal(false);
  581. });
  582. });
  583. describe('#setAmbariJavaHome', function() {
  584. beforeEach(function() {
  585. sinon.spy($, 'ajax');
  586. });
  587. afterEach(function() {
  588. $.ajax.restore();
  589. });
  590. it('should do ajax-request', function() {
  591. var controller = App.WizardStep2Controller.create({onGetAmbariJavaHomeSuccess: Em.K, onGetAmbariJavaHomeError: Em.K});
  592. controller.setAmbariJavaHome();
  593. expect($.ajax.calledOnce).to.equal(true);
  594. });
  595. });
  596. describe('#onGetAmbariJavaHomeSuccess', function() {
  597. it('should set java.home value receiced from server', function() {
  598. var controller = App.WizardStep2Controller.create({content: {installOptions: {}}});
  599. var test = {RootServiceComponents: {properties: {'java.home': '/root'}}};
  600. controller.onGetAmbariJavaHomeSuccess(test);
  601. expect(controller.content.installOptions.javaHome).to.equal('/root');
  602. });
  603. });
  604. describe('#onGetAmbariJavaHomeError', function() {
  605. it('should set default java.home value', function() {
  606. var controller = App.WizardStep2Controller.create({content: {installOptions: {}}});
  607. controller.onGetAmbariJavaHomeError();
  608. expect(controller.content.installOptions.javaHome).to.equal(App.get('defaultJavaHome'));
  609. });
  610. });
  611. describe('#saveHosts', function() {
  612. beforeEach(function() {
  613. sinon.stub(c, 'setAmbariJavaHome', Em.K);
  614. c.reopen({
  615. hostNameArr: ['h1'],
  616. content: {
  617. hosts: null
  618. }
  619. });
  620. });
  621. afterEach(function() {
  622. c.setAmbariJavaHome.restore();
  623. });
  624. it('should call setAmbariJavaHome', function() {
  625. c.saveHosts();
  626. expect(c.setAmbariJavaHome.calledOnce).to.equal(true);
  627. });
  628. it('should set content.hosts', function() {
  629. c.saveHosts();
  630. expect(Em.keys(c.get('content.hosts'))).to.eql(['h1']);
  631. });
  632. });
  633. });