step3_test.js 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307
  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 Ember = require('ember');
  19. var App = require('app');
  20. var c;
  21. require('utils/http_client');
  22. require('models/host');
  23. require('controllers/wizard/step3_controller');
  24. describe('App.WizardStep3Controller', function () {
  25. beforeEach(function() {
  26. c = App.WizardStep3Controller.create({
  27. wizardController: App.InstallerController.create(),
  28. disablePreviousSteps: Em.K
  29. });
  30. });
  31. describe('#getAllRegisteredHostsCallback', function () {
  32. it('One host is already in the cluster, one host is registered', function() {
  33. var controller = App.WizardStep3Controller.create({
  34. hostsInCluster: [{
  35. hostName: 'wst3_host1'
  36. }],
  37. bootHosts: [
  38. {name:'wst3_host1'},
  39. {name:'wst3_host2'}
  40. ]
  41. });
  42. var test_data = {
  43. items: [
  44. {
  45. Hosts: {
  46. host_name: 'wst3_host1'
  47. }
  48. },
  49. {
  50. Hosts: {
  51. host_name: 'wst3_host2'
  52. }
  53. },
  54. {
  55. Hosts: {
  56. host_name: 'wst3_host3'
  57. }
  58. }
  59. ]
  60. };
  61. controller.getAllRegisteredHostsCallback(test_data);
  62. expect(controller.get('hasMoreRegisteredHosts')).to.equal(true);
  63. expect(controller.get('registeredHosts').length).to.equal(1);
  64. });
  65. it('All hosts are new', function() {
  66. var controller = App.WizardStep3Controller.create({
  67. hostsInCluster: [{
  68. hostName: 'wst3_host1'
  69. }],
  70. bootHosts: [
  71. {name:'wst3_host3'},
  72. {name:'wst3_host4'}
  73. ]
  74. });
  75. var test_data = {
  76. items: [
  77. {
  78. Hosts: {
  79. host_name: 'wst3_host3'
  80. }
  81. },
  82. {
  83. Hosts: {
  84. host_name: 'wst3_host4'
  85. }
  86. }
  87. ]
  88. };
  89. controller.getAllRegisteredHostsCallback(test_data);
  90. expect(controller.get('hasMoreRegisteredHosts')).to.equal(false);
  91. expect(controller.get('registeredHosts')).to.equal('');
  92. });
  93. it('No new hosts', function() {
  94. var controller = App.WizardStep3Controller.create({
  95. hostsInCluster: [{
  96. hostName: 'wst3_host1'
  97. }],
  98. bootHosts: [
  99. {name:'wst3_host1'}
  100. ]
  101. });
  102. var test_data = {
  103. items: [
  104. {
  105. Hosts: {
  106. host_name: 'wst3_host1'
  107. }
  108. }
  109. ]
  110. };
  111. controller.getAllRegisteredHostsCallback(test_data);
  112. expect(controller.get('hasMoreRegisteredHosts')).to.equal(false);
  113. expect(controller.get('registeredHosts')).to.equal('');
  114. });
  115. });
  116. describe('#registrationTimeoutSecs', function() {
  117. it('Manual install', function() {
  118. var controller = App.WizardStep3Controller.create({
  119. content: {
  120. installOptions: {
  121. manualInstall: true
  122. }
  123. }
  124. });
  125. expect(controller.get('registrationTimeoutSecs')).to.equal(15);
  126. });
  127. it('Not manual install', function() {
  128. var controller = App.WizardStep3Controller.create({
  129. content: {
  130. installOptions: {
  131. manualInstall: false
  132. }
  133. }
  134. });
  135. expect(controller.get('registrationTimeoutSecs')).to.equal(120);
  136. });
  137. });
  138. describe('#isHostHaveWarnings', function() {
  139. var tests = [
  140. {
  141. warnings: [{},{}],
  142. m: 'Warnings exist',
  143. e: true
  144. },
  145. {
  146. warnings: [],
  147. m: 'Warnings don\'t exist',
  148. e: false
  149. }
  150. ];
  151. tests.forEach(function(test) {
  152. var controller = App.WizardStep3Controller.create();
  153. controller.set('warnings', test.warnings);
  154. it(test.m, function() {
  155. expect(controller.get('isHostHaveWarnings')).to.equal(test.e);
  156. });
  157. });
  158. });
  159. describe('#isWarningsBoxVisible', function() {
  160. it('for testMode should be always true', function() {
  161. App.testMode = true;
  162. expect(c.get('isWarningsBoxVisible')).to.equal(true);
  163. App.testMode = false;
  164. });
  165. it('for "real" mode should be based on isRegistrationInProgress', function() {
  166. c.set('disablePreviousSteps', Em.K);
  167. App.testMode = false;
  168. c.set('isRegistrationInProgress', false);
  169. expect(c.get('isWarningsBoxVisible')).to.equal(true);
  170. c.set('isRegistrationInProgress', true);
  171. expect(c.get('isWarningsBoxVisible')).to.equal(false);
  172. App.testMode = true;
  173. });
  174. });
  175. describe('#clearStep', function() {
  176. it('should clear hosts', function() {
  177. c.set('hosts', [{}, {}]);
  178. c.clearStep();
  179. expect(c.get('hosts')).to.eql([]);
  180. });
  181. it('should clear bootHosts', function() {
  182. c.set('bootHosts', [{}, {}]);
  183. c.clearStep();
  184. expect(c.get('bootHosts').length).to.equal(0);
  185. });
  186. it('should set stopBootstrap to false', function() {
  187. c.set('stopBootstrap', true);
  188. c.clearStep();
  189. expect(c.get('stopBootstrap')).to.equal(false);
  190. });
  191. it('should set wizardController DBProperty bootStatus to false', function() {
  192. c.get('wizardController').setDBProperty('bootStatus', true);
  193. c.clearStep();
  194. expect(c.get('wizardController').getDBProperty('bootStatus')).to.equal(false);
  195. });
  196. it('should set isSubmitDisabled to true', function() {
  197. c.set('isSubmitDisabled', false);
  198. c.clearStep();
  199. expect(c.get('isSubmitDisabled')).to.equal(true);
  200. });
  201. it('should set isSubmitDisabled to true', function() {
  202. c.set('isRetryDisabled', false);
  203. c.clearStep();
  204. expect(c.get('isRetryDisabled')).to.equal(true);
  205. });
  206. });
  207. describe('#loadStep', function() {
  208. it('should set registrationStartedAt to null', function() {
  209. c.set('disablePreviousSteps', Em.K);
  210. c.set('registrationStartedAt', {});
  211. c.loadStep();
  212. expect(c.get('registrationStartedAt')).to.be.null;
  213. });
  214. it('should set isLoaded to false', function() {
  215. c.set('disablePreviousSteps', Em.K);
  216. c.set('clearStep', Em.K);
  217. c.set('loadHosts', Em.K);
  218. c.set('isLoaded', true);
  219. c.loadStep();
  220. expect(c.get('isLoaded')).to.equal(false);
  221. });
  222. it('should call clearStep', function() {
  223. c.set('disablePreviousSteps', Em.K);
  224. c.set('loadHosts', Em.K);
  225. sinon.spy(c, 'clearStep');
  226. c.loadStep();
  227. expect(c.get('clearStep').calledOnce).to.equal(true);
  228. c.clearStep.restore();
  229. });
  230. it('should call loadHosts', function() {
  231. c.set('disablePreviousSteps', Em.K);
  232. c.set('loadHosts', Em.K);
  233. sinon.spy(c, 'loadHosts');
  234. c.loadStep();
  235. expect(c.get('loadHosts').calledOnce).to.equal(true);
  236. c.loadHosts.restore();
  237. });
  238. it('should call disablePreviousSteps', function() {
  239. c.set('disablePreviousSteps', Em.K);
  240. c.set('loadHosts', Em.K);
  241. sinon.spy(c, 'disablePreviousSteps');
  242. c.loadStep();
  243. expect(c.get('disablePreviousSteps').calledOnce).to.equal(true);
  244. c.disablePreviousSteps.restore();
  245. });
  246. });
  247. describe('#loadHosts', function() {
  248. it('should set isLoaded to true', function() {
  249. c.set('navigateStep', Em.K);
  250. c.set('content', {hosts: {}});
  251. c.loadHosts();
  252. expect(c.get('isLoaded')).to.equal(true);
  253. });
  254. it('should set bootStatus REGISTERED on testMode', function() {
  255. App.testMode = true;
  256. c.set('navigateStep', Em.K);
  257. c.set('content', {hosts: {c: {name: 'name'}}});
  258. c.loadHosts();
  259. expect(c.get('hosts').everyProperty('bootStatus', 'REGISTERED')).to.equal(true);
  260. });
  261. it('should set bootStatus DONE on "real" mode and when installOptions.manualInstall is selected', function() {
  262. App.testMode = false;
  263. c.set('navigateStep', Em.K);
  264. c.set('content', {installOptions:{manualInstall: true}, hosts: {c: {name: 'name'}}});
  265. c.loadHosts();
  266. expect(c.get('hosts').everyProperty('bootStatus', 'DONE')).to.equal(true);
  267. App.testMode = true;
  268. });
  269. it('should set bootStatus PENDING on "real" mode and when installOptions.manualInstall is not selected', function() {
  270. App.testMode = false;
  271. c.set('navigateStep', Em.K);
  272. c.set('content', {installOptions:{manualInstall: false}, hosts: {c: {name: 'name'}}});
  273. c.loadHosts();
  274. expect(c.get('hosts').everyProperty('bootStatus', 'PENDING')).to.equal(true);
  275. App.testMode = true;
  276. });
  277. it('should set bootStatus PENDING on "real" mode and when installOptions.manualInstall is not selected', function() {
  278. c.set('navigateStep', Em.K);
  279. c.set('content', {hosts: {c: {name: 'name'}, d: {name: 'name1'}}});
  280. c.loadHosts();
  281. expect(c.get('hosts').everyProperty('isChecked', false)).to.equal(true);
  282. });
  283. });
  284. describe('#parseHostInfo', function() {
  285. var tests = Em.A([
  286. {
  287. bootHosts: Em.A([
  288. Em.Object.create({name: 'c1', bootStatus: 'REGISTERED', bootLog: ''}),
  289. Em.Object.create({name: 'c2', bootStatus: 'REGISTERING', bootLog: ''}),
  290. Em.Object.create({name: 'c3', bootStatus: 'RUNNING', bootLog: ''})
  291. ]),
  292. hostsStatusFromServer: Em.A([
  293. {hostName: 'c1', status: 'REGISTERED', log: 'c1'},
  294. {hostName: 'c2', status: 'REGISTERED', log: 'c2'},
  295. {hostName: 'c3', status: 'RUNNING', log: 'c3'}
  296. ]),
  297. m: 'bootHosts not empty, hostsStatusFromServer not empty, one is RUNNING',
  298. e: {
  299. c: true,
  300. r: true
  301. }
  302. },
  303. {
  304. bootHosts: Em.A([]),
  305. hostsStatusFromServer: Em.A([
  306. {hostName: 'c1', status: 'REGISTERED', log: 'c1'},
  307. {hostName: 'c2', status: 'REGISTERED', log: 'c2'},
  308. {hostName: 'c3', status: 'RUNNING', log: 'c3'}
  309. ]),
  310. m: 'bootHosts is empty',
  311. e: {
  312. c: false,
  313. r: false
  314. }
  315. },
  316. {
  317. bootHosts: Em.A([
  318. Em.Object.create({name: 'c1', bootStatus: 'REGISTERED', bootLog: ''}),
  319. Em.Object.create({name: 'c2', bootStatus: 'REGISTERING', bootLog: ''}),
  320. Em.Object.create({name: 'c3', bootStatus: 'REGISTERED', bootLog: ''})
  321. ]),
  322. hostsStatusFromServer: Em.A([
  323. {hostName: 'c1', status: 'REGISTERED', log: 'c1'},
  324. {hostName: 'c2', status: 'REGISTERED', log: 'c2'},
  325. {hostName: 'c3', status: 'REGISTERED', log: 'c3'}
  326. ]),
  327. m: 'bootHosts not empty, hostsStatusFromServer not empty, no one is RUNNING',
  328. e: {
  329. c: true,
  330. r: false
  331. }
  332. }
  333. ]);
  334. tests.forEach(function(test) {
  335. it(test.m, function() {
  336. c.set('bootHosts', test.bootHosts);
  337. var r = c.parseHostInfo(test.hostsStatusFromServer);
  338. expect(r).to.equal(test.e.r);
  339. if (test.e.c) {
  340. test.hostsStatusFromServer.forEach(function(h) {
  341. var r = c.get('bootHosts').findProperty('name', h.hostName);
  342. if (!['REGISTERED', 'REGISTERING'].contains(r.get('bootStatus'))) {
  343. expect(r.get('bootStatus')).to.equal(h.status);
  344. expect(r.get('bootLog')).to.equal(h.log);
  345. }
  346. });
  347. }
  348. });
  349. });
  350. });
  351. describe('#removeHosts', function() {
  352. it('should call App.showConfirmationPopup', function() {
  353. sinon.spy(App, 'showConfirmationPopup');
  354. c.removeHosts(Em.A([]));
  355. expect(App.showConfirmationPopup.calledOnce).to.equal(true);
  356. App.showConfirmationPopup.restore();
  357. });
  358. it('primary should disable Submit if no more hosts', function() {
  359. var hosts = [{}];
  360. c.set('hosts', hosts);
  361. var popup = c.removeHosts(hosts);
  362. popup.onPrimary();
  363. expect(c.get('isSubmitDisabled')).to.equal(true);
  364. });
  365. });
  366. describe('#removeHost', function() {
  367. it('should call removeHosts with array as arg', function() {
  368. var host = {a:''};
  369. sinon.spy(c, 'removeHosts');
  370. c.removeHost(host);
  371. expect(c.removeHosts.calledWith([host]));
  372. c.removeHosts.restore();
  373. });
  374. });
  375. describe('#removeSelectedHosts', function() {
  376. it('should remove selected hosts', function() {
  377. c = App.WizardStep3Controller.create({
  378. wizardController: App.InstallerController.create(),
  379. hosts: [
  380. {isChecked: true, name: 'c1'},
  381. {isChecked: false, name: 'c2'}
  382. ]
  383. });
  384. c.removeSelectedHosts().onPrimary();
  385. expect(c.get('hosts').mapProperty('name')).to.eql(['c2']);
  386. });
  387. });
  388. describe('#selectedHostsPopup', function() {
  389. it('should show App.ModalPopup', function() {
  390. sinon.spy(App.ModalPopup, 'show');
  391. c.selectedHostsPopup();
  392. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  393. App.ModalPopup.show.restore();
  394. });
  395. });
  396. describe('#retryHosts', function () {
  397. var s;
  398. var installer = {launchBootstrap: Em.K};
  399. beforeEach(function () {
  400. sinon.spy(installer, "launchBootstrap");
  401. s = sinon.stub(App.router, 'get', function () {
  402. return installer;
  403. });
  404. sinon.stub(c, 'doBootstrap', Em.K);
  405. });
  406. afterEach(function () {
  407. c.doBootstrap.restore();
  408. s.restore();
  409. installer.launchBootstrap.restore();
  410. });
  411. it('should set numPolls to 0', function () {
  412. c.set('content', {installOptions: {}});
  413. c.set('numPolls', 123);
  414. c.retryHosts(Em.A([]));
  415. expect(c.get('numPolls')).to.equal(0);
  416. });
  417. it('should set registrationStartedAt to null', function () {
  418. c.set('content', {installOptions: {}});
  419. c.retryHosts(Em.A([]));
  420. expect(c.get('registrationStartedAt')).to.be.null;
  421. });
  422. it('should startRegistration if installOptions.manualInstall is true', function () {
  423. sinon.spy(c, 'startRegistration');
  424. c.set('content', {installOptions: {manualInstall: true}});
  425. c.retryHosts(Em.A([]));
  426. expect(c.startRegistration.calledOnce).to.equal(true);
  427. c.startRegistration.restore();
  428. });
  429. it('should launchBootstrap if installOptions.manualInstall is false', function () {
  430. c.set('content', {installOptions: {manualInstall: false}});
  431. c.retryHosts(Em.A([]));
  432. expect(installer.launchBootstrap.calledOnce).to.be.true;
  433. });
  434. });
  435. describe('#retryHost', function() {
  436. it('should callretryHosts with array as arg', function() {
  437. var host = {n: 'c'}, s = sinon.stub(App.router, 'get', function() {
  438. return {launchBootstrap: Em.K}
  439. });
  440. sinon.spy(c, 'retryHosts');
  441. c.set('content', {installOptions: {}});
  442. c.set('doBootstrap', Em.K);
  443. c.retryHost(host);
  444. expect(c.retryHosts.calledWith([host])).to.equal(true);
  445. c.retryHosts.restore();
  446. s.restore();
  447. });
  448. });
  449. describe('#retrySelectedHosts', function() {
  450. it('shouldn\'t do nothing if isRetryDisabled is true', function() {
  451. c.set('isRetryDisabled', true);
  452. sinon.spy(c, 'retryHosts');
  453. c.retrySelectedHosts();
  454. expect(c.retryHosts.called).to.equal(false);
  455. c.retryHosts.restore();
  456. });
  457. it('should retry hosts with FAILED bootStatus and set isRetryDisabled to true', function() {
  458. var s = sinon.stub(App.router, 'get', function() {
  459. return {launchBootstrap: Em.K}
  460. });
  461. c = App.WizardStep3Controller.create({
  462. wizardController: App.InstallerController.create(),
  463. bootHosts: Em.A([{name: 'c1', bootStatus: 'FAILED'}, {name: 'c2', bootStatus: 'REGISTERED'}]),
  464. content: {installOptions: {}},
  465. doBootstrap: Em.K
  466. });
  467. sinon.spy(c, 'retryHosts');
  468. c.retrySelectedHosts();
  469. expect(c.retryHosts.calledWith([{name: 'c1', bootStatus: 'RUNNING'}]));
  470. expect(c.get('isRetryDisabled')).to.equal(true);
  471. c.retryHosts.restore();
  472. s.restore();
  473. });
  474. });
  475. describe('#startBootstrap', function() {
  476. it('should drop numPolls and registrationStartedAt', function() {
  477. c.set('numPolls', 123);
  478. c.set('registrationStartedAt', 1234);
  479. c.set('doBootstrap', Em.K);
  480. c.startBootstrap();
  481. expect(c.get('numPolls')).to.equal(0);
  482. expect(c.get('registrationStartedAt')).to.be.null;
  483. });
  484. it('should drop numPolls and registrationStartedAt', function() {
  485. var hosts = Em.A([{name: 'c1'}, {name: 'c2'}]);
  486. c = App.WizardStep3Controller.create({
  487. wizardController: App.InstallerController.create(),
  488. doBootstrap: Em.K,
  489. setRegistrationInProgressOnce: Em.K,
  490. hosts: hosts
  491. });
  492. c.startBootstrap();
  493. expect(c.get('bootHosts').mapProperty('name')).to.eql(['c1','c2']);
  494. });
  495. });
  496. describe('#setRegistrationInProgressOnce', function() {
  497. it('should call Ember.run.once with "setRegistrationInProgress"', function() {
  498. sinon.spy(Em.run, 'once');
  499. c.setRegistrationInProgressOnce();
  500. expect(Em.run.once.firstCall.args[1]).to.equal('setRegistrationInProgress');
  501. Em.run.once.restore();
  502. });
  503. });
  504. describe('#setRegistrationInProgress', function() {
  505. var tests = Em.A([
  506. {
  507. bootHosts: [],
  508. isLoaded: false,
  509. e: true,
  510. m: 'no bootHosts and isLoaded is false'
  511. },
  512. {
  513. bootHosts: [],
  514. isLoaded: true,
  515. e: false,
  516. m: 'no bootHosts and isLoaded is true'
  517. },
  518. {
  519. bootHosts: [
  520. Em.Object.create({bootStatus: 'RUNNING'}),
  521. Em.Object.create({bootStatus: 'RUNNING'})
  522. ],
  523. isLoaded: true,
  524. e: false,
  525. m: 'bootHosts without REGISTERED/FAILED and isLoaded is true'
  526. },
  527. {
  528. bootHosts: [
  529. Em.Object.create({bootStatus: 'RUNNING'}),
  530. Em.Object.create({bootStatus: 'RUNNING'})
  531. ],
  532. isLoaded: false,
  533. e: true,
  534. m: 'bootHosts without REGISTERED/FAILED and isLoaded is false'
  535. },
  536. {
  537. bootHosts: [
  538. Em.Object.create({bootStatus: 'REGISTERED'}),
  539. Em.Object.create({bootStatus: 'RUNNING'})
  540. ],
  541. isLoaded: false,
  542. e: true,
  543. m: 'bootHosts with one REGISTERED and isLoaded is false'
  544. },
  545. {
  546. bootHosts: [
  547. Em.Object.create({bootStatus: 'FAILED'}),
  548. Em.Object.create({bootStatus: 'RUNNING'})
  549. ],
  550. isLoaded: false,
  551. e: true,
  552. m: 'bootHosts with one FAILED and isLoaded is false'
  553. },
  554. {
  555. bootHosts: [
  556. Em.Object.create({bootStatus: 'REGISTERED'}),
  557. Em.Object.create({bootStatus: 'RUNNING'})
  558. ],
  559. isLoaded: true,
  560. e: false,
  561. m: 'bootHosts with one REGISTERED and isLoaded is true'
  562. },
  563. {
  564. bootHosts: [
  565. Em.Object.create({bootStatus: 'FAILED'}),
  566. Em.Object.create({bootStatus: 'RUNNING'})
  567. ],
  568. isLoaded: true,
  569. e: false,
  570. m: 'bootHosts with one FAILED and isLoaded is true'
  571. }
  572. ]);
  573. tests.forEach(function(test) {
  574. it(test.m, function() {
  575. sinon.stub(c, 'disablePreviousSteps', Em.K);
  576. c.set('bootHosts', test.bootHosts);
  577. c.set('isLoaded', test.isLoaded);
  578. c.setRegistrationInProgress();
  579. expect(c.get('isRegistrationInProgress')).to.equal(test.e);
  580. c.disablePreviousSteps.restore();
  581. });
  582. });
  583. });
  584. describe('#doBootstrap', function() {
  585. beforeEach(function() {
  586. sinon.spy(App.ajax, 'send');
  587. });
  588. afterEach(function() {
  589. App.ajax.send.restore();
  590. });
  591. it('shouldn\'t do nothing if stopBootstrap is true', function() {
  592. c.set('stopBootstrap', true);
  593. c.doBootstrap();
  594. expect(App.ajax.send.called).to.equal(false);
  595. });
  596. it('should increment numPolls if stopBootstrap is false', function() {
  597. c.set('stopBootstrap', false);
  598. c.set('numPolls', 0);
  599. c.doBootstrap();
  600. expect(c.get('numPolls')).to.equal(1);
  601. });
  602. it('should do ajax call if stopBootstrap is false', function() {
  603. c.set('stopBootstrap', false);
  604. c.doBootstrap();
  605. expect(App.ajax.send.called).to.equal(true);
  606. });
  607. });
  608. describe('#startRegistration', function() {
  609. it('shouldn\'t do nothing if registrationStartedAt isn\'t null', function() {
  610. c.set('registrationStartedAt', 1234);
  611. sinon.spy(c, 'isHostsRegistered');
  612. c.startRegistration();
  613. expect(c.isHostsRegistered.called).to.equal(false);
  614. expect(c.get('registrationStartedAt')).to.equal(1234);
  615. c.isHostsRegistered.restore();
  616. });
  617. it('shouldn\'t do nothing if registrationStartedAt isn\'t null', function() {
  618. c.set('registrationStartedAt', null);
  619. sinon.spy(c, 'isHostsRegistered');
  620. c.startRegistration();
  621. expect(c.isHostsRegistered.calledOnce).to.equal(true);
  622. c.isHostsRegistered.restore();
  623. });
  624. });
  625. describe('#isHostsRegistered', function() {
  626. beforeEach(function() {
  627. sinon.spy(App.ajax, 'send');
  628. });
  629. afterEach(function() {
  630. App.ajax.send.restore();
  631. });
  632. it('shouldn\'t do nothing if stopBootstrap is true', function() {
  633. c.set('stopBootstrap', true);
  634. c.isHostsRegistered();
  635. expect(App.ajax.send.called).to.equal(false);
  636. });
  637. it('should do ajax call if stopBootstrap is false', function() {
  638. c.set('stopBootstrap', false);
  639. c.isHostsRegistered();
  640. expect(App.ajax.send.called).to.equal(true);
  641. });
  642. });
  643. describe('#isHostsRegisteredSuccessCallback', function() {
  644. var tests = Em.A([
  645. {
  646. bootHosts: Em.A([
  647. Em.Object.create({bootStatus: 'DONE'})
  648. ]),
  649. data: {items:[]},
  650. m: 'one host DONE',
  651. e: {
  652. bs: 'REGISTERING',
  653. getHostInfoCalled: false
  654. }
  655. },
  656. {
  657. bootHosts: Em.A([
  658. Em.Object.create({bootStatus: 'REGISTERING', name: 'c1'})
  659. ]),
  660. data: {items:[{Hosts: {host_name: 'c1'}}]},
  661. m: ' one host REGISTERING',
  662. e: {
  663. bs: 'FAILED',
  664. getHostInfoCalled: true
  665. }
  666. },
  667. {
  668. bootHosts: Em.A([
  669. Em.Object.create({bootStatus: 'REGISTERING', name: 'c1'})
  670. ]),
  671. data: {items:[{Hosts: {host_name: 'c2'}}]},
  672. m: 'one host REGISTERING but data without info about it',
  673. e: {
  674. bs: 'FAILED',
  675. getHostInfoCalled: true
  676. }
  677. },
  678. {
  679. bootHosts: Em.A([
  680. Em.Object.create({bootStatus: 'RUNNING', name: 'c1'})
  681. ]),
  682. data: {items:[{Hosts: {host_name: 'c1'}}]},
  683. m: ' one host RUNNING',
  684. e: {
  685. bs: 'RUNNING',
  686. getHostInfoCalled: false
  687. }
  688. }
  689. ]);
  690. tests.forEach(function(test) {
  691. it(test.m, function() {
  692. sinon.spy(c, 'getHostInfo');
  693. c.set('bootHosts', test.bootHosts);
  694. c.isHostsRegisteredSuccessCallback(test.data);
  695. expect(c.get('bootHosts')[0].get('bootStatus')).to.equal(test.e.bs);
  696. expect(c.getHostInfo.called).to.equal(test.e.getHostInfoCalled);
  697. c.getHostInfo.restore();
  698. });
  699. });
  700. });
  701. describe('#getAllRegisteredHosts', function() {
  702. it('should call App.ajax.send', function() {
  703. sinon.spy(App.ajax, 'send');
  704. c.getAllRegisteredHosts();
  705. expect(App.ajax.send.calledOnce).to.equal(true);
  706. App.ajax.send.restore();
  707. });
  708. });
  709. describe('#getAllRegisteredHostsCallback', function() {
  710. var tests = Em.A([
  711. {
  712. hostsInCluster: ['c3'],
  713. bootHosts: [{name:'c1'},{name:'c2'}],
  714. hosts: Em.A([
  715. {Hosts: {host_name:'c1'}},
  716. {Hosts: {host_name:'c2'}}
  717. ]),
  718. m: 'No registered hosts',
  719. e: {
  720. hasMoreRegisteredHosts: false,
  721. registeredHosts: ''
  722. }
  723. },
  724. {
  725. hostsInCluster: ['c4'],
  726. bootHosts: [{name:'c3'},{name:'c5'}],
  727. hosts: Em.A([
  728. {Hosts: {host_name:'c1'}},
  729. {Hosts: {host_name:'c2'}}
  730. ]),
  731. m: '2 registered hosts',
  732. e: {
  733. hasMoreRegisteredHosts: true,
  734. registeredHosts: ['c1','c2']
  735. }
  736. },
  737. {
  738. hostsInCluster: ['c4'],
  739. bootHosts: [{name:'c1'},{name:'c5'}],
  740. hosts: Em.A([
  741. {Hosts: {host_name:'c1'}},
  742. {Hosts: {host_name:'c2'}}
  743. ]),
  744. m: '1 registered host',
  745. e: {
  746. hasMoreRegisteredHosts: true,
  747. registeredHosts: ['c2']
  748. }
  749. },
  750. {
  751. hostsInCluster: ['c1'],
  752. bootHosts: [{name:'c3'},{name:'c5'}],
  753. hosts: Em.A([
  754. {Hosts: {host_name:'c1'}},
  755. {Hosts: {host_name:'c2'}}
  756. ]),
  757. m: '1 registered host (2)',
  758. e: {
  759. hasMoreRegisteredHosts: true,
  760. registeredHosts: ['c2']
  761. }
  762. }
  763. ]);
  764. tests.forEach(function(test) {
  765. it(test.m, function() {
  766. c.reopen({hostsInCluster: test.hostsInCluster, setRegistrationInProgress: Em.K});
  767. c.set('bootHosts', test.bootHosts);
  768. c.getAllRegisteredHostsCallback({items:test.hosts});
  769. expect(c.get('hasMoreRegisteredHosts')).to.equal(test.e.hasMoreRegisteredHosts);
  770. expect(c.get('registeredHosts')).to.eql(test.e.registeredHosts);
  771. });
  772. });
  773. });
  774. describe('#registerErrPopup', function() {
  775. it('should call App.ModalPopup.show', function() {
  776. sinon.spy(App.ModalPopup, 'show');
  777. c.registerErrPopup();
  778. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  779. App.ModalPopup.show.restore();
  780. });
  781. });
  782. describe('#getHostInfo', function() {
  783. it('should do ajax request', function() {
  784. sinon.spy(App.ajax, 'send');
  785. c.getHostInfo();
  786. expect(App.ajax.send.calledOnce).to.equal(true);
  787. App.ajax.send.restore();
  788. });
  789. });
  790. describe('#getHostInfoErrorCallback', function() {
  791. it('should call registerErrPopup', function() {
  792. sinon.spy(c, 'registerErrPopup');
  793. c.getHostInfoErrorCallback();
  794. expect(c.registerErrPopup.calledOnce).to.equal(true);
  795. c.registerErrPopup.restore();
  796. });
  797. });
  798. describe('#stopRegistration', function() {
  799. var tests = Em.A([
  800. {
  801. bootHosts: [{bootStatus: 'REGISTERED'}, {bootStatus: 'RUNNING'}],
  802. e: {isSubmitDisabled: false, isRetryDisabled: true}
  803. },
  804. {
  805. bootHosts: [{bootStatus: 'FAILED'}, {bootStatus: 'RUNNING'}],
  806. e: {isSubmitDisabled: true, isRetryDisabled: false}
  807. },
  808. {
  809. bootHosts: [{bootStatus: 'FAILED'}, {bootStatus: 'REGISTERED'}],
  810. e: {isSubmitDisabled: false, isRetryDisabled: false}
  811. },
  812. {
  813. bootHosts: [{bootStatus: 'RUNNING'}, {bootStatus: 'RUNNING'}],
  814. e: {isSubmitDisabled: true, isRetryDisabled: true}
  815. }
  816. ]);
  817. tests.forEach(function(test) {
  818. it(test.bootHosts.mapProperty('bootStatus').join(', '), function() {
  819. c.reopen({bootHosts: test.bootHosts});
  820. c.stopRegistration();
  821. expect(c.get('isSubmitDisabled')).to.equal(test.e.isSubmitDisabled);
  822. expect(c.get('isRetryDisabled')).to.equal(test.e.isRetryDisabled);
  823. });
  824. });
  825. });
  826. describe('#submit', function() {
  827. it('if isHostHaveWarnings should show confirmation popup', function() {
  828. c.reopen({isHostHaveWarnings: true});
  829. sinon.spy(App.ModalPopup, 'show');
  830. c.submit();
  831. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  832. App.ModalPopup.show.restore();
  833. });
  834. it('if isHostHaveWarnings should show confirmation popup. on Primary should set bootHosts to content.hosts', function() {
  835. var bootHosts = [{name: 'c1'}];
  836. c.reopen({isHostHaveWarnings: true, bootHosts: bootHosts, hosts: []});
  837. c.submit().onPrimary();
  838. expect(c.get('content.hosts')).to.eql(bootHosts);
  839. });
  840. it('if isHostHaveWarnings is false should set bootHosts to content.hosts', function() {
  841. var bootHosts = [{name: 'c1'}];
  842. c.reopen({isHostHaveWarnings: false, bootHosts: bootHosts, hosts: []});
  843. c.submit();
  844. expect(c.get('content.hosts')).to.eql(bootHosts);
  845. });
  846. });
  847. describe('#hostLogPopup', function() {
  848. it('should show App.ModalPopup', function() {
  849. sinon.spy(App.ModalPopup, 'show');
  850. c.hostLogPopup({context:Em.Object.create({})});
  851. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  852. App.ModalPopup.show.restore();
  853. });
  854. });
  855. describe('#rerunChecksSuccessCallback', function() {
  856. beforeEach(function() {
  857. sinon.stub(c, 'parseWarnings', Em.K);
  858. });
  859. afterEach(function() {
  860. c.parseWarnings.restore();
  861. });
  862. it('should set checksUpdateProgress to 100', function() {
  863. c.set('checksUpdateProgress', 0);
  864. c.rerunChecksSuccessCallback({});
  865. expect(c.get('checksUpdateProgress')).to.equal(100);
  866. });
  867. it('should set checksUpdateStatus to SUCCESS', function() {
  868. c.set('checksUpdateStatus', '');
  869. c.rerunChecksSuccessCallback({});
  870. expect(c.get('checksUpdateStatus')).to.equal('SUCCESS');
  871. });
  872. it('should set call parseWarnings', function() {
  873. c.rerunChecksSuccessCallback({});
  874. expect(c.parseWarnings.calledOnce).to.equal(true);
  875. });
  876. });
  877. describe('#rerunChecksErrorCallback', function() {
  878. it('should set checksUpdateProgress to 100', function() {
  879. c.set('checksUpdateProgress', 0);
  880. c.rerunChecksErrorCallback({});
  881. expect(c.get('checksUpdateProgress')).to.equal(100);
  882. });
  883. it('should set checksUpdateStatus to FAILED', function() {
  884. c.set('checksUpdateStatus', '');
  885. c.rerunChecksErrorCallback({});
  886. expect(c.get('checksUpdateStatus')).to.equal('FAILED');
  887. });
  888. });
  889. describe('#filterBootHosts', function() {
  890. var tests = Em.A([
  891. {
  892. bootHosts: [
  893. Em.Object.create({name: 'c1'}),
  894. Em.Object.create({name: 'c2'})
  895. ],
  896. data: {
  897. items: [
  898. {Hosts: {host_name: 'c1'}}
  899. ]
  900. },
  901. m: 'one host',
  902. e: ['c1']
  903. },
  904. {
  905. bootHosts: [
  906. Em.Object.create({name: 'c1'}),
  907. Em.Object.create({name: 'c2'})
  908. ],
  909. data: {
  910. items: [
  911. {Hosts: {host_name: 'c3'}}
  912. ]
  913. },
  914. m: 'no hosts',
  915. e: []
  916. },
  917. {
  918. bootHosts: [
  919. Em.Object.create({name: 'c1'}),
  920. Em.Object.create({name: 'c2'})
  921. ],
  922. data: {
  923. items: [
  924. {Hosts: {host_name: 'c1'}},
  925. {Hosts: {host_name: 'c2'}}
  926. ]
  927. },
  928. m: 'many hosts',
  929. e: ['c1', 'c2']
  930. }
  931. ]);
  932. tests.forEach(function(test) {
  933. it(test.m, function() {
  934. c.reopen({bootHosts: test.bootHosts});
  935. var filteredData = c.filterBootHosts(test.data);
  936. expect(filteredData.items.mapProperty('Hosts.host_name')).to.eql(test.e);
  937. });
  938. });
  939. });
  940. describe('#hostWarningsPopup', function() {
  941. it('should show App.ModalPopup', function() {
  942. sinon.spy(App.ModalPopup, 'show');
  943. c.hostWarningsPopup();
  944. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  945. App.ModalPopup.show.restore();
  946. });
  947. });
  948. describe('#registeredHostsPopup', function() {
  949. it('should show App.ModalPopup', function() {
  950. sinon.spy(App.ModalPopup, 'show');
  951. c.registeredHostsPopup();
  952. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  953. App.ModalPopup.show.restore();
  954. });
  955. });
  956. describe('#parseWarnings', function() {
  957. it('no warnings if last_agent_env isn\'t specified', function() {
  958. c.set('warnings', [{}]);
  959. c.set('warningsByHost', [{},{}]);
  960. c.parseWarnings({items:[{Hosts:{host_name:'c1'}}]});
  961. expect(c.get('warnings')).to.eql([]);
  962. expect(c.get('warningsByHost.length')).to.equal(1); // default group
  963. expect(c.get('isWarningsLoaded')).to.equal(true);
  964. });
  965. Em.A([
  966. {
  967. m: 'parse stackFoldersAndFiles',
  968. tests : Em.A([
  969. {
  970. items: [{Hosts:{host_name: 'c1', last_agent_env: {stackFoldersAndFiles: []}}}],
  971. m: 'empty stackFoldersAndFiles',
  972. e: {
  973. warnings: [],
  974. warningsByHost: [0]
  975. }
  976. },
  977. {
  978. items: [{Hosts:{host_name: 'c1', last_agent_env: {stackFoldersAndFiles: [{name: 'n1'}]}}}],
  979. m: 'not empty stackFoldersAndFiles',
  980. e: {
  981. warnings: [{
  982. name: 'n1',
  983. hosts: ['c1'],
  984. onSingleHost: true,
  985. category: 'fileFolders'
  986. }],
  987. warningsByHost: [1]
  988. }
  989. },
  990. {
  991. items: [
  992. {Hosts:{host_name: 'c1', last_agent_env: {stackFoldersAndFiles: [{name: 'n1'}]}}},
  993. {Hosts:{host_name: 'c2', last_agent_env: {stackFoldersAndFiles: [{name: 'n1'}]}}}
  994. ],
  995. m: 'not empty stackFoldersAndFiles on two hosts',
  996. e: {
  997. warnings: [{
  998. name: 'n1',
  999. hosts: ['c1', 'c2'],
  1000. onSingleHost: false,
  1001. category: 'fileFolders'
  1002. }],
  1003. warningsByHost: [1]
  1004. }
  1005. }
  1006. ])
  1007. },
  1008. {
  1009. m: 'parse installedPackages',
  1010. tests : Em.A([
  1011. {
  1012. items: [{Hosts:{host_name: 'c1', last_agent_env: {installedPackages: []}}}],
  1013. m: 'empty installedPackages',
  1014. e: {
  1015. warnings: [],
  1016. warningsByHost: [0]
  1017. }
  1018. },
  1019. {
  1020. items: [{Hosts:{host_name: 'c1', last_agent_env: {installedPackages: [{name: 'n1'}]}}}],
  1021. m: 'not empty installedPackages',
  1022. e: {
  1023. warnings: [{
  1024. name: 'n1',
  1025. hosts: ['c1'],
  1026. onSingleHost: true,
  1027. category: 'packages'
  1028. }],
  1029. warningsByHost: [1]
  1030. }
  1031. },
  1032. {
  1033. items: [
  1034. {Hosts:{host_name: 'c1', last_agent_env: {installedPackages: [{name: 'n1'}]}}},
  1035. {Hosts:{host_name: 'c2', last_agent_env: {installedPackages: [{name: 'n1'}]}}}
  1036. ],
  1037. m: 'not empty installedPackages on two hosts',
  1038. e: {
  1039. warnings: [{
  1040. name: 'n1',
  1041. hosts: ['c1', 'c2'],
  1042. onSingleHost: false,
  1043. category: 'packages'
  1044. }],
  1045. warningsByHost: [1]
  1046. }
  1047. }
  1048. ])
  1049. },
  1050. {
  1051. m: 'parse hostHealth.liveServices',
  1052. tests : Em.A([
  1053. {
  1054. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth: []}}}],
  1055. m: 'empty hostHealth',
  1056. e: {
  1057. warnings: [],
  1058. warningsByHost: [0]
  1059. }
  1060. },
  1061. {
  1062. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{liveServices: []}}}}],
  1063. m: 'empty liveServices',
  1064. e: {
  1065. warnings: [],
  1066. warningsByHost: [0]
  1067. }
  1068. },
  1069. {
  1070. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{liveServices: [{status: 'Unhealthy', name: 'n1'}]}}}}],
  1071. m: 'not empty hostHealth.liveServices',
  1072. e: {
  1073. warnings: [{
  1074. name: 'n1',
  1075. hosts: ['c1'],
  1076. onSingleHost: true,
  1077. category: 'services'
  1078. }],
  1079. warningsByHost: [1]
  1080. }
  1081. },
  1082. {
  1083. items: [
  1084. {Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{liveServices: [{status: 'Unhealthy', name: 'n1'}]}}}},
  1085. {Hosts:{host_name: 'c2', last_agent_env: {hostHealth:{liveServices: [{status: 'Unhealthy', name: 'n1'}]}}}}
  1086. ],
  1087. m: 'not empty hostHealth.liveServices on two hosts',
  1088. e: {
  1089. warnings: [{
  1090. name: 'n1',
  1091. hosts: ['c1', 'c2'],
  1092. onSingleHost: false,
  1093. category: 'services'
  1094. }],
  1095. warningsByHost: [1, 1]
  1096. }
  1097. }
  1098. ])
  1099. },
  1100. {
  1101. m: 'parse existingUsers',
  1102. tests : Em.A([
  1103. {
  1104. items: [{Hosts:{host_name: 'c1', last_agent_env: {existingUsers: []}}}],
  1105. m: 'empty existingUsers',
  1106. e: {
  1107. warnings: [],
  1108. warningsByHost: [0]
  1109. }
  1110. },
  1111. {
  1112. items: [{Hosts:{host_name: 'c1', last_agent_env: {existingUsers: [{userName: 'n1'}]}}}],
  1113. m: 'not empty existingUsers',
  1114. e: {
  1115. warnings: [{
  1116. name: 'n1',
  1117. hosts: ['c1'],
  1118. onSingleHost: true,
  1119. category: 'users'
  1120. }],
  1121. warningsByHost: [1]
  1122. }
  1123. },
  1124. {
  1125. items: [
  1126. {Hosts:{host_name: 'c1', last_agent_env: {existingUsers: [{userName: 'n1'}]}}},
  1127. {Hosts:{host_name: 'c2', last_agent_env: {existingUsers: [{userName: 'n1'}]}}}
  1128. ],
  1129. m: 'not empty existingUsers on two hosts',
  1130. e: {
  1131. warnings: [{
  1132. name: 'n1',
  1133. hosts: ['c1', 'c2'],
  1134. onSingleHost: false,
  1135. category: 'users'
  1136. }],
  1137. warningsByHost: [1, 1]
  1138. }
  1139. }
  1140. ])
  1141. },
  1142. {
  1143. m: 'parse alternatives',
  1144. tests : Em.A([
  1145. {
  1146. items: [{Hosts:{host_name: 'c1', last_agent_env: {alternatives: []}}}],
  1147. m: 'empty alternatives',
  1148. e: {
  1149. warnings: [],
  1150. warningsByHost: [0]
  1151. }
  1152. },
  1153. {
  1154. items: [{Hosts:{host_name: 'c1', last_agent_env: {alternatives: [{name: 'n1'}]}}}],
  1155. m: 'not empty alternatives',
  1156. e: {
  1157. warnings: [{
  1158. name: 'n1',
  1159. hosts: ['c1'],
  1160. onSingleHost: true,
  1161. category: 'alternatives'
  1162. }],
  1163. warningsByHost: [1]
  1164. }
  1165. },
  1166. {
  1167. items: [
  1168. {Hosts:{host_name: 'c1', last_agent_env: {alternatives: [{name: 'n1'}]}}},
  1169. {Hosts:{host_name: 'c2', last_agent_env: {alternatives: [{name: 'n1'}]}}}
  1170. ],
  1171. m: 'not empty alternatives on two hosts',
  1172. e: {
  1173. warnings: [{
  1174. name: 'n1',
  1175. hosts: ['c1', 'c2'],
  1176. onSingleHost: false,
  1177. category: 'alternatives'
  1178. }],
  1179. warningsByHost: [1, 1]
  1180. }
  1181. }
  1182. ])
  1183. },
  1184. {
  1185. m: 'parse hostHealth.activeJavaProcs',
  1186. tests : Em.A([
  1187. {
  1188. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth: [], javaProcs: []}}}],
  1189. m: 'empty hostHealth',
  1190. e: {
  1191. warnings: [],
  1192. warningsByHost: [0]
  1193. }
  1194. },
  1195. {
  1196. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{activeJavaProcs: []}}}}],
  1197. m: 'empty activeJavaProcs',
  1198. e: {
  1199. warnings: [],
  1200. warningsByHost: [0]
  1201. }
  1202. },
  1203. {
  1204. items: [{Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{activeJavaProcs: [{pid: 'n1', command: ''}]}}}}],
  1205. m: 'not empty hostHealth.activeJavaProcs',
  1206. e: {
  1207. warnings: [{
  1208. pid: 'n1',
  1209. hosts: ['c1'],
  1210. onSingleHost: true,
  1211. category: 'processes'
  1212. }],
  1213. warningsByHost: [1]
  1214. }
  1215. },
  1216. {
  1217. items: [
  1218. {Hosts:{host_name: 'c1', last_agent_env: {hostHealth:{activeJavaProcs: [{pid: 'n1', command: ''}]}}}},
  1219. {Hosts:{host_name: 'c2', last_agent_env: {hostHealth:{activeJavaProcs: [{pid: 'n1', command: ''}]}}}}
  1220. ],
  1221. m: 'not empty hostHealth.activeJavaProcs on two hosts',
  1222. e: {
  1223. warnings: [{
  1224. pid: 'n1',
  1225. hosts: ['c1', 'c2'],
  1226. onSingleHost: false,
  1227. category: 'processes'
  1228. }],
  1229. warningsByHost: [1, 1]
  1230. }
  1231. }
  1232. ])
  1233. }
  1234. ]).forEach(function(category) {
  1235. describe(category.m, function() {
  1236. category.tests.forEach(function(test) {
  1237. it(test.m, function() {
  1238. c.parseWarnings({items: test.items});
  1239. c.get('warnings').forEach(function(w, i) {
  1240. Em.keys(test.e.warnings[i]).forEach(function(k) {
  1241. expect(w[k]).to.eql(test.e.warnings[i][k]);
  1242. });
  1243. });
  1244. for(var i in test.e.warningsByHost) {
  1245. if(test.e.warningsByHost.hasOwnProperty(i)) {
  1246. expect(c.get('warningsByHost')[i].warnings.length).to.equal(test.e.warningsByHost[i]);
  1247. }
  1248. }
  1249. });
  1250. });
  1251. });
  1252. });
  1253. });
  1254. });