wizard_test.js 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655
  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. name: 'admin_password',
  990. value: 'value',
  991. serviceName: 'serviceName',
  992. isFinal: true,
  993. filename: 'krb5-conf.xml'
  994. }),
  995. Em.Object.create({
  996. name: 'admin_principal',
  997. value: 'value',
  998. serviceName: 'serviceName',
  999. isFinal: true,
  1000. filename: 'krb5-conf.xml'
  1001. })
  1002. ]
  1003. })
  1004. ]
  1005. });
  1006. var stepController = Em.Object.create({
  1007. installedServiceNames: ['HDFS'],
  1008. stepConfigs: [
  1009. Em.Object.create({
  1010. serviceName: 'HDFS',
  1011. configs: [
  1012. Em.Object.create({
  1013. name: 'name',
  1014. value: 'value',
  1015. serviceName: 'serviceName',
  1016. isFinal: true,
  1017. filename: 'hdfs-site',
  1018. }),
  1019. Em.Object.create({
  1020. name: 'name2',
  1021. value: 'value',
  1022. serviceName: 'serviceName',
  1023. isFinal: true,
  1024. filename: 'hdfs-site'
  1025. })
  1026. ]
  1027. }),
  1028. Em.Object.create({
  1029. serviceName: 'YARN',
  1030. configs: [
  1031. Em.Object.create({
  1032. name: 'name',
  1033. value: 'value',
  1034. serviceName: 'serviceName',
  1035. isFinal: true,
  1036. filename: 'filename'
  1037. })
  1038. ]
  1039. })
  1040. ]});
  1041. it('should save configs from default config group to content.serviceConfigProperties', function () {
  1042. c.saveServiceConfigProperties(stepController);
  1043. var saved = c.get('content.serviceConfigProperties');
  1044. expect(saved.length).to.equal(3);
  1045. });
  1046. it('should not save admin_principal or admin_password to the localStorage', function () {
  1047. c.saveServiceConfigProperties(kerberosStepController);
  1048. var saved = c.get('content.serviceConfigProperties');
  1049. expect(saved.everyProperty('value', '')).to.be.true;
  1050. });
  1051. });
  1052. describe('#enableStep', function () {
  1053. beforeEach(function () {
  1054. c.set('isStepDisabled', [
  1055. Em.Object.create({step: 1, value: true}),
  1056. Em.Object.create({step: 2, value: true}),
  1057. Em.Object.create({step: 3, value: true}),
  1058. Em.Object.create({step: 4, value: true}),
  1059. Em.Object.create({step: 5, value: true}),
  1060. Em.Object.create({step: 6, value: true}),
  1061. Em.Object.create({step: 7, value: true})
  1062. ]);
  1063. });
  1064. it('should update 1st value in isStepDisabled', function () {
  1065. c.enableStep(1);
  1066. expect(c.get('isStepDisabled')[0].get('value')).to.be.false;
  1067. });
  1068. it('should update 6th value in isStepDisabled', function () {
  1069. c.enableStep(7);
  1070. expect(c.get('isStepDisabled')[6].get('value')).to.be.false;
  1071. });
  1072. });
  1073. describe('#allHosts', function () {
  1074. it('should return all hosts', function () {
  1075. var hosts = {
  1076. 'h1': {hostComponents: ['c1', 'c2'], disk_info: [{size: 2, available: 1}]},
  1077. 'h2': {hostComponents: ['c3', 'c4'], disk_info: [{size: 2, available: 1}]}
  1078. };
  1079. var content = Em.Object.create({
  1080. hosts: hosts
  1081. });
  1082. c.set('content', content);
  1083. var exp = [
  1084. {
  1085. "id": "h1",
  1086. "hostName": "h1",
  1087. "publicHostName": "h1",
  1088. "diskInfo": [
  1089. {
  1090. "size": 2,
  1091. "available": 1
  1092. }
  1093. ],
  1094. "diskTotal": 0.0000019073486328125,
  1095. "diskFree": 9.5367431640625e-7,
  1096. "disksMounted": 1,
  1097. "osType": 0,
  1098. "osArch": 0,
  1099. "ip": 0,
  1100. "hostComponents": [
  1101. {
  1102. "componentName": "c1",
  1103. "displayName": "C1"
  1104. },
  1105. {
  1106. "componentName": "c2",
  1107. "displayName": "C2"
  1108. }
  1109. ]
  1110. },
  1111. {
  1112. "id": "h2",
  1113. "hostName": "h2",
  1114. "publicHostName": "h2",
  1115. "diskInfo": [
  1116. {
  1117. "size": 2,
  1118. "available": 1
  1119. }
  1120. ],
  1121. "diskTotal": 0.0000019073486328125,
  1122. "diskFree": 9.5367431640625e-7,
  1123. "disksMounted": 1,
  1124. "osType": 0,
  1125. "osArch": 0,
  1126. "ip": 0,
  1127. "hostComponents": [
  1128. {
  1129. "componentName": "c3",
  1130. "displayName": "C3"
  1131. },
  1132. {
  1133. "componentName": "c4",
  1134. "displayName": "C4"
  1135. }
  1136. ]
  1137. }
  1138. ];
  1139. var res = JSON.parse(JSON.stringify(c.get('allHosts')));
  1140. expect(res).to.be.eql(exp);
  1141. });
  1142. });
  1143. describe('#getSlaveComponentHosts', function () {
  1144. beforeEach(function () {
  1145. sinon.stub(App.Service, 'find').returns(Em.A([
  1146. Em.Object.create({
  1147. serviceName: 's1'
  1148. })
  1149. ]));
  1150. sinon.stub(App.StackService, 'find').returns(Em.A([
  1151. Em.Object.create({
  1152. serviceName: 's2',
  1153. isSelected: true
  1154. })
  1155. ]));
  1156. sinon.stub(App.StackServiceComponent, 'find').returns(Em.A([
  1157. Em.Object.create({componentName: 'DATANODE', serviceName: 's1', isSlave: true}),
  1158. Em.Object.create({componentName: 'c2', serviceName: 's2', isSlave: true})
  1159. ]));
  1160. sinon.stub(App.HostComponent, 'find').returns(Em.A([
  1161. Em.Object.create({
  1162. componentName: 'DATANODE',
  1163. hostName: 'h1'
  1164. })
  1165. ]));
  1166. });
  1167. afterEach(function () {
  1168. App.Service.find.restore();
  1169. App.HostComponent.find.restore();
  1170. App.StackService.find.restore();
  1171. App.StackServiceComponent.find.restore();
  1172. });
  1173. it('should return slave components', function () {
  1174. var res = JSON.parse(JSON.stringify(c.getSlaveComponentHosts()));
  1175. var exp = [
  1176. {
  1177. "componentName": "DATANODE",
  1178. "displayName": "DataNode",
  1179. "hosts": [
  1180. {
  1181. "group": "Default",
  1182. "hostName": "h1",
  1183. "isInstalled": true
  1184. }
  1185. ],
  1186. "isInstalled": true
  1187. },
  1188. {
  1189. "componentName": "CLIENT",
  1190. "displayName": "Client",
  1191. "hosts": [],
  1192. "isInstalled": true
  1193. },
  1194. {
  1195. "componentName": "c2",
  1196. "displayName": "C2",
  1197. "hosts": [
  1198. {
  1199. "group": "Default",
  1200. "hostName": "h1",
  1201. "isInstalled": false
  1202. }
  1203. ],
  1204. "isInstalled": false
  1205. }
  1206. ];
  1207. expect(res).to.be.eql(exp);
  1208. });
  1209. });
  1210. describe('#setSkipSlavesStep', function () {
  1211. var step = 6,
  1212. cases = [
  1213. {
  1214. services: [
  1215. {
  1216. hasSlave: true,
  1217. hasNonMastersWithCustomAssignment: true
  1218. }
  1219. ],
  1220. skipSlavesStep: false,
  1221. title: 'service with customizable slave selected'
  1222. },
  1223. {
  1224. services: [
  1225. {
  1226. hasClient: true,
  1227. hasNonMastersWithCustomAssignment: true
  1228. }
  1229. ],
  1230. skipSlavesStep: false,
  1231. title: 'service with customizable client selected'
  1232. },
  1233. {
  1234. services: [
  1235. {
  1236. hasSlave: true,
  1237. hasNonMastersWithCustomAssignment: false
  1238. },
  1239. {
  1240. hasClient: true,
  1241. hasNonMastersWithCustomAssignment: false
  1242. }
  1243. ],
  1244. skipSlavesStep: true,
  1245. title: 'no service with customizable slaves or clients selected'
  1246. },
  1247. {
  1248. services: [
  1249. {
  1250. hasSlave: false,
  1251. hasClient: false
  1252. }
  1253. ],
  1254. skipSlavesStep: true,
  1255. title: 'no service with slaves or clients selected'
  1256. }
  1257. ];
  1258. beforeEach(function () {
  1259. c.reopen({
  1260. isStepDisabled: [
  1261. Em.Object.create({
  1262. step: 6
  1263. })
  1264. ],
  1265. content: {}
  1266. });
  1267. });
  1268. cases.forEach(function (item) {
  1269. it(item.title, function () {
  1270. c.setSkipSlavesStep(item.services, step);
  1271. expect(Boolean(c.get('isStepDisabled').findProperty('step', step).get('value'))).to.equal(item.skipSlavesStep);
  1272. });
  1273. });
  1274. });
  1275. describe('#toJSInstance', function () {
  1276. var testCases = [
  1277. {
  1278. o: {'test': 'test'},
  1279. e: {'test': 'test'}
  1280. },
  1281. {
  1282. o: {'test': Em.Object.create()},
  1283. e: {'test': {}}
  1284. },
  1285. {
  1286. o: {'test': Em.Object.create({'test': {}})},
  1287. e: {'test': {'test': {}}}
  1288. },
  1289. {
  1290. o: [],
  1291. e: []
  1292. },
  1293. {
  1294. o: Em.A([[]]),
  1295. e: [[]]
  1296. },
  1297. {
  1298. o: 11,
  1299. e: 11
  1300. },
  1301. {
  1302. o: '11',
  1303. e: '11'
  1304. },
  1305. {
  1306. o: null,
  1307. e: null
  1308. }
  1309. ];
  1310. testCases.forEach(function (testCase, index) {
  1311. it('should convert objects and arrays to pure JS objects and arrays (' + (index + 1) + ')', function () {
  1312. expect(c.toJSInstance(testCase.o)).to.eql(testCase.e);
  1313. });
  1314. });
  1315. });
  1316. describe('#loadConfigThemes', function() {
  1317. beforeEach(function () {
  1318. sinon.stub(wizardController, 'loadConfigThemeForServices').returns({
  1319. always: Em.clb
  1320. });
  1321. sinon.stub(App.themesMapper, 'generateAdvancedTabs').returns(true);
  1322. sinon.stub(App.config, 'loadConfigsFromStack').returns({
  1323. done: Em.clb
  1324. });
  1325. sinon.stub(App.StackService, 'find').returns(Em.A([
  1326. Em.Object.create({
  1327. isSelected: true,
  1328. serviceName: 's1'
  1329. })
  1330. ]));
  1331. this.stub = sinon.stub(App, 'get');
  1332. });
  1333. afterEach(function () {
  1334. App.get.restore();
  1335. App.StackService.find.restore();
  1336. App.config.loadConfigsFromStack.restore();
  1337. App.themesMapper.generateAdvancedTabs.restore();
  1338. wizardController.loadConfigThemeForServices.restore();
  1339. });
  1340. it('Should load config themes', function(done) {
  1341. this.stub.returns(true);
  1342. wizardController.loadConfigThemes().then(function() {
  1343. done();
  1344. });
  1345. });
  1346. it('Should load config themes (2)', function(done) {
  1347. this.stub.returns(false);
  1348. wizardController.loadConfigThemes().then(function() {
  1349. done();
  1350. });
  1351. });
  1352. });
  1353. describe('#dataLoading', function () {
  1354. var clusterController = Em.Object.create({
  1355. isLoaded: false
  1356. });
  1357. beforeEach(function(){
  1358. sinon.stub(App.router,'get').returns(clusterController);
  1359. sinon.stub(wizardController, 'connectOutlet', Em.K);
  1360. clusterController.set('isLoaded', false);
  1361. });
  1362. afterEach(function(){
  1363. App.router.get.restore();
  1364. wizardController.connectOutlet.restore();
  1365. });
  1366. it('should load data', function () {
  1367. clusterController.set('isLoaded', true);
  1368. wizardController.dataLoading().then(function(data){
  1369. expect(data).to.be.undefined;
  1370. });
  1371. });
  1372. it('should load data after 25ms', function () {
  1373. clusterController.set('isLoaded', false);
  1374. setTimeout(function(){
  1375. clusterController.set('isLoaded', true);
  1376. },25);
  1377. wizardController.dataLoading().then(function(data){
  1378. expect(data).to.be.undefined;
  1379. });
  1380. });
  1381. });
  1382. describe('#saveMasterComponentHosts', function () {
  1383. var stepController = Em.Object.create({
  1384. selectedServicesMasters: [
  1385. Em.Object.create({
  1386. display_name: 'd0',
  1387. component_name: 'c0',
  1388. selectedHost: 'h0',
  1389. serviceId: 's0',
  1390. isInstalled: true
  1391. }),
  1392. Em.Object.create({
  1393. display_name: 'd1',
  1394. component_name: 'c1',
  1395. selectedHost: 'h1',
  1396. serviceId: 's1',
  1397. isInstalled: false
  1398. })
  1399. ]
  1400. }),
  1401. masterComponentHosts = [
  1402. {
  1403. display_name: 'd0',
  1404. component: 'c0',
  1405. hostName: 'h0',
  1406. serviceId: 's0',
  1407. isInstalled: true
  1408. },
  1409. {
  1410. display_name: 'd1',
  1411. component: 'c1',
  1412. hostName: 'h1',
  1413. serviceId: 's1',
  1414. isInstalled: false
  1415. }
  1416. ];
  1417. beforeEach(function () {
  1418. sinon.stub(wizardController, 'setDBProperty', Em.K);
  1419. });
  1420. afterEach(function () {
  1421. wizardController.setDBProperty.restore();
  1422. });
  1423. it('should save master component hosts', function () {
  1424. wizardController.saveMasterComponentHosts(stepController);
  1425. expect(wizardController.setDBProperty.calledOnce).to.be.true;
  1426. expect(wizardController.setDBProperty.calledWith('masterComponentHosts', masterComponentHosts)).to.be.true;
  1427. expect(wizardController.get('content.masterComponentHosts')).to.eql(masterComponentHosts);
  1428. });
  1429. });
  1430. describe('#clearMasterComponentHosts', function () {
  1431. beforeEach(function () {
  1432. sinon.stub(wizardController, 'setDBProperty', Em.K);
  1433. });
  1434. afterEach(function () {
  1435. wizardController.setDBProperty.restore();
  1436. });
  1437. it('should clear master component hosts', function () {
  1438. wizardController.set('content.masterComponentHosts', {});
  1439. wizardController.clearMasterComponentHosts();
  1440. expect(wizardController.setDBProperty.calledOnce).to.be.true;
  1441. expect(wizardController.setDBProperty.calledWith('masterComponentHosts', null)).to.be.true;
  1442. expect(wizardController.get('content.masterComponentHosts')).to.be.null;
  1443. });
  1444. });
  1445. describe('#loadRecommendations', function () {
  1446. beforeEach(function () {
  1447. sinon.stub(c, 'getDBProperty').returns({});
  1448. });
  1449. afterEach(function () {
  1450. c.getDBProperty.restore();
  1451. });
  1452. it('should set recommendations', function () {
  1453. c.set('content', {});
  1454. c.loadRecommendations();
  1455. expect(c.get('content.recommendations')).to.eql({});
  1456. });
  1457. });
  1458. describe("#resetOnClose()", function () {
  1459. var ctrl = Em.Object.create({
  1460. finish: Em.K,
  1461. popup: {
  1462. hide: Em.K
  1463. }
  1464. });
  1465. var mock = Em.Object.create({
  1466. resetUser: Em.K
  1467. });
  1468. beforeEach(function () {
  1469. sinon.stub(ctrl, 'finish');
  1470. sinon.stub(ctrl.popup, 'hide');
  1471. sinon.stub(App.router, 'get').returns(mock);
  1472. sinon.stub(App.clusterStatus, 'setClusterStatus', function (arg1, arg2) {
  1473. arg2.alwaysCallback();
  1474. });
  1475. sinon.stub(Em.run, 'next');
  1476. sinon.stub(mock, 'resetUser');
  1477. sinon.stub(App.router, 'transitionTo');
  1478. c.resetOnClose(ctrl, 'path');
  1479. });
  1480. afterEach(function () {
  1481. ctrl.finish.restore();
  1482. ctrl.popup.hide.restore();
  1483. App.router.get.restore();
  1484. App.clusterStatus.setClusterStatus.restore();
  1485. Em.run.next.restore();
  1486. mock.resetUser.restore();
  1487. App.router.transitionTo.restore();
  1488. });
  1489. it("resetUser should be called", function () {
  1490. expect(mock.resetUser.calledOnce).to.be.true;
  1491. });
  1492. it("finish should be called", function () {
  1493. expect(ctrl.finish.calledOnce).to.be.true;
  1494. });
  1495. it("isWorking should be true", function () {
  1496. expect(mock.get('isWorking')).to.be.true;
  1497. });
  1498. it("App.clusterStatus.setClusterStatus should be called", function () {
  1499. expect(App.clusterStatus.setClusterStatus.calledOnce).to.be.true;
  1500. });
  1501. it("popup should be hidden", function () {
  1502. expect(ctrl.get('popup').hide.calledOnce).to.be.true;
  1503. });
  1504. it("App.router.transitionTo should be called", function () {
  1505. expect(App.router.transitionTo.calledOnce).to.be.true;
  1506. });
  1507. it("Em.run.next should be called", function () {
  1508. expect(Em.run.next.calledOnce).to.be.true;
  1509. });
  1510. });
  1511. });