wizard_test.js 37 KB

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