step4_test.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  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
  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 not disabled services', function () {
  71. controller.setEach('isSelected', true);
  72. controller.selectMinimum();
  73. expect(controller.findProperty('serviceName', 'HDFS').get('isSelected')).to.equal(true);
  74. expect(controller.filterProperty('isDisabled', false).everyProperty('isSelected', false)).to.equal(true);
  75. });
  76. });
  77. describe('#needToAddMapReduce()', function () {
  78. it('should return true if Pig is selected and MapReduce is not selected', function () {
  79. controller.setEach('isSelected', false);
  80. controller.findProperty('serviceName', 'PIG').set('isSelected', true);
  81. expect(controller.needToAddMapReduce()).to.equal(true);
  82. });
  83. it('should return true if Oozie is selected and MapReduce is not selected', function () {
  84. controller.setEach('isSelected', false);
  85. controller.findProperty('serviceName', 'OOZIE').set('isSelected', true);
  86. expect(controller.needToAddMapReduce()).to.equal(true);
  87. });
  88. it('should return true if Hive is selected and MapReduce is not selected', function () {
  89. controller.setEach('isSelected', false);
  90. controller.findProperty('serviceName', 'HIVE').set('isSelected', true);
  91. expect(controller.needToAddMapReduce()).to.equal(true);
  92. });
  93. it('should return false if MapReduce is selected or Pig, Oozie and Hive are not selected', function () {
  94. controller.findProperty('serviceName', 'MAPREDUCE').set('isSelected', true);
  95. expect(controller.needToAddMapReduce()).to.equal(false);
  96. controller.setEach('isSelected', false);
  97. expect(controller.needToAddMapReduce()).to.equal(false);
  98. });
  99. });
  100. describe('#needToAddYarnMapReduce2()', function () {
  101. it('should return true if Pig is selected and YARN+MapReduce2 is not selected', function () {
  102. controller.setEach('isSelected', false);
  103. controller.findProperty('serviceName', 'PIG').set('isSelected', true);
  104. expect(controller.needToAddYarnMapReduce2()).to.equal(true);
  105. });
  106. it('should return true if Oozie is selected and YARN+MapReduce2 is not selected', function () {
  107. controller.setEach('isSelected', false);
  108. controller.findProperty('serviceName', 'OOZIE').set('isSelected', true);
  109. expect(controller.needToAddYarnMapReduce2()).to.equal(true);
  110. });
  111. it('should return true if Hive is selected and YARN+MapReduce2 is not selected', function () {
  112. controller.setEach('isSelected', false);
  113. controller.findProperty('serviceName', 'HIVE').set('isSelected', true);
  114. expect(controller.needToAddYarnMapReduce2()).to.equal(true);
  115. });
  116. it('should return false if YARN+MapReduce2 is selected or Pig, Oozie and Hive are not selected', function () {
  117. controller.findProperty('serviceName', 'YARN').set('isSelected', true);
  118. expect(controller.needToAddYarnMapReduce2()).to.equal(false);
  119. controller.setEach('isSelected', false);
  120. expect(controller.needToAddYarnMapReduce2()).to.equal(false);
  121. });
  122. });
  123. describe('#needToAddZooKeeper()', function () {
  124. beforeEach(function() {
  125. ajax_send = App.ajax.send;
  126. App.ajax.send = function() {};
  127. });
  128. afterEach(function() {
  129. App.ajax.send = ajax_send;
  130. });
  131. var originalStackVersion = App.get('currentStackVersion');
  132. it('should return false if ZOOKEEPER is selected and Hadoop version above 2', function () {
  133. App.set('currentStackVersion', 'HDP-2.1.1');
  134. controller.findProperty('serviceName', 'ZOOKEEPER').set('isSelected', true);
  135. expect(controller.needToAddZooKeeper()).to.equal(false);
  136. });
  137. it('should return true if ZOOKEEPER is not selected and Hadoop version above 2', function () {
  138. controller.findProperty('serviceName', 'ZOOKEEPER').set('isSelected', false);
  139. expect(controller.needToAddZooKeeper()).to.equal(true);
  140. });
  141. it('should return false if none of the HBASE, HIVE, WEBHCAT, STORM is selected and Hadoop version below 2', function () {
  142. App.set('currentStackVersion', 'HDP-1.3.0');
  143. expect(controller.needToAddZooKeeper()).to.equal(false);
  144. });
  145. it('should return true if HBASE is not selected and Hadoop version below 2', function () {
  146. controller.findProperty('serviceName', 'HBASE').set('isSelected', true);
  147. expect(controller.needToAddZooKeeper()).to.equal(true);
  148. });
  149. it('should return true if HBASE, HIVE, WEBHCAT, STORM are selected and Hadoop version below 2', function () {
  150. controller.findProperty('serviceName', 'HIVE').set('isSelected', true);
  151. controller.findProperty('serviceName', 'WEBHCAT').set('isSelected', true);
  152. controller.findProperty('serviceName', 'STORM').set('isSelected', true);
  153. expect(controller.needToAddZooKeeper()).to.equal(true);
  154. App.set('currentStackVersion', originalStackVersion);
  155. });
  156. });
  157. describe('#gangliaOrNagiosNotSelected()', function () {
  158. it('should return true if Nagios or Ganglia is not selected', function () {
  159. controller.setEach('isSelected', true);
  160. controller.findProperty('serviceName', 'NAGIOS').set('isSelected', false);
  161. expect(controller.gangliaOrNagiosNotSelected()).to.equal(true);
  162. controller.setEach('isSelected', true);
  163. controller.findProperty('serviceName', 'GANGLIA').set('isSelected', false);
  164. expect(controller.gangliaOrNagiosNotSelected()).to.equal(true);
  165. });
  166. it('should return false if Nagios and Ganglia is selected', function () {
  167. controller.setEach('isSelected', false);
  168. controller.findProperty('serviceName', 'GANGLIA').set('isSelected', true);
  169. controller.findProperty('serviceName', 'NAGIOS').set('isSelected', true);
  170. expect(controller.gangliaOrNagiosNotSelected()).to.equal(false);
  171. });
  172. });
  173. describe('#needToAddTez()', function () {
  174. it('should return false if YARN is present, but not selected', function () {
  175. controller.findProperty('serviceName', 'YARN').set('isSelected', false);
  176. expect(controller.needToAddTez()).to.equal(false);
  177. });
  178. it('should return true if YARN is selected', function () {
  179. controller.findProperty('serviceName', 'YARN').set('isSelected', true);
  180. expect(controller.needToAddTez()).to.equal(true);
  181. });
  182. });
  183. describe('#needToAddOozie()', function () {
  184. it('should return false if FALCON is present, but not selected', function () {
  185. controller.findProperty('serviceName', 'FALCON').set('isSelected', false);
  186. expect(controller.needToAddOozie()).to.equal(false);
  187. });
  188. it('should return true if FALCON is selected', function () {
  189. controller.findProperty('serviceName', 'FALCON').set('isSelected', true);
  190. expect(controller.needToAddOozie()).to.equal(true);
  191. });
  192. });
  193. describe('#noDFSs()', function () {
  194. it('should return true if HDFS is not selected and GLUSTERFS is absent', function () {
  195. controller.findProperty('serviceName', 'HDFS').set('isSelected', false);
  196. expect(controller.noDFSs()).to.equal(true);
  197. });
  198. it('should return false if HDFS is selected and GLUSTERFS is absent', function () {
  199. controller.findProperty('serviceName', 'HDFS').set('isSelected', true);
  200. expect(controller.noDFSs()).to.equal(false);
  201. });
  202. it('should return true if HDFS is not selected and GLUSTERFS is not selected, but present', function () {
  203. controller.pushObject(Ember.Object.create({
  204. 'serviceName':'GLUSTERFS', 'isSelected': false, 'canBeSelected': true, 'isInstalled': false, 'isDisabled': false
  205. }));
  206. controller.findProperty('serviceName', 'HDFS').set('isSelected', false);
  207. expect(controller.noDFSs()).to.equal(true);
  208. });
  209. it('should return false if HDFS is not selected and GLUSTERFS is selected', function () {
  210. controller.findProperty('serviceName', 'GLUSTERFS').set('isSelected', true);
  211. expect(controller.noDFSs()).to.equal(false);
  212. });
  213. });
  214. describe('#multipleDFSs()', function () {
  215. it('should return true if HDFS is selected and GLUSTERFS is selected', function () {
  216. controller.findProperty('serviceName', 'HDFS').set('isSelected', true);
  217. controller.findProperty('serviceName', 'GLUSTERFS').set('isSelected', true);
  218. expect(controller.multipleDFSs()).to.equal(true);
  219. });
  220. it('should return false if HDFS is not selected and GLUSTERFS is selected', function () {
  221. controller.findProperty('serviceName', 'HDFS').set('isSelected', false);
  222. expect(controller.multipleDFSs()).to.equal(false);
  223. });
  224. it('should return false if HDFS is selected and GLUSTERFS is not selected', function () {
  225. controller.findProperty('serviceName', 'HDFS').set('isSelected', true);
  226. controller.findProperty('serviceName', 'GLUSTERFS').set('isSelected', false);
  227. expect(controller.multipleDFSs()).to.equal(false);
  228. });
  229. });
  230. describe('#checkDependencies()', function () {
  231. var testCases = [
  232. {
  233. title: 'should set HCATALOG and WEBHCAT isSelected to true when HIVE is selected',
  234. condition: {
  235. 'HBASE': true,
  236. 'ZOOKEEPER': true,
  237. 'HIVE': true,
  238. 'HCATALOG': true,
  239. 'WEBHCAT': true
  240. },
  241. result: {
  242. 'HCATALOG': true,
  243. 'WEBHCAT': true
  244. }
  245. },
  246. {
  247. title: 'should set HCATALOG and WEBHCAT isSelected to false when HIVE is not selected',
  248. condition: {
  249. 'HBASE': true,
  250. 'ZOOKEEPER': true,
  251. 'HIVE': false,
  252. 'HCATALOG': true,
  253. 'WEBHCAT': true
  254. },
  255. result: {
  256. 'HCATALOG': false,
  257. 'WEBHCAT': false
  258. }
  259. },
  260. {
  261. title: 'should set MAPREDUCE2 isSelected to true when YARN is selected',
  262. condition: {
  263. 'HBASE': true,
  264. 'ZOOKEEPER': true,
  265. 'HIVE': false,
  266. 'HCATALOG': true,
  267. 'WEBHCAT': true,
  268. 'YARN': true,
  269. 'MAPREDUCE2': true
  270. },
  271. result: {
  272. 'MAPREDUCE2': true,
  273. 'HCATALOG': false,
  274. 'WEBHCAT': false
  275. }
  276. },
  277. {
  278. title: 'should set MAPREDUCE2 isSelected to false when YARN is not selected',
  279. condition: {
  280. 'HBASE': true,
  281. 'ZOOKEEPER': true,
  282. 'HIVE': true,
  283. 'HCATALOG': true,
  284. 'WEBHCAT': true,
  285. 'YARN': false,
  286. 'MAPREDUCE2': true
  287. },
  288. result: {
  289. 'MAPREDUCE2': false,
  290. 'HCATALOG': true,
  291. 'WEBHCAT': true
  292. }
  293. }
  294. ];
  295. testCases.forEach(function(testCase){
  296. it(testCase.title, function () {
  297. controller.clear();
  298. for(var id in testCase.condition) {
  299. controller.pushObject(Ember.Object.create({
  300. 'serviceName':id, 'isSelected': testCase.condition[id], 'canBeSelected': true, 'isInstalled': false
  301. }));
  302. }
  303. controller.checkDependencies();
  304. for(var service in testCase.result) {
  305. expect(controller.findProperty('serviceName', service).get('isSelected')).to.equal(testCase.result[service]);
  306. }
  307. });
  308. }, this);
  309. });
  310. describe('#monitoringCheckPopup', function() {
  311. it('should show App.ModalPopup', function() {
  312. sinon.spy(App.ModalPopup, 'show');
  313. controller.monitoringCheckPopup();
  314. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  315. App.ModalPopup.show.restore();
  316. });
  317. it('onPrimary should proceed to next step', function() {
  318. sinon.stub(App.router, 'send', Em.K);
  319. controller.monitoringCheckPopup().onPrimary();
  320. expect(App.router.send.calledWith('next')).to.equal(true);
  321. App.router.send.restore();
  322. });
  323. });
  324. describe('#needToAddServicePopup', function() {
  325. Em.A([
  326. {
  327. m: 'one service',
  328. services: {selected: true, serviceName: 's1'},
  329. content: [Em.Object.create({serviceName: 's1', isSelected: false})],
  330. e: [true]
  331. },
  332. {
  333. m: 'many services',
  334. services: [{selected: true, serviceName: 's1'}, {selected: false, serviceName: 's2'}],
  335. content: [Em.Object.create({serviceName: 's1', isSelected: false}),
  336. Em.Object.create({serviceName: 's2', isSelected: true})],
  337. e: [true, false]
  338. }
  339. ]).forEach(function (test) {
  340. it(test.m, function () {
  341. sinon.stub(controller, 'submit', Em.K);
  342. controller.set('content', test.content);
  343. controller.needToAddServicePopup(test.services, '').onPrimary();
  344. expect(controller.submit.calledOnce).to.equal(true);
  345. expect(controller.mapProperty('isSelected')).to.eql(test.e);
  346. controller.submit.restore();
  347. });
  348. });
  349. });
  350. describe('#validateMonitoring', function() {
  351. Em.A([
  352. {
  353. gangliaOrNagiosNotSelected: true,
  354. e: {
  355. monitoringCheckPopup: true,
  356. send: false
  357. }
  358. },
  359. {
  360. gangliaOrNagiosNotSelected: false,
  361. e: {
  362. monitoringCheckPopup: false,
  363. send: true
  364. }
  365. }
  366. ]).forEach(function (test) {
  367. it(test.m, function () {
  368. sinon.stub(controller, 'monitoringCheckPopup', Em.K);
  369. sinon.stub(App.router, 'send', Em.K);
  370. sinon.stub(controller, 'gangliaOrNagiosNotSelected', function() {
  371. return test.gangliaOrNagiosNotSelected;
  372. });
  373. controller.validateMonitoring();
  374. if (test.e.monitoringCheckPopup) {
  375. expect(controller.monitoringCheckPopup.calledOnce).to.equal(true);
  376. }
  377. else {
  378. expect(controller.monitoringCheckPopup.called).to.equal(false);
  379. }
  380. if (test.e.send) {
  381. expect(App.router.send.calledWith('next')).to.equal(true);
  382. }
  383. else {
  384. expect(App.router.send.called).to.equal(false);
  385. }
  386. controller.gangliaOrNagiosNotSelected.restore();
  387. controller.monitoringCheckPopup.restore();
  388. App.router.send.restore();
  389. });
  390. });
  391. });
  392. describe('#submit', function() {
  393. beforeEach(function() {
  394. sinon.stub(controller, 'validateMonitoring', Em.K);
  395. });
  396. afterEach(function() {
  397. controller.validateMonitoring.restore();
  398. });
  399. it('if not isSubmitDisabled shound\'t do nothing', function() {
  400. controller.reopen({isSubmitDisabled: true});
  401. controller.submit();
  402. expect(controller.validateMonitoring.called).to.equal(false);
  403. });
  404. it('if isSubmitDisabled and not submitChecks should call validateMonitoring', function() {
  405. controller.reopen({
  406. isSubmitDisabled: false,
  407. submitChecks: []
  408. });
  409. controller.submit();
  410. expect(controller.validateMonitoring.calledOnce).to.equal(true);
  411. });
  412. it('if isSubmitDisabled and some submitChecks true shouldn\'t call validateMonitoring', function() {
  413. controller.reopen({
  414. isSubmitDisabled: false,
  415. submitChecks: [
  416. {
  417. checkCallback: 'needToAddMapReduce',
  418. popupParams: [
  419. {serviceName: 'MAPREDUCE', selected: true},
  420. 'mapreduceCheck'
  421. ]
  422. }
  423. ]
  424. });
  425. sinon.stub(controller, 'needToAddMapReduce', function() {return true;});
  426. controller.submit();
  427. expect(controller.validateMonitoring.called).to.equal(false);
  428. controller.needToAddMapReduce.restore();
  429. });
  430. it('if isSubmitDisabled and some submitChecks false should call validateMonitoring', function() {
  431. controller.reopen({
  432. isSubmitDisabled: false,
  433. submitChecks: [
  434. {
  435. checkCallback: 'needToAddMapReduce',
  436. popupParams: [
  437. {serviceName: 'MAPREDUCE', selected: true},
  438. 'mapreduceCheck'
  439. ]
  440. }
  441. ]
  442. });
  443. sinon.stub(controller, 'needToAddMapReduce', function() {return false;});
  444. controller.submit();
  445. expect(controller.validateMonitoring.calledOnce).to.equal(true);
  446. controller.needToAddMapReduce.restore();
  447. });
  448. });
  449. });