step6_test.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  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('#checkCallback', function () {
  135. beforeEach(function () {
  136. sinon.stub(controller, 'clearError', Em.K);
  137. });
  138. afterEach(function () {
  139. controller.clearError.restore();
  140. });
  141. it('should call clearError', function () {
  142. controller.checkCallback('');
  143. expect(controller.clearError.calledOnce).to.equal(true);
  144. });
  145. Em.A([
  146. {
  147. m: 'all checked, isInstalled false',
  148. headers: Em.A([
  149. Em.Object.create({name: 'c1'})
  150. ]),
  151. hosts: Em.A([
  152. Em.Object.create({
  153. checkboxes: Em.A([
  154. Em.Object.create({
  155. component: 'c1',
  156. isInstalled: false,
  157. checked: true
  158. })
  159. ])
  160. })
  161. ]),
  162. component: 'c1',
  163. e: {
  164. allChecked: true,
  165. noChecked: false
  166. }
  167. },
  168. {
  169. m: 'all checked, isInstalled true',
  170. headers: Em.A([
  171. Em.Object.create({name: 'c1'})
  172. ]),
  173. hosts: Em.A([
  174. Em.Object.create({
  175. checkboxes: Em.A([
  176. Em.Object.create({
  177. component: 'c1',
  178. isInstalled: true,
  179. checked: true
  180. })
  181. ])
  182. })
  183. ]),
  184. component: 'c1',
  185. e: {
  186. allChecked: true,
  187. noChecked: true
  188. }
  189. },
  190. {
  191. m: 'no one checked',
  192. headers: Em.A([
  193. Em.Object.create({name: 'c1'})
  194. ]),
  195. hosts: Em.A([
  196. Em.Object.create({
  197. checkboxes: Em.A([
  198. Em.Object.create({
  199. component: 'c1',
  200. isInstalled: false,
  201. checked: false
  202. })
  203. ])
  204. })
  205. ]),
  206. component: 'c1',
  207. e: {
  208. allChecked: false,
  209. noChecked: true
  210. }
  211. },
  212. {
  213. m: 'some checked',
  214. headers: Em.A([
  215. Em.Object.create({name: 'c1'})
  216. ]),
  217. hosts: Em.A([
  218. Em.Object.create({
  219. checkboxes: Em.A([
  220. Em.Object.create({
  221. component: 'c1',
  222. isInstalled: false,
  223. checked: true
  224. }),
  225. Em.Object.create({
  226. component: 'c1',
  227. isInstalled: false,
  228. checked: false
  229. })
  230. ])
  231. })
  232. ]),
  233. component: 'c1',
  234. e: {
  235. allChecked: false,
  236. noChecked: false
  237. }
  238. },
  239. {
  240. m: 'some checked, some isInstalled true',
  241. headers: Em.A([
  242. Em.Object.create({name: 'c1'})
  243. ]),
  244. hosts: Em.A([
  245. Em.Object.create({
  246. checkboxes: Em.A([
  247. Em.Object.create({
  248. component: 'c1',
  249. isInstalled: true,
  250. checked: true
  251. }),
  252. Em.Object.create({
  253. component: 'c1',
  254. isInstalled: true,
  255. checked: true
  256. })
  257. ])
  258. })
  259. ]),
  260. component: 'c1',
  261. e: {
  262. allChecked: true,
  263. noChecked: true
  264. }
  265. },
  266. {
  267. m: 'some checked, some isInstalled true (2)',
  268. headers: Em.A([
  269. Em.Object.create({name: 'c1'})
  270. ]),
  271. hosts: Em.A([
  272. Em.Object.create({
  273. checkboxes: Em.A([
  274. Em.Object.create({
  275. component: 'c1',
  276. isInstalled: false,
  277. checked: false
  278. }),
  279. Em.Object.create({
  280. component: 'c1',
  281. isInstalled: true,
  282. checked: true
  283. })
  284. ])
  285. })
  286. ]),
  287. component: 'c1',
  288. e: {
  289. allChecked: false,
  290. noChecked: true
  291. }
  292. }
  293. ]).forEach(function (test) {
  294. it(test.m, function () {
  295. controller.clearStep();
  296. controller.set('headers', test.headers);
  297. controller.set('hosts', test.hosts);
  298. controller.checkCallback(test.component);
  299. var header = controller.get('headers').findProperty('name', test.component);
  300. expect(header.get('allChecked')).to.equal(test.e.allChecked);
  301. expect(header.get('noChecked')).to.equal(test.e.noChecked);
  302. });
  303. });
  304. });
  305. describe('#getHostNames', function () {
  306. var tests = Em.A([
  307. {
  308. hosts: {
  309. h1: {bootStatus: 'REGISTERED', name: 'h1'},
  310. h2: {bootStatus: 'REGISTERED', name: 'h2'},
  311. h3: {bootStatus: 'REGISTERED', name: 'h3'}
  312. },
  313. m: 'All REGISTERED',
  314. e: ['h1', 'h2', 'h3']
  315. },
  316. {
  317. hosts: {
  318. h1: {bootStatus: 'REGISTERED', name: 'h1'},
  319. h2: {bootStatus: 'FAILED', name: 'h2'},
  320. h3: {bootStatus: 'REGISTERED', name: 'h3'}
  321. },
  322. m: 'Some REGISTERED',
  323. e: ['h1', 'h3']
  324. },
  325. {
  326. hosts: {
  327. h1: {bootStatus: 'FAILED', name: 'h1'},
  328. h2: {bootStatus: 'FAILED', name: 'h2'},
  329. h3: {bootStatus: 'FAILED', name: 'h3'}
  330. },
  331. m: 'No one REGISTERED',
  332. e: []
  333. },
  334. {
  335. hosts: {},
  336. m: 'Empty hosts',
  337. e: []
  338. }
  339. ]);
  340. tests.forEach(function (test) {
  341. it(test.m, function () {
  342. controller.set('content.hosts', test.hosts);
  343. var r = controller.getHostNames();
  344. expect(r).to.eql(test.e);
  345. });
  346. });
  347. });
  348. describe('#validate', function () {
  349. var tests = Em.A([
  350. {
  351. controllerName: 'addHostController',
  352. method: 'validateEachHost',
  353. r: true,
  354. e: true
  355. },
  356. {
  357. controllerName: 'addHostController',
  358. method: 'validateEachHost',
  359. r: false,
  360. e: false
  361. },
  362. {
  363. controllerName: 'addServiceController',
  364. method: 'validateEachComponent',
  365. r: true,
  366. e: true
  367. },
  368. {
  369. controllerName: 'addServiceController',
  370. method: 'validateEachComponent',
  371. r: false,
  372. e: false
  373. },
  374. {
  375. controllerName: 'installerController',
  376. method: 'validateEachComponent',
  377. r: true,
  378. e: true
  379. },
  380. {
  381. controllerName: 'installerController',
  382. method: 'validateEachComponent',
  383. r: false,
  384. e: false
  385. }
  386. ]);
  387. tests.forEach(function (test) {
  388. it(test.controllerName + ' ' + test.method + ' returns ' + test.r.toString(), function () {
  389. sinon.stub(controller, test.method, function () {
  390. return test.r
  391. });
  392. controller.set('content.controllerName', test.controllerName);
  393. expect(controller.callClientSideValidation()).to.equal(test.e);
  394. controller[test.method].restore();
  395. });
  396. });
  397. });
  398. describe('#getMasterComponentsForHost', function () {
  399. var tests = Em.A([
  400. {
  401. masterComponentHosts: Em.A([
  402. {hostName: 'h1', component: 'c1'}
  403. ]),
  404. hostName: 'h1',
  405. m: 'host exists',
  406. e: ['c1']
  407. },
  408. {
  409. masterComponentHosts: Em.A([
  410. {hostName: 'h1', component: 'c1'}
  411. ]),
  412. hostName: 'h2',
  413. m: 'host donesn\'t exists',
  414. e: []
  415. }
  416. ]);
  417. tests.forEach(function (test) {
  418. it(test.m, function () {
  419. controller.set('content.masterComponentHosts', test.masterComponentHosts);
  420. var r = controller.getMasterComponentsForHost(test.hostName);
  421. expect(r).to.eql(test.e);
  422. });
  423. });
  424. });
  425. describe('#selectMasterComponents', function () {
  426. var tests = Em.A([
  427. {
  428. masterComponentHosts: Em.A([
  429. {
  430. hostName: 'h1',
  431. component: 'c1'
  432. }
  433. ]),
  434. hostsObj: [
  435. Em.Object.create({
  436. hostName: 'h1',
  437. checkboxes: [
  438. Em.Object.create({
  439. component: 'c1',
  440. checked: false
  441. })
  442. ]
  443. })
  444. ],
  445. e: true,
  446. m: 'host and component exist'
  447. },
  448. {
  449. masterComponentHosts: Em.A([
  450. {
  451. hostName: 'h1',
  452. component: 'c2'
  453. }
  454. ]),
  455. hostsObj: [
  456. Em.Object.create({
  457. hostName: 'h1',
  458. checkboxes: [
  459. Em.Object.create({
  460. component: 'c1',
  461. checked: false
  462. })
  463. ]
  464. })
  465. ],
  466. e: false,
  467. m: 'host exists'
  468. },
  469. {
  470. masterComponentHosts: Em.A([
  471. {
  472. hostName: 'h2',
  473. component: 'c2'
  474. }
  475. ]),
  476. hostsObj: [
  477. Em.Object.create({
  478. hostName: 'h1',
  479. checkboxes: [
  480. Em.Object.create({
  481. component: 'c1',
  482. checked: false
  483. })
  484. ]
  485. })
  486. ],
  487. e: false,
  488. m: 'host and component don\'t exist'
  489. }
  490. ]);
  491. tests.forEach(function (test) {
  492. it(test.m, function () {
  493. controller.set('content.masterComponentHosts', test.masterComponentHosts);
  494. var r = controller.selectMasterComponents(test.hostsObj);
  495. expect(r.findProperty('hostName', 'h1').get('checkboxes').findProperty('component', 'c1').get('checked')).to.equal(test.e);
  496. });
  497. });
  498. });
  499. });