wizard_controller_test.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  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/admin/highAvailability/journalNode/wizard_controller');
  20. describe('App.ManageJournalNodeWizardController', function () {
  21. var controller;
  22. beforeEach(function () {
  23. controller = App.ManageJournalNodeWizardController.create({
  24. content: Em.Object.create(),
  25. currentStep: 0
  26. });
  27. });
  28. describe('#setCurrentStep', function() {
  29. beforeEach(function() {
  30. sinon.stub(App.clusterStatus, 'setClusterStatus');
  31. });
  32. afterEach(function() {
  33. App.clusterStatus.setClusterStatus.restore();
  34. });
  35. it('setCurrentStep should be called', function() {
  36. controller.setCurrentStep(1, true);
  37. expect(App.clusterStatus.setClusterStatus.calledOnce).to.be.true;
  38. });
  39. });
  40. describe('#getCluster', function() {
  41. beforeEach(function() {
  42. sinon.stub(App.router, 'getClusterName').returns('c1');
  43. });
  44. afterEach(function() {
  45. App.router.getClusterName.restore();
  46. });
  47. it('should return cluster object', function() {
  48. controller.set('clusterStatusTemplate', {});
  49. expect(controller.getCluster()).to.be.eql({
  50. name: 'c1'
  51. });
  52. });
  53. });
  54. describe('#getJournalNodesToAdd', function() {
  55. it('should return journalnodes hosts array', function() {
  56. controller.set('content.masterComponentHosts', [
  57. Em.Object.create({
  58. component: 'JOURNALNODE',
  59. isInstalled: false,
  60. hostName: 'host1'
  61. })
  62. ]);
  63. expect(controller.getJournalNodesToAdd()).to.be.eql(['host1']);
  64. });
  65. it('should return empty array', function() {
  66. controller.set('content.masterComponentHosts', null);
  67. expect(controller.getJournalNodesToAdd()).to.be.empty;
  68. });
  69. });
  70. describe('#getJournalNodesToDelete', function() {
  71. beforeEach(function() {
  72. sinon.stub(App.HostComponent, 'find').returns([
  73. Em.Object.create({
  74. componentName: 'JOURNALNODE',
  75. hostName: 'host2'
  76. }),
  77. Em.Object.create({
  78. componentName: 'JOURNALNODE',
  79. hostName: 'host1'
  80. })
  81. ]);
  82. });
  83. afterEach(function() {
  84. App.HostComponent.find.restore();
  85. });
  86. it('should return empty array', function() {
  87. controller.set('content.masterComponentHosts', null);
  88. expect(controller.getJournalNodesToDelete()).to.be.empty;
  89. });
  90. it('should return journalnodes hosts array', function() {
  91. controller.set('content.masterComponentHosts', [
  92. Em.Object.create({
  93. component: 'JOURNALNODE',
  94. isInstalled: false,
  95. hostName: 'host1'
  96. })
  97. ]);
  98. expect(controller.getJournalNodesToDelete()).to.be.eql([
  99. 'host2'
  100. ]);
  101. });
  102. });
  103. describe('#isDeleteOnly', function() {
  104. beforeEach(function() {
  105. this.mockAdd = sinon.stub(controller, 'getJournalNodesToAdd').returns([]);
  106. this.mockDelete = sinon.stub(controller, 'getJournalNodesToDelete').returns([]);
  107. });
  108. afterEach(function() {
  109. this.mockDelete.restore();
  110. this.mockAdd.restore();
  111. });
  112. it('should return false when currentStep less than 2nd', function() {
  113. controller.set('currentStep', 1);
  114. expect(controller.get('isDeleteOnly')).to.be.false;
  115. });
  116. it('should return false when there are nodes to add', function() {
  117. this.mockAdd.returns(['host1']);
  118. controller.set('currentStep', 2);
  119. controller.propertyDidChange('isDeleteOnly');
  120. expect(controller.get('isDeleteOnly')).to.be.false;
  121. });
  122. it('should return false when there are no nodes to delete', function() {
  123. this.mockAdd.returns([]);
  124. this.mockDelete.returns([]);
  125. controller.set('currentStep', 2);
  126. controller.propertyDidChange('isDeleteOnly');
  127. expect(controller.get('isDeleteOnly')).to.be.false;
  128. });
  129. it('should return true when there are nodes to delete', function() {
  130. this.mockAdd.returns([]);
  131. this.mockDelete.returns(['host1']);
  132. controller.set('currentStep', 2);
  133. controller.propertyDidChange('isDeleteOnly');
  134. expect(controller.get('isDeleteOnly')).to.be.true;
  135. });
  136. });
  137. describe('#saveServiceConfigProperties', function() {
  138. beforeEach(function() {
  139. sinon.stub(controller, 'setDBProperty');
  140. });
  141. afterEach(function() {
  142. controller.setDBProperty.restore();
  143. });
  144. it('serviceConfigProperties should be set', function() {
  145. var stepCtrl = Em.Object.create({
  146. serverConfigData: {
  147. items: [{
  148. type: 'file1',
  149. properties: {
  150. c1: 'val1'
  151. }
  152. }]
  153. },
  154. stepConfigs: [
  155. Em.Object.create({
  156. configs: [
  157. Em.Object.create({
  158. name: 'c1',
  159. value: 'val1',
  160. filename: 'file1'
  161. })
  162. ]
  163. })
  164. ]
  165. });
  166. controller.saveServiceConfigProperties(stepCtrl);
  167. expect(JSON.stringify(controller.get('content.serviceConfigProperties'))).to.be.eql(JSON.stringify({
  168. "items": [
  169. {
  170. "type": "file1",
  171. "properties": {
  172. "c1": "val1"
  173. }
  174. }
  175. ]
  176. }));
  177. expect(controller.setDBProperty.calledWith('serviceConfigProperties', {
  178. "items": [
  179. {
  180. "type": "file1",
  181. "properties": {
  182. "c1": "val1"
  183. }
  184. }
  185. ]
  186. })).to.be.true;
  187. });
  188. });
  189. describe('#loadServiceConfigProperties', function() {
  190. beforeEach(function() {
  191. sinon.stub(controller, 'getDBProperty').returns({});
  192. });
  193. it('serviceConfigProperties should be set', function() {
  194. controller.loadServiceConfigProperties();
  195. expect(controller.get('content.serviceConfigProperties')).to.be.eql({});
  196. });
  197. });
  198. describe('#saveNNs', function() {
  199. beforeEach(function() {
  200. sinon.stub(App.HostComponent, 'find').returns([
  201. {
  202. displayNameAdvanced: 'Active NameNode'
  203. },
  204. {
  205. displayNameAdvanced: 'Standby NameNode'
  206. }
  207. ]);
  208. sinon.stub(controller, 'setDBProperty');
  209. });
  210. afterEach(function() {
  211. controller.setDBProperty.restore();
  212. App.HostComponent.find.restore();
  213. });
  214. it('NameNodes should be set', function() {
  215. controller.saveNNs();
  216. expect(controller.get('content.activeNN')).to.be.eql({
  217. displayNameAdvanced: 'Active NameNode'
  218. });
  219. expect(controller.get('content.standByNN')).to.be.eql({
  220. displayNameAdvanced: 'Standby NameNode'
  221. });
  222. });
  223. it('setDBProperty should be called', function() {
  224. controller.saveNNs();
  225. expect(controller.setDBProperty.calledWith('activeNN', {
  226. displayNameAdvanced: 'Active NameNode'
  227. })).to.be.true;
  228. expect(controller.setDBProperty.calledWith('standByNN', {
  229. displayNameAdvanced: 'Standby NameNode'
  230. })).to.be.true;
  231. });
  232. });
  233. describe('#loadNNs', function() {
  234. beforeEach(function() {
  235. sinon.stub(controller, 'getDBProperty').returns({});
  236. });
  237. it('NameNodes should be set', function() {
  238. controller.loadNNs();
  239. expect(controller.get('content.activeNN')).to.be.eql({});
  240. expect(controller.get('content.standByNN')).to.be.eql({});
  241. });
  242. });
  243. describe('#loadConfigTag', function() {
  244. beforeEach(function() {
  245. sinon.stub(App.db, 'getManageJournalNodeWizardConfigTag').returns('val1');
  246. });
  247. it('should load config tag', function() {
  248. controller.loadConfigTag('tag1');
  249. expect(App.db.getManageJournalNodeWizardConfigTag.calledWith('tag1')).to.be.true;
  250. expect(controller.get('content.tag1')).to.be.equal('val1');
  251. });
  252. });
  253. describe('#saveConfigTag', function() {
  254. beforeEach(function() {
  255. sinon.stub(App.db, 'setManageJournalNodeWizardConfigTag');
  256. });
  257. it('should save config tag', function() {
  258. controller.saveConfigTag({name: 'tag1', value: 'val1'});
  259. expect(App.db.setManageJournalNodeWizardConfigTag.calledWith({name: 'tag1', value: 'val1'})).to.be.true;
  260. expect(controller.get('content.tag1')).to.be.equal('val1');
  261. });
  262. });
  263. describe('#saveNameServiceIds', function() {
  264. beforeEach(function() {
  265. sinon.stub(controller, 'setDBProperty');
  266. });
  267. it('nameServiceId should be set', function() {
  268. controller.saveNameServiceIds(['id0', 'id1']);
  269. expect(controller.setDBProperty.calledWith('nameServiceIds', ['id0', 'id1'])).to.be.true;
  270. expect(controller.get('content.nameServiceIds')).to.eql(['id0', 'id1']);
  271. });
  272. });
  273. describe('#loadNameServiceIds', function() {
  274. beforeEach(function() {
  275. sinon.stub(controller, 'getDBProperty').returns(['id0', 'id1']);
  276. });
  277. it('nameServiceId should be set', function() {
  278. controller.loadNameServiceIds();
  279. expect(controller.get('content.nameServiceIds')).to.eql(['id0', 'id1']);
  280. });
  281. });
  282. describe('#clearAllSteps', function() {
  283. beforeEach(function() {
  284. sinon.stub(controller, 'clearInstallOptions');
  285. sinon.stub(controller, 'getCluster').returns({name: 'c1'});
  286. });
  287. it('cluster should be set and clearInstallOptions should be called', function() {
  288. controller.clearAllSteps();
  289. expect(controller.get('content.cluster')).to.be.eql({name: 'c1'});
  290. expect(controller.clearInstallOptions.calledOnce).to.be.true;
  291. });
  292. });
  293. describe('#clearTasksData', function() {
  294. beforeEach(function() {
  295. sinon.stub(controller, 'saveTasksStatuses');
  296. sinon.stub(controller, 'saveRequestIds');
  297. sinon.stub(controller, 'saveTasksRequestIds');
  298. controller.clearTasksData();
  299. });
  300. afterEach(function() {
  301. controller.saveTasksRequestIds.restore();
  302. controller.saveRequestIds.restore();
  303. controller.saveTasksStatuses.restore();
  304. });
  305. it('saveTasksStatuses should be called', function() {
  306. expect(controller.saveTasksStatuses.calledWith(undefined)).to.be.true;
  307. });
  308. it('saveRequestIds should be called', function() {
  309. expect(controller.saveRequestIds.calledWith(undefined)).to.be.true;
  310. });
  311. it('saveTasksRequestIds should be called', function() {
  312. expect(controller.saveTasksRequestIds.calledWith(undefined)).to.be.true;
  313. });
  314. });
  315. describe('#finish', function() {
  316. var mock = {
  317. updateAll: Em.K
  318. };
  319. beforeEach(function() {
  320. sinon.stub(App.router, 'get').returns(mock);
  321. sinon.spy(mock, 'updateAll');
  322. sinon.stub(controller, 'resetDbNamespace');
  323. controller.finish();
  324. });
  325. afterEach(function() {
  326. controller.resetDbNamespace.restore();
  327. mock.updateAll.restore();
  328. App.router.get.restore();
  329. });
  330. it('resetDbNamespace should be called', function() {
  331. expect(controller.resetDbNamespace.calledOnce).to.be.true;
  332. });
  333. it('updateAll should be called', function() {
  334. expect(mock.updateAll.calledOnce).to.be.true;
  335. });
  336. });
  337. });