Repository: ambari Updated Branches: refs/heads/trunk 0a745f8ba -> 5c782dd84
http://git-wip-us.apache.org/repos/asf/ambari/blob/5c782dd8/ambari-web/test/controllers/main/admin/kerberos/step4_controller_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/main/admin/kerberos/step4_controller_test.js b/ambari-web/test/controllers/main/admin/kerberos/step4_controller_test.js index 1d69a29..8ef0fe8 100644 --- a/ambari-web/test/controllers/main/admin/kerberos/step4_controller_test.js +++ b/ambari-web/test/controllers/main/admin/kerberos/step4_controller_test.js @@ -17,14 +17,43 @@ */ var App = require('app'); -var c = App.KerberosWizardStep4Controller.create({ - wizardController: Em.Object.create({ - name: '' - }) -}); +var testHelpers = require('test/helpers'); + +function getController() { + return App.KerberosWizardStep4Controller.create({ + wizardController: Em.Object.create({ + name: '' + }) + }); +} + describe('App.KerberosWizardStep4Controller', function() { + var c; + + beforeEach(function() { + c = getController(); + }); - App.TestAliases.testAsComputedEqual(c, 'isWithinAddService', 'wizardController.name', 'addServiceController'); + App.TestAliases.testAsComputedEqual(getController(), 'isWithinAddService', 'wizardController.name', 'addServiceController'); + + describe("#clearStep()", function () { + + beforeEach(function() { + c.clearStep(); + }); + + it("isRecommendedLoaded should be set to false", function() { + expect(c.get('isRecommendedLoaded')).to.be.false; + }); + + it("selectedService should be set to null", function() { + expect(c.get('selectedService')).to.be.null; + }); + + it("stepConfigs should be set to false", function() { + expect(c.get('stepConfigs')).to.be.empty; + }); + }); describe('#isSubmitDisabled', function() { var controller = App.KerberosWizardStep4Controller.create({}); @@ -537,4 +566,357 @@ describe('App.KerberosWizardStep4Controller', function() { }); }); }); + + describe("#getDescriptor()", function () { + var mock = { + then: Em.K + }; + + beforeEach(function() { + c.reopen({ + isWithinAddService: true + }); + sinon.stub(c, 'storeClusterDescriptorStatus'); + sinon.stub(c, 'loadClusterDescriptorConfigs').returns(mock); + sinon.stub(c, 'loadStackDescriptorConfigs').returns(mock); + sinon.stub(mock, 'then'); + }); + + afterEach(function() { + c.loadClusterDescriptorConfigs.restore(); + c.storeClusterDescriptorStatus.restore(); + c.loadStackDescriptorConfigs.restore(); + mock.then.restore(); + }); + + it("App.ajax.send should be called", function() { + c.getDescriptor(); + var args = testHelpers.findAjaxRequest('name', 'admin.kerberize.cluster_descriptor_artifact'); + expect(args[0]).to.be.eql({ + sender: c, + name: 'admin.kerberize.cluster_descriptor_artifact' + }); + }); + + it("storeClusterDescriptorStatus should be called", function() { + c.getDescriptor(); + expect(c.storeClusterDescriptorStatus.calledOnce).to.be.true; + }); + + it("loadClusterDescriptorConfigs should be called", function() { + c.getDescriptor(); + expect(c.loadClusterDescriptorConfigs.calledOnce).to.be.true; + }); + + it("then should be called", function() { + c.getDescriptor(); + expect(mock.then.calledOnce).to.be.true; + }); + + it("loadStackDescriptorConfigs should be called", function() { + c.set('isWithinAddService', false); + c.getDescriptor(); + expect(c.loadStackDescriptorConfigs.calledOnce).to.be.true; + }); + + it("then should be called, isWithinAddService is false", function() { + c.set('isWithinAddService', false); + c.getDescriptor(); + expect(mock.then.calledOnce).to.be.true; + }); + }); + + describe("#tweakConfigProperty()", function () { + + beforeEach(function() { + this.mock = sinon.stub(App.HostComponent, 'find'); + }); + + afterEach(function() { + this.mock.restore(); + }); + + it("config value should not be set", function() { + this.mock.returns([ + Em.Object.create({ + componentName: 'HIVE_METASTORE', + hostName: 'host1' + }) + ]); + var config = Em.Object.create({ + name: 'templeton.hive.properties', + value: 'thrift://host1:9000\,,', + recommendedValue: '' + }); + c.tweakConfigProperty(config); + expect(config.get('value')).to.be.equal('thrift://host1:9000\,,'); + expect(config.get('recommendedValue')).to.be.equal(''); + }); + + it("config value should be set", function() { + this.mock.returns([ + Em.Object.create({ + componentName: 'HIVE_METASTORE', + hostName: 'host1' + }), + Em.Object.create({ + componentName: 'HIVE_METASTORE', + hostName: 'host2' + }) + ]); + var config = Em.Object.create({ + name: 'templeton.hive.properties', + value: 'thrift://host1:9000\,,' + }); + c.tweakConfigProperty(config); + expect(config.get('value')).to.be.equal("thrift://host1:9000\\,thrift://host2:9000,,"); + expect(config.get('recommendedValue')).to.be.equal("thrift://host1:9000\\,thrift://host2:9000,,"); + }); + }); + + describe("#spnegoPropertiesObserver()", function () { + + beforeEach(function() { + sinon.stub(Em.run, 'once', function(context, callback) { + callback(); + }); + }); + + afterEach(function() { + Em.run.once.restore(); + }); + + it("value should not be changed", function() { + var configProperty = Em.Object.create({ + name: 'n1', + value: 'new', + recommendedValue: 'new' + }); + var config = Em.Object.create({ + observesValueFrom: 'n2', + value: '', + recommendedValue: '' + }); + c.set('stepConfigs', [Em.Object.create({ + name: 'ADVANCED', + configs: [config] + })]); + c.spnegoPropertiesObserver(configProperty); + expect(config.get('value')).to.be.empty; + expect(config.get('recommendedValue')).to.be.empty; + }); + + it("value should be changed", function() { + var configProperty = Em.Object.create({ + name: 'n1', + value: 'new', + recommendedValue: 'new' + }); + var config = Em.Object.create({ + observesValueFrom: 'n1', + value: '', + recommendedValue: '' + }); + c.set('stepConfigs', [Em.Object.create({ + name: 'ADVANCED', + configs: [config] + })]); + c.spnegoPropertiesObserver(configProperty); + expect(config.get('value')).to.be.equal('new'); + expect(config.get('recommendedValue')).to.be.equal('new'); + }); + }); + + describe("#submit()", function () { + + beforeEach(function() { + sinon.stub(c, 'saveConfigurations'); + sinon.stub(App.router, 'send'); + }); + + afterEach(function() { + c.saveConfigurations.restore(); + App.router.send.restore(); + }); + + it("saveConfigurations should be called", function() { + c.submit(); + expect(c.saveConfigurations.calledOnce).to.be.true; + }); + + it("App.router.send should be called", function() { + c.submit(); + expect(App.router.send.calledWith('next')).to.be.true; + }); + }); + + describe("#saveConfigurations()", function () { + var mock = { + saveKerberosDescriptorConfigs: Em.K + }; + + beforeEach(function() { + sinon.stub(c, 'updateKerberosDescriptor'); + sinon.stub(App, 'get').returns(mock); + sinon.spy(mock, 'saveKerberosDescriptorConfigs'); + c.set('kerberosDescriptor', {}); + c.set('stepConfigs', [ + Em.Object.create({ + configs: [{}] + }), + Em.Object.create({ + configs: [{}] + }) + ]); + c.saveConfigurations(); + }); + + afterEach(function() { + c.updateKerberosDescriptor.restore(); + App.get.restore(); + mock.saveKerberosDescriptorConfigs.restore(); + }); + + it("updateKerberosDescriptor should be called", function() { + expect(c.updateKerberosDescriptor.calledWith({}, [{}, {}])).to.be.true; + }); + + it("saveKerberosDescriptorConfigs should be called", function() { + expect(mock.saveKerberosDescriptorConfigs.calledWith({})).to.be.true; + }); + }); + + describe("#loadServerSideConfigsRecommendations()", function () { + + it("App.ajax.send should be called", function() { + c.loadServerSideConfigsRecommendations([]); + var args = testHelpers.findAjaxRequest('name', 'config.recommendations'); + expect(args[0]).to.be.exists; + }); + }); + + describe("#applyServiceConfigs()", function () { + + it("isRecommendedLoaded should be true", function() { + c.applyServiceConfigs([Em.Object.create({configGroups: []})]); + expect(c.get('isRecommendedLoaded')).to.be.true; + }); + + it("selectedService should be set", function() { + c.applyServiceConfigs([Em.Object.create({configGroups: []})]); + expect(c.get('selectedService')).to.be.eql(Em.Object.create({configGroups: []})); + }); + }); + + describe("#bootstrapRecommendationPayload()", function () { + + beforeEach(function() { + sinon.stub(c, 'getServicesConfigurations').returns({ + then: function(callback) { + callback([{}]); + } + }); + sinon.stub(c, 'getBlueprintPayloadObject').returns({blueprint: { + configurations: [] + }}); + c.bootstrapRecommendationPayload({}); + }); + + afterEach(function() { + c.getServicesConfigurations.restore(); + c.getBlueprintPayloadObject.restore(); + }); + + it("getServicesConfigurations should be called", function() { + expect(c.getServicesConfigurations.calledOnce).to.be.true; + }); + + it("getBlueprintPayloadObject should be called", function() { + expect(c.getBlueprintPayloadObject.calledWith([{}], {})).to.be.true; + }); + + it("servicesConfigurations should be set", function() { + expect(c.get('servicesConfigurations')).to.be.eql([{}]); + }); + + it("initialConfigValues should be set", function() { + expect(c.get('initialConfigValues')).to.be.eql([]); + }); + }); + + describe("#getBlueprintPayloadObject()", function () { + + beforeEach(function() { + sinon.stub(c, 'mergeDescriptorToConfigurations').returns([{ + type: 't1', + properties: [] + }]); + sinon.stub(c, 'createServicesStackDescriptorConfigs'); + }); + + afterEach(function() { + c.createServicesStackDescriptorConfigs.restore(); + c.mergeDescriptorToConfigurations.restore(); + }); + + it("should return recommendations", function () { + c.reopen({ + hostGroups: { + blueprint: { + configurations: [] + } + } + }); + expect(c.getBlueprintPayloadObject([], {})).to.be.eql({ + "blueprint": { + "configurations": { + "t1": { + "properties": [] + } + } + } + }); + }); + }); + + describe("#getServicesConfigObject()", function () { + + it("should return ADVANCED step config", function() { + c.set('stepConfigs', [{name: 'ADVANCED'}]); + expect(c.getServicesConfigObject()).to.be.eql({name: 'ADVANCED'}); + }); + }); + + describe("#getServiceByFilename()", function () { + + beforeEach(function() { + this.mockService = sinon.stub(App.Service, 'find'); + sinon.stub(App.StackService, 'find').returns([ + Em.Object.create({ + serviceName: 'S1', + configTypes: { + site1: {} + } + }) + ]); + }); + + afterEach(function() { + this.mockService.restore(); + App.StackService.find.restore(); + }); + + it("should return 'HDFS' ", function() { + this.mockService.returns([{serviceName: 'HDFS'}]); + expect(c.getServiceByFilename('core-site')).to.be.equal('HDFS'); + }); + + it("should return 'S1' ", function() { + expect(c.getServiceByFilename('site1')).to.be.equal('S1'); + }); + + it("should return empty", function() { + expect(c.getServiceByFilename('site2')).to.be.empty; + }); + }); }); http://git-wip-us.apache.org/repos/asf/ambari/blob/5c782dd8/ambari-web/test/controllers/main/admin/kerberos/step5_controller_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/main/admin/kerberos/step5_controller_test.js b/ambari-web/test/controllers/main/admin/kerberos/step5_controller_test.js index d3180e3..8718802 100644 --- a/ambari-web/test/controllers/main/admin/kerberos/step5_controller_test.js +++ b/ambari-web/test/controllers/main/admin/kerberos/step5_controller_test.js @@ -17,9 +17,12 @@ */ var App = require('app'); -var c; -describe('App.KerberosWizardStep5Controller', function() { +var testHelpers = require('test/helpers'); +var stringUtils = require('utils/string_utils'); +var fileUtils = require('utils/file_utils'); +describe('App.KerberosWizardStep5Controller', function() { + var c; beforeEach(function () { c = App.KerberosWizardStep5Controller.create({}); }); @@ -27,7 +30,6 @@ describe('App.KerberosWizardStep5Controller', function() { describe('#prepareCSVData', function () { it('should split data', function () { - var data = [ 'a,b,c', 'd,e', @@ -35,10 +37,176 @@ describe('App.KerberosWizardStep5Controller', function() { ]; var result = c.prepareCSVData(data); - expect(result).to.be.eql([['a', 'b', 'c'], ['d', 'e'], ['1', '2', '3', '4']]) + expect(result).to.be.eql([['a', 'b', 'c'], ['d', 'e'], ['1', '2', '3', '4']]); + }); + }); + + describe("#submit()", function () { + + beforeEach(function() { + sinon.stub(App.router, 'send'); + }); + + afterEach(function() { + App.router.send.restore(); + }); + + it("App.router.send should be called", function() { + c.submit(); + expect(App.router.send.calledWith('next')).to.be.true; + }); + }); + + describe("#getCSVData()", function () { + + it("App.ajax.send should be called", function() { + c.getCSVData(true); + var args = testHelpers.findAjaxRequest('name', 'admin.kerberos.cluster.csv'); + expect(args[0]).to.be.eql({ + name: 'admin.kerberos.cluster.csv', + sender: c, + data: { + 'skipDownload': true + }, + success: 'getCSVDataSuccessCallback', + error: 'getCSVDataSuccessCallback' + }); + }); + }); + + describe("#getCSVDataSuccessCallback()", function () { + + beforeEach(function() { + sinon.stub(fileUtils, 'downloadTextFile'); + sinon.stub(stringUtils, 'arrayToCSV').returns('arrayToCSV'); + sinon.stub(c, 'prepareCSVData').returns('csvData'); + c.getCSVDataSuccessCallback("a\nb", {}, {skipDownload: false}); + }); + + afterEach(function() { + fileUtils.downloadTextFile.restore(); + stringUtils.arrayToCSV.restore(); + c.prepareCSVData.restore(); + }); + + it("csvData should be set", function() { + expect(c.get('csvData')).to.be.equal('csvData'); + }); + + it("fileUtils.downloadTextFile should be called", function() { + expect(fileUtils.downloadTextFile.calledWith('arrayToCSV', 'csv', 'kerberos.csv')).to.be.true; + }); + }); + describe("#postKerberosDescriptor()", function () { + + it("App.ajax.send should be called", function() { + c.postKerberosDescriptor('kerberosDescriptor'); + var args = testHelpers.findAjaxRequest('name', 'admin.kerberos.cluster.artifact.create'); + expect(args[0]).to.be.eql({ + name: 'admin.kerberos.cluster.artifact.create', + sender: c, + data: { + artifactName: 'kerberos_descriptor', + data: { + artifact_data: 'kerberosDescriptor' + } + } + }); }); + }); + + describe("#putKerberosDescriptor()", function () { + + it("App.ajax.send should be called", function() { + c.putKerberosDescriptor('kerberosDescriptor'); + var args = testHelpers.findAjaxRequest('name', 'admin.kerberos.cluster.artifact.update'); + expect(args[0]).to.be.eql({ + name: 'admin.kerberos.cluster.artifact.update', + sender: c, + data: { + artifactName: 'kerberos_descriptor', + data: { + artifact_data: 'kerberosDescriptor' + } + }, + success: 'unkerberizeCluster', + error: 'unkerberizeCluster' + }); + }); + }); + + describe("#unkerberizeCluster()", function () { + it("App.ajax.send should be called", function() { + c.unkerberizeCluster(); + var args = testHelpers.findAjaxRequest('name', 'admin.unkerberize.cluster'); + expect(args[0]).to.be.eql({ + name: 'admin.unkerberize.cluster', + sender: c, + success: 'goToNextStep', + error: 'goToNextStep' + }); + }); }); + describe("#goToNextStep()", function () { + + beforeEach(function() { + sinon.stub(c, 'clearStage'); + sinon.stub(App.router, 'transitionTo'); + c.goToNextStep(); + }); + + afterEach(function() { + c.clearStage.restore(); + App.router.transitionTo.restore(); + }); + + it("clearStage should be called", function() { + expect(c.clearStage.calledOnce).to.be.true; + }); + + it("App.router.transitionTo should be called", function() { + expect(App.router.transitionTo.calledWith('step5')).to.be.true; + }); + }); + + describe("#confirmProperties", function () { + + beforeEach(function() { + this.mock = sinon.stub(App.router, 'get'); + }); + + afterEach(function() { + this.mock.restore(); + }); + + it("should return properties", function() { + this.mock.returns(Em.Object.create({ + content: { + kerberosOption: Em.I18n.t('admin.kerberos.wizard.step1.option.kdc'), + serviceConfigProperties: [{name: 'kdc_type'}] + } + })); + c.propertyDidChange('confirmProperties'); + expect(c.get('confirmProperties')).to.be.eql([ + { + name: 'kdc_type', + label: Em.I18n.t('admin.kerberos.wizard.step5.kdc_type.label') + } + ]); + }); + + it("should return empty properties", function() { + this.mock.returns(Em.Object.create({ + content: { + kerberosOption: null, + serviceConfigProperties: [{name: 'kdc_type'}] + } + })); + c.propertyDidChange('confirmProperties'); + expect(c.get('confirmProperties')).to.be.empty; + }); + }); }); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/5c782dd8/ambari-web/test/controllers/main/admin/kerberos/step6_controller_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/main/admin/kerberos/step6_controller_test.js b/ambari-web/test/controllers/main/admin/kerberos/step6_controller_test.js index 8fe9bc2..b89a91f 100644 --- a/ambari-web/test/controllers/main/admin/kerberos/step6_controller_test.js +++ b/ambari-web/test/controllers/main/admin/kerberos/step6_controller_test.js @@ -17,8 +17,15 @@ */ var App = require('app'); +var testHelpers = require('test/helpers'); describe('App.KerberosWizardStep6Controller', function() { + var controller; + + beforeEach(function() { + controller = App.KerberosWizardStep6Controller.create({ commands: ['stopServices'] }); + }); + describe('#checkComponentsRemoval', function() { @@ -39,9 +46,7 @@ describe('App.KerberosWizardStep6Controller', function() { tests.forEach(function(test) { var message = 'YARN installed: {0}, ATS supported: {1} list of commands should be {2}'.format(test.yarnInstalled, test.doesATSSupportKerberos, test.commands.toString()); describe(message, function () { - var controller; beforeEach(function () { - controller = App.KerberosWizardStep6Controller.create({ commands: ['stopServices'] }); sinon.stub(App, 'get').withArgs('doesATSSupportKerberos').returns(test.doesATSSupportKerberos); sinon.stub(App.Service, 'find').returns(test.yarnInstalled ? [Em.Object.create({serviceName: 'YARN'})] : []); sinon.stub(App.HostComponent, 'find').returns(test.ATSInstalled ? [Em.Object.create({componentName: 'APP_TIMELINE_SERVER'})] : []); @@ -55,4 +60,108 @@ describe('App.KerberosWizardStep6Controller', function() { }); }); }); + + + describe("#stopServices()", function () { + + it("App.ajax.send should be called", function() { + controller.stopServices(); + var args = testHelpers.findAjaxRequest('name', 'common.services.update'); + expect(args[0]).to.be.eql({ + name: 'common.services.update', + data: { + context: "Stop services", + "ServiceInfo": { + "state": "INSTALLED" + } + }, + sender: controller, + success: 'startPolling', + error: 'onTaskError' + }); + }); + }); + + describe("#loadStep()", function () { + + beforeEach(function() { + sinon.stub(controller, 'checkComponentsRemoval'); + }); + + afterEach(function() { + controller.checkComponentsRemoval.restore(); + }); + + it("loadStep should be called", function() { + controller.loadStep(); + expect(controller.checkComponentsRemoval.calledOnce).to.be.true; + }); + }); + + describe("#deleteATS()", function () { + + beforeEach(function() { + sinon.stub(App.HostComponent, 'find').returns([Em.Object.create({ + componentName: 'APP_TIMELINE_SERVER', + hostName: 'host1' + })]); + }); + + afterEach(function() { + App.HostComponent.find.restore(); + }); + + it("deleteATS should be called", function() { + controller.deleteATS(); + var args = testHelpers.findAjaxRequest('name', 'common.delete.host_component'); + expect(args[0]).to.be.eql({ + name: 'common.delete.host_component', + sender: controller, + data: { + componentName: 'APP_TIMELINE_SERVER', + hostName: 'host1' + }, + success: 'onDeleteATSSuccess', + error: 'onDeleteATSError' + }); + }); + }); + + describe("#onDeleteATSSuccess", function () { + + beforeEach(function() { + sinon.stub(controller, 'onTaskCompleted'); + }); + + afterEach(function() { + controller.onTaskCompleted.restore(); + }); + + it("onDeleteATSSuccess should be called", function() { + controller.onDeleteATSSuccess(); + expect(controller.onTaskCompleted.calledOnce).to.be.true; + }); + }); + + describe("#onDeleteATSError()", function () { + + beforeEach(function() { + sinon.stub(controller, 'onDeleteATSSuccess'); + }); + + afterEach(function() { + controller.onDeleteATSSuccess.restore(); + }); + + it("onDeleteATSSuccess should not be called", function() { + controller.onDeleteATSError({responseText: ""}); + expect(controller.onDeleteATSSuccess.called).to.be.false; + }); + + it("onDeleteATSSuccess should be called", function() { + controller.onDeleteATSError({responseText: "org.apache.ambari.server.controller.spi.NoSuchResourceException"}); + expect(controller.onDeleteATSSuccess.calledOnce).to.be.true; + }); + }); + }); http://git-wip-us.apache.org/repos/asf/ambari/blob/5c782dd8/ambari-web/test/controllers/main/admin/kerberos/step7_controller_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/main/admin/kerberos/step7_controller_test.js b/ambari-web/test/controllers/main/admin/kerberos/step7_controller_test.js new file mode 100644 index 0000000..de4dcb1 --- /dev/null +++ b/ambari-web/test/controllers/main/admin/kerberos/step7_controller_test.js @@ -0,0 +1,220 @@ +/** + * 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'); + +function getController() { + return App.KerberosWizardStep7Controller.create({}); +} + +describe('App.KerberosWizardStep7Controller', function () { + var controller; + + beforeEach(function () { + controller = getController(); + }); + + describe("#setRequest()", function () { + + beforeEach(function () { + sinon.stub(controller, 'clearStage'); + sinon.stub(controller, 'loadStep'); + }); + + afterEach(function () { + controller.clearStage.restore(); + controller.loadStep.restore(); + }); + + it("request should be set", function () { + controller.setRequest(true); + expect(controller.get('request')).to.be.eql({ + name: 'KERBERIZE_CLUSTER', + ajaxName: 'admin.kerberize.cluster.force' + }); + }); + + it("clearStage should be called", function () { + controller.setRequest(true); + expect(controller.clearStage.calledOnce).to.be.true; + }); + + it("loadStep should be called", function () { + controller.setRequest(true); + expect(controller.loadStep.calledOnce).to.be.true; + }); + + it("kerberize request should be set", function () { + controller.setRequest(false); + expect(controller.get('request')).to.be.eql({ + name: 'KERBERIZE_CLUSTER', + ajaxName: 'admin.kerberize.cluster', + ajaxData: { + data: { + Clusters: { + security_type: "KERBEROS" + } + } + } + }); + }); + }); + + describe("#unkerberizeCluster()", function () { + + it("App.ajax.send should be called", function () { + controller.unkerberizeCluster(); + var args = testHelpers.findAjaxRequest('name', 'admin.unkerberize.cluster'); + expect(args[0]).to.be.eql({ + name: 'admin.unkerberize.cluster', + sender: controller, + success: 'goToNextStep', + error: 'goToNextStep' + }); + }); + }); + + describe("#goToNextStep()", function () { + + beforeEach(function() { + sinon.stub(controller, 'clearStage'); + sinon.stub(App.router, 'transitionTo'); + controller.goToNextStep(); + }); + + afterEach(function() { + controller.clearStage.restore(); + App.router.transitionTo.restore(); + }); + + it("clearStage should be called", function() { + expect(controller.clearStage.calledOnce).to.be.true; + }); + + it("App.router.transitionTo should be called", function() { + expect(App.router.transitionTo.calledWith('step7')).to.be.true; + }); + }); + + describe("#postKerberosDescriptor()", function () { + + it("App.ajax.send should be called", function () { + controller.postKerberosDescriptor(true); + var args = testHelpers.findAjaxRequest('name', 'admin.kerberos.cluster.artifact.create'); + expect(args[0]).to.be.eql({ + name: 'admin.kerberos.cluster.artifact.create', + sender: controller, + data: { + artifactName: 'kerberos_descriptor', + data: { + artifact_data: true + } + } + }); + }); + }); + + describe("#putKerberosDescriptor()", function () { + + it("App.ajax.send should be called", function () { + controller.putKerberosDescriptor(true); + var args = testHelpers.findAjaxRequest('name', 'admin.kerberos.cluster.artifact.update'); + expect(args[0]).to.be.eql({ + name: 'admin.kerberos.cluster.artifact.update', + sender: controller, + data: { + artifactName: 'kerberos_descriptor', + data: { + artifact_data: true + } + }, + success: 'unkerberizeCluster', + error: 'unkerberizeCluster' + }); + }); + }); + + describe("#retry()", function () { + + beforeEach(function() { + sinon.stub(controller, 'removeObserver'); + sinon.stub(controller, 'setRequest'); + controller.set('tasks', [Em.Object.create()]); + controller.retry(); + }); + + afterEach(function() { + controller.removeObserver.restore(); + controller.setRequest.restore(); + }); + + it("showRetry should be false", function() { + expect(controller.get('showRetry')).to.be.false; + }); + + it("removeObserver should be called", function() { + expect(controller.removeObserver.calledWith('[email protected]', controller, 'onTaskStatusChange')).to.be.true; + }); + + it("status should be IN_PROGRESS", function() { + expect(controller.get('status')).to.be.equal('IN_PROGRESS'); + }); + + it("tasks status should be PENDING", function() { + expect(controller.get('tasks').mapProperty('status')).to.be.eql(['PENDING']); + }); + + it("setRequest should be called", function() { + expect(controller.setRequest.calledWith(true)).to.be.true; + }); + }); + + describe("#enableDisablePreviousSteps()", function () { + var mock = { + enableStep: Em.K, + setLowerStepsDisable: Em.K + }; + + beforeEach(function() { + sinon.stub(App.router, 'get').returns(mock); + sinon.stub(mock, 'setLowerStepsDisable'); + sinon.stub(mock, 'enableStep'); + }); + + afterEach(function() { + App.router.get.restore(); + mock.enableStep.restore(); + mock.setLowerStepsDisable.restore(); + }); + + it("FAILED tasks", function() { + controller.set('tasks', [{status: 'FAILED'}]); + controller.enableDisablePreviousSteps(); + expect(controller.get('isBackButtonDisabled')).to.be.false; + expect(mock.enableStep.calledWith(4)).to.be.true; + }); + + it("COMPLETED tasks", function() { + controller.set('tasks', [{status: 'COMPLETED'}]); + controller.enableDisablePreviousSteps(); + expect(controller.get('isBackButtonDisabled')).to.be.true; + expect(mock.setLowerStepsDisable.calledWith(6)).to.be.true; + }); + }); +}); http://git-wip-us.apache.org/repos/asf/ambari/blob/5c782dd8/ambari-web/test/controllers/main/admin/kerberos/step8_controller_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/main/admin/kerberos/step8_controller_test.js b/ambari-web/test/controllers/main/admin/kerberos/step8_controller_test.js new file mode 100644 index 0000000..50a705d --- /dev/null +++ b/ambari-web/test/controllers/main/admin/kerberos/step8_controller_test.js @@ -0,0 +1,64 @@ +/** + * 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'); + +function getController() { + return App.KerberosWizardStep8Controller.create({}); +} + +describe('App.KerberosWizardStep8Controller', function() { + var controller; + + beforeEach(function() { + controller = getController(); + }); + + describe("#startServices()", function () { + + beforeEach(function() { + sinon.stub(App.router, 'get').returns({ + "skip.service.checks": "true" + }); + }); + + afterEach(function() { + App.router.get.restore(); + }); + + it("App.ajax.send should be called", function() { + controller.startServices(); + var args = testHelpers.findAjaxRequest('name', 'common.services.update'); + expect(args[0]).to.be.eql({ + name: 'common.services.update', + sender: controller, + data: { + "context": "Start services", + "ServiceInfo": { + "state": "STARTED" + }, + urlParams: "params/run_smoke_test=false" + }, + success: 'startPolling', + error: 'onTaskError' + }); + }); + }); + +});
