step4_test.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  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. var modelSetup = require('test/init_model_test');
  21. require('controllers/wizard/step4_controller');
  22. describe('App.WizardStep4Controller', function () {
  23. var services = [
  24. 'HDFS', 'MAPREDUCE', 'NAGIOS', 'GANGLIA', 'OOZIE', 'HIVE', 'HBASE', 'PIG', 'SCOOP', 'ZOOKEEPER', 'HCATALOG',
  25. 'WEBHCAT', 'YARN', 'MAPREDUCE2', 'FALCON', 'TEZ', 'STORM'
  26. ];
  27. var controller = App.WizardStep4Controller.create();
  28. var generateSelectedServicesContent = function(selectedServiceNames) {
  29. var allServices = services.slice(0);
  30. if (selectedServiceNames.contains('GLUSTERFS')) allServices.push('GLUSTERFS');
  31. allServices = allServices.map(function(serviceName) {
  32. return [Ember.Object.create({
  33. 'serviceName': serviceName,
  34. 'isSelected': false,
  35. 'canBeSelected': true,
  36. 'isInstalled': false,
  37. isPrimaryDFS: serviceName == 'HDFS',
  38. isDFS: ['HDFS','GLUSTERFS'].contains(serviceName),
  39. isMonitoringService: ['NAGIOS','GANGLIA'].contains(serviceName),
  40. dependentServices: App.StackService.dependency['HDP-2'][serviceName],
  41. displayNameOnSelectServicePage: App.format.role(serviceName),
  42. coSelectedServices: function() {
  43. return App.StackService.coSelected[this.get('serviceName')] || [];
  44. }.property('serviceName')
  45. })];
  46. }).reduce(function(current, prev) { return current.concat(prev); });
  47. selectedServiceNames.forEach(function(serviceName) {
  48. allServices.findProperty('serviceName', serviceName).set('isSelected', true);
  49. });
  50. return allServices;
  51. };
  52. services.forEach(function(serviceName, index){
  53. controller.pushObject(Ember.Object.create({
  54. 'serviceName':serviceName, 'isSelected': true, 'isHiddenOnSelectServicePage': false, 'isInstalled': false, 'isDisabled': 'HDFS' === serviceName, isDFS: 'HDFS' === serviceName
  55. }));
  56. });
  57. describe('#isSubmitDisabled', function () {
  58. it('should return false if at least one selected service is not installed', function () {
  59. expect(controller.get('isSubmitDisabled')).to.equal(false);
  60. });
  61. it('should return true if all selected services are already installed', function () {
  62. controller.setEach('isInstalled', true);
  63. controller.findProperty('serviceName', 'HDFS').set('isSelected', false);
  64. expect(controller.get('isSubmitDisabled')).to.equal(true);
  65. });
  66. });
  67. describe('#isAll', function () {
  68. it('should return true if all services are selected', function () {
  69. controller.setEach('isInstalled', false);
  70. controller.findProperty('serviceName', 'HDFS').set('isSelected', true);
  71. expect(controller.get('isAll')).to.equal(true);
  72. });
  73. it('should return false if at least one service is not selected', function () {
  74. controller.findProperty('serviceName', 'HDFS').set('isSelected', false);
  75. expect(controller.get('isAll')).to.equal(false);
  76. });
  77. });
  78. describe('#isMinimum', function () {
  79. it('should return true if there are no services selected, except disabled', function () {
  80. controller.setEach('isSelected', false);
  81. expect(controller.get('isMinimum')).to.equal(true);
  82. });
  83. it('should return false if at least one service is selected, except disabled', function () {
  84. controller.findProperty('serviceName', 'MAPREDUCE').set('isSelected', true);
  85. expect(controller.get('isMinimum')).to.equal(false);
  86. });
  87. });
  88. describe('#selectAll()', function () {
  89. it('should select all services', function () {
  90. controller.setEach('isSelected', false);
  91. controller.selectAll();
  92. expect(controller.filterProperty('canBeSelected', true).everyProperty('isSelected', true)).to.equal(true);
  93. });
  94. });
  95. describe('#selectMinimum()', function () {
  96. it('should set isSelected false for all services', function () {
  97. controller.setEach('isSelected', true);
  98. controller.selectMinimum();
  99. expect(controller.findProperty('serviceName', 'HDFS').get('isSelected')).to.equal(false);
  100. expect(controller.filterProperty('isDisabled', false).everyProperty('isSelected', false)).to.equal(true);
  101. });
  102. });
  103. describe('#multipleDFSs()', function () {
  104. it('should return true if HDFS is selected and GLUSTERFS is selected', function () {
  105. controller.set('content', generateSelectedServicesContent(['HDFS', 'GLUSTERFS']));
  106. expect(controller.multipleDFSs()).to.equal(true);
  107. });
  108. it('should return false if HDFS is not selected and GLUSTERFS is selected', function () {
  109. controller.set('content', generateSelectedServicesContent(['GLUSTERFS']));
  110. expect(controller.multipleDFSs()).to.equal(false);
  111. });
  112. it('should return false if HDFS is selected and GLUSTERFS is not selected', function () {
  113. controller.set('content', generateSelectedServicesContent(['HDFS']));
  114. expect(controller.multipleDFSs()).to.equal(false);
  115. });
  116. });
  117. describe('#setGroupedServices()', function () {
  118. var testCases = [
  119. {
  120. title: 'should set HCATALOG and WEBHCAT isSelected to true when HIVE is selected',
  121. condition: {
  122. 'HBASE': true,
  123. 'ZOOKEEPER': true,
  124. 'HIVE': true,
  125. 'HCATALOG': true,
  126. 'WEBHCAT': true
  127. },
  128. result: {
  129. 'HCATALOG': true,
  130. 'WEBHCAT': true
  131. }
  132. },
  133. {
  134. title: 'should set HCATALOG and WEBHCAT isSelected to false when HIVE is not selected',
  135. condition: {
  136. 'HBASE': true,
  137. 'ZOOKEEPER': true,
  138. 'HIVE': false,
  139. 'HCATALOG': true,
  140. 'WEBHCAT': true
  141. },
  142. result: {
  143. 'HCATALOG': false,
  144. 'WEBHCAT': false
  145. }
  146. },
  147. {
  148. title: 'should set MAPREDUCE2 isSelected to true when YARN is selected',
  149. condition: {
  150. 'HBASE': true,
  151. 'ZOOKEEPER': true,
  152. 'HIVE': false,
  153. 'HCATALOG': true,
  154. 'WEBHCAT': true,
  155. 'YARN': true,
  156. 'MAPREDUCE2': true
  157. },
  158. result: {
  159. 'MAPREDUCE2': true,
  160. 'HCATALOG': false,
  161. 'WEBHCAT': false
  162. }
  163. },
  164. {
  165. title: 'should set MAPREDUCE2 isSelected to false when YARN is not selected',
  166. condition: {
  167. 'HBASE': true,
  168. 'ZOOKEEPER': true,
  169. 'HIVE': true,
  170. 'HCATALOG': true,
  171. 'WEBHCAT': true,
  172. 'YARN': false,
  173. 'MAPREDUCE2': true
  174. },
  175. result: {
  176. 'MAPREDUCE2': false,
  177. 'HCATALOG': true,
  178. 'WEBHCAT': true
  179. }
  180. }
  181. ];
  182. testCases.forEach(function(testCase){
  183. it(testCase.title, function () {
  184. controller.clear();
  185. for(var id in testCase.condition) {
  186. controller.pushObject(Ember.Object.create({
  187. 'serviceName':id, 'isSelected': testCase.condition[id], 'canBeSelected': true, 'isInstalled': false,
  188. coSelectedServices: function() {
  189. return App.StackService.coSelected[this.get('serviceName')] || [];
  190. }.property('serviceName')
  191. }));
  192. }
  193. controller.setGroupedServices();
  194. for(var service in testCase.result) {
  195. expect(controller.findProperty('serviceName', service).get('isSelected')).to.equal(testCase.result[service]);
  196. }
  197. });
  198. }, this);
  199. });
  200. describe('#addValidationError()', function() {
  201. var tests = [
  202. {
  203. errorObjects: [
  204. {
  205. id: 'serviceCheck_ZOOKEEPER',
  206. shouldBeAdded: true
  207. },
  208. {
  209. id: 'serviceCheck_YARN',
  210. shouldBeAdded: true
  211. }
  212. ],
  213. expectedIds: ['serviceCheck_ZOOKEEPER', 'serviceCheck_YARN']
  214. },
  215. {
  216. errorObjects: [
  217. {
  218. id: 'fsCheck',
  219. shouldBeAdded: true
  220. },
  221. {
  222. id: 'fsCheck',
  223. shouldBeAdded: false
  224. }
  225. ],
  226. expectedIds: ['fsCheck']
  227. }
  228. ];
  229. beforeEach(function() {
  230. controller.clear();
  231. controller.set('errorStack', []);
  232. });
  233. tests.forEach(function(test) {
  234. var message = 'Erorrs {0} thrown. errorStack property should contains ids: {1}'
  235. .format(test.errorObjects.mapProperty('id').join(', '), test.expectedIds.join(', '));
  236. it(message, function() {
  237. test.errorObjects.forEach(function(errorObject) {
  238. expect(controller.addValidationError(errorObject)).to.equal(errorObject.shouldBeAdded);
  239. });
  240. expect(controller.get('errorStack').mapProperty('id')).to.eql(test.expectedIds);
  241. });
  242. })
  243. });
  244. describe('#validate()', function() {
  245. var tests = [
  246. {
  247. services: ['HDFS','ZOOKEEPER'],
  248. errorsExpected: ['monitoringCheck']
  249. },
  250. {
  251. services: ['ZOOKEEPER'],
  252. errorsExpected: ['fsCheck', 'monitoringCheck']
  253. },
  254. {
  255. services: ['HDFS'],
  256. errorsExpected: ['serviceCheck_ZOOKEEPER', 'monitoringCheck']
  257. },
  258. {
  259. services: ['HDFS', 'TEZ', 'ZOOKEEPER'],
  260. errorsExpected: ['serviceCheck_YARN', 'monitoringCheck']
  261. },
  262. {
  263. services: ['HDFS', 'ZOOKEEPER', 'FALCON', 'NAGIOS'],
  264. errorsExpected: ['serviceCheck_OOZIE', 'monitoringCheck']
  265. },
  266. {
  267. services: ['HDFS', 'ZOOKEEPER', 'GANGLIA', 'NAGIOS', 'HIVE'],
  268. errorsExpected: ['serviceCheck_YARN']
  269. },
  270. {
  271. services: ['HDFS', 'GLUSTERFS', 'ZOOKEEPER', 'HIVE'],
  272. errorsExpected: ['serviceCheck_YARN', 'multipleDFS', 'monitoringCheck']
  273. },
  274. {
  275. services: ['HDFS','ZOOKEEPER', 'NAGIOS', 'GANGLIA'],
  276. errorsExpected: []
  277. }
  278. ];
  279. tests.forEach(function(test) {
  280. var message = '{0} selected validation should be {1}, errors with ids: {2} present'
  281. .format(test.services.join(','), !!test.validationPassed ? 'passed' : 'failed', test.errorsExpected.join(','));
  282. it(message, function() {
  283. controller.clear();
  284. controller.set('content', generateSelectedServicesContent(test.services));
  285. controller.validate();
  286. expect(controller.get('errorStack').mapProperty('id')).to.be.eql(test.errorsExpected);
  287. });
  288. })
  289. });
  290. describe('#onPrimaryPopupCallback()', function() {
  291. var c;
  292. var tests = [
  293. {
  294. services: ['HDFS','ZOOKEEPER'],
  295. confirmPopupCount: 1,
  296. errorsExpected: ['monitoringCheck']
  297. },
  298. {
  299. services: ['ZOOKEEPER'],
  300. confirmPopupCount: 2,
  301. errorsExpected: ['fsCheck', 'monitoringCheck']
  302. },
  303. {
  304. services: ['HDFS', 'GLUSTERFS', 'ZOOKEEPER', 'HIVE'],
  305. confirmPopupCount: 3,
  306. errorsExpected: ['serviceCheck_YARN', 'serviceCheck_TEZ', 'multipleDFS', 'monitoringCheck']
  307. },
  308. {
  309. services: ['HDFS','ZOOKEEPER', 'NAGIOS', 'GANGLIA'],
  310. confirmPopupCount: 0,
  311. errorsExpected: []
  312. }
  313. ];
  314. beforeEach(function() {
  315. c = App.WizardStep4Controller.create({});
  316. sinon.stub(App.router, 'send', Em.K);
  317. sinon.stub(c, 'submit', Em.K);
  318. sinon.spy(c, 'onPrimaryPopupCallback');
  319. });
  320. afterEach(function() {
  321. App.router.send.restore();
  322. c.submit.restore();
  323. c.onPrimaryPopupCallback.restore();
  324. });
  325. tests.forEach(function(test) {
  326. var message = 'Selected services: {0}. {1} errors should be confirmed'
  327. .format(test.services.join(', '), test.confirmPopupCount);
  328. it(message, function() {
  329. var runValidations = function() {
  330. c.serviceDependencyValidation();
  331. c.fileSystemServiceValidation();
  332. c.serviceMonitoringValidation();
  333. }
  334. c.set('content', generateSelectedServicesContent(test.services));
  335. runValidations();
  336. // errors count validation
  337. expect(c.get('errorStack.length')).to.equal(test.confirmPopupCount);
  338. // if errors detected than it should be shown
  339. if (test.errorsExpected) {
  340. test.errorsExpected.forEach(function(error, index, errors) {
  341. // validate current error
  342. var currentErrorObject = c.get('errorStack').findProperty('isShown', false);
  343. if (currentErrorObject) {
  344. expect(error).to.be.equal(currentErrorObject.id);
  345. // show current error
  346. var popup = c.showError(currentErrorObject);
  347. // submit popup
  348. popup.onPrimary();
  349. // onPrimaryPopupCallback should be called
  350. expect(c.onPrimaryPopupCallback.called).to.equal(true);
  351. // submit called
  352. expect(c.submit.called).to.equal(true);
  353. if (c.get('errorStack').length) {
  354. // current error isShown flag changed to true
  355. expect(currentErrorObject.isShown).to.equal(true);
  356. }
  357. runValidations();
  358. }
  359. });
  360. }
  361. });
  362. });
  363. });
  364. describe('#needToAddServicePopup', function() {
  365. Em.A([
  366. {
  367. m: 'one service',
  368. services: {selected: true, serviceName: 's1'},
  369. content: [Em.Object.create({serviceName: 's1', isSelected: false})],
  370. e: [true]
  371. },
  372. {
  373. m: 'many services',
  374. services: [{selected: true, serviceName: 's1'}, {selected: false, serviceName: 's2'}],
  375. content: [Em.Object.create({serviceName: 's1', isSelected: false}),
  376. Em.Object.create({serviceName: 's2', isSelected: true})],
  377. e: [true, false]
  378. }
  379. ]).forEach(function (test) {
  380. it(test.m, function () {
  381. sinon.stub(controller, 'submit', Em.K);
  382. controller.set('content', test.content);
  383. controller.needToAddServicePopup(test.services, '').onPrimary();
  384. expect(controller.submit.calledOnce).to.equal(true);
  385. expect(controller.mapProperty('isSelected')).to.eql(test.e);
  386. controller.submit.restore();
  387. });
  388. });
  389. });
  390. describe('#submit', function() {
  391. var c;
  392. var tests = [
  393. {
  394. isSubmitDisabled: true,
  395. validate: false,
  396. userCanProceed: false
  397. },
  398. {
  399. isSubmitDisabled: false,
  400. validate: false,
  401. userCanProceed: false
  402. },
  403. {
  404. isSubmitDisabled: false,
  405. validate: true,
  406. userCanProceed: true
  407. }
  408. ];
  409. beforeEach(function() {
  410. c = App.WizardStep4Controller.create();
  411. sinon.stub(App.router, 'send', Em.K);
  412. });
  413. afterEach(function() {
  414. App.router.send.restore();
  415. });
  416. tests.forEach(function(test) {
  417. var messageFormat = [
  418. test.isSubmitDisabled ? 'disabled' : 'enabled',
  419. test.validate ? 'success' : 'failed',
  420. test.userCanProceed ? '' : 'not'
  421. ];
  422. var message = String.prototype.format.apply('Submit btn: {0}. Validation: {1}. Can{2} move to the next step.', messageFormat);
  423. it(message, function() {
  424. c.reopen({
  425. isSubmitDisabled: test.isSubmitDisabled,
  426. validate: function() { return test.validate; }
  427. });
  428. c.clear();
  429. c.submit();
  430. expect(App.router.send.calledOnce).to.equal(test.userCanProceed);
  431. });
  432. })
  433. });
  434. });