config_test.js 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. require('controllers/main/service/info/configs');
  20. var batchUtils = require('utils/batch_scheduled_requests');
  21. var mainServiceInfoConfigsController = null;
  22. describe("App.MainServiceInfoConfigsController", function () {
  23. beforeEach(function () {
  24. mainServiceInfoConfigsController = App.MainServiceInfoConfigsController.create({});
  25. });
  26. describe("#showSavePopup", function () {
  27. var tests = [
  28. {
  29. path: false,
  30. event: false,
  31. action: "onSave",
  32. m: "save configs without path/event",
  33. results: [
  34. {
  35. method: "restartServicePopup",
  36. called: true
  37. },
  38. {
  39. method: "selectConfigGroup",
  40. called: false
  41. }
  42. ]
  43. },
  44. {
  45. path: true,
  46. event: true,
  47. action: "onSave",
  48. m: "save configs with path/event",
  49. results: [
  50. {
  51. method: "restartServicePopup",
  52. called: true
  53. },
  54. {
  55. method: "selectConfigGroup",
  56. called: false
  57. }
  58. ]
  59. },
  60. {
  61. path: false,
  62. event: false,
  63. action: "onDiscard",
  64. m: "discard changes without path/event",
  65. results: [
  66. {
  67. method: "restartServicePopup",
  68. called: false
  69. },
  70. {
  71. method: "selectConfigGroup",
  72. called: false
  73. }
  74. ]
  75. },
  76. {
  77. path: false,
  78. event: true,
  79. action: "onDiscard",
  80. m: "discard changes with event",
  81. results: [
  82. {
  83. method: "restartServicePopup",
  84. called: false
  85. },
  86. {
  87. method: "selectConfigGroup",
  88. called: true
  89. },
  90. {
  91. field: "hash",
  92. value: "hash"
  93. }
  94. ]
  95. },
  96. {
  97. path: true,
  98. event: false,
  99. action: "onDiscard",
  100. m: "discard changes with path",
  101. results: [
  102. {
  103. method: "restartServicePopup",
  104. called: false
  105. },
  106. {
  107. method: "selectConfigGroup",
  108. called: false
  109. },
  110. {
  111. field: "forceTransition",
  112. value: true
  113. }
  114. ]
  115. }
  116. ];
  117. beforeEach(function () {
  118. sinon.stub(mainServiceInfoConfigsController, "restartServicePopup", Em.K);
  119. sinon.stub(mainServiceInfoConfigsController, "selectConfigGroup", Em.K);
  120. sinon.stub(mainServiceInfoConfigsController, "getHash", function () {
  121. return "hash"
  122. });
  123. App.router.route = Em.K;
  124. });
  125. afterEach(function () {
  126. mainServiceInfoConfigsController.restartServicePopup.restore();
  127. mainServiceInfoConfigsController.selectConfigGroup.restore();
  128. mainServiceInfoConfigsController.getHash.restore();
  129. });
  130. tests.forEach(function (t) {
  131. t.results.forEach(function (r) {
  132. it(t.m + " " + r.method + " " + r.field, function () {
  133. mainServiceInfoConfigsController.showSavePopup(t.path, t.event)[t.action]();
  134. if (r.method) {
  135. expect(mainServiceInfoConfigsController[r.method].calledOnce).to.equal(r.called);
  136. } else if (r.field) {
  137. expect(mainServiceInfoConfigsController.get(r.field)).to.equal(r.value);
  138. }
  139. }, this);
  140. });
  141. }, this);
  142. });
  143. describe("#hasUnsavedChanges", function () {
  144. beforeEach(function () {
  145. sinon.stub(mainServiceInfoConfigsController, "getHash", function () {
  146. return "hash"
  147. });
  148. });
  149. afterEach(function () {
  150. mainServiceInfoConfigsController.getHash.restore();
  151. });
  152. it("with unsaved", function () {
  153. mainServiceInfoConfigsController.set("hash", "hash1");
  154. expect(mainServiceInfoConfigsController.hasUnsavedChanges()).to.equal(true);
  155. });
  156. it("without unsaved", function () {
  157. mainServiceInfoConfigsController.set("hash", "hash");
  158. expect(mainServiceInfoConfigsController.hasUnsavedChanges()).to.equal(false);
  159. });
  160. });
  161. describe("#manageConfigurationGroup", function () {
  162. beforeEach(function () {
  163. sinon.stub(mainServiceInfoConfigsController, "manageConfigurationGroups", Em.K);
  164. });
  165. afterEach(function () {
  166. mainServiceInfoConfigsController.manageConfigurationGroups.restore();
  167. });
  168. it("run manageConfigurationGroups", function () {
  169. mainServiceInfoConfigsController.manageConfigurationGroup();
  170. expect(mainServiceInfoConfigsController.manageConfigurationGroups.calledOnce).to.equal(true);
  171. });
  172. });
  173. describe("#addOverrideProperty", function () {
  174. var serviceConfigProperty = Em.Object.create({
  175. overrides: []
  176. });
  177. var newSCP = App.ServiceConfigProperty.create(serviceConfigProperty);
  178. newSCP.set('value', '');
  179. newSCP.set('isOriginalSCP', false);
  180. newSCP.set('parentSCP', serviceConfigProperty);
  181. newSCP.set('isEditable', true);
  182. it("add new overridden property", function () {
  183. mainServiceInfoConfigsController.addOverrideProperty(serviceConfigProperty);
  184. expect(serviceConfigProperty.get("overrides")[0]).to.eql(newSCP);
  185. });
  186. });
  187. describe("#showComponentsShouldBeRestarted", function () {
  188. var tests = [
  189. {
  190. input: {
  191. 'publicHostName1': ['TaskTracker'],
  192. 'publicHostName2': ['JobTracker', 'TaskTracker']
  193. },
  194. components: "2 TaskTrackers, 1 JobTracker",
  195. text: Em.I18n.t('service.service.config.restartService.shouldBeRestarted').format(Em.I18n.t('common.components'))
  196. },
  197. {
  198. input: {
  199. 'publicHostName1': ['TaskTracker']
  200. },
  201. components: "1 TaskTracker",
  202. text: Em.I18n.t('service.service.config.restartService.shouldBeRestarted').format(Em.I18n.t('common.component'))
  203. }
  204. ];
  205. beforeEach(function () {
  206. sinon.stub(mainServiceInfoConfigsController, "showItemsShouldBeRestarted", Em.K);
  207. mainServiceInfoConfigsController.set("content", {restartRequiredHostsAndComponents: ""});
  208. });
  209. afterEach(function () {
  210. mainServiceInfoConfigsController.showItemsShouldBeRestarted.restore();
  211. mainServiceInfoConfigsController.set("content", undefined);
  212. });
  213. tests.forEach(function (t) {
  214. it("trigger showItemsShouldBeRestarted popup with components", function () {
  215. mainServiceInfoConfigsController.set("content.restartRequiredHostsAndComponents", t.input);
  216. mainServiceInfoConfigsController.showComponentsShouldBeRestarted();
  217. expect(mainServiceInfoConfigsController.showItemsShouldBeRestarted.calledWith(t.components, t.text)).to.equal(true);
  218. });
  219. });
  220. });
  221. describe("#showHostsShouldBeRestarted", function () {
  222. var tests = [
  223. {
  224. input: {
  225. 'publicHostName1': ['TaskTracker'],
  226. 'publicHostName2': ['JobTracker', 'TaskTracker']
  227. },
  228. hosts: "publicHostName1, publicHostName2",
  229. text: Em.I18n.t('service.service.config.restartService.shouldBeRestarted').format(Em.I18n.t('common.hosts'))
  230. },
  231. {
  232. input: {
  233. 'publicHostName1': ['TaskTracker']
  234. },
  235. hosts: "publicHostName1",
  236. text: Em.I18n.t('service.service.config.restartService.shouldBeRestarted').format(Em.I18n.t('common.host'))
  237. }
  238. ];
  239. beforeEach(function () {
  240. sinon.stub(mainServiceInfoConfigsController, "showItemsShouldBeRestarted", Em.K);
  241. mainServiceInfoConfigsController.set("content", {restartRequiredHostsAndComponents: ""});
  242. });
  243. afterEach(function () {
  244. mainServiceInfoConfigsController.showItemsShouldBeRestarted.restore();
  245. mainServiceInfoConfigsController.set("content", undefined);
  246. });
  247. tests.forEach(function (t) {
  248. it("trigger showItemsShouldBeRestarted popup with hosts", function () {
  249. mainServiceInfoConfigsController.set("content.restartRequiredHostsAndComponents", t.input);
  250. mainServiceInfoConfigsController.showHostsShouldBeRestarted();
  251. expect(mainServiceInfoConfigsController.showItemsShouldBeRestarted.calledWith(t.hosts, t.text)).to.equal(true);
  252. });
  253. });
  254. });
  255. describe("rollingRestartStaleConfigSlaveComponents", function () {
  256. var tests = [
  257. {
  258. componentName: {
  259. context: "ComponentName"
  260. },
  261. displayName: "displayName",
  262. passiveState: "ON"
  263. },
  264. {
  265. componentName: {
  266. context: "ComponentName1"
  267. },
  268. displayName: "displayName1",
  269. passiveState: "OFF"
  270. }
  271. ];
  272. beforeEach(function () {
  273. mainServiceInfoConfigsController.set("content", {displayName: "", passiveState: ""});
  274. sinon.stub(batchUtils, "launchHostComponentRollingRestart", Em.K);
  275. });
  276. afterEach(function () {
  277. batchUtils.launchHostComponentRollingRestart.restore();
  278. });
  279. tests.forEach(function (t) {
  280. it("trigger rollingRestartStaleConfigSlaveComponents", function () {
  281. mainServiceInfoConfigsController.set("content.displayName", t.displayName);
  282. mainServiceInfoConfigsController.set("content.passiveState", t.passiveState);
  283. mainServiceInfoConfigsController.rollingRestartStaleConfigSlaveComponents(t.componentName);
  284. expect(batchUtils.launchHostComponentRollingRestart.calledWith(t.componentName.context, t.displayName, t.passiveState == "ON", true)).to.equal(true);
  285. });
  286. });
  287. });
  288. describe("#restartAllStaleConfigComponents", function () {
  289. beforeEach(function () {
  290. sinon.stub(batchUtils, "restartAllServiceHostComponents", Em.K);
  291. });
  292. afterEach(function () {
  293. batchUtils.restartAllServiceHostComponents.restore();
  294. });
  295. it("trigger restartAllServiceHostComponents", function () {
  296. mainServiceInfoConfigsController.restartAllStaleConfigComponents().onPrimary();
  297. expect(batchUtils.restartAllServiceHostComponents.calledOnce).to.equal(true);
  298. });
  299. });
  300. describe("#doCancel", function () {
  301. beforeEach(function () {
  302. sinon.stub(Em.run, 'once', Em.K);
  303. });
  304. afterEach(function () {
  305. Em.run.once.restore();
  306. });
  307. it("trigger onConfigGroupChange", function () {
  308. mainServiceInfoConfigsController.doCancel();
  309. expect(Em.run.once.calledWith(mainServiceInfoConfigsController, "onConfigGroupChange")).to.equal(true);
  310. });
  311. });
  312. describe("#getCurrentServiceComponents", function () {
  313. var t = Em.Object.create({
  314. content: Em.Object.create({
  315. hostComponents: [
  316. Em.Object.create({
  317. componentName: "componentName1",
  318. displayName: "displayName1"
  319. }),
  320. Em.Object.create({
  321. componentName: "componentName2",
  322. displayName: "displayName2"
  323. })
  324. ]
  325. }),
  326. validComponents: Em.A([
  327. Em.Object.create({
  328. componentName: "componentName1",
  329. displayName: "displayName1",
  330. selected: false
  331. }),
  332. Em.Object.create({
  333. componentName: "componentName2",
  334. displayName: "displayName2",
  335. selected: false
  336. })
  337. ])
  338. });
  339. beforeEach(function () {
  340. mainServiceInfoConfigsController.set("content", { hostComponents: Em.A([])});
  341. });
  342. it("get current service components", function () {
  343. mainServiceInfoConfigsController.get("content.hostComponents").push(t.content.hostComponents[0]);
  344. var com = mainServiceInfoConfigsController.get("getCurrentServiceComponents");
  345. expect(com[0]).to.eql(t.validComponents[0]);
  346. });
  347. });
  348. describe("#getMasterComponentHostValue", function () {
  349. var tests = [
  350. {
  351. content: {
  352. hostComponents: [
  353. Em.Object.create({
  354. componentName: "componentName1",
  355. hostName: "hostName"
  356. })
  357. ]
  358. },
  359. result: "hostName",
  360. multiple: false,
  361. m: "returns hostname"
  362. },
  363. {
  364. content: {
  365. hostComponents: [
  366. Em.Object.create({
  367. componentName: "componentName2",
  368. hostName: "hostName1"
  369. }),
  370. Em.Object.create({
  371. componentName: "componentName2",
  372. hostName: "hostName2"
  373. })
  374. ]
  375. },
  376. result: ["hostName1","hostName2"],
  377. multiple: true,
  378. m: "returns hostnames"
  379. }
  380. ];
  381. tests.forEach(function(t){
  382. beforeEach(function () {
  383. mainServiceInfoConfigsController.set("content", { hostComponents: []});
  384. });
  385. it(t.m, function () {
  386. mainServiceInfoConfigsController.set("content.hostComponents", t.content.hostComponents);
  387. expect(mainServiceInfoConfigsController.getMasterComponentHostValue(t.content.hostComponents[0].componentName, t.multiple)).to.eql(t.result);
  388. });
  389. });
  390. });
  391. describe("#setServerConfigValue", function () {
  392. it("parsing storm.zookeeper.servers property in non standart method", function () {
  393. expect(mainServiceInfoConfigsController.setServerConfigValue("storm.zookeeper.servers", ["a", "b"])).to.equal('[\'a\',\'b\']');
  394. });
  395. it("parsing default properties", function () {
  396. expect(mainServiceInfoConfigsController.setServerConfigValue("any.other.property", "value")).to.equal("value");
  397. });
  398. });
  399. describe("#createSiteObj", function () {
  400. var tests = [
  401. {
  402. siteName: "hdfs-site",
  403. tagName: "version1",
  404. siteObj: Em.A([
  405. {
  406. name: "property1",
  407. value: "value1"
  408. },
  409. {
  410. name: "property2",
  411. value: "value2<"
  412. }
  413. ]),
  414. result: {
  415. "type": "hdfs-site",
  416. "tag": "version1",
  417. "properties": {
  418. "property1": "value1",
  419. "property2": "value2<"
  420. }
  421. },
  422. m: "default"
  423. },
  424. {
  425. siteName: "falcon-startup.properties",
  426. tagName: "version1",
  427. siteObj: Em.A([
  428. {
  429. name: "property1",
  430. value: "value1"
  431. },
  432. {
  433. name: "property2",
  434. value: "value2<"
  435. }
  436. ]),
  437. result: {
  438. "type": "falcon-startup.properties",
  439. "tag": "version1",
  440. "properties": {
  441. "property1": "value1",
  442. "property2": "value2<"
  443. }
  444. },
  445. m: "for falcon-startup.properties"
  446. }
  447. ];
  448. tests.forEach(function (t) {
  449. it("create site object " + t.m, function () {
  450. expect(mainServiceInfoConfigsController.createSiteObj(t.siteName, t.tagName, t.siteObj)).to.deep.eql(t.result)
  451. });
  452. });
  453. });
  454. describe("#createCoreSiteObj", function () {
  455. var tests = [
  456. {
  457. tagName: "version1",
  458. uiConfigs: Em.A([
  459. Em.Object.create({
  460. name: "property1",
  461. value: "value1",
  462. filename: "core-site.xml"
  463. }),
  464. Em.Object.create({
  465. name: "property2",
  466. value: "value2<",
  467. filename: "core-site.xml"
  468. })
  469. ]),
  470. result: {
  471. "type": "core-site",
  472. "tag": "version1",
  473. "properties": {
  474. "property1": "value1",
  475. "property2": "value2<"
  476. }
  477. }
  478. }
  479. ];
  480. tests.forEach(function (t) {
  481. it("create core object", function () {
  482. mainServiceInfoConfigsController.set("uiConfigs", t.uiConfigs);
  483. expect(mainServiceInfoConfigsController.createCoreSiteObj(t.tagName)).to.deep.eql(t.result);
  484. });
  485. });
  486. });
  487. describe("#doPUTClusterConfigurationSites", function () {
  488. var sc = [
  489. Em.Object.create({
  490. configs: [
  491. Em.Object.create({
  492. name: '_heapsize',
  493. value: '1024m'
  494. }),
  495. Em.Object.create({
  496. name: '_newsize',
  497. value: '1024m'
  498. }),
  499. Em.Object.create({
  500. name: '_maxnewsize',
  501. value: '1024m'
  502. })
  503. ]
  504. })
  505. ],
  506. scExc = [
  507. Em.Object.create({
  508. configs: [
  509. Em.Object.create({
  510. name: 'hadoop_heapsize',
  511. value: '1024m'
  512. }),
  513. Em.Object.create({
  514. name: 'yarn_heapsize',
  515. value: '1024m'
  516. }),
  517. Em.Object.create({
  518. name: 'nodemanager_heapsize',
  519. value: '1024m'
  520. }),
  521. Em.Object.create({
  522. name: 'resourcemanager_heapsize',
  523. value: '1024m'
  524. }),
  525. Em.Object.create({
  526. name: 'apptimelineserver_heapsize',
  527. value: '1024m'
  528. }),
  529. Em.Object.create({
  530. name: 'jobhistory_heapsize',
  531. value: '1024m'
  532. })
  533. ]
  534. })
  535. ];
  536. beforeEach(function () {
  537. sinon.stub(App.router, 'getClusterName', function() {
  538. return 'clName';
  539. });
  540. sinon.stub(App.ajax, "send", Em.K);
  541. });
  542. afterEach(function () {
  543. App.ajax.send.restore();
  544. App.router.getClusterName.restore();
  545. });
  546. it("ajax request to put clsuter cfg", function () {
  547. mainServiceInfoConfigsController.set('stepConfigs', sc);
  548. expect(mainServiceInfoConfigsController.doPUTClusterConfigurationSites([])).to.equal(mainServiceInfoConfigsController.get("doPUTClusterConfigurationSiteResult"));
  549. expect(App.ajax.send.calledOnce).to.be.true;
  550. });
  551. it('values should be parsed', function () {
  552. mainServiceInfoConfigsController.set('stepConfigs', sc);
  553. mainServiceInfoConfigsController.doPUTClusterConfigurationSites([]);
  554. expect(mainServiceInfoConfigsController.get('stepConfigs')[0].get('configs').mapProperty('value').uniq()).to.eql(['1024m']);
  555. });
  556. it('values should not be parsed', function () {
  557. mainServiceInfoConfigsController.set('stepConfigs', scExc);
  558. mainServiceInfoConfigsController.doPUTClusterConfigurationSites([]);
  559. expect(mainServiceInfoConfigsController.get('stepConfigs')[0].get('configs').mapProperty('value').uniq()).to.eql(['1024m']);
  560. });
  561. });
  562. describe("#isConfigChanged", function () {
  563. var tests = [
  564. {
  565. loadedConfig: {
  566. apptimelineserver_heapsize: "1024",
  567. hbase_log_dir: "/var/log/hbase",
  568. lzo_enabled: "true"
  569. },
  570. savingConfig: {
  571. apptimelineserver_heapsize: "1024",
  572. hbase_log_dir: "/var/log/hbase",
  573. lzo_enabled: "true"
  574. },
  575. m: "configs doesn't changed",
  576. res: false
  577. },
  578. {
  579. loadedConfig: {
  580. apptimelineserver_heapsize: "1024",
  581. hbase_log_dir: "/var/log/hbase",
  582. lzo_enabled: "true"
  583. },
  584. savingConfig: {
  585. apptimelineserver_heapsize: "1024",
  586. hbase_log_dir: "/var/log/hbase",
  587. lzo_enabled: "false"
  588. },
  589. m: "configs changed",
  590. res: true
  591. },
  592. {
  593. loadedConfig: {
  594. apptimelineserver_heapsize: "1024",
  595. hbase_log_dir: "/var/log/hbase"
  596. },
  597. savingConfig: {
  598. apptimelineserver_heapsize: "1024",
  599. hbase_log_dir: "/var/log/hbase",
  600. lzo_enabled: "false"
  601. },
  602. m: "add new config",
  603. res: true
  604. }
  605. ];
  606. tests.forEach(function(t){
  607. it(t.m, function () {
  608. expect(mainServiceInfoConfigsController.isConfigChanged(t.loadedConfig, t.savingConfig)).to.equal(t.res);
  609. });
  610. });
  611. });
  612. describe("#isDirChanged", function() {
  613. describe("when service name is HDFS", function() {
  614. beforeEach(function() {
  615. mainServiceInfoConfigsController.set('content', Ember.Object.create ({ serviceName: 'HDFS' }));
  616. });
  617. describe("when isHadoop2Stack is true", function() {
  618. var tests = [
  619. {
  620. it: "should set dirChanged to false if none of the properties exist",
  621. expect: false,
  622. config: Ember.Object.create ({})
  623. },
  624. {
  625. it: "should set dirChanged to true if dfs.namenode.name.dir is not default",
  626. expect: true,
  627. config: Ember.Object.create ({
  628. name: 'dfs.namenode.name.dir',
  629. isNotDefaultValue: true
  630. })
  631. },
  632. {
  633. it: "should set dirChanged to false if dfs.namenode.name.dir is default",
  634. expect: false,
  635. config: Ember.Object.create ({
  636. name: 'dfs.namenode.name.dir',
  637. isNotDefaultValue: false
  638. })
  639. },
  640. {
  641. it: "should set dirChanged to true if dfs.namenode.checkpoint.dir is not default",
  642. expect: true,
  643. config: Ember.Object.create ({
  644. name: 'dfs.namenode.checkpoint.dir',
  645. isNotDefaultValue: true
  646. })
  647. },
  648. {
  649. it: "should set dirChanged to false if dfs.namenode.checkpoint.dir is default",
  650. expect: false,
  651. config: Ember.Object.create ({
  652. name: 'dfs.namenode.checkpoint.dir',
  653. isNotDefaultValue: false
  654. })
  655. },
  656. {
  657. it: "should set dirChanged to true if dfs.datanode.data.dir is not default",
  658. expect: true,
  659. config: Ember.Object.create ({
  660. name: 'dfs.datanode.data.dir',
  661. isNotDefaultValue: true
  662. })
  663. },
  664. {
  665. it: "should set dirChanged to false if dfs.datanode.data.dir is default",
  666. expect: false,
  667. config: Ember.Object.create ({
  668. name: 'dfs.datanode.data.dir',
  669. isNotDefaultValue: false
  670. })
  671. }
  672. ];
  673. beforeEach(function() {
  674. sinon.stub(App, 'get').returns(true);
  675. });
  676. afterEach(function() {
  677. App.get.restore();
  678. });
  679. tests.forEach(function(test) {
  680. it(test.it, function() {
  681. mainServiceInfoConfigsController.set('stepConfigs', [Ember.Object.create ({ configs: [test.config], serviceName: 'HDFS' })]);
  682. expect(mainServiceInfoConfigsController.isDirChanged()).to.equal(test.expect);
  683. })
  684. });
  685. });
  686. describe("when isHadoop2Stack is false", function() {
  687. var tests = [
  688. {
  689. it: "should set dirChanged to false if none of the properties exist",
  690. expect: false,
  691. config: Ember.Object.create ({})
  692. },
  693. {
  694. it: "should set dirChanged to true if dfs.name.dir is not default",
  695. expect: true,
  696. config: Ember.Object.create ({
  697. name: 'dfs.name.dir',
  698. isNotDefaultValue: true
  699. })
  700. },
  701. {
  702. it: "should set dirChanged to false if dfs.name.dir is default",
  703. expect: false,
  704. config: Ember.Object.create ({
  705. name: 'dfs.name.dir',
  706. isNotDefaultValue: false
  707. })
  708. },
  709. {
  710. it: "should set dirChanged to true if fs.checkpoint.dir is not default",
  711. expect: true,
  712. config: Ember.Object.create ({
  713. name: 'fs.checkpoint.dir',
  714. isNotDefaultValue: true
  715. })
  716. },
  717. {
  718. it: "should set dirChanged to false if fs.checkpoint.dir is default",
  719. expect: false,
  720. config: Ember.Object.create ({
  721. name: 'fs.checkpoint.dir',
  722. isNotDefaultValue: false
  723. })
  724. },
  725. {
  726. it: "should set dirChanged to true if dfs.data.dir is not default",
  727. expect: true,
  728. config: Ember.Object.create ({
  729. name: 'dfs.data.dir',
  730. isNotDefaultValue: true
  731. })
  732. },
  733. {
  734. it: "should set dirChanged to false if dfs.data.dir is default",
  735. expect: false,
  736. config: Ember.Object.create ({
  737. name: 'dfs.data.dir',
  738. isNotDefaultValue: false
  739. })
  740. }
  741. ];
  742. beforeEach(function() {
  743. sinon.stub(App, 'get').returns(false);
  744. });
  745. afterEach(function() {
  746. App.get.restore();
  747. });
  748. tests.forEach(function(test) {
  749. it(test.it, function() {
  750. mainServiceInfoConfigsController.set('stepConfigs', [Ember.Object.create ({ configs: [test.config], serviceName: 'HDFS' })]);
  751. expect(mainServiceInfoConfigsController.isDirChanged()).to.equal(test.expect);
  752. })
  753. });
  754. });
  755. });
  756. describe("when service name is MAPREDUCE", function() {
  757. beforeEach(function() {
  758. mainServiceInfoConfigsController.set('content', Ember.Object.create ({ serviceName: 'MAPREDUCE' }));
  759. });
  760. var tests = [
  761. {
  762. it: "should set dirChanged to false if none of the properties exist",
  763. expect: false,
  764. config: Ember.Object.create ({})
  765. },
  766. {
  767. it: "should set dirChanged to true if mapred.local.dir is not default",
  768. expect: true,
  769. config: Ember.Object.create ({
  770. name: 'mapred.local.dir',
  771. isNotDefaultValue: true
  772. })
  773. },
  774. {
  775. it: "should set dirChanged to false if mapred.local.dir is default",
  776. expect: false,
  777. config: Ember.Object.create ({
  778. name: 'mapred.local.dir',
  779. isNotDefaultValue: false
  780. })
  781. },
  782. {
  783. it: "should set dirChanged to true if mapred.system.dir is not default",
  784. expect: true,
  785. config: Ember.Object.create ({
  786. name: 'mapred.system.dir',
  787. isNotDefaultValue: true
  788. })
  789. },
  790. {
  791. it: "should set dirChanged to false if mapred.system.dir is default",
  792. expect: false,
  793. config: Ember.Object.create ({
  794. name: 'mapred.system.dir',
  795. isNotDefaultValue: false
  796. })
  797. }
  798. ];
  799. tests.forEach(function(test) {
  800. it(test.it, function() {
  801. mainServiceInfoConfigsController.set('stepConfigs', [Ember.Object.create ({ configs: [test.config], serviceName: 'MAPREDUCE' })]);
  802. expect(mainServiceInfoConfigsController.isDirChanged()).to.equal(test.expect);
  803. })
  804. });
  805. });
  806. });
  807. describe("#addDynamicProperties", function() {
  808. var tests = [
  809. {
  810. stepConfigs: [Em.Object.create({
  811. serviceName: "HIVE",
  812. configs: []
  813. })],
  814. content: Em.Object.create({
  815. serviceName: "HIVE"
  816. }),
  817. m: "add dynamic property",
  818. addDynamic: true
  819. },
  820. {
  821. stepConfigs: [Em.Object.create({
  822. serviceName: "HIVE",
  823. configs: [
  824. Em.Object.create({
  825. name: "templeton.hive.properties"
  826. })
  827. ]
  828. })],
  829. content: Em.Object.create({
  830. serviceName: "HIVE"
  831. }),
  832. m: "don't add dynamic property (already included)",
  833. addDynamic: false
  834. },
  835. {
  836. stepConfigs: [Em.Object.create({
  837. serviceName: "HDFS",
  838. configs: []
  839. })],
  840. content: Em.Object.create({
  841. serviceName: "HDFS"
  842. }),
  843. m: "don't add dynamic property (wrong service)",
  844. addDynamic: false
  845. }
  846. ];
  847. var dynamicProperty = {
  848. "name": "templeton.hive.properties",
  849. "templateName": ["hivemetastore_host"],
  850. "foreignKey": null,
  851. "value": "hive.metastore.local=false,hive.metastore.uris=thrift://<templateName[0]>:9083,hive.metastore.sasl.enabled=yes,hive.metastore.execute.setugi=true,hive.metastore.warehouse.dir=/apps/hive/warehouse",
  852. "filename": "webhcat-site.xml"
  853. };
  854. tests.forEach(function(t) {
  855. it(t.m, function() {
  856. mainServiceInfoConfigsController.set("content", t.content);
  857. mainServiceInfoConfigsController.set("stepConfigs", t.stepConfigs);
  858. var configs = [];
  859. mainServiceInfoConfigsController.addDynamicProperties(configs);
  860. if (t.addDynamic){
  861. expect(configs.findProperty("name","templeton.hive.properties")).to.deep.eql(dynamicProperty);
  862. }
  863. });
  864. });
  865. });
  866. describe("#loadUiSideConfigs", function () {
  867. var t = {
  868. configMapping: [
  869. {
  870. foreignKey: null,
  871. templateName: "",
  872. value: "default",
  873. name: "name1",
  874. filename: "filename1"
  875. },
  876. {
  877. foreignKey: "notNull",
  878. templateName: "",
  879. value: "default2",
  880. name: "name2",
  881. filename: "filename2"
  882. }
  883. ],
  884. configMappingf: [
  885. {
  886. foreignKey: null,
  887. templateName: "",
  888. value: "default",
  889. name: "name1",
  890. filename: "filename1"
  891. }
  892. ],
  893. valueWithOverrides: {
  894. "value": "default",
  895. "overrides": {
  896. "value1": "value1",
  897. "value2": "value2"
  898. }
  899. },
  900. uiConfigs: [
  901. {
  902. "id": "site property",
  903. "name": "name1",
  904. "value": "default",
  905. "filename": "filename1",
  906. "overrides": {
  907. "value1": "value1",
  908. "value2": "value2"
  909. }
  910. }
  911. ]
  912. };
  913. beforeEach(function(){
  914. sinon.stub(mainServiceInfoConfigsController, "addDynamicProperties", Em.K);
  915. sinon.stub(mainServiceInfoConfigsController, "getGlobConfigValueWithOverrides", function () {
  916. return t.valueWithOverrides
  917. });
  918. });
  919. afterEach(function(){
  920. mainServiceInfoConfigsController.addDynamicProperties.restore();
  921. mainServiceInfoConfigsController.getGlobConfigValueWithOverrides.restore();
  922. });
  923. it("load ui config", function() {
  924. expect(mainServiceInfoConfigsController.loadUiSideConfigs(t.configMapping)[0]).to.deep.equal(t.uiConfigs[0]);
  925. expect(mainServiceInfoConfigsController.addDynamicProperties.calledWith(t.configMappingf)).to.equal(true);
  926. });
  927. });
  928. describe("#formatConfigValues", function () {
  929. var t = {
  930. configs: [
  931. Em.Object.create({ name: "p1", value: " v1 v1 ", displayType: "" }),
  932. Em.Object.create({ name: "p2", value: true, displayType: "" }),
  933. Em.Object.create({ name: "p3", value: " d1 ", displayType: "directory" }),
  934. Em.Object.create({ name: "p4", value: " d1 d2 d3 ", displayType: "directories" }),
  935. Em.Object.create({ name: "p5", value: " v1 ", displayType: "password" }),
  936. Em.Object.create({ name: "p6", value: " v ", displayType: "host" }),
  937. Em.Object.create({ name: "javax.jdo.option.ConnectionURL", value: " v1 ", displayType: "advanced" }),
  938. Em.Object.create({ name: "oozie.service.JPAService.jdbc.url", value: " v1 ", displayType: "advanced" })
  939. ],
  940. result: [
  941. Em.Object.create({ name: "p1", value: " v1 v1", displayType: "" }),
  942. Em.Object.create({ name: "p2", value: "true", displayType: "" }),
  943. Em.Object.create({ name: "p3", value: "d1", displayType: "directory" }),
  944. Em.Object.create({ name: "p4", value: "d1,d2,d3", displayType: "directories" }),
  945. Em.Object.create({ name: "p5", value: " v1 ", displayType: "password" }),
  946. Em.Object.create({ name: "p6", value: "v", displayType: "host" }),
  947. Em.Object.create({ name: "javax.jdo.option.ConnectionURL", value: " v1", displayType: "advanced" }),
  948. Em.Object.create({ name: "oozie.service.JPAService.jdbc.url", value: " v1", displayType: "advanced" })
  949. ]
  950. };
  951. it("format config values", function () {
  952. mainServiceInfoConfigsController.formatConfigValues(t.configs);
  953. expect(t.configs).to.deep.equal(t.result);
  954. });
  955. });
  956. describe("#createConfigObject", function() {
  957. var tests = [
  958. {
  959. siteName: "core-site",
  960. serviceName: "HDFS",
  961. method: "createCoreSiteObj"
  962. },
  963. {
  964. siteName: "core-site",
  965. serviceName: "ANY",
  966. method: false
  967. },
  968. {
  969. siteName: "any",
  970. method: "createSiteObj"
  971. },
  972. {
  973. siteName: "mapred-queue-acls",
  974. method: false
  975. }
  976. ];
  977. beforeEach(function() {
  978. sinon.stub(mainServiceInfoConfigsController, "createCoreSiteObj", Em.K);
  979. sinon.stub(mainServiceInfoConfigsController, "createSiteObj", Em.K);
  980. mainServiceInfoConfigsController.set("content", {});
  981. });
  982. afterEach(function() {
  983. mainServiceInfoConfigsController.createCoreSiteObj.restore();
  984. mainServiceInfoConfigsController.createSiteObj.restore();
  985. });
  986. tests.forEach(function(t) {
  987. it("create object for " + t.siteName + " run method " + t.method, function() {
  988. mainServiceInfoConfigsController.set("content.serviceName", t.serviceName);
  989. mainServiceInfoConfigsController.createConfigObject(t.siteName, "versrion1");
  990. if (t.method) {
  991. expect(mainServiceInfoConfigsController[t.method].calledOnce).to.equal(true);
  992. } else {
  993. expect(mainServiceInfoConfigsController["createCoreSiteObj"].calledOnce).to.equal(false);
  994. expect(mainServiceInfoConfigsController["createSiteObj"].calledOnce).to.equal(false);
  995. }
  996. });
  997. });
  998. });
  999. describe("#putConfigGroupChanges", function() {
  1000. var t = {
  1001. data: {
  1002. ConfigGroup: {
  1003. id: "id"
  1004. }
  1005. },
  1006. request: [{
  1007. ConfigGroup: {
  1008. id: "id"
  1009. }
  1010. }]
  1011. };
  1012. beforeEach(function() {
  1013. sinon.spy($,"ajax");
  1014. });
  1015. afterEach(function() {
  1016. $.ajax.restore();
  1017. });
  1018. it("updates configs groups", function() {
  1019. mainServiceInfoConfigsController.putConfigGroupChanges(t.data);
  1020. expect(JSON.parse($.ajax.args[0][0].data)).to.deep.equal(t.request);
  1021. });
  1022. });
  1023. describe("#setValueForCheckBox", function() {
  1024. var tests = [
  1025. {
  1026. serviceConfigPropertyInput: Em.Object.create({
  1027. value: "true",
  1028. defaultValue: "true",
  1029. displayType: 'checkbox'
  1030. }),
  1031. serviceConfigProperty: Em.Object.create({
  1032. value: true,
  1033. defaultValue: true,
  1034. displayType: 'checkbox'
  1035. })
  1036. },
  1037. {
  1038. serviceConfigPropertyInput: Em.Object.create({
  1039. value: "false",
  1040. defaultValue: "false",
  1041. displayType: 'checkbox'
  1042. }),
  1043. serviceConfigProperty: Em.Object.create({
  1044. value: false,
  1045. defaultValue: false,
  1046. displayType: 'checkbox'
  1047. })
  1048. },
  1049. {
  1050. serviceConfigPropertyInput: Em.Object.create({
  1051. value: "false",
  1052. defaultValue: "false"
  1053. }),
  1054. serviceConfigProperty: Em.Object.create({
  1055. value: "false",
  1056. defaultValue: "false"
  1057. })
  1058. }
  1059. ];
  1060. tests.forEach(function(t) {
  1061. it("set " + t.serviceConfigPropertyInput.value, function(){
  1062. var serviceConfigProperty = t.serviceConfigPropertyInput;
  1063. mainServiceInfoConfigsController.setValueForCheckBox(serviceConfigProperty);
  1064. expect(serviceConfigProperty).to.eql(t.serviceConfigProperty);
  1065. });
  1066. });
  1067. });
  1068. describe("#setEditability", function () {
  1069. var tests = [
  1070. {
  1071. isAdmin: true,
  1072. isHostsConfigsPage: false,
  1073. defaultGroupSelected: true,
  1074. isReconfigurable: true,
  1075. isEditable: true,
  1076. m: ""
  1077. },
  1078. {
  1079. isAdmin: false,
  1080. isHostsConfigsPage: false,
  1081. defaultGroupSelected: true,
  1082. isReconfigurable: true,
  1083. isEditable: false,
  1084. m: "(non admin)"
  1085. },
  1086. {
  1087. isAdmin: true,
  1088. isHostsConfigsPage: true,
  1089. defaultGroupSelected: true,
  1090. isReconfigurable: true,
  1091. isEditable: false,
  1092. m: "(isHostsConfigsPage)"
  1093. },
  1094. {
  1095. isAdmin: true,
  1096. isHostsConfigsPage: false,
  1097. defaultGroupSelected: false,
  1098. isReconfigurable: true,
  1099. isEditable: false,
  1100. m: "(defaultGroupSelected is false)"
  1101. },
  1102. {
  1103. isAdmin: true,
  1104. isHostsConfigsPage: false,
  1105. defaultGroupSelected: true,
  1106. isReconfigurable: false,
  1107. isEditable: false,
  1108. m: "(isReconfigurable is false)"
  1109. }
  1110. ];
  1111. var a = App.get('isAdmin');
  1112. afterEach(function () {
  1113. App.set('isAdmin', a);
  1114. });
  1115. tests.forEach(function(t) {
  1116. it("set isEditable " + t.isEditable + t.m, function(){
  1117. App.set('isAdmin', t.isAdmin);
  1118. mainServiceInfoConfigsController.set("isHostsConfigsPage", t.isHostsConfigsPage);
  1119. var serviceConfigProperty = Em.Object.create({
  1120. isReconfigurable: t.isReconfigurable
  1121. });
  1122. mainServiceInfoConfigsController.setEditability(serviceConfigProperty, t.defaultGroupSelected);
  1123. expect(serviceConfigProperty.get("isEditable")).to.equal(t.isEditable);
  1124. });
  1125. });
  1126. });
  1127. describe("#checkOverrideProperty", function () {
  1128. var tests = [{
  1129. overrideToAdd: {
  1130. name: "name1",
  1131. filename: "filename1"
  1132. },
  1133. componentConfig: {
  1134. configs: [
  1135. {
  1136. name: "name1",
  1137. filename: "filename2"
  1138. },
  1139. {
  1140. name: "name1",
  1141. filename: "filename1"
  1142. }
  1143. ]
  1144. },
  1145. add: true,
  1146. m: "add property"
  1147. },
  1148. {
  1149. overrideToAdd: {
  1150. name: "name1"
  1151. },
  1152. componentConfig: {
  1153. configs: [
  1154. {
  1155. name: "name2"
  1156. }
  1157. ]
  1158. },
  1159. add: false,
  1160. m: "don't add property, different names"
  1161. },
  1162. {
  1163. overrideToAdd: {
  1164. name: "name1",
  1165. filename: "filename1"
  1166. },
  1167. componentConfig: {
  1168. configs: [
  1169. {
  1170. name: "name1",
  1171. filename: "filename2"
  1172. }
  1173. ]
  1174. },
  1175. add: false,
  1176. m: "don't add property, different filenames"
  1177. },
  1178. {
  1179. overrideToAdd: null,
  1180. componentConfig: {},
  1181. add: false,
  1182. m: "don't add property, overrideToAdd is null"
  1183. }];
  1184. beforeEach(function() {
  1185. sinon.stub(mainServiceInfoConfigsController,"addOverrideProperty", Em.K)
  1186. });
  1187. afterEach(function() {
  1188. mainServiceInfoConfigsController.addOverrideProperty.restore();
  1189. });
  1190. tests.forEach(function(t) {
  1191. it(t.m, function() {
  1192. mainServiceInfoConfigsController.set("overrideToAdd", t.overrideToAdd);
  1193. mainServiceInfoConfigsController.checkOverrideProperty(t.componentConfig);
  1194. if(t.add) {
  1195. expect(mainServiceInfoConfigsController.addOverrideProperty.calledWith(t.overrideToAdd)).to.equal(true);
  1196. expect(mainServiceInfoConfigsController.get("overrideToAdd")).to.equal(null);
  1197. } else {
  1198. expect(mainServiceInfoConfigsController.addOverrideProperty.calledOnce).to.equal(false);
  1199. }
  1200. });
  1201. });
  1202. });
  1203. describe("#setValuesForOverrides", function() {
  1204. var tests = [
  1205. {
  1206. overrides: [
  1207. {name: "override1"},
  1208. {name: "override2"}
  1209. ],
  1210. _serviceConfigProperty: {},
  1211. serviceConfigProperty: Em.Object.create({overrides: Em.A([])}),
  1212. defaultGroupSelected: true
  1213. }
  1214. ];
  1215. beforeEach(function() {
  1216. sinon.stub(mainServiceInfoConfigsController, "createNewSCP", function(override) {return {name: override.name}})
  1217. });
  1218. afterEach(function() {
  1219. mainServiceInfoConfigsController.createNewSCP.restore();
  1220. });
  1221. tests.forEach(function(t) {
  1222. it("set values for overrides. use createNewSCP method to do this", function() {
  1223. var serviceConfigProperty = t.serviceConfigProperty;
  1224. mainServiceInfoConfigsController.setValuesForOverrides(t.overrides, serviceConfigProperty, t.serviceConfigProperty, t.defaultGroupSelected);
  1225. expect(serviceConfigProperty.get("overrides")[0]).to.eql(t.overrides[0]);
  1226. expect(serviceConfigProperty.get("overrides")[1]).to.eql(t.overrides[1]);
  1227. });
  1228. });
  1229. });
  1230. describe("#createConfigProperty", function() {
  1231. var tests = [
  1232. {
  1233. _serviceConfigProperty: {
  1234. overrides: {
  1235. }
  1236. },
  1237. defaultGroupSelected: true,
  1238. restartData: {},
  1239. serviceConfigsData: {},
  1240. serviceConfigProperty: {
  1241. overrides: null,
  1242. isOverridable: true
  1243. }
  1244. }];
  1245. beforeEach(function() {
  1246. sinon.stub(mainServiceInfoConfigsController, "setValueForCheckBox", Em.K);
  1247. sinon.stub(mainServiceInfoConfigsController, "setValidator", Em.K);
  1248. sinon.stub(mainServiceInfoConfigsController, "setValuesForOverrides", Em.K);
  1249. sinon.stub(mainServiceInfoConfigsController, "setEditability", Em.K);
  1250. });
  1251. afterEach(function() {
  1252. mainServiceInfoConfigsController.setValueForCheckBox.restore();
  1253. mainServiceInfoConfigsController.setValidator.restore();
  1254. mainServiceInfoConfigsController.setValuesForOverrides.restore();
  1255. mainServiceInfoConfigsController.setEditability.restore();
  1256. });
  1257. tests.forEach(function(t) {
  1258. it("create service config. run methods to correctly set object fileds", function() {
  1259. var result = mainServiceInfoConfigsController.createConfigProperty(t._serviceConfigProperty, t.defaultGroupSelected, t.restartData, t.serviceConfigsData);
  1260. expect(mainServiceInfoConfigsController.setValueForCheckBox.calledWith(t.serviceConfigProperty));
  1261. expect(mainServiceInfoConfigsController.setValidator.calledWith(t.serviceConfigProperty, t.serviceConfigsData));
  1262. expect(mainServiceInfoConfigsController.setValuesForOverrides.calledWith(t._serviceConfigProperty.overrides, t._serviceConfigProperty, t.serviceConfigProperty, t.defaultGroupSelected));
  1263. expect(mainServiceInfoConfigsController.setValidator.calledWith(t.serviceConfigProperty, t.defaultGroupSelected));
  1264. expect(result.getProperties('overrides','isOverridable')).to.eql(t.serviceConfigProperty);
  1265. });
  1266. });
  1267. });
  1268. describe("#createNewSCP", function() {
  1269. var tests = [
  1270. {
  1271. overrides: {
  1272. value: "value",
  1273. group: {
  1274. value: "group1"
  1275. }
  1276. },
  1277. _serviceConfigProperty: {},
  1278. serviceConfigProperty: Em.Object.create({
  1279. value: "parentSCP",
  1280. supportsFinal: true
  1281. }),
  1282. defaultGroupSelected: true,
  1283. newSCP: {
  1284. value: "value",
  1285. isOriginalSCP: false,
  1286. parentSCP:Em.Object.create({
  1287. value: "parentSCP",
  1288. supportsFinal: true
  1289. }),
  1290. group: {
  1291. value: "group1"
  1292. },
  1293. isEditable: false
  1294. }
  1295. }
  1296. ];
  1297. tests.forEach(function(t) {
  1298. it("", function() {
  1299. var newSCP = mainServiceInfoConfigsController.createNewSCP(t.overrides, t._serviceConfigProperty, t.serviceConfigProperty, t.defaultGroupSelected);
  1300. expect(newSCP.getProperties("value", "isOriginalSCP", "parentSCP", "group", "isEditable")).to.eql(t.newSCP);
  1301. });
  1302. });
  1303. });
  1304. describe("setCompareDefaultGroupConfig", function() {
  1305. beforeEach(function() {
  1306. sinon.stub(mainServiceInfoConfigsController, "getComparisonConfig").returns("compConfig");
  1307. sinon.stub(mainServiceInfoConfigsController, "getMockComparisonConfig").returns("mockConfig");
  1308. sinon.stub(mainServiceInfoConfigsController, "hasCompareDiffs").returns(true);
  1309. });
  1310. afterEach(function() {
  1311. mainServiceInfoConfigsController.getComparisonConfig.restore();
  1312. mainServiceInfoConfigsController.getMockComparisonConfig.restore();
  1313. mainServiceInfoConfigsController.hasCompareDiffs.restore();
  1314. });
  1315. it("expect that setCompareDefaultGroupConfig will not run anything", function() {
  1316. expect(mainServiceInfoConfigsController.setCompareDefaultGroupConfig({}).compareConfigs.length).to.equal(0);
  1317. });
  1318. it("expect that setCompareDefaultGroupConfig will not run anything", function() {
  1319. expect(mainServiceInfoConfigsController.setCompareDefaultGroupConfig({},{}).compareConfigs.length).to.equal(0);
  1320. });
  1321. it("expect that serviceConfig.compareConfigs will be getMockComparisonConfig", function() {
  1322. expect(mainServiceInfoConfigsController.setCompareDefaultGroupConfig({isUserProperty: true}, null)).to.eql({compareConfigs: ["mockConfig"], isUserProperty: true, isComparison: true, hasCompareDiffs: true});
  1323. });
  1324. it("expect that serviceConfig.compareConfigs will be getComparisonConfig", function() {
  1325. expect(mainServiceInfoConfigsController.setCompareDefaultGroupConfig({isUserProperty: true}, {})).to.eql({compareConfigs: ["compConfig"], isUserProperty: true, isComparison: true, hasCompareDiffs: true});
  1326. });
  1327. it("expect that serviceConfig.compareConfigs will be getComparisonConfig", function() {
  1328. expect(mainServiceInfoConfigsController.setCompareDefaultGroupConfig({isReconfigurable: true}, {})).to.eql({compareConfigs: ["compConfig"], isReconfigurable: true, isComparison: true, hasCompareDiffs: true});
  1329. });
  1330. it("expect that serviceConfig.compareConfigs will be getComparisonConfig", function() {
  1331. expect(mainServiceInfoConfigsController.setCompareDefaultGroupConfig({isReconfigurable: true, isMock: true}, {})).to.eql({compareConfigs: ["compConfig"], isReconfigurable: true, isMock: true, isComparison: true, hasCompareDiffs: true});
  1332. });
  1333. });
  1334. });