step4_test.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  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('#noDFSs()', function () {
  104. it('should return true if HDFS is not selected and GLUSTERFS is absent', function () {
  105. controller.findProperty('serviceName', 'HDFS').set('isSelected', false);
  106. expect(controller.noDFSs()).to.equal(true);
  107. });
  108. it('should return false if HDFS is selected and GLUSTERFS is absent', function () {
  109. controller.findProperty('serviceName', 'HDFS').set('isSelected', true);
  110. expect(controller.noDFSs()).to.equal(false);
  111. });
  112. it('should return true if HDFS is not selected and GLUSTERFS is not selected, but present', function () {
  113. controller.pushObject(Ember.Object.create({
  114. 'serviceName':'GLUSTERFS', 'isSelected': false, 'canBeSelected': true, 'isInstalled': false, 'isDisabled': false, 'isDFS': true
  115. }));
  116. controller.findProperty('serviceName', 'HDFS').set('isSelected', false);
  117. expect(controller.noDFSs()).to.equal(true);
  118. });
  119. it('should return false if HDFS is not selected and GLUSTERFS is selected', function () {
  120. controller.findProperty('serviceName', 'GLUSTERFS').set('isSelected', true);
  121. expect(controller.noDFSs()).to.equal(false);
  122. });
  123. });
  124. describe('#multipleDFSs()', function () {
  125. it('should return true if HDFS is selected and GLUSTERFS is selected', function () {
  126. controller.findProperty('serviceName', 'HDFS').set('isSelected', true);
  127. controller.findProperty('serviceName', 'GLUSTERFS').set('isSelected', true);
  128. expect(controller.multipleDFSs()).to.equal(true);
  129. });
  130. it('should return false if HDFS is not selected and GLUSTERFS is selected', function () {
  131. controller.findProperty('serviceName', 'HDFS').set('isSelected', false);
  132. expect(controller.multipleDFSs()).to.equal(false);
  133. });
  134. it('should return false if HDFS is selected and GLUSTERFS is not selected', function () {
  135. controller.findProperty('serviceName', 'HDFS').set('isSelected', true);
  136. controller.findProperty('serviceName', 'GLUSTERFS').set('isSelected', false);
  137. expect(controller.multipleDFSs()).to.equal(false);
  138. });
  139. });
  140. describe('#setGroupedServices()', function () {
  141. var testCases = [
  142. {
  143. title: 'should set HCATALOG and WEBHCAT isSelected to true when HIVE is selected',
  144. condition: {
  145. 'HBASE': true,
  146. 'ZOOKEEPER': true,
  147. 'HIVE': true,
  148. 'HCATALOG': true,
  149. 'WEBHCAT': true
  150. },
  151. result: {
  152. 'HCATALOG': true,
  153. 'WEBHCAT': true
  154. }
  155. },
  156. {
  157. title: 'should set HCATALOG and WEBHCAT isSelected to false when HIVE is not selected',
  158. condition: {
  159. 'HBASE': true,
  160. 'ZOOKEEPER': true,
  161. 'HIVE': false,
  162. 'HCATALOG': true,
  163. 'WEBHCAT': true
  164. },
  165. result: {
  166. 'HCATALOG': false,
  167. 'WEBHCAT': false
  168. }
  169. },
  170. {
  171. title: 'should set MAPREDUCE2 isSelected to true when YARN is selected',
  172. condition: {
  173. 'HBASE': true,
  174. 'ZOOKEEPER': true,
  175. 'HIVE': false,
  176. 'HCATALOG': true,
  177. 'WEBHCAT': true,
  178. 'YARN': true,
  179. 'MAPREDUCE2': true
  180. },
  181. result: {
  182. 'MAPREDUCE2': true,
  183. 'HCATALOG': false,
  184. 'WEBHCAT': false
  185. }
  186. },
  187. {
  188. title: 'should set MAPREDUCE2 isSelected to false when YARN is not selected',
  189. condition: {
  190. 'HBASE': true,
  191. 'ZOOKEEPER': true,
  192. 'HIVE': true,
  193. 'HCATALOG': true,
  194. 'WEBHCAT': true,
  195. 'YARN': false,
  196. 'MAPREDUCE2': true
  197. },
  198. result: {
  199. 'MAPREDUCE2': false,
  200. 'HCATALOG': true,
  201. 'WEBHCAT': true
  202. }
  203. }
  204. ];
  205. testCases.forEach(function(testCase){
  206. it(testCase.title, function () {
  207. controller.clear();
  208. for(var id in testCase.condition) {
  209. controller.pushObject(Ember.Object.create({
  210. 'serviceName':id, 'isSelected': testCase.condition[id], 'canBeSelected': true, 'isInstalled': false,
  211. coSelectedServices: function() {
  212. return App.StackService.coSelected[this.get('serviceName')] || [];
  213. }.property('serviceName')
  214. }));
  215. }
  216. controller.setGroupedServices();
  217. for(var service in testCase.result) {
  218. expect(controller.findProperty('serviceName', service).get('isSelected')).to.equal(testCase.result[service]);
  219. }
  220. });
  221. }, this);
  222. });
  223. describe('#addValidationError()', function() {
  224. var tests = [
  225. {
  226. errorObjects: [
  227. {
  228. id: 'serviceCheck_ZOOKEEPER',
  229. shouldBeAdded: true
  230. },
  231. {
  232. id: 'serviceCheck_YARN',
  233. shouldBeAdded: true
  234. }
  235. ],
  236. expectedIds: ['serviceCheck_ZOOKEEPER', 'serviceCheck_YARN']
  237. },
  238. {
  239. errorObjects: [
  240. {
  241. id: 'fsCheck',
  242. shouldBeAdded: true
  243. },
  244. {
  245. id: 'fsCheck',
  246. shouldBeAdded: false
  247. }
  248. ],
  249. expectedIds: ['fsCheck']
  250. }
  251. ];
  252. beforeEach(function() {
  253. controller.clear();
  254. controller.set('errorStack', []);
  255. });
  256. tests.forEach(function(test) {
  257. var message = 'Erorrs {0} thrown. errorStack property should contains ids: {1}'
  258. .format(test.errorObjects.mapProperty('id').join(', '), test.expectedIds.join(', '));
  259. it(message, function() {
  260. test.errorObjects.forEach(function(errorObject) {
  261. expect(controller.addValidationError(errorObject)).to.equal(errorObject.shouldBeAdded);
  262. });
  263. expect(controller.get('errorStack').mapProperty('id')).to.eql(test.expectedIds);
  264. });
  265. })
  266. });
  267. describe('#validate()', function() {
  268. var tests = [
  269. {
  270. services: ['HDFS','ZOOKEEPER'],
  271. errorsExpected: ['monitoringCheck']
  272. },
  273. {
  274. services: ['ZOOKEEPER'],
  275. errorsExpected: ['fsCheck', 'monitoringCheck']
  276. },
  277. {
  278. services: ['HDFS'],
  279. errorsExpected: ['serviceCheck_ZOOKEEPER', 'monitoringCheck']
  280. },
  281. {
  282. services: ['HDFS', 'TEZ', 'ZOOKEEPER'],
  283. errorsExpected: ['serviceCheck_YARN', 'monitoringCheck']
  284. },
  285. {
  286. services: ['HDFS', 'ZOOKEEPER', 'FALCON', 'NAGIOS'],
  287. errorsExpected: ['serviceCheck_OOZIE', 'monitoringCheck']
  288. },
  289. {
  290. services: ['HDFS', 'ZOOKEEPER', 'GANGLIA', 'NAGIOS', 'HIVE'],
  291. errorsExpected: ['serviceCheck_YARN']
  292. },
  293. {
  294. services: ['HDFS', 'GLUSTERFS', 'ZOOKEEPER', 'HIVE'],
  295. errorsExpected: ['serviceCheck_YARN', 'multipleDFS', 'monitoringCheck']
  296. },
  297. {
  298. services: ['HDFS','ZOOKEEPER', 'NAGIOS', 'GANGLIA'],
  299. errorsExpected: []
  300. }
  301. ];
  302. tests.forEach(function(test) {
  303. var message = '{0} selected validation should be {1}, errors with ids: {2} present'
  304. .format(test.services.join(','), !!test.validationPassed ? 'passed' : 'failed', test.errorsExpected.join(','));
  305. it(message, function() {
  306. controller.clear();
  307. controller.set('content', generateSelectedServicesContent(test.services));
  308. controller.validate();
  309. expect(controller.get('errorStack').mapProperty('id')).to.be.eql(test.errorsExpected);
  310. });
  311. })
  312. });
  313. describe('#onPrimaryPopupCallback()', function() {
  314. var c;
  315. var tests = [
  316. {
  317. services: ['HDFS','ZOOKEEPER'],
  318. confirmPopupCount: 1,
  319. errorsExpected: ['monitoringCheck']
  320. },
  321. {
  322. services: ['ZOOKEEPER'],
  323. confirmPopupCount: 2,
  324. errorsExpected: ['fsCheck', 'monitoringCheck']
  325. },
  326. {
  327. services: ['HDFS', 'GLUSTERFS', 'ZOOKEEPER', 'HIVE'],
  328. confirmPopupCount: 3,
  329. errorsExpected: ['serviceCheck_YARN', 'serviceCheck_TEZ', 'multipleDFS', 'monitoringCheck']
  330. },
  331. {
  332. services: ['HDFS','ZOOKEEPER', 'NAGIOS', 'GANGLIA'],
  333. confirmPopupCount: 0,
  334. errorsExpected: []
  335. }
  336. ];
  337. beforeEach(function() {
  338. c = App.WizardStep4Controller.create({});
  339. sinon.stub(App.router, 'send', Em.K);
  340. sinon.stub(c, 'submit', Em.K);
  341. sinon.spy(c, 'onPrimaryPopupCallback');
  342. });
  343. afterEach(function() {
  344. App.router.send.restore();
  345. c.submit.restore();
  346. c.onPrimaryPopupCallback.restore();
  347. });
  348. tests.forEach(function(test) {
  349. var message = 'Selected services: {0}. {1} errors should be confirmed'
  350. .format(test.services.join(', '), test.confirmPopupCount);
  351. it(message, function() {
  352. var runValidations = function() {
  353. c.serviceDependencyValidation();
  354. c.fileSystemServiceValidation();
  355. c.serviceMonitoringValidation();
  356. }
  357. c.set('content', generateSelectedServicesContent(test.services));
  358. runValidations();
  359. // errors count validation
  360. expect(c.get('errorStack.length')).to.equal(test.confirmPopupCount);
  361. // if errors detected than it should be shown
  362. if (test.errorsExpected) {
  363. test.errorsExpected.forEach(function(error, index, errors) {
  364. // validate current error
  365. var currentErrorObject = c.get('errorStack').findProperty('isShown', false);
  366. if (currentErrorObject) {
  367. expect(error).to.be.equal(currentErrorObject.id);
  368. // show current error
  369. var popup = c.showError(currentErrorObject);
  370. // submit popup
  371. popup.onPrimary();
  372. // onPrimaryPopupCallback should be called
  373. expect(c.onPrimaryPopupCallback.called).to.equal(true);
  374. // submit called
  375. expect(c.submit.called).to.equal(true);
  376. if (c.get('errorStack').length) {
  377. // current error isShown flag changed to true
  378. expect(currentErrorObject.isShown).to.equal(true);
  379. }
  380. runValidations();
  381. }
  382. });
  383. }
  384. });
  385. });
  386. });
  387. describe('#needToAddServicePopup', function() {
  388. Em.A([
  389. {
  390. m: 'one service',
  391. services: {selected: true, serviceName: 's1'},
  392. content: [Em.Object.create({serviceName: 's1', isSelected: false})],
  393. e: [true]
  394. },
  395. {
  396. m: 'many services',
  397. services: [{selected: true, serviceName: 's1'}, {selected: false, serviceName: 's2'}],
  398. content: [Em.Object.create({serviceName: 's1', isSelected: false}),
  399. Em.Object.create({serviceName: 's2', isSelected: true})],
  400. e: [true, false]
  401. }
  402. ]).forEach(function (test) {
  403. it(test.m, function () {
  404. sinon.stub(controller, 'submit', Em.K);
  405. controller.set('content', test.content);
  406. controller.needToAddServicePopup(test.services, '').onPrimary();
  407. expect(controller.submit.calledOnce).to.equal(true);
  408. expect(controller.mapProperty('isSelected')).to.eql(test.e);
  409. controller.submit.restore();
  410. });
  411. });
  412. });
  413. describe('#submit', function() {
  414. var c;
  415. var tests = [
  416. {
  417. isSubmitDisabled: true,
  418. validate: false,
  419. userCanProceed: false
  420. },
  421. {
  422. isSubmitDisabled: false,
  423. validate: false,
  424. userCanProceed: false
  425. },
  426. {
  427. isSubmitDisabled: false,
  428. validate: true,
  429. userCanProceed: true
  430. }
  431. ];
  432. beforeEach(function() {
  433. c = App.WizardStep4Controller.create();
  434. sinon.stub(App.router, 'send', Em.K);
  435. });
  436. afterEach(function() {
  437. App.router.send.restore();
  438. });
  439. tests.forEach(function(test) {
  440. var messageFormat = [
  441. test.isSubmitDisabled ? 'disabled' : 'enabled',
  442. test.validate ? 'success' : 'failed',
  443. test.userCanProceed ? '' : 'not'
  444. ];
  445. var message = String.prototype.format.apply('Submit btn: {0}. Validation: {1}. Can{2} move to the next step.', messageFormat);
  446. it(message, function() {
  447. c.reopen({
  448. isSubmitDisabled: test.isSubmitDisabled,
  449. validate: function() { return test.validate; }
  450. });
  451. c.clear();
  452. c.submit();
  453. expect(App.router.send.calledOnce).to.equal(test.userCanProceed);
  454. });
  455. })
  456. });
  457. });