wizard_test.js 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504
  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. require('models/cluster');
  20. require('controllers/wizard');
  21. var c;
  22. describe('App.WizardController', function () {
  23. var wizardController = App.WizardController.create({});
  24. var totalSteps = 11;
  25. var ruller = [];
  26. for(var i = 0; i < totalSteps; i++) {
  27. ruller.push(i);
  28. }
  29. beforeEach(function () {
  30. c = App.WizardController.create({});
  31. });
  32. describe('#setLowerStepsDisable', function() {
  33. for(var i = 1; i < totalSteps; i++) {
  34. var indx = i;
  35. var steps = [];
  36. for(var j = 1; j <= indx; j++) {
  37. steps.push(Em.Object.create({step:j,value:false}));
  38. }
  39. wizardController.set('isStepDisabled', steps);
  40. for(j = 1; j <= indx; j++) {
  41. it('Steps: ' + i + ' | Disabled: ' + (j-1), function() {
  42. wizardController.setLowerStepsDisable(j);
  43. expect(wizardController.get('isStepDisabled').filterProperty('value', true).length).to.equal(j-1);
  44. });
  45. }
  46. }
  47. });
  48. // isStep0 ... isStep10 tests
  49. App.WizardController1 = App.WizardController.extend({currentStep:''});
  50. var tests = [];
  51. for(var i = 0; i < totalSteps; i++) {
  52. var n = ruller.slice(0);
  53. n.splice(i,1);
  54. tests.push({i:i,n:n});
  55. }
  56. tests.forEach(function(test) {
  57. describe('isStep'+test.i, function() {
  58. var w = App.WizardController1.create();
  59. w.set('currentStep', test.i);
  60. it('Current Step is ' + test.i + ', so isStep' + test.i + ' is TRUE', function() {
  61. expect(w.get('isStep'+ test.i)).to.equal(true);
  62. });
  63. test.n.forEach(function(indx) {
  64. it('Current Step is ' + test.i + ', so isStep' + indx + ' is FALSE', function() {
  65. expect(w.get('isStep'+ indx)).to.equal(false);
  66. });
  67. });
  68. });
  69. });
  70. // isStep0 ... isStep10 tests end
  71. describe('#gotoStep', function() {
  72. var w = App.WizardController1.create();
  73. var steps = [];
  74. for(var j = 0; j < totalSteps; j++) {
  75. steps.push(Em.Object.create({step:j,value:false}));
  76. }
  77. steps.forEach(function(step, index) {
  78. step.set('value', true);
  79. w.set('isStepDisabled', steps);
  80. it('step ' + index + ' is disabled, so gotoStep('+index+') is not possible', function() {
  81. expect(w.gotoStep(index)).to.equal(false);
  82. });
  83. });
  84. });
  85. describe('#launchBootstrapSuccessCallback', function() {
  86. it('Save bootstrapRequestId', function() {
  87. var data = {requestId: 123};
  88. var params = {popup: {finishLoading: function(){}}};
  89. sinon.spy(params.popup, "finishLoading");
  90. wizardController.launchBootstrapSuccessCallback(data, {}, params);
  91. expect(params.popup.finishLoading.calledWith(123)).to.be.true;
  92. params.popup.finishLoading.restore();
  93. });
  94. });
  95. describe('#getInstallOptions', function () {
  96. var cases = [
  97. {
  98. isHadoopWindowsStack: true,
  99. expected: {
  100. useSsh: false
  101. }
  102. },
  103. {
  104. isHadoopWindowsStack: false,
  105. expected: {
  106. useSsh: true
  107. }
  108. }
  109. ],
  110. title = 'should return {0}';
  111. beforeEach(function () {
  112. sinon.stub(wizardController, 'get')
  113. .withArgs('installOptionsTemplate').returns({useSsh: true})
  114. .withArgs('installWindowsOptionsTemplate').returns({useSsh: false});
  115. });
  116. afterEach(function () {
  117. App.get.restore();
  118. wizardController.get.restore();
  119. });
  120. cases.forEach(function (item) {
  121. it(title.format(item.expected), function () {
  122. sinon.stub(App, 'get').withArgs('isHadoopWindowsStack').returns(item.isHadoopWindowsStack);
  123. expect(wizardController.getInstallOptions()).to.eql(item.expected);
  124. });
  125. });
  126. });
  127. describe('#clearInstallOptions', function () {
  128. wizardController.setProperties({
  129. content: {},
  130. name: 'wizard'
  131. });
  132. beforeEach(function () {
  133. sinon.stub(App, 'get').withArgs('isHadoopWindowsStack').returns(false);
  134. });
  135. afterEach(function () {
  136. App.get.restore();
  137. });
  138. it('should clear install options', function () {
  139. wizardController.clearInstallOptions();
  140. expect(wizardController.get('content.installOptions')).to.eql(wizardController.get('installOptionsTemplate'));
  141. expect(wizardController.get('content.hosts')).to.eql({});
  142. expect(wizardController.getDBProperty('installOptions')).to.eql(wizardController.get('installOptionsTemplate'));
  143. expect(wizardController.getDBProperty('hosts')).to.eql({});
  144. });
  145. });
  146. describe('#loadServiceConfigGroups', function () {
  147. beforeEach(function () {
  148. sinon.stub(wizardController, 'getDBProperty', function(message){
  149. if (message == 'serviceConfigGroups') {
  150. return [
  151. {
  152. hosts: ['h1']
  153. }
  154. ];
  155. } else {
  156. return Em.Object.create({
  157. h1: Em.Object.create({
  158. id: 'h1'
  159. })
  160. });
  161. }
  162. });
  163. });
  164. afterEach(function () {
  165. wizardController.getDBProperty.restore();
  166. });
  167. it('should load service confgig group', function () {
  168. wizardController.loadServiceConfigGroups();
  169. expect(wizardController.get('content.configGroups')).to.eql([
  170. {
  171. "hosts": [
  172. "h1"
  173. ]
  174. }
  175. ]);
  176. });
  177. });
  178. describe('#saveTasksStatuses', function () {
  179. it('should set status', function () {
  180. wizardController.saveTasksStatuses('st');
  181. expect(wizardController.get('content.tasksStatuses')).to.equal('st');
  182. });
  183. });
  184. describe('#saveSlaveComponentHosts', function () {
  185. beforeEach(function(){
  186. sinon.stub(wizardController,'getDBProperty').returns(Em.A({
  187. 'h1': {
  188. id: 1
  189. }
  190. }));
  191. });
  192. afterEach(function(){
  193. wizardController.getDBProperty.restore();
  194. });
  195. it('should save slave components', function () {
  196. var stepController = Em.Object.create({
  197. hosts: Em.A([
  198. Em.Object.create({
  199. hostName: 'h1',
  200. checkboxes: Em.A([
  201. Em.Object.create({title: 'hl1', checked: true})
  202. ])
  203. })
  204. ]),
  205. headers: Em.A([
  206. Em.Object.create({name: 'header1', label: 'hl1'})
  207. ])
  208. });
  209. wizardController.saveSlaveComponentHosts(stepController);
  210. var res = JSON.parse(JSON.stringify(wizardController.get('content.slaveComponentHosts')));
  211. expect(res).to.eql([
  212. {
  213. "componentName": "header1",
  214. "displayName": "hl1",
  215. "hosts": [
  216. {
  217. "group": "Default",
  218. "host_id": 1
  219. }
  220. ]
  221. }
  222. ]);
  223. });
  224. });
  225. describe('#showLaunchBootstrapPopup', function () {
  226. beforeEach(function(){
  227. sinon.stub(App.ModalPopup,'show', function(data){
  228. data.finishLoading.call(wizardController);
  229. });
  230. });
  231. afterEach(function(){
  232. App.ModalPopup.show.restore();
  233. });
  234. it('should set error', function () {
  235. wizardController.showLaunchBootstrapPopup(Em.K);
  236. expect(wizardController.get('isError')).to.be.true;
  237. });
  238. });
  239. describe('#gotoStep0', function () {
  240. var res;
  241. beforeEach(function(){
  242. sinon.stub(wizardController,'gotoStep', function(step){
  243. res = step;
  244. });
  245. });
  246. afterEach(function(){
  247. wizardController.gotoStep.restore();
  248. });
  249. it('should go to 0 step', function () {
  250. wizardController.gotoStep0(Em.K);
  251. expect(res).to.be.equal(0);
  252. });
  253. });
  254. describe('#gotoStep1', function () {
  255. var res;
  256. beforeEach(function(){
  257. sinon.stub(wizardController,'gotoStep', function(step){
  258. res = step;
  259. });
  260. });
  261. afterEach(function(){
  262. wizardController.gotoStep.restore();
  263. });
  264. it('should go to 1 step', function () {
  265. wizardController.gotoStep1(Em.K);
  266. expect(res).to.be.equal(1);
  267. });
  268. });
  269. describe('#gotoStep2', function () {
  270. var res;
  271. beforeEach(function(){
  272. sinon.stub(wizardController,'gotoStep', function(step){
  273. res = step;
  274. });
  275. });
  276. afterEach(function(){
  277. wizardController.gotoStep.restore();
  278. });
  279. it('should go to 2 step', function () {
  280. wizardController.gotoStep2(Em.K);
  281. expect(res).to.be.equal(2);
  282. });
  283. });
  284. describe('#gotoSte3', function () {
  285. var res;
  286. beforeEach(function(){
  287. sinon.stub(wizardController,'gotoStep', function(step){
  288. res = step;
  289. });
  290. });
  291. afterEach(function(){
  292. wizardController.gotoStep.restore();
  293. });
  294. it('should go to 3 step', function () {
  295. wizardController.gotoStep3(Em.K);
  296. expect(res).to.be.equal(3);
  297. });
  298. });
  299. describe('#gotoStep4', function () {
  300. var res;
  301. beforeEach(function(){
  302. sinon.stub(wizardController,'gotoStep', function(step){
  303. res = step;
  304. });
  305. });
  306. afterEach(function(){
  307. wizardController.gotoStep.restore();
  308. });
  309. it('should go to 4 step', function () {
  310. wizardController.gotoStep4(Em.K);
  311. expect(res).to.be.equal(4);
  312. });
  313. });
  314. describe('#gotoStep5', function () {
  315. var res;
  316. beforeEach(function(){
  317. sinon.stub(wizardController,'gotoStep', function(step){
  318. res = step;
  319. });
  320. });
  321. afterEach(function(){
  322. wizardController.gotoStep.restore();
  323. });
  324. it('should go to 5 step', function () {
  325. wizardController.gotoStep5(Em.K);
  326. expect(res).to.be.equal(5);
  327. });
  328. });
  329. describe('#gotoStep6', function () {
  330. var res;
  331. beforeEach(function(){
  332. sinon.stub(wizardController,'gotoStep', function(step){
  333. res = step;
  334. });
  335. });
  336. afterEach(function(){
  337. wizardController.gotoStep.restore();
  338. });
  339. it('should go to 6 step', function () {
  340. wizardController.gotoStep6(Em.K);
  341. expect(res).to.be.equal(6);
  342. });
  343. });
  344. describe('#gotoStep7', function () {
  345. var res;
  346. beforeEach(function(){
  347. sinon.stub(wizardController,'gotoStep', function(step){
  348. res = step;
  349. });
  350. });
  351. afterEach(function(){
  352. wizardController.gotoStep.restore();
  353. });
  354. it('should go to 7 step', function () {
  355. wizardController.gotoStep7(Em.K);
  356. expect(res).to.be.equal(7);
  357. });
  358. });
  359. describe('#gotoStep8', function () {
  360. var res;
  361. beforeEach(function(){
  362. sinon.stub(wizardController,'gotoStep', function(step){
  363. res = step;
  364. });
  365. });
  366. afterEach(function(){
  367. wizardController.gotoStep.restore();
  368. });
  369. it('should go to 8 step', function () {
  370. wizardController.gotoStep8(Em.K);
  371. expect(res).to.be.equal(8);
  372. });
  373. });
  374. describe('#gotoStep9', function () {
  375. var res;
  376. beforeEach(function(){
  377. sinon.stub(wizardController,'gotoStep', function(step){
  378. res = step;
  379. });
  380. });
  381. afterEach(function(){
  382. wizardController.gotoStep.restore();
  383. });
  384. it('should go to 9 step', function () {
  385. wizardController.gotoStep9(Em.K);
  386. expect(res).to.be.equal(9);
  387. });
  388. });
  389. describe('#gotoStep10', function () {
  390. var res;
  391. beforeEach(function(){
  392. sinon.stub(wizardController,'gotoStep', function(step){
  393. res = step;
  394. });
  395. });
  396. afterEach(function(){
  397. wizardController.gotoStep.restore();
  398. });
  399. it('should go to 10 step', function () {
  400. wizardController.gotoStep10(Em.K);
  401. expect(res).to.be.equal(10);
  402. });
  403. });
  404. describe('#gotoStep', function () {
  405. beforeEach(function(){
  406. sinon.stub(App.ModalPopup,'show', Em.K);
  407. sinon.stub(App.clusterStatus,'setClusterStatus', Em.K);
  408. sinon.stub(App.router,'send', Em.K);
  409. });
  410. afterEach(function(){
  411. App.ModalPopup.show.restore();
  412. App.clusterStatus.setClusterStatus.restore();
  413. App.router.send.restore();
  414. });
  415. it('should go to step', function () {
  416. wizardController.set('isStepDisabled', Em.A([
  417. Em.Object.create({
  418. step: '8',
  419. value: false
  420. })
  421. ]));
  422. wizardController.hide = Em.K;
  423. wizardController.set('content.controllerName','installerController');
  424. wizardController.set('currentStep','9');
  425. expect(wizardController.gotoStep('8')).to.be.true;
  426. });
  427. });
  428. describe('#launchBootstrap', function () {
  429. beforeEach(function(){
  430. sinon.stub(wizardController,'showLaunchBootstrapPopup').returns({
  431. name: 'popup'
  432. });
  433. sinon.stub(App.ajax,'send', Em.K);
  434. });
  435. afterEach(function(){
  436. wizardController.showLaunchBootstrapPopup.restore();
  437. App.ajax.send.restore();
  438. });
  439. it('should return popup', function () {
  440. expect(wizardController.launchBootstrap()).to.be.eql({
  441. name: 'popup'
  442. });
  443. });
  444. });
  445. describe('#save', function () {
  446. it('should save data', function () {
  447. var res;
  448. sinon.stub(wizardController,'setDBProperty', function(data){
  449. res = data;
  450. });
  451. sinon.stub(wizardController,'toJSInstance').returns('val');
  452. wizardController.save('name');
  453. wizardController.setDBProperty.restore();
  454. wizardController.toJSInstance.restore();
  455. expect(res).to.be.equal('name');
  456. });
  457. });
  458. describe('#installServicesSuccessCallback', function () {
  459. var res;
  460. beforeEach(function(){
  461. sinon.stub(wizardController,'saveClusterStatus', function(data){
  462. res = JSON.parse(JSON.stringify(data));
  463. });
  464. sinon.stub(App,'dateTime').returns('22');
  465. });
  466. afterEach(function(){
  467. wizardController.saveClusterStatus.restore();
  468. App.dateTime.restore();
  469. });
  470. it('should call callbeck with data', function () {
  471. var jsonData = {
  472. Requests: {
  473. id: 1
  474. }
  475. };
  476. wizardController.installServicesSuccessCallback(jsonData);
  477. expect(res).to.be.eql({
  478. "status": "PENDING",
  479. "requestId": 1,
  480. "isInstallError": false,
  481. "isCompleted": false,
  482. "installStartTime": "22"
  483. });
  484. });
  485. });
  486. describe('#installServices', function () {
  487. var res;
  488. beforeEach(function(){
  489. sinon.stub(wizardController,'saveClusterStatus', function(data){
  490. res = JSON.parse(JSON.stringify(data));
  491. });
  492. sinon.stub(App.ajax,'send').returns({
  493. then: function() {}
  494. });
  495. });
  496. afterEach(function(){
  497. wizardController.saveClusterStatus.restore();
  498. App.ajax.send.restore();
  499. });
  500. it('should call callbeck with data', function () {
  501. var jsonData = {
  502. Requests: {
  503. id: 1
  504. }
  505. };
  506. wizardController.set('content', Em.Object.create({
  507. cluster: {
  508. oldRequestsId: '1'
  509. }
  510. }));
  511. wizardController.installServices(true);
  512. expect(res).to.be.eql({
  513. "status": "PENDING"
  514. });
  515. });
  516. });
  517. describe('#saveInstalledHosts', function () {
  518. beforeEach(function(){
  519. sinon.stub(wizardController,'getDBProperty').returns({
  520. 'h1': {
  521. id: 1,
  522. status: '',
  523. name: 'h1'
  524. }
  525. });
  526. });
  527. afterEach(function(){
  528. wizardController.getDBProperty.restore();
  529. });
  530. it('should save installed hosts', function () {
  531. var stepController = Em.Object.create({
  532. hosts: Em.A([
  533. Em.Object.create({
  534. hostName: 'h1',
  535. name: 'h1',
  536. status: 'st',
  537. message: 'ms',
  538. checkboxes: Em.A([
  539. Em.Object.create({title: 'hl1', checked: true})
  540. ])
  541. })
  542. ])
  543. });
  544. wizardController.saveInstalledHosts(stepController);
  545. var res = JSON.parse(JSON.stringify(wizardController.get('content.hosts')));
  546. expect(res).to.eql({
  547. "h1": {
  548. "id": 1,
  549. "status": "st",
  550. "name": "h1",
  551. "message": "ms"
  552. }
  553. });
  554. });
  555. });
  556. describe('#saveConfirmedHosts', function () {
  557. beforeEach(function(){
  558. sinon.stub(wizardController,'getDBProperty').returns({
  559. 'h1': {
  560. id: 1,
  561. status: '',
  562. name: 'h1'
  563. }
  564. });
  565. });
  566. afterEach(function(){
  567. wizardController.getDBProperty.restore();
  568. });
  569. it('should save confirmed hosts', function () {
  570. var stepController = Em.Object.create({
  571. confirmedHosts: Em.A([
  572. {
  573. name: 'h2',
  574. cpu: '1',
  575. isInstalled: true
  576. }
  577. ])
  578. });
  579. wizardController.set('content.hosts', {
  580. 'h1': {
  581. isInstalled: false,
  582. bootStatus: 'REGISTERED'
  583. },
  584. 'h2': {
  585. isInstalled: true,
  586. bootStatus: 'REGISTERED'
  587. }
  588. });
  589. wizardController.saveConfirmedHosts(stepController);
  590. var res = JSON.parse(JSON.stringify(wizardController.get('content.hosts')));
  591. expect(res).to.eql({
  592. "h2": {
  593. "isInstalled": true,
  594. "bootStatus": "REGISTERED"
  595. }
  596. });
  597. });
  598. });
  599. describe('#loadTasksStatuses', function () {
  600. beforeEach(function () {
  601. sinon.stub(wizardController, 'getDBProperty').returns('st');
  602. });
  603. afterEach(function () {
  604. wizardController.getDBProperty.restore();
  605. });
  606. it('should load status', function () {
  607. wizardController.loadTasksStatuses();
  608. expect(wizardController.get('content.tasksStatuses')).to.equal('st');
  609. });
  610. });
  611. describe('#saveTasksRequestIds', function () {
  612. it('should save id', function () {
  613. wizardController.saveTasksRequestIds('st');
  614. expect(wizardController.get('content.tasksRequestIds')).to.equal('st');
  615. });
  616. });
  617. describe('#loadTasksRequestIds', function () {
  618. beforeEach(function () {
  619. sinon.stub(wizardController, 'getDBProperty').returns('st');
  620. });
  621. afterEach(function () {
  622. wizardController.getDBProperty.restore();
  623. });
  624. it('should load status', function () {
  625. wizardController.loadTasksRequestIds();
  626. expect(wizardController.get('content.tasksRequestIds')).to.equal('st');
  627. });
  628. });
  629. describe('#saveRequestIds', function () {
  630. it('should save id', function () {
  631. wizardController.saveRequestIds('st');
  632. expect(wizardController.get('content.requestIds')).to.equal('st');
  633. });
  634. });
  635. describe('#load', function () {
  636. it('should clear install options', function () {
  637. var name = 'Name';
  638. wizardController.set('get'+name.capitalize(), function() {return 'res';});
  639. wizardController.load(name, true);
  640. expect(wizardController.get('content.' + name)).to.equal('res');
  641. });
  642. });
  643. describe('#usersLoading', function () {
  644. beforeEach(function(){
  645. sinon.stub(App.MainAdminServiceAccountsController,'create').returns({
  646. loadUsers: function() {},
  647. get: function(type) {
  648. if (type == 'dataIsLoaded') {
  649. return true;
  650. }
  651. return Em.Object.create({
  652. hdfsUser: {
  653. name: 'user'
  654. }
  655. });
  656. }
  657. });
  658. });
  659. afterEach(function(){
  660. App.MainAdminServiceAccountsController.create.restore();
  661. });
  662. it('should load users', function () {
  663. wizardController.set('content.hdfsUser', true);
  664. wizardController.usersLoading().then(function(data){
  665. expect(data).to.be.undefined;
  666. });
  667. });
  668. });
  669. describe('#loadConfirmedHosts', function () {
  670. beforeEach(function(){
  671. sinon.stub(App.db, 'getHosts').returns(Em.A([
  672. Em.Object.create({
  673. name: 'h1'
  674. })
  675. ]));
  676. });
  677. afterEach(function(){
  678. App.db.getHosts.restore();
  679. });
  680. it('should load hosts from db', function () {
  681. wizardController.loadConfirmedHosts();
  682. var res = JSON.parse(JSON.stringify(wizardController.get('content.hosts')));
  683. expect(res).to.eql([
  684. {
  685. "name": "h1"
  686. }
  687. ]);
  688. });
  689. });
  690. describe('#loadServicesFromServer', function () {//TODO
  691. var res;
  692. beforeEach(function(){
  693. sinon.stub(App.StackService, 'find').returns(Em.A([
  694. Em.Object.create({
  695. isSelected: false,
  696. isInstalled: false,
  697. serviceName: 's1'
  698. })
  699. ]));
  700. sinon.stub(App.Service, 'find').returns(Em.A([
  701. Em.Object.create({
  702. isSelected: false,
  703. isInstalled: false,
  704. serviceName: 's1'
  705. })
  706. ]));
  707. sinon.stub(wizardController, 'setDBProperty', function(data) {
  708. res = data;
  709. });
  710. });
  711. afterEach(function () {
  712. App.StackService.find.restore();
  713. App.Service.find.restore();
  714. wizardController.setDBProperty.restore();
  715. });
  716. it('should load services from server', function () {
  717. wizardController.loadServicesFromServer();
  718. expect(res).to.eql('services');
  719. });
  720. });
  721. describe('#loadRequestIds', function () {
  722. beforeEach(function () {
  723. sinon.stub(wizardController, 'getDBProperty').returns('st');
  724. });
  725. afterEach(function () {
  726. wizardController.getDBProperty.restore();
  727. });
  728. it('should load status', function () {
  729. wizardController.loadRequestIds();
  730. expect(wizardController.get('content.requestIds')).to.equal('st');
  731. });
  732. });
  733. describe('#loadServiceComponentsSuccessCallback', function () {
  734. beforeEach(function () {
  735. sinon.stub(wizardController, 'getDBProperty', function(message) {
  736. if (message == 'selectedServiceNames') {
  737. return ['a','b'];
  738. } else {
  739. return ['c','d'];
  740. }
  741. });
  742. sinon.stub(App.stackServiceMapper, 'mapStackServices', Em.K);
  743. });
  744. afterEach(function () {
  745. wizardController.getDBProperty.restore();
  746. App.stackServiceMapper.mapStackServices.restore();
  747. });
  748. it('should load json data', function () {
  749. var jsonData = {
  750. items: [
  751. {
  752. StackServices: {
  753. isSelected: false,
  754. service_name: 'a'
  755. }
  756. },
  757. {
  758. StackServices: {
  759. isSelected: false,
  760. service_name: 'none'
  761. }
  762. }
  763. ]
  764. };
  765. wizardController.loadServiceComponentsSuccessCallback(jsonData);
  766. var exp = {
  767. "items": [
  768. {
  769. "StackServices": {
  770. "isSelected": false,
  771. "service_name": "a",
  772. "is_selected": true,
  773. "is_installed": false
  774. }
  775. },
  776. {
  777. "StackServices": {
  778. "isSelected": false,
  779. "service_name": "none",
  780. "is_selected": false,
  781. "is_installed": false
  782. }
  783. }
  784. ]
  785. };
  786. expect(jsonData).to.eql(exp);
  787. });
  788. });
  789. describe('#setInfoForStep9', function () {
  790. var res;
  791. beforeEach(function () {
  792. sinon.stub(wizardController, 'getDBProperty').returns(Em.Object.create({
  793. status: {},
  794. message: {},
  795. logTasks: {},
  796. tasks: {},
  797. progress: {}
  798. }));
  799. sinon.stub(wizardController, 'setDBProperty', function(title,data) {
  800. res = data;
  801. });
  802. });
  803. afterEach(function () {
  804. wizardController.getDBProperty.restore();
  805. wizardController.setDBProperty.restore();
  806. });
  807. it('should return info for step 9', function () {
  808. wizardController.setInfoForStep9();
  809. var exp = {
  810. "status": {
  811. "status": "pending",
  812. "message": "Waiting",
  813. "logTasks": [],
  814. "tasks": [],
  815. "progress": "0"
  816. },
  817. "message": {
  818. "status": "pending",
  819. "message": "Waiting",
  820. "logTasks": [],
  821. "tasks": [],
  822. "progress": "0"
  823. },
  824. "logTasks": {
  825. "status": "pending",
  826. "message": "Waiting",
  827. "logTasks": [],
  828. "tasks": [],
  829. "progress": "0"
  830. },
  831. "tasks": {
  832. "status": "pending",
  833. "message": "Waiting",
  834. "logTasks": [],
  835. "tasks": [],
  836. "progress": "0"
  837. },
  838. "progress": {
  839. "status": "pending",
  840. "message": "Waiting",
  841. "logTasks": [],
  842. "tasks": [],
  843. "progress": "0"
  844. }
  845. };
  846. res = JSON.parse(JSON.stringify(res));
  847. expect(res).to.eql(exp);
  848. });
  849. });
  850. describe('#saveServiceConfigProperties', function () {
  851. beforeEach(function () {
  852. c.set('content', {});
  853. sinon.stub(c, 'setDBProperty', Em.K);
  854. sinon.stub(App.config, 'shouldSupportFinal').returns(true);
  855. });
  856. afterEach(function () {
  857. c.setDBProperty.restore();
  858. App.config.shouldSupportFinal.restore();
  859. });
  860. var kerberosStepController = Em.Object.create({
  861. installedServiceNames: ['KERBEROS'],
  862. stepConfigs: [
  863. Em.Object.create({
  864. serviceName: 'KERBEROS',
  865. configs: [
  866. Em.Object.create({
  867. id: 'id',
  868. name: 'admin_password',
  869. value: 'value',
  870. defaultValue: 'defaultValue',
  871. description: 'description',
  872. serviceName: 'serviceName',
  873. domain: 'domain',
  874. isVisible: true,
  875. isNotDefaultValue: true,
  876. isFinal: true,
  877. defaultIsFinal: true,
  878. supportsFinal: true,
  879. filename: 'krb5-conf.xml',
  880. displayType: 'string',
  881. isRequiredByAgent: true,
  882. hasInitialValue: true,
  883. isRequired: true,
  884. group: {name: 'group'},
  885. showLabel: true,
  886. category: 'some_category'
  887. }),
  888. Em.Object.create({
  889. id: 'id',
  890. name: 'admin_principal',
  891. value: 'value',
  892. defaultValue: 'defaultValue',
  893. description: 'description',
  894. serviceName: 'serviceName',
  895. domain: 'domain',
  896. isVisible: true,
  897. isNotDefaultValue: true,
  898. isFinal: true,
  899. defaultIsFinal: true,
  900. supportsFinal: true,
  901. filename: 'krb5-conf.xml',
  902. displayType: 'string',
  903. isRequiredByAgent: true,
  904. hasInitialValue: true,
  905. isRequired: true,
  906. group: {name: 'group'},
  907. showLabel: true,
  908. category: 'some_category'
  909. })
  910. ]
  911. })
  912. ]
  913. });
  914. var stepController = Em.Object.create({
  915. installedServiceNames: ['HDFS'],
  916. stepConfigs: [
  917. Em.Object.create({
  918. serviceName: 'HDFS',
  919. configs: [
  920. Em.Object.create({
  921. id: 'id',
  922. name: 'name',
  923. value: 'value',
  924. defaultValue: 'defaultValue',
  925. description: 'description',
  926. serviceName: 'serviceName',
  927. domain: 'domain',
  928. isVisible: true,
  929. isNotDefaultValue: true,
  930. isFinal: true,
  931. defaultIsFinal: true,
  932. supportsFinal: true,
  933. filename: 'filename',
  934. displayType: 'string',
  935. isRequiredByAgent: true,
  936. hasInitialValue: true,
  937. isRequired: true,
  938. group: {name: 'group'},
  939. showLabel: true,
  940. category: 'some_category'
  941. })
  942. ]
  943. }),
  944. Em.Object.create({
  945. serviceName: 'YARN',
  946. configs: [
  947. Em.Object.create({
  948. id: 'id',
  949. name: 'name',
  950. value: 'value',
  951. defaultValue: 'defaultValue',
  952. description: 'description',
  953. serviceName: 'serviceName',
  954. domain: 'domain',
  955. isVisible: true,
  956. isFinal: true,
  957. defaultIsFinal: true,
  958. supportsFinal: true,
  959. filename: 'filename',
  960. displayType: 'string',
  961. isRequiredByAgent: true,
  962. hasInitialValue: true,
  963. isRequired: true,
  964. group: {name: 'group'},
  965. showLabel: true,
  966. category: 'some_category'
  967. })
  968. ]
  969. })
  970. ]});
  971. it('should save configs to content.serviceConfigProperties', function () {
  972. c.saveServiceConfigProperties(stepController);
  973. var saved = c.get('content.serviceConfigProperties');
  974. expect(saved.length).to.equal(2);
  975. expect(saved[0].category).to.equal('some_category');
  976. });
  977. it('should not save admin_principal or admin_password to the localStorage', function () {
  978. c.saveServiceConfigProperties(kerberosStepController);
  979. var saved = c.get('content.serviceConfigProperties');
  980. saved.forEach(function(config) {
  981. expect(config.value).to.equal('');
  982. });
  983. });
  984. });
  985. describe('#enableStep', function () {
  986. it('should update appropriate value in isStepDisabled', function () {
  987. c.set('isStepDisabled', [
  988. Em.Object.create({step: 1, value: true}),
  989. Em.Object.create({step: 2, value: true}),
  990. Em.Object.create({step: 3, value: true}),
  991. Em.Object.create({step: 4, value: true}),
  992. Em.Object.create({step: 5, value: true}),
  993. Em.Object.create({step: 6, value: true}),
  994. Em.Object.create({step: 7, value: true})
  995. ]);
  996. c.enableStep(1);
  997. expect(c.get('isStepDisabled')[0].get('value')).to.be.false;
  998. c.enableStep(7);
  999. expect(c.get('isStepDisabled')[6].get('value')).to.be.false;
  1000. });
  1001. });
  1002. describe('#allHosts', function () {
  1003. it('should return all hosts', function () {
  1004. var hosts = {
  1005. 'h1': {hostComponents: ['c1', 'c2'], disk_info: [{size: 2, available: 1}]},
  1006. 'h2': {hostComponents: ['c3', 'c4'], disk_info: [{size: 2, available: 1}]}
  1007. };
  1008. var content = Em.Object.create({
  1009. hosts: hosts
  1010. });
  1011. c.set('content', content);
  1012. var exp = [
  1013. {
  1014. "id": "h1",
  1015. "hostName": "h1",
  1016. "publicHostName": "h1",
  1017. "diskInfo": [
  1018. {
  1019. "size": 2,
  1020. "available": 1
  1021. }
  1022. ],
  1023. "diskTotal": 0.0000019073486328125,
  1024. "diskFree": 9.5367431640625e-7,
  1025. "disksMounted": 1,
  1026. "osType": 0,
  1027. "osArch": 0,
  1028. "ip": 0,
  1029. "hostComponents": [
  1030. {
  1031. "componentName": "c1",
  1032. "displayName": "C1"
  1033. },
  1034. {
  1035. "componentName": "c2",
  1036. "displayName": "C2"
  1037. }
  1038. ]
  1039. },
  1040. {
  1041. "id": "h2",
  1042. "hostName": "h2",
  1043. "publicHostName": "h2",
  1044. "diskInfo": [
  1045. {
  1046. "size": 2,
  1047. "available": 1
  1048. }
  1049. ],
  1050. "diskTotal": 0.0000019073486328125,
  1051. "diskFree": 9.5367431640625e-7,
  1052. "disksMounted": 1,
  1053. "osType": 0,
  1054. "osArch": 0,
  1055. "ip": 0,
  1056. "hostComponents": [
  1057. {
  1058. "componentName": "c3",
  1059. "displayName": "C3"
  1060. },
  1061. {
  1062. "componentName": "c4",
  1063. "displayName": "C4"
  1064. }
  1065. ]
  1066. }
  1067. ];
  1068. var res = JSON.parse(JSON.stringify(c.get('allHosts')));
  1069. expect(res).to.be.eql(exp);
  1070. });
  1071. });
  1072. describe('#getSlaveComponentHosts', function () {
  1073. beforeEach(function () {
  1074. sinon.stub(App.Service, 'find').returns(Em.A([
  1075. Em.Object.create({
  1076. serviceName: 's1'
  1077. })
  1078. ]));
  1079. sinon.stub(App.StackService, 'find').returns(Em.A([
  1080. Em.Object.create({
  1081. serviceName: 's2',
  1082. isSelected: true
  1083. })
  1084. ]));
  1085. sinon.stub(App.StackServiceComponent, 'find').returns(Em.A([
  1086. Em.Object.create({componentName: 'DATANODE', serviceName: 's1', isSlave: true}),
  1087. Em.Object.create({componentName: 'c2', serviceName: 's2', isSlave: true})
  1088. ]));
  1089. sinon.stub(App.HostComponent, 'find').returns(Em.A([
  1090. Em.Object.create({
  1091. componentName: 'DATANODE',
  1092. hostName: 'h1'
  1093. })
  1094. ]));
  1095. });
  1096. afterEach(function () {
  1097. App.Service.find.restore();
  1098. App.HostComponent.find.restore();
  1099. App.StackService.find.restore();
  1100. App.StackServiceComponent.find.restore();
  1101. });
  1102. it('should return slave components', function () {
  1103. var res = JSON.parse(JSON.stringify(c.getSlaveComponentHosts()));
  1104. var exp = [
  1105. {
  1106. "componentName": "DATANODE",
  1107. "displayName": "DataNode",
  1108. "hosts": [
  1109. {
  1110. "group": "Default",
  1111. "hostName": "h1",
  1112. "isInstalled": true
  1113. }
  1114. ],
  1115. "isInstalled": true
  1116. },
  1117. {
  1118. "componentName": "CLIENT",
  1119. "displayName": "Client",
  1120. "hosts": [],
  1121. "isInstalled": true
  1122. },
  1123. {
  1124. "componentName": "c2",
  1125. "displayName": "C2",
  1126. "hosts": [
  1127. {
  1128. "group": "Default",
  1129. "hostName": "h1",
  1130. "isInstalled": false
  1131. }
  1132. ],
  1133. "isInstalled": false
  1134. }
  1135. ];
  1136. expect(res).to.be.eql(exp);
  1137. });
  1138. });
  1139. describe('#setSkipSlavesStep', function () {
  1140. var step = 6,
  1141. cases = [
  1142. {
  1143. services: [
  1144. {
  1145. hasSlave: true,
  1146. hasNonMastersWithCustomAssignment: true
  1147. }
  1148. ],
  1149. skipSlavesStep: false,
  1150. title: 'service with customizable slave selected'
  1151. },
  1152. {
  1153. services: [
  1154. {
  1155. hasClient: true,
  1156. hasNonMastersWithCustomAssignment: true
  1157. }
  1158. ],
  1159. skipSlavesStep: false,
  1160. title: 'service with customizable client selected'
  1161. },
  1162. {
  1163. services: [
  1164. {
  1165. hasSlave: true,
  1166. hasNonMastersWithCustomAssignment: false
  1167. },
  1168. {
  1169. hasClient: true,
  1170. hasNonMastersWithCustomAssignment: false
  1171. }
  1172. ],
  1173. skipSlavesStep: true,
  1174. title: 'no service with customizable slaves or clients selected'
  1175. },
  1176. {
  1177. services: [
  1178. {
  1179. hasSlave: false,
  1180. hasClient: false
  1181. }
  1182. ],
  1183. skipSlavesStep: true,
  1184. title: 'no service with slaves or clients selected'
  1185. }
  1186. ];
  1187. beforeEach(function () {
  1188. c.reopen({
  1189. isStepDisabled: [
  1190. Em.Object.create({
  1191. step: 6
  1192. })
  1193. ],
  1194. content: {}
  1195. });
  1196. });
  1197. cases.forEach(function (item) {
  1198. it(item.title, function () {
  1199. c.setSkipSlavesStep(item.services, step);
  1200. expect(Boolean(c.get('isStepDisabled').findProperty('step', step).get('value'))).to.equal(item.skipSlavesStep);
  1201. });
  1202. });
  1203. });
  1204. describe('#toJSInstance', function () {
  1205. var testCases = [
  1206. {
  1207. o: {'test': 'test'},
  1208. e: {'test': 'test'}
  1209. },
  1210. {
  1211. o: {'test': Em.Object.create()},
  1212. e: {'test': {}}
  1213. },
  1214. {
  1215. o: {'test': Em.Object.create({'test': {}})},
  1216. e: {'test': {'test': {}}}
  1217. },
  1218. {
  1219. o: [],
  1220. e: []
  1221. },
  1222. {
  1223. o: Em.A([[]]),
  1224. e: [[]]
  1225. },
  1226. {
  1227. o: 11,
  1228. e: 11
  1229. },
  1230. {
  1231. o: '11',
  1232. e: '11'
  1233. },
  1234. {
  1235. o: null,
  1236. e: null
  1237. }
  1238. ];
  1239. it('should convert objects and arrays to pure JS objects and arrays', function () {
  1240. testCases.forEach(function (testCase) {
  1241. expect(c.toJSInstance(testCase.o)).to.eql(testCase.e);
  1242. });
  1243. });
  1244. });
  1245. describe('#loadConfigThemes', function() {
  1246. beforeEach(function () {
  1247. sinon.stub(wizardController, 'loadConfigThemeForServices').returns({
  1248. always: function(callback) {callback();}
  1249. });
  1250. sinon.stub(App.themesMapper, 'generateAdvancedTabs').returns(true);
  1251. sinon.stub(App.config, 'loadConfigsFromStack').returns({
  1252. done: function(callback) {
  1253. callback();
  1254. }
  1255. });
  1256. sinon.stub(App.StackService, 'find').returns(Em.A([
  1257. Em.Object.create({
  1258. isSelected: true,
  1259. serviceName: 's1'
  1260. })
  1261. ]));
  1262. });
  1263. afterEach(function () {
  1264. App.get.restore();
  1265. App.StackService.find.restore();
  1266. App.config.loadConfigsFromStack.restore();
  1267. App.themesMapper.generateAdvancedTabs.restore();
  1268. wizardController.loadConfigThemeForServices.restore();
  1269. });
  1270. it('Should load config themes', function() {
  1271. sinon.stub(App, 'get').returns(true);
  1272. wizardController.loadConfigThemes().then(function(data) {
  1273. expect().to.be.undefined;
  1274. });
  1275. });
  1276. it('Should load config themes', function() {
  1277. sinon.stub(App, 'get').returns(false);
  1278. wizardController.loadConfigThemes().then(function(data) {
  1279. expect().to.be.undefined;
  1280. });
  1281. });
  1282. });
  1283. describe('#dataLoading', function () {
  1284. var clusterController = Em.Object.create({
  1285. isLoaded: false
  1286. });
  1287. beforeEach(function(){
  1288. sinon.stub(App.router,'get').returns(clusterController);
  1289. sinon.stub(wizardController, 'connectOutlet', Em.K);
  1290. clusterController.set('isLoaded', false);
  1291. });
  1292. afterEach(function(){
  1293. App.router.get.restore();
  1294. wizardController.connectOutlet.restore();
  1295. });
  1296. it('should load data', function () {
  1297. clusterController.set('isLoaded', true);
  1298. wizardController.dataLoading().then(function(data){
  1299. expect(data).to.be.undefined;
  1300. });
  1301. });
  1302. it('should load data after 25ms', function () {
  1303. clusterController.set('isLoaded', false);
  1304. setTimeout(function(){
  1305. clusterController.set('isLoaded', true);
  1306. },25);
  1307. wizardController.dataLoading().then(function(data){
  1308. expect(data).to.be.undefined;
  1309. });
  1310. });
  1311. });
  1312. describe('#saveMasterComponentHosts', function () {
  1313. var stepController = Em.Object.create({
  1314. selectedServicesMasters: [
  1315. Em.Object.create({
  1316. display_name: 'd0',
  1317. component_name: 'c0',
  1318. selectedHost: 'h0',
  1319. serviceId: 's0',
  1320. isInstalled: true
  1321. }),
  1322. Em.Object.create({
  1323. display_name: 'd1',
  1324. component_name: 'c1',
  1325. selectedHost: 'h1',
  1326. serviceId: 's1',
  1327. isInstalled: false
  1328. })
  1329. ]
  1330. }),
  1331. masterComponentHosts = [
  1332. {
  1333. display_name: 'd0',
  1334. component: 'c0',
  1335. hostName: 'h0',
  1336. serviceId: 's0',
  1337. isInstalled: true
  1338. },
  1339. {
  1340. display_name: 'd1',
  1341. component: 'c1',
  1342. hostName: 'h1',
  1343. serviceId: 's1',
  1344. isInstalled: false
  1345. }
  1346. ];
  1347. beforeEach(function () {
  1348. sinon.stub(wizardController, 'setDBProperty', Em.K);
  1349. });
  1350. afterEach(function () {
  1351. wizardController.setDBProperty.restore();
  1352. });
  1353. it('should save master component hosts', function () {
  1354. wizardController.saveMasterComponentHosts(stepController);
  1355. expect(wizardController.setDBProperty.calledOnce).to.be.true;
  1356. expect(wizardController.setDBProperty.calledWith('masterComponentHosts', masterComponentHosts)).to.be.true;
  1357. expect(wizardController.get('content.masterComponentHosts')).to.eql(masterComponentHosts);
  1358. });
  1359. });
  1360. describe('#clearMasterComponentHosts', function () {
  1361. beforeEach(function () {
  1362. sinon.stub(wizardController, 'setDBProperty', Em.K);
  1363. });
  1364. afterEach(function () {
  1365. wizardController.setDBProperty.restore();
  1366. });
  1367. it('should clear master component hosts', function () {
  1368. wizardController.set('content.masterComponentHosts', {});
  1369. wizardController.clearMasterComponentHosts();
  1370. expect(wizardController.setDBProperty.calledOnce).to.be.true;
  1371. expect(wizardController.setDBProperty.calledWith('masterComponentHosts', null)).to.be.true;
  1372. expect(wizardController.get('content.masterComponentHosts')).to.be.null;
  1373. });
  1374. });
  1375. describe('#loadRecommendations', function () {
  1376. beforeEach(function () {
  1377. sinon.stub(c, 'getDBProperty').returns({});
  1378. });
  1379. afterEach(function () {
  1380. c.getDBProperty.restore();
  1381. });
  1382. it('should set recommendations', function () {
  1383. c.set('content', {});
  1384. c.loadRecommendations();
  1385. expect(c.get('content.recommendations')).to.eql({});
  1386. });
  1387. });
  1388. });