assign_master_controller_test.js 11 KB

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