This is an automated email from the ASF dual-hosted git repository. atkach pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ambari.git
The following commit(s) were added to refs/heads/trunk by this push: new 1b58df7 AMBARI-25082 Cover HA wizard controller with unit tests 1b58df7 is described below commit 1b58df7829ad92fdb81042f29d97a07257d90705 Author: Andrii Tkach <atk...@apache.org> AuthorDate: Thu Jan 3 13:41:47 2019 +0200 AMBARI-25082 Cover HA wizard controller with unit tests --- ambari-web/app/assets/test/tests.js | 1 + .../hawq/addStandby/step3_controller.js | 4 +- .../hawq/addStandby/step3_controller_test.js | 75 ++++++- .../hawq/addStandby/wizard_controller_test.js | 234 +++++++++++++++++++++ 4 files changed, 311 insertions(+), 3 deletions(-) diff --git a/ambari-web/app/assets/test/tests.js b/ambari-web/app/assets/test/tests.js index 4f27190..3fe472b 100644 --- a/ambari-web/app/assets/test/tests.js +++ b/ambari-web/app/assets/test/tests.js @@ -91,6 +91,7 @@ var files = [ 'test/controllers/main/admin/highAvailability/resourceManager/wizard_controller_test', 'test/controllers/main/admin/highAvailability/hawq/addStandby/step3_controller_test', 'test/controllers/main/admin/highAvailability/hawq/addStandby/step4_controller_test', + 'test/controllers/main/admin/highAvailability/hawq/addStandby/wizard_controller_test', 'test/controllers/main/admin/highAvailability/hawq/removeStandby/step2_controller_test', 'test/controllers/main/admin/highAvailability/hawq/activateStandby/step2_controller_test', 'test/controllers/main/admin/highAvailability/hawq/activateStandby/step3_controller_test', diff --git a/ambari-web/app/controllers/main/admin/highAvailability/hawq/addStandby/step3_controller.js b/ambari-web/app/controllers/main/admin/highAvailability/hawq/addStandby/step3_controller.js index bc454c2..ccd4da8 100644 --- a/ambari-web/app/controllers/main/admin/highAvailability/hawq/addStandby/step3_controller.js +++ b/ambari-web/app/controllers/main/admin/highAvailability/hawq/addStandby/step3_controller.js @@ -139,8 +139,8 @@ App.AddHawqStandbyWizardStep3Controller = Em.Controller.extend({ submit: function () { if (!this.get('isSubmitDisabled')) { - dataDir = this.get('hawqProps').items[0].properties['hawq_master_directory']; - hawqStandby = this.get('content.hawqHosts.newHawqStandby'); + const dataDir = this.get('hawqProps').items[0].properties['hawq_master_directory']; + const hawqStandby = this.get('content.hawqHosts.newHawqStandby'); App.showConfirmationPopup( function() { App.get('router.mainAdminKerberosController').getKDCSessionState(function() { diff --git a/ambari-web/test/controllers/main/admin/highAvailability/hawq/addStandby/step3_controller_test.js b/ambari-web/test/controllers/main/admin/highAvailability/hawq/addStandby/step3_controller_test.js index 2180248..039c6e7 100644 --- a/ambari-web/test/controllers/main/admin/highAvailability/hawq/addStandby/step3_controller_test.js +++ b/ambari-web/test/controllers/main/admin/highAvailability/hawq/addStandby/step3_controller_test.js @@ -182,5 +182,78 @@ describe('App.AddHawqStandbyWizardStep3Controller', function () { expect(configs.configs.findProperty('name', 'hawq_standby_address_host').get('recommendedValue')).to.equal('h1'); }); }); - + + describe('#loadStep', function() { + beforeEach(function() { + sinon.stub(controller, 'renderConfigs'); + }); + afterEach(function() { + controller.renderConfigs.restore(); + }); + + it('renderConfigs should be called', function() { + controller.loadStep(); + expect(controller.renderConfigs.calledOnce).to.be.true; + }); + }); + + describe('#renderConfigs', function() { + beforeEach(function() { + sinon.stub(App.Service, 'find').returns([{ + serviceName: 'HAWQ' + }]); + sinon.stub(controller, 'renderConfigProperties'); + controller.renderConfigs(); + }); + afterEach(function() { + App.Service.find.restore(); + controller.renderConfigProperties.restore(); + }); + + it('Request should be sent', function() { + var request = testHelpers.findAjaxRequest('name', 'config.tags'); + expect(request[0]).to.exist; + }); + + it('renderConfigProperties should be called', function() { + expect(controller.renderConfigProperties.calledOnce).to.be.true; + }); + }); + + describe('#renderConfigProperties', function() { + + it('should move component configs', function() { + var _componentConfig = {configs: [{isReconfigurable: true}]}; + var componentConfig = {configs: []}; + controller.renderConfigProperties(_componentConfig, componentConfig); + expect(componentConfig.configs).to.not.be.empty; + expect(componentConfig.configs[0].get('isEditable')).to.be.true; + }); + }); + + describe('#submit', function() { + beforeEach(function() { + sinon.stub(App, 'showConfirmationPopup', Em.clb); + sinon.stub(App, 'get').returns({getKDCSessionState: Em.clb}); + sinon.stub(App.router, 'send'); + controller.set('isLoaded', true); + controller.set('hawqProps', {items: [{properties: {'hawq_master_directory': 'dir'}}]}); + controller.submit(); + }); + afterEach(function() { + App.showConfirmationPopup.restore(); + App.get.restore(); + App.router.send.restore(); + }); + + it('App.showConfirmationPopup should be called', function() { + expect(App.showConfirmationPopup.calledOnce).to.be.true; + }); + + it('App.router.send should be called', function() { + expect(App.router.send.calledWith('next')).to.be.true; + }); + }); + + }); diff --git a/ambari-web/test/controllers/main/admin/highAvailability/hawq/addStandby/wizard_controller_test.js b/ambari-web/test/controllers/main/admin/highAvailability/hawq/addStandby/wizard_controller_test.js new file mode 100644 index 0000000..8b01514 --- /dev/null +++ b/ambari-web/test/controllers/main/admin/highAvailability/hawq/addStandby/wizard_controller_test.js @@ -0,0 +1,234 @@ +/** + * 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 App = require('app'); +require('controllers/main/admin/highAvailability/hawq/addStandby/wizard_controller'); + +function getController() { + return App.AddHawqStandbyWizardController.create(); +} +var controller; + +describe('App.AddHawqStandbyWizardController', function () { + + beforeEach(function () { + controller = getController(); + }); + + describe('#loadMap', function() { + describe('#step1', function() { + var step; + beforeEach(function() { + step = controller.get('loadMap')['1']; + sinon.stub(controller, 'load'); + }); + afterEach(function() { + controller.load.restore(); + }); + + it('load should be called', function() { + step[0].callback.apply(controller); + expect(controller.load.calledWith('cluster')).to.be.true; + }); + }); + describe('#step2', function() { + var step; + beforeEach(function() { + step = controller.get('loadMap')['2']; + sinon.stub(controller, 'loadHawqHosts'); + sinon.stub(controller, 'loadServicesFromServer'); + sinon.stub(controller, 'loadMasterComponentHosts').returns({done: Em.clb}); + sinon.stub(controller, 'loadConfirmedHosts'); + step[0].callback.apply(controller); + }); + afterEach(function() { + controller.loadHawqHosts.restore(); + controller.loadServicesFromServer.restore(); + controller.loadMasterComponentHosts.restore(); + controller.loadConfirmedHosts.restore(); + }); + + it('loadHawqHosts should be called', function() { + expect(controller.loadHawqHosts.calledOnce).to.be.true; + }); + it('loadServicesFromServer should be called', function() { + expect(controller.loadServicesFromServer.calledOnce).to.be.true; + }); + it('loadMasterComponentHosts should be called', function() { + expect(controller.loadMasterComponentHosts.calledOnce).to.be.true; + }); + it('loadConfirmedHosts should be called', function() { + expect(controller.loadConfirmedHosts.calledOnce).to.be.true; + }); + }); + describe('#step4', function() { + var step; + beforeEach(function() { + step = controller.get('loadMap')['4']; + sinon.stub(controller, 'loadTasksStatuses'); + sinon.stub(controller, 'loadTasksRequestIds'); + sinon.stub(controller, 'loadRequestIds').returns({done: Em.clb}); + sinon.stub(controller, 'loadConfigs'); + step[0].callback.apply(controller); + }); + afterEach(function() { + controller.loadTasksStatuses.restore(); + controller.loadTasksRequestIds.restore(); + controller.loadRequestIds.restore(); + controller.loadConfigs.restore(); + }); + + it('loadTasksStatuses should be called', function() { + expect(controller.loadTasksStatuses.calledOnce).to.be.true; + }); + it('loadTasksRequestIds should be called', function() { + expect(controller.loadTasksRequestIds.calledOnce).to.be.true; + }); + it('loadRequestIds should be called', function() { + expect(controller.loadRequestIds.calledOnce).to.be.true; + }); + it('loadConfigs should be called', function() { + expect(controller.loadConfigs.calledOnce).to.be.true; + }); + }); + }); + + describe('#setCurrentStep', function() { + beforeEach(function() { + sinon.stub(App.clusterStatus, 'setClusterStatus'); + }); + afterEach(function() { + App.clusterStatus.setClusterStatus.restore(); + }); + + it('App.clusterStatus.setClusterStatus should be called', function() { + controller.setCurrentStep(); + expect(App.clusterStatus.setClusterStatus.calledOnce).to.be.true; + }); + }); + + describe('#saveHawqHosts', function() { + beforeEach(function() { + sinon.stub(controller, 'setDBProperty'); + controller.saveHawqHosts(['host1']); + }); + afterEach(function() { + controller.setDBProperty.restore(); + }); + + it('hosts should be set to DB', function() { + expect(controller.setDBProperty.calledWith('hawqHosts', ['host1'])).to.be.true; + }); + + it('hosts should be set to content', function() { + expect(controller.get('content.hawqHosts')).to.be.eql(['host1']); + }); + }); + + describe('#loadHawqHosts', function() { + beforeEach(function() { + sinon.stub(controller, 'getDBProperty').returns(['host1']); + controller.loadHawqHosts(); + }); + afterEach(function() { + controller.getDBProperty.restore(); + }); + + it('hosts should be set to content', function() { + expect(controller.get('content.hawqHosts')).to.be.eql(['host1']); + }); + }); + + describe('#saveConfigs', function() { + beforeEach(function() { + sinon.stub(controller, 'setDBProperty'); + controller.saveConfigs([{}]); + }); + afterEach(function() { + controller.setDBProperty.restore(); + }); + + it('configs should be set to DB', function() { + expect(controller.setDBProperty.calledWith('configs', [{}])).to.be.true; + }); + + it('configs should be set to content', function() { + expect(controller.get('content.configs')).to.be.eql([{}]); + }); + }); + + describe('#loadConfigs', function() { + beforeEach(function() { + sinon.stub(controller, 'getDBProperty').returns([{}]); + controller.loadHawqHosts(); + }); + afterEach(function() { + controller.getDBProperty.restore(); + }); + + it('configs should be set to content', function() { + expect(controller.get('content.configs')).to.be.eql([{}]); + }); + }); + + describe('#clearAllSteps', function() { + beforeEach(function() { + sinon.stub(controller, 'clearInstallOptions'); + sinon.stub(controller, 'getCluster').returns({clusterName: 'c1'}); + controller.clearAllSteps(); + }); + afterEach(function() { + controller.clearInstallOptions.restore(); + controller.getCluster.restore(); + }); + + it('clearInstallOptions should be called', function() { + expect(controller.clearInstallOptions.calledOnce).to.be.true; + }); + + it('cluster should be set', function() { + expect(controller.get('content.cluster')).to.be.eql({clusterName: 'c1'}); + }); + }); + + describe('#finish', function() { + var mock = {updateAll: sinon.spy()}; + beforeEach(function() { + sinon.stub(controller, 'resetDbNamespace'); + sinon.stub(App.router, 'get').returns(mock); + controller.finish(); + }); + afterEach(function() { + controller.resetDbNamespace.restore(); + App.router.get.restore(); + }); + + it('resetDbNamespace should be called', function() { + expect(controller.resetDbNamespace.calledOnce).to.be.true; + }); + + it('updateAll should be called', function() { + expect(mock.updateAll.called).to.be.true; + }); + + it('isFinished should be true', function() { + expect(controller.get('isFinished')).to.be.true; + }); + }); + +});