step7_test.js 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217
  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. properties = [
  488. { name: "p1", filename: "file.xml" },
  489. { name: "p2", filename: "file.xml" }
  490. ],
  491. serviceConfigGroups = [
  492. {service: {id: 'HDFS'}, properties: properties.slice(), isDefault: true, n: 'n1'},
  493. {service: {id: 'HDFS'}, properties: properties.slice(), isDefault: false, n: 'n2'}
  494. ];
  495. installerStep7Controller.reopen({
  496. stepConfigs: [Em.Object.create({serviceName: serviceName, configGroups: configGroups, configs: properties})]
  497. });
  498. installerStep7Controller.loadConfigGroups(serviceConfigGroups);
  499. expect(installerStep7Controller.get('stepConfigs.firstObject.configGroups.length')).to.equal(2);
  500. expect(installerStep7Controller.get('stepConfigs.firstObject.configGroups').findProperty('isDefault').get('n')).to.equal('n1');
  501. expect(installerStep7Controller.get('stepConfigs.firstObject.configGroups').findProperty('isDefault', false).get('properties').everyProperty('group.n', 'n2')).to.equal(true);
  502. expect(installerStep7Controller.get('stepConfigs.firstObject.configGroups').findProperty('isDefault', false).get('parentConfigGroup.n')).to.equal('n1');
  503. });
  504. });
  505. describe('#_getDisplayedConfigGroups', function () {
  506. it('should return [] if no selected group', function () {
  507. installerStep7Controller.reopen({
  508. content: {services: []},
  509. selectedConfigGroup: null
  510. });
  511. expect(installerStep7Controller._getDisplayedConfigGroups()).to.eql([]);
  512. });
  513. it('should return default config group if another selected', function () {
  514. var defaultGroup = Em.Object.create({isDefault: false});
  515. installerStep7Controller.reopen({
  516. content: {services: []},
  517. selectedConfigGroup: defaultGroup
  518. });
  519. expect(installerStep7Controller._getDisplayedConfigGroups()).to.eql([defaultGroup]);
  520. });
  521. it('should return other groups if default selected', function () {
  522. var defaultGroup = Em.Object.create({isDefault: true}),
  523. cfgG = Em.Object.create({isDefault: true}),
  524. configGroups = Em.A([
  525. Em.Object.create({isDefault: false}),
  526. Em.Object.create({isDefault: false}),
  527. cfgG,
  528. Em.Object.create({isDefault: false})
  529. ]);
  530. installerStep7Controller.reopen({
  531. content: {services: []},
  532. selectedConfigGroup: defaultGroup,
  533. selectedService: {configGroups: configGroups}
  534. });
  535. expect(installerStep7Controller._getDisplayedConfigGroups()).to.eql(configGroups.without(cfgG));
  536. });
  537. });
  538. describe('#_setEditableValue', function () {
  539. it('shouldn\'t update config if no selectedConfigGroup', function () {
  540. installerStep7Controller.reopen({
  541. selectedConfigGroup: null
  542. });
  543. var config = Em.Object.create({isEditable: null});
  544. var updatedConfig = installerStep7Controller._setEditableValue(config);
  545. expect(updatedConfig.get('isEditable')).to.be.null;
  546. });
  547. it('should set isEditable equal to selectedGroup.isDefault if service not installed', function () {
  548. var isDefault = true;
  549. installerStep7Controller.reopen({
  550. installedServiceNames: [],
  551. selectedService: {serviceName: 'abc'},
  552. selectedConfigGroup: Em.Object.create({isDefault: isDefault})
  553. });
  554. var config = Em.Object.create({isEditable: null});
  555. var updatedConfig = installerStep7Controller._setEditableValue(config);
  556. expect(updatedConfig.get('isEditable')).to.equal(isDefault);
  557. installerStep7Controller.toggleProperty('selectedConfigGroup.isDefault');
  558. updatedConfig = installerStep7Controller._setEditableValue(config);
  559. expect(updatedConfig.get('isEditable')).to.equal(!isDefault);
  560. });
  561. Em.A([
  562. {
  563. isEditable: false,
  564. isReconfigurable: false,
  565. isDefault: true,
  566. e: false
  567. },
  568. {
  569. isEditable: true,
  570. isReconfigurable: true,
  571. isDefault: true,
  572. e: true
  573. },
  574. {
  575. isEditable: false,
  576. isReconfigurable: true,
  577. isDefault: false,
  578. e: false
  579. },
  580. {
  581. isEditable: true,
  582. isReconfigurable: false,
  583. isDefault: false,
  584. e: false
  585. }
  586. ]).forEach(function (test) {
  587. it('service installed, isEditable = ' + test.isEditable.toString() + ', isReconfigurable = ' + test.isReconfigurable.toString(), function () {
  588. var config = Em.Object.create({
  589. isReconfigurable: test.isReconfigurable,
  590. isEditable: test.isEditable
  591. });
  592. installerStep7Controller.reopen({
  593. installedServiceNames: Em.A(['a']),
  594. selectedService: Em.Object.create({serviceName: 'a'}),
  595. selectedConfigGroup: Em.Object.create({isDefault: test.isDefault})
  596. });
  597. var updateConfig = installerStep7Controller._setEditableValue(config);
  598. expect(updateConfig.get('isEditable')).to.equal(test.e);
  599. });
  600. });
  601. });
  602. describe('#_setOverrides', function () {
  603. it('shouldn\'t update config if no selectedConfigGroup', function () {
  604. installerStep7Controller.reopen({
  605. selectedConfigGroup: null
  606. });
  607. var config = Em.Object.create({overrides: null});
  608. var updatedConfig = installerStep7Controller._setOverrides(config, []);
  609. expect(updatedConfig.get('overrides')).to.be.null;
  610. });
  611. it('no overrideToAdd', function () {
  612. var isDefault = true,
  613. name = 'n1',
  614. config = Em.Object.create({overrides: null, name: name, flag: 'flag'}),
  615. overrides = Em.A([
  616. Em.Object.create({name: name, value: 'v1'}),
  617. Em.Object.create({name: name, value: 'v2'}),
  618. Em.Object.create({name: 'n2', value: 'v3'})
  619. ]);
  620. installerStep7Controller.reopen({
  621. overrideToAdd: null,
  622. selectedConfigGroup: Em.Object.create({
  623. isDefault: isDefault
  624. })
  625. });
  626. var updatedConfig = installerStep7Controller._setOverrides(config, overrides);
  627. expect(updatedConfig.get('overrides.length')).to.equal(2);
  628. expect(updatedConfig.get('overrides').everyProperty('isEditable', !isDefault)).to.equal(true);
  629. expect(updatedConfig.get('overrides').everyProperty('parentSCP.flag', 'flag')).to.equal(true);
  630. });
  631. it('overrideToAdd exists', function () {
  632. var isDefault = true,
  633. name = 'n1',
  634. config = Em.Object.create({overrides: null, name: name, flag: 'flag'}),
  635. overrides = Em.A([
  636. Em.Object.create({name: name, value: 'v1'}),
  637. Em.Object.create({name: name, value: 'v2'}),
  638. Em.Object.create({name: 'n2', value: 'v3'})
  639. ]);
  640. installerStep7Controller.reopen({
  641. overrideToAdd: Em.Object.create({name: name}),
  642. selectedService: {configGroups: [Em.Object.create({name: 'n', properties: []})]},
  643. selectedConfigGroup: Em.Object.create({
  644. isDefault: isDefault,
  645. name: 'n'
  646. })
  647. });
  648. var updatedConfig = installerStep7Controller._setOverrides(config, overrides);
  649. expect(updatedConfig.get('overrides.length')).to.equal(3);
  650. expect(updatedConfig.get('overrides').everyProperty('isEditable', !isDefault)).to.equal(true);
  651. expect(updatedConfig.get('overrides').everyProperty('parentSCP.flag', 'flag')).to.equal(true);
  652. });
  653. });
  654. describe('#switchConfigGroupConfigs', function () {
  655. it('if selectedConfigGroup is null, serviceConfigs shouldn\'t be changed', function () {
  656. installerStep7Controller.reopen({
  657. selectedConfigGroup: null,
  658. content: {services: []},
  659. serviceConfigs: {configs: [
  660. {overrides: []},
  661. {overrides: []}
  662. ]}
  663. });
  664. installerStep7Controller.switchConfigGroupConfigs();
  665. expect(installerStep7Controller.get('serviceConfigs.configs').everyProperty('overrides.length', 0)).to.equal(true);
  666. });
  667. it('should set configs for serviceConfigs', function () {
  668. var configGroups = [
  669. Em.Object.create({
  670. properties: [
  671. {name: 'g1', value: 'v1'},
  672. {name: 'g2', value: 'v2'}
  673. ]
  674. })
  675. ];
  676. sinon.stub(installerStep7Controller, '_getDisplayedConfigGroups', function () {
  677. return configGroups;
  678. });
  679. sinon.stub(installerStep7Controller, '_setEditableValue', function (config) {
  680. config.set('isEditable', true);
  681. return config;
  682. });
  683. installerStep7Controller.reopen({
  684. selectedConfigGroup: Em.Object.create({isDefault: true, name: 'g1'}),
  685. content: {services: []},
  686. selectedService: {configs: Em.A([Em.Object.create({name: 'g1', overrides: [], properties: []}), Em.Object.create({name: 'g2', overrides: []})])},
  687. serviceConfigs: {configs: [Em.Object.create({name: 'g1'})]}
  688. });
  689. installerStep7Controller.switchConfigGroupConfigs();
  690. var configs = installerStep7Controller.get('selectedService.configs');
  691. expect(configs.findProperty('name', 'g1').get('overrides').length).to.equal(1);
  692. expect(configs.findProperty('name', 'g2').get('overrides').length).to.equal(1);
  693. expect(configs.everyProperty('isEditable', true)).to.equal(true);
  694. installerStep7Controller._getDisplayedConfigGroups.restore();
  695. installerStep7Controller._setEditableValue.restore();
  696. });
  697. });
  698. describe('#selectProperService', function () {
  699. Em.A([
  700. {
  701. name: 'addServiceController',
  702. stepConfigs: [
  703. {selected: false, name: 'n1'},
  704. {selected: true, name: 'n2'},
  705. {selected: true, name: 'n3'}
  706. ],
  707. e: 'n2'
  708. },
  709. {
  710. name: 'installerController',
  711. stepConfigs: [
  712. {showConfig: false, name: 'n1'},
  713. {showConfig: false, name: 'n2'},
  714. {showConfig: true, name: 'n3'}
  715. ],
  716. e: 'n3'
  717. }
  718. ]).forEach(function (test) {
  719. it(test.name, function () {
  720. sinon.stub(installerStep7Controller, 'selectedServiceObserver', Em.K);
  721. installerStep7Controller.reopen({
  722. wizardController: Em.Object.create({
  723. name: test.name
  724. }),
  725. stepConfigs: test.stepConfigs
  726. });
  727. installerStep7Controller.selectProperService();
  728. expect(installerStep7Controller.get('selectedService.name')).to.equal(test.e);
  729. installerStep7Controller.selectedServiceObserver.restore();
  730. });
  731. });
  732. });
  733. describe('#setStepConfigs', function () {
  734. beforeEach(function () {
  735. installerStep7Controller.reopen({
  736. content: {services: []},
  737. wizardController: Em.Object.create({
  738. getDBProperty: function (key) {
  739. return this.get(key);
  740. }
  741. })
  742. });
  743. });
  744. afterEach(function () {
  745. App.config.renderConfigs.restore();
  746. });
  747. it('if wizard isn\'t addService, should set output of App.config.renderConfigs', function () {
  748. var serviceConfigs = Em.A([
  749. {},
  750. {}
  751. ]);
  752. sinon.stub(App.config, 'renderConfigs', function () {
  753. return serviceConfigs;
  754. });
  755. installerStep7Controller.set('wizardController.name', 'installerController');
  756. installerStep7Controller.setStepConfigs([], []);
  757. expect(installerStep7Controller.get('stepConfigs')).to.eql(serviceConfigs);
  758. });
  759. it('addServiceWizard used', function () {
  760. var serviceConfigs = Em.A([Em.Object.create({serviceName: 's1'}), Em.Object.create({serviceName: 's2'})]);
  761. installerStep7Controller.set('wizardController.name', 'addServiceController');
  762. installerStep7Controller.reopen({selectedServiceNames: ['s2']});
  763. sinon.stub(App.config, 'renderConfigs', function () {
  764. return serviceConfigs;
  765. });
  766. installerStep7Controller.setStepConfigs([], []);
  767. expect(installerStep7Controller.get('stepConfigs').everyProperty('showConfig', true)).to.equal(true);
  768. expect(installerStep7Controller.get('stepConfigs').findProperty('serviceName', 's2').get('selected')).to.equal(true);
  769. });
  770. it('addServiceWizard used, HA enabled', function () {
  771. sinon.stub(App, 'get', function (k) {
  772. if (k === 'isHaEnabled') {
  773. return true;
  774. }
  775. return Em.get(App, k);
  776. });
  777. var serviceConfigs = Em.A([
  778. Em.Object.create({
  779. serviceName: 'HDFS',
  780. configs: [
  781. {category: 'SECONDARY_NAMENODE'},
  782. {category: 'SECONDARY_NAMENODE'},
  783. {category: 'NameNode'},
  784. {category: 'NameNode'},
  785. {category: 'SECONDARY_NAMENODE'}
  786. ]
  787. }),
  788. Em.Object.create({serviceName: 's2'})]
  789. );
  790. installerStep7Controller.set('wizardController.name', 'addServiceController');
  791. installerStep7Controller.reopen({selectedServiceNames: ['HDFS', 's2']});
  792. sinon.stub(App.config, 'renderConfigs', function () {
  793. return serviceConfigs;
  794. });
  795. installerStep7Controller.setStepConfigs([], []);
  796. expect(installerStep7Controller.get('stepConfigs').everyProperty('showConfig', true)).to.equal(true);
  797. expect(installerStep7Controller.get('stepConfigs').findProperty('serviceName', 'HDFS').get('selected')).to.equal(true);
  798. expect(installerStep7Controller.get('stepConfigs').findProperty('serviceName', 'HDFS').get('configs').length).to.equal(2);
  799. App.get.restore();
  800. });
  801. });
  802. describe('#checkHostOverrideInstaller', function () {
  803. beforeEach(function () {
  804. sinon.stub(installerStep7Controller, 'loadConfigGroups', Em.K);
  805. sinon.stub(installerStep7Controller, 'loadInstalledServicesConfigGroups', Em.K);
  806. });
  807. afterEach(function () {
  808. installerStep7Controller.loadConfigGroups.restore();
  809. installerStep7Controller.loadInstalledServicesConfigGroups.restore();
  810. App.get.restore();
  811. });
  812. Em.A([
  813. {
  814. hostOverridesInstaller: false,
  815. installedServiceNames: [],
  816. m: 'hostOverridesInstaller is false, installedServiceNames is empty',
  817. e: {
  818. loadConfigGroups: false,
  819. loadInstalledServicesConfigGroups: false
  820. }
  821. },
  822. {
  823. hostOverridesInstaller: false,
  824. installedServiceNames: ['s1', 's2'],
  825. m: 'hostOverridesInstaller is false, installedServiceNames is n\'t empty',
  826. e: {
  827. loadConfigGroups: false,
  828. loadInstalledServicesConfigGroups: false
  829. }
  830. },
  831. {
  832. hostOverridesInstaller: true,
  833. installedServiceNames: [],
  834. m: 'hostOverridesInstaller is true, installedServiceNames is empty',
  835. e: {
  836. loadConfigGroups: true,
  837. loadInstalledServicesConfigGroups: false
  838. }
  839. },
  840. {
  841. hostOverridesInstaller: true,
  842. installedServiceNames: ['s1', 's2', 's3'],
  843. m: 'hostOverridesInstaller is true, installedServiceNames isn\'t empty',
  844. e: {
  845. loadConfigGroups: true,
  846. loadInstalledServicesConfigGroups: true
  847. }
  848. }
  849. ]).forEach(function (test) {
  850. it(test.m, function () {
  851. sinon.stub(App, 'get', function (k) {
  852. if (k === 'supports.hostOverridesInstaller') return test.hostOverridesInstaller;
  853. return Em.get(App, k);
  854. });
  855. installerStep7Controller.reopen({installedServiceNames: test.installedServiceNames});
  856. installerStep7Controller.checkHostOverrideInstaller();
  857. if (test.e.loadConfigGroups) {
  858. expect(installerStep7Controller.loadConfigGroups.calledOnce).to.equal(true);
  859. }
  860. else {
  861. expect(installerStep7Controller.loadConfigGroups.called).to.equal(false);
  862. }
  863. if (test.e.loadInstalledServicesConfigGroups) {
  864. expect(installerStep7Controller.loadInstalledServicesConfigGroups.calledOnce).to.equal(true);
  865. }
  866. else {
  867. expect(installerStep7Controller.loadInstalledServicesConfigGroups.called).to.equal(false);
  868. }
  869. });
  870. });
  871. });
  872. describe('#loadStep', function () {
  873. beforeEach(function () {
  874. installerStep7Controller.reopen({
  875. content: {services: []},
  876. wizardController: Em.Object.create({
  877. getDBProperty: function (k) {
  878. return this.get(k);
  879. }
  880. })
  881. });
  882. sinon.stub(App.config, 'mergePreDefinedWithStored', Em.K);
  883. sinon.stub(App.config, 'addAdvancedConfigs', Em.K);
  884. sinon.stub(App.config, 'addCustomConfigs', Em.K);
  885. sinon.stub(App.config, 'fileConfigsIntoTextarea', Em.K);
  886. sinon.stub(installerStep7Controller, 'clearStep', Em.K);
  887. sinon.stub(installerStep7Controller, 'getConfigTags', Em.K);
  888. sinon.stub(installerStep7Controller, 'setInstalledServiceConfigs', Em.K);
  889. sinon.stub(installerStep7Controller, 'resolveServiceDependencyConfigs', Em.K);
  890. sinon.stub(installerStep7Controller, 'setStepConfigs', Em.K);
  891. sinon.stub(installerStep7Controller, 'checkHostOverrideInstaller', Em.K);
  892. sinon.stub(installerStep7Controller, 'activateSpecialConfigs', Em.K);
  893. sinon.stub(installerStep7Controller, 'selectProperService', Em.K);
  894. sinon.stub(App.router, 'send', Em.K);
  895. });
  896. afterEach(function () {
  897. App.config.mergePreDefinedWithStored.restore();
  898. App.config.addAdvancedConfigs.restore();
  899. App.config.addCustomConfigs.restore();
  900. App.config.fileConfigsIntoTextarea.restore();
  901. installerStep7Controller.clearStep.restore();
  902. installerStep7Controller.getConfigTags.restore();
  903. installerStep7Controller.setInstalledServiceConfigs.restore();
  904. installerStep7Controller.resolveServiceDependencyConfigs.restore();
  905. installerStep7Controller.setStepConfigs.restore();
  906. installerStep7Controller.checkHostOverrideInstaller.restore();
  907. installerStep7Controller.activateSpecialConfigs.restore();
  908. installerStep7Controller.selectProperService.restore();
  909. App.router.send.restore();
  910. });
  911. it('should call clearStep', function () {
  912. installerStep7Controller.loadStep();
  913. expect(installerStep7Controller.clearStep.calledOnce).to.equal(true);
  914. });
  915. it('shouldn\'t do nothing if isAdvancedConfigLoaded is false', function () {
  916. installerStep7Controller.set('isAdvancedConfigLoaded', false);
  917. installerStep7Controller.loadStep();
  918. expect(installerStep7Controller.clearStep.called).to.equal(false);
  919. });
  920. it('should use App.config to map configs', function () {
  921. installerStep7Controller.loadStep();
  922. expect(App.config.mergePreDefinedWithStored.calledOnce).to.equal(true);
  923. expect(App.config.addAdvancedConfigs.calledOnce).to.equal(true);
  924. expect(App.config.addCustomConfigs.calledOnce).to.equal(true);
  925. });
  926. Em.A([
  927. {
  928. allSelectedServiceNames: ['YARN'],
  929. capacitySchedulerUi: false,
  930. e: true
  931. },
  932. {
  933. allSelectedServiceNames: ['YARN'],
  934. capacitySchedulerUi: true,
  935. e: false
  936. },
  937. {
  938. allSelectedServiceNames: ['HDFS'],
  939. capacitySchedulerUi: false,
  940. e: false
  941. },
  942. {
  943. allSelectedServiceNames: ['HDFS'],
  944. capacitySchedulerUi: true,
  945. e: false
  946. }
  947. ]).forEach(function (test) {
  948. it('allSelectedServiceNames = ' + JSON.stringify(test.allSelectedServiceNames) + ', capacitySchedulerUi = ' + test.capacitySchedulerUi.toString(), function () {
  949. sinon.stub(App, 'get', function (k) {
  950. if (k === 'supports.capacitySchedulerUi') return test.capacitySchedulerUi;
  951. return Em.get(App, k);
  952. });
  953. installerStep7Controller.reopen({allSelectedServiceNames: test.allSelectedServiceNames});
  954. installerStep7Controller.loadStep();
  955. if (test.e) {
  956. expect(App.config.fileConfigsIntoTextarea.calledOnce).to.equal(true);
  957. }
  958. else {
  959. expect(App.config.fileConfigsIntoTextarea.called).to.equal(false);
  960. }
  961. App.get.restore();
  962. });
  963. });
  964. it('should call setInstalledServiceConfigs for addServiceController', function () {
  965. installerStep7Controller.set('wizardController.name', 'addServiceController');
  966. installerStep7Controller.loadStep();
  967. expect(installerStep7Controller.setInstalledServiceConfigs.calledOnce).to.equal(true);
  968. });
  969. Em.A([
  970. {
  971. allSelectedServiceNames: ['STORM'],
  972. installedServiceNames: ['STORM'],
  973. m: 'allSelectedServiceNames contains STORM, installedServiceNames contains STORM',
  974. e: true
  975. },
  976. {
  977. allSelectedServiceNames: [],
  978. installedServiceNames: ['STORM'],
  979. m: 'allSelectedServiceNames doesn\'t contain STORM, installedServiceNames contains STORM',
  980. e: true
  981. },
  982. {
  983. allSelectedServiceNames: ['STORM'],
  984. installedServiceNames: [],
  985. m: 'allSelectedServiceNames contains STORM, installedServiceNames doesn\'t contain STORM',
  986. e: true
  987. },
  988. {
  989. allSelectedServiceNames: [],
  990. installedServiceNames: [],
  991. m: 'allSelectedServiceNames doesn\'t contain STORM, installedServiceNames doesn\'t contain STORM',
  992. e: false
  993. }
  994. ]).forEach(function (test) {
  995. it(test.m, function () {
  996. installerStep7Controller.reopen({
  997. allSelectedServiceNames: test.allSelectedServiceNames,
  998. installedServiceNames: test.installedServiceNames
  999. });
  1000. installerStep7Controller.loadStep();
  1001. if (test.e) {
  1002. expect(installerStep7Controller.resolveServiceDependencyConfigs.calledOnce).to.equal(true);
  1003. }
  1004. else {
  1005. expect(installerStep7Controller.resolveServiceDependencyConfigs.called).to.equal(false);
  1006. }
  1007. });
  1008. });
  1009. it('should call setStepConfigs', function () {
  1010. installerStep7Controller.loadStep();
  1011. expect(installerStep7Controller.setStepConfigs.calledOnce).to.equal(true);
  1012. });
  1013. it('should call checkHostOverrideInstaller', function () {
  1014. installerStep7Controller.loadStep();
  1015. expect(installerStep7Controller.checkHostOverrideInstaller.calledOnce).to.equal(true);
  1016. });
  1017. it('should call activateSpecialConfigs', function () {
  1018. installerStep7Controller.loadStep();
  1019. expect(installerStep7Controller.activateSpecialConfigs.calledOnce).to.equal(true);
  1020. });
  1021. it('should call selectProperService', function () {
  1022. installerStep7Controller.loadStep();
  1023. expect(installerStep7Controller.selectProperService.calledOnce).to.equal(true);
  1024. });
  1025. Em.A([
  1026. {
  1027. m: 'should skip config step',
  1028. skipConfigStep: true,
  1029. e: true
  1030. },
  1031. {
  1032. m: 'shouldn\'t skip config step',
  1033. skipConfigStep: false,
  1034. e: false
  1035. }
  1036. ]).forEach(function (test) {
  1037. it(test.m, function () {
  1038. installerStep7Controller.set('content.skipConfigStep', test.skipConfigStep);
  1039. installerStep7Controller.loadStep();
  1040. if (test.e) {
  1041. expect(App.router.send.calledWith('next')).to.equal(true);
  1042. }
  1043. else {
  1044. expect(App.router.send.called).to.equal(false);
  1045. }
  1046. });
  1047. });
  1048. });
  1049. describe('#_updateValueForCheckBoxConfig', function () {
  1050. Em.A([
  1051. {
  1052. v: 'true',
  1053. e: true
  1054. },
  1055. {
  1056. v: 'false',
  1057. e: false
  1058. }
  1059. ]).forEach(function (test) {
  1060. it(test.v, function () {
  1061. var serviceConfigProperty = Em.Object.create({value: test.v});
  1062. installerStep7Controller._updateValueForCheckBoxConfig(serviceConfigProperty);
  1063. expect(serviceConfigProperty.get('value')).to.equal(test.e);
  1064. expect(serviceConfigProperty.get('defaultValue')).to.equal(test.e);
  1065. });
  1066. });
  1067. });
  1068. describe('#_updateIsEditableFlagForConfig', function () {
  1069. Em.A([
  1070. {
  1071. isAdmin: false,
  1072. isReconfigurable: false,
  1073. isHostsConfigsPage: true,
  1074. defaultGroupSelected: false,
  1075. m: 'false for non-admin users',
  1076. e: false
  1077. },
  1078. {
  1079. isAdmin: true,
  1080. isReconfigurable: false,
  1081. isHostsConfigsPage: true,
  1082. defaultGroupSelected: false,
  1083. m: 'false if defaultGroupSelected is false and isHostsConfigsPage is true',
  1084. e: false
  1085. },
  1086. {
  1087. isAdmin: true,
  1088. isReconfigurable: false,
  1089. isHostsConfigsPage: true,
  1090. defaultGroupSelected: true,
  1091. m: 'false if defaultGroupSelected is true and isHostsConfigsPage is true',
  1092. e: false
  1093. },
  1094. {
  1095. isAdmin: true,
  1096. isReconfigurable: false,
  1097. isHostsConfigsPage: false,
  1098. defaultGroupSelected: false,
  1099. m: 'false if defaultGroupSelected is false and isHostsConfigsPage is false',
  1100. e: false
  1101. },
  1102. {
  1103. isAdmin: true,
  1104. isReconfigurable: true,
  1105. isHostsConfigsPage: false,
  1106. defaultGroupSelected: true,
  1107. m: 'equal to isReconfigurable if defaultGroupSelected is true and isHostsConfigsPage is false',
  1108. e: true
  1109. }
  1110. ]).forEach(function (test) {
  1111. it(test.m, function () {
  1112. sinon.stub(App, 'get', function (k) {
  1113. if (k === 'isAdmin') return test.isAdmin;
  1114. return Em.get(App, k);
  1115. });
  1116. installerStep7Controller.reopen({isHostsConfigsPage: test.isHostsConfigsPage});
  1117. var serviceConfigProperty = Em.Object.create({
  1118. isReconfigurable: test.isReconfigurable
  1119. });
  1120. installerStep7Controller._updateIsEditableFlagForConfig(serviceConfigProperty, test.defaultGroupSelected);
  1121. App.get.restore();
  1122. expect(serviceConfigProperty.get('isEditable')).to.equal(test.e);
  1123. });
  1124. });
  1125. });
  1126. describe('#_updateOverridesForConfig', function () {
  1127. it('should set empty array', function () {
  1128. var serviceConfigProperty = Em.Object.create({
  1129. overrides: null
  1130. }), component = Em.Object.create();
  1131. installerStep7Controller._updateOverridesForConfig(serviceConfigProperty, component);
  1132. expect(serviceConfigProperty.get('overrides')).to.eql(Em.A([]));
  1133. });
  1134. it('host overrides not supported', function () {
  1135. var serviceConfigProperty = Em.Object.create({
  1136. overrides: [
  1137. {value: 'new value'}
  1138. ]
  1139. }), component = Em.Object.create({selectedConfigGroup: {isDefault: false}});
  1140. installerStep7Controller._updateOverridesForConfig(serviceConfigProperty, component);
  1141. expect(serviceConfigProperty.get('overrides').length).to.equal(1);
  1142. expect(serviceConfigProperty.get('overrides.firstObject.value')).to.equal('new value');
  1143. expect(serviceConfigProperty.get('overrides.firstObject.isOriginalSCP')).to.equal(false);
  1144. expect(serviceConfigProperty.get('overrides.firstObject.parentSCP')).to.eql(serviceConfigProperty);
  1145. });
  1146. it('host overrides supported', function () {
  1147. sinon.stub(App, 'get', function (k) {
  1148. if (k === 'supports.hostOverrides') return true;
  1149. return Em.get(App, k);
  1150. });
  1151. var serviceConfigProperty = Em.Object.create({
  1152. overrides: [
  1153. {value: 'new value', group: Em.Object.create({name: 'n1'})}
  1154. ]
  1155. }),
  1156. component = Em.Object.create({
  1157. selectedConfigGroup: {isDefault: true},
  1158. configGroups: Em.A([
  1159. Em.Object.create({name: 'n1', properties: []})
  1160. ])
  1161. });
  1162. installerStep7Controller._updateOverridesForConfig(serviceConfigProperty, component);
  1163. App.get.restore();
  1164. expect(serviceConfigProperty.get('overrides').length).to.equal(1);
  1165. expect(serviceConfigProperty.get('overrides.firstObject.value')).to.equal('new value');
  1166. expect(serviceConfigProperty.get('overrides.firstObject.isOriginalSCP')).to.equal(false);
  1167. expect(serviceConfigProperty.get('overrides.firstObject.parentSCP')).to.eql(serviceConfigProperty);
  1168. expect(component.get('configGroups.firstObject.properties').length).to.equal(1);
  1169. expect(component.get('configGroups.firstObject.properties.firstObject.isEditable')).to.equal(false);
  1170. expect(component.get('configGroups.firstObject.properties.firstObject.group')).to.be.object;
  1171. });
  1172. });
  1173. });