step2_test.js 24 KB

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