wizard_test.js 44 KB

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