123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498 |
- /**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- var Ember = require('ember');
- var App = require('app');
- var modelSetup = require('test/init_model_test');
- require('controllers/wizard/step4_controller');
- describe('App.WizardStep4Controller', function () {
- var services = [
- 'HDFS', 'MAPREDUCE', 'NAGIOS', 'GANGLIA', 'OOZIE', 'HIVE', 'HBASE', 'PIG', 'SCOOP', 'ZOOKEEPER', 'HCATALOG',
- 'WEBHCAT', 'YARN', 'MAPREDUCE2', 'FALCON', 'TEZ', 'STORM'
- ];
- var controller = App.WizardStep4Controller.create();
- var generateSelectedServicesContent = function(selectedServiceNames) {
- var allServices = services.slice(0);
- if (selectedServiceNames.contains('GLUSTERFS')) allServices.push('GLUSTERFS');
- allServices = allServices.map(function(serviceName) {
- return [Ember.Object.create({
- 'serviceName': serviceName,
- 'isSelected': false,
- 'canBeSelected': true,
- 'isInstalled': false,
- isPrimaryDFS: serviceName == 'HDFS',
- isDFS: ['HDFS','GLUSTERFS'].contains(serviceName),
- isMonitoringService: ['NAGIOS','GANGLIA'].contains(serviceName),
- dependentServices: App.StackService.dependency['HDP-2'][serviceName],
- displayNameOnSelectServicePage: App.format.role(serviceName),
- coSelectedServices: function() {
- return App.StackService.coSelected[this.get('serviceName')] || [];
- }.property('serviceName')
- })];
- }).reduce(function(current, prev) { return current.concat(prev); });
- selectedServiceNames.forEach(function(serviceName) {
- allServices.findProperty('serviceName', serviceName).set('isSelected', true);
- });
- return allServices;
- };
- services.forEach(function(serviceName, index){
- controller.pushObject(Ember.Object.create({
- 'serviceName':serviceName, 'isSelected': true, 'isHiddenOnSelectServicePage': false, 'isInstalled': false, 'isDisabled': 'HDFS' === serviceName, isDFS: 'HDFS' === serviceName
- }));
- });
- describe('#isSubmitDisabled', function () {
- it('should return false if at least one selected service is not installed', function () {
- expect(controller.get('isSubmitDisabled')).to.equal(false);
- });
- it('should return true if all selected services are already installed', function () {
- controller.setEach('isInstalled', true);
- controller.findProperty('serviceName', 'HDFS').set('isSelected', false);
- expect(controller.get('isSubmitDisabled')).to.equal(true);
- });
- });
- describe('#isAll', function () {
- it('should return true if all services are selected', function () {
- controller.setEach('isInstalled', false);
- controller.findProperty('serviceName', 'HDFS').set('isSelected', true);
- expect(controller.get('isAll')).to.equal(true);
- });
- it('should return false if at least one service is not selected', function () {
- controller.findProperty('serviceName', 'HDFS').set('isSelected', false);
- expect(controller.get('isAll')).to.equal(false);
- });
- });
- describe('#isMinimum', function () {
- it('should return true if there are no services selected, except disabled', function () {
- controller.setEach('isSelected', false);
- expect(controller.get('isMinimum')).to.equal(true);
- });
- it('should return false if at least one service is selected, except disabled', function () {
- controller.findProperty('serviceName', 'MAPREDUCE').set('isSelected', true);
- expect(controller.get('isMinimum')).to.equal(false);
- });
- });
- describe('#selectAll()', function () {
- it('should select all services', function () {
- controller.setEach('isSelected', false);
- controller.selectAll();
- expect(controller.filterProperty('canBeSelected', true).everyProperty('isSelected', true)).to.equal(true);
- });
- });
- describe('#selectMinimum()', function () {
- it('should set isSelected false for all services', function () {
- controller.setEach('isSelected', true);
- controller.selectMinimum();
- expect(controller.findProperty('serviceName', 'HDFS').get('isSelected')).to.equal(false);
- expect(controller.filterProperty('isDisabled', false).everyProperty('isSelected', false)).to.equal(true);
- });
- });
- describe('#noDFSs()', function () {
- it('should return true if HDFS is not selected and GLUSTERFS is absent', function () {
- controller.findProperty('serviceName', 'HDFS').set('isSelected', false);
- expect(controller.noDFSs()).to.equal(true);
- });
- it('should return false if HDFS is selected and GLUSTERFS is absent', function () {
- controller.findProperty('serviceName', 'HDFS').set('isSelected', true);
- expect(controller.noDFSs()).to.equal(false);
- });
- it('should return true if HDFS is not selected and GLUSTERFS is not selected, but present', function () {
- controller.pushObject(Ember.Object.create({
- 'serviceName':'GLUSTERFS', 'isSelected': false, 'canBeSelected': true, 'isInstalled': false, 'isDisabled': false, 'isDFS': true
- }));
- controller.findProperty('serviceName', 'HDFS').set('isSelected', false);
- expect(controller.noDFSs()).to.equal(true);
- });
- it('should return false if HDFS is not selected and GLUSTERFS is selected', function () {
- controller.findProperty('serviceName', 'GLUSTERFS').set('isSelected', true);
- expect(controller.noDFSs()).to.equal(false);
- });
- });
- describe('#multipleDFSs()', function () {
- it('should return true if HDFS is selected and GLUSTERFS is selected', function () {
- controller.findProperty('serviceName', 'HDFS').set('isSelected', true);
- controller.findProperty('serviceName', 'GLUSTERFS').set('isSelected', true);
- expect(controller.multipleDFSs()).to.equal(true);
- });
- it('should return false if HDFS is not selected and GLUSTERFS is selected', function () {
- controller.findProperty('serviceName', 'HDFS').set('isSelected', false);
- expect(controller.multipleDFSs()).to.equal(false);
- });
- it('should return false if HDFS is selected and GLUSTERFS is not selected', function () {
- controller.findProperty('serviceName', 'HDFS').set('isSelected', true);
- controller.findProperty('serviceName', 'GLUSTERFS').set('isSelected', false);
- expect(controller.multipleDFSs()).to.equal(false);
- });
- });
- describe('#setGroupedServices()', function () {
- var testCases = [
- {
- title: 'should set HCATALOG and WEBHCAT isSelected to true when HIVE is selected',
- condition: {
- 'HBASE': true,
- 'ZOOKEEPER': true,
- 'HIVE': true,
- 'HCATALOG': true,
- 'WEBHCAT': true
- },
- result: {
- 'HCATALOG': true,
- 'WEBHCAT': true
- }
- },
- {
- title: 'should set HCATALOG and WEBHCAT isSelected to false when HIVE is not selected',
- condition: {
- 'HBASE': true,
- 'ZOOKEEPER': true,
- 'HIVE': false,
- 'HCATALOG': true,
- 'WEBHCAT': true
- },
- result: {
- 'HCATALOG': false,
- 'WEBHCAT': false
- }
- },
- {
- title: 'should set MAPREDUCE2 isSelected to true when YARN is selected',
- condition: {
- 'HBASE': true,
- 'ZOOKEEPER': true,
- 'HIVE': false,
- 'HCATALOG': true,
- 'WEBHCAT': true,
- 'YARN': true,
- 'MAPREDUCE2': true
- },
- result: {
- 'MAPREDUCE2': true,
- 'HCATALOG': false,
- 'WEBHCAT': false
- }
- },
- {
- title: 'should set MAPREDUCE2 isSelected to false when YARN is not selected',
- condition: {
- 'HBASE': true,
- 'ZOOKEEPER': true,
- 'HIVE': true,
- 'HCATALOG': true,
- 'WEBHCAT': true,
- 'YARN': false,
- 'MAPREDUCE2': true
- },
- result: {
- 'MAPREDUCE2': false,
- 'HCATALOG': true,
- 'WEBHCAT': true
- }
- }
- ];
- testCases.forEach(function(testCase){
- it(testCase.title, function () {
- controller.clear();
- for(var id in testCase.condition) {
- controller.pushObject(Ember.Object.create({
- 'serviceName':id, 'isSelected': testCase.condition[id], 'canBeSelected': true, 'isInstalled': false,
- coSelectedServices: function() {
- return App.StackService.coSelected[this.get('serviceName')] || [];
- }.property('serviceName')
- }));
- }
- controller.setGroupedServices();
- for(var service in testCase.result) {
- expect(controller.findProperty('serviceName', service).get('isSelected')).to.equal(testCase.result[service]);
- }
- });
- }, this);
- });
- describe('#addValidationError()', function() {
- var tests = [
- {
- errorObjects: [
- {
- id: 'serviceCheck_ZOOKEEPER',
- shouldBeAdded: true
- },
- {
- id: 'serviceCheck_YARN',
- shouldBeAdded: true
- }
- ],
- expectedIds: ['serviceCheck_ZOOKEEPER', 'serviceCheck_YARN']
- },
- {
- errorObjects: [
- {
- id: 'fsCheck',
- shouldBeAdded: true
- },
- {
- id: 'fsCheck',
- shouldBeAdded: false
- }
- ],
- expectedIds: ['fsCheck']
- }
- ];
- beforeEach(function() {
- controller.clear();
- controller.set('errorStack', []);
- });
- tests.forEach(function(test) {
- var message = 'Erorrs {0} thrown. errorStack property should contains ids: {1}'
- .format(test.errorObjects.mapProperty('id').join(', '), test.expectedIds.join(', '));
- it(message, function() {
- test.errorObjects.forEach(function(errorObject) {
- expect(controller.addValidationError(errorObject)).to.equal(errorObject.shouldBeAdded);
- });
- expect(controller.get('errorStack').mapProperty('id')).to.eql(test.expectedIds);
- });
- })
- });
- describe('#validate()', function() {
- var tests = [
- {
- services: ['HDFS','ZOOKEEPER'],
- errorsExpected: ['monitoringCheck']
- },
- {
- services: ['ZOOKEEPER'],
- errorsExpected: ['fsCheck', 'monitoringCheck']
- },
- {
- services: ['HDFS'],
- errorsExpected: ['serviceCheck_ZOOKEEPER', 'monitoringCheck']
- },
- {
- services: ['HDFS', 'TEZ', 'ZOOKEEPER'],
- errorsExpected: ['serviceCheck_YARN', 'monitoringCheck']
- },
- {
- services: ['HDFS', 'ZOOKEEPER', 'FALCON', 'NAGIOS'],
- errorsExpected: ['serviceCheck_OOZIE', 'monitoringCheck']
- },
- {
- services: ['HDFS', 'ZOOKEEPER', 'GANGLIA', 'NAGIOS', 'HIVE'],
- errorsExpected: ['serviceCheck_YARN']
- },
- {
- services: ['HDFS', 'GLUSTERFS', 'ZOOKEEPER', 'HIVE'],
- errorsExpected: ['serviceCheck_YARN', 'multipleDFS', 'monitoringCheck']
- },
- {
- services: ['HDFS','ZOOKEEPER', 'NAGIOS', 'GANGLIA'],
- errorsExpected: []
- }
- ];
- tests.forEach(function(test) {
- var message = '{0} selected validation should be {1}, errors with ids: {2} present'
- .format(test.services.join(','), !!test.validationPassed ? 'passed' : 'failed', test.errorsExpected.join(','));
- it(message, function() {
- controller.clear();
- controller.set('content', generateSelectedServicesContent(test.services));
- controller.validate();
- expect(controller.get('errorStack').mapProperty('id')).to.be.eql(test.errorsExpected);
- });
- })
- });
- describe('#onPrimaryPopupCallback()', function() {
- var c;
- var tests = [
- {
- services: ['HDFS','ZOOKEEPER'],
- confirmPopupCount: 1,
- errorsExpected: ['monitoringCheck']
- },
- {
- services: ['ZOOKEEPER'],
- confirmPopupCount: 2,
- errorsExpected: ['fsCheck', 'monitoringCheck']
- },
- {
- services: ['HDFS', 'GLUSTERFS', 'ZOOKEEPER', 'HIVE'],
- confirmPopupCount: 3,
- errorsExpected: ['serviceCheck_YARN', 'serviceCheck_TEZ', 'multipleDFS', 'monitoringCheck']
- },
- {
- services: ['HDFS','ZOOKEEPER', 'NAGIOS', 'GANGLIA'],
- confirmPopupCount: 0,
- errorsExpected: []
- }
- ];
- beforeEach(function() {
- c = App.WizardStep4Controller.create({});
- sinon.stub(App.router, 'send', Em.K);
- sinon.stub(c, 'submit', Em.K);
- sinon.spy(c, 'onPrimaryPopupCallback');
- });
- afterEach(function() {
- App.router.send.restore();
- c.submit.restore();
- c.onPrimaryPopupCallback.restore();
- });
- tests.forEach(function(test) {
- var message = 'Selected services: {0}. {1} errors should be confirmed'
- .format(test.services.join(', '), test.confirmPopupCount);
- it(message, function() {
- var runValidations = function() {
- c.serviceDependencyValidation();
- c.fileSystemServiceValidation();
- c.serviceMonitoringValidation();
- }
- c.set('content', generateSelectedServicesContent(test.services));
- runValidations();
- // errors count validation
- expect(c.get('errorStack.length')).to.equal(test.confirmPopupCount);
- // if errors detected than it should be shown
- if (test.errorsExpected) {
- test.errorsExpected.forEach(function(error, index, errors) {
- // validate current error
- var currentErrorObject = c.get('errorStack').findProperty('isShown', false);
- if (currentErrorObject) {
- expect(error).to.be.equal(currentErrorObject.id);
- // show current error
- var popup = c.showError(currentErrorObject);
- // submit popup
- popup.onPrimary();
- // onPrimaryPopupCallback should be called
- expect(c.onPrimaryPopupCallback.called).to.equal(true);
- // submit called
- expect(c.submit.called).to.equal(true);
- if (c.get('errorStack').length) {
- // current error isShown flag changed to true
- expect(currentErrorObject.isShown).to.equal(true);
- }
- runValidations();
- }
- });
- }
- });
- });
- });
- describe('#needToAddServicePopup', function() {
- Em.A([
- {
- m: 'one service',
- services: {selected: true, serviceName: 's1'},
- content: [Em.Object.create({serviceName: 's1', isSelected: false})],
- e: [true]
- },
- {
- m: 'many services',
- services: [{selected: true, serviceName: 's1'}, {selected: false, serviceName: 's2'}],
- content: [Em.Object.create({serviceName: 's1', isSelected: false}),
- Em.Object.create({serviceName: 's2', isSelected: true})],
- e: [true, false]
- }
- ]).forEach(function (test) {
- it(test.m, function () {
- sinon.stub(controller, 'submit', Em.K);
- controller.set('content', test.content);
- controller.needToAddServicePopup(test.services, '').onPrimary();
- expect(controller.submit.calledOnce).to.equal(true);
- expect(controller.mapProperty('isSelected')).to.eql(test.e);
- controller.submit.restore();
- });
- });
- });
- describe('#submit', function() {
- var c;
- var tests = [
- {
- isSubmitDisabled: true,
- validate: false,
- userCanProceed: false
- },
- {
- isSubmitDisabled: false,
- validate: false,
- userCanProceed: false
- },
- {
- isSubmitDisabled: false,
- validate: true,
- userCanProceed: true
- }
- ];
- beforeEach(function() {
- c = App.WizardStep4Controller.create();
- sinon.stub(App.router, 'send', Em.K);
- });
- afterEach(function() {
- App.router.send.restore();
- });
- tests.forEach(function(test) {
- var messageFormat = [
- test.isSubmitDisabled ? 'disabled' : 'enabled',
- test.validate ? 'success' : 'failed',
- test.userCanProceed ? '' : 'not'
- ];
- var message = String.prototype.format.apply('Submit btn: {0}. Validation: {1}. Can{2} move to the next step.', messageFormat);
- it(message, function() {
- c.reopen({
- isSubmitDisabled: test.isSubmitDisabled,
- validate: function() { return test.validate; }
- });
- c.clear();
- c.submit();
- expect(App.router.send.calledOnce).to.equal(test.userCanProceed);
- });
- })
- });
- });
|