assign_master_controller_test.js 12 KB

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