assign_master_controller_test.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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. });
  134. beforeEach(function() {
  135. sinon.stub(stringUtils, 'getFormattedStringFromArray');
  136. sinon.stub(mock, 'setValue');
  137. sinon.stub(mock, 'toggleProperty');
  138. sinon.spy(App.ModalPopup, 'show');
  139. });
  140. afterEach(function() {
  141. stringUtils.getFormattedStringFromArray.restore();
  142. mock.setValue.restore();
  143. mock.toggleProperty.restore();
  144. App.ModalPopup.show.restore();
  145. });
  146. it("test", function() {
  147. view.set('configWidgetContext', mock);
  148. var popup = view.showInstallServicesPopup();
  149. expect(App.ModalPopup.show.calledOnce).to.be.true;
  150. popup.onPrimary();
  151. expect(mock.get('config.value')).to.be.equal('init');
  152. expect(mock.setValue.calledWith('init')).to.be.true;
  153. });
  154. });
  155. describe("#removeMasterComponent()", function () {
  156. var mock = {
  157. setDBProperty: Em.K
  158. };
  159. beforeEach(function() {
  160. sinon.stub(App.router, 'get').returns(mock);
  161. sinon.stub(mock, 'setDBProperty');
  162. });
  163. afterEach(function() {
  164. App.router.get.restore();
  165. mock.setDBProperty.restore();
  166. });
  167. it("should set masterComponentHosts", function() {
  168. view.reopen({
  169. content: Em.Object.create({
  170. controllerName: 'ctrl1',
  171. masterComponentHosts: [
  172. {component: 'C1'},
  173. {component: 'C2'}
  174. ],
  175. recommendationsHostGroups: {
  176. blueprint: {host_groups: [{name: 'host-group-1', components: [{name: 'C1'}, {name: 'C2'}]}]},
  177. blueprint_cluster_binding: {host_groups: [{name: 'host-group-1', hosts: [{fqdn: 'localhost'}]}]}
  178. }
  179. }),
  180. configWidgetContext: {
  181. config: Em.Object.create()
  182. }
  183. });
  184. view.set('mastersToCreate', ['C2']);
  185. view.removeMasterComponent();
  186. expect(view.get('content.masterComponentHosts')).to.be.eql([{component: 'C1'}]);
  187. expect(view.get('content.recommendationsHostGroups').blueprint).to.be.eql({host_groups: [{name: 'host-group-1', components: [{name: 'C1'}]}]});
  188. expect(mock.setDBProperty.calledWith('masterComponentHosts', [{component: 'C1'}])).to.be.true;
  189. });
  190. });
  191. describe("#renderHostInfo()", function () {
  192. beforeEach(function() {
  193. sinon.stub(App.Host, 'find').returns([
  194. Em.Object.create({
  195. hostName: 'host1',
  196. cpu: 1,
  197. memory: 1,
  198. diskInfo: {}
  199. })
  200. ]);
  201. sinon.stub(view, 'sortHosts');
  202. sinon.stub(numberUtils, 'bytesToSize').returns(1);
  203. });
  204. afterEach(function() {
  205. App.Host.find.restore();
  206. view.sortHosts.restore();
  207. numberUtils.bytesToSize.restore();
  208. });
  209. it("should set hosts", function() {
  210. view.reopen({
  211. content: Em.Object.create({
  212. controllerName: null
  213. })
  214. });
  215. view.renderHostInfo();
  216. expect(view.get('hosts')).to.be.eql([Em.Object.create({
  217. host_name: 'host1',
  218. cpu: 1,
  219. memory: 1,
  220. disk_info: {},
  221. host_info: Em.I18n.t('installer.step5.hostInfo').fmt('host1', 1, 1)
  222. })]);
  223. expect(view.sortHosts.calledWith([Em.Object.create({
  224. host_name: 'host1',
  225. cpu: 1,
  226. memory: 1,
  227. disk_info: {},
  228. host_info: Em.I18n.t('installer.step5.hostInfo').fmt('host1', 1, 1)
  229. })])).to.be.true;
  230. });
  231. });
  232. describe("#loadMasterComponentHosts()", function () {
  233. beforeEach(function() {
  234. sinon.stub(App.HostComponent, 'find').returns([
  235. Em.Object.create({
  236. componentName: 'C1'
  237. }),
  238. Em.Object.create({
  239. componentName: 'C2'
  240. })
  241. ]);
  242. sinon.stub(App, 'get').returns(['C2']);
  243. });
  244. afterEach(function() {
  245. App.get.restore();
  246. App.HostComponent.find.restore();
  247. });
  248. it("should set master components", function() {
  249. view.loadMasterComponentHosts();
  250. expect(view.get('masterComponentHosts').mapProperty('component')).to.be.eql(['C2']);
  251. });
  252. });
  253. describe("#getAllMissingDependentServices()", function () {
  254. beforeEach(function() {
  255. sinon.stub(App.StackServiceComponent, 'find').returns(Em.Object.create({
  256. stackService: Em.Object.create({
  257. requiredServices: ['S1', 'S2']
  258. })
  259. }));
  260. sinon.stub(App.Service, 'find').returns([
  261. {serviceName: 'S1'}
  262. ]);
  263. sinon.stub(App.StackService, 'find', function(input) {
  264. return Em.Object.create({displayName: input});
  265. });
  266. });
  267. afterEach(function() {
  268. App.StackServiceComponent.find.restore();
  269. App.Service.find.restore();
  270. App.StackService.find.restore();
  271. });
  272. it("test", function() {
  273. view.set('configActionComponent', Em.Object.create({
  274. componentName: 'C1'
  275. }));
  276. expect(view.getAllMissingDependentServices()).to.be.eql(['S2']);
  277. });
  278. });
  279. describe("#submit()", function () {
  280. var popup = {
  281. hide: Em.K
  282. },
  283. mock = {
  284. saveMasterComponentHosts: Em.K,
  285. loadMasterComponentHosts: Em.K,
  286. setDBProperty: Em.K
  287. },
  288. config = Em.Object.create({
  289. filename: 'file1',
  290. name: 'conf1'
  291. });
  292. beforeEach(function() {
  293. sinon.stub(popup, 'hide');
  294. sinon.stub(App.router, 'get').returns(mock);
  295. sinon.stub(mock, 'saveMasterComponentHosts');
  296. sinon.stub(mock, 'loadMasterComponentHosts');
  297. sinon.stub(mock, 'setDBProperty');
  298. view.reopen({
  299. content: Em.Object.create({
  300. controllerName: 'ctrl1'
  301. }),
  302. selectedServicesMasters: [
  303. {
  304. component_name: 'C1',
  305. selectedHost: 'host1'
  306. }
  307. ],
  308. popup: popup,
  309. configActionComponent: {
  310. componentName: 'C1'
  311. },
  312. configWidgetContext: Em.Object.create({
  313. config: Em.Object.create({
  314. configAction: {
  315. hostComponentConfig: {
  316. fileName: 'file1',
  317. configName: 'conf1'
  318. }
  319. },
  320. serviceName: 'S1',
  321. toggleProperty: Em.K
  322. }),
  323. controller: Em.Object.create({
  324. stepConfigs: [
  325. Em.Object.create({
  326. serviceName: 'S1',
  327. configs: [
  328. config
  329. ]
  330. })
  331. ]
  332. })
  333. })
  334. });
  335. view.submit();
  336. });
  337. afterEach(function() {
  338. App.router.get.restore();
  339. popup.hide.restore();
  340. mock.saveMasterComponentHosts.restore();
  341. mock.loadMasterComponentHosts.restore();
  342. mock.setDBProperty.restore();
  343. });
  344. it("saveMasterComponentHosts should be called", function() {
  345. expect(mock.saveMasterComponentHosts.calledOnce).to.be.true;
  346. });
  347. it("loadMasterComponentHosts�������������������������� should be called", function() {
  348. expect(mock.loadMasterComponentHosts.calledOnce).to.be.true;
  349. });
  350. it("configActionComponent should be set", function() {
  351. expect(view.get('configWidgetContext.config.configActionComponent')).to.be.eql({
  352. componentName: 'C1',
  353. hostName: 'host1'
  354. });
  355. });
  356. it("config should be set", function() {
  357. expect(config.get('value')).to.be.equal('host1');
  358. expect(config.get('recommendedValue')).to.be.equal('host1');
  359. });
  360. });
  361. });