wizard_test.js 48 KB

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