step7_test.js 47 KB

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