step7_test.js 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471
  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. content: Em.Object.create({
  83. controllerName: 'addServiceController',
  84. services: Em.A([
  85. Em.Object.create({
  86. isInstalled: true,
  87. serviceName: 'SQOOP'
  88. }),
  89. Em.Object.create({
  90. isInstalled: true,
  91. serviceName: 'HIVE'
  92. }),
  93. Em.Object.create({
  94. isInstalled: true,
  95. serviceName: 'HDFS'
  96. })
  97. ])
  98. }),
  99. e: ['HIVE', 'HDFS'],
  100. m: 'addServiceController with SQOOP'
  101. }
  102. ]);
  103. tests.forEach(function (test) {
  104. it(test.m, function () {
  105. installerStep7Controller.set('content', test.content);
  106. expect(installerStep7Controller.get('installedServiceNames')).to.include.members(test.e);
  107. expect(test.e).to.include.members(installerStep7Controller.get('installedServiceNames'));
  108. });
  109. });
  110. });
  111. describe('#isSubmitDisabled', function () {
  112. it('should be true if miscModalVisible', function () {
  113. installerStep7Controller.reopen({miscModalVisible: true});
  114. expect(installerStep7Controller.get('isSubmitDisabled')).to.equal(true);
  115. });
  116. it('should be true if some of stepConfigs has errors', function () {
  117. installerStep7Controller.reopen({
  118. miscModalVisible: false,
  119. stepConfigs: [
  120. {
  121. showConfig: true,
  122. errorCount: 1
  123. }
  124. ]
  125. });
  126. expect(installerStep7Controller.get('isSubmitDisabled')).to.equal(true);
  127. });
  128. it('should be false if all of stepConfigs don\'t have errors and miscModalVisible is false', function () {
  129. installerStep7Controller.reopen({
  130. miscModalVisible: false,
  131. stepConfigs: [
  132. {
  133. showConfig: true,
  134. errorCount: 0
  135. }
  136. ]
  137. });
  138. expect(installerStep7Controller.get('isSubmitDisabled')).to.equal(false);
  139. });
  140. });
  141. describe('#selectedServiceNames', function () {
  142. it('should use content.services as source of data', function () {
  143. installerStep7Controller.set('content', {
  144. services: [
  145. {isSelected: true, isInstalled: false, serviceName: 's1'},
  146. {isSelected: false, isInstalled: false, serviceName: 's2'},
  147. {isSelected: true, isInstalled: true, serviceName: 's3'},
  148. {isSelected: false, isInstalled: false, serviceName: 's4'},
  149. {isSelected: true, isInstalled: false, serviceName: 's5'},
  150. {isSelected: false, isInstalled: false, serviceName: 's6'},
  151. {isSelected: true, isInstalled: true, serviceName: 's7'},
  152. {isSelected: false, isInstalled: false, serviceName: 's8'}
  153. ]
  154. });
  155. var expected = ['s1', 's5'];
  156. expect(installerStep7Controller.get('selectedServiceNames')).to.eql(expected);
  157. });
  158. });
  159. describe('#allSelectedServiceNames', function () {
  160. it('should use content.services as source of data', function () {
  161. installerStep7Controller.set('content', {
  162. services: [
  163. {isSelected: true, isInstalled: false, serviceName: 's1'},
  164. {isSelected: false, isInstalled: false, serviceName: 's2'},
  165. {isSelected: true, isInstalled: true, serviceName: 's3'},
  166. {isSelected: false, isInstalled: false, serviceName: 's4'},
  167. {isSelected: true, isInstalled: false, serviceName: 's5'},
  168. {isSelected: false, isInstalled: false, serviceName: 's6'},
  169. {isSelected: true, isInstalled: true, serviceName: 's7'},
  170. {isSelected: false, isInstalled: false, serviceName: 's8'}
  171. ]
  172. });
  173. var expected = ['s1', 's3', 's5', 's7'];
  174. expect(installerStep7Controller.get('allSelectedServiceNames')).to.eql(expected);
  175. });
  176. });
  177. describe('#masterComponentHosts', function () {
  178. it('should be equal to content.masterComponentHosts', function () {
  179. var masterComponentHosts = [
  180. {},
  181. {},
  182. {}
  183. ];
  184. installerStep7Controller.reopen({content: {masterComponentHosts: masterComponentHosts}});
  185. expect(installerStep7Controller.get('masterComponentHosts')).to.eql(masterComponentHosts);
  186. });
  187. });
  188. describe('#slaveComponentHosts', function () {
  189. it('should be equal to content.slaveGroupProperties', function () {
  190. var slaveGroupProperties = [
  191. {},
  192. {},
  193. {}
  194. ];
  195. installerStep7Controller.reopen({content: {slaveGroupProperties: slaveGroupProperties}});
  196. expect(installerStep7Controller.get('slaveComponentHosts')).to.eql(slaveGroupProperties);
  197. });
  198. });
  199. describe('#clearStep', function () {
  200. it('should clear serviceConfigTags', function () {
  201. installerStep7Controller.set('serviceConfigTags', [
  202. {},
  203. {}
  204. ]);
  205. installerStep7Controller.clearStep();
  206. expect(installerStep7Controller.get('serviceConfigTags.length')).to.equal(0);
  207. });
  208. it('should clear stepConfigs', function () {
  209. installerStep7Controller.set('stepConfigs', [
  210. {},
  211. {}
  212. ]);
  213. installerStep7Controller.clearStep();
  214. expect(installerStep7Controller.get('stepConfigs.length')).to.equal(0);
  215. });
  216. it('should clear filter', function () {
  217. installerStep7Controller.set('filter', 'filter');
  218. installerStep7Controller.clearStep();
  219. expect(installerStep7Controller.get('filter')).to.equal('');
  220. });
  221. it('should set for each filterColumns "selected" false', function () {
  222. installerStep7Controller.set('filterColumns', [
  223. {selected: true},
  224. {selected: false},
  225. {selected: true}
  226. ]);
  227. installerStep7Controller.clearStep();
  228. expect(installerStep7Controller.get('filterColumns').everyProperty('selected', false)).to.equal(true);
  229. });
  230. });
  231. describe('#loadInstalledServicesConfigGroups', function () {
  232. before(function () {
  233. sinon.stub(App.ajax, 'send', Em.K);
  234. });
  235. after(function () {
  236. App.ajax.send.restore();
  237. });
  238. it('should do ajax request for each received service name', function () {
  239. var serviceNames = ['s1', 's2', 's3'];
  240. installerStep7Controller.loadInstalledServicesConfigGroups(serviceNames);
  241. expect(App.ajax.send.callCount).to.equal(serviceNames.length);
  242. });
  243. });
  244. describe('#getConfigTags', function () {
  245. before(function () {
  246. sinon.stub(App.ajax, 'send', Em.K);
  247. });
  248. after(function () {
  249. App.ajax.send.restore();
  250. });
  251. it('should do ajax-request', function () {
  252. installerStep7Controller.getConfigTags();
  253. expect(App.ajax.send.calledOnce).to.equal(true);
  254. });
  255. });
  256. describe('#setGroupsToDelete', function () {
  257. beforeEach(function () {
  258. installerStep7Controller.set('wizardController', Em.Object.create(App.LocalStorage, {name: 'tdk'}));
  259. });
  260. it('should add new groups to groupsToDelete', function () {
  261. var groupsToDelete = [
  262. {id: '1'},
  263. {id: '2'}
  264. ],
  265. groups = [
  266. Em.Object.create({id: '3'}),
  267. Em.Object.create(),
  268. Em.Object.create({id: '5'})
  269. ],
  270. expected = [
  271. {id: "1"},
  272. {id: "2"},
  273. {id: "3"},
  274. {id: "5"}
  275. ];
  276. installerStep7Controller.set('groupsToDelete', groupsToDelete);
  277. installerStep7Controller.setGroupsToDelete(groups);
  278. expect(installerStep7Controller.get('groupsToDelete')).to.eql(expected);
  279. expect(installerStep7Controller.get('wizardController').getDBProperty('groupsToDelete')).to.eql(expected);
  280. });
  281. });
  282. describe('#selectConfigGroup', function () {
  283. beforeEach(function () {
  284. installerStep7Controller.reopen({content: {services: []}});
  285. sinon.stub(installerStep7Controller, 'switchConfigGroupConfigs', Em.K);
  286. });
  287. afterEach(function () {
  288. installerStep7Controller.switchConfigGroupConfigs.restore();
  289. });
  290. it('should set selectedConfigGroup', function () {
  291. var group = {':': []};
  292. installerStep7Controller.selectConfigGroup({context: group});
  293. expect(installerStep7Controller.get('selectedConfigGroup')).to.eql(group);
  294. });
  295. });
  296. describe('#submit', function () {
  297. beforeEach(function () {
  298. sinon.stub(App.router, 'send', Em.K);
  299. });
  300. afterEach(function () {
  301. App.router.send.restore();
  302. });
  303. it('should proceed if submit is not disabled', function () {
  304. installerStep7Controller.reopen({isSubmitDisabled: false});
  305. installerStep7Controller.submit();
  306. expect(App.router.send.calledOnce).to.equal(true);
  307. });
  308. it('should not proceed if submit is disabled', function () {
  309. installerStep7Controller.reopen({isSubmitDisabled: true});
  310. installerStep7Controller.submit();
  311. expect(App.router.send.called).to.equal(false);
  312. });
  313. });
  314. describe('#addOverrideProperty', function () {
  315. it('should add override property', function () {
  316. var groupName = 'groupName',
  317. selectedService = {configGroups: [Em.Object.create({name: groupName, properties: []})]},
  318. selectedConfigGroup = {name: groupName},
  319. serviceConfigProperty = Em.Object.create({overrides: []}),
  320. expected = Em.Object.create({
  321. value: '',
  322. isOriginalSCP: false,
  323. isEditable: true
  324. });
  325. installerStep7Controller.reopen({selectedService: selectedService, selectedConfigGroup: selectedConfigGroup});
  326. var newSCP = installerStep7Controller.addOverrideProperty(serviceConfigProperty);
  327. Em.keys(expected).forEach(function (k) {
  328. expect(newSCP.get(k)).to.equal(expected.get(k));
  329. });
  330. var group = installerStep7Controller.get('selectedService.configGroups').findProperty('name', groupName);
  331. expect(newSCP.get('group')).to.eql(group);
  332. expect(newSCP.get('parentSCP')).to.eql(serviceConfigProperty);
  333. expect(group.get('properties.length')).to.equal(1);
  334. });
  335. });
  336. describe('#getConfigTagsSuccess', function () {
  337. it('should update serviceConfigTags', function () {
  338. var installedServiceNames = ['s1', 's2'],
  339. serviceConfigsData = [
  340. {serviceName: 's1', sites: ['s1-site', 's1-log']},
  341. {serviceName: 's2', sites: ['s2-site', 'core-site']},
  342. {serviceName: 's3', sites: ['s3-site']}
  343. ],
  344. data = {
  345. Clusters: {
  346. desired_configs: {
  347. "core-site": {
  348. "user": "admin",
  349. "tag": "version1398780546992"
  350. },
  351. "global": {
  352. "user": "admin",
  353. "tag": "version1398780546992"
  354. },
  355. "s1-site": {
  356. "user": "admin",
  357. "tag": "version1"
  358. },
  359. "s1-log": {
  360. "user": "admin",
  361. "tag": "version1"
  362. },
  363. "s2-site": {
  364. "user": "admin",
  365. "tag": "version1"
  366. },
  367. "s3-site": {
  368. "user": "admin",
  369. "tag": "version1"
  370. }
  371. }
  372. }
  373. },
  374. serviceConfigTags = [
  375. {siteName: 'core-site', tagName: 'version1398780546992', newTagName: null},
  376. {siteName: 's1-site', tagName: 'version1', newTagName: null},
  377. {siteName: 's1-log', tagName: 'version1', newTagName: null},
  378. {siteName: 's2-site', tagName: 'version1', newTagName: null}
  379. ];
  380. installerStep7Controller.reopen({serviceConfigsData: serviceConfigsData, installedServiceNames: installedServiceNames});
  381. installerStep7Controller.getConfigTagsSuccess(data);
  382. expect(installerStep7Controller.get('serviceConfigTags')).to.eql(serviceConfigTags);
  383. });
  384. });
  385. describe('#resolveStormConfigs', function () {
  386. beforeEach(function () {
  387. installerStep7Controller.reopen({
  388. content: {services: []},
  389. wizardController: Em.Object.create({
  390. getDBProperty: function () {
  391. return [
  392. {component: 'GANGLIA_SERVER', hostName: 'h1'}
  393. ];
  394. }
  395. })
  396. });
  397. });
  398. it('shouldn\'t do nothing if Ganglia and Storm are installed', function () {
  399. var installedServiceNames = ['GANGLIA', 'STORM'],
  400. configs = [
  401. {name: 'nimbus.childopts', value: '.jar=host=', defaultValue: ''},
  402. {name: 'supervisor.childopts', value: '.jar=host=', defaultValue: ''},
  403. {name: 'worker.childopts', value: '.jar=host=', defaultValue: ''}
  404. ],
  405. expected = [
  406. {name: 'nimbus.childopts', value: '.jar=host=', defaultValue: ''},
  407. {name: 'supervisor.childopts', value: '.jar=host=', defaultValue: ''},
  408. {name: 'worker.childopts', value: '.jar=host=', defaultValue: ''}
  409. ];
  410. installerStep7Controller.reopen({installedServiceNames: installedServiceNames});
  411. installerStep7Controller.resolveStormConfigs(configs);
  412. expect(configs).to.eql(expected);
  413. });
  414. it('shouldn\'t do nothing if Ganglia is in allSelectedServiceNames', function () {
  415. var allSelectedServiceNames = ['GANGLIA'],
  416. configs = [
  417. {name: 'nimbus.childopts', value: '.jar=host=', defaultValue: ''},
  418. {name: 'supervisor.childopts', value: '.jar=host=', defaultValue: ''},
  419. {name: 'worker.childopts', value: '.jar=host=', defaultValue: ''}
  420. ],
  421. expected = [
  422. {name: 'nimbus.childopts', value: '.jar=host=h1', defaultValue: '.jar=host=h1', forceUpdate: true},
  423. {name: 'supervisor.childopts', value: '.jar=host=h1', defaultValue: '.jar=host=h1', forceUpdate: true},
  424. {name: 'worker.childopts', value: '.jar=host=h1', defaultValue: '.jar=host=h1', forceUpdate: true}
  425. ];
  426. installerStep7Controller.reopen({allSelectedServiceNames: allSelectedServiceNames});
  427. installerStep7Controller.resolveStormConfigs(configs);
  428. Em.keys(expected[0]).forEach(function (k) {
  429. expect(configs.mapProperty(k)).to.eql(expected.mapProperty(k));
  430. });
  431. });
  432. it('shouldn\'t do nothing if Ganglia is in installedServiceNames', function () {
  433. var installedServiceNames = ['GANGLIA'],
  434. configs = [
  435. {name: 'nimbus.childopts', value: '.jar=host=', defaultValue: ''},
  436. {name: 'supervisor.childopts', value: '.jar=host=', defaultValue: ''},
  437. {name: 'worker.childopts', value: '.jar=host=', defaultValue: ''}
  438. ],
  439. expected = [
  440. {name: 'nimbus.childopts', value: '.jar=host=h1', defaultValue: '.jar=host=h1', forceUpdate: true},
  441. {name: 'supervisor.childopts', value: '.jar=host=h1', defaultValue: '.jar=host=h1', forceUpdate: true},
  442. {name: 'worker.childopts', value: '.jar=host=h1', defaultValue: '.jar=host=h1', forceUpdate: true}
  443. ];
  444. installerStep7Controller.reopen({installedServiceNames: installedServiceNames});
  445. installerStep7Controller.resolveStormConfigs(configs);
  446. Em.keys(expected[0]).forEach(function (k) {
  447. expect(configs.mapProperty(k)).to.eql(expected.mapProperty(k));
  448. });
  449. });
  450. });
  451. describe('#resolveServiceDependencyConfigs', function () {
  452. beforeEach(function () {
  453. sinon.stub(installerStep7Controller, 'resolveStormConfigs', Em.K);
  454. });
  455. afterEach(function () {
  456. installerStep7Controller.resolveStormConfigs.restore();
  457. });
  458. it('should call resolveStormConfigs if serviceName is STORM', function () {
  459. var serviceName = 'STORM', configs = [
  460. {},
  461. {},
  462. {}
  463. ];
  464. installerStep7Controller.resolveServiceDependencyConfigs(serviceName, configs);
  465. expect(installerStep7Controller.resolveStormConfigs.calledWith(configs)).to.equal(true);
  466. });
  467. });
  468. describe('#selectedServiceObserver', function () {
  469. beforeEach(function () {
  470. installerStep7Controller.reopen({content: {services: []}});
  471. sinon.stub(installerStep7Controller, 'switchConfigGroupConfigs', Em.K);
  472. });
  473. afterEach(function () {
  474. installerStep7Controller.switchConfigGroupConfigs.restore();
  475. });
  476. it('shouldn\'t do nothing if App.supports.hostOverridesInstaller is false', function () {
  477. App.set('supports.hostOverridesInstaller', false);
  478. var configGroups = [
  479. {},
  480. {}
  481. ],
  482. selectedConfigGroup = {};
  483. installerStep7Controller.reopen({configGroups: configGroups, selectedConfigGroup: selectedConfigGroup});
  484. installerStep7Controller.selectedServiceObserver();
  485. expect(installerStep7Controller.get('configGroups')).to.eql(configGroups);
  486. expect(installerStep7Controller.get('selectedConfigGroup')).to.eql(selectedConfigGroup);
  487. });
  488. it('shouldn\'t do nothing if selectedService is null', function () {
  489. App.set('supports.hostOverridesInstaller', true);
  490. var configGroups = [
  491. {},
  492. {}
  493. ],
  494. selectedConfigGroup = {};
  495. installerStep7Controller.reopen({selectedService: null, configGroups: configGroups, selectedConfigGroup: selectedConfigGroup});
  496. installerStep7Controller.selectedServiceObserver();
  497. expect(installerStep7Controller.get('configGroups')).to.eql(configGroups);
  498. expect(installerStep7Controller.get('selectedConfigGroup')).to.eql(selectedConfigGroup);
  499. });
  500. it('shouldn\'t do nothing if selectedService.serviceName is MISC', function () {
  501. App.set('supports.hostOverridesInstaller', true);
  502. var configGroups = [
  503. {},
  504. {}
  505. ],
  506. selectedConfigGroup = {};
  507. installerStep7Controller.reopen({selectedService: {serviceName: 'MISC'}, configGroups: configGroups, selectedConfigGroup: selectedConfigGroup});
  508. installerStep7Controller.selectedServiceObserver();
  509. expect(installerStep7Controller.get('configGroups')).to.eql(configGroups);
  510. expect(installerStep7Controller.get('selectedConfigGroup')).to.eql(selectedConfigGroup);
  511. });
  512. it('should update configGroups and selectedConfigGroup', function () {
  513. App.set('supports.hostOverridesInstaller', true);
  514. var defaultGroup = {isDefault: true, n: 'n2'},
  515. configGroups = [
  516. {isDefault: false, n: 'n1'},
  517. defaultGroup,
  518. {n: 'n3'}
  519. ],
  520. selectedConfigGroup = {};
  521. installerStep7Controller.reopen({selectedService: {serviceName: 's1', configGroups: configGroups}});
  522. installerStep7Controller.selectedServiceObserver();
  523. expect(installerStep7Controller.get('configGroups').mapProperty('n')).to.eql(['n2', 'n1', 'n3']);
  524. expect(installerStep7Controller.get('selectedConfigGroup')).to.eql(defaultGroup);
  525. });
  526. });
  527. describe('#loadConfigGroups', function () {
  528. beforeEach(function () {
  529. installerStep7Controller.reopen({
  530. wizardController: Em.Object.create({
  531. allHosts: [
  532. {hostName: 'h1'},
  533. {hostName: 'h2'},
  534. {hostName: 'h3'}
  535. ]
  536. })
  537. });
  538. });
  539. it('shouldn\'t do nothing if only MISC available', function () {
  540. var configGroups = [
  541. {}
  542. ];
  543. installerStep7Controller.reopen({
  544. stepConfigs: [Em.Object.create({serviceName: 'MISC', configGroups: configGroups})]
  545. });
  546. installerStep7Controller.loadConfigGroups([]);
  547. expect(installerStep7Controller.get('stepConfigs.firstObject.configGroups')).to.eql(configGroups);
  548. });
  549. it('should set configGroups for service if they don\'t exist', function () {
  550. var configGroups = [],
  551. serviceName = 'HDFS',
  552. serviceConfigGroups = [
  553. {service: {id: 's1'}}
  554. ];
  555. installerStep7Controller.reopen({
  556. stepConfigs: [Em.Object.create({serviceName: serviceName, configGroups: configGroups})]
  557. });
  558. installerStep7Controller.loadConfigGroups(serviceConfigGroups);
  559. expect(installerStep7Controller.get('stepConfigs.firstObject.configGroups.length')).to.equal(1);
  560. var group = installerStep7Controller.get('stepConfigs.firstObject.configGroups.firstObject');
  561. expect(group.get('name')).to.equal(serviceName + ' Default');
  562. expect(group.get('description').contains(serviceName)).to.equal(true);
  563. expect(group.get('isDefault')).to.equal(true);
  564. expect(group.get('hosts')).to.eql(['h1', 'h2', 'h3']);
  565. expect(group.get('service.id')).to.equal(serviceName);
  566. expect(group.get('serviceName')).to.equal(serviceName);
  567. });
  568. it('should update configGroups for service (only default group)', function () {
  569. var configGroups = [],
  570. serviceName = 'HDFS',
  571. serviceConfigGroups = [
  572. {service: {id: 'HDFS'}, isDefault: true, n: 'n1'}
  573. ];
  574. installerStep7Controller.reopen({
  575. stepConfigs: [Em.Object.create({serviceName: serviceName, configGroups: configGroups})]
  576. });
  577. installerStep7Controller.loadConfigGroups(serviceConfigGroups);
  578. expect(installerStep7Controller.get('stepConfigs.firstObject.configGroups').findProperty('isDefault').get('n')).to.equal('n1');
  579. });
  580. it('should update configGroups for service', function () {
  581. var configGroups = [],
  582. serviceName = 'HDFS',
  583. serviceConfigGroups = [
  584. {service: {id: 'HDFS'}, properties: [
  585. {},
  586. {}
  587. ], isDefault: true, n: 'n1'},
  588. {service: {id: 'HDFS'}, properties: [
  589. {},
  590. {}
  591. ], isDefault: false, n: 'n2'}
  592. ];
  593. installerStep7Controller.reopen({
  594. stepConfigs: [Em.Object.create({serviceName: serviceName, configGroups: configGroups})]
  595. });
  596. installerStep7Controller.loadConfigGroups(serviceConfigGroups);
  597. expect(installerStep7Controller.get('stepConfigs.firstObject.configGroups.length')).to.equal(2);
  598. expect(installerStep7Controller.get('stepConfigs.firstObject.configGroups').findProperty('isDefault').get('n')).to.equal('n1');
  599. expect(installerStep7Controller.get('stepConfigs.firstObject.configGroups').findProperty('isDefault', false).get('properties').everyProperty('group.n', 'n2')).to.equal(true);
  600. expect(installerStep7Controller.get('stepConfigs.firstObject.configGroups').findProperty('isDefault', false).get('parentConfigGroup.n')).to.equal('n1');
  601. });
  602. });
  603. describe('#_getDisplayedConfigGroups', function () {
  604. it('should return [] if no selected group', function () {
  605. installerStep7Controller.reopen({
  606. content: {services: []},
  607. selectedConfigGroup: null
  608. });
  609. expect(installerStep7Controller._getDisplayedConfigGroups()).to.eql([]);
  610. });
  611. it('should return default config group if another selected', function () {
  612. var defaultGroup = Em.Object.create({isDefault: false});
  613. installerStep7Controller.reopen({
  614. content: {services: []},
  615. selectedConfigGroup: defaultGroup
  616. });
  617. expect(installerStep7Controller._getDisplayedConfigGroups()).to.eql([defaultGroup]);
  618. });
  619. it('should return other groups if default selected', function () {
  620. var defaultGroup = Em.Object.create({isDefault: true}),
  621. cfgG = Em.Object.create({isDefault: true}),
  622. configGroups = Em.A([
  623. Em.Object.create({isDefault: false}),
  624. Em.Object.create({isDefault: false}),
  625. cfgG,
  626. Em.Object.create({isDefault: false})
  627. ]);
  628. installerStep7Controller.reopen({
  629. content: {services: []},
  630. selectedConfigGroup: defaultGroup,
  631. selectedService: {configGroups: configGroups}
  632. });
  633. expect(installerStep7Controller._getDisplayedConfigGroups()).to.eql(configGroups.without(cfgG));
  634. });
  635. });
  636. describe('#_setEditableValue', function () {
  637. it('shouldn\'t update config if no selectedConfigGroup', function () {
  638. installerStep7Controller.reopen({
  639. selectedConfigGroup: null
  640. });
  641. var config = Em.Object.create({isEditable: null});
  642. var updatedConfig = installerStep7Controller._setEditableValue(config);
  643. expect(updatedConfig.get('isEditable')).to.be.null;
  644. });
  645. it('should set isEditable equal to selectedGroup.isDefault if service not installed', function () {
  646. var isDefault = true;
  647. installerStep7Controller.reopen({
  648. installedServiceNames: [],
  649. selectedService: {serviceName: 'abc'},
  650. selectedConfigGroup: Em.Object.create({isDefault: isDefault})
  651. });
  652. var config = Em.Object.create({isEditable: null});
  653. var updatedConfig = installerStep7Controller._setEditableValue(config);
  654. expect(updatedConfig.get('isEditable')).to.equal(isDefault);
  655. installerStep7Controller.toggleProperty('selectedConfigGroup.isDefault');
  656. updatedConfig = installerStep7Controller._setEditableValue(config);
  657. expect(updatedConfig.get('isEditable')).to.equal(!isDefault);
  658. });
  659. Em.A([
  660. {
  661. isEditable: false,
  662. isReconfigurable: false,
  663. isDefault: true,
  664. e: false
  665. },
  666. {
  667. isEditable: true,
  668. isReconfigurable: true,
  669. isDefault: true,
  670. e: true
  671. },
  672. {
  673. isEditable: false,
  674. isReconfigurable: true,
  675. isDefault: false,
  676. e: false
  677. },
  678. {
  679. isEditable: true,
  680. isReconfigurable: false,
  681. isDefault: false,
  682. e: false
  683. }
  684. ]).forEach(function (test) {
  685. it('service installed, isEditable = ' + test.isEditable.toString() + ', isReconfigurable = ' + test.isReconfigurable.toString(), function () {
  686. var config = Em.Object.create({
  687. isReconfigurable: test.isReconfigurable,
  688. isEditable: test.isEditable
  689. });
  690. installerStep7Controller.reopen({
  691. installedServiceNames: Em.A(['a']),
  692. selectedService: Em.Object.create({serviceName: 'a'}),
  693. selectedConfigGroup: Em.Object.create({isDefault: test.isDefault})
  694. });
  695. var updateConfig = installerStep7Controller._setEditableValue(config);
  696. expect(updateConfig.get('isEditable')).to.equal(test.e);
  697. });
  698. });
  699. });
  700. describe('#_setOverrides', function () {
  701. it('shouldn\'t update config if no selectedConfigGroup', function () {
  702. installerStep7Controller.reopen({
  703. selectedConfigGroup: null
  704. });
  705. var config = Em.Object.create({overrides: null});
  706. var updatedConfig = installerStep7Controller._setOverrides(config, []);
  707. expect(updatedConfig.get('overrides')).to.be.null;
  708. });
  709. it('no overrideToAdd', function () {
  710. var isDefault = true,
  711. name = 'n1',
  712. config = Em.Object.create({overrides: null, name: name, flag: 'flag'}),
  713. overrides = Em.A([
  714. Em.Object.create({name: name, value: 'v1'}),
  715. Em.Object.create({name: name, value: 'v2'}),
  716. Em.Object.create({name: 'n2', value: 'v3'})
  717. ]);
  718. installerStep7Controller.reopen({
  719. overrideToAdd: null,
  720. selectedConfigGroup: Em.Object.create({
  721. isDefault: isDefault
  722. })
  723. });
  724. var updatedConfig = installerStep7Controller._setOverrides(config, overrides);
  725. expect(updatedConfig.get('overrides.length')).to.equal(2);
  726. expect(updatedConfig.get('overrides').everyProperty('isEditable', !isDefault)).to.equal(true);
  727. expect(updatedConfig.get('overrides').everyProperty('parentSCP.flag', 'flag')).to.equal(true);
  728. });
  729. it('overrideToAdd exists', function () {
  730. var isDefault = true,
  731. name = 'n1',
  732. config = Em.Object.create({overrides: null, name: name, flag: 'flag'}),
  733. overrides = Em.A([
  734. Em.Object.create({name: name, value: 'v1'}),
  735. Em.Object.create({name: name, value: 'v2'}),
  736. Em.Object.create({name: 'n2', value: 'v3'})
  737. ]);
  738. installerStep7Controller.reopen({
  739. overrideToAdd: Em.Object.create({name: name}),
  740. selectedService: {configGroups: [Em.Object.create({name: 'n', properties: []})]},
  741. selectedConfigGroup: Em.Object.create({
  742. isDefault: isDefault,
  743. name: 'n'
  744. })
  745. });
  746. var updatedConfig = installerStep7Controller._setOverrides(config, overrides);
  747. expect(updatedConfig.get('overrides.length')).to.equal(3);
  748. expect(updatedConfig.get('overrides').everyProperty('isEditable', !isDefault)).to.equal(true);
  749. expect(updatedConfig.get('overrides').everyProperty('parentSCP.flag', 'flag')).to.equal(true);
  750. });
  751. });
  752. describe('#switchConfigGroupConfigs', function () {
  753. it('if selectedConfigGroup is null, serviceConfigs shouldn\'t be changed', function () {
  754. installerStep7Controller.reopen({
  755. selectedConfigGroup: null,
  756. content: {services: []},
  757. serviceConfigs: {configs: [
  758. {overrides: []},
  759. {overrides: []}
  760. ]}
  761. });
  762. installerStep7Controller.switchConfigGroupConfigs();
  763. expect(installerStep7Controller.get('serviceConfigs.configs').everyProperty('overrides.length', 0)).to.equal(true);
  764. });
  765. it('should set configs for serviceConfigs', function () {
  766. var configGroups = [
  767. Em.Object.create({
  768. properties: [
  769. {name: 'g1', value: 'v1'},
  770. {name: 'g2', value: 'v2'}
  771. ]
  772. })
  773. ];
  774. sinon.stub(installerStep7Controller, '_getDisplayedConfigGroups', function () {
  775. return configGroups;
  776. });
  777. sinon.stub(installerStep7Controller, '_setEditableValue', function (config) {
  778. config.set('isEditable', true);
  779. return config;
  780. });
  781. installerStep7Controller.reopen({
  782. selectedConfigGroup: Em.Object.create({isDefault: true, name: 'g1'}),
  783. content: {services: []},
  784. selectedService: {configs: Em.A([Em.Object.create({name: 'g1', overrides: [], properties: []}), Em.Object.create({name: 'g2', overrides: []})])},
  785. serviceConfigs: {configs: [Em.Object.create({name: 'g1'})]}
  786. });
  787. installerStep7Controller.switchConfigGroupConfigs();
  788. var configs = installerStep7Controller.get('selectedService.configs');
  789. expect(configs.findProperty('name', 'g1').get('overrides').length).to.equal(1);
  790. expect(configs.findProperty('name', 'g2').get('overrides').length).to.equal(1);
  791. expect(configs.everyProperty('isEditable', true)).to.equal(true);
  792. installerStep7Controller._getDisplayedConfigGroups.restore();
  793. installerStep7Controller._setEditableValue.restore();
  794. });
  795. });
  796. describe('#selectProperService', function () {
  797. Em.A([
  798. {
  799. name: 'addServiceController',
  800. stepConfigs: [
  801. {selected: false, name: 'n1'},
  802. {selected: true, name: 'n2'},
  803. {selected: true, name: 'n3'}
  804. ],
  805. e: 'n2'
  806. },
  807. {
  808. name: 'installerController',
  809. stepConfigs: [
  810. {showConfig: false, name: 'n1'},
  811. {showConfig: false, name: 'n2'},
  812. {showConfig: true, name: 'n3'}
  813. ],
  814. e: 'n3'
  815. }
  816. ]).forEach(function (test) {
  817. it(test.name, function () {
  818. sinon.stub(installerStep7Controller, 'selectedServiceObserver', Em.K);
  819. installerStep7Controller.reopen({
  820. wizardController: Em.Object.create({
  821. name: test.name
  822. }),
  823. stepConfigs: test.stepConfigs
  824. });
  825. installerStep7Controller.selectProperService();
  826. expect(installerStep7Controller.get('selectedService.name')).to.equal(test.e);
  827. installerStep7Controller.selectedServiceObserver.restore();
  828. });
  829. });
  830. });
  831. describe('#setStepConfigs', function () {
  832. beforeEach(function () {
  833. installerStep7Controller.reopen({
  834. content: {services: []},
  835. wizardController: Em.Object.create({
  836. getDBProperty: function (key) {
  837. return this.get(key);
  838. }
  839. })
  840. });
  841. });
  842. afterEach(function () {
  843. App.config.renderConfigs.restore();
  844. });
  845. it('if wizard isn\'t addService, should set output of App.config.renderConfigs', function () {
  846. var serviceConfigs = Em.A([
  847. {},
  848. {}
  849. ]);
  850. sinon.stub(App.config, 'renderConfigs', function () {
  851. return serviceConfigs;
  852. });
  853. installerStep7Controller.set('wizardController.name', 'installerController');
  854. installerStep7Controller.setStepConfigs([], []);
  855. expect(installerStep7Controller.get('stepConfigs')).to.eql(serviceConfigs);
  856. });
  857. it('addServiceWizard used', function () {
  858. var serviceConfigs = Em.A([Em.Object.create({serviceName: 's1'}), Em.Object.create({serviceName: 's2'})]);
  859. installerStep7Controller.set('wizardController.name', 'addServiceController');
  860. installerStep7Controller.reopen({selectedServiceNames: ['s2']});
  861. sinon.stub(App.config, 'renderConfigs', function () {
  862. return serviceConfigs;
  863. });
  864. installerStep7Controller.setStepConfigs([], []);
  865. expect(installerStep7Controller.get('stepConfigs').everyProperty('showConfig', true)).to.equal(true);
  866. expect(installerStep7Controller.get('stepConfigs').findProperty('serviceName', 's2').get('selected')).to.equal(true);
  867. });
  868. it('addServiceWizard used, HA enabled', function () {
  869. sinon.stub(App, 'get', function (k) {
  870. if (k === 'isHaEnabled') {
  871. return true;
  872. }
  873. return Em.get(App, k);
  874. });
  875. var serviceConfigs = Em.A([
  876. Em.Object.create({
  877. serviceName: 'HDFS',
  878. configs: [
  879. {category: 'SNameNode'},
  880. {category: 'SNameNode'},
  881. {category: 'NameNode'},
  882. {category: 'NameNode'},
  883. {category: 'SNameNode'}
  884. ]
  885. }),
  886. Em.Object.create({serviceName: 's2'})]
  887. );
  888. installerStep7Controller.set('wizardController.name', 'addServiceController');
  889. installerStep7Controller.reopen({selectedServiceNames: ['HDFS', 's2']});
  890. sinon.stub(App.config, 'renderConfigs', function () {
  891. return serviceConfigs;
  892. });
  893. installerStep7Controller.setStepConfigs([], []);
  894. expect(installerStep7Controller.get('stepConfigs').everyProperty('showConfig', true)).to.equal(true);
  895. expect(installerStep7Controller.get('stepConfigs').findProperty('serviceName', 'HDFS').get('selected')).to.equal(true);
  896. expect(installerStep7Controller.get('stepConfigs').findProperty('serviceName', 'HDFS').get('configs').length).to.equal(2);
  897. App.get.restore();
  898. });
  899. });
  900. describe('#checkHostOverrideInstaller', function () {
  901. beforeEach(function () {
  902. sinon.stub(installerStep7Controller, 'loadConfigGroups', Em.K);
  903. sinon.stub(installerStep7Controller, 'loadInstalledServicesConfigGroups', Em.K);
  904. });
  905. afterEach(function () {
  906. installerStep7Controller.loadConfigGroups.restore();
  907. installerStep7Controller.loadInstalledServicesConfigGroups.restore();
  908. App.get.restore();
  909. });
  910. Em.A([
  911. {
  912. hostOverridesInstaller: false,
  913. installedServiceNames: [],
  914. m: 'hostOverridesInstaller is false, installedServiceNames is empty',
  915. e: {
  916. loadConfigGroups: false,
  917. loadInstalledServicesConfigGroups: false
  918. }
  919. },
  920. {
  921. hostOverridesInstaller: false,
  922. installedServiceNames: ['s1', 's2'],
  923. m: 'hostOverridesInstaller is false, installedServiceNames is n\'t empty',
  924. e: {
  925. loadConfigGroups: false,
  926. loadInstalledServicesConfigGroups: false
  927. }
  928. },
  929. {
  930. hostOverridesInstaller: true,
  931. installedServiceNames: [],
  932. m: 'hostOverridesInstaller is true, installedServiceNames is empty',
  933. e: {
  934. loadConfigGroups: true,
  935. loadInstalledServicesConfigGroups: false
  936. }
  937. },
  938. {
  939. hostOverridesInstaller: true,
  940. installedServiceNames: ['s1', 's2', 's3'],
  941. m: 'hostOverridesInstaller is true, installedServiceNames isn\'t empty',
  942. e: {
  943. loadConfigGroups: true,
  944. loadInstalledServicesConfigGroups: true
  945. }
  946. }
  947. ]).forEach(function (test) {
  948. it(test.m, function () {
  949. sinon.stub(App, 'get', function (k) {
  950. if (k === 'supports.hostOverridesInstaller') return test.hostOverridesInstaller;
  951. return Em.get(App, k);
  952. });
  953. installerStep7Controller.reopen({installedServiceNames: test.installedServiceNames});
  954. installerStep7Controller.checkHostOverrideInstaller();
  955. if (test.e.loadConfigGroups) {
  956. expect(installerStep7Controller.loadConfigGroups.calledOnce).to.equal(true);
  957. }
  958. else {
  959. expect(installerStep7Controller.loadConfigGroups.called).to.equal(false);
  960. }
  961. if (test.e.loadInstalledServicesConfigGroups) {
  962. expect(installerStep7Controller.loadInstalledServicesConfigGroups.calledOnce).to.equal(true);
  963. }
  964. else {
  965. expect(installerStep7Controller.loadInstalledServicesConfigGroups.called).to.equal(false);
  966. }
  967. });
  968. });
  969. });
  970. describe('#loadStep', function () {
  971. beforeEach(function () {
  972. installerStep7Controller.reopen({
  973. content: {services: []},
  974. wizardController: Em.Object.create({
  975. getDBProperty: function (k) {
  976. return this.get(k);
  977. }
  978. })
  979. });
  980. sinon.stub(App.config, 'mergePreDefinedWithStored', Em.K);
  981. sinon.stub(App.config, 'addAdvancedConfigs', Em.K);
  982. sinon.stub(App.config, 'addCustomConfigs', Em.K);
  983. sinon.stub(App.config, 'fileConfigsIntoTextarea', Em.K);
  984. sinon.stub(installerStep7Controller, 'clearStep', Em.K);
  985. sinon.stub(installerStep7Controller, 'getConfigTags', Em.K);
  986. sinon.stub(installerStep7Controller, 'setInstalledServiceConfigs', Em.K);
  987. sinon.stub(installerStep7Controller, 'resolveServiceDependencyConfigs', Em.K);
  988. sinon.stub(installerStep7Controller, 'setStepConfigs', Em.K);
  989. sinon.stub(installerStep7Controller, 'checkHostOverrideInstaller', Em.K);
  990. sinon.stub(installerStep7Controller, 'activateSpecialConfigs', Em.K);
  991. sinon.stub(installerStep7Controller, 'selectProperService', Em.K);
  992. sinon.stub(App.router, 'send', Em.K);
  993. });
  994. afterEach(function () {
  995. App.config.mergePreDefinedWithStored.restore();
  996. App.config.addAdvancedConfigs.restore();
  997. App.config.addCustomConfigs.restore();
  998. App.config.fileConfigsIntoTextarea.restore();
  999. installerStep7Controller.clearStep.restore();
  1000. installerStep7Controller.getConfigTags.restore();
  1001. installerStep7Controller.setInstalledServiceConfigs.restore();
  1002. installerStep7Controller.resolveServiceDependencyConfigs.restore();
  1003. installerStep7Controller.setStepConfigs.restore();
  1004. installerStep7Controller.checkHostOverrideInstaller.restore();
  1005. installerStep7Controller.activateSpecialConfigs.restore();
  1006. installerStep7Controller.selectProperService.restore();
  1007. App.router.send.restore();
  1008. });
  1009. it('should call clearStep', function () {
  1010. installerStep7Controller.loadStep();
  1011. expect(installerStep7Controller.clearStep.calledOnce).to.equal(true);
  1012. });
  1013. it('shouldn\'t do nothing if isAdvancedConfigLoaded is false', function () {
  1014. installerStep7Controller.set('isAdvancedConfigLoaded', false);
  1015. installerStep7Controller.loadStep();
  1016. expect(installerStep7Controller.clearStep.called).to.equal(false);
  1017. });
  1018. it('should use App.config to map configs', function () {
  1019. installerStep7Controller.loadStep();
  1020. expect(App.config.mergePreDefinedWithStored.calledOnce).to.equal(true);
  1021. expect(App.config.addAdvancedConfigs.calledOnce).to.equal(true);
  1022. expect(App.config.addCustomConfigs.calledOnce).to.equal(true);
  1023. });
  1024. Em.A([
  1025. {
  1026. allSelectedServiceNames: ['YARN'],
  1027. capacitySchedulerUi: false,
  1028. e: true
  1029. },
  1030. {
  1031. allSelectedServiceNames: ['YARN'],
  1032. capacitySchedulerUi: true,
  1033. e: false
  1034. },
  1035. {
  1036. allSelectedServiceNames: ['HDFS'],
  1037. capacitySchedulerUi: false,
  1038. e: false
  1039. },
  1040. {
  1041. allSelectedServiceNames: ['HDFS'],
  1042. capacitySchedulerUi: true,
  1043. e: false
  1044. }
  1045. ]).forEach(function (test) {
  1046. it('allSelectedServiceNames = ' + JSON.stringify(test.allSelectedServiceNames) + ', capacitySchedulerUi = ' + test.capacitySchedulerUi.toString(), function () {
  1047. sinon.stub(App, 'get', function (k) {
  1048. if (k === 'supports.capacitySchedulerUi') return test.capacitySchedulerUi;
  1049. return Em.get(App, k);
  1050. });
  1051. installerStep7Controller.reopen({allSelectedServiceNames: test.allSelectedServiceNames});
  1052. installerStep7Controller.loadStep();
  1053. if (test.e) {
  1054. expect(App.config.fileConfigsIntoTextarea.calledOnce).to.equal(true);
  1055. }
  1056. else {
  1057. expect(App.config.fileConfigsIntoTextarea.called).to.equal(false);
  1058. }
  1059. App.get.restore();
  1060. });
  1061. });
  1062. it('should call getConfigTags, setInstalledServiceConfigs for addServiceController', function () {
  1063. installerStep7Controller.set('wizardController.name', 'addServiceController');
  1064. installerStep7Controller.loadStep();
  1065. expect(installerStep7Controller.getConfigTags.calledOnce).to.equal(true);
  1066. expect(installerStep7Controller.setInstalledServiceConfigs.calledOnce).to.equal(true);
  1067. });
  1068. Em.A([
  1069. {
  1070. allSelectedServiceNames: ['STORM'],
  1071. installedServiceNames: ['STORM'],
  1072. m: 'allSelectedServiceNames contains STORM, installedServiceNames contains STORM',
  1073. e: true
  1074. },
  1075. {
  1076. allSelectedServiceNames: [],
  1077. installedServiceNames: ['STORM'],
  1078. m: 'allSelectedServiceNames doesn\'t contain STORM, installedServiceNames contains STORM',
  1079. e: true
  1080. },
  1081. {
  1082. allSelectedServiceNames: ['STORM'],
  1083. installedServiceNames: [],
  1084. m: 'allSelectedServiceNames contains STORM, installedServiceNames doesn\'t contain STORM',
  1085. e: true
  1086. },
  1087. {
  1088. allSelectedServiceNames: [],
  1089. installedServiceNames: [],
  1090. m: 'allSelectedServiceNames doesn\'t contain STORM, installedServiceNames doesn\'t contain STORM',
  1091. e: false
  1092. }
  1093. ]).forEach(function (test) {
  1094. it(test.m, function () {
  1095. installerStep7Controller.reopen({
  1096. allSelectedServiceNames: test.allSelectedServiceNames,
  1097. installedServiceNames: test.installedServiceNames
  1098. });
  1099. installerStep7Controller.loadStep();
  1100. if (test.e) {
  1101. expect(installerStep7Controller.resolveServiceDependencyConfigs.calledOnce).to.equal(true);
  1102. }
  1103. else {
  1104. expect(installerStep7Controller.resolveServiceDependencyConfigs.called).to.equal(false);
  1105. }
  1106. });
  1107. });
  1108. it('should call setStepConfigs', function () {
  1109. installerStep7Controller.loadStep();
  1110. expect(installerStep7Controller.setStepConfigs.calledOnce).to.equal(true);
  1111. });
  1112. it('should call checkHostOverrideInstaller', function () {
  1113. installerStep7Controller.loadStep();
  1114. expect(installerStep7Controller.checkHostOverrideInstaller.calledOnce).to.equal(true);
  1115. });
  1116. it('should call activateSpecialConfigs', function () {
  1117. installerStep7Controller.loadStep();
  1118. expect(installerStep7Controller.activateSpecialConfigs.calledOnce).to.equal(true);
  1119. });
  1120. it('should call selectProperService', function () {
  1121. installerStep7Controller.loadStep();
  1122. expect(installerStep7Controller.selectProperService.calledOnce).to.equal(true);
  1123. });
  1124. Em.A([
  1125. {
  1126. m: 'should skip config step',
  1127. skipConfigStep: true,
  1128. e: true
  1129. },
  1130. {
  1131. m: 'shouldn\'t skip config step',
  1132. skipConfigStep: false,
  1133. e: false
  1134. }
  1135. ]).forEach(function (test) {
  1136. it(test.m, function () {
  1137. installerStep7Controller.set('content.skipConfigStep', test.skipConfigStep);
  1138. installerStep7Controller.loadStep();
  1139. if (test.e) {
  1140. expect(App.router.send.calledWith('next')).to.equal(true);
  1141. }
  1142. else {
  1143. expect(App.router.send.called).to.equal(false);
  1144. }
  1145. });
  1146. });
  1147. });
  1148. describe('#_updateValueForCheckBoxConfig', function () {
  1149. Em.A([
  1150. {
  1151. v: 'true',
  1152. e: true
  1153. },
  1154. {
  1155. v: 'false',
  1156. e: false
  1157. }
  1158. ]).forEach(function (test) {
  1159. it(test.v, function () {
  1160. var serviceConfigProperty = Em.Object.create({value: test.v});
  1161. installerStep7Controller._updateValueForCheckBoxConfig(serviceConfigProperty);
  1162. expect(serviceConfigProperty.get('value')).to.equal(test.e);
  1163. expect(serviceConfigProperty.get('defaultValue')).to.equal(test.e);
  1164. });
  1165. });
  1166. });
  1167. describe('#_updateIsEditableFlagForConfig', function () {
  1168. Em.A([
  1169. {
  1170. isAdmin: false,
  1171. isReconfigurable: false,
  1172. isHostsConfigsPage: true,
  1173. defaultGroupSelected: false,
  1174. m: 'false for non-admin users',
  1175. e: false
  1176. },
  1177. {
  1178. isAdmin: true,
  1179. isReconfigurable: false,
  1180. isHostsConfigsPage: true,
  1181. defaultGroupSelected: false,
  1182. m: 'false if defaultGroupSelected is false and isHostsConfigsPage is true',
  1183. e: false
  1184. },
  1185. {
  1186. isAdmin: true,
  1187. isReconfigurable: false,
  1188. isHostsConfigsPage: true,
  1189. defaultGroupSelected: true,
  1190. m: 'false if defaultGroupSelected is true and isHostsConfigsPage is true',
  1191. e: false
  1192. },
  1193. {
  1194. isAdmin: true,
  1195. isReconfigurable: false,
  1196. isHostsConfigsPage: false,
  1197. defaultGroupSelected: false,
  1198. m: 'false if defaultGroupSelected is false and isHostsConfigsPage is false',
  1199. e: false
  1200. },
  1201. {
  1202. isAdmin: true,
  1203. isReconfigurable: true,
  1204. isHostsConfigsPage: false,
  1205. defaultGroupSelected: true,
  1206. m: 'equal to isReconfigurable if defaultGroupSelected is true and isHostsConfigsPage is false',
  1207. e: true
  1208. }
  1209. ]).forEach(function (test) {
  1210. it(test.m, function () {
  1211. sinon.stub(App, 'get', function (k) {
  1212. if (k === 'isAdmin') return test.isAdmin;
  1213. return Em.get(App, k);
  1214. });
  1215. installerStep7Controller.reopen({isHostsConfigsPage: test.isHostsConfigsPage});
  1216. var serviceConfigProperty = Em.Object.create({
  1217. isReconfigurable: test.isReconfigurable
  1218. });
  1219. installerStep7Controller._updateIsEditableFlagForConfig(serviceConfigProperty, test.defaultGroupSelected);
  1220. App.get.restore();
  1221. expect(serviceConfigProperty.get('isEditable')).to.equal(test.e);
  1222. });
  1223. });
  1224. });
  1225. describe('#_updateOverridesForConfig', function () {
  1226. it('should set empty array', function () {
  1227. var serviceConfigProperty = Em.Object.create({
  1228. overrides: null
  1229. }), component = Em.Object.create();
  1230. installerStep7Controller._updateOverridesForConfig(serviceConfigProperty, component);
  1231. expect(serviceConfigProperty.get('overrides')).to.eql(Em.A([]));
  1232. });
  1233. it('host overrides not supported', function () {
  1234. var serviceConfigProperty = Em.Object.create({
  1235. overrides: [
  1236. {value: 'new value'}
  1237. ]
  1238. }), component = Em.Object.create({selectedConfigGroup: {isDefault: false}});
  1239. installerStep7Controller._updateOverridesForConfig(serviceConfigProperty, component);
  1240. expect(serviceConfigProperty.get('overrides').length).to.equal(1);
  1241. expect(serviceConfigProperty.get('overrides.firstObject.value')).to.equal('new value');
  1242. expect(serviceConfigProperty.get('overrides.firstObject.isOriginalSCP')).to.equal(false);
  1243. expect(serviceConfigProperty.get('overrides.firstObject.parentSCP')).to.eql(serviceConfigProperty);
  1244. });
  1245. it('host overrides supported', function () {
  1246. sinon.stub(App, 'get', function (k) {
  1247. if (k === 'supports.hostOverrides') return true;
  1248. return Em.get(App, k);
  1249. });
  1250. var serviceConfigProperty = Em.Object.create({
  1251. overrides: [
  1252. {value: 'new value', group: Em.Object.create({name: 'n1'})}
  1253. ]
  1254. }),
  1255. component = Em.Object.create({
  1256. selectedConfigGroup: {isDefault: true},
  1257. configGroups: Em.A([
  1258. Em.Object.create({name: 'n1', properties: []})
  1259. ])
  1260. });
  1261. installerStep7Controller._updateOverridesForConfig(serviceConfigProperty, component);
  1262. App.get.restore();
  1263. expect(serviceConfigProperty.get('overrides').length).to.equal(1);
  1264. expect(serviceConfigProperty.get('overrides.firstObject.value')).to.equal('new value');
  1265. expect(serviceConfigProperty.get('overrides.firstObject.isOriginalSCP')).to.equal(false);
  1266. expect(serviceConfigProperty.get('overrides.firstObject.parentSCP')).to.eql(serviceConfigProperty);
  1267. expect(component.get('configGroups.firstObject.properties').length).to.equal(1);
  1268. expect(component.get('configGroups.firstObject.properties.firstObject.isEditable')).to.equal(false);
  1269. expect(component.get('configGroups.firstObject.properties.firstObject.group')).to.be.object;
  1270. });
  1271. });
  1272. describe('#_updateValidatorsForConfig', function () {
  1273. it('should set isVisible to false', function () {
  1274. var serviceConfigProperty = Em.Object.create({serviceName: 's1', isVisible: true}),
  1275. component = Em.Object.create({serviceName: 's2'}),
  1276. serviceConfigsData = {};
  1277. installerStep7Controller._updateValidatorsForConfig(serviceConfigProperty, component, serviceConfigsData);
  1278. expect(serviceConfigProperty.get('isVisible')).to.equal(false);
  1279. });
  1280. it('should set serviceValidator', function () {
  1281. var serviceConfigProperty = Em.Object.create({serviceName: 's1', name: 'n1', serviceValidator: null}),
  1282. component = Em.Object.create({serviceName: 's1'}),
  1283. serviceConfigsData = {
  1284. configsValidator: Em.Object.create({
  1285. configValidators: {
  1286. n1: {},
  1287. n2: {}
  1288. }
  1289. })
  1290. };
  1291. installerStep7Controller._updateValidatorsForConfig(serviceConfigProperty, component, serviceConfigsData);
  1292. expect(serviceConfigProperty.get('serviceValidator')).to.be.object;
  1293. expect(Em.keys(serviceConfigProperty.get('serviceValidator.configValidators'))).to.eql(['n1', 'n2']);
  1294. });
  1295. });
  1296. describe('#getRecommendedDefaultsForComponent', function () {
  1297. beforeEach(function () {
  1298. sinon.stub(App.router, 'get', function (k) {
  1299. if (k === 'mainServiceInfoConfigsController') return Em.Object.create({
  1300. getInfoForDefaults: Em.K
  1301. });
  1302. return Em.get(App.router, k);
  1303. });
  1304. });
  1305. afterEach(function () {
  1306. App.router.get.restore();
  1307. });
  1308. it('should return empty object', function () {
  1309. var serviceConfigsData = [
  1310. {serviceName: 's1'}
  1311. ],
  1312. serviceName = 's1';
  1313. installerStep7Controller.reopen({serviceConfigsData: serviceConfigsData});
  1314. var r = installerStep7Controller._getRecommendedDefaultsForComponent(serviceName);
  1315. expect(r).to.eql({});
  1316. });
  1317. it('should return recommendedDefaults', function () {
  1318. var serviceConfigsData = [
  1319. {serviceName: 's1', defaultsProviders: [
  1320. {getDefaults: function () {
  1321. return {c1: 'v1', c2: 'v2'};
  1322. }},
  1323. {getDefaults: function () {
  1324. return {c3: 'v3', c4: 'v4'};
  1325. }}
  1326. ]}
  1327. ],
  1328. serviceName = 's1';
  1329. installerStep7Controller.reopen({serviceConfigsData: serviceConfigsData});
  1330. var r = installerStep7Controller._getRecommendedDefaultsForComponent(serviceName);
  1331. expect(r).to.eql({c1: 'v1', c2: 'v2', c3: 'v3', c4: 'v4'});
  1332. });
  1333. });
  1334. describe('#loadComponentConfigs', function () {
  1335. beforeEach(function () {
  1336. sinon.stub(installerStep7Controller, '_updateValidatorsForConfig', Em.K);
  1337. sinon.stub(installerStep7Controller, '_updateOverridesForConfig', Em.K);
  1338. sinon.stub(installerStep7Controller, '_updateIsEditableFlagForConfig', Em.K);
  1339. });
  1340. afterEach(function () {
  1341. installerStep7Controller._updateIsEditableFlagForConfig.restore();
  1342. installerStep7Controller._updateOverridesForConfig.restore();
  1343. installerStep7Controller._updateValidatorsForConfig.restore();
  1344. });
  1345. it('should set recommended defaults', function () {
  1346. var configs = [],
  1347. serviceConfigsData = [
  1348. {serviceName: 's1', configsValidator: Em.Object.create({recommendedDefaults: {}})}
  1349. ],
  1350. component = Em.Object.create({serviceName: 's1'}),
  1351. componentConfig = {},
  1352. recommendedDefaults = {c1: 'v1', c2: 'v2'};
  1353. installerStep7Controller.reopen({serviceConfigsData: serviceConfigsData});
  1354. sinon.stub(installerStep7Controller, '_getRecommendedDefaultsForComponent', function () {
  1355. return recommendedDefaults;
  1356. });
  1357. installerStep7Controller.loadComponentConfigs(configs, componentConfig, component);
  1358. installerStep7Controller._getRecommendedDefaultsForComponent.restore();
  1359. expect(installerStep7Controller.get('serviceConfigsData.firstObject.configsValidator.recommendedDefaults')).to.eql(recommendedDefaults);
  1360. });
  1361. it('should skip null configs', function () {
  1362. var configs = [null, null, null],
  1363. serviceConfigsData = [
  1364. {serviceName: 's1'}
  1365. ],
  1366. component = Em.Object.create({serviceName: 's1'}),
  1367. componentConfig = Em.Object.create({configs: []});
  1368. installerStep7Controller.reopen({serviceConfigsData: serviceConfigsData});
  1369. installerStep7Controller.loadComponentConfigs(configs, componentConfig, component);
  1370. expect(componentConfig.get('configs.length')).to.equal(0);
  1371. });
  1372. it('should update isOverridable flag', function () {
  1373. var configs = [Em.Object.create({validate: Em.K}), Em.Object.create({validate: Em.K})],
  1374. componentConfig = Em.Object.create({configs: []}),
  1375. serviceConfigsData = [
  1376. {serviceName: 's1'}
  1377. ],
  1378. component = Em.Object.create({serviceName: 's1'});
  1379. installerStep7Controller.reopen({serviceConfigsData: serviceConfigsData});
  1380. installerStep7Controller.loadComponentConfigs(configs, componentConfig, component);
  1381. expect(componentConfig.get('configs').getEach('isOverridable')).to.eql([true, true]);
  1382. });
  1383. it('should update value for checkboxes', function () {
  1384. var configs = [
  1385. Em.Object.create({displayType: 'checkbox', value: 'true', validate: Em.K}),
  1386. Em.Object.create({displayType: 'checkbox', value: 'false', validate: Em.K})
  1387. ],
  1388. componentConfig = Em.Object.create({configs: []}),
  1389. serviceConfigsData = [
  1390. {serviceName: 's1'}
  1391. ],
  1392. component = Em.Object.create({serviceName: 's1'});
  1393. installerStep7Controller.reopen({serviceConfigsData: serviceConfigsData});
  1394. installerStep7Controller.loadComponentConfigs(configs, componentConfig, component);
  1395. expect(componentConfig.get('configs').getEach('value')).to.eql([true, false]);
  1396. expect(componentConfig.get('configs').getEach('defaultValue')).to.eql([true, false]);
  1397. });
  1398. });
  1399. describe('#_createSiteToTagMap', function () {
  1400. it('should map sites', function () {
  1401. var desired_configs = {
  1402. s1: {tag: 't1'},
  1403. s2: {tag: 't1'},
  1404. s3: {tag: 't3'},
  1405. s4: {tag: 't1'},
  1406. s5: {tag: 't2'}
  1407. },
  1408. sites = ['s1', 's2', 's3'],
  1409. expected = {s1: 't1', s2: 't1', s3: 't3'};
  1410. var r = installerStep7Controller._createSiteToTagMap(desired_configs, sites);
  1411. expect(r).to.eql(expected);
  1412. });
  1413. });
  1414. });