manage_config_groups_controller_test.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  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 c;
  20. describe('App.ManageConfigGroupsController', function() {
  21. var controller = App.ManageConfigGroupsController.create({});
  22. beforeEach(function() {
  23. c = App.ManageConfigGroupsController.create({});
  24. });
  25. var manageConfigGroupsController = App.ManageConfigGroupsController.create({});
  26. describe('#addConfigGroup', function() {
  27. beforeEach(function() {
  28. manageConfigGroupsController.addConfigGroup();
  29. });
  30. describe("#validate", function() {
  31. it("should display no warning if user inputs valid characters into group name", function() {
  32. manageConfigGroupsController.addGroupPopup.set('configGroupName', 'hello');
  33. expect(manageConfigGroupsController.addGroupPopup.warningMessage).to.be.empty;
  34. });
  35. it("should display warning if user inputs invalid characters into group name", function() {
  36. manageConfigGroupsController.addGroupPopup.set('configGroupName', '/{"!@#$%');
  37. expect(manageConfigGroupsController.addGroupPopup.warningMessage).to.equal('Invalid Group Name. Only alphanumerics, hyphens, spaces and underscores are allowed.');
  38. });
  39. });
  40. });
  41. describe('#renameConfigGroup', function() {
  42. beforeEach(function() {
  43. var configGroup = Ember.Object.create ({
  44. name: 'name',
  45. description: 'description'
  46. });
  47. manageConfigGroupsController.set('selectedConfigGroup', configGroup);
  48. manageConfigGroupsController.renameConfigGroup();
  49. });
  50. describe("#validate", function() {
  51. it("should display no warning if user inputs valid characters into group name", function() {
  52. manageConfigGroupsController.renameGroupPopup.set('configGroupName', 'hello');
  53. expect(manageConfigGroupsController.renameGroupPopup.warningMessage).to.be.empty;
  54. });
  55. it("should display warning if user inputs invalid characters into group name", function() {
  56. manageConfigGroupsController.renameGroupPopup.set('configGroupName', '/{"!@#$%');
  57. expect(manageConfigGroupsController.renameGroupPopup.warningMessage).to.equal('Invalid Group Name. Only alphanumerics, hyphens, spaces and underscores are allowed.');
  58. });
  59. });
  60. });
  61. describe('#addHostsCallback', function() {
  62. beforeEach(function() {
  63. c.reopen({
  64. selectedConfigGroup: Em.Object.create({
  65. hosts: ['h1'],
  66. parentConfigGroup: Em.Object.create({
  67. hosts: ['h2', 'h3']
  68. })
  69. })
  70. });
  71. });
  72. it('should set hosts to selectedConfigGroup and remove them form default group', function () {
  73. c.addHostsCallback(['h2', 'h3']);
  74. expect(c.get('selectedConfigGroup.hosts')).to.include.members(['h1','h2','h3']);
  75. expect(c.get('selectedConfigGroup.parentConfigGroup.hosts').toArray()).to.be.empty;
  76. });
  77. });
  78. describe('#isHostsModified', function () {
  79. Em.A([
  80. {
  81. o: {
  82. toClearHosts: [],
  83. toDelete: [],
  84. toSetHosts: [],
  85. toCreate: []
  86. },
  87. e: false
  88. },
  89. {
  90. o: {
  91. toClearHosts: [{}],
  92. toDelete: [],
  93. toSetHosts: [],
  94. toCreate: []
  95. },
  96. e: true
  97. },
  98. {
  99. o: {
  100. toClearHosts: [],
  101. toDelete: [{}],
  102. toSetHosts: [],
  103. toCreate: []
  104. },
  105. e: true
  106. },
  107. {
  108. o: {
  109. toClearHosts: [],
  110. toDelete: [],
  111. toSetHosts: [{}],
  112. toCreate: []
  113. },
  114. e: true
  115. },
  116. {
  117. o: {
  118. toClearHosts: [],
  119. toDelete: [],
  120. toSetHosts: [],
  121. toCreate: [{}]
  122. },
  123. e: true
  124. }
  125. ]).forEach(function (test, index) {
  126. it('test #' + index, function () {
  127. c.reopen({
  128. isLoaded: true,
  129. hostsModifiedConfigGroups: test.o
  130. });
  131. expect(c.get('isHostsModified')).to.equal(test.e);
  132. });
  133. });
  134. });
  135. describe('#deleteConfigGroup', function () {
  136. beforeEach(function() {
  137. var defaultGroup = Em.Object.create({
  138. hosts: ['h2', 'h3'],
  139. isDefault: true
  140. });
  141. var selectedGroup = Em.Object.create({
  142. hosts: ['h1'],
  143. parentConfigGroup: defaultGroup
  144. });
  145. c.reopen({
  146. configGroups: [defaultGroup, selectedGroup],
  147. selectedConfigGroup: selectedGroup
  148. });
  149. sinon.stub(App.configGroupsMapper, 'deleteRecord', Em.K);
  150. });
  151. afterEach(function(){
  152. App.configGroupsMapper.deleteRecord.restore();
  153. });
  154. it('after deleting some config group, Default should be selected', function () {
  155. c.deleteConfigGroup();
  156. expect(c.get('configGroups.length')).to.equal(1);
  157. expect(c.get('selectedConfigGroup.hosts')).to.include.members(['h1','h2','h3']);
  158. expect(c.get('selectedConfigGroup.isDefault')).to.be.true;
  159. });
  160. });
  161. describe("#manageConfigurationGroups", function () {
  162. var service = Em.Object.create({});
  163. manageConfigGroupsController.set('hostsModifiedConfigGroups', {});
  164. describe("#controller passed", function () {
  165. controller = Em.Object.create({
  166. content: Em.Object.create()
  167. });
  168. var popup = manageConfigGroupsController.manageConfigurationGroups(controller, service);
  169. describe("#onPrimary()", function () {
  170. beforeEach(function () {
  171. sinon.stub(popup, 'onPrimaryWizard', Em.K);
  172. });
  173. afterEach(function () {
  174. popup.onPrimaryWizard.restore();
  175. });
  176. it("onPrimaryWizard is called", function () {
  177. popup.onPrimary();
  178. expect(popup.onPrimaryWizard.calledOnce).to.be.true;
  179. });
  180. });
  181. describe("#onPrimaryWizard()", function () {
  182. var ctrl = Em.Object.create({
  183. selectedService: Em.Object.create({
  184. selected: false
  185. }),
  186. selectedServiceObserver: Em.K,
  187. setGroupsToDelete: Em.K
  188. });
  189. beforeEach(function () {
  190. sinon.spy(ctrl, 'selectedServiceObserver');
  191. sinon.spy(ctrl, 'setGroupsToDelete');
  192. sinon.stub(manageConfigGroupsController, 'persistConfigGroups', Em.K);
  193. sinon.stub(popup, 'updateConfigGroupOnServicePage', Em.K);
  194. sinon.stub(popup, 'hide', Em.K);
  195. });
  196. afterEach(function () {
  197. ctrl.setGroupsToDelete.restore();
  198. ctrl.selectedServiceObserver.restore();
  199. manageConfigGroupsController.persistConfigGroups.restore();
  200. popup.updateConfigGroupOnServicePage.restore();
  201. popup.hide.restore();
  202. });
  203. describe("groups deleted on 7th step", function () {
  204. beforeEach(function () {
  205. ctrl.set('name', 'wizardStep7Controller');
  206. popup.onPrimaryWizard(ctrl, {toDelete: [1]});
  207. });
  208. it('selectedServiceObserver is called once', function () {
  209. expect(ctrl.selectedServiceObserver.calledOnce).to.be.true;
  210. });
  211. it('setGroupsToDelete is called with [1]', function () {
  212. expect(ctrl.setGroupsToDelete.calledWith([1])).to.be.true;
  213. });
  214. it('persistConfigGroups is called once', function () {
  215. expect(manageConfigGroupsController.persistConfigGroups.calledOnce).to.be.true;
  216. });
  217. it('updateConfigGroupOnServicePage is called once', function () {
  218. expect(popup.updateConfigGroupOnServicePage.calledOnce).to.be.true;
  219. });
  220. it('hide is called once', function () {
  221. expect(popup.hide.calledOnce).to.be.true;
  222. });
  223. });
  224. describe("wizard not on 7th step", function () {
  225. beforeEach(function () {
  226. ctrl.set('name', '');
  227. popup.onPrimaryWizard(ctrl, {});
  228. });
  229. it('selectedServiceObserver is called once', function () {
  230. expect(ctrl.selectedServiceObserver.calledOnce).to.be.true;
  231. });
  232. it('setGroupsToDelete is not called', function () {
  233. expect(ctrl.setGroupsToDelete.called).to.be.false;
  234. });
  235. it('persistConfigGroups is not called', function () {
  236. expect(manageConfigGroupsController.persistConfigGroups.called).to.be.false;
  237. });
  238. it('updateConfigGroupOnServicePage is not called', function () {
  239. expect(popup.updateConfigGroupOnServicePage.called).to.be.false;
  240. });
  241. it('hide is called once', function () {
  242. expect(popup.hide.calledOnce).to.be.true;
  243. });
  244. });
  245. describe("wizard on 7th step, service selected", function () {
  246. beforeEach(function () {
  247. ctrl.set('name', 'wizardStep7Controller');
  248. ctrl.set('selectedService.selected', true);
  249. popup.onPrimaryWizard(ctrl, {toDelete: [1]});
  250. });
  251. it('selectedServiceObserver is called once', function () {
  252. expect(ctrl.selectedServiceObserver.calledOnce).to.be.true;
  253. });
  254. it('setGroupsToDelete is not called', function () {
  255. expect(ctrl.setGroupsToDelete.called).to.be.false;
  256. });
  257. it('persistConfigGroups is called once', function () {
  258. expect(manageConfigGroupsController.persistConfigGroups.calledOnce).to.be.true;
  259. });
  260. it('updateConfigGroupOnServicePage is called once', function () {
  261. expect(popup.updateConfigGroupOnServicePage.calledOnce).to.be.true;
  262. });
  263. it('hide is called once', function () {
  264. expect(popup.hide.calledOnce).to.be.true;
  265. });
  266. });
  267. describe("wizard on 7th step, no groups to delete", function () {
  268. beforeEach(function () {
  269. ctrl.set('name', 'wizardStep7Controller');
  270. ctrl.set('selectedService.selected', false);
  271. popup.onPrimaryWizard(ctrl, {toDelete: []});
  272. });
  273. it('selectedServiceObserver is called once', function () {
  274. expect(ctrl.selectedServiceObserver.calledOnce).to.be.true;
  275. });
  276. it('setGroupsToDelete is not called', function () {
  277. expect(ctrl.setGroupsToDelete.called).to.be.false;
  278. });
  279. it('persistConfigGroups is called once', function () {
  280. expect(manageConfigGroupsController.persistConfigGroups.calledOnce).to.be.true;
  281. });
  282. it('updateConfigGroupOnServicePage is called once', function () {
  283. expect(popup.updateConfigGroupOnServicePage.calledOnce).to.be.true;
  284. });
  285. it('hide is called once', function () {
  286. expect(popup.hide.calledOnce).to.be.true;
  287. });
  288. });
  289. });
  290. });
  291. describe("#controller not passed", function () {
  292. var popup = manageConfigGroupsController.manageConfigurationGroups(null, service);
  293. describe("#onPrimary()", function () {
  294. beforeEach(function () {
  295. sinon.stub(popup, 'runClearCGQueue').returns({
  296. done: function (callback) {
  297. callback();
  298. }
  299. });
  300. sinon.stub(popup, 'runModifyCGQueue').returns({
  301. done: function (callback) {
  302. callback();
  303. }
  304. });
  305. sinon.stub(popup, 'runCreateCGQueue').returns({
  306. done: function (callback) {
  307. callback();
  308. }
  309. });
  310. sinon.stub(popup, 'updateConfigGroupOnServicePage', Em.K);
  311. sinon.stub(popup, 'hide', Em.K);
  312. manageConfigGroupsController.set('hostsModifiedConfigGroups', {toCreate: []});
  313. popup.onPrimary();
  314. });
  315. afterEach(function () {
  316. popup.runCreateCGQueue.restore();
  317. popup.runModifyCGQueue.restore();
  318. popup.runClearCGQueue.restore();
  319. popup.updateConfigGroupOnServicePage.restore();
  320. popup.hide.restore();
  321. });
  322. it("runClearCGQueue is called", function () {
  323. expect(popup.runClearCGQueue.calledOnce).to.be.true;
  324. });
  325. it("runModifyCGQueue is called", function () {
  326. expect(popup.runModifyCGQueue.calledOnce).to.be.true;
  327. });
  328. it("runCreateCGQueue is called", function () {
  329. expect(popup.runCreateCGQueue.calledOnce).to.be.true;
  330. });
  331. it("updateConfigGroupOnServicePage is called", function () {
  332. expect(popup.updateConfigGroupOnServicePage.calledOnce).to.be.true;
  333. });
  334. it("hide is called", function () {
  335. expect(popup.hide.calledOnce).to.be.true;
  336. });
  337. });
  338. describe("#runClearCGQueue()", function () {
  339. beforeEach(function () {
  340. sinon.stub(manageConfigGroupsController, 'updateConfigurationGroup', Em.K);
  341. sinon.stub(manageConfigGroupsController, 'deleteConfigurationGroup', Em.K);
  342. popup.runClearCGQueue(Em.K, {
  343. initialGroups: [],
  344. toClearHosts: [Em.Object.create()],
  345. toDelete: [1]
  346. });
  347. });
  348. afterEach(function () {
  349. manageConfigGroupsController.updateConfigurationGroup.restore();
  350. manageConfigGroupsController.deleteConfigurationGroup.restore();
  351. });
  352. it("updateConfigurationGroup is called once", function () {
  353. expect(manageConfigGroupsController.updateConfigurationGroup.calledOnce).to.be.true;
  354. });
  355. it("deleteConfigurationGroup is called once", function () {
  356. expect(manageConfigGroupsController.deleteConfigurationGroup.calledOnce).to.be.true;
  357. });
  358. });
  359. describe("#runModifyCGQueue()", function () {
  360. beforeEach(function () {
  361. sinon.stub(manageConfigGroupsController, 'updateConfigurationGroup', Em.K);
  362. });
  363. afterEach(function () {
  364. manageConfigGroupsController.updateConfigurationGroup.restore();
  365. });
  366. it("updateConfigurationGroup is called once", function () {
  367. popup.runModifyCGQueue(Em.K, {toSetHosts: [1]});
  368. expect(manageConfigGroupsController.updateConfigurationGroup.calledOnce).to.be.true;
  369. });
  370. });
  371. describe("#runCreateCGQueue()", function () {
  372. beforeEach(function () {
  373. sinon.stub(manageConfigGroupsController, 'postNewConfigurationGroup', Em.K);
  374. });
  375. afterEach(function () {
  376. manageConfigGroupsController.postNewConfigurationGroup.restore();
  377. });
  378. it("postNewConfigurationGroup is called once", function () {
  379. popup.runCreateCGQueue(Em.K, {toCreate: [1]});
  380. expect(manageConfigGroupsController.postNewConfigurationGroup.calledOnce).to.be.true;
  381. });
  382. });
  383. });
  384. });
  385. describe('#_onLoadPropertiesSuccess', function () {
  386. var data = {
  387. items: [
  388. {
  389. type: 'type1',
  390. tag: 'tag1',
  391. properties: {
  392. prop1: 'val1',
  393. prop2: 'val2'
  394. }
  395. },
  396. {
  397. type: 'type1',
  398. tag: 'tag2',
  399. properties: {
  400. prop3: 'val3'
  401. }
  402. },
  403. {
  404. type: 'type2',
  405. tag: 'tag1',
  406. properties: {
  407. prop4: 'val4'
  408. }
  409. }
  410. ]
  411. };
  412. var params = {
  413. typeTagToGroupMap: {
  414. 'type1///tag1': 'group1',
  415. 'type1///tag2': 'group2',
  416. 'type2///tag1': 'group3'
  417. }
  418. };
  419. var configGroups = [
  420. Em.Object.create({
  421. name: 'group1',
  422. properties: []
  423. }),
  424. Em.Object.create({
  425. name: 'group2',
  426. properties: []
  427. }),
  428. Em.Object.create({
  429. name: 'group3',
  430. properties: []
  431. }),
  432. Em.Object.create({
  433. name: 'group4',
  434. properties: []
  435. })
  436. ];
  437. beforeEach(function () {
  438. sinon.stub(c, 'resortConfigGroup', Em.K);
  439. });
  440. afterEach(function () {
  441. c.resortConfigGroup.restore();
  442. });
  443. it('should set properties to config groups', function () {
  444. c.set('configGroups', configGroups);
  445. c._onLoadPropertiesSuccess(data, null, params);
  446. expect(JSON.stringify(c.get('configGroups'))).to.equal(JSON.stringify([
  447. Em.Object.create({
  448. properties: [
  449. {
  450. name: 'prop1',
  451. value: 'val1',
  452. type: 'type1'
  453. },
  454. {
  455. name: 'prop2',
  456. value: 'val2',
  457. type: 'type1'
  458. }
  459. ],
  460. name: 'group1'
  461. }),
  462. Em.Object.create({
  463. properties: [
  464. {
  465. name: 'prop3',
  466. value: 'val3',
  467. type: 'type1'
  468. }
  469. ],
  470. name: 'group2'
  471. }),
  472. Em.Object.create({
  473. properties: [
  474. {
  475. name: 'prop4',
  476. value: 'val4',
  477. type: 'type2'
  478. }
  479. ],
  480. name: 'group3'
  481. }),
  482. Em.Object.create({
  483. properties: [],
  484. name: 'group4'
  485. })
  486. ]));
  487. });
  488. });
  489. describe('#componentsForFilter', function () {
  490. beforeEach(function () {
  491. sinon.stub(App.StackServiceComponent, 'find', function () {
  492. return [
  493. Em.Object.create({
  494. serviceName: 'HDFS'
  495. }),
  496. Em.Object.create({
  497. serviceName: 'noHDFS'
  498. }),
  499. Em.Object.create({
  500. serviceName: 'HDFS'
  501. })
  502. ];
  503. });
  504. c.set('serviceName', 'HDFS');
  505. });
  506. afterEach(function () {
  507. App.StackServiceComponent.find.restore();
  508. });
  509. it('should map components for current service', function () {
  510. expect(c.get('componentsForFilter')).to.have.property('length').equal(2);
  511. });
  512. it('no one is selected', function () {
  513. expect(c.get('componentsForFilter').mapProperty('selected')).to.be.eql([false, false]);
  514. });
  515. });
  516. });