step4_test.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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 Ember = require('ember');
  19. var App = require('app');
  20. require('controllers/wizard/step4_controller');
  21. describe('App.WizardStep4Controller', function () {
  22. var services = [
  23. 'HDFS', 'MAPREDUCE', 'NAGIOS', 'GANGLIA', 'OOZIE', 'HIVE', 'HBASE', 'PIG', 'SCOOP', 'ZOOKEEPER', 'HCATALOG',
  24. 'WEBHCAT', 'YARN', 'MAPREDUCE2', 'FALCON', 'TEZ', 'STORM'
  25. ];
  26. var controller = App.WizardStep4Controller.create();
  27. services.forEach(function(serviceName, index){
  28. controller.pushObject(Ember.Object.create({
  29. 'serviceName':serviceName, 'isSelected': true, 'canBeSelected': true, 'isInstalled': false, 'isDisabled': 'HDFS' === serviceName, isDFS: 'HDFS' === serviceName
  30. }));
  31. });
  32. describe('#isSubmitDisabled', function () {
  33. it('should return false if at least one selected service is not installed', function () {
  34. expect(controller.get('isSubmitDisabled')).to.equal(false);
  35. });
  36. it('should return true if all selected services are already installed', function () {
  37. controller.setEach('isInstalled', true);
  38. controller.findProperty('serviceName', 'HDFS').set('isSelected', false);
  39. expect(controller.get('isSubmitDisabled')).to.equal(true);
  40. });
  41. });
  42. describe('#isAll', function () {
  43. it('should return true if all services are selected', function () {
  44. controller.findProperty('serviceName', 'HDFS').set('isSelected', true);
  45. expect(controller.get('isAll')).to.equal(true);
  46. });
  47. it('should return false if at least one service is not selected', function () {
  48. controller.findProperty('serviceName', 'HDFS').set('isSelected', false);
  49. expect(controller.get('isAll')).to.equal(false);
  50. });
  51. });
  52. describe('#isMinimum', function () {
  53. it('should return true if there are no services selected, except disabled', function () {
  54. controller.setEach('isSelected', false);
  55. expect(controller.get('isMinimum')).to.equal(true);
  56. });
  57. it('should return false if at least one service is selected, except disabled', function () {
  58. controller.findProperty('serviceName', 'MAPREDUCE').set('isSelected', true);
  59. expect(controller.get('isMinimum')).to.equal(false);
  60. });
  61. });
  62. describe('#selectAll()', function () {
  63. it('should select all services', function () {
  64. controller.setEach('isSelected', false);
  65. controller.selectAll();
  66. expect(controller.filterProperty('canBeSelected', true).everyProperty('isSelected', true)).to.equal(true);
  67. });
  68. });
  69. describe('#selectMinimum()', function () {
  70. it('should set isSelected false for all services', function () {
  71. controller.setEach('isSelected', true);
  72. controller.selectMinimum();
  73. expect(controller.findProperty('serviceName', 'HDFS').get('isSelected')).to.equal(false);
  74. expect(controller.filterProperty('isDisabled', false).everyProperty('isSelected', false)).to.equal(true);
  75. });
  76. });
  77. describe('#noDFSs()', function () {
  78. it('should return true if HDFS is not selected and GLUSTERFS is absent', function () {
  79. controller.findProperty('serviceName', 'HDFS').set('isSelected', false);
  80. expect(controller.noDFSs()).to.equal(true);
  81. });
  82. it('should return false if HDFS is selected and GLUSTERFS is absent', function () {
  83. controller.findProperty('serviceName', 'HDFS').set('isSelected', true);
  84. expect(controller.noDFSs()).to.equal(false);
  85. });
  86. it('should return true if HDFS is not selected and GLUSTERFS is not selected, but present', function () {
  87. controller.pushObject(Ember.Object.create({
  88. 'serviceName':'GLUSTERFS', 'isSelected': false, 'canBeSelected': true, 'isInstalled': false, 'isDisabled': false, 'isDFS': true
  89. }));
  90. controller.findProperty('serviceName', 'HDFS').set('isSelected', false);
  91. expect(controller.noDFSs()).to.equal(true);
  92. });
  93. it('should return false if HDFS is not selected and GLUSTERFS is selected', function () {
  94. controller.findProperty('serviceName', 'GLUSTERFS').set('isSelected', true);
  95. expect(controller.noDFSs()).to.equal(false);
  96. });
  97. });
  98. describe('#multipleDFSs()', function () {
  99. it('should return true if HDFS is selected and GLUSTERFS is selected', function () {
  100. controller.findProperty('serviceName', 'HDFS').set('isSelected', true);
  101. controller.findProperty('serviceName', 'GLUSTERFS').set('isSelected', true);
  102. expect(controller.multipleDFSs()).to.equal(true);
  103. });
  104. it('should return false if HDFS is not selected and GLUSTERFS is selected', function () {
  105. controller.findProperty('serviceName', 'HDFS').set('isSelected', false);
  106. expect(controller.multipleDFSs()).to.equal(false);
  107. });
  108. it('should return false if HDFS is selected and GLUSTERFS is not selected', function () {
  109. controller.findProperty('serviceName', 'HDFS').set('isSelected', true);
  110. controller.findProperty('serviceName', 'GLUSTERFS').set('isSelected', false);
  111. expect(controller.multipleDFSs()).to.equal(false);
  112. });
  113. });
  114. describe('#setGroupedServices()', function () {
  115. var testCases = [
  116. {
  117. title: 'should set HCATALOG and WEBHCAT isSelected to true when HIVE is selected',
  118. condition: {
  119. 'HBASE': true,
  120. 'ZOOKEEPER': true,
  121. 'HIVE': true,
  122. 'HCATALOG': true,
  123. 'WEBHCAT': true
  124. },
  125. result: {
  126. 'HCATALOG': true,
  127. 'WEBHCAT': true
  128. }
  129. },
  130. {
  131. title: 'should set HCATALOG and WEBHCAT isSelected to false when HIVE is not selected',
  132. condition: {
  133. 'HBASE': true,
  134. 'ZOOKEEPER': true,
  135. 'HIVE': false,
  136. 'HCATALOG': true,
  137. 'WEBHCAT': true
  138. },
  139. result: {
  140. 'HCATALOG': false,
  141. 'WEBHCAT': false
  142. }
  143. },
  144. {
  145. title: 'should set MAPREDUCE2 isSelected to true when YARN is selected',
  146. condition: {
  147. 'HBASE': true,
  148. 'ZOOKEEPER': true,
  149. 'HIVE': false,
  150. 'HCATALOG': true,
  151. 'WEBHCAT': true,
  152. 'YARN': true,
  153. 'MAPREDUCE2': true
  154. },
  155. result: {
  156. 'MAPREDUCE2': true,
  157. 'HCATALOG': false,
  158. 'WEBHCAT': false
  159. }
  160. },
  161. {
  162. title: 'should set MAPREDUCE2 isSelected to false when YARN is not selected',
  163. condition: {
  164. 'HBASE': true,
  165. 'ZOOKEEPER': true,
  166. 'HIVE': true,
  167. 'HCATALOG': true,
  168. 'WEBHCAT': true,
  169. 'YARN': false,
  170. 'MAPREDUCE2': true
  171. },
  172. result: {
  173. 'MAPREDUCE2': false,
  174. 'HCATALOG': true,
  175. 'WEBHCAT': true
  176. }
  177. }
  178. ];
  179. testCases.forEach(function(testCase){
  180. it(testCase.title, function () {
  181. controller.clear();
  182. for(var id in testCase.condition) {
  183. controller.pushObject(Ember.Object.create({
  184. 'serviceName':id, 'isSelected': testCase.condition[id], 'canBeSelected': true, 'isInstalled': false,
  185. coSelectedServices: function() {
  186. return App.StackService.coSelected[this.get('serviceName')] || [];
  187. }.property('serviceName')
  188. }));
  189. }
  190. controller.setGroupedServices();
  191. for(var service in testCase.result) {
  192. expect(controller.findProperty('serviceName', service).get('isSelected')).to.equal(testCase.result[service]);
  193. }
  194. });
  195. }, this);
  196. });
  197. describe('#monitoringCheckPopup', function() {
  198. it('should show App.ModalPopup', function() {
  199. sinon.spy(App.ModalPopup, 'show');
  200. controller.monitoringCheckPopup();
  201. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  202. App.ModalPopup.show.restore();
  203. });
  204. it('onPrimary should proceed to next step', function() {
  205. sinon.stub(App.router, 'send', Em.K);
  206. controller.monitoringCheckPopup().onPrimary();
  207. expect(App.router.send.calledWith('next')).to.equal(true);
  208. App.router.send.restore();
  209. });
  210. });
  211. describe('#needToAddServicePopup', function() {
  212. Em.A([
  213. {
  214. m: 'one service',
  215. services: {selected: true, serviceName: 's1'},
  216. content: [Em.Object.create({serviceName: 's1', isSelected: false})],
  217. e: [true]
  218. },
  219. {
  220. m: 'many services',
  221. services: [{selected: true, serviceName: 's1'}, {selected: false, serviceName: 's2'}],
  222. content: [Em.Object.create({serviceName: 's1', isSelected: false}),
  223. Em.Object.create({serviceName: 's2', isSelected: true})],
  224. e: [true, false]
  225. }
  226. ]).forEach(function (test) {
  227. it(test.m, function () {
  228. sinon.stub(controller, 'submit', Em.K);
  229. controller.set('content', test.content);
  230. controller.needToAddServicePopup(test.services, '').onPrimary();
  231. expect(controller.submit.calledOnce).to.equal(true);
  232. expect(controller.mapProperty('isSelected')).to.eql(test.e);
  233. controller.submit.restore();
  234. });
  235. });
  236. });
  237. describe('#submit', function() {
  238. beforeEach(function() {
  239. sinon.stub(controller, 'validateMonitoring', Em.K);
  240. sinon.stub(controller, 'setGroupedServices', Em.K);
  241. });
  242. afterEach(function() {
  243. controller.validateMonitoring.restore();
  244. controller.setGroupedServices.restore();
  245. });
  246. it('if not isSubmitDisabled shound\'t do nothing', function() {
  247. controller.reopen({isSubmitDisabled: true});
  248. controller.submit();
  249. expect(controller.validateMonitoring.called).to.equal(false);
  250. });
  251. it('if isSubmitDisabled and not submitChecks should call validateMonitoring', function() {
  252. sinon.stub(controller, 'isSubmitChecksFailed', function() { return false; });
  253. controller.reopen({
  254. isSubmitDisabled: false,
  255. submitChecks: []
  256. });
  257. controller.submit();
  258. expect(controller.validateMonitoring.calledOnce).to.equal(true);
  259. controller.isSubmitChecksFailed.restore();
  260. });
  261. it('if isSubmitDisabled and some submitChecks true shouldn\'t call validateMonitoring', function() {
  262. controller.reopen({
  263. isSubmitDisabled: false,
  264. submitChecks: [
  265. {
  266. popupParams: [
  267. {serviceName: 'MAPREDUCE', selected: true},
  268. 'mapreduceCheck'
  269. ]
  270. }
  271. ]
  272. });
  273. sinon.stub(controller, 'isSubmitChecksFailed', function() { return true; });
  274. controller.submit();
  275. controller.isSubmitChecksFailed.restore();
  276. expect(controller.validateMonitoring.called).to.equal(false);
  277. });
  278. it('if isSubmitDisabled and some submitChecks false should call validateMonitoring', function() {
  279. controller.reopen({
  280. isSubmitDisabled: false,
  281. submitChecks: [
  282. {
  283. checkCallback: 'needToAddMapReduce',
  284. popupParams: [
  285. {serviceName: 'MAPREDUCE', selected: true},
  286. 'mapreduceCheck'
  287. ]
  288. }
  289. ]
  290. });
  291. sinon.stub(controller, 'isSubmitChecksFailed', function() { return false; });
  292. controller.submit();
  293. controller.isSubmitChecksFailed.restore();
  294. expect(controller.validateMonitoring.calledOnce).to.equal(true);
  295. });
  296. });
  297. });