step7_test.js 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219
  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. var numberUtils = require('utils/number_utils');
  20. require('mixins/common/localStorage');
  21. require('models/config_group');
  22. require('controllers/wizard/step7_controller');
  23. var installerStep7Controller;
  24. describe('App.InstallerStep7Controller', function () {
  25. beforeEach(function () {
  26. installerStep7Controller = App.WizardStep7Controller.create();
  27. });
  28. describe('#installedServiceNames', function () {
  29. var tests = Em.A([
  30. {
  31. content: Em.Object.create({
  32. controllerName: 'installerController',
  33. services: Em.A([
  34. Em.Object.create({
  35. isInstalled: true,
  36. serviceName: 'SQOOP'
  37. }),
  38. Em.Object.create({
  39. isInstalled: true,
  40. serviceName: 'HDFS'
  41. })
  42. ])
  43. }),
  44. e: ['SQOOP', 'HDFS'],
  45. m: 'installerController with SQOOP'
  46. },
  47. {
  48. content: Em.Object.create({
  49. controllerName: 'installerController',
  50. services: Em.A([
  51. Em.Object.create({
  52. isInstalled: true,
  53. serviceName: 'HIVE'
  54. }),
  55. Em.Object.create({
  56. isInstalled: true,
  57. serviceName: 'HDFS'
  58. })
  59. ])
  60. }),
  61. e: ['HIVE', 'HDFS'],
  62. m: 'installerController without SQOOP'
  63. },
  64. {
  65. content: Em.Object.create({
  66. controllerName: 'addServiceController',
  67. services: Em.A([
  68. Em.Object.create({
  69. isInstalled: true,
  70. serviceName: 'HIVE'
  71. }),
  72. Em.Object.create({
  73. isInstalled: true,
  74. serviceName: 'HDFS'
  75. })
  76. ])
  77. }),
  78. e: ['HIVE', 'HDFS'],
  79. m: 'addServiceController without SQOOP'
  80. }
  81. ]);
  82. tests.forEach(function (test) {
  83. it(test.m, function () {
  84. installerStep7Controller.set('content', test.content);
  85. expect(installerStep7Controller.get('installedServiceNames')).to.include.members(test.e);
  86. expect(test.e).to.include.members(installerStep7Controller.get('installedServiceNames'));
  87. });
  88. });
  89. });
  90. describe('#isSubmitDisabled', function () {
  91. it('should be true if miscModalVisible', function () {
  92. installerStep7Controller.reopen({miscModalVisible: true});
  93. expect(installerStep7Controller.get('isSubmitDisabled')).to.equal(true);
  94. });
  95. it('should be true if some of stepConfigs has errors', function () {
  96. installerStep7Controller.reopen({
  97. miscModalVisible: false,
  98. stepConfigs: [
  99. {
  100. showConfig: true,
  101. errorCount: 1
  102. }
  103. ]
  104. });
  105. expect(installerStep7Controller.get('isSubmitDisabled')).to.equal(true);
  106. });
  107. it('should be false if all of stepConfigs don\'t have errors and miscModalVisible is false', function () {
  108. installerStep7Controller.reopen({
  109. miscModalVisible: false,
  110. stepConfigs: [
  111. {
  112. showConfig: true,
  113. errorCount: 0
  114. }
  115. ]
  116. });
  117. expect(installerStep7Controller.get('isSubmitDisabled')).to.equal(false);
  118. });
  119. });
  120. describe('#selectedServiceNames', function () {
  121. it('should use content.services as source of data', function () {
  122. installerStep7Controller.set('content', {
  123. services: [
  124. {isSelected: true, isInstalled: false, serviceName: 's1'},
  125. {isSelected: false, isInstalled: false, serviceName: 's2'},
  126. {isSelected: true, isInstalled: true, serviceName: 's3'},
  127. {isSelected: false, isInstalled: false, serviceName: 's4'},
  128. {isSelected: true, isInstalled: false, serviceName: 's5'},
  129. {isSelected: false, isInstalled: false, serviceName: 's6'},
  130. {isSelected: true, isInstalled: true, serviceName: 's7'},
  131. {isSelected: false, isInstalled: false, serviceName: 's8'}
  132. ]
  133. });
  134. var expected = ['s1', 's5'];
  135. expect(installerStep7Controller.get('selectedServiceNames')).to.eql(expected);
  136. });
  137. });
  138. describe('#allSelectedServiceNames', function () {
  139. it('should use content.services as source of data', function () {
  140. installerStep7Controller.set('content', {
  141. services: [
  142. Em.Object.create({isSelected: true, isInstalled: false, serviceName: 's1'}),
  143. Em.Object.create({isSelected: false, isInstalled: false, serviceName: 's2'}),
  144. Em.Object.create({isSelected: true, isInstalled: true, serviceName: 's3'}),
  145. Em.Object.create({isSelected: false, isInstalled: false, serviceName: 's4'}),
  146. Em.Object.create({isSelected: true, isInstalled: false, serviceName: 's5'}),
  147. Em.Object.create({isSelected: false, isInstalled: false, serviceName: 's6'}),
  148. Em.Object.create({isSelected: true, isInstalled: true, serviceName: 's7'}),
  149. Em.Object.create({isSelected: false, isInstalled: false, serviceName: 's8'})
  150. ]
  151. });
  152. var expected = ['s1', 's3', 's5', 's7'];
  153. expect(installerStep7Controller.get('allSelectedServiceNames')).to.eql(expected);
  154. });
  155. });
  156. describe('#masterComponentHosts', function () {
  157. it('should be equal to content.masterComponentHosts', function () {
  158. var masterComponentHosts = [
  159. {},
  160. {},
  161. {}
  162. ];
  163. installerStep7Controller.reopen({content: {masterComponentHosts: masterComponentHosts}});
  164. expect(installerStep7Controller.get('masterComponentHosts')).to.eql(masterComponentHosts);
  165. });
  166. });
  167. describe('#slaveComponentHosts', function () {
  168. it('should be equal to content.slaveGroupProperties', function () {
  169. var slaveGroupProperties = [
  170. {},
  171. {},
  172. {}
  173. ];
  174. installerStep7Controller.reopen({content: {slaveGroupProperties: slaveGroupProperties}});
  175. expect(installerStep7Controller.get('slaveComponentHosts')).to.eql(slaveGroupProperties);
  176. });
  177. });
  178. describe('#clearStep', function () {
  179. it('should clear stepConfigs', function () {
  180. installerStep7Controller.set('stepConfigs', [
  181. {},
  182. {}
  183. ]);
  184. installerStep7Controller.clearStep();
  185. expect(installerStep7Controller.get('stepConfigs.length')).to.equal(0);
  186. });
  187. it('should clear filter', function () {
  188. installerStep7Controller.set('filter', 'filter');
  189. installerStep7Controller.clearStep();
  190. expect(installerStep7Controller.get('filter')).to.equal('');
  191. });
  192. it('should set for each filterColumns "selected" false', function () {
  193. installerStep7Controller.set('filterColumns', [
  194. {selected: true},
  195. {selected: false},
  196. {selected: true}
  197. ]);
  198. installerStep7Controller.clearStep();
  199. expect(installerStep7Controller.get('filterColumns').everyProperty('selected', false)).to.equal(true);
  200. });
  201. });
  202. describe('#loadInstalledServicesConfigGroups', function () {
  203. before(function () {
  204. sinon.stub(App.ajax, 'send', Em.K);
  205. });
  206. after(function () {
  207. App.ajax.send.restore();
  208. });
  209. it('should do ajax request for each received service name', function () {
  210. var serviceNames = ['s1', 's2', 's3'];
  211. installerStep7Controller.loadInstalledServicesConfigGroups(serviceNames);
  212. expect(App.ajax.send.callCount).to.equal(serviceNames.length);
  213. });
  214. });
  215. describe('#getConfigTags', function () {
  216. before(function () {
  217. sinon.stub(App.ajax, 'send', Em.K);
  218. });
  219. after(function () {
  220. App.ajax.send.restore();
  221. });
  222. it('should do ajax-request', function () {
  223. installerStep7Controller.getConfigTags();
  224. expect(App.ajax.send.calledOnce).to.equal(true);
  225. });
  226. });
  227. describe('#setGroupsToDelete', function () {
  228. beforeEach(function () {
  229. installerStep7Controller.set('wizardController', Em.Object.create(App.LocalStorage, {name: 'tdk'}));
  230. });
  231. it('should add new groups to groupsToDelete', function () {
  232. var groupsToDelete = [
  233. {id: '1'},
  234. {id: '2'}
  235. ],
  236. groups = [
  237. Em.Object.create({id: '3'}),
  238. Em.Object.create(),
  239. Em.Object.create({id: '5'})
  240. ],
  241. expected = [
  242. {id: "1"},
  243. {id: "2"},
  244. {id: "3"},
  245. {id: "5"}
  246. ];
  247. installerStep7Controller.set('groupsToDelete', groupsToDelete);
  248. installerStep7Controller.setGroupsToDelete(groups);
  249. expect(installerStep7Controller.get('groupsToDelete')).to.eql(expected);
  250. expect(installerStep7Controller.get('wizardController').getDBProperty('groupsToDelete')).to.eql(expected);
  251. });
  252. });
  253. describe('#selectConfigGroup', function () {
  254. beforeEach(function () {
  255. installerStep7Controller.reopen({content: {services: []}});
  256. sinon.stub(installerStep7Controller, 'switchConfigGroupConfigs', Em.K);
  257. });
  258. afterEach(function () {
  259. installerStep7Controller.switchConfigGroupConfigs.restore();
  260. });
  261. it('should set selectedConfigGroup', function () {
  262. var group = {':': []};
  263. installerStep7Controller.selectConfigGroup({context: group});
  264. expect(installerStep7Controller.get('selectedConfigGroup')).to.eql(group);
  265. });
  266. });
  267. describe('#addOverrideProperty', function () {
  268. it('should add override property', function () {
  269. var groupName = 'groupName',
  270. selectedService = {configGroups: [Em.Object.create({name: groupName, properties: []})]},
  271. selectedConfigGroup = {name: groupName},
  272. serviceConfigProperty = Em.Object.create({overrides: []}),
  273. expected = Em.Object.create({
  274. value: '',
  275. isOriginalSCP: false,
  276. isEditable: true
  277. });
  278. installerStep7Controller.reopen({selectedService: selectedService, selectedConfigGroup: selectedConfigGroup});
  279. var newSCP = installerStep7Controller.addOverrideProperty(serviceConfigProperty);
  280. Em.keys(expected).forEach(function (k) {
  281. expect(newSCP.get(k)).to.equal(expected.get(k));
  282. });
  283. var group = installerStep7Controller.get('selectedService.configGroups').findProperty('name', groupName);
  284. expect(newSCP.get('group')).to.eql(group);
  285. expect(newSCP.get('parentSCP')).to.eql(serviceConfigProperty);
  286. expect(group.get('properties.length')).to.equal(1);
  287. });
  288. });
  289. describe('#resolveStormConfigs', function () {
  290. beforeEach(function () {
  291. installerStep7Controller.reopen({
  292. content: {services: []},
  293. wizardController: Em.Object.create({
  294. getDBProperty: function () {
  295. return [
  296. {component: 'GANGLIA_SERVER', hostName: 'h1'}
  297. ];
  298. }
  299. })
  300. });
  301. });
  302. it('shouldn\'t do nothing if Ganglia and Storm are installed', function () {
  303. var installedServiceNames = ['GANGLIA', 'STORM'],
  304. configs = [
  305. {name: 'nimbus.childopts', value: '.jar=host=', defaultValue: ''},
  306. {name: 'supervisor.childopts', value: '.jar=host=', defaultValue: ''},
  307. {name: 'worker.childopts', value: '.jar=host=', defaultValue: ''}
  308. ],
  309. expected = [
  310. {name: 'nimbus.childopts', value: '.jar=host=', defaultValue: ''},
  311. {name: 'supervisor.childopts', value: '.jar=host=', defaultValue: ''},
  312. {name: 'worker.childopts', value: '.jar=host=', defaultValue: ''}
  313. ];
  314. installerStep7Controller.reopen({installedServiceNames: installedServiceNames});
  315. installerStep7Controller.resolveStormConfigs(configs);
  316. expect(configs).to.eql(expected);
  317. });
  318. it('shouldn\'t do nothing if Ganglia is in allSelectedServiceNames', function () {
  319. var allSelectedServiceNames = ['GANGLIA'],
  320. configs = [
  321. {name: 'nimbus.childopts', value: '.jar=host=', defaultValue: ''},
  322. {name: 'supervisor.childopts', value: '.jar=host=', defaultValue: ''},
  323. {name: 'worker.childopts', value: '.jar=host=', defaultValue: ''}
  324. ],
  325. expected = [
  326. {name: 'nimbus.childopts', value: 'h1', defaultValue: 'h1', forceUpdate: true},
  327. {name: 'supervisor.childopts', value: 'h1', defaultValue: 'h1', forceUpdate: true},
  328. {name: 'worker.childopts', value: 'h1', defaultValue: 'h1', forceUpdate: true}
  329. ];
  330. installerStep7Controller.reopen({allSelectedServiceNames: allSelectedServiceNames});
  331. installerStep7Controller.resolveStormConfigs(configs);
  332. Em.keys(expected[0]).forEach(function (k) {
  333. expect(configs.mapProperty(k)).to.eql(expected.mapProperty(k));
  334. });
  335. });
  336. it('shouldn\'t do nothing if Ganglia is in installedServiceNames (2)', function () {
  337. var installedServiceNames = ['GANGLIA'],
  338. configs = [
  339. {name: 'nimbus.childopts', value: '.jar=host=', defaultValue: ''},
  340. {name: 'supervisor.childopts', value: '.jar=host=', defaultValue: ''},
  341. {name: 'worker.childopts', value: '.jar=host=', defaultValue: ''}
  342. ],
  343. expected = [
  344. {name: 'nimbus.childopts', value: 'h1', defaultValue: 'h1', forceUpdate: true},
  345. {name: 'supervisor.childopts', value: 'h1', defaultValue: 'h1', forceUpdate: true},
  346. {name: 'worker.childopts', value: 'h1', defaultValue: 'h1', forceUpdate: true}
  347. ];
  348. installerStep7Controller.reopen({installedServiceNames: installedServiceNames});
  349. installerStep7Controller.resolveStormConfigs(configs);
  350. Em.keys(expected[0]).forEach(function (k) {
  351. expect(configs.mapProperty(k)).to.eql(expected.mapProperty(k));
  352. });
  353. });
  354. });
  355. describe('#resolveServiceDependencyConfigs', function () {
  356. beforeEach(function () {
  357. sinon.stub(installerStep7Controller, 'resolveStormConfigs', Em.K);
  358. });
  359. afterEach(function () {
  360. installerStep7Controller.resolveStormConfigs.restore();
  361. });
  362. it('should call resolveStormConfigs if serviceName is STORM', function () {
  363. var serviceName = 'STORM', configs = [
  364. {},
  365. {},
  366. {}
  367. ];
  368. installerStep7Controller.resolveServiceDependencyConfigs(serviceName, configs);
  369. expect(installerStep7Controller.resolveStormConfigs.calledWith(configs)).to.equal(true);
  370. });
  371. });
  372. describe('#selectedServiceObserver', function () {
  373. beforeEach(function () {
  374. installerStep7Controller.reopen({content: {services: []}});
  375. sinon.stub(installerStep7Controller, 'switchConfigGroupConfigs', Em.K);
  376. });
  377. afterEach(function () {
  378. installerStep7Controller.switchConfigGroupConfigs.restore();
  379. });
  380. it('shouldn\'t do nothing if App.supports.hostOverridesInstaller is false', function () {
  381. App.set('supports.hostOverridesInstaller', false);
  382. var configGroups = [
  383. {},
  384. {}
  385. ],
  386. selectedConfigGroup = {};
  387. installerStep7Controller.reopen({configGroups: configGroups, selectedConfigGroup: selectedConfigGroup});
  388. installerStep7Controller.selectedServiceObserver();
  389. expect(installerStep7Controller.get('configGroups')).to.eql(configGroups);
  390. expect(installerStep7Controller.get('selectedConfigGroup')).to.eql(selectedConfigGroup);
  391. });
  392. it('shouldn\'t do nothing if selectedService is null', function () {
  393. App.set('supports.hostOverridesInstaller', true);
  394. var configGroups = [
  395. {},
  396. {}
  397. ],
  398. selectedConfigGroup = {};
  399. installerStep7Controller.reopen({selectedService: null, configGroups: configGroups, selectedConfigGroup: selectedConfigGroup});
  400. installerStep7Controller.selectedServiceObserver();
  401. expect(installerStep7Controller.get('configGroups')).to.eql(configGroups);
  402. expect(installerStep7Controller.get('selectedConfigGroup')).to.eql(selectedConfigGroup);
  403. });
  404. it('shouldn\'t do nothing if selectedService.serviceName is MISC', function () {
  405. App.set('supports.hostOverridesInstaller', true);
  406. var configGroups = [
  407. {},
  408. {}
  409. ],
  410. selectedConfigGroup = {};
  411. installerStep7Controller.reopen({selectedService: {serviceName: 'MISC'}, configGroups: configGroups, selectedConfigGroup: selectedConfigGroup});
  412. installerStep7Controller.selectedServiceObserver();
  413. expect(installerStep7Controller.get('configGroups')).to.eql(configGroups);
  414. expect(installerStep7Controller.get('selectedConfigGroup')).to.eql(selectedConfigGroup);
  415. });
  416. it('should update configGroups and selectedConfigGroup', function () {
  417. App.set('supports.hostOverridesInstaller', true);
  418. var defaultGroup = {isDefault: true, n: 'n2'},
  419. configGroups = [
  420. {isDefault: false, n: 'n1'},
  421. defaultGroup,
  422. {n: 'n3'}
  423. ],
  424. selectedConfigGroup = {};
  425. installerStep7Controller.reopen({selectedService: {serviceName: 's1', configGroups: configGroups}});
  426. installerStep7Controller.selectedServiceObserver();
  427. expect(installerStep7Controller.get('configGroups').mapProperty('n')).to.eql(['n2', 'n1', 'n3']);
  428. expect(installerStep7Controller.get('selectedConfigGroup')).to.eql(defaultGroup);
  429. });
  430. });
  431. describe('#loadConfigGroups', function () {
  432. beforeEach(function () {
  433. installerStep7Controller.reopen({
  434. wizardController: Em.Object.create({
  435. allHosts: [
  436. {hostName: 'h1'},
  437. {hostName: 'h2'},
  438. {hostName: 'h3'}
  439. ]
  440. })
  441. });
  442. });
  443. it('shouldn\'t do nothing if only MISC available', function () {
  444. var configGroups = [
  445. {}
  446. ];
  447. installerStep7Controller.reopen({
  448. stepConfigs: [Em.Object.create({serviceName: 'MISC', configGroups: configGroups})]
  449. });
  450. installerStep7Controller.loadConfigGroups([]);
  451. expect(installerStep7Controller.get('stepConfigs.firstObject.configGroups')).to.eql(configGroups);
  452. });
  453. it('should set configGroups for service if they don\'t exist', function () {
  454. var configGroups = [],
  455. serviceName = 'HDFS',
  456. serviceConfigGroups = [
  457. {service: {id: 's1'}}
  458. ];
  459. installerStep7Controller.reopen({
  460. stepConfigs: [Em.Object.create({serviceName: serviceName, displayName: serviceName, configGroups: configGroups})]
  461. });
  462. installerStep7Controller.loadConfigGroups(serviceConfigGroups);
  463. expect(installerStep7Controller.get('stepConfigs.firstObject.configGroups.length')).to.equal(1);
  464. var group = installerStep7Controller.get('stepConfigs.firstObject.configGroups.firstObject');
  465. expect(group.get('name')).to.equal(serviceName + ' Default');
  466. expect(group.get('description').contains(serviceName)).to.equal(true);
  467. expect(group.get('isDefault')).to.equal(true);
  468. expect(group.get('hosts')).to.eql(['h1', 'h2', 'h3']);
  469. expect(group.get('service.id')).to.equal(serviceName);
  470. expect(group.get('serviceName')).to.equal(serviceName);
  471. });
  472. it('should update configGroups for service (only default group)', function () {
  473. var configGroups = [],
  474. serviceName = 'HDFS',
  475. serviceConfigGroups = [
  476. {service: {id: 'HDFS'}, isDefault: true, n: 'n1'}
  477. ];
  478. installerStep7Controller.reopen({
  479. stepConfigs: [Em.Object.create({serviceName: serviceName, displayName: serviceName, configGroups: configGroups})]
  480. });
  481. installerStep7Controller.loadConfigGroups(serviceConfigGroups);
  482. expect(installerStep7Controller.get('stepConfigs.firstObject.configGroups').findProperty('isDefault').get('n')).to.equal('n1');
  483. });
  484. it('should update configGroups for service', function () {
  485. var configGroups = [],
  486. serviceName = 'HDFS',
  487. serviceConfigGroups = [
  488. {service: {id: 'HDFS'}, properties: [
  489. {},
  490. {}
  491. ], isDefault: true, n: 'n1'},
  492. {service: {id: 'HDFS'}, properties: [
  493. {},
  494. {}
  495. ], isDefault: false, n: 'n2'}
  496. ];
  497. installerStep7Controller.reopen({
  498. stepConfigs: [Em.Object.create({serviceName: serviceName, configGroups: configGroups})]
  499. });
  500. installerStep7Controller.loadConfigGroups(serviceConfigGroups);
  501. expect(installerStep7Controller.get('stepConfigs.firstObject.configGroups.length')).to.equal(2);
  502. expect(installerStep7Controller.get('stepConfigs.firstObject.configGroups').findProperty('isDefault').get('n')).to.equal('n1');
  503. expect(installerStep7Controller.get('stepConfigs.firstObject.configGroups').findProperty('isDefault', false).get('properties').everyProperty('group.n', 'n2')).to.equal(true);
  504. expect(installerStep7Controller.get('stepConfigs.firstObject.configGroups').findProperty('isDefault', false).get('parentConfigGroup.n')).to.equal('n1');
  505. });
  506. });
  507. describe('#_getDisplayedConfigGroups', function () {
  508. it('should return [] if no selected group', function () {
  509. installerStep7Controller.reopen({
  510. content: {services: []},
  511. selectedConfigGroup: null
  512. });
  513. expect(installerStep7Controller._getDisplayedConfigGroups()).to.eql([]);
  514. });
  515. it('should return default config group if another selected', function () {
  516. var defaultGroup = Em.Object.create({isDefault: false});
  517. installerStep7Controller.reopen({
  518. content: {services: []},
  519. selectedConfigGroup: defaultGroup
  520. });
  521. expect(installerStep7Controller._getDisplayedConfigGroups()).to.eql([defaultGroup]);
  522. });
  523. it('should return other groups if default selected', function () {
  524. var defaultGroup = Em.Object.create({isDefault: true}),
  525. cfgG = Em.Object.create({isDefault: true}),
  526. configGroups = Em.A([
  527. Em.Object.create({isDefault: false}),
  528. Em.Object.create({isDefault: false}),
  529. cfgG,
  530. Em.Object.create({isDefault: false})
  531. ]);
  532. installerStep7Controller.reopen({
  533. content: {services: []},
  534. selectedConfigGroup: defaultGroup,
  535. selectedService: {configGroups: configGroups}
  536. });
  537. expect(installerStep7Controller._getDisplayedConfigGroups()).to.eql(configGroups.without(cfgG));
  538. });
  539. });
  540. describe('#_setEditableValue', function () {
  541. it('shouldn\'t update config if no selectedConfigGroup', function () {
  542. installerStep7Controller.reopen({
  543. selectedConfigGroup: null
  544. });
  545. var config = Em.Object.create({isEditable: null});
  546. var updatedConfig = installerStep7Controller._setEditableValue(config);
  547. expect(updatedConfig.get('isEditable')).to.be.null;
  548. });
  549. it('should set isEditable equal to selectedGroup.isDefault if service not installed', function () {
  550. var isDefault = true;
  551. installerStep7Controller.reopen({
  552. installedServiceNames: [],
  553. selectedService: {serviceName: 'abc'},
  554. selectedConfigGroup: Em.Object.create({isDefault: isDefault})
  555. });
  556. var config = Em.Object.create({isEditable: null});
  557. var updatedConfig = installerStep7Controller._setEditableValue(config);
  558. expect(updatedConfig.get('isEditable')).to.equal(isDefault);
  559. installerStep7Controller.toggleProperty('selectedConfigGroup.isDefault');
  560. updatedConfig = installerStep7Controller._setEditableValue(config);
  561. expect(updatedConfig.get('isEditable')).to.equal(!isDefault);
  562. });
  563. Em.A([
  564. {
  565. isEditable: false,
  566. isReconfigurable: false,
  567. isDefault: true,
  568. e: false
  569. },
  570. {
  571. isEditable: true,
  572. isReconfigurable: true,
  573. isDefault: true,
  574. e: true
  575. },
  576. {
  577. isEditable: false,
  578. isReconfigurable: true,
  579. isDefault: false,
  580. e: false
  581. },
  582. {
  583. isEditable: true,
  584. isReconfigurable: false,
  585. isDefault: false,
  586. e: false
  587. }
  588. ]).forEach(function (test) {
  589. it('service installed, isEditable = ' + test.isEditable.toString() + ', isReconfigurable = ' + test.isReconfigurable.toString(), function () {
  590. var config = Em.Object.create({
  591. isReconfigurable: test.isReconfigurable,
  592. isEditable: test.isEditable
  593. });
  594. installerStep7Controller.reopen({
  595. installedServiceNames: Em.A(['a']),
  596. selectedService: Em.Object.create({serviceName: 'a'}),
  597. selectedConfigGroup: Em.Object.create({isDefault: test.isDefault})
  598. });
  599. var updateConfig = installerStep7Controller._setEditableValue(config);
  600. expect(updateConfig.get('isEditable')).to.equal(test.e);
  601. });
  602. });
  603. });
  604. describe('#_setOverrides', function () {
  605. it('shouldn\'t update config if no selectedConfigGroup', function () {
  606. installerStep7Controller.reopen({
  607. selectedConfigGroup: null
  608. });
  609. var config = Em.Object.create({overrides: null});
  610. var updatedConfig = installerStep7Controller._setOverrides(config, []);
  611. expect(updatedConfig.get('overrides')).to.be.null;
  612. });
  613. it('no overrideToAdd', function () {
  614. var isDefault = true,
  615. name = 'n1',
  616. config = Em.Object.create({overrides: null, name: name, flag: 'flag'}),
  617. overrides = Em.A([
  618. Em.Object.create({name: name, value: 'v1'}),
  619. Em.Object.create({name: name, value: 'v2'}),
  620. Em.Object.create({name: 'n2', value: 'v3'})
  621. ]);
  622. installerStep7Controller.reopen({
  623. overrideToAdd: null,
  624. selectedConfigGroup: Em.Object.create({
  625. isDefault: isDefault
  626. })
  627. });
  628. var updatedConfig = installerStep7Controller._setOverrides(config, overrides);
  629. expect(updatedConfig.get('overrides.length')).to.equal(2);
  630. expect(updatedConfig.get('overrides').everyProperty('isEditable', !isDefault)).to.equal(true);
  631. expect(updatedConfig.get('overrides').everyProperty('parentSCP.flag', 'flag')).to.equal(true);
  632. });
  633. it('overrideToAdd exists', function () {
  634. var isDefault = true,
  635. name = 'n1',
  636. config = Em.Object.create({overrides: null, name: name, flag: 'flag'}),
  637. overrides = Em.A([
  638. Em.Object.create({name: name, value: 'v1'}),
  639. Em.Object.create({name: name, value: 'v2'}),
  640. Em.Object.create({name: 'n2', value: 'v3'})
  641. ]);
  642. installerStep7Controller.reopen({
  643. overrideToAdd: Em.Object.create({name: name}),
  644. selectedService: {configGroups: [Em.Object.create({name: 'n', properties: []})]},
  645. selectedConfigGroup: Em.Object.create({
  646. isDefault: isDefault,
  647. name: 'n'
  648. })
  649. });
  650. var updatedConfig = installerStep7Controller._setOverrides(config, overrides);
  651. expect(updatedConfig.get('overrides.length')).to.equal(3);
  652. expect(updatedConfig.get('overrides').everyProperty('isEditable', !isDefault)).to.equal(true);
  653. expect(updatedConfig.get('overrides').everyProperty('parentSCP.flag', 'flag')).to.equal(true);
  654. });
  655. });
  656. describe('#switchConfigGroupConfigs', function () {
  657. it('if selectedConfigGroup is null, serviceConfigs shouldn\'t be changed', function () {
  658. installerStep7Controller.reopen({
  659. selectedConfigGroup: null,
  660. content: {services: []},
  661. serviceConfigs: {configs: [
  662. {overrides: []},
  663. {overrides: []}
  664. ]}
  665. });
  666. installerStep7Controller.switchConfigGroupConfigs();
  667. expect(installerStep7Controller.get('serviceConfigs.configs').everyProperty('overrides.length', 0)).to.equal(true);
  668. });
  669. it('should set configs for serviceConfigs', function () {
  670. var configGroups = [
  671. Em.Object.create({
  672. properties: [
  673. {name: 'g1', value: 'v1'},
  674. {name: 'g2', value: 'v2'}
  675. ]
  676. })
  677. ];
  678. sinon.stub(installerStep7Controller, '_getDisplayedConfigGroups', function () {
  679. return configGroups;
  680. });
  681. sinon.stub(installerStep7Controller, '_setEditableValue', function (config) {
  682. config.set('isEditable', true);
  683. return config;
  684. });
  685. installerStep7Controller.reopen({
  686. selectedConfigGroup: Em.Object.create({isDefault: true, name: 'g1'}),
  687. content: {services: []},
  688. selectedService: {configs: Em.A([Em.Object.create({name: 'g1', overrides: [], properties: []}), Em.Object.create({name: 'g2', overrides: []})])},
  689. serviceConfigs: {configs: [Em.Object.create({name: 'g1'})]}
  690. });
  691. installerStep7Controller.switchConfigGroupConfigs();
  692. var configs = installerStep7Controller.get('selectedService.configs');
  693. expect(configs.findProperty('name', 'g1').get('overrides').length).to.equal(1);
  694. expect(configs.findProperty('name', 'g2').get('overrides').length).to.equal(1);
  695. expect(configs.everyProperty('isEditable', true)).to.equal(true);
  696. installerStep7Controller._getDisplayedConfigGroups.restore();
  697. installerStep7Controller._setEditableValue.restore();
  698. });
  699. });
  700. describe('#selectProperService', function () {
  701. Em.A([
  702. {
  703. name: 'addServiceController',
  704. stepConfigs: [
  705. {selected: false, name: 'n1'},
  706. {selected: true, name: 'n2'},
  707. {selected: true, name: 'n3'}
  708. ],
  709. e: 'n2'
  710. },
  711. {
  712. name: 'installerController',
  713. stepConfigs: [
  714. {showConfig: false, name: 'n1'},
  715. {showConfig: false, name: 'n2'},
  716. {showConfig: true, name: 'n3'}
  717. ],
  718. e: 'n3'
  719. }
  720. ]).forEach(function (test) {
  721. it(test.name, function () {
  722. sinon.stub(installerStep7Controller, 'selectedServiceObserver', Em.K);
  723. installerStep7Controller.reopen({
  724. wizardController: Em.Object.create({
  725. name: test.name
  726. }),
  727. stepConfigs: test.stepConfigs
  728. });
  729. installerStep7Controller.selectProperService();
  730. expect(installerStep7Controller.get('selectedService.name')).to.equal(test.e);
  731. installerStep7Controller.selectedServiceObserver.restore();
  732. });
  733. });
  734. });
  735. describe('#setStepConfigs', function () {
  736. beforeEach(function () {
  737. installerStep7Controller.reopen({
  738. content: {services: []},
  739. wizardController: Em.Object.create({
  740. getDBProperty: function (key) {
  741. return this.get(key);
  742. }
  743. })
  744. });
  745. });
  746. afterEach(function () {
  747. App.config.renderConfigs.restore();
  748. });
  749. it('if wizard isn\'t addService, should set output of App.config.renderConfigs', function () {
  750. var serviceConfigs = Em.A([
  751. {},
  752. {}
  753. ]);
  754. sinon.stub(App.config, 'renderConfigs', function () {
  755. return serviceConfigs;
  756. });
  757. installerStep7Controller.set('wizardController.name', 'installerController');
  758. installerStep7Controller.setStepConfigs([], []);
  759. expect(installerStep7Controller.get('stepConfigs')).to.eql(serviceConfigs);
  760. });
  761. it('addServiceWizard used', function () {
  762. var serviceConfigs = Em.A([Em.Object.create({serviceName: 's1'}), Em.Object.create({serviceName: 's2'})]);
  763. installerStep7Controller.set('wizardController.name', 'addServiceController');
  764. installerStep7Controller.reopen({selectedServiceNames: ['s2']});
  765. sinon.stub(App.config, 'renderConfigs', function () {
  766. return serviceConfigs;
  767. });
  768. installerStep7Controller.setStepConfigs([], []);
  769. expect(installerStep7Controller.get('stepConfigs').everyProperty('showConfig', true)).to.equal(true);
  770. expect(installerStep7Controller.get('stepConfigs').findProperty('serviceName', 's2').get('selected')).to.equal(true);
  771. });
  772. it('addServiceWizard used, HA enabled', function () {
  773. sinon.stub(App, 'get', function (k) {
  774. if (k === 'isHaEnabled') {
  775. return true;
  776. }
  777. return Em.get(App, k);
  778. });
  779. var serviceConfigs = Em.A([
  780. Em.Object.create({
  781. serviceName: 'HDFS',
  782. configs: [
  783. {category: 'SECONDARY_NAMENODE'},
  784. {category: 'SECONDARY_NAMENODE'},
  785. {category: 'NameNode'},
  786. {category: 'NameNode'},
  787. {category: 'SECONDARY_NAMENODE'}
  788. ]
  789. }),
  790. Em.Object.create({serviceName: 's2'})]
  791. );
  792. installerStep7Controller.set('wizardController.name', 'addServiceController');
  793. installerStep7Controller.reopen({selectedServiceNames: ['HDFS', 's2']});
  794. sinon.stub(App.config, 'renderConfigs', function () {
  795. return serviceConfigs;
  796. });
  797. installerStep7Controller.setStepConfigs([], []);
  798. expect(installerStep7Controller.get('stepConfigs').everyProperty('showConfig', true)).to.equal(true);
  799. expect(installerStep7Controller.get('stepConfigs').findProperty('serviceName', 'HDFS').get('selected')).to.equal(true);
  800. expect(installerStep7Controller.get('stepConfigs').findProperty('serviceName', 'HDFS').get('configs').length).to.equal(2);
  801. App.get.restore();
  802. });
  803. });
  804. describe('#checkHostOverrideInstaller', function () {
  805. beforeEach(function () {
  806. sinon.stub(installerStep7Controller, 'loadConfigGroups', Em.K);
  807. sinon.stub(installerStep7Controller, 'loadInstalledServicesConfigGroups', Em.K);
  808. });
  809. afterEach(function () {
  810. installerStep7Controller.loadConfigGroups.restore();
  811. installerStep7Controller.loadInstalledServicesConfigGroups.restore();
  812. App.get.restore();
  813. });
  814. Em.A([
  815. {
  816. hostOverridesInstaller: false,
  817. installedServiceNames: [],
  818. m: 'hostOverridesInstaller is false, installedServiceNames is empty',
  819. e: {
  820. loadConfigGroups: false,
  821. loadInstalledServicesConfigGroups: false
  822. }
  823. },
  824. {
  825. hostOverridesInstaller: false,
  826. installedServiceNames: ['s1', 's2'],
  827. m: 'hostOverridesInstaller is false, installedServiceNames is n\'t empty',
  828. e: {
  829. loadConfigGroups: false,
  830. loadInstalledServicesConfigGroups: false
  831. }
  832. },
  833. {
  834. hostOverridesInstaller: true,
  835. installedServiceNames: [],
  836. m: 'hostOverridesInstaller is true, installedServiceNames is empty',
  837. e: {
  838. loadConfigGroups: true,
  839. loadInstalledServicesConfigGroups: false
  840. }
  841. },
  842. {
  843. hostOverridesInstaller: true,
  844. installedServiceNames: ['s1', 's2', 's3'],
  845. m: 'hostOverridesInstaller is true, installedServiceNames isn\'t empty',
  846. e: {
  847. loadConfigGroups: true,
  848. loadInstalledServicesConfigGroups: true
  849. }
  850. }
  851. ]).forEach(function (test) {
  852. it(test.m, function () {
  853. sinon.stub(App, 'get', function (k) {
  854. if (k === 'supports.hostOverridesInstaller') return test.hostOverridesInstaller;
  855. return Em.get(App, k);
  856. });
  857. installerStep7Controller.reopen({installedServiceNames: test.installedServiceNames});
  858. installerStep7Controller.checkHostOverrideInstaller();
  859. if (test.e.loadConfigGroups) {
  860. expect(installerStep7Controller.loadConfigGroups.calledOnce).to.equal(true);
  861. }
  862. else {
  863. expect(installerStep7Controller.loadConfigGroups.called).to.equal(false);
  864. }
  865. if (test.e.loadInstalledServicesConfigGroups) {
  866. expect(installerStep7Controller.loadInstalledServicesConfigGroups.calledOnce).to.equal(true);
  867. }
  868. else {
  869. expect(installerStep7Controller.loadInstalledServicesConfigGroups.called).to.equal(false);
  870. }
  871. });
  872. });
  873. });
  874. describe('#loadStep', function () {
  875. beforeEach(function () {
  876. installerStep7Controller.reopen({
  877. content: {services: []},
  878. wizardController: Em.Object.create({
  879. getDBProperty: function (k) {
  880. return this.get(k);
  881. }
  882. })
  883. });
  884. sinon.stub(App.config, 'mergePreDefinedWithStored', Em.K);
  885. sinon.stub(App.config, 'addAdvancedConfigs', Em.K);
  886. sinon.stub(App.config, 'addCustomConfigs', Em.K);
  887. sinon.stub(App.config, 'fileConfigsIntoTextarea', Em.K);
  888. sinon.stub(installerStep7Controller, 'clearStep', Em.K);
  889. sinon.stub(installerStep7Controller, 'getConfigTags', Em.K);
  890. sinon.stub(installerStep7Controller, 'setInstalledServiceConfigs', Em.K);
  891. sinon.stub(installerStep7Controller, 'resolveServiceDependencyConfigs', Em.K);
  892. sinon.stub(installerStep7Controller, 'setStepConfigs', Em.K);
  893. sinon.stub(installerStep7Controller, 'checkHostOverrideInstaller', Em.K);
  894. sinon.stub(installerStep7Controller, 'activateSpecialConfigs', Em.K);
  895. sinon.stub(installerStep7Controller, 'selectProperService', Em.K);
  896. sinon.stub(App.router, 'send', Em.K);
  897. });
  898. afterEach(function () {
  899. App.config.mergePreDefinedWithStored.restore();
  900. App.config.addAdvancedConfigs.restore();
  901. App.config.addCustomConfigs.restore();
  902. App.config.fileConfigsIntoTextarea.restore();
  903. installerStep7Controller.clearStep.restore();
  904. installerStep7Controller.getConfigTags.restore();
  905. installerStep7Controller.setInstalledServiceConfigs.restore();
  906. installerStep7Controller.resolveServiceDependencyConfigs.restore();
  907. installerStep7Controller.setStepConfigs.restore();
  908. installerStep7Controller.checkHostOverrideInstaller.restore();
  909. installerStep7Controller.activateSpecialConfigs.restore();
  910. installerStep7Controller.selectProperService.restore();
  911. App.router.send.restore();
  912. });
  913. it('should call clearStep', function () {
  914. installerStep7Controller.loadStep();
  915. expect(installerStep7Controller.clearStep.calledOnce).to.equal(true);
  916. });
  917. it('shouldn\'t do nothing if isAdvancedConfigLoaded is false', function () {
  918. installerStep7Controller.set('isAdvancedConfigLoaded', false);
  919. installerStep7Controller.loadStep();
  920. expect(installerStep7Controller.clearStep.called).to.equal(false);
  921. });
  922. it('should use App.config to map configs', function () {
  923. installerStep7Controller.loadStep();
  924. expect(App.config.mergePreDefinedWithStored.calledOnce).to.equal(true);
  925. expect(App.config.addAdvancedConfigs.calledOnce).to.equal(true);
  926. expect(App.config.addCustomConfigs.calledOnce).to.equal(true);
  927. });
  928. Em.A([
  929. {
  930. allSelectedServiceNames: ['YARN'],
  931. capacitySchedulerUi: false,
  932. e: true
  933. },
  934. {
  935. allSelectedServiceNames: ['YARN'],
  936. capacitySchedulerUi: true,
  937. e: false
  938. },
  939. {
  940. allSelectedServiceNames: ['HDFS'],
  941. capacitySchedulerUi: false,
  942. e: false
  943. },
  944. {
  945. allSelectedServiceNames: ['HDFS'],
  946. capacitySchedulerUi: true,
  947. e: false
  948. }
  949. ]).forEach(function (test) {
  950. it('allSelectedServiceNames = ' + JSON.stringify(test.allSelectedServiceNames) + ', capacitySchedulerUi = ' + test.capacitySchedulerUi.toString(), function () {
  951. sinon.stub(App, 'get', function (k) {
  952. if (k === 'supports.capacitySchedulerUi') return test.capacitySchedulerUi;
  953. return Em.get(App, k);
  954. });
  955. installerStep7Controller.reopen({allSelectedServiceNames: test.allSelectedServiceNames});
  956. installerStep7Controller.loadStep();
  957. if (test.e) {
  958. expect(App.config.fileConfigsIntoTextarea.calledOnce).to.equal(true);
  959. }
  960. else {
  961. expect(App.config.fileConfigsIntoTextarea.called).to.equal(false);
  962. }
  963. App.get.restore();
  964. });
  965. });
  966. it('should call setInstalledServiceConfigs for addServiceController', function () {
  967. installerStep7Controller.set('wizardController.name', 'addServiceController');
  968. installerStep7Controller.loadStep();
  969. expect(installerStep7Controller.setInstalledServiceConfigs.calledOnce).to.equal(true);
  970. });
  971. Em.A([
  972. {
  973. allSelectedServiceNames: ['STORM'],
  974. installedServiceNames: ['STORM'],
  975. m: 'allSelectedServiceNames contains STORM, installedServiceNames contains STORM',
  976. e: true
  977. },
  978. {
  979. allSelectedServiceNames: [],
  980. installedServiceNames: ['STORM'],
  981. m: 'allSelectedServiceNames doesn\'t contain STORM, installedServiceNames contains STORM',
  982. e: true
  983. },
  984. {
  985. allSelectedServiceNames: ['STORM'],
  986. installedServiceNames: [],
  987. m: 'allSelectedServiceNames contains STORM, installedServiceNames doesn\'t contain STORM',
  988. e: true
  989. },
  990. {
  991. allSelectedServiceNames: [],
  992. installedServiceNames: [],
  993. m: 'allSelectedServiceNames doesn\'t contain STORM, installedServiceNames doesn\'t contain STORM',
  994. e: false
  995. }
  996. ]).forEach(function (test) {
  997. it(test.m, function () {
  998. installerStep7Controller.reopen({
  999. allSelectedServiceNames: test.allSelectedServiceNames,
  1000. installedServiceNames: test.installedServiceNames
  1001. });
  1002. installerStep7Controller.loadStep();
  1003. if (test.e) {
  1004. expect(installerStep7Controller.resolveServiceDependencyConfigs.calledOnce).to.equal(true);
  1005. }
  1006. else {
  1007. expect(installerStep7Controller.resolveServiceDependencyConfigs.called).to.equal(false);
  1008. }
  1009. });
  1010. });
  1011. it('should call setStepConfigs', function () {
  1012. installerStep7Controller.loadStep();
  1013. expect(installerStep7Controller.setStepConfigs.calledOnce).to.equal(true);
  1014. });
  1015. it('should call checkHostOverrideInstaller', function () {
  1016. installerStep7Controller.loadStep();
  1017. expect(installerStep7Controller.checkHostOverrideInstaller.calledOnce).to.equal(true);
  1018. });
  1019. it('should call activateSpecialConfigs', function () {
  1020. installerStep7Controller.loadStep();
  1021. expect(installerStep7Controller.activateSpecialConfigs.calledOnce).to.equal(true);
  1022. });
  1023. it('should call selectProperService', function () {
  1024. installerStep7Controller.loadStep();
  1025. expect(installerStep7Controller.selectProperService.calledOnce).to.equal(true);
  1026. });
  1027. Em.A([
  1028. {
  1029. m: 'should skip config step',
  1030. skipConfigStep: true,
  1031. e: true
  1032. },
  1033. {
  1034. m: 'shouldn\'t skip config step',
  1035. skipConfigStep: false,
  1036. e: false
  1037. }
  1038. ]).forEach(function (test) {
  1039. it(test.m, function () {
  1040. installerStep7Controller.set('content.skipConfigStep', test.skipConfigStep);
  1041. installerStep7Controller.loadStep();
  1042. if (test.e) {
  1043. expect(App.router.send.calledWith('next')).to.equal(true);
  1044. }
  1045. else {
  1046. expect(App.router.send.called).to.equal(false);
  1047. }
  1048. });
  1049. });
  1050. });
  1051. describe('#_updateValueForCheckBoxConfig', function () {
  1052. Em.A([
  1053. {
  1054. v: 'true',
  1055. e: true
  1056. },
  1057. {
  1058. v: 'false',
  1059. e: false
  1060. }
  1061. ]).forEach(function (test) {
  1062. it(test.v, function () {
  1063. var serviceConfigProperty = Em.Object.create({value: test.v});
  1064. installerStep7Controller._updateValueForCheckBoxConfig(serviceConfigProperty);
  1065. expect(serviceConfigProperty.get('value')).to.equal(test.e);
  1066. expect(serviceConfigProperty.get('defaultValue')).to.equal(test.e);
  1067. });
  1068. });
  1069. });
  1070. describe('#_updateIsEditableFlagForConfig', function () {
  1071. Em.A([
  1072. {
  1073. isAdmin: false,
  1074. isReconfigurable: false,
  1075. isHostsConfigsPage: true,
  1076. defaultGroupSelected: false,
  1077. m: 'false for non-admin users',
  1078. e: false
  1079. },
  1080. {
  1081. isAdmin: true,
  1082. isReconfigurable: false,
  1083. isHostsConfigsPage: true,
  1084. defaultGroupSelected: false,
  1085. m: 'false if defaultGroupSelected is false and isHostsConfigsPage is true',
  1086. e: false
  1087. },
  1088. {
  1089. isAdmin: true,
  1090. isReconfigurable: false,
  1091. isHostsConfigsPage: true,
  1092. defaultGroupSelected: true,
  1093. m: 'false if defaultGroupSelected is true and isHostsConfigsPage is true',
  1094. e: false
  1095. },
  1096. {
  1097. isAdmin: true,
  1098. isReconfigurable: false,
  1099. isHostsConfigsPage: false,
  1100. defaultGroupSelected: false,
  1101. m: 'false if defaultGroupSelected is false and isHostsConfigsPage is false',
  1102. e: false
  1103. },
  1104. {
  1105. isAdmin: true,
  1106. isReconfigurable: true,
  1107. isHostsConfigsPage: false,
  1108. defaultGroupSelected: true,
  1109. m: 'equal to isReconfigurable if defaultGroupSelected is true and isHostsConfigsPage is false',
  1110. e: true
  1111. }
  1112. ]).forEach(function (test) {
  1113. it(test.m, function () {
  1114. sinon.stub(App, 'get', function (k) {
  1115. if (k === 'isAdmin') return test.isAdmin;
  1116. return Em.get(App, k);
  1117. });
  1118. installerStep7Controller.reopen({isHostsConfigsPage: test.isHostsConfigsPage});
  1119. var serviceConfigProperty = Em.Object.create({
  1120. isReconfigurable: test.isReconfigurable
  1121. });
  1122. installerStep7Controller._updateIsEditableFlagForConfig(serviceConfigProperty, test.defaultGroupSelected);
  1123. App.get.restore();
  1124. expect(serviceConfigProperty.get('isEditable')).to.equal(test.e);
  1125. });
  1126. });
  1127. });
  1128. describe('#_updateOverridesForConfig', function () {
  1129. it('should set empty array', function () {
  1130. var serviceConfigProperty = Em.Object.create({
  1131. overrides: null
  1132. }), component = Em.Object.create();
  1133. installerStep7Controller._updateOverridesForConfig(serviceConfigProperty, component);
  1134. expect(serviceConfigProperty.get('overrides')).to.eql(Em.A([]));
  1135. });
  1136. it('host overrides not supported', function () {
  1137. var serviceConfigProperty = Em.Object.create({
  1138. overrides: [
  1139. {value: 'new value'}
  1140. ]
  1141. }), component = Em.Object.create({selectedConfigGroup: {isDefault: false}});
  1142. installerStep7Controller._updateOverridesForConfig(serviceConfigProperty, component);
  1143. expect(serviceConfigProperty.get('overrides').length).to.equal(1);
  1144. expect(serviceConfigProperty.get('overrides.firstObject.value')).to.equal('new value');
  1145. expect(serviceConfigProperty.get('overrides.firstObject.isOriginalSCP')).to.equal(false);
  1146. expect(serviceConfigProperty.get('overrides.firstObject.parentSCP')).to.eql(serviceConfigProperty);
  1147. });
  1148. it('host overrides supported', function () {
  1149. sinon.stub(App, 'get', function (k) {
  1150. if (k === 'supports.hostOverrides') return true;
  1151. return Em.get(App, k);
  1152. });
  1153. var serviceConfigProperty = Em.Object.create({
  1154. overrides: [
  1155. {value: 'new value', group: Em.Object.create({name: 'n1'})}
  1156. ]
  1157. }),
  1158. component = Em.Object.create({
  1159. selectedConfigGroup: {isDefault: true},
  1160. configGroups: Em.A([
  1161. Em.Object.create({name: 'n1', properties: []})
  1162. ])
  1163. });
  1164. installerStep7Controller._updateOverridesForConfig(serviceConfigProperty, component);
  1165. App.get.restore();
  1166. expect(serviceConfigProperty.get('overrides').length).to.equal(1);
  1167. expect(serviceConfigProperty.get('overrides.firstObject.value')).to.equal('new value');
  1168. expect(serviceConfigProperty.get('overrides.firstObject.isOriginalSCP')).to.equal(false);
  1169. expect(serviceConfigProperty.get('overrides.firstObject.parentSCP')).to.eql(serviceConfigProperty);
  1170. expect(component.get('configGroups.firstObject.properties').length).to.equal(1);
  1171. expect(component.get('configGroups.firstObject.properties.firstObject.isEditable')).to.equal(false);
  1172. expect(component.get('configGroups.firstObject.properties.firstObject.group')).to.be.object;
  1173. });
  1174. });
  1175. });