wizard_test.js 40 KB

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