assign_master_controller_test.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  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 stringUtils = require('utils/string_utils');
  20. var numberUtils = require('utils/number_utils');
  21. require('models/stack_service_component');
  22. describe('App.AssignMasterOnStep7Controller', function () {
  23. var view;
  24. beforeEach(function () {
  25. view = App.AssignMasterOnStep7Controller.create();
  26. });
  27. describe("#content", function () {
  28. it("content is correct", function () {
  29. view.set('configWidgetContext.controller', Em.Object.create({
  30. content: {'name': 'name'}
  31. }));
  32. view.propertyDidChange('content');
  33. expect(view.get('content')).to.be.eql({'name': 'name'});
  34. });
  35. it("content is null", function () {
  36. view.set('configWidgetContext.controller', Em.Object.create({
  37. content: null
  38. }));
  39. view.propertyDidChange('content');
  40. expect(view.get('content')).to.be.empty;
  41. });
  42. });
  43. describe("#execute()", function () {
  44. var context = Em.Object.create({
  45. controller: {
  46. content: Em.Object.create({
  47. controllerName: ""
  48. })
  49. }
  50. });
  51. beforeEach(function() {
  52. this.mock = sinon.stub(view, 'getAllMissingDependentServices');
  53. sinon.stub(view, 'showInstallServicesPopup');
  54. sinon.stub(view, 'showAssignComponentPopup');
  55. sinon.stub(view, 'removeMasterComponent');
  56. view.reopen({
  57. content: Em.Object.create()
  58. });
  59. });
  60. afterEach(function() {
  61. this.mock.restore();
  62. view.showInstallServicesPopup.restore();
  63. view.showAssignComponentPopup.restore();
  64. view.removeMasterComponent.restore();
  65. });
  66. it("ADD action, controllerName is empty", function() {
  67. this.mock.returns([{}]);
  68. view.execute(context, 'ADD', {componentName: 'C1'});
  69. expect(view.showInstallServicesPopup.calledOnce).to.be.true;
  70. });
  71. it("ADD action, controllerName is set", function() {
  72. context = Em.Object.create({
  73. controller: {
  74. content: Em.Object.create({
  75. controllerName: "ctrl1"
  76. })
  77. }
  78. });
  79. this.mock.returns([{}]);
  80. view.execute(context, 'ADD', {componentName: 'C1'});
  81. expect(view.showAssignComponentPopup.calledOnce).to.be.true;
  82. });
  83. it("ADD action, no dependent services", function() {
  84. this.mock.returns([]);
  85. view.execute(context, 'ADD', {componentName: 'C1'});
  86. expect(view.showAssignComponentPopup.calledOnce).to.be.true;
  87. });
  88. it("DELETE action", function() {
  89. this.mock.returns([{}]);
  90. view.execute(context, 'DELETE', {componentName: 'C1'});
  91. expect(view.removeMasterComponent.calledOnce).to.be.true;
  92. });
  93. });
  94. describe("#showAssignComponentPopup()", function () {
  95. beforeEach(function() {
  96. sinon.stub(view, 'loadMasterComponentHosts');
  97. sinon.stub(App.ModalPopup, 'show');
  98. });
  99. afterEach(function() {
  100. view.loadMasterComponentHosts.restore();
  101. App.ModalPopup.show.restore();
  102. });
  103. it("loadMasterComponentHosts should be called", function() {
  104. view.reopen({
  105. content: {
  106. controllerName: null
  107. }
  108. });
  109. view.showAssignComponentPopup();
  110. expect(view.loadMasterComponentHosts.calledOnce).to.be.true;
  111. expect(App.ModalPopup.show.calledOnce).to.be.true;
  112. });
  113. it("loadMasterComponentHosts should not be called", function() {
  114. view.reopen({
  115. content: {
  116. controllerName: 'ctrl1'
  117. }
  118. });
  119. view.showAssignComponentPopup();
  120. expect(view.loadMasterComponentHosts.called).to.be.false;
  121. expect(App.ModalPopup.show.calledOnce).to.be.true;
  122. });
  123. });
  124. describe("#showInstallServicesPopup()", function () {
  125. var mock = Em.Object.create({
  126. config: Em.Object.create({
  127. initialValue: 'init',
  128. value: '',
  129. displayName: 'c1'
  130. }),
  131. setValue: Em.K,
  132. toggleProperty: Em.K,
  133. sendRequestRorDependentConfigs: Em.K
  134. });
  135. beforeEach(function() {
  136. sinon.stub(stringUtils, 'getFormattedStringFromArray');
  137. sinon.stub(mock, 'setValue');
  138. sinon.stub(mock, 'toggleProperty');
  139. sinon.stub(mock, 'sendRequestRorDependentConfigs');
  140. sinon.spy(App.ModalPopup, 'show');
  141. });
  142. afterEach(function() {
  143. stringUtils.getFormattedStringFromArray.restore();
  144. mock.setValue.restore();
  145. mock.toggleProperty.restore();
  146. mock.sendRequestRorDependentConfigs.restore();
  147. App.ModalPopup.show.restore();
  148. });
  149. it("test", function() {
  150. view.set('configWidgetContext', mock);
  151. var popup = view.showInstallServicesPopup();
  152. expect(App.ModalPopup.show.calledOnce).to.be.true;
  153. popup.onPrimary();
  154. expect(mock.get('config.value')).to.be.equal('init');
  155. expect(mock.setValue.calledWith('init')).to.be.true;
  156. });
  157. });
  158. describe("#removeMasterComponent()", function () {
  159. var mock = {
  160. setDBProperty: Em.K
  161. };
  162. beforeEach(function() {
  163. sinon.stub(App.router, 'get').returns(mock);
  164. sinon.stub(mock, 'setDBProperty');
  165. });
  166. afterEach(function() {
  167. App.router.get.restore();
  168. mock.setDBProperty.restore();
  169. });
  170. it("should set masterComponentHosts", function() {
  171. view.reopen({
  172. content: Em.Object.create({
  173. controllerName: 'ctrl1',
  174. masterComponentHosts: [
  175. {component: 'C1'},
  176. {component: 'C2'}
  177. ],
  178. componentsFromConfigs: ["C1","C2"],
  179. recommendationsHostGroups: {
  180. blueprint: {host_groups: [{name: 'host-group-1', components: [{name: 'C1'}, {name: 'C2'}]}]},
  181. blueprint_cluster_binding: {host_groups: [{name: 'host-group-1', hosts: [{fqdn: 'localhost'}]}]}
  182. }
  183. }),
  184. configWidgetContext: {
  185. config: Em.Object.create()
  186. }
  187. });
  188. view.set('mastersToCreate', ['C2']);
  189. view.removeMasterComponent();
  190. expect(view.get('content.masterComponentHosts')).to.be.eql([{component: 'C1'}]);
  191. expect(view.get('content.recommendationsHostGroups').blueprint).to.be.eql({host_groups: [{name: 'host-group-1', components: [{name: 'C1'}]}]});
  192. });
  193. });
  194. describe("#renderHostInfo()", function () {
  195. beforeEach(function() {
  196. sinon.stub(App.Host, 'find').returns([
  197. Em.Object.create({
  198. hostName: 'host1',
  199. cpu: 1,
  200. memory: 1,
  201. diskInfo: {}
  202. })
  203. ]);
  204. sinon.stub(view, 'sortHosts');
  205. sinon.stub(numberUtils, 'bytesToSize').returns(1);
  206. });
  207. afterEach(function() {
  208. App.Host.find.restore();
  209. view.sortHosts.restore();
  210. numberUtils.bytesToSize.restore();
  211. });
  212. it("should set hosts", function() {
  213. view.reopen({
  214. content: Em.Object.create({
  215. controllerName: null
  216. })
  217. });
  218. view.renderHostInfo();
  219. expect(view.get('hosts')).to.be.eql([Em.Object.create({
  220. host_name: 'host1',
  221. cpu: 1,
  222. memory: 1,
  223. disk_info: {},
  224. host_info: Em.I18n.t('installer.step5.hostInfo').fmt('host1', 1, 1)
  225. })]);
  226. expect(view.sortHosts.calledWith([Em.Object.create({
  227. host_name: 'host1',
  228. cpu: 1,
  229. memory: 1,
  230. disk_info: {},
  231. host_info: Em.I18n.t('installer.step5.hostInfo').fmt('host1', 1, 1)
  232. })])).to.be.true;
  233. });
  234. });
  235. describe("#loadMasterComponentHosts()", function () {
  236. beforeEach(function() {
  237. sinon.stub(App.HostComponent, 'find').returns([
  238. Em.Object.create({
  239. componentName: 'C1'
  240. }),
  241. Em.Object.create({
  242. componentName: 'C2'
  243. })
  244. ]);
  245. sinon.stub(App, 'get').returns(['C2']);
  246. });
  247. afterEach(function() {
  248. App.get.restore();
  249. App.HostComponent.find.restore();
  250. });
  251. it("should set master components", function() {
  252. view.loadMasterComponentHosts();
  253. expect(view.get('masterComponentHosts').mapProperty('component')).to.be.eql(['C2']);
  254. });
  255. });
  256. describe("#getAllMissingDependentServices()", function () {
  257. beforeEach(function() {
  258. sinon.stub(App.StackServiceComponent, 'find').returns(Em.Object.create({
  259. stackService: Em.Object.create({
  260. requiredServices: ['S1', 'S2']
  261. })
  262. }));
  263. sinon.stub(App.Service, 'find').returns([
  264. {serviceName: 'S1'}
  265. ]);
  266. sinon.stub(App.StackService, 'find', function(input) {
  267. return Em.Object.create({displayName: input});
  268. });
  269. });
  270. afterEach(function() {
  271. App.StackServiceComponent.find.restore();
  272. App.Service.find.restore();
  273. App.StackService.find.restore();
  274. });
  275. it("test", function() {
  276. view.set('configActionComponent', Em.Object.create({
  277. componentName: 'C1'
  278. }));
  279. expect(view.getAllMissingDependentServices()).to.be.eql(['S2']);
  280. });
  281. });
  282. describe("#submit()", function () {
  283. var popup = {
  284. hide: Em.K
  285. },
  286. mock = {
  287. saveMasterComponentHosts: Em.K,
  288. loadMasterComponentHosts: Em.K,
  289. setDBProperty: Em.K,
  290. loadConfigRecommendations: Em.K
  291. },
  292. config = Em.Object.create({
  293. filename: 'file1',
  294. name: 'conf1'
  295. });
  296. beforeEach(function() {
  297. sinon.stub(popup, 'hide');
  298. sinon.stub(App.router, 'get').returns(mock);
  299. sinon.stub(mock, 'saveMasterComponentHosts');
  300. sinon.stub(mock, 'loadMasterComponentHosts');
  301. sinon.stub(mock, 'setDBProperty');
  302. sinon.stub(mock, 'loadConfigRecommendations');
  303. view.reopen({
  304. content: Em.Object.create({
  305. controllerName: 'ctrl1',
  306. componentsFromConfigs: []
  307. }),
  308. selectedServicesMasters: [
  309. {
  310. component_name: 'C1',
  311. selectedHost: 'host1'
  312. }
  313. ],
  314. popup: popup,
  315. configActionComponent: {
  316. componentName: 'C1'
  317. },
  318. configWidgetContext: Em.Object.create({
  319. config: Em.Object.create({
  320. configAction: {
  321. hostComponentConfig: {
  322. fileName: 'file1',
  323. configName: 'conf1'
  324. }
  325. },
  326. serviceName: 'S1',
  327. toggleProperty: Em.K
  328. }),
  329. controller: Em.Object.create({
  330. stepConfigs: [
  331. Em.Object.create({
  332. serviceName: 'S1',
  333. configs: [
  334. config
  335. ]
  336. })
  337. ],
  338. loadConfigRecommendations: mock.loadConfigRecommendations
  339. })
  340. })
  341. });
  342. view.submit();
  343. });
  344. afterEach(function() {
  345. App.router.get.restore();
  346. popup.hide.restore();
  347. mock.saveMasterComponentHosts.restore();
  348. mock.loadMasterComponentHosts.restore();
  349. mock.setDBProperty.restore();
  350. mock.loadConfigRecommendations.restore();
  351. });
  352. it("saveMasterComponentHosts should be called", function() {
  353. expect(mock.saveMasterComponentHosts.calledOnce).to.be.true;
  354. });
  355. it("loadMasterComponentHosts�������������������������� should be called", function() {
  356. expect(mock.loadMasterComponentHosts.calledOnce).to.be.true;
  357. });
  358. it("configActionComponent should be set", function() {
  359. expect(view.get('configWidgetContext.config.configActionComponent')).to.be.eql({
  360. componentName: 'C1',
  361. hostName: 'host1'
  362. });
  363. });
  364. it("config should be set", function() {
  365. expect(config.get('value')).to.be.equal('host1');
  366. expect(config.get('recommendedValue')).to.be.equal('host1');
  367. });
  368. it("config should be set (loadConfigRecommendations is called once)", function() {
  369. expect(mock.loadConfigRecommendations.calledOnce).to.be.true;
  370. });
  371. });
  372. });