config_test.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825
  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. sinon.stub(App.themesMapper, 'generateAdvancedTabs').returns(Em.K);
  25. mainServiceInfoConfigsController = App.MainServiceInfoConfigsController.create({
  26. dependentServiceNames: [],
  27. loadDependentConfigs: function () {
  28. return {done: Em.K}
  29. },
  30. loadConfigTheme: function () {
  31. return $.Deferred().resolve().promise();
  32. }
  33. });
  34. });
  35. afterEach(function() {
  36. App.themesMapper.generateAdvancedTabs.restore();
  37. });
  38. describe("#showSavePopup", function () {
  39. var tests = [
  40. {
  41. path: false,
  42. callback: null,
  43. action: "onSave",
  44. m: "save configs without path/callback",
  45. results: [
  46. {
  47. method: "restartServicePopup",
  48. called: true
  49. }
  50. ]
  51. },
  52. {
  53. path: true,
  54. callback: true,
  55. action: "onSave",
  56. m: "save configs with path/callback",
  57. results: [
  58. {
  59. method: "restartServicePopup",
  60. called: true
  61. }
  62. ]
  63. },
  64. {
  65. path: false,
  66. callback: false,
  67. action: "onDiscard",
  68. m: "discard changes without path/callback",
  69. results: [
  70. {
  71. method: "restartServicePopup",
  72. called: false
  73. }
  74. ]
  75. },
  76. {
  77. path: false,
  78. callback: true,
  79. action: "onDiscard",
  80. m: "discard changes with callback",
  81. results: [
  82. {
  83. method: "restartServicePopup",
  84. called: false
  85. },
  86. {
  87. method: "callback",
  88. called: true
  89. },
  90. {
  91. field: "hash",
  92. value: "hash"
  93. }
  94. ]
  95. },
  96. {
  97. path: true,
  98. callback: null,
  99. action: "onDiscard",
  100. m: "discard changes with path",
  101. results: [
  102. {
  103. method: "restartServicePopup",
  104. called: false
  105. },
  106. {
  107. field: "forceTransition",
  108. value: true
  109. }
  110. ]
  111. }
  112. ];
  113. beforeEach(function () {
  114. sinon.stub(mainServiceInfoConfigsController, "get", function(key) {
  115. return key == 'isSubmitDisabled' ? false : Em.get(mainServiceInfoConfigsController, key);
  116. });
  117. sinon.stub(mainServiceInfoConfigsController, "restartServicePopup", Em.K);
  118. sinon.stub(mainServiceInfoConfigsController, "getHash", function () {
  119. return "hash"
  120. });
  121. sinon.stub(App.router, "route", Em.K);
  122. });
  123. afterEach(function () {
  124. mainServiceInfoConfigsController.get.restore();
  125. mainServiceInfoConfigsController.restartServicePopup.restore();
  126. mainServiceInfoConfigsController.getHash.restore();
  127. App.router.route.restore();
  128. });
  129. tests.forEach(function (t) {
  130. t.results.forEach(function (r) {
  131. it(t.m + " " + r.method + " " + r.field, function () {
  132. if (t.callback) {
  133. t.callback = sinon.stub();
  134. }
  135. mainServiceInfoConfigsController.showSavePopup(t.path, t.callback)[t.action]();
  136. if (r.method) {
  137. if (r.method === 'callback') {
  138. expect(t.callback.calledOnce).to.equal(r.called);
  139. } else {
  140. expect(mainServiceInfoConfigsController[r.method].calledOnce).to.equal(r.called);
  141. }
  142. } else if (r.field) {
  143. expect(mainServiceInfoConfigsController.get(r.field)).to.equal(r.value);
  144. }
  145. }, this);
  146. });
  147. }, this);
  148. });
  149. describe("#hasUnsavedChanges", function () {
  150. var cases = [
  151. {
  152. hash: null,
  153. hasUnsavedChanges: false,
  154. title: 'configs not rendered'
  155. },
  156. {
  157. hash: 'hash1',
  158. hasUnsavedChanges: true,
  159. title: 'with unsaved'
  160. },
  161. {
  162. hash: 'hash',
  163. hasUnsavedChanges: false,
  164. title: 'without unsaved'
  165. }
  166. ];
  167. beforeEach(function () {
  168. sinon.stub(mainServiceInfoConfigsController, "getHash", function () {
  169. return "hash"
  170. });
  171. });
  172. afterEach(function () {
  173. mainServiceInfoConfigsController.getHash.restore();
  174. });
  175. cases.forEach(function (item) {
  176. it(item.title, function () {
  177. mainServiceInfoConfigsController.set('hash', item.hash);
  178. expect(mainServiceInfoConfigsController.hasUnsavedChanges()).to.equal(item.hasUnsavedChanges);
  179. });
  180. });
  181. });
  182. describe("#showComponentsShouldBeRestarted", function () {
  183. var tests = [
  184. {
  185. input: {
  186. context: {
  187. restartRequiredHostsAndComponents: {
  188. 'publicHostName1': ['TaskTracker'],
  189. 'publicHostName2': ['JobTracker', 'TaskTracker']
  190. }
  191. }
  192. },
  193. components: "2 TaskTrackers, 1 JobTracker",
  194. text: Em.I18n.t('service.service.config.restartService.shouldBeRestarted').format(Em.I18n.t('common.components'))
  195. },
  196. {
  197. input: {
  198. context: {
  199. restartRequiredHostsAndComponents: {
  200. 'publicHostName1': ['TaskTracker']
  201. }
  202. }
  203. },
  204. components: "1 TaskTracker",
  205. text: Em.I18n.t('service.service.config.restartService.shouldBeRestarted').format(Em.I18n.t('common.component'))
  206. }
  207. ];
  208. beforeEach(function () {
  209. sinon.stub(mainServiceInfoConfigsController, "showItemsShouldBeRestarted", Em.K);
  210. });
  211. afterEach(function () {
  212. mainServiceInfoConfigsController.showItemsShouldBeRestarted.restore();
  213. });
  214. tests.forEach(function (t) {
  215. it("trigger showItemsShouldBeRestarted popup with components", function () {
  216. mainServiceInfoConfigsController.showComponentsShouldBeRestarted(t.input);
  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. context: {
  226. restartRequiredHostsAndComponents: {
  227. 'publicHostName1': ['TaskTracker'],
  228. 'publicHostName2': ['JobTracker', 'TaskTracker']
  229. }
  230. }
  231. },
  232. hosts: "publicHostName1, publicHostName2",
  233. text: Em.I18n.t('service.service.config.restartService.shouldBeRestarted').format(Em.I18n.t('common.hosts'))
  234. },
  235. {
  236. input: {
  237. context: {
  238. restartRequiredHostsAndComponents: {
  239. 'publicHostName1': ['TaskTracker']
  240. }
  241. }
  242. },
  243. hosts: "publicHostName1",
  244. text: Em.I18n.t('service.service.config.restartService.shouldBeRestarted').format(Em.I18n.t('common.host'))
  245. }
  246. ];
  247. beforeEach(function () {
  248. sinon.stub(mainServiceInfoConfigsController, "showItemsShouldBeRestarted", Em.K);
  249. });
  250. afterEach(function () {
  251. mainServiceInfoConfigsController.showItemsShouldBeRestarted.restore();
  252. });
  253. tests.forEach(function (t) {
  254. it("trigger showItemsShouldBeRestarted popup with hosts", function () {
  255. mainServiceInfoConfigsController.showHostsShouldBeRestarted(t.input);
  256. expect(mainServiceInfoConfigsController.showItemsShouldBeRestarted.calledWith(t.hosts, t.text)).to.equal(true);
  257. });
  258. });
  259. });
  260. describe("#rollingRestartStaleConfigSlaveComponents", function () {
  261. var tests = [
  262. {
  263. componentName: {
  264. context: "ComponentName"
  265. },
  266. displayName: "displayName",
  267. passiveState: "ON"
  268. },
  269. {
  270. componentName: {
  271. context: "ComponentName1"
  272. },
  273. displayName: "displayName1",
  274. passiveState: "OFF"
  275. }
  276. ];
  277. beforeEach(function () {
  278. mainServiceInfoConfigsController.set("content", {displayName: "", passiveState: ""});
  279. sinon.stub(batchUtils, "launchHostComponentRollingRestart", Em.K);
  280. });
  281. afterEach(function () {
  282. batchUtils.launchHostComponentRollingRestart.restore();
  283. });
  284. tests.forEach(function (t) {
  285. it("trigger rollingRestartStaleConfigSlaveComponents", function () {
  286. mainServiceInfoConfigsController.set("content.displayName", t.displayName);
  287. mainServiceInfoConfigsController.set("content.passiveState", t.passiveState);
  288. mainServiceInfoConfigsController.rollingRestartStaleConfigSlaveComponents(t.componentName);
  289. expect(batchUtils.launchHostComponentRollingRestart.calledWith(t.componentName.context, t.displayName, t.passiveState == "ON", true)).to.equal(true);
  290. });
  291. });
  292. });
  293. describe("#restartAllStaleConfigComponents", function () {
  294. beforeEach(function () {
  295. sinon.stub(batchUtils, "restartAllServiceHostComponents", Em.K);
  296. });
  297. afterEach(function () {
  298. batchUtils.restartAllServiceHostComponents.restore();
  299. });
  300. it("trigger restartAllServiceHostComponents", function () {
  301. mainServiceInfoConfigsController.restartAllStaleConfigComponents().onPrimary();
  302. expect(batchUtils.restartAllServiceHostComponents.calledOnce).to.equal(true);
  303. });
  304. it("trigger check last check point warning before triggering restartAllServiceHostComponents", function () {
  305. var mainConfigsControllerHdfsStarted = App.MainServiceInfoConfigsController.create({
  306. content: {
  307. serviceName: "HDFS",
  308. hostComponents: [{
  309. componentName: 'NAMENODE',
  310. workStatus: 'STARTED'
  311. }],
  312. restartRequiredHostsAndComponents: {
  313. "host1": ['NameNode'],
  314. "host2": ['DataNode', 'ZooKeeper']
  315. }
  316. }
  317. });
  318. var mainServiceItemController = App.MainServiceItemController.create({});
  319. sinon.stub(mainServiceItemController, 'checkNnLastCheckpointTime', function() {
  320. return true;
  321. });
  322. sinon.stub(App.router, 'get', function(k) {
  323. if ('mainServiceItemController' === k) {
  324. return mainServiceItemController;
  325. }
  326. return Em.get(App.router, k);
  327. });
  328. mainConfigsControllerHdfsStarted.restartAllStaleConfigComponents();
  329. expect(mainServiceItemController.checkNnLastCheckpointTime.calledOnce).to.equal(true);
  330. mainServiceItemController.checkNnLastCheckpointTime.restore();
  331. App.router.get.restore();
  332. });
  333. });
  334. describe("#doCancel", function () {
  335. beforeEach(function () {
  336. sinon.stub(Em.run, 'once', Em.K);
  337. });
  338. afterEach(function () {
  339. Em.run.once.restore();
  340. });
  341. it("should clear dependent configs", function() {
  342. mainServiceInfoConfigsController.set('groupsToSave', { HDFS: 'my cool group'});
  343. mainServiceInfoConfigsController.set('_dependentConfigValues', Em.A([{name: 'prop_1'}]));
  344. mainServiceInfoConfigsController.doCancel();
  345. expect(App.isEmptyObject(mainServiceInfoConfigsController.get('_dependentConfigValues'))).to.be.true;
  346. });
  347. });
  348. describe("#putChangedConfigurations", function () {
  349. var sc = [
  350. Em.Object.create({
  351. configs: [
  352. Em.Object.create({
  353. name: '_heapsize',
  354. value: '1024m'
  355. }),
  356. Em.Object.create({
  357. name: '_newsize',
  358. value: '1024m'
  359. }),
  360. Em.Object.create({
  361. name: '_maxnewsize',
  362. value: '1024m'
  363. })
  364. ]
  365. })
  366. ],
  367. scExc = [
  368. Em.Object.create({
  369. configs: [
  370. Em.Object.create({
  371. name: 'hadoop_heapsize',
  372. value: '1024m'
  373. }),
  374. Em.Object.create({
  375. name: 'yarn_heapsize',
  376. value: '1024m'
  377. }),
  378. Em.Object.create({
  379. name: 'nodemanager_heapsize',
  380. value: '1024m'
  381. }),
  382. Em.Object.create({
  383. name: 'resourcemanager_heapsize',
  384. value: '1024m'
  385. }),
  386. Em.Object.create({
  387. name: 'apptimelineserver_heapsize',
  388. value: '1024m'
  389. }),
  390. Em.Object.create({
  391. name: 'jobhistory_heapsize',
  392. value: '1024m'
  393. })
  394. ]
  395. })
  396. ];
  397. beforeEach(function () {
  398. sinon.stub(App.router, 'getClusterName', function() {
  399. return 'clName';
  400. });
  401. sinon.stub(App.ajax, "send", Em.K);
  402. });
  403. afterEach(function () {
  404. App.ajax.send.restore();
  405. App.router.getClusterName.restore();
  406. });
  407. it("ajax request to put cluster cfg", function () {
  408. mainServiceInfoConfigsController.set('stepConfigs', sc);
  409. expect(mainServiceInfoConfigsController.putChangedConfigurations([]));
  410. expect(App.ajax.send.calledOnce).to.be.true;
  411. });
  412. it('values should be parsed', function () {
  413. mainServiceInfoConfigsController.set('stepConfigs', sc);
  414. mainServiceInfoConfigsController.putChangedConfigurations([]);
  415. expect(mainServiceInfoConfigsController.get('stepConfigs')[0].get('configs').mapProperty('value').uniq()).to.eql(['1024m']);
  416. });
  417. it('values should not be parsed', function () {
  418. mainServiceInfoConfigsController.set('stepConfigs', scExc);
  419. mainServiceInfoConfigsController.putChangedConfigurations([]);
  420. expect(mainServiceInfoConfigsController.get('stepConfigs')[0].get('configs').mapProperty('value').uniq()).to.eql(['1024m']);
  421. });
  422. });
  423. describe("#isDirChanged", function() {
  424. describe("when service name is HDFS", function() {
  425. beforeEach(function() {
  426. mainServiceInfoConfigsController.set('content', Ember.Object.create ({ serviceName: 'HDFS' }));
  427. });
  428. describe("for hadoop 2", function() {
  429. var tests = [
  430. {
  431. it: "should set dirChanged to false if none of the properties exist",
  432. expect: false,
  433. config: Ember.Object.create ({})
  434. },
  435. {
  436. it: "should set dirChanged to true if dfs.namenode.name.dir is not default",
  437. expect: true,
  438. config: Ember.Object.create ({
  439. name: 'dfs.namenode.name.dir',
  440. isNotDefaultValue: true
  441. })
  442. },
  443. {
  444. it: "should set dirChanged to false if dfs.namenode.name.dir is default",
  445. expect: false,
  446. config: Ember.Object.create ({
  447. name: 'dfs.namenode.name.dir',
  448. isNotDefaultValue: false
  449. })
  450. },
  451. {
  452. it: "should set dirChanged to true if dfs.namenode.checkpoint.dir is not default",
  453. expect: true,
  454. config: Ember.Object.create ({
  455. name: 'dfs.namenode.checkpoint.dir',
  456. isNotDefaultValue: true
  457. })
  458. },
  459. {
  460. it: "should set dirChanged to false if dfs.namenode.checkpoint.dir is default",
  461. expect: false,
  462. config: Ember.Object.create ({
  463. name: 'dfs.namenode.checkpoint.dir',
  464. isNotDefaultValue: false
  465. })
  466. },
  467. {
  468. it: "should set dirChanged to true if dfs.datanode.data.dir is not default",
  469. expect: true,
  470. config: Ember.Object.create ({
  471. name: 'dfs.datanode.data.dir',
  472. isNotDefaultValue: true
  473. })
  474. },
  475. {
  476. it: "should set dirChanged to false if dfs.datanode.data.dir is default",
  477. expect: false,
  478. config: Ember.Object.create ({
  479. name: 'dfs.datanode.data.dir',
  480. isNotDefaultValue: false
  481. })
  482. }
  483. ];
  484. beforeEach(function() {
  485. sinon.stub(App, 'get').returns(true);
  486. });
  487. afterEach(function() {
  488. App.get.restore();
  489. });
  490. tests.forEach(function(test) {
  491. it(test.it, function() {
  492. mainServiceInfoConfigsController.set('stepConfigs', [Ember.Object.create ({ configs: [test.config], serviceName: 'HDFS' })]);
  493. expect(mainServiceInfoConfigsController.isDirChanged()).to.equal(test.expect);
  494. })
  495. });
  496. });
  497. });
  498. });
  499. describe("#formatConfigValues", function () {
  500. var t = {
  501. configs: [
  502. Em.Object.create({ name: "p1", value: " v1 v1 ", displayType: "" }),
  503. Em.Object.create({ name: "p2", value: true, displayType: "" }),
  504. Em.Object.create({ name: "p3", value: " d1 ", displayType: "directory" }),
  505. Em.Object.create({ name: "p4", value: " d1 d2 d3 ", displayType: "directories" }),
  506. Em.Object.create({ name: "p5", value: " v1 ", displayType: "password" }),
  507. Em.Object.create({ name: "p6", value: " v ", displayType: "host" }),
  508. Em.Object.create({ name: "javax.jdo.option.ConnectionURL", value: " v1 ", displayType: "string" }),
  509. Em.Object.create({ name: "oozie.service.JPAService.jdbc.url", value: " v1 ", displayType: "string" })
  510. ],
  511. result: [
  512. Em.Object.create({ name: "p1", value: " v1 v1", displayType: "" }),
  513. Em.Object.create({ name: "p2", value: "true", displayType: "" }),
  514. Em.Object.create({ name: "p3", value: "d1", displayType: "directory" }),
  515. Em.Object.create({ name: "p4", value: "d1,d2,d3", displayType: "directories" }),
  516. Em.Object.create({ name: "p5", value: " v1 ", displayType: "password" }),
  517. Em.Object.create({ name: "p6", value: "v", displayType: "host" }),
  518. Em.Object.create({ name: "javax.jdo.option.ConnectionURL", value: " v1", displayType: "string" }),
  519. Em.Object.create({ name: "oozie.service.JPAService.jdbc.url", value: " v1", displayType: "string" })
  520. ]
  521. };
  522. it("format config values", function () {
  523. mainServiceInfoConfigsController.formatConfigValues(t.configs);
  524. expect(t.configs).to.deep.equal(t.result);
  525. });
  526. });
  527. describe("#putConfigGroupChanges", function() {
  528. var t = {
  529. data: {
  530. ConfigGroup: {
  531. id: "id"
  532. }
  533. },
  534. request: [{
  535. ConfigGroup: {
  536. id: "id"
  537. }
  538. }]
  539. };
  540. beforeEach(function() {
  541. sinon.spy($,"ajax");
  542. });
  543. afterEach(function() {
  544. $.ajax.restore();
  545. });
  546. it("updates configs groups", function() {
  547. mainServiceInfoConfigsController.putConfigGroupChanges(t.data);
  548. expect(JSON.parse($.ajax.args[0][0].data)).to.deep.equal(t.request);
  549. });
  550. });
  551. describe("#checkOverrideProperty", function () {
  552. var tests = [{
  553. overrideToAdd: {
  554. name: "name1",
  555. filename: "filename1"
  556. },
  557. componentConfig: {
  558. configs: [
  559. {
  560. name: "name1",
  561. filename: "filename2"
  562. },
  563. {
  564. name: "name1",
  565. filename: "filename1"
  566. }
  567. ]
  568. },
  569. add: true,
  570. m: "add property"
  571. },
  572. {
  573. overrideToAdd: {
  574. name: "name1"
  575. },
  576. componentConfig: {
  577. configs: [
  578. {
  579. name: "name2"
  580. }
  581. ]
  582. },
  583. add: false,
  584. m: "don't add property, different names"
  585. },
  586. {
  587. overrideToAdd: {
  588. name: "name1",
  589. filename: "filename1"
  590. },
  591. componentConfig: {
  592. configs: [
  593. {
  594. name: "name1",
  595. filename: "filename2"
  596. }
  597. ]
  598. },
  599. add: false,
  600. m: "don't add property, different filenames"
  601. },
  602. {
  603. overrideToAdd: null,
  604. componentConfig: {},
  605. add: false,
  606. m: "don't add property, overrideToAdd is null"
  607. }];
  608. beforeEach(function() {
  609. sinon.stub(App.config,"createOverride", Em.K)
  610. });
  611. afterEach(function() {
  612. App.config.createOverride.restore();
  613. });
  614. tests.forEach(function(t) {
  615. it(t.m, function() {
  616. mainServiceInfoConfigsController.set("overrideToAdd", t.overrideToAdd);
  617. mainServiceInfoConfigsController.checkOverrideProperty(t.componentConfig);
  618. if(t.add) {
  619. expect(App.config.createOverride.calledWith(t.overrideToAdd)).to.equal(true);
  620. expect(mainServiceInfoConfigsController.get("overrideToAdd")).to.equal(null);
  621. } else {
  622. expect(App.config.createOverride.calledOnce).to.equal(false);
  623. }
  624. });
  625. });
  626. });
  627. describe("#trackRequest()", function () {
  628. after(function(){
  629. mainServiceInfoConfigsController.get('requestsInProgress').clear();
  630. });
  631. it("should set requestsInProgress", function () {
  632. mainServiceInfoConfigsController.get('requestsInProgress').clear();
  633. mainServiceInfoConfigsController.trackRequest({'request': {}});
  634. expect(mainServiceInfoConfigsController.get('requestsInProgress')[0]).to.eql({'request': {}});
  635. });
  636. });
  637. describe("#setCompareDefaultGroupConfig", function() {
  638. beforeEach(function() {
  639. sinon.stub(mainServiceInfoConfigsController, "getComparisonConfig").returns("compConfig");
  640. sinon.stub(mainServiceInfoConfigsController, "getMockComparisonConfig").returns("mockConfig");
  641. sinon.stub(mainServiceInfoConfigsController, "hasCompareDiffs").returns(true);
  642. });
  643. afterEach(function() {
  644. mainServiceInfoConfigsController.getComparisonConfig.restore();
  645. mainServiceInfoConfigsController.getMockComparisonConfig.restore();
  646. mainServiceInfoConfigsController.hasCompareDiffs.restore();
  647. });
  648. it("empty service config passed, expect that setCompareDefaultGroupConfig will not run anything", function() {
  649. expect(mainServiceInfoConfigsController.setCompareDefaultGroupConfig({}).compareConfigs.length).to.equal(0);
  650. });
  651. it("empty service config and comparison passed, expect that setCompareDefaultGroupConfig will not run anything", function() {
  652. expect(mainServiceInfoConfigsController.setCompareDefaultGroupConfig({},{}).compareConfigs).to.eql(["compConfig"]);
  653. });
  654. it("expect that serviceConfig.compareConfigs will be getMockComparisonConfig", function() {
  655. expect(mainServiceInfoConfigsController.setCompareDefaultGroupConfig({isUserProperty: true}, null)).to.eql({compareConfigs: ["mockConfig"], isUserProperty: true, isComparison: true, hasCompareDiffs: true});
  656. });
  657. it("expect that serviceConfig.compareConfigs will be getComparisonConfig", function() {
  658. expect(mainServiceInfoConfigsController.setCompareDefaultGroupConfig({isUserProperty: true}, {})).to.eql({compareConfigs: ["compConfig"], isUserProperty: true, isComparison: true, hasCompareDiffs: true});
  659. });
  660. it("expect that serviceConfig.compareConfigs will be getComparisonConfig", function() {
  661. expect(mainServiceInfoConfigsController.setCompareDefaultGroupConfig({isReconfigurable: true}, {})).to.eql({compareConfigs: ["compConfig"], isReconfigurable: true, isComparison: true, hasCompareDiffs: true});
  662. });
  663. it("expect that serviceConfig.compareConfigs will be getComparisonConfig", function() {
  664. expect(mainServiceInfoConfigsController.setCompareDefaultGroupConfig({isReconfigurable: true, isMock: true}, {})).to.eql({compareConfigs: ["compConfig"], isReconfigurable: true, isMock: true, isComparison: true, hasCompareDiffs: true});
  665. });
  666. it("property was created during upgrade and have no comparison, compare with 'Undefined' value should be created", function() {
  667. expect(mainServiceInfoConfigsController.setCompareDefaultGroupConfig({name: 'prop1', isUserProperty: false}, null)).to.eql({
  668. name: 'prop1', isUserProperty: false, compareConfigs: ["mockConfig"],
  669. isComparison: true, hasCompareDiffs: true
  670. });
  671. });
  672. });
  673. describe('#showSaveConfigsPopup', function () {
  674. var bodyView;
  675. describe('#bodyClass', function () {
  676. beforeEach(function() {
  677. sinon.stub(App.StackService, 'find').returns([{dependentServiceNames: []}]);
  678. sinon.stub(App.ajax, 'send', Em.K);
  679. // default implementation
  680. bodyView = mainServiceInfoConfigsController.showSaveConfigsPopup().get('bodyClass').create({
  681. parentView: Em.View.create()
  682. });
  683. });
  684. afterEach(function() {
  685. App.ajax.send.restore();
  686. App.StackService.find.restore();
  687. });
  688. describe('#componentsFilterSuccessCallback', function () {
  689. it('check components with unknown state', function () {
  690. bodyView = mainServiceInfoConfigsController.showSaveConfigsPopup('', true, '', {}, '', 'unknown', '').get('bodyClass').create({
  691. parentView: Em.View.create()
  692. });
  693. bodyView.componentsFilterSuccessCallback({
  694. items: [
  695. {
  696. ServiceComponentInfo: {
  697. total_count: 4,
  698. started_count: 2,
  699. installed_count: 1,
  700. component_name: 'c1'
  701. },
  702. host_components: [
  703. {HostRoles: {host_name: 'h1'}}
  704. ]
  705. }
  706. ]
  707. });
  708. var unknownHosts = bodyView.get('unknownHosts');
  709. expect(unknownHosts.length).to.equal(1);
  710. expect(unknownHosts[0]).to.eql({name: 'h1', components: 'C1'});
  711. });
  712. });
  713. });
  714. });
  715. describe('#errorsCount', function () {
  716. it('should ignore configs with widgets (enhanced configs)', function () {
  717. mainServiceInfoConfigsController.reopen({selectedService: {
  718. configs: [
  719. Em.Object.create({isVisible: true, widget: Em.View, isValid: false}),
  720. Em.Object.create({isVisible: true, widget: Em.View, isValid: true}),
  721. Em.Object.create({isVisible: true, isValid: true}),
  722. Em.Object.create({isVisible: true, isValid: false})
  723. ]
  724. }});
  725. expect(mainServiceInfoConfigsController.get('errorsCount')).to.equal(1);
  726. });
  727. it('should ignore configs with widgets (enhanced configs) and hidden configs', function () {
  728. mainServiceInfoConfigsController.reopen({selectedService: {
  729. configs: [
  730. Em.Object.create({isVisible: true, widget: Em.View, isValid: false}),
  731. Em.Object.create({isVisible: true, widget: Em.View, isValid: true}),
  732. Em.Object.create({isVisible: false, isValid: false}),
  733. Em.Object.create({isVisible: true, isValid: true}),
  734. Em.Object.create({isVisible: true, isValid: false})
  735. ]
  736. }});
  737. expect(mainServiceInfoConfigsController.get('errorsCount')).to.equal(1);
  738. });
  739. });
  740. describe('#_onLoadComplete', function () {
  741. beforeEach(function () {
  742. sinon.stub(Em.run, 'next', Em.K);
  743. mainServiceInfoConfigsController.setProperties({
  744. dataIsLoaded: false,
  745. versionLoaded: false,
  746. isInit: true
  747. });
  748. });
  749. afterEach(function () {
  750. Em.run.next.restore();
  751. });
  752. it('should update flags', function () {
  753. mainServiceInfoConfigsController._onLoadComplete();
  754. expect(mainServiceInfoConfigsController.get('dataIsLoaded')).to.be.true;
  755. expect(mainServiceInfoConfigsController.get('versionLoaded')).to.be.true;
  756. expect(mainServiceInfoConfigsController.get('isInit')).to.be.false;
  757. });
  758. });
  759. });