step2_test.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  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('controllers/main/admin/security/add/step2');
  20. require('models/service');
  21. describe('App.MainAdminSecurityAddStep2Controller', function () {
  22. var controller = App.MainAdminSecurityAddStep2Controller.create({
  23. content: {}
  24. });
  25. describe('#clearStep()', function () {
  26. it('Info is empty', function () {
  27. controller.set('stepConfigs', []);
  28. controller.set('securityUsers', []);
  29. controller.clearStep();
  30. expect(controller.get('stepConfigs')).to.be.empty;
  31. expect(controller.get('securityUsers')).to.be.empty;
  32. });
  33. it('Info filled', function () {
  34. controller.set('stepConfigs', [1]);
  35. controller.set('securityUsers', [1]);
  36. controller.clearStep();
  37. expect(controller.get('stepConfigs')).to.be.empty;
  38. expect(controller.get('securityUsers')).to.be.empty;
  39. });
  40. });
  41. describe('#isSubmitDisabled', function () {
  42. var tests = [
  43. {
  44. config: [
  45. {
  46. showConfig: true,
  47. errorCount: 0
  48. }
  49. ],
  50. m: 'All show configs, nothing with errors',
  51. e: false
  52. },
  53. {
  54. config: [
  55. {
  56. showConfig: true,
  57. errorCount: 0
  58. },
  59. {
  60. showConfig: true,
  61. errorCount: 1
  62. }
  63. ],
  64. m: 'All show configs, 1 with errors',
  65. e: true
  66. },
  67. {
  68. config: [
  69. {
  70. showConfig: true,
  71. errorCount: 0
  72. },
  73. {
  74. showConfig: false,
  75. errorCount: 1
  76. }
  77. ],
  78. m: '1 has errors but not visible',
  79. e: false
  80. },
  81. {
  82. config: [
  83. {
  84. showConfig: false,
  85. errorCount: 0
  86. },
  87. {
  88. showConfig: false,
  89. errorCount: 1
  90. }
  91. ],
  92. m: '1 has errors, all not visible',
  93. e: false
  94. },
  95. {
  96. config: [
  97. {
  98. showConfig: true,
  99. errorCount: 1
  100. },
  101. {
  102. showConfig: true,
  103. errorCount: 1
  104. }
  105. ],
  106. m: 'All has errors, all not visible',
  107. e: true
  108. }
  109. ];
  110. tests.forEach(function (test) {
  111. it(test.m, function () {
  112. controller.set('stepConfigs', test.config);
  113. expect(controller.get('isSubmitDisabled')).to.equal(test.e);
  114. });
  115. });
  116. });
  117. describe('#loadStep()', function () {
  118. it('load step', function () {
  119. controller.set('stepConfigs', [
  120. {}
  121. ]);
  122. controller.set('securityUsers', ['user1']);
  123. controller.set('content.services', ['service1']);
  124. controller.set('content.serviceConfigProperties', ['config1']);
  125. sinon.stub(controller, 'clearStep', Em.K);
  126. sinon.stub(controller, 'loadUsers', Em.K);
  127. sinon.stub(controller, 'addUserPrincipals', Em.K);
  128. sinon.stub(controller, 'renderServiceConfigs', Em.K);
  129. sinon.stub(controller, 'changeCategoryOnHa', Em.K);
  130. sinon.stub(controller, 'setStoredConfigsValue', Em.K);
  131. sinon.stub(controller, 'addHostPrincipals', Em.K);
  132. sinon.stub(App.Service, 'find', function () {
  133. return [
  134. {serviceName: 'HDFS'}
  135. ];
  136. });
  137. controller.loadStep();
  138. expect(controller.get('installedServices')).to.eql(['HDFS']);
  139. expect(controller.clearStep.calledOnce).to.be.true;
  140. expect(controller.loadUsers.calledOnce).to.be.true;
  141. expect(controller.addUserPrincipals.calledWith(['service1'], ['user1'])).to.be.true;
  142. expect(controller.addHostPrincipals.calledOnce).to.be.true;
  143. expect(controller.renderServiceConfigs.calledWith(['service1'])).to.be.true;
  144. expect(controller.changeCategoryOnHa.calledWith(['service1'], [{}])).to.be.true;
  145. expect(controller.setStoredConfigsValue.calledWith(['config1'])).to.be.true;
  146. controller.clearStep.restore();
  147. controller.loadUsers.restore();
  148. controller.addUserPrincipals.restore();
  149. controller.renderServiceConfigs.restore();
  150. controller.changeCategoryOnHa.restore();
  151. controller.setStoredConfigsValue.restore();
  152. controller.addHostPrincipals.restore();
  153. App.Service.find.restore();
  154. });
  155. });
  156. describe('#setStoredConfigsValue()', function () {
  157. it('storedConfigProperties is null', function () {
  158. expect(controller.setStoredConfigsValue(null)).to.be.false;
  159. });
  160. it('stepConfigs is empty', function () {
  161. controller.set('stepConfigs', []);
  162. expect(controller.setStoredConfigsValue([])).to.be.true;
  163. expect(controller.get('stepConfigs')).to.be.empty;
  164. });
  165. it('stepConfig has no configs', function () {
  166. controller.set('stepConfigs', [Em.Object.create({
  167. configs: []
  168. })]);
  169. expect(controller.setStoredConfigsValue([])).to.be.true;
  170. expect(controller.get('stepConfigs')[0].get('configs')).to.be.empty;
  171. });
  172. it('stepConfig has no stored configs', function () {
  173. controller.set('stepConfigs', [Em.Object.create({
  174. configs: [Em.Object.create({
  175. name: 'config1',
  176. value: 'value1'
  177. })]
  178. })]);
  179. var storedConfigProperties = [
  180. {
  181. name: 'config2',
  182. value: "value2"
  183. }
  184. ];
  185. expect(controller.setStoredConfigsValue(storedConfigProperties)).to.be.true;
  186. expect(controller.get('stepConfigs')[0].get('configs').findProperty('name', 'config1').get('value')).to.equal('value1');
  187. });
  188. it('stepConfig has stored configs', function () {
  189. controller.set('stepConfigs', [Em.Object.create({
  190. configs: [Em.Object.create({
  191. name: 'config2',
  192. value: 'value1'
  193. })]
  194. })]);
  195. var storedConfigProperties = [
  196. {
  197. name: 'config2',
  198. value: "value2"
  199. }
  200. ];
  201. expect(controller.setStoredConfigsValue(storedConfigProperties)).to.be.true;
  202. expect(controller.get('stepConfigs')[0].get('configs').findProperty('name', 'config2').get('value')).to.equal('value2');
  203. });
  204. });
  205. describe('#renderServiceConfigs()', function () {
  206. it('serviceConfigs and stepConfigs are empty', function () {
  207. controller.set('stepConfigs', []);
  208. controller.renderServiceConfigs([]);
  209. expect(controller.get('selectedService')).to.be.undefined;
  210. });
  211. it('serviceConfigs is empty', function () {
  212. controller.set('stepConfigs', [
  213. {showConfig: true}
  214. ]);
  215. controller.renderServiceConfigs([]);
  216. expect(controller.get('selectedService')).to.eql({showConfig: true});
  217. });
  218. it('serviceConfigs has service', function () {
  219. var serviceConfigs = [
  220. {
  221. serviceName: 'HDFS',
  222. configs: []
  223. }
  224. ];
  225. sinon.stub(controller, 'wrapConfigProperties', function () {
  226. return [];
  227. });
  228. controller.set('stepConfigs', []);
  229. controller.renderServiceConfigs(serviceConfigs);
  230. expect(controller.get('selectedService').get('serviceName')).to.equal('HDFS');
  231. expect(controller.get('selectedService').get('showConfig')).to.be.true;
  232. expect(controller.get('selectedService').get('configs')).to.be.empty;
  233. expect(controller.wrapConfigProperties.calledWith({
  234. serviceName: 'HDFS',
  235. configs: []
  236. })).to.be.true;
  237. controller.wrapConfigProperties.restore();
  238. });
  239. });
  240. describe('#wrapConfigProperties()', function () {
  241. it('_componentConfig is empty', function () {
  242. expect(controller.wrapConfigProperties({configs: []})).to.be.empty;
  243. });
  244. it('serviceConfigs has service', function () {
  245. var mock = Em.Object.create({
  246. validate: Em.K,
  247. isReconfigurable: true,
  248. isEditable: false
  249. });
  250. var _componentConfig = {configs: [
  251. {name: 'config1'}
  252. ]};
  253. sinon.stub(App.ServiceConfigProperty, 'create', function () {
  254. return mock;
  255. });
  256. sinon.spy(mock, 'validate');
  257. expect(controller.wrapConfigProperties(_componentConfig)[0].get('isEditable')).to.be.true;
  258. expect(App.ServiceConfigProperty.create.calledWith({name: 'config1'})).to.be.true;
  259. expect(mock.validate.calledOnce).to.be.true;
  260. mock.validate.restore();
  261. App.ServiceConfigProperty.create.restore();
  262. });
  263. });
  264. describe('#setHostsToConfig()', function () {
  265. it('service is null', function () {
  266. expect(controller.setHostsToConfig(null)).to.be.false;
  267. });
  268. it('service.configs is empty', function () {
  269. controller.set('content.services', [
  270. {
  271. serviceName: 'HDFS',
  272. configs: []
  273. }
  274. ]);
  275. expect(controller.setHostsToConfig('HDFS')).to.be.false;
  276. });
  277. it('No such config name in service.configs', function () {
  278. controller.set('content.services', [
  279. {
  280. serviceName: 'HDFS',
  281. configs: [
  282. {
  283. name: 'config1'
  284. }
  285. ]
  286. }
  287. ]);
  288. expect(controller.setHostsToConfig('HDFS', 'config2')).to.be.false;
  289. });
  290. it('Correct config in service.configs', function () {
  291. sinon.stub(App.Service, 'find', function () {
  292. return Em.Object.create({
  293. hostComponents: [
  294. Em.Object.create({
  295. componentName: 'comp1',
  296. hostName: 'host1'
  297. })
  298. ]
  299. });
  300. });
  301. expect(controller.setHostsToConfig('HDFS', 'config1', ['comp1'])).to.be.true;
  302. expect(controller.get('content.services')[0].configs[0].defaultValue).to.eql(['host1']);
  303. App.Service.find.restore();
  304. });
  305. });
  306. describe('#setHostToPrincipal()', function () {
  307. it('service is null', function () {
  308. expect(controller.setHostToPrincipal(null)).to.be.false;
  309. });
  310. it('service.configs is empty', function () {
  311. controller.set('content.services', [
  312. {
  313. serviceName: 'HDFS',
  314. configs: []
  315. }
  316. ]);
  317. expect(controller.setHostToPrincipal('HDFS')).to.be.false;
  318. });
  319. it('No such hostConfigName name in service.configs', function () {
  320. controller.set('content.services', [
  321. {
  322. serviceName: 'HDFS',
  323. configs: [
  324. {
  325. name: 'config1'
  326. }
  327. ]
  328. }
  329. ]);
  330. expect(controller.setHostToPrincipal('HDFS', 'config2', 'config1')).to.be.false;
  331. });
  332. it('No such principalConfigName name in service.configs', function () {
  333. expect(controller.setHostToPrincipal('HDFS', 'config1', 'config2')).to.be.false;
  334. });
  335. it('Correct config in service.configs', function () {
  336. controller.set('content.services', [
  337. {
  338. serviceName: 'HDFS',
  339. configs: [
  340. {
  341. name: 'config1',
  342. defaultValue: 'value1'
  343. },
  344. {
  345. name: 'principal1'
  346. }
  347. ]
  348. }
  349. ]);
  350. expect(controller.setHostToPrincipal('HDFS', 'config1', 'principal1', 'name1')).to.be.true;
  351. expect(controller.get('content.services')[0].configs[0].defaultValue).to.equal('value1');
  352. expect(controller.get('content.services')[0].configs[1].defaultValue).to.equal('name1value1');
  353. });
  354. it('Correct config in service.configs, defaultValue is array', function () {
  355. controller.set('content.services', [
  356. {
  357. serviceName: 'HDFS',
  358. configs: [
  359. {
  360. name: 'config1',
  361. defaultValue: ['Value1']
  362. },
  363. {
  364. name: 'principal1'
  365. }
  366. ]
  367. }
  368. ]);
  369. expect(controller.setHostToPrincipal('HDFS', 'config1', 'principal1', 'name1')).to.be.true;
  370. // expect(controller.get('content.services')[0].configs[0].defaultValue).to.equal('Value1');
  371. expect(controller.get('content.services')[0].configs[1].defaultValue).to.equal('name1Value1');
  372. });
  373. it('stack 2.2 `storm_principal_name` config should be set to `storm`', function() {
  374. sinon.stub(App, 'get').withArgs('currentStackVersionNumber').returns('2.2');
  375. controller.set('content.services', [
  376. {
  377. serviceName: 'STORM',
  378. configs: [
  379. {
  380. name: 'nimbus_host',
  381. defaultValue: 'Value1'
  382. },
  383. {
  384. name: 'storm_principal_name'
  385. }
  386. ]
  387. }
  388. ]);
  389. controller.setHostToPrincipal('STORM', 'nimbus_host', 'storm_principal_name', 'storm');
  390. App.get.restore();
  391. expect(controller.get('content.services')[0].configs[1].defaultValue).to.equal('storm');
  392. });
  393. it('stack 2.1 `oozie_http_principal_name` value should contains OOZIE_SERVER host', function() {
  394. sinon.stub(App, 'get').withArgs('currentStackVersionNumber').returns('2.1');
  395. controller.set('content.services', [
  396. {
  397. serviceName: 'OOZIE',
  398. configs: [
  399. {
  400. name: 'oozie_servername',
  401. defaultValue: 'host1.com'
  402. },
  403. {
  404. name: 'oozie_http_principal_name'
  405. }
  406. ]
  407. }
  408. ]);
  409. controller.setHostToPrincipal('OOZIE', 'oozie_servername', 'oozie_http_principal_name', 'HTTP/');
  410. App.get.restore();
  411. expect(controller.get('content.services')[0].configs[1].defaultValue).to.equal('HTTP/host1.com');
  412. });
  413. it('stack 2.2 `oozie_http_principal_name` value should be set to HTTP/_HOST', function() {
  414. sinon.stub(App, 'get').withArgs('currentStackVersionNumber').returns('2.2');
  415. controller.set('content.services', [
  416. {
  417. serviceName: 'OOZIE',
  418. configs: [
  419. {
  420. name: 'oozie_servername',
  421. defaultValue: 'host1.com'
  422. },
  423. {
  424. name: 'oozie_http_principal_name'
  425. }
  426. ]
  427. }
  428. ]);
  429. controller.setHostToPrincipal('OOZIE', 'oozie_servername', 'oozie_http_principal_name', 'HTTP/');
  430. App.get.restore();
  431. expect(controller.get('content.services')[0].configs[1].defaultValue).to.equal('HTTP/_HOST');
  432. });
  433. });
  434. describe('#loadUsers()', function () {
  435. afterEach(function () {
  436. App.router.get.restore();
  437. });
  438. it('serviceUsers is correct', function () {
  439. sinon.stub(App.router, 'get', function () {
  440. return Em.Object.create({serviceUsers: [
  441. {}
  442. ]})
  443. });
  444. controller.loadUsers();
  445. expect(controller.get('securityUsers')).to.eql([
  446. {}
  447. ]);
  448. });
  449. it('serviceUsers is null, testMode = true', function () {
  450. sinon.stub(App.router, 'get', function () {
  451. return Em.Object.create({serviceUsers: null})
  452. });
  453. sinon.stub(App, 'get', function(k) {
  454. if ('testMode' === k) return true;
  455. return Em.get(App, k);
  456. });
  457. controller.loadUsers();
  458. expect(controller.get('securityUsers').mapProperty('name')).to.eql(["hdfs_user",
  459. "mapred_user",
  460. "hbase_user",
  461. "hive_user",
  462. "smokeuser"
  463. ]);
  464. App.get.restore();
  465. });
  466. it('serviceUsers is empty, testMode = true', function () {
  467. sinon.stub(App.router, 'get', function () {
  468. return Em.Object.create({serviceUsers: []})
  469. });
  470. sinon.stub(App, 'get', function(k) {
  471. if ('testMode' === k) return true;
  472. return Em.get(App, k);
  473. });
  474. controller.loadUsers();
  475. expect(controller.get('securityUsers').mapProperty('name')).to.eql(["hdfs_user",
  476. "mapred_user",
  477. "hbase_user",
  478. "hive_user",
  479. "smokeuser"
  480. ]);
  481. App.get.restore();
  482. });
  483. it('serviceUsers is null, testMode = false', function () {
  484. sinon.stub(App.router, 'get', function () {
  485. return Em.Object.create({serviceUsers: null})
  486. });
  487. sinon.stub(App.db, 'getSecureUserInfo', function () {
  488. return [
  489. {}
  490. ];
  491. });
  492. sinon.stub(App, 'get', function(k) {
  493. if ('testMode' === k) return false;
  494. return Em.get(App, k);
  495. });
  496. controller.loadUsers();
  497. expect(controller.get('securityUsers')).to.eql([
  498. {}
  499. ]);
  500. expect(App.db.getSecureUserInfo.calledOnce).to.be.true;
  501. App.db.getSecureUserInfo.restore();
  502. App.get.restore();
  503. });
  504. it('serviceUsers is empty, testMode = false', function () {
  505. sinon.stub(App.router, 'get', function () {
  506. return Em.Object.create({serviceUsers: []})
  507. });
  508. sinon.stub(App.db, 'getSecureUserInfo', function () {
  509. return [
  510. {}
  511. ];
  512. });
  513. sinon.stub(App, 'get', function(k) {
  514. if ('testMode' === k) return false;
  515. return Em.get(App, k);
  516. });
  517. controller.loadUsers();
  518. expect(controller.get('securityUsers')).to.eql([
  519. {}
  520. ]);
  521. expect(App.db.getSecureUserInfo.calledOnce).to.be.true;
  522. App.db.getSecureUserInfo.restore();
  523. App.get.restore();
  524. });
  525. });
  526. describe('#addUserPrincipals()', function () {
  527. beforeEach(function () {
  528. sinon.stub(controller, 'setUserPrincipalValue', function () {
  529. return true;
  530. });
  531. });
  532. afterEach(function () {
  533. controller.setUserPrincipalValue.restore();
  534. });
  535. var generalConfigs = [
  536. {
  537. serviceName: 'GENERAL',
  538. configs: [
  539. {
  540. name: 'hbase_principal_name',
  541. isVisible: false
  542. },
  543. {
  544. name: 'hbase_user_keytab',
  545. isVisible: false
  546. },
  547. {
  548. name: 'hdfs_principal_name',
  549. isVisible: false
  550. },
  551. {
  552. name: 'hdfs_user_keytab',
  553. isVisible: false
  554. }
  555. ]
  556. }
  557. ];
  558. var securityUsers = [];
  559. it('HBASE or HDFS services are not installed neither', function () {
  560. var serviceConfigs = generalConfigs.slice(0);
  561. controller.addUserPrincipals(serviceConfigs, securityUsers);
  562. expect(serviceConfigs[0].configs.findProperty('name', 'hbase_principal_name').isVisible).to.be.false;
  563. expect(serviceConfigs[0].configs.findProperty('name', 'hbase_user_keytab').isVisible).to.be.false;
  564. });
  565. it('HBASE service is installed', function () {
  566. var serviceConfigs = generalConfigs.slice(0);
  567. serviceConfigs.push({serviceName: 'HBASE'});
  568. controller.addUserPrincipals(serviceConfigs, securityUsers);
  569. expect(serviceConfigs[0].configs.findProperty('name', 'hbase_principal_name').isVisible).to.be.true;
  570. expect(serviceConfigs[0].configs.findProperty('name', 'hbase_user_keytab').isVisible).to.be.true;
  571. });
  572. it('HDFS service is installed', function () {
  573. var serviceConfigs = generalConfigs.slice(0);
  574. serviceConfigs.push({serviceName: 'HDFS'});
  575. controller.addUserPrincipals(serviceConfigs, securityUsers);
  576. expect(serviceConfigs[0].configs.findProperty('name', 'hdfs_principal_name').isVisible).to.be.true;
  577. expect(serviceConfigs[0].configs.findProperty('name', 'hdfs_user_keytab').isVisible).to.be.true;
  578. });
  579. it('HDFS and HBASE services are installed', function () {
  580. var serviceConfigs = generalConfigs.slice(0);
  581. serviceConfigs.push({serviceName: 'HDFS'});
  582. serviceConfigs.push({serviceName: 'HBASE'});
  583. controller.addUserPrincipals(serviceConfigs, securityUsers);
  584. expect(serviceConfigs[0].configs.findProperty('name', 'hdfs_principal_name').isVisible).to.be.true;
  585. expect(serviceConfigs[0].configs.findProperty('name', 'hdfs_user_keytab').isVisible).to.be.true;
  586. expect(serviceConfigs[0].configs.findProperty('name', 'hbase_principal_name').isVisible).to.be.true;
  587. expect(serviceConfigs[0].configs.findProperty('name', 'hbase_user_keytab').isVisible).to.be.true;
  588. });
  589. });
  590. describe('#setUserPrincipalValue()', function () {
  591. it('user and userPrincipal are null', function () {
  592. expect(controller.setUserPrincipalValue(null, null)).to.be.false;
  593. });
  594. it('user is null', function () {
  595. expect(controller.setUserPrincipalValue(null, {})).to.be.false;
  596. });
  597. it('userPrincipal is null', function () {
  598. expect(controller.setUserPrincipalValue({}, null)).to.be.false;
  599. });
  600. it('user and userPrincipal are correct', function () {
  601. var user = {value: 'value1'};
  602. var userPrincipal = {};
  603. expect(controller.setUserPrincipalValue(user, userPrincipal)).to.be.true;
  604. expect(userPrincipal.defaultValue).to.equal('value1');
  605. });
  606. });
  607. describe('#addHostPrincipals()', function () {
  608. it('hostToPrincipalMap is empty', function () {
  609. sinon.stub(controller, 'setHostToPrincipal', Em.K);
  610. controller.set('hostToPrincipalMap', []);
  611. controller.addHostPrincipals();
  612. expect(controller.setHostToPrincipal.called).to.be.false;
  613. controller.setHostToPrincipal.restore();
  614. });
  615. it('Correct data', function () {
  616. sinon.stub(controller, 'setHostToPrincipal', Em.K);
  617. controller.set('hostToPrincipalMap', [
  618. {
  619. serviceName: 'HDFS',
  620. configName: 'datanode_hosts',
  621. principalName: 'principal1',
  622. primaryName: 'name1'
  623. }
  624. ]);
  625. controller.addHostPrincipals();
  626. expect(controller.setHostToPrincipal.calledWith('HDFS', 'datanode_hosts', 'principal1', 'name1')).to.be.true;
  627. controller.setHostToPrincipal.restore();
  628. });
  629. });
  630. describe('#changeCategoryOnHa()', function () {
  631. beforeEach(function () {
  632. sinon.stub(controller, 'removeConfigCategory', Em.K);
  633. });
  634. afterEach(function () {
  635. controller.removeConfigCategory.restore();
  636. });
  637. var serviceConfigs = [{
  638. serviceName: 'HDFS',
  639. configCategories: []
  640. }];
  641. var stepConfigs = [Em.Object.create({
  642. serviceName: 'HDFS',
  643. configs: []
  644. })];
  645. it('HDFS service is absent', function () {
  646. expect(controller.changeCategoryOnHa([], [])).to.be.false;
  647. });
  648. it('HDFS service installed, App.testMode and App.testNameNodeHA - true', function () {
  649. sinon.stub(App, 'get', function(k) {
  650. if ('testMode' === k) return true;
  651. if ('testNameNodeHA' === k) return true;
  652. return Em.get(App, k);
  653. });
  654. expect(controller.changeCategoryOnHa(serviceConfigs, stepConfigs)).to.be.true;
  655. expect(controller.removeConfigCategory.calledWith([], [], 'SNameNode')).to.be.true;
  656. App.get.restore();
  657. });
  658. it('HDFS service installed, content.isNnHa = true', function () {
  659. controller.set('content.isNnHa', 'true');
  660. expect(controller.changeCategoryOnHa(serviceConfigs, stepConfigs)).to.be.true;
  661. expect(controller.removeConfigCategory.calledWith([], [], 'SNameNode')).to.be.true;
  662. });
  663. it('HDFS service installed, HA disabled', function () {
  664. controller.set('content.isNnHa', 'false');
  665. expect(controller.changeCategoryOnHa(serviceConfigs, stepConfigs)).to.be.true;
  666. expect(controller.removeConfigCategory.calledWith([], [], 'JournalNode')).to.be.true;
  667. });
  668. });
  669. describe('#removeConfigCategory()', function () {
  670. it('properties should be hidden', function () {
  671. var properties = [
  672. Em.Object.create({
  673. category: 'comp1',
  674. isVisible: true
  675. })
  676. ];
  677. controller.removeConfigCategory(properties, [], 'comp1');
  678. expect(properties[0].isVisible).to.be.false;
  679. });
  680. it('category should be removed', function () {
  681. var configCategories = [
  682. Em.Object.create({
  683. name: 'comp1'
  684. })
  685. ];
  686. controller.removeConfigCategory([], configCategories, 'comp1');
  687. expect(configCategories).to.be.empty;
  688. });
  689. });
  690. });