This is an automated email from the ASF dual-hosted git repository.

akovalenko 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 813f938  AMBARI-25145. Cover controllers of High Availability wizard 
with unit tests
813f938 is described below

commit 813f9386eeefe8ecb57672cc850c76a70193ec6c
Author: Aleksandr Kovalenko <akovale...@apache.org>
AuthorDate: Tue Feb 5 19:32:46 2019 +0200

    AMBARI-25145. Cover controllers of High Availability wizard with unit tests
---
 ambari-web/app/assets/test/tests.js                |   2 +
 .../hawq/removeStandby/step2_controller_test.js    |  35 ++-
 .../hawq/removeStandby/step3_controller_test.js    | 167 +++++++++++++
 .../hawq/removeStandby/wizard_controller_test.js   | 260 +++++++++++++++++++++
 4 files changed, 458 insertions(+), 6 deletions(-)

diff --git a/ambari-web/app/assets/test/tests.js 
b/ambari-web/app/assets/test/tests.js
index 5e0b52c..ca7b58b 100644
--- a/ambari-web/app/assets/test/tests.js
+++ b/ambari-web/app/assets/test/tests.js
@@ -93,6 +93,8 @@ var files = [
   
'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/removeStandby/step3_controller_test',
+  
'test/controllers/main/admin/highAvailability/hawq/removeStandby/wizard_controller_test',
   
'test/controllers/main/admin/highAvailability/hawq/activateStandby/step2_controller_test',
   
'test/controllers/main/admin/highAvailability/hawq/activateStandby/step3_controller_test',
   
'test/controllers/main/admin/highAvailability/journalNode/progress_controller_test',
diff --git 
a/ambari-web/test/controllers/main/admin/highAvailability/hawq/removeStandby/step2_controller_test.js
 
b/ambari-web/test/controllers/main/admin/highAvailability/hawq/removeStandby/step2_controller_test.js
index 0a55445..0bb1217 100644
--- 
a/ambari-web/test/controllers/main/admin/highAvailability/hawq/removeStandby/step2_controller_test.js
+++ 
b/ambari-web/test/controllers/main/admin/highAvailability/hawq/removeStandby/step2_controller_test.js
@@ -20,13 +20,18 @@ var App = require('app');
 
require('controllers/main/admin/highAvailability/hawq/removeStandby/step2_controller');
 
 describe('App.RemoveHawqStandbyWizardStep2Controller', function () {
-
+  
+  var controller;
+  
+  beforeEach(function() {
+    controller = App.RemoveHawqStandbyWizardStep2Controller.create({
+      content: Em.Object.create({})
+    })
+  });
+  
   describe('#isSubmitDisabled', function () {
 
-    var controller = App.RemoveHawqStandbyWizardStep2Controller.create({
-        content: Em.Object.create({})
-      }),
-      cases = [
+    var cases = [
         {
           isLoaded: false,
           isSubmitDisabled: true,
@@ -45,8 +50,26 @@ describe('App.RemoveHawqStandbyWizardStep2Controller', 
function () {
         
expect(controller.get('isSubmitDisabled')).to.equal(item.isSubmitDisabled);
       });
     });
-
   });
 
+  
+  describe('#submit', function() {
+    beforeEach(function() {
+      sinon.stub(App, 'get').returns({
+        getKDCSessionState: Em.clb
+      });
+      sinon.stub(App.router, 'send');
+    });
+    afterEach(function() {
+      App.get.restore();
+      App.router.send.restore();
+    });
+    
+    it('App.router.send should be called', function() {
+      controller.set('isLoaded', true);
+      controller.submit();
+      expect(App.router.send.calledWith('next')).to.be.true;
+    });
+  });
 
 });
diff --git 
a/ambari-web/test/controllers/main/admin/highAvailability/hawq/removeStandby/step3_controller_test.js
 
b/ambari-web/test/controllers/main/admin/highAvailability/hawq/removeStandby/step3_controller_test.js
new file mode 100644
index 0000000..f1aa0d5
--- /dev/null
+++ 
b/ambari-web/test/controllers/main/admin/highAvailability/hawq/removeStandby/step3_controller_test.js
@@ -0,0 +1,167 @@
+/**
+ * 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');
+var testHelpers = require('test/helpers');
+require('controllers/main/admin/highAvailability/hawq/removeStandby/step3_controller');
+
+describe('App.RemoveHawqStandbyWizardStep3Controller', function () {
+  
+  var controller;
+  
+  beforeEach(function() {
+    controller = App.RemoveHawqStandbyWizardStep3Controller.create({
+      content: Em.Object.create({}),
+      deleteComponent: Em.K,
+      startServices: Em.K,
+      onTaskCompleted: Em.K
+    });
+  });
+  
+  describe('#removeStandby', function() {
+    
+    it('App.ajax.send should be called', function() {
+      controller.set('content.hawqHosts', {hawqMaster: ['host1']});
+      controller.removeStandby();
+      
+      expect(testHelpers.findAjaxRequest('name', 
'service.item.executeCustomCommand')[0].data).to.be.eql({
+        command: 'REMOVE_HAWQ_STANDBY',
+        context: 
Em.I18n.t('admin.removeHawqStandby.wizard.step3.removeHawqStandbyCommand.context'),
+        hosts: ['host1'],
+        serviceName: 'HAWQ',
+        componentName: 'HAWQMASTER'
+      });
+    });
+  });
+  
+  describe('#stopRequiredServices', function() {
+    beforeEach(function() {
+      sinon.stub(controller, 'stopServices');
+    });
+    afterEach(function() {
+      controller.stopServices.restore();
+    });
+    
+    it('stopServices should be called', function() {
+      controller.stopRequiredServices();
+      expect(controller.stopServices.calledWith(['HAWQ'], true)).to.be.true;
+    });
+  });
+  
+  describe('#reconfigureHAWQ', function() {
+    
+    it('App.ajax.send should be called', function() {
+      controller.reconfigureHAWQ();
+      
+      expect(testHelpers.findAjaxRequest('name', 'config.tags')[0]).to.be.eql({
+        name: 'config.tags',
+        sender: controller,
+        success: 'onLoadHawqConfigsTags',
+        error: 'onTaskError'
+      });
+    });
+  });
+  
+  describe('#onLoadHawqConfigsTags', function() {
+    
+    it('App.ajax.send should be called', function() {
+      controller.onLoadHawqConfigsTags({Clusters: {desired_configs: 
{'hawq-site': {tag: 'tag1'}}}});
+      
+      expect(testHelpers.findAjaxRequest('name', 
'reassign.load_configs')[0]).to.be.eql({
+        name: 'reassign.load_configs',
+        sender: controller,
+        data: {
+          urlParams: '(type=hawq-site&tag=tag1)',
+          type: 'hawq-site'
+        },
+        success: 'onLoadConfigs',
+        error: 'onTaskError'
+      });
+    });
+  });
+  
+  describe('#onLoadConfigs', function() {
+  
+    beforeEach(function() {
+      sinon.stub(controller, 'reconfigureSites').returns({});
+    });
+    afterEach(function() {
+      controller.reconfigureSites.restore();
+    });
+    
+    it('App.ajax.send should be called', function() {
+      controller.onLoadConfigs({items: [{properties: {}}]}, {}, {type: 
'type1'});
+      
+      expect(testHelpers.findAjaxRequest('name', 
'common.service.configurations')[0]).to.be.eql({
+        name: 'common.service.configurations',
+        sender: controller,
+        data: {
+          desired_config: {}
+        },
+        success: 'onSaveConfigs',
+        error: 'onTaskError'
+      });
+    });
+  });
+  
+  describe('#onSaveConfigs', function() {
+    beforeEach(function() {
+      sinon.stub(controller, 'onTaskCompleted');
+    });
+    afterEach(function() {
+      controller.onTaskCompleted.restore();
+    });
+    
+    it('onTaskCompleted should be called', function() {
+      controller.onSaveConfigs();
+      expect(controller.onTaskCompleted.calledOnce).to.be.true;
+    });
+  });
+  
+  describe('#deleteHawqStandbyComponent', function() {
+    beforeEach(function() {
+      sinon.stub(controller, 'deleteComponent');
+    });
+    afterEach(function() {
+      controller.deleteComponent.restore();
+    });
+    
+    it('deleteComponent should be called', function() {
+      controller.set('content.hawqHosts', {hawqStandby: 'host1'});
+      controller.deleteHawqStandbyComponent();
+      expect(controller.deleteComponent.calledWith('HAWQSTANDBY', 
'host1')).to.be.true;
+    });
+  });
+  
+  describe('#startRequiredServices', function() {
+    beforeEach(function() {
+      sinon.stub(controller, 'startServices');
+    });
+    afterEach(function() {
+      controller.startServices.restore();
+    });
+    
+    it('startServices should be called', function() {
+      controller.startRequiredServices();
+      expect(controller.startServices.calledWith(false, ['HAWQ'], 
true)).to.be.true;
+    });
+  });
+  
+
+
+});
diff --git 
a/ambari-web/test/controllers/main/admin/highAvailability/hawq/removeStandby/wizard_controller_test.js
 
b/ambari-web/test/controllers/main/admin/highAvailability/hawq/removeStandby/wizard_controller_test.js
new file mode 100644
index 0000000..938e4f4
--- /dev/null
+++ 
b/ambari-web/test/controllers/main/admin/highAvailability/hawq/removeStandby/wizard_controller_test.js
@@ -0,0 +1,260 @@
+/**
+ * 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/removeStandby/step3_controller');
+
+describe('App.RemoveHawqStandbyWizardController', function () {
+  
+  var controller;
+  
+  beforeEach(function() {
+    controller = App.RemoveHawqStandbyWizardController.create();
+  });
+  
+  
+  describe('#loadMap', function() {
+    
+    describe('#step1', function() {
+      beforeEach(function() {
+        sinon.stub(controller, 'load');
+      });
+      afterEach(function() {
+        controller.load.restore();
+      });
+      
+      it('load should be called', function() {
+        controller.loadMap['1'][0].callback.apply(controller);
+        expect(controller.load.calledWith('cluster')).to.be.true;
+      });
+    });
+    
+    describe('#step2', function() {
+      beforeEach(function() {
+        sinon.stub(controller, 'loadHawqHosts');
+        sinon.stub(controller, 'loadServicesFromServer');
+        sinon.stub(controller, 'loadMasterComponentHosts').returns({done: 
Em.clb})
+      });
+      afterEach(function() {
+        controller.loadHawqHosts.restore();
+        controller.loadServicesFromServer.restore();
+        controller.loadMasterComponentHosts.restore();
+      });
+    
+      it('loadHawqHosts should be called', function() {
+        controller.loadMap['2'][0].callback.apply(controller);
+        expect(controller.loadHawqHosts.calledOnce).to.be.true;
+      });
+      it('loadServicesFromServer should be called', function() {
+        controller.loadMap['2'][0].callback.apply(controller);
+        expect(controller.loadServicesFromServer.calledOnce).to.be.true;
+      });
+      it('loadMasterComponentHosts should be called', function() {
+        controller.loadMap['2'][0].callback.apply(controller);
+        expect(controller.loadMasterComponentHosts.calledOnce).to.be.true;
+      });
+    });
+  
+    describe('#step3', function() {
+      beforeEach(function() {
+        sinon.stub(controller, 'loadTasksStatuses');
+        sinon.stub(controller, 'loadTasksRequestIds');
+        sinon.stub(controller, 'loadRequestIds');
+        sinon.stub(controller, 'loadConfigs');
+      });
+      afterEach(function() {
+        controller.loadTasksStatuses.restore();
+        controller.loadTasksRequestIds.restore();
+        controller.loadRequestIds.restore();
+        controller.loadConfigs.restore();
+      });
+    
+      it('loadTasksStatuses should be called', function() {
+        controller.loadMap['3'][0].callback.apply(controller);
+        expect(controller.loadTasksStatuses.calledOnce).to.be.true;
+      });
+      it('loadTasksRequestIds should be called', function() {
+        controller.loadMap['3'][0].callback.apply(controller);
+        expect(controller.loadTasksRequestIds.calledOnce).to.be.true;
+      });
+      it('loadRequestIds should be called', function() {
+        controller.loadMap['3'][0].callback.apply(controller);
+        expect(controller.loadRequestIds.calledOnce).to.be.true;
+      });
+      it('loadConfigs should be called', function() {
+        controller.loadMap['3'][0].callback.apply(controller);
+        expect(controller.loadConfigs.calledOnce).to.be.true;
+      });
+    });
+  });
+  
+  describe('#init', function() {
+    beforeEach(function() {
+      sinon.stub(controller, 'clearStep');
+    });
+    afterEach(function() {
+      controller.clearStep.restore();
+    });
+    
+    it('clearStep should be called', function() {
+      controller.init();
+      expect(controller.clearStep.calledOnce).to.be.true;
+    });
+  });
+  
+  describe('#clearStep', function() {
+    
+    it('isFinished should be false', function() {
+      controller.clearStep();
+      expect(controller.get('isFinished')).to.be.false;
+    });
+  });
+  
+  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');
+    });
+    afterEach(function() {
+      controller.setDBProperty.restore();
+    });
+    
+    it('setDBProperty should be called', function() {
+      controller.saveHawqHosts(['host1']);
+      expect(controller.setDBProperty.calledWith('hawqHosts', 
['host1'])).to.be.true;
+    });
+  
+    it('should set hawqHosts', function() {
+      controller.saveHawqHosts(['host1']);
+      expect(controller.get('content.hawqHosts')).to.be.eql(['host1']);
+    });
+  });
+  
+  describe('#loadHawqHosts', function() {
+    beforeEach(function() {
+      sinon.stub(controller, 'getDBProperty').returns(['host1']);
+    });
+    afterEach(function() {
+      controller.getDBProperty.restore();
+    });
+    
+    it('should set hawqHosts', function() {
+      controller.loadHawqHosts();
+      expect(controller.get('content.hawqHosts')).to.be.eql(['host1']);
+    });
+  });
+  
+  describe('#saveConfigs', function() {
+    beforeEach(function() {
+      sinon.stub(controller, 'setDBProperty');
+    });
+    afterEach(function() {
+      controller.setDBProperty.restore();
+    });
+    
+    it('setDBProperty should be called', function() {
+      controller.saveConfigs([{}]);
+      expect(controller.setDBProperty.calledWith('configs', [{}])).to.be.true;
+    });
+    
+    it('should set configs', function() {
+      controller.saveConfigs([{}]);
+      expect(controller.get('content.configs')).to.be.eql([{}]);
+    });
+  });
+  
+  describe('#loadConfigs', function() {
+    beforeEach(function() {
+      sinon.stub(controller, 'getDBProperty').returns([{}]);
+    });
+    afterEach(function() {
+      controller.getDBProperty.restore();
+    });
+    
+    it('should set configs', function() {
+      controller.loadConfigs();
+      expect(controller.get('content.configs')).to.be.eql([{}]);
+    });
+  });
+  
+  describe('#clearAllSteps', function() {
+    beforeEach(function() {
+      sinon.stub(controller, 'clearInstallOptions');
+      sinon.stub(controller, 'getCluster').returns({clusterName: 'c1'})
+    });
+    afterEach(function() {
+      controller.clearInstallOptions.restore();
+      controller.getCluster.restore();
+    });
+  
+    it('clearInstallOptions should be called', function() {
+      controller.clearAllSteps();
+      expect(controller.clearInstallOptions.calledOnce).to.be.true;
+    });
+  
+    it('cluster should be set', function() {
+      controller.clearAllSteps();
+      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);
+    });
+    afterEach(function() {
+      controller.resetDbNamespace.restore();
+      App.router.get.restore();
+    });
+    
+    it('resetDbNamespace should be called', function() {
+      controller.finish();
+      expect(controller.resetDbNamespace.calledOnce).to.be.true;
+    });
+    it('isFinished should be true', function() {
+      controller.finish();
+      expect(controller.get('isFinished')).to.be.true;
+    });
+    it('updateAll should be called', function() {
+      controller.finish();
+      expect(mock.updateAll.called).to.be.true;
+    });
+  });
+  
+  
+  
+  
+
+});

Reply via email to