step6_test.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  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. require('utils/helper');
  21. require('controllers/wizard/step6_controller');
  22. var controller,
  23. services = [
  24. Em.Object.create({
  25. serviceName: 'MAPREDUCE',
  26. isSelected: true
  27. }),
  28. Em.Object.create({
  29. serviceName: 'YARN',
  30. isSelected: true
  31. }),
  32. Em.Object.create({
  33. serviceName: 'HBASE',
  34. isSelected: true
  35. }),
  36. Em.Object.create({
  37. serviceName: 'HDFS',
  38. isSelected: true
  39. }),
  40. Em.Object.create({
  41. serviceName: 'STORM',
  42. isSelected: true
  43. }),
  44. Em.Object.create({
  45. serviceName: 'FLUME',
  46. isSelected: true
  47. })
  48. ];
  49. describe('App.WizardStep6Controller', function () {
  50. beforeEach(function () {
  51. controller = App.WizardStep6Controller.create();
  52. controller.set('content', {
  53. hosts: {},
  54. masterComponentHosts: {},
  55. services: services
  56. });
  57. var h = {}, m = [];
  58. Em.A(['host0', 'host1', 'host2', 'host3']).forEach(function (hostName) {
  59. var obj = Em.Object.create({
  60. name: hostName,
  61. hostName: hostName,
  62. bootStatus: 'REGISTERED'
  63. });
  64. h[hostName] = obj;
  65. m.push(obj);
  66. });
  67. controller.set('content.hosts', h);
  68. controller.set('content.masterComponentHosts', m);
  69. controller.set('isMasters', false);
  70. });
  71. describe('#isAddHostWizard', function () {
  72. it('true if content.controllerName is addHostController', function () {
  73. controller.set('content.controllerName', 'addHostController');
  74. expect(controller.get('isAddHostWizard')).to.equal(true);
  75. });
  76. it('false if content.controllerName is not addHostController', function () {
  77. controller.set('content.controllerName', 'mainController');
  78. expect(controller.get('isAddHostWizard')).to.equal(false);
  79. });
  80. });
  81. describe('#isInstallerWizard', function () {
  82. it('true if content.controllerName is addHostController', function () {
  83. controller.set('content.controllerName', 'installerController');
  84. expect(controller.get('isInstallerWizard')).to.equal(true);
  85. });
  86. it('false if content.controllerName is not addHostController', function () {
  87. controller.set('content.controllerName', 'mainController');
  88. expect(controller.get('isInstallerWizard')).to.equal(false);
  89. });
  90. });
  91. describe('#isAddServiceWizard', function () {
  92. it('true if content.controllerName is addServiceController', function () {
  93. controller.set('content.controllerName', 'addServiceController');
  94. expect(controller.get('isAddServiceWizard')).to.equal(true);
  95. });
  96. it('false if content.controllerName is not addServiceController', function () {
  97. controller.set('content.controllerName', 'mainController');
  98. expect(controller.get('isAddServiceWizard')).to.equal(false);
  99. });
  100. });
  101. describe('#clearStep', function () {
  102. beforeEach(function () {
  103. sinon.stub(controller, 'clearError', Em.K);
  104. });
  105. afterEach(function () {
  106. controller.clearError.restore();
  107. });
  108. it('should call clearError', function () {
  109. controller.clearStep();
  110. expect(controller.clearError.calledOnce).to.equal(true);
  111. });
  112. it('should clear hosts', function () {
  113. controller.set('hosts', [
  114. {},
  115. {}
  116. ]);
  117. controller.clearStep();
  118. expect(controller.get('hosts')).to.eql([]);
  119. });
  120. it('should clear headers', function () {
  121. controller.set('headers', [
  122. {},
  123. {}
  124. ]);
  125. controller.clearStep();
  126. expect(controller.get('headers')).to.eql([]);
  127. });
  128. it('should set isLoaded to false', function () {
  129. controller.set('isLoaded', true);
  130. controller.clearStep();
  131. expect(controller.get('isLoaded')).to.equal(false);
  132. });
  133. });
  134. describe('#selectAllNodes', function () {
  135. beforeEach(function () {
  136. sinon.stub(controller, 'setAllNodes', Em.K);
  137. });
  138. afterEach(function () {
  139. controller.setAllNodes.restore();
  140. });
  141. it('should call setAllNodes', function () {
  142. controller.selectAllNodes({context: {name: 'name'}});
  143. expect(controller.setAllNodes.calledWith('name', true)).to.equal(true);
  144. });
  145. it('shouldn\'t call setAllNodes', function () {
  146. controller.selectAllNodes();
  147. expect(controller.setAllNodes.called).to.equal(false);
  148. });
  149. });
  150. describe('#deselectAllNodes', function () {
  151. beforeEach(function () {
  152. sinon.stub(controller, 'setAllNodes', Em.K);
  153. });
  154. afterEach(function () {
  155. controller.setAllNodes.restore();
  156. });
  157. it('should call setAllNodes', function () {
  158. controller.deselectAllNodes({context: {name: 'name'}});
  159. expect(controller.setAllNodes.calledWith('name', false)).to.equal(true);
  160. });
  161. it('shouldn\'t call setAllNodes', function () {
  162. controller.deselectAllNodes();
  163. expect(controller.setAllNodes.called).to.equal(false);
  164. });
  165. });
  166. describe('#checkCallback', function () {
  167. beforeEach(function () {
  168. sinon.stub(controller, 'clearError', Em.K);
  169. });
  170. afterEach(function () {
  171. controller.clearError.restore();
  172. });
  173. it('should call clearError', function () {
  174. controller.checkCallback('');
  175. expect(controller.clearError.calledOnce).to.equal(true);
  176. });
  177. Em.A([
  178. {
  179. m: 'all checked, isInstalled false',
  180. headers: Em.A([
  181. Em.Object.create({name: 'c1'})
  182. ]),
  183. hosts: Em.A([
  184. Em.Object.create({
  185. checkboxes: Em.A([
  186. Em.Object.create({
  187. component: 'c1',
  188. isInstalled: false,
  189. checked: true
  190. })
  191. ])
  192. })
  193. ]),
  194. component: 'c1',
  195. e: {
  196. allChecked: true,
  197. noChecked: false
  198. }
  199. },
  200. {
  201. m: 'all checked, isInstalled true',
  202. headers: Em.A([
  203. Em.Object.create({name: 'c1'})
  204. ]),
  205. hosts: Em.A([
  206. Em.Object.create({
  207. checkboxes: Em.A([
  208. Em.Object.create({
  209. component: 'c1',
  210. isInstalled: true,
  211. checked: true
  212. })
  213. ])
  214. })
  215. ]),
  216. component: 'c1',
  217. e: {
  218. allChecked: true,
  219. noChecked: true
  220. }
  221. },
  222. {
  223. m: 'no one checked',
  224. headers: Em.A([
  225. Em.Object.create({name: 'c1'})
  226. ]),
  227. hosts: Em.A([
  228. Em.Object.create({
  229. checkboxes: Em.A([
  230. Em.Object.create({
  231. component: 'c1',
  232. isInstalled: false,
  233. checked: false
  234. })
  235. ])
  236. })
  237. ]),
  238. component: 'c1',
  239. e: {
  240. allChecked: false,
  241. noChecked: true
  242. }
  243. },
  244. {
  245. m: 'some checked',
  246. headers: Em.A([
  247. Em.Object.create({name: 'c1'})
  248. ]),
  249. hosts: Em.A([
  250. Em.Object.create({
  251. checkboxes: Em.A([
  252. Em.Object.create({
  253. component: 'c1',
  254. isInstalled: false,
  255. checked: true
  256. }),
  257. Em.Object.create({
  258. component: 'c1',
  259. isInstalled: false,
  260. checked: false
  261. })
  262. ])
  263. })
  264. ]),
  265. component: 'c1',
  266. e: {
  267. allChecked: false,
  268. noChecked: false
  269. }
  270. },
  271. {
  272. m: 'some checked, some isInstalled true',
  273. headers: Em.A([
  274. Em.Object.create({name: 'c1'})
  275. ]),
  276. hosts: Em.A([
  277. Em.Object.create({
  278. checkboxes: Em.A([
  279. Em.Object.create({
  280. component: 'c1',
  281. isInstalled: true,
  282. checked: true
  283. }),
  284. Em.Object.create({
  285. component: 'c1',
  286. isInstalled: true,
  287. checked: true
  288. })
  289. ])
  290. })
  291. ]),
  292. component: 'c1',
  293. e: {
  294. allChecked: true,
  295. noChecked: true
  296. }
  297. },
  298. {
  299. m: 'some checked, some isInstalled true (2)',
  300. headers: Em.A([
  301. Em.Object.create({name: 'c1'})
  302. ]),
  303. hosts: Em.A([
  304. Em.Object.create({
  305. checkboxes: Em.A([
  306. Em.Object.create({
  307. component: 'c1',
  308. isInstalled: false,
  309. checked: false
  310. }),
  311. Em.Object.create({
  312. component: 'c1',
  313. isInstalled: true,
  314. checked: true
  315. })
  316. ])
  317. })
  318. ]),
  319. component: 'c1',
  320. e: {
  321. allChecked: false,
  322. noChecked: true
  323. }
  324. }
  325. ]).forEach(function (test) {
  326. it(test.m, function () {
  327. controller.clearStep();
  328. controller.set('headers', test.headers);
  329. controller.set('hosts', test.hosts);
  330. controller.checkCallback(test.component);
  331. var header = controller.get('headers').findProperty('name', test.component);
  332. expect(header.get('allChecked')).to.equal(test.e.allChecked);
  333. expect(header.get('noChecked')).to.equal(test.e.noChecked);
  334. });
  335. });
  336. });
  337. describe('#getHostNames', function () {
  338. var tests = Em.A([
  339. {
  340. hosts: {
  341. h1: {bootStatus: 'REGISTERED', name: 'h1'},
  342. h2: {bootStatus: 'REGISTERED', name: 'h2'},
  343. h3: {bootStatus: 'REGISTERED', name: 'h3'}
  344. },
  345. m: 'All REGISTERED',
  346. e: ['h1', 'h2', 'h3']
  347. },
  348. {
  349. hosts: {
  350. h1: {bootStatus: 'REGISTERED', name: 'h1'},
  351. h2: {bootStatus: 'FAILED', name: 'h2'},
  352. h3: {bootStatus: 'REGISTERED', name: 'h3'}
  353. },
  354. m: 'Some REGISTERED',
  355. e: ['h1', 'h3']
  356. },
  357. {
  358. hosts: {
  359. h1: {bootStatus: 'FAILED', name: 'h1'},
  360. h2: {bootStatus: 'FAILED', name: 'h2'},
  361. h3: {bootStatus: 'FAILED', name: 'h3'}
  362. },
  363. m: 'No one REGISTERED',
  364. e: []
  365. },
  366. {
  367. hosts: {},
  368. m: 'Empty hosts',
  369. e: []
  370. }
  371. ]);
  372. tests.forEach(function (test) {
  373. it(test.m, function () {
  374. controller.set('content.hosts', test.hosts);
  375. var r = controller.getHostNames();
  376. expect(r).to.eql(test.e);
  377. });
  378. });
  379. });
  380. describe('#validate', function () {
  381. var tests = Em.A([
  382. {
  383. controllerName: 'addHostController',
  384. method: 'validateEachHost',
  385. r: true,
  386. e: true
  387. },
  388. {
  389. controllerName: 'addHostController',
  390. method: 'validateEachHost',
  391. r: false,
  392. e: false
  393. },
  394. {
  395. controllerName: 'addServiceController',
  396. method: 'validateEachComponent',
  397. r: true,
  398. e: true
  399. },
  400. {
  401. controllerName: 'addServiceController',
  402. method: 'validateEachComponent',
  403. r: false,
  404. e: false
  405. },
  406. {
  407. controllerName: 'installerController',
  408. method: 'validateEachComponent',
  409. r: true,
  410. e: true
  411. },
  412. {
  413. controllerName: 'installerController',
  414. method: 'validateEachComponent',
  415. r: false,
  416. e: false
  417. }
  418. ]);
  419. tests.forEach(function (test) {
  420. it(test.controllerName + ' ' + test.method + ' returns ' + test.r.toString(), function () {
  421. sinon.stub(controller, test.method, function () {
  422. return test.r
  423. });
  424. controller.set('content.controllerName', test.controllerName);
  425. expect(controller.validate()).to.equal(test.e);
  426. controller[test.method].restore();
  427. });
  428. });
  429. });
  430. describe('#getMasterComponentsForHost', function () {
  431. var tests = Em.A([
  432. {
  433. masterComponentHosts: Em.A([
  434. {hostName: 'h1', component: 'c1'}
  435. ]),
  436. hostName: 'h1',
  437. m: 'host exists',
  438. e: ['c1']
  439. },
  440. {
  441. masterComponentHosts: Em.A([
  442. {hostName: 'h1', component: 'c1'}
  443. ]),
  444. hostName: 'h2',
  445. m: 'host donesn\'t exists',
  446. e: []
  447. }
  448. ]);
  449. tests.forEach(function (test) {
  450. it(test.m, function () {
  451. controller.set('content.masterComponentHosts', test.masterComponentHosts);
  452. var r = controller.getMasterComponentsForHost(test.hostName);
  453. expect(r).to.eql(test.e);
  454. });
  455. });
  456. });
  457. describe('#selectMasterComponents', function () {
  458. var tests = Em.A([
  459. {
  460. masterComponentHosts: Em.A([
  461. {
  462. hostName: 'h1',
  463. component: 'c1'
  464. }
  465. ]),
  466. hostsObj: [
  467. Em.Object.create({
  468. hostName: 'h1',
  469. checkboxes: [
  470. Em.Object.create({
  471. component: 'c1',
  472. checked: false
  473. })
  474. ]
  475. })
  476. ],
  477. e: true,
  478. m: 'host and component exist'
  479. },
  480. {
  481. masterComponentHosts: Em.A([
  482. {
  483. hostName: 'h1',
  484. component: 'c2'
  485. }
  486. ]),
  487. hostsObj: [
  488. Em.Object.create({
  489. hostName: 'h1',
  490. checkboxes: [
  491. Em.Object.create({
  492. component: 'c1',
  493. checked: false
  494. })
  495. ]
  496. })
  497. ],
  498. e: false,
  499. m: 'host exists'
  500. },
  501. {
  502. masterComponentHosts: Em.A([
  503. {
  504. hostName: 'h2',
  505. component: 'c2'
  506. }
  507. ]),
  508. hostsObj: [
  509. Em.Object.create({
  510. hostName: 'h1',
  511. checkboxes: [
  512. Em.Object.create({
  513. component: 'c1',
  514. checked: false
  515. })
  516. ]
  517. })
  518. ],
  519. e: false,
  520. m: 'host and component don\'t exist'
  521. }
  522. ]);
  523. tests.forEach(function (test) {
  524. it(test.m, function () {
  525. controller.set('content.masterComponentHosts', test.masterComponentHosts);
  526. var r = controller.selectMasterComponents(test.hostsObj);
  527. expect(r.findProperty('hostName', 'h1').get('checkboxes').findProperty('component', 'c1').get('checked')).to.equal(test.e);
  528. });
  529. });
  530. });
  531. });