You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by at...@apache.org on 2016/05/05 10:38:35 UTC
[1/2] ambari git commit: AMBARI-16257 Cover Kerberos wizard
controllers with unit tests. (atkach)
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('tasks.@each.status', 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'
+ });
+ });
+ });
+
+});
[2/2] ambari git commit: AMBARI-16257 Cover Kerberos wizard
controllers with unit tests. (atkach)
Posted by at...@apache.org.
AMBARI-16257 Cover Kerberos wizard controllers with unit tests. (atkach)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/5c782dd8
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/5c782dd8
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/5c782dd8
Branch: refs/heads/trunk
Commit: 5c782dd843c3fca5891e8c937c1d93c9d0fdfaad
Parents: 0a745f8
Author: Andrii Tkach <at...@apache.org>
Authored: Wed May 4 20:46:15 2016 +0300
Committer: Andrii Tkach <at...@apache.org>
Committed: Thu May 5 13:26:29 2016 +0300
----------------------------------------------------------------------
ambari-web/app/assets/test/tests.js | 5 +
.../main/admin/kerberos/step1_controller.js | 6 +-
.../main/admin/kerberos/step2_controller.js | 108 ++-
.../main/admin/kerberos/step3_controller.js | 6 +-
.../main/admin/kerberos/step4_controller.js | 15 +-
.../main/admin/kerberos/step5_controller.js | 65 +-
.../main/admin/kerberos/step7_controller.js | 7 +-
.../main/admin/kerberos/wizard_controller.js | 38 +-
.../admin/kerberos/disable_controller_test.js | 122 +++
.../kerberos/kerberos_wizard_controler_test.js | 507 +++++++++++-
.../admin/kerberos/step1_controller_test.js | 93 +++
.../admin/kerberos/step2_controller_test.js | 793 ++++++++++++++++++-
.../admin/kerberos/step3_controller_test.js | 190 ++++-
.../admin/kerberos/step4_controller_test.js | 394 ++++++++-
.../admin/kerberos/step5_controller_test.js | 176 +++-
.../admin/kerberos/step6_controller_test.js | 113 ++-
.../admin/kerberos/step7_controller_test.js | 220 +++++
.../admin/kerberos/step8_controller_test.js | 64 ++
18 files changed, 2808 insertions(+), 114 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/5c782dd8/ambari-web/app/assets/test/tests.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/assets/test/tests.js b/ambari-web/app/assets/test/tests.js
index 7226720..eb2edf1 100644
--- a/ambari-web/app/assets/test/tests.js
+++ b/ambari-web/app/assets/test/tests.js
@@ -58,11 +58,16 @@ var files = [
'test/controllers/main/alerts/manage_alert_notifications_controller_test',
'test/controllers/main/admin/kerberos_test',
'test/controllers/main/admin/kerberos/kerberos_wizard_controler_test',
+ 'test/controllers/main/admin/kerberos/disable_controller_test',
+ 'test/controllers/main/admin/kerberos/step1_controller_test',
'test/controllers/main/admin/kerberos/step2_controller_test',
'test/controllers/main/admin/kerberos/step3_controller_test',
'test/controllers/main/admin/kerberos/step4_controller_test',
'test/controllers/main/admin/kerberos/step5_controller_test',
'test/controllers/main/admin/kerberos/step6_controller_test',
+ 'test/controllers/main/admin/kerberos/step7_controller_test',
+ 'test/controllers/main/admin/kerberos/step8_controller_test',
+
'test/controllers/main/admin/stack_and_upgrade_controller_test',
'test/controllers/main/admin/serviceAccounts_controller_test',
'test/controllers/main/admin/highAvailability_controller_test',
http://git-wip-us.apache.org/repos/asf/ambari/blob/5c782dd8/ambari-web/app/controllers/main/admin/kerberos/step1_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/admin/kerberos/step1_controller.js b/ambari-web/app/controllers/main/admin/kerberos/step1_controller.js
index 1b96b13..7f561dd 100644
--- a/ambari-web/app/controllers/main/admin/kerberos/step1_controller.js
+++ b/ambari-web/app/controllers/main/admin/kerberos/step1_controller.js
@@ -44,7 +44,7 @@ App.KerberosWizardStep1Controller = Em.Controller.extend({
Em.Object.create({
displayText: Em.I18n.t('admin.kerberos.wizard.step1.option.ipa.condition.4'),
checked: false
- }),
+ })
]
}),
@@ -125,9 +125,7 @@ App.KerberosWizardStep1Controller = Em.Controller.extend({
* precondition for the selected KDC option
*/
selectedOption: function () {
- var options = this.get('options');
- var selectedItem = this.get('selectedItem');
- return options.findProperty('value', selectedItem);
+ return this.get('options').findProperty('value', this.get('selectedItem'));
}.property('selectedItem'),
http://git-wip-us.apache.org/repos/asf/ambari/blob/5c782dd8/ambari-web/app/controllers/main/admin/kerberos/step2_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/admin/kerberos/step2_controller.js b/ambari-web/app/controllers/main/admin/kerberos/step2_controller.js
index 52177b7..ce622e4 100644
--- a/ambari-web/app/controllers/main/admin/kerberos/step2_controller.js
+++ b/ambari-web/app/controllers/main/admin/kerberos/step2_controller.js
@@ -36,6 +36,21 @@ App.KerberosWizardStep2Controller = App.WizardStep7Controller.extend(App.KDCCred
addMiscTabToPage: false,
+ kerberosConfigMap: {
+ 'ad': {
+ configNames: ['ldap_url', 'container_dn', 'ad_create_attributes_template'],
+ type: Em.I18n.t('admin.kerberos.wizard.step1.option.ad')
+ },
+ 'mit': {
+ configNames: ['kdc_create_attributes'],
+ type: Em.I18n.t('admin.kerberos.wizard.step1.option.kdc')
+ },
+ 'ipa': {
+ configNames: ['group', 'set_password_expiry', 'password_chat_timeout'],
+ type: Em.I18n.t('admin.kerberos.wizard.step1.option.ipa')
+ }
+ },
+
/**
* @type {boolean} true if test connection to hosts is in progress
*/
@@ -67,7 +82,6 @@ App.KerberosWizardStep2Controller = App.WizardStep7Controller.extend(App.KDCCred
this.set('servicesInstalled', false);
},
-
isConfigsLoaded: Em.computed.alias('wizardController.stackConfigsLoaded'),
/**
@@ -77,19 +91,13 @@ App.KerberosWizardStep2Controller = App.WizardStep7Controller.extend(App.KDCCred
loadStep: function () {
if (!App.StackService.find().someProperty('serviceName', 'KERBEROS') || !this.get('isConfigsLoaded')) {
- return;
+ return false;
}
this.clearStep();
App.config.setPreDefinedServiceConfigs(this.get('addMiscTabToPage'));
var stored = this.get('content.serviceConfigProperties');
- var kerberosConfigTypes = Em.keys(App.config.get('preDefinedServiceConfigs').findProperty('serviceName', 'KERBEROS').get('configTypes'));
- this.set('configs', stored || App.configsCollection.getAll().filter(function(configProperty) {
- var fileName = Em.getWithDefault(configProperty, 'fileName', false);
- var isService = ['KERBEROS'].contains(Em.get(configProperty, 'serviceName'));
- var isFileName = fileName && kerberosConfigTypes.contains(App.config.getConfigTagFromFileName(fileName));
- return isService || isFileName;
- }));
+ this.set('configs', stored || this.getKerberosConfigs());
this.filterConfigs(this.get('configs'));
if (!this.get('wizardController.skipClientInstall')) {
@@ -102,16 +110,27 @@ App.KerberosWizardStep2Controller = App.WizardStep7Controller.extend(App.KDCCred
},
/**
+ * @method getKerberosConfigs
+ * @returns {Array.<T>|*}
+ */
+ getKerberosConfigs: function() {
+ var kerberosConfigTypes = Em.keys(App.config.get('preDefinedServiceConfigs').findProperty('serviceName', 'KERBEROS').get('configTypes'));
+
+ return App.configsCollection.getAll().filter(function(configProperty) {
+ var fileName = Em.getWithDefault(configProperty, 'fileName', false);
+ var isService = ['KERBEROS'].contains(Em.get(configProperty, 'serviceName'));
+ var isFileName = fileName && kerberosConfigTypes.contains(App.config.getConfigTagFromFileName(fileName));
+ return isService || isFileName;
+ });
+ },
+
+ /**
* Make Active Directory or IPA specific configs visible if user has selected AD or IPA option
* @param configs
*/
filterConfigs: function (configs) {
var kdcType = this.get('content.kerberosOption');
- var adConfigNames = ['ldap_url', 'container_dn', 'ad_create_attributes_template'];
- var mitConfigNames = ['kdc_create_attributes'];
- var ipaConfigNames = ['group', 'set_password_expiry', 'password_chat_timeout'];
-
- var kerberosWizardController = this.controllers.get('kerberosWizardController');
+ var kerberosWizardController = this.get('controllers.kerberosWizardController');
var manageIdentitiesConfig = configs.findProperty('name', 'manage_identities');
configs.filterProperty('serviceName', 'KERBEROS').setEach('isVisible', true);
@@ -126,32 +145,33 @@ App.KerberosWizardStep2Controller = App.WizardStep7Controller.extend(App.KDCCred
manageIdentitiesConfig.value = 'true';
}
- adConfigNames.forEach(function (_configName) {
- var config = configs.findProperty('name', _configName);
- if (config) {
- config.isVisible = kdcType === Em.I18n.t('admin.kerberos.wizard.step1.option.ad');
- }
- }, this);
+ this.setConfigVisibility('ad', configs, kdcType);
+ this.setConfigVisibility('mit', configs, kdcType);
+ this.setConfigVisibility('ipa', configs, kdcType);
+ },
- mitConfigNames.forEach(function (_configName) {
- var config = configs.findProperty('name', _configName);
- if (config) {
- config.isVisible = kdcType === Em.I18n.t('admin.kerberos.wizard.step1.option.kdc');
- }
- }, this);
+ /**
+ *
+ * @param {string} type
+ * @param {Array} configs
+ * @param {string} kdcType
+ */
+ setConfigVisibility: function(type, configs, kdcType) {
+ var typeSettings = this.get('kerberosConfigMap')[type];
- ipaConfigNames.forEach(function (_configName) {
+ typeSettings.configNames.forEach(function (_configName) {
var config = configs.findProperty('name', _configName);
if (config) {
- config.isVisible = kdcType === Em.I18n.t('admin.kerberos.wizard.step1.option.ipa');
+ config.isVisible = kdcType === typeSettings.type;
}
}, this);
},
+
submit: function () {
- if (this.get('isSubmitDisabled')) return false;
- this.set('isSubmitDisabled', true);
var self = this;
+
+ if (this.get('isSubmitDisabled')) return false;
this.get('wizardController').deleteKerberosService().always(function () {
self.configureKerberos();
});
@@ -175,9 +195,12 @@ App.KerberosWizardStep2Controller = App.WizardStep7Controller.extend(App.KDCCred
},
createConfigurations: function () {
- var service = App.StackService.find().findProperty('serviceName', 'KERBEROS');
- var serviceConfigTags = [];
- var tag = 'version' + (new Date).getTime();
+ var service = App.StackService.find().findProperty('serviceName', 'KERBEROS'),
+ serviceConfigTags = [],
+ tag = 'version' + (new Date).getTime(),
+ allConfigData = [],
+ serviceConfigData = [];
+
Object.keys(service.get('configTypes')).forEach(function (type) {
if (!serviceConfigTags.someProperty('type', type)) {
var obj = this.createKerberosSiteObj(type, tag);
@@ -185,8 +208,7 @@ App.KerberosWizardStep2Controller = App.WizardStep7Controller.extend(App.KDCCred
serviceConfigTags.pushObject(obj);
}
}, this);
- var allConfigData = [];
- var serviceConfigData = [];
+
Object.keys(service.get('configTypesRendered')).forEach(function (type) {
var serviceConfigTag = serviceConfigTags.findProperty('type', type);
if (serviceConfigTag) {
@@ -215,6 +237,7 @@ App.KerberosWizardStep2Controller = App.WizardStep7Controller.extend(App.KDCCred
var configs = content.filterProperty('filename', site + '.xml');
// properties that should be formated as hosts
var hostProperties = ['kdc_hosts', 'realm'];
+
configs.forEach(function (_configProperty) {
// do not pass any globals whose name ends with _host or _hosts
if (_configProperty.isRequiredByAgent !== false) {
@@ -232,9 +255,10 @@ App.KerberosWizardStep2Controller = App.WizardStep7Controller.extend(App.KDCCred
},
tweakKdcTypeValue: function (properties) {
- for (var prop in App.router.get('mainAdminKerberosController.kdcTypesValues')) {
- if (App.router.get('mainAdminKerberosController.kdcTypesValues').hasOwnProperty(prop)) {
- if (App.router.get('mainAdminKerberosController.kdcTypesValues')[prop] === properties['kdc_type']) {
+ var kdcTypesValues = App.router.get('mainAdminKerberosController.kdcTypesValues');
+ for (var prop in kdcTypesValues) {
+ if (kdcTypesValues.hasOwnProperty(prop)) {
+ if (kdcTypesValues[prop] === properties['kdc_type']) {
properties['kdc_type'] = prop;
}
}
@@ -242,7 +266,7 @@ App.KerberosWizardStep2Controller = App.WizardStep7Controller.extend(App.KDCCred
},
tweakManualKdcProperties: function (properties) {
- var kerberosWizardController = this.controllers.get('kerberosWizardController');
+ var kerberosWizardController = this.get('controllers.kerberosWizardController');
if (properties['kdc_type'] === 'none' || kerberosWizardController.get('skipClientInstall')) {
if (properties.hasOwnProperty('manage_identities')) {
properties['manage_identities'] = 'false';
@@ -286,7 +310,7 @@ App.KerberosWizardStep2Controller = App.WizardStep7Controller.extend(App.KDCCred
name: 'common.cluster.update',
sender: this,
data: {
- clusterName: App.get('clusterName') || App.clusterStatus.get('clusterName'),
+ clusterName: App.get('clusterName'),
data: [{
session_attributes: {
kerberos_admin: {principal: adminPrincipalValue, password: adminPasswordValue}
@@ -298,12 +322,12 @@ App.KerberosWizardStep2Controller = App.WizardStep7Controller.extend(App.KDCCred
/**
* shows popup with to warn user
- * @param primary
+ * @param {Function} primary
*/
showConnectionInProgressPopup: function(primary) {
var primaryText = Em.I18n.t('common.exitAnyway');
var msg = Em.I18n.t('services.service.config.connection.exitPopup.msg');
- App.showConfirmationPopup(primary, msg, null, null, primaryText)
+ App.showConfirmationPopup(primary, msg, null, null, primaryText);
},
setKDCTypeProperty: function(configs) {
http://git-wip-us.apache.org/repos/asf/ambari/blob/5c782dd8/ambari-web/app/controllers/main/admin/kerberos/step3_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/admin/kerberos/step3_controller.js b/ambari-web/app/controllers/main/admin/kerberos/step3_controller.js
index 22191de..a244348 100644
--- a/ambari-web/app/controllers/main/admin/kerberos/step3_controller.js
+++ b/ambari-web/app/controllers/main/admin/kerberos/step3_controller.js
@@ -57,8 +57,8 @@ App.KerberosWizardStep3Controller = App.KerberosProgressPageController.extend({
name: 'common.service_component.info',
sender: this,
data: {
- serviceName: this.serviceName,
- componentName: this.componentName,
+ serviceName: this.get('serviceName'),
+ componentName: this.get('componentName'),
urlParams: "fields=ServiceComponentInfo/state"
}
});
@@ -116,6 +116,6 @@ App.KerberosWizardStep3Controller = App.KerberosProgressPageController.extend({
if (this.get('showIgnore')) {
this.set('isSubmitDisabled', !this.get('ignore'));
}
- }.observes('ignore','showIgnore')
+ }.observes('ignore', 'showIgnore')
});
http://git-wip-us.apache.org/repos/asf/ambari/blob/5c782dd8/ambari-web/app/controllers/main/admin/kerberos/step4_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/admin/kerberos/step4_controller.js b/ambari-web/app/controllers/main/admin/kerberos/step4_controller.js
index b3acb8b..1d6f5c9 100644
--- a/ambari-web/app/controllers/main/admin/kerberos/step4_controller.js
+++ b/ambari-web/app/controllers/main/admin/kerberos/step4_controller.js
@@ -293,16 +293,16 @@ App.KerberosWizardStep4Controller = App.WizardStep7Controller.extend(App.AddSecu
* @param {App.ServiceConfigProperty} configProperty
*/
spnegoPropertiesObserver: function(configProperty) {
- var self = this;
var stepConfig = this.get('stepConfigs').findProperty('name', 'ADVANCED');
+
stepConfig.get('configs').forEach(function(config) {
if (config.get('observesValueFrom') === configProperty.get('name')) {
- Em.run.once(self, function() {
+ Em.run.once(this, function() {
config.set('value', configProperty.get('value'));
config.set('recommendedValue', configProperty.get('value'));
});
}
- });
+ }, this);
},
submit: function() {
@@ -313,6 +313,7 @@ App.KerberosWizardStep4Controller = App.WizardStep7Controller.extend(App.AddSecu
saveConfigurations: function() {
var kerberosDescriptor = this.get('kerberosDescriptor');
var configs = [];
+
this.get('stepConfigs').forEach(function(_stepConfig){
configs = configs.concat(_stepConfig.get('configs'));
});
@@ -418,6 +419,7 @@ App.KerberosWizardStep4Controller = App.WizardStep7Controller.extend(App.AddSecu
bootstrapRecommendationPayload: function(kerberosDescriptor) {
var dfd = $.Deferred();
var self = this;
+
this.getServicesConfigurations().then(function(configurations) {
var recommendations = self.getBlueprintPayloadObject(configurations, kerberosDescriptor);
self.set('servicesConfigurations', configurations);
@@ -469,6 +471,7 @@ App.KerberosWizardStep4Controller = App.WizardStep7Controller.extend(App.AddSecu
getBlueprintPayloadObject: function(configurations, kerberosDescriptor) {
var recommendations = this.get('hostGroups');
var mergedConfigurations = this.mergeDescriptorToConfigurations(configurations, this.createServicesStackDescriptorConfigs(kerberosDescriptor));
+
recommendations.blueprint.configurations = mergedConfigurations.reduce(function(p, c) {
p[c.type] = {};
p[c.type].properties = c.properties;
@@ -593,6 +596,12 @@ App.KerberosWizardStep4Controller = App.WizardStep7Controller.extend(App.AddSecu
}, resultMap);
},
+ /**
+ *
+ * @method getServiceByFilename
+ * @param {string}fileName
+ * @returns {string}
+ */
getServiceByFilename: function(fileName) {
// core-site properties goes to HDFS
if (fileName === 'core-site' && App.Service.find().someProperty('serviceName', 'HDFS')) {
http://git-wip-us.apache.org/repos/asf/ambari/blob/5c782dd8/ambari-web/app/controllers/main/admin/kerberos/step5_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/admin/kerberos/step5_controller.js b/ambari-web/app/controllers/main/admin/kerberos/step5_controller.js
index a298cf3..9cb75e0 100644
--- a/ambari-web/app/controllers/main/admin/kerberos/step5_controller.js
+++ b/ambari-web/app/controllers/main/admin/kerberos/step5_controller.js
@@ -20,8 +20,34 @@ var fileUtils = require('utils/file_utils');
App.KerberosWizardStep5Controller = App.KerberosProgressPageController.extend({
name: 'kerberosWizardStep5Controller',
+
+ /**
+ * @type {Array}
+ */
csvData: [],
+ /**
+ * @type {Array}
+ */
+ kdcProperties: [
+ {
+ key: Em.I18n.t('admin.kerberos.wizard.step1.option.kdc'),
+ properties: ['kdc_type', 'kdc_hosts', 'realm', 'executable_search_paths']
+ },
+ {
+ key: Em.I18n.t('admin.kerberos.wizard.step1.option.ad'),
+ properties: ['kdc_type', 'kdc_hosts', 'realm', 'ldap_url', 'container_dn', 'executable_search_paths']
+ },
+ {
+ key: Em.I18n.t('admin.kerberos.wizard.step1.option.ipa'),
+ properties: ['kdc_type', 'kdc_hosts', 'realm', 'executable_search_paths']
+ },
+ {
+ key: Em.I18n.t('admin.kerberos.wizard.step1.option.manual'),
+ properties: ['kdc_type', 'realm', 'executable_search_paths']
+ }
+ ],
+
submit: function() {
App.router.send('next');
},
@@ -30,7 +56,7 @@ App.KerberosWizardStep5Controller = App.KerberosProgressPageController.extend({
* get CSV data from the server
*/
getCSVData: function (skipDownload) {
- App.ajax.send({
+ return App.ajax.send({
name: 'admin.kerberos.cluster.csv',
sender: this,
data: {
@@ -38,15 +64,18 @@ App.KerberosWizardStep5Controller = App.KerberosProgressPageController.extend({
},
success: 'getCSVDataSuccessCallback',
error: 'getCSVDataSuccessCallback'
- })
+ });
},
/**
* get CSV data from server success callback
+ * @param data {string}
+ * @param opt {object}
+ * @param params {object}
*/
getCSVDataSuccessCallback: function (data, opt, params) {
this.set('csvData', this.prepareCSVData(data.split('\n')));
- if(!Em.get(params, 'skipDownload')){
+ if (!Em.get(params, 'skipDownload')) {
fileUtils.downloadTextFile(stringUtils.arrayToCSV(this.get('csvData')), 'csv', 'kerberos.csv');
}
},
@@ -119,31 +148,15 @@ App.KerberosWizardStep5Controller = App.KerberosProgressPageController.extend({
isSubmitDisabled: Em.computed.notExistsIn('status', ['COMPLETED', 'FAILED']),
confirmProperties: function () {
- var kdc_type = App.router.get('kerberosWizardController.content.kerberosOption'),
- filterObject = [
- {
- key: Em.I18n.t('admin.kerberos.wizard.step1.option.kdc'),
- properties: ['kdc_type', 'kdc_hosts', 'realm', 'executable_search_paths']
- },
- {
- key: Em.I18n.t('admin.kerberos.wizard.step1.option.ad'),
- properties: ['kdc_type', 'kdc_hosts', 'realm', 'ldap_url', 'container_dn', 'executable_search_paths']
- },
- {
- key: Em.I18n.t('admin.kerberos.wizard.step1.option.ipa'),
- properties: ['kdc_type', 'kdc_hosts', 'realm', 'executable_search_paths']
- },
- {
- key: Em.I18n.t('admin.kerberos.wizard.step1.option.manual'),
- properties: ['kdc_type', 'realm', 'executable_search_paths']
- }
- ],
- kdcTypeProperties = filterObject.filter(function (item) {
+ var wizardController = App.router.get('kerberosWizardController');
+ var kdc_type = wizardController.get('content.kerberosOption'),
+ kdcTypeProperties = this.get('kdcProperties').filter(function (item) {
return item.key === kdc_type;
}),
- filterBy = kdcTypeProperties.length ? kdcTypeProperties[0].properties : [];
- return App.router.kerberosWizardController.content.serviceConfigProperties.filter(function (item) {
- return filterBy.contains(item.name);
+ properties = kdcTypeProperties.length ? kdcTypeProperties[0].properties : [];
+
+ return wizardController.get('content.serviceConfigProperties').filter(function (item) {
+ return properties.contains(item.name);
}).map(function (item) {
item['label'] = Em.I18n.t('admin.kerberos.wizard.step5.' + item['name'] + '.label');
return item;
http://git-wip-us.apache.org/repos/asf/ambari/blob/5c782dd8/ambari-web/app/controllers/main/admin/kerberos/step7_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/admin/kerberos/step7_controller.js b/ambari-web/app/controllers/main/admin/kerberos/step7_controller.js
index 2a4fb90..50e5ec3 100644
--- a/ambari-web/app/controllers/main/admin/kerberos/step7_controller.js
+++ b/ambari-web/app/controllers/main/admin/kerberos/step7_controller.js
@@ -35,7 +35,6 @@ App.KerberosWizardStep7Controller = App.KerberosProgressPageController.extend({
* @param {bool} isRetry
*/
setRequest: function (isRetry) {
- var self = this;
var kerberizeRequest = {
name: 'KERBERIZE_CLUSTER',
ajaxName: 'admin.kerberize.cluster',
@@ -49,12 +48,12 @@ App.KerberosWizardStep7Controller = App.KerberosProgressPageController.extend({
};
if (isRetry) {
// on retry send force update
- self.set('request', {
+ this.set('request', {
name: 'KERBERIZE_CLUSTER',
ajaxName: 'admin.kerberize.cluster.force'
});
- self.clearStage();
- self.loadStep();
+ this.clearStage();
+ this.loadStep();
} else {
this.set('request', kerberizeRequest);
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/5c782dd8/ambari-web/app/controllers/main/admin/kerberos/wizard_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/admin/kerberos/wizard_controller.js b/ambari-web/app/controllers/main/admin/kerberos/wizard_controller.js
index baceb80..5fc1633 100644
--- a/ambari-web/app/controllers/main/admin/kerberos/wizard_controller.js
+++ b/ambari-web/app/controllers/main/admin/kerberos/wizard_controller.js
@@ -101,11 +101,11 @@ App.KerberosWizardController = App.WizardController.extend(App.InstallComponent,
* @return Object
*/
getCluster: function () {
- return jQuery.extend({}, this.get('clusterStatusTemplate'), {name: App.get('router').getClusterName()});
+ return jQuery.extend({}, this.get('clusterStatusTemplate'), {name: App.get('clusterName')});
},
updateClusterEnvData: function (configs) {
- var kerberosDescriptor = this.kerberosDescriptorConfigs;
+ var kerberosDescriptor = this.get('kerberosDescriptorConfigs');
configs['security_enabled'] = true;
configs['kerberos_domain'] = kerberosDescriptor.properties.realm;
return configs;
@@ -156,14 +156,14 @@ App.KerberosWizardController = App.WizardController.extend(App.InstallComponent,
* Override the visibility of a list of form items with a new value
*
* @param {Array} itemsArray
- * @param newValue
- * @param exceptions
+ * @param {boolean} newValue
+ * @param {Array} exceptions
*/
overrideVisibility: function (itemsArray, newValue, exceptions) {
newValue = newValue || false;
for (var i = 0, len = itemsArray.length; i < len; i += 1) {
- if (!Ember.$.isEmptyObject(itemsArray[i])) {
+ if (!App.isEmptyObject(itemsArray[i])) {
var isException = exceptions.filterProperty(itemsArray[i].category, itemsArray[i].name);
if (!isException.length) {
itemsArray[i].isVisible = newValue;
@@ -176,8 +176,12 @@ App.KerberosWizardController = App.WizardController.extend(App.InstallComponent,
this.set('content.kerberosOption', this.getDBProperty('kerberosOption'));
},
+ /**
+ * @method saveKerberosDescriptorConfigs
+ * @param {App.ServiceConfigProperty[]} kerberosDescriptorConfigs
+ */
saveKerberosDescriptorConfigs: function (kerberosDescriptorConfigs) {
- this.setDBProperty('kerberosDescriptorConfigs',kerberosDescriptorConfigs);
+ this.setDBProperty('kerberosDescriptorConfigs', kerberosDescriptorConfigs);
this.set('kerberosDescriptorConfigs', kerberosDescriptorConfigs);
},
@@ -196,7 +200,7 @@ App.KerberosWizardController = App.WizardController.extend(App.InstallComponent,
sender: this,
data: {
data: '{"ServiceInfo": { "service_name": "KERBEROS"}}',
- cluster: App.get('clusterName') || App.clusterStatus.get('clusterName')
+ cluster: App.get('clusterName')
}
});
},
@@ -207,12 +211,15 @@ App.KerberosWizardController = App.WizardController.extend(App.InstallComponent,
* @returns {$.Deferred}
*/
deleteKerberosService: function () {
- var serviceName = 'KERBEROS';
- if (App.cache.services.someProperty('ServiceInfo.service_name', serviceName)) {
- App.cache.services.removeAt(App.cache.services.indexOf(App.cache.services.findProperty('ServiceInfo.service_name', serviceName)));
+ var serviceName = 'KERBEROS',
+ cachedService = App.cache.services.findProperty('ServiceInfo.service_name', serviceName),
+ modelService = App.Service.find(serviceName);
+
+ if (cachedService) {
+ App.cache.services.removeObject(cachedService);
}
- if (App.Service.find().someProperty('serviceName', serviceName)) {
- App.serviceMapper.deleteRecord(App.Service.find(serviceName));
+ if (modelService.get('isLoaded')) {
+ App.serviceMapper.deleteRecord(modelService);
}
return App.ajax.send({
name: 'common.delete.service',
@@ -263,7 +270,7 @@ App.KerberosWizardController = App.WizardController.extend(App.InstallComponent,
name: 'wizard.step8.register_host_to_component',
sender: this,
data: {
- cluster: App.router.getClusterName(),
+ cluster: App.get('clusterName'),
data: JSON.stringify(data)
}
});
@@ -335,10 +342,11 @@ App.KerberosWizardController = App.WizardController.extend(App.InstallComponent,
this.saveRequestIds(undefined);
this.saveTasksRequestIds(undefined);
},
+
/**
* shows popup with to warn user
- * @param primary
- * @param isCritical
+ * @param {Function} primary
+ * @param {boolean} isCritical
*/
warnBeforeExitPopup: function(primary, isCritical) {
var primaryText = Em.I18n.t('common.exitAnyway');
http://git-wip-us.apache.org/repos/asf/ambari/blob/5c782dd8/ambari-web/test/controllers/main/admin/kerberos/disable_controller_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/main/admin/kerberos/disable_controller_test.js b/ambari-web/test/controllers/main/admin/kerberos/disable_controller_test.js
new file mode 100644
index 0000000..bbccbc0
--- /dev/null
+++ b/ambari-web/test/controllers/main/admin/kerberos/disable_controller_test.js
@@ -0,0 +1,122 @@
+/**
+ * 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');
+
+
+describe('App.KerberosDisableController', function() {
+ var controller;
+
+ beforeEach(function() {
+ controller = App.KerberosDisableController.create();
+ });
+
+ describe("#loadStep()", function () {
+
+ beforeEach(function() {
+ sinon.stub(controller, 'loadTasksStatuses');
+ sinon.stub(controller, 'loadTasksRequestIds');
+ sinon.stub(controller, 'loadRequestIds');
+ controller.loadStep();
+ });
+
+ afterEach(function() {
+ controller.loadTasksStatuses.restore();
+ controller.loadTasksRequestIds.restore();
+ controller.loadRequestIds.restore();
+ });
+
+ it("controllerName should be set", function() {
+ expect(controller.get('content.controllerName')).to.be.equal('kerberosDisableController');
+ });
+
+ 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;
+ });
+ });
+
+ describe("#unkerberize()", function () {
+
+ it("App.ajax.send should be called", function() {
+ controller.unkerberize();
+ var args = testHelpers.findAjaxRequest('name', 'admin.unkerberize.cluster');
+ expect(args[0]).to.be.eql({
+ name: 'admin.unkerberize.cluster',
+ sender: controller,
+ success: 'startPolling',
+ error: 'onTaskErrorWithSkip'
+ });
+ });
+ });
+
+ describe("#skipTask()", function () {
+
+ it("App.ajax.send should be called", function() {
+ controller.skipTask();
+ var args = testHelpers.findAjaxRequest('name', 'admin.unkerberize.cluster.skip');
+ expect(args[0]).to.be.eql({
+ name: 'admin.unkerberize.cluster.skip',
+ sender: controller,
+ success: 'startPolling',
+ error: 'onTaskError'
+ });
+ });
+ });
+
+ describe("#deleteKerberos()", function () {
+
+ it("App.ajax.send should be called", function() {
+ controller.deleteKerberos();
+ var args = testHelpers.findAjaxRequest('name', 'common.delete.service');
+ expect(args[0]).to.be.eql({
+ name: 'common.delete.service',
+ sender: controller,
+ data: {
+ serviceName: 'KERBEROS'
+ },
+ success: 'onTaskCompleted',
+ error: 'onTaskCompleted'
+ });
+ });
+ });
+
+ describe("#startAllServices()", function () {
+
+ beforeEach(function() {
+ sinon.stub(controller, 'startServices');
+ });
+
+ afterEach(function() {
+ controller.startServices.restore();
+ });
+
+ it("startServices should be called", function() {
+ controller.startAllServices();
+ expect(controller.startServices.calledOnce).to.be.true;
+ });
+ });
+});
http://git-wip-us.apache.org/repos/asf/ambari/blob/5c782dd8/ambari-web/test/controllers/main/admin/kerberos/kerberos_wizard_controler_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/main/admin/kerberos/kerberos_wizard_controler_test.js b/ambari-web/test/controllers/main/admin/kerberos/kerberos_wizard_controler_test.js
index 7651bdb..6696c3c 100644
--- a/ambari-web/test/controllers/main/admin/kerberos/kerberos_wizard_controler_test.js
+++ b/ambari-web/test/controllers/main/admin/kerberos/kerberos_wizard_controler_test.js
@@ -17,9 +17,14 @@
*/
var App = require('app');
+var testHelpers = require('test/helpers');
describe('App.KerberosWizardController', function() {
- var controller = App.KerberosWizardController.create({});
+ var controller;
+
+ beforeEach(function() {
+ controller = App.KerberosWizardController.create({});
+ });
describe('#warnBeforeExitPopup()', function () {
beforeEach(function () {
@@ -41,6 +46,506 @@ describe('App.KerberosWizardController', function() {
});
});
+ describe("#skipClientInstall", function () {
+
+ it("kerberosOption is null", function() {
+ controller.set('content.kerberosOption', null);
+ controller.propertyDidChange('skipClientInstall');
+ expect(controller.get('skipClientInstall')).to.be.false;
+ });
+
+ it("kerberosOption is 'opt1'", function() {
+ controller.set('content.kerberosOption', 'opt1');
+ controller.propertyDidChange('skipClientInstall');
+ expect(controller.get('skipClientInstall')).to.be.false;
+ });
+
+ it("kerberosOption is manual", function() {
+ controller.set('content.kerberosOption', Em.I18n.t('admin.kerberos.wizard.step1.option.manual'));
+ controller.propertyDidChange('skipClientInstall');
+ expect(controller.get('skipClientInstall')).to.be.true;
+ });
+ });
+
+ describe("#setCurrentStep()", function () {
+
+ beforeEach(function() {
+ sinon.stub(App.clusterStatus, 'setClusterStatus');
+ });
+
+ afterEach(function() {
+ App.clusterStatus.setClusterStatus.restore();
+ });
+
+ it("skipStateSave is true", function() {
+ controller.setCurrentStep("", true, true);
+ expect(App.clusterStatus.setClusterStatus.called).to.be.false;
+ });
+
+ it("skipStateSave is false", function() {
+ controller.setCurrentStep("", true, false);
+ expect(App.clusterStatus.setClusterStatus.calledOnce).to.be.true;
+ });
+ });
+
+ describe("#getCluster()", function () {
+
+ it("jQuery.extend should be called", function() {
+ App.set('clusterName', 'c1');
+ controller.set('clusterStatusTemplate', {});
+ expect(controller.getCluster()).to.be.eql({name: 'c1'});
+ });
+ });
+
+ describe("#updateClusterEnvData()", function () {
+
+ it("configs should be set", function() {
+ var configs = {};
+ controller.set('kerberosDescriptorConfigs', {
+ properties: {
+ realm: 'realm'
+ }
+ });
+ controller.updateClusterEnvData(configs);
+ expect(configs).to.be.eql({
+ security_enabled: true,
+ kerberos_domain: 'realm'
+ });
+ });
+ });
+
+ describe("#saveClusterStatus()", function () {
+
+ beforeEach(function() {
+ sinon.stub(controller, 'save');
+ });
+
+ afterEach(function() {
+ controller.save.restore();
+ });
+
+ it("save should be called", function() {
+ controller.set('content.cluster', {});
+ controller.saveClusterStatus({});
+ expect(controller.save.calledWith('cluster')).to.be.true;
+ });
+
+ it("new requestId should be pushed", function() {
+ controller.set('content.cluster', {});
+ controller.saveClusterStatus({requestId: [1], oldRequestsId: []});
+ expect(controller.get('content.cluster')).to.be.eql({
+ oldRequestsId: [1],
+ requestId: [1]
+ });
+ });
+
+ it("new requestId should not be pushed", function() {
+ controller.set('content.cluster', {});
+ controller.saveClusterStatus({requestId: [1], oldRequestsId: [1]});
+ expect(controller.get('content.cluster')).to.be.eql({
+ oldRequestsId: [1],
+ requestId: [1]
+ });
+ });
+ });
+
+ describe("#saveConfigTag()", function () {
+ var tag = {
+ name: 'n1',
+ value: 'v1'
+ };
+
+ beforeEach(function() {
+ sinon.stub(App.db, 'setKerberosWizardConfigTag');
+ controller.saveConfigTag(tag);
+ });
+
+ afterEach(function() {
+ App.db.setKerberosWizardConfigTag.restore();
+ });
+
+ it("App.db.setKerberosWizardConfigTag should be called", function() {
+ expect(App.db.setKerberosWizardConfigTag.calledWith(tag)).to.be.true;
+ });
+
+ it("content property should be set", function() {
+ expect(controller.get('content.n1')).to.be.equal('v1');
+ });
+ });
+
+ describe("#saveKerberosOption()", function () {
+
+ beforeEach(function() {
+ sinon.stub(controller, 'setDBProperty');
+ controller.saveKerberosOption(Em.Object.create({selectedItem: "selectedItem"}));
+ });
+
+ afterEach(function() {
+ controller.setDBProperty.restore();
+ });
+
+ it("setDBProperty should be called", function() {
+ expect(controller.setDBProperty.calledWith('kerberosOption', "selectedItem")).to.be.true;
+ });
+
+ it("kerberosOption should be set", function() {
+ expect(controller.get('content.kerberosOption')).to.be.equal('selectedItem');
+ });
+ });
+
+ describe("#loadServiceConfigProperties()", function () {
+
+ beforeEach(function() {
+ sinon.stub(controller, 'getDBProperty').returns([{}]);
+ });
+
+ afterEach(function() {
+ controller.getDBProperty.restore();
+ });
+
+ it("serviceConfigProperties should be set", function() {
+ controller.loadServiceConfigProperties();
+ expect(controller.get('content.serviceConfigProperties')).to.be.eql([{}]);
+ });
+ });
+
+ describe("#loadKerberosDescriptorConfigs()", function () {
+
+ beforeEach(function() {
+ sinon.stub(controller, 'getDBProperty').returns({});
+ });
+
+ afterEach(function() {
+ controller.getDBProperty.restore();
+ });
+
+ it("kerberosDescriptorConfigs should be set", function() {
+ controller.loadKerberosDescriptorConfigs();
+ expect(controller.get('kerberosDescriptorConfigs')).to.be.eql({});
+ });
+ });
+
+ describe("#overrideVisibility()", function () {
+
+ it("empty object", function() {
+ var itemsArray = [
+ {}
+ ];
+ controller.overrideVisibility(itemsArray, true, []);
+ expect(itemsArray[0]).to.be.empty;
+ });
+
+ it("override in exception", function() {
+ var itemsArray = [
+ {
+ category: 'c1',
+ name: 'n1',
+ isVisible: false
+ }
+ ];
+ controller.overrideVisibility(itemsArray, true, [{c1: 'n1'}]);
+ expect(itemsArray[0].isVisible).to.be.false;
+ });
+
+ it("override should be set to visible", function() {
+ var itemsArray = [
+ {
+ category: 'c1',
+ name: 'n1',
+ isVisible: false
+ }
+ ];
+ controller.overrideVisibility(itemsArray, true, []);
+ expect(itemsArray[0].isVisible).to.be.true;
+ });
+ });
+
+ describe("#loadKerberosOption()", function () {
+
+ beforeEach(function() {
+ sinon.stub(controller, 'getDBProperty').returns('kerberosOption');
+ });
+
+ afterEach(function() {
+ controller.getDBProperty.restore();
+ });
+
+ it("kerberosOption should be set", function() {
+ controller.loadKerberosOption();
+ expect(controller.get('content.kerberosOption')).to.be.equal('kerberosOption');
+ });
+ });
+
+ describe("#saveKerberosDescriptorConfigs()", function () {
+
+ beforeEach(function() {
+ sinon.stub(controller, 'setDBProperty');
+ controller.saveKerberosDescriptorConfigs([]);
+ });
+
+ afterEach(function() {
+ controller.setDBProperty.restore();
+ });
+
+ it("setDBProperty should be called", function() {
+ expect(controller.setDBProperty.calledWith('kerberosDescriptorConfigs', [])).to.be.true;
+ });
+
+ it("kerberosDescriptorConfigs should be set", function() {
+ expect(controller.get('kerberosDescriptorConfigs')).to.be.eql([]);
+ });
+ });
+
+ describe("#createKerberosResources()", function () {
+ var mock = {
+ callback: Em.K
+ };
+
+ beforeEach(function() {
+ sinon.stub(mock, 'callback');
+ sinon.stub(controller, 'createKerberosService').returns({
+ done: Em.clb
+ });
+ sinon.stub(controller, 'updateAndCreateServiceComponent').returns({
+ done: Em.clb
+ });
+ sinon.stub(controller, 'createKerberosHostComponents').returns({
+ done: Em.clb
+ });
+ controller.createKerberosResources(mock.callback);
+ });
+
+ afterEach(function() {
+ controller.createKerberosHostComponents.restore();
+ controller.updateAndCreateServiceComponent.restore();
+ controller.createKerberosService.restore();
+ mock.callback.restore();
+ });
+
+ it("createKerberosService should be called", function() {
+ expect(controller.createKerberosService.calledOnce).to.be.true;
+ });
+
+ it("updateAndCreateServiceComponent should be called", function() {
+ expect(controller.updateAndCreateServiceComponent.calledWith('KERBEROS_CLIENT')).to.be.true;
+ });
+
+ it("createKerberosHostComponents should be called", function() {
+ expect(controller.createKerberosHostComponents.calledOnce).to.be.true;
+ });
+
+ it("callback should be called", function() {
+ expect(mock.callback.calledOnce).to.be.true;
+ });
+ });
+
+ describe("#createKerberosService()", function () {
+
+ it("App.ajax.send should be called", function() {
+ App.set('clusterName', 'c1');
+ controller.createKerberosService();
+ var args = testHelpers.findAjaxRequest('name', 'wizard.step8.create_selected_services');
+ expect(args[0]).to.be.eql({
+ name: 'wizard.step8.create_selected_services',
+ sender: controller,
+ data: {
+ data: '{"ServiceInfo": { "service_name": "KERBEROS"}}',
+ cluster: 'c1'
+ }
+ });
+ });
+ });
+
+ describe("#deleteKerberosService()", function () {
+
+ beforeEach(function() {
+ App.cache.services = [{
+ ServiceInfo: {
+ service_name: 'KERBEROS'
+ }
+ }];
+ sinon.stub(App.serviceMapper, 'deleteRecord');
+ sinon.stub(App.Service, 'find').returns(Em.Object.create({
+ isLoaded: true
+ }));
+ controller.deleteKerberosService();
+ });
+
+ afterEach(function() {
+ App.serviceMapper.deleteRecord.restore();
+ App.Service.find.restore();
+ });
+
+ it("App.cache.services should be empty", function() {
+ expect(App.cache.services).to.be.empty;
+ });
+
+ it("App.serviceMapper.deleteRecord should be called", function () {
+ expect(App.serviceMapper.deleteRecord.calledWith(Em.Object.create({
+ isLoaded: true
+ }))).to.be.true;
+ });
+
+ it("App.ajax.send should be called", function() {
+ var args = testHelpers.findAjaxRequest('name', 'common.delete.service');
+ expect(args[0]).to.be.eql({
+ name: 'common.delete.service',
+ sender: controller,
+ data: {
+ serviceName: 'KERBEROS'
+ }
+ });
+ });
+ });
+
+ describe("#unkerberize()", function () {
+
+ it("App.ajax.send should be called", function() {
+ controller.unkerberize();
+ var args = testHelpers.findAjaxRequest('name', 'admin.unkerberize.cluster');
+ expect(args[0]).to.be.eql({
+ name: 'admin.unkerberize.cluster',
+ sender: controller
+ });
+ });
+ });
+
+ describe("#createKerberosHostComponents()", function () {
+
+ it("App.ajax.send should be called", function() {
+ App.set('clusterName', 'c1');
+ App.set('allHostNames', ['host1']);
+ controller.createKerberosHostComponents();
+ var args = testHelpers.findAjaxRequest('name', 'wizard.step8.register_host_to_component');
+ expect(args[0]).to.be.exists;
+ });
+ });
+
+ describe("#clearAllSteps()", function () {
+
+ beforeEach(function() {
+ sinon.stub(controller, 'clearInstallOptions');
+ sinon.stub(controller, 'getCluster').returns({});
+ controller.clearAllSteps();
+ });
+
+ afterEach(function() {
+ controller.clearInstallOptions.restore();
+ controller.getCluster.restore();
+ });
+
+ it("clearInstallOptions should be called", function() {
+ expect(controller.clearInstallOptions.calledOnce).to.be.true;
+ });
+
+ it("content.cluster should be set", function() {
+ expect(controller.get('content.cluster')).to.be.eql({});
+ });
+ });
+
+ describe("#clearTasksData()", function () {
+
+ beforeEach(function() {
+ sinon.stub(controller, 'saveTasksStatuses');
+ sinon.stub(controller, 'saveRequestIds');
+ sinon.stub(controller, 'saveTasksRequestIds');
+ controller.clearTasksData();
+ });
+
+ afterEach(function() {
+ controller.saveTasksRequestIds.restore();
+ controller.saveTasksStatuses.restore();
+ controller.saveRequestIds.restore();
+ });
+
+ it("saveTasksRequestIds should be called", function() {
+ expect(controller.saveTasksRequestIds.calledWith(undefined)).to.be.true;
+ });
+
+ it("saveRequestIds should be called", function() {
+ expect(controller.saveRequestIds.calledWith(undefined)).to.be.true;
+ });
+
+ it("saveTasksRequestIds should be called", function() {
+ expect(controller.saveTasksRequestIds.calledWith(undefined)).to.be.true;
+ });
+ });
+
+ describe("#warnBeforeExitPopup()", function () {
+
+ beforeEach(function() {
+ sinon.stub(App, 'showConfirmationPopup');
+ });
+
+ afterEach(function() {
+ App.showConfirmationPopup.restore();
+ });
+
+ it("isCritical is true", function() {
+ controller.warnBeforeExitPopup(Em.K, true);
+ expect(App.showConfirmationPopup.calledWith(Em.K, Em.I18n.t('admin.kerberos.wizard.exit.critical.msg'), null, null, Em.I18n.t('common.exitAnyway'), true)).to.be.true;
+ });
+
+ it("isCritical is false", function() {
+ controller.warnBeforeExitPopup(Em.K, false);
+ expect(App.showConfirmationPopup.calledWith(Em.K, Em.I18n.t('admin.kerberos.wizard.exit.warning.msg'), null, null, Em.I18n.t('common.exitAnyway'), false)).to.be.true;
+ });
+ });
+
+ describe("#finish()", function () {
+
+ beforeEach(function() {
+ sinon.stub(controller, 'setCurrentStep');
+ sinon.stub(controller, 'resetDbNamespace');
+ controller.finish();
+ });
+
+ afterEach(function() {
+ controller.setCurrentStep.restore();
+ controller.resetDbNamespace.restore();
+ });
+
+ it("setCurrentStep should be called", function() {
+ expect(controller.setCurrentStep.calledWith('1', false, true)).to.be.true;
+ });
+
+ it("resetDbNamespace should be called", function() {
+ expect(controller.resetDbNamespace.calledOnce).to.be.true;
+ });
+ });
+
+ describe("#discardChanges()", function () {
+ var mock = {
+ onResolve: Em.K
+ };
+
+ beforeEach(function() {
+ sinon.stub(controller, 'unkerberize').returns({always: Em.clb});
+ sinon.stub(controller, 'deleteKerberosService').returns({always: Em.clb});
+ sinon.stub(mock, 'onResolve');
+ controller.discardChanges().done(mock.onResolve);
+ });
+
+ afterEach(function() {
+ controller.unkerberize.restore();
+ controller.deleteKerberosService.restore();
+ mock.onResolve.restore();
+ });
+
+ it("unkerberize should be called", function() {
+ expect(controller.unkerberize.calledOnce).to.be.true;
+ });
+
+ it("deleteKerberosService should be called", function() {
+ expect(controller.deleteKerberosService.calledOnce).to.be.true;
+ });
+
+ it("onResolve should be called", function() {
+ expect(mock.onResolve.calledOnce).to.be.true;
+ });
+ });
+
+
});
http://git-wip-us.apache.org/repos/asf/ambari/blob/5c782dd8/ambari-web/test/controllers/main/admin/kerberos/step1_controller_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/main/admin/kerberos/step1_controller_test.js b/ambari-web/test/controllers/main/admin/kerberos/step1_controller_test.js
new file mode 100644
index 0000000..280f923
--- /dev/null
+++ b/ambari-web/test/controllers/main/admin/kerberos/step1_controller_test.js
@@ -0,0 +1,93 @@
+/**
+ * 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.KerberosWizardStep1Controller.create({});
+}
+
+describe('App.KerberosWizardStep1Controller', function() {
+ var controller;
+
+ beforeEach(function() {
+ controller = getController();
+ });
+
+ describe("#selectedOption", function () {
+
+ it("test", function() {
+ controller.setProperties({
+ options: [{value: 'item1'}],
+ selectedItem: 'item1'
+ });
+ controller.propertyDidChange('selectedOption');
+ expect(controller.get('selectedOption')).to.be.eql({value: 'item1'});
+ });
+ });
+
+ describe("#loadStep()", function () {
+
+ beforeEach(function() {
+ controller.set('options', []);
+ });
+
+ it("enableIpa is true", function() {
+ App.set('supports.enableIpa', true);
+ controller.loadStep();
+ expect(controller.get('selectedItem')).to.be.equal(Em.I18n.t('admin.kerberos.wizard.step1.option.kdc'));
+ expect(controller.get('options')).to.not.be.empty;
+ });
+
+ it("enableIpa is false", function() {
+ App.set('supports.enableIpa', false);
+ controller.loadStep();
+ expect(controller.get('selectedItem')).to.be.equal(Em.I18n.t('admin.kerberos.wizard.step1.option.kdc'));
+ expect(controller.get('options')).to.be.empty;
+ });
+ });
+
+ describe("#next()", function () {
+
+ beforeEach(function() {
+ sinon.stub(App.router, 'send');
+ });
+
+ afterEach(function() {
+ App.router.send.restore();
+ });
+
+ it("App.router.send should be called", function() {
+ controller.reopen({
+ 'isSubmitDisabled': false
+ });
+ controller.next();
+ expect(App.router.send.calledOnce).to.be.true;
+ });
+
+ it("App.router.send should not be called", function() {
+ controller.reopen({
+ 'isSubmitDisabled': true
+ });
+ controller.next();
+ expect(App.router.send.called).to.be.false;
+ });
+ });
+
+});
http://git-wip-us.apache.org/repos/asf/ambari/blob/5c782dd8/ambari-web/test/controllers/main/admin/kerberos/step2_controller_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/main/admin/kerberos/step2_controller_test.js b/ambari-web/test/controllers/main/admin/kerberos/step2_controller_test.js
index 28264e4..260782c 100644
--- a/ambari-web/test/controllers/main/admin/kerberos/step2_controller_test.js
+++ b/ambari-web/test/controllers/main/admin/kerberos/step2_controller_test.js
@@ -18,12 +18,24 @@
var App = require('app');
var setups = require('test/init_model_test');
+var testHelpers = require('test/helpers');
function getController() {
- return App.KerberosWizardStep2Controller.create({});
+ return App.KerberosWizardStep2Controller.create({
+ wizardController: Em.Object.create({
+ deleteKerberosService: Em.K
+ }),
+ controllers: Em.Object.create(),
+ content: Em.Object.create()
+ });
}
describe('App.KerberosWizardStep2Controller', function() {
+ var controller;
+
+ beforeEach(function() {
+ controller = getController();
+ });
App.TestAliases.testAsComputedAlias(getController(), 'isBackBtnDisabled', 'testConnectionInProgress', 'boolean');
@@ -32,11 +44,9 @@ describe('App.KerberosWizardStep2Controller', function() {
App.TestAliases.testAsComputedAlias(getController(), 'isConfigsLoaded', 'wizardController.stackConfigsLoaded', 'boolean');
describe('#createKerberosSiteObj', function() {
- var controller;
beforeEach(function() {
setups.setupStackVersion(this, 'HDP-2.3');
- controller = getController();
sinon.stub(controller, 'tweakKdcTypeValue', Em.K);
sinon.stub(controller, 'tweakManualKdcProperties', Em.K);
});
@@ -104,4 +114,781 @@ describe('App.KerberosWizardStep2Controller', function() {
});
});
+ describe("#isSubmitDisabled", function () {
+ var testCases = [
+ {
+ title: 'stepConfigs is empty',
+ data: {
+ stepConfigs: []
+ },
+ expected: true
+ },
+ {
+ title: 'testConnectionInProgress is true',
+ data: {
+ stepConfigs: [{}],
+ testConnectionInProgress: true
+ },
+ expected: true
+ },
+ {
+ title: 'submitButtonClicked is true',
+ data: {
+ stepConfigs: [{}],
+ testConnectionInProgress: false,
+ submitButtonClicked: true
+ },
+ expected: true
+ },
+ {
+ title: 'configs has errors',
+ data: {
+ stepConfigs: [{showConfig: true, errorCount: 1}],
+ testConnectionInProgress: false,
+ submitButtonClicked: false
+ },
+ expected: true
+ },
+ {
+ title: 'miscModalVisible is true',
+ data: {
+ stepConfigs: [{showConfig: true, errorCount: 0}],
+ testConnectionInProgress: false,
+ submitButtonClicked: false,
+ miscModalVisible: true
+ },
+ expected: true
+ },
+ {
+ title: 'miscModalVisible is false',
+ data: {
+ stepConfigs: [{showConfig: true, errorCount: 0}],
+ testConnectionInProgress: false,
+ submitButtonClicked: false,
+ miscModalVisible: false
+ },
+ expected: false
+ }
+ ];
+
+ testCases.forEach(function(test) {
+ it(test.title, function() {
+ controller.setProperties(test.data);
+ controller.propertyDidChange('isSubmitDisabled');
+ expect(controller.get('isSubmitDisabled')).to.be.equal(test.expected);
+ });
+ });
+ });
+
+ describe("#clearStep()", function () {
+
+ beforeEach(function() {
+ controller.setProperties({
+ configs: [{}],
+ serviceConfigTags: [{}],
+ servicesInstalled: true
+ });
+ controller.clearStep();
+ });
+
+ it("configs should be empty", function() {
+ expect(controller.get('configs')).to.be.empty;
+ });
+
+ it("serviceConfigTags should be empty", function() {
+ expect(controller.get('serviceConfigTags')).to.be.empty;
+ });
+
+ it("servicesInstalled should be false", function() {
+ expect(controller.get('servicesInstalled')).to.be.false;
+ });
+ });
+
+ describe("#loadStep()", function () {
+
+ beforeEach(function() {
+ this.mockStackService = sinon.stub(App.StackService, 'find').returns([{
+ serviceName: 'KERBEROS'
+ }]);
+ sinon.stub(controller, 'clearStep');
+ sinon.stub(App.config, 'setPreDefinedServiceConfigs');
+ sinon.stub(controller, 'filterConfigs');
+ sinon.stub(controller, 'getKerberosConfigs');
+ sinon.stub(controller, 'initializeKDCStoreProperties');
+ sinon.stub(controller, 'applyServicesConfigs');
+ sinon.stub(controller, 'updateKDCStoreProperties');
+ controller.reopen({
+ isConfigsLoaded: true,
+ stepConfigs: [Em.Object.create({serviceName: 'KERBEROS'})],
+ content: Em.Object.create({
+ serviceConfigProperties: [{}]
+ }),
+ wizardController: {
+ skipClientInstall: true
+ }
+ });
+ });
+
+ afterEach(function() {
+ this.mockStackService.restore();
+ controller.clearStep.restore();
+ App.config.setPreDefinedServiceConfigs.restore();
+ controller.filterConfigs.restore();
+ controller.getKerberosConfigs.restore();
+ controller.initializeKDCStoreProperties.restore();
+ controller.applyServicesConfigs.restore();
+ controller.updateKDCStoreProperties.restore();
+ });
+
+ it("KERBEROS service absent", function() {
+ this.mockStackService.returns([]);
+ expect(controller.loadStep()).to.be.false;
+ });
+
+ it("configs not loaded", function() {
+ controller.set('isConfigsLoaded', false);
+ expect(controller.loadStep()).to.be.false;
+ });
+
+ it("clearStep should be called", function() {
+ controller.loadStep();
+ expect(controller.clearStep.calledOnce).to.be.true;
+ });
+
+ it("App.config.setPreDefinedServiceConfigs should be called", function() {
+ controller.loadStep();
+ expect(App.config.setPreDefinedServiceConfigs.calledOnce).to.be.true;
+ });
+
+ it("getKerberosConfigs should be called", function() {
+ controller.set('content.serviceConfigProperties', null);
+ controller.loadStep();
+ expect(controller.getKerberosConfigs.calledOnce).to.be.true;
+ });
+
+ it("filterConfigs should be called", function() {
+ controller.loadStep();
+ expect(controller.filterConfigs.calledOnce).to.be.true;
+ });
+
+ it("initializeKDCStoreProperties should be called", function() {
+ controller.set('wizardController.skipClientInstall', false);
+ controller.loadStep();
+ expect(controller.initializeKDCStoreProperties.calledOnce).to.be.true;
+ });
+
+ it("applyServicesConfigs should be called", function() {
+ controller.loadStep();
+ expect(controller.applyServicesConfigs.calledOnce).to.be.true;
+ });
+
+ it("updateKDCStoreProperties should be called", function() {
+ controller.set('wizardController.skipClientInstall', false);
+ controller.loadStep();
+ expect(controller.updateKDCStoreProperties.calledOnce).to.be.true;
+ });
+ });
+
+ describe("#getKerberosConfigs()", function () {
+
+ beforeEach(function() {
+ this.mock = sinon.stub(App.configsCollection, 'getAll');
+ sinon.stub(App.config, 'getConfigTagFromFileName').returns('t1');
+ sinon.stub(App.config, 'get').returns([
+ Em.Object.create({
+ serviceName: 'KERBEROS',
+ configTypes: {
+ 't1': {}
+ }
+ })
+ ]);
+ });
+
+ afterEach(function() {
+ this.mock .restore();
+ App.config.getConfigTagFromFileName.restore();
+ App.config.get.restore();
+ });
+
+ it("fileName not specified", function() {
+ this.mock.returns([
+ {
+ serviceName: 'S1'
+ }
+ ]);
+ expect(controller.getKerberosConfigs()).to.be.empty;
+ });
+
+ it("fileName not specified", function() {
+ this.mock.returns([
+ {
+ serviceName: 'KERBEROS'
+ }
+ ]);
+ expect(controller.getKerberosConfigs()).to.be.eql([
+ {
+ serviceName: 'KERBEROS'
+ }
+ ]);
+ });
+
+ it("incorrect service", function() {
+ this.mock.returns([
+ {
+ fileName: 'f1',
+ serviceName: 'S1'
+ }
+ ]);
+ expect(controller.getKerberosConfigs()).to.be.eql([
+ {
+ fileName: 'f1',
+ serviceName: 'S1'
+ }
+ ]);
+ });
+
+ it("fileName and service correct", function() {
+ this.mock.returns([
+ {
+ fileName: 'f1',
+ serviceName: 'KERBEROS'
+ }
+ ]);
+ expect(controller.getKerberosConfigs()).to.be.eql([
+ {
+ fileName: 'f1',
+ serviceName: 'KERBEROS'
+ }
+ ]);
+ });
+ });
+
+ describe("#filterConfigs()", function () {
+ var configs = [
+ Em.Object.create({
+ serviceName: 'KERBEROS',
+ isVisible: false
+ }),
+ Em.Object.create({
+ serviceName: 'S1',
+ isVisible: false
+ })
+ ];
+
+ beforeEach(function() {
+ controller.set('controllers', {
+ kerberosWizardController: Em.Object.create({
+ skipClientInstall: false,
+ overrideVisibility: Em.K
+ })
+ });
+ controller.set('content', Em.Object.create({
+ kerberosOption: null
+ }));
+ sinon.stub(controller.get('controllers.kerberosWizardController'), 'overrideVisibility');
+ sinon.stub(controller, 'setKDCTypeProperty');
+ sinon.stub(controller, 'setConfigVisibility');
+ });
+
+ afterEach(function() {
+ controller.setKDCTypeProperty.restore();
+ controller.setConfigVisibility.restore();
+ controller.get('controllers.kerberosWizardController').overrideVisibility.restore();
+ });
+
+ it("KERBEROS config should be visible", function() {
+ controller.filterConfigs(configs);
+ expect(configs.mapProperty('isVisible')).to.be.eql([true, false]);
+ });
+
+ it("setKDCTypeProperty should be called", function() {
+ controller.filterConfigs(configs);
+ expect(controller.setKDCTypeProperty.calledOnce).to.be.true;
+ });
+
+ it("setConfigVisibility should not be called", function() {
+ controller.set('content.kerberosOption', Em.I18n.t('admin.kerberos.wizard.step1.option.manual'));
+ controller.filterConfigs(configs);
+ expect(controller.setConfigVisibility.called).to.be.false;
+ });
+
+ it("overrideVisibility should be called", function() {
+ controller.set('content.kerberosOption', Em.I18n.t('admin.kerberos.wizard.step1.option.manual'));
+ controller.set('controllers.kerberosWizardController.skipClientInstall', true);
+ controller.filterConfigs(configs);
+ expect(controller.get('controllers.kerberosWizardController').overrideVisibility.calledOnce).to.be.true;
+ });
+
+ it("overrideVisibility should be called", function() {
+ configs = [{
+ name: 'manage_identities'
+ }];
+ controller.filterConfigs(configs);
+ expect(configs[0].isVisible).to.be.false;
+ expect(configs[0].value).to.be.equal('true');
+ });
+
+ it("setConfigVisibility should be called", function() {
+ controller.filterConfigs(configs);
+ expect(controller.setConfigVisibility.calledThrice).to.be.true;
+ });
+ });
+
+ describe("#setConfigVisibility()", function () {
+
+ it("ad type configs", function() {
+ var configs = [{name: 'ldap_url'}];
+ controller.setConfigVisibility('ad', configs, Em.I18n.t('admin.kerberos.wizard.step1.option.ad'));
+ expect(configs[0].isVisible).to.be.true;
+ });
+
+ it("mit type configs", function() {
+ var configs = [{name: 'kdc_create_attributes'}];
+ controller.setConfigVisibility('mit', configs, Em.I18n.t('admin.kerberos.wizard.step1.option.kdc'));
+ expect(configs[0].isVisible).to.be.true;
+ });
+
+ it("ipa type configs", function() {
+ var configs = [{name: 'group'}];
+ controller.setConfigVisibility('ipa', configs, Em.I18n.t('admin.kerberos.wizard.step1.option.ipa'));
+ expect(configs[0].isVisible).to.be.true;
+ });
+ });
+
+ describe("#submit()", function () {
+
+ beforeEach(function() {
+ sinon.stub(controller.get('wizardController'), 'deleteKerberosService').returns({
+ always: Em.clb
+ });
+ sinon.stub(controller, 'configureKerberos');
+ controller.reopen({
+ isSubmitDisabled: false
+ });
+ });
+
+ afterEach(function() {
+ controller.get('wizardController').deleteKerberosService.restore();
+ controller.configureKerberos.restore();
+ });
+
+ it("deleteKerberosService should not be called", function() {
+ controller.set('isSubmitDisabled', true);
+ expect(controller.submit()).to.be.false;
+ expect(controller.get('wizardController').deleteKerberosService.called).to.be.false;
+ });
+
+ it("deleteKerberosService should be called", function() {
+ controller.submit();
+ expect(controller.get('wizardController').deleteKerberosService.called).to.be.true;
+ });
+
+ it("configureKerberos should be called", function() {
+ controller.submit();
+ expect(controller.configureKerberos.calledOnce).to.be.true;
+ });
+ });
+
+ describe("#configureKerberos()", function () {
+ var mock = Em.Object.create({
+ createKerberosResources: Em.K
+ });
+
+ beforeEach(function() {
+ sinon.stub(App.router, 'get').returns(mock);
+ sinon.stub(controller, 'createConfigurations').returns({
+ done: Em.clb
+ });
+ sinon.stub(controller, 'createKerberosAdminSession').returns({
+ done: Em.clb
+ });
+ sinon.stub(App.router, 'send');
+ sinon.stub(mock, 'createKerberosResources');
+ });
+
+ afterEach(function() {
+ App.router.get.restore();
+ controller.createConfigurations.restore();
+ controller.createKerberosAdminSession.restore();
+ App.router.send.restore();
+ mock.createKerberosResources.restore();
+ });
+
+ it("createConfigurations should be called", function() {
+ mock.set('skipClientInstall', true);
+ controller.configureKerberos();
+ expect(controller.createConfigurations.calledOnce).to.be.true;
+ });
+
+ it("createKerberosAdminSession should be called", function() {
+ mock.set('skipClientInstall', true);
+ controller.configureKerberos();
+ expect(controller.createKerberosAdminSession.calledOnce).to.be.true;
+ });
+
+ it("App.router.send should be called", function() {
+ mock.set('skipClientInstall', true);
+ controller.configureKerberos();
+ expect(App.router.send.calledWith('next')).to.be.true;
+ });
+
+ it("App.router.send should be called", function() {
+ mock.set('skipClientInstall', false);
+ controller.configureKerberos();
+ expect(mock.createKerberosResources.calledOnce).to.be.true;
+ });
+ });
+
+ describe("#createConfigurations()", function () {
+
+ beforeEach(function() {
+ sinon.stub(App.StackService, 'find').returns([
+ Em.Object.create({
+ serviceName: 'KERBEROS',
+ configTypes: {
+ t1: {},
+ t3: {}
+ },
+ configTypesRendered: {
+ t1: {},
+ t2: {}
+ }
+ })
+ ]);
+ sinon.stub(controller, 'createKerberosSiteObj').returns({
+ type: 't1'
+ });
+ });
+
+ afterEach(function() {
+ App.StackService.find.restore();
+ controller.createKerberosSiteObj.restore();
+ });
+
+ it("App.ajax.send should be called", function() {
+ controller.createConfigurations();
+ var args = testHelpers.findAjaxRequest('name', 'common.across.services.configurations');
+ expect(args[0]).to.be.eql({
+ name: 'common.across.services.configurations',
+ sender: controller,
+ data: {
+ data: '[' + JSON.stringify({
+ Clusters: {
+ desired_config: [
+ {
+ type: 't1',
+ service_config_version_note: Em.I18n.t('admin.kerberos.wizard.configuration.note')
+ }
+ ]
+ }
+ }).toString() + ']'
+ }
+ });
+ });
+ });
+
+ describe("#createKerberosSiteObj()", function () {
+
+ beforeEach(function() {
+ sinon.stub(controller, 'tweakKdcTypeValue');
+ sinon.stub(controller, 'tweakManualKdcProperties');
+ sinon.stub(controller, 'tweakIpaKdcProperties');
+ sinon.stub(App.config, 'trimProperty', function(arg) {
+ return arg;
+ });
+ controller.set('stepConfigs', [Em.Object.create({
+ configs: []
+ })]);
+ });
+
+ afterEach(function() {
+ controller.tweakKdcTypeValue.restore();
+ controller.tweakManualKdcProperties.restore();
+ controller.tweakIpaKdcProperties.restore();
+ App.config.trimProperty.restore();
+ });
+
+ it("tweakKdcTypeValue should be called", function() {
+ controller.createKerberosSiteObj();
+ expect(controller.tweakKdcTypeValue.calledWith({})).to.be.true;
+ });
+
+ it("tweakManualKdcProperties should be called", function() {
+ controller.createKerberosSiteObj();
+ expect(controller.tweakManualKdcProperties.calledWith({})).to.be.true;
+ });
+
+ it("tweakIpaKdcProperties should be called", function() {
+ controller.createKerberosSiteObj();
+ expect(controller.tweakIpaKdcProperties.calledWith({})).to.be.true;
+ });
+
+ it("properties should be empty", function() {
+ controller.set('stepConfigs', [Em.Object.create({
+ configs: [{
+ isRequiredByAgent: false,
+ filename: 'site.xml'
+ }]
+ })]);
+ expect(controller.createKerberosSiteObj('site', 'tag')).to.be.eql({
+ "type": 'site',
+ "tag": 'tag',
+ "properties": {}
+ });
+ });
+
+ it("properties should contain kdc_hosts", function() {
+ controller.set('stepConfigs', [Em.Object.create({
+ configs: [{
+ name: 'kdc_hosts',
+ value: 'v1',
+ filename: 'site.xml'
+ }]
+ })]);
+ expect(controller.createKerberosSiteObj('site', 'tag')).to.be.eql({
+ "type": 'site',
+ "tag": 'tag',
+ "properties": {
+ 'kdc_hosts': {
+ displayType: 'host',
+ value: 'v1'
+ }
+ }
+ });
+ });
+
+ it("properties should contain n1", function() {
+ controller.set('stepConfigs', [Em.Object.create({
+ configs: [{
+ name: 'n1',
+ value: 'v1',
+ filename: 'site.xml'
+ }]
+ })]);
+ expect(controller.createKerberosSiteObj('site', 'tag')).to.be.eql({
+ "type": 'site',
+ "tag": 'tag',
+ "properties": {
+ 'n1': {
+ name: 'n1',
+ value: 'v1',
+ filename: 'site.xml'
+ }
+ }
+ });
+ });
+ });
+
+ describe("#tweakKdcTypeValue()", function () {
+
+ beforeEach(function() {
+ sinon.stub(App.router, 'get').returns({
+ 'k1': 'p1'
+ });
+ });
+
+ afterEach(function() {
+ App.router.get.restore();
+ });
+
+ it("kdc_type should be p2", function() {
+ var properties = {'kdc_type': 'p2'};
+ controller.tweakKdcTypeValue(properties);
+ expect(properties['kdc_type']).to.be.equal('p2')
+ });
+
+ it("kdc_type should be k1", function() {
+ var properties = {'kdc_type': 'p1'};
+ controller.tweakKdcTypeValue(properties);
+ expect(properties['kdc_type']).to.be.equal('k1')
+ });
+ });
+
+ describe("#tweakManualKdcProperties()", function () {
+
+ it("properties shouldn't be changed", function() {
+ var properties = {
+ 'kdc_type': 'p1'
+ };
+ controller.set('controllers.kerberosWizardController', Em.Object.create({
+ skipClientInstall: false
+ }));
+ controller.tweakManualKdcProperties(properties);
+ expect(properties).to.be.eql({
+ 'kdc_type': 'p1'
+ });
+ });
+
+ it("kdc_type is none", function() {
+ var properties = {
+ 'kdc_type': 'none',
+ 'manage_identities': 'true'
+ };
+ controller.set('controllers.kerberosWizardController', Em.Object.create({
+ skipClientInstall: false
+ }));
+ controller.tweakManualKdcProperties(properties);
+ expect(properties).to.be.eql({
+ 'kdc_type': 'none',
+ 'manage_identities': 'false'
+ });
+ });
+
+ it("skipClientInstall is true", function() {
+ var properties = {
+ 'kdc_type': 'p1',
+ 'manage_identities': 'true',
+ 'install_packages': 'true',
+ 'manage_krb5_conf': 'true'
+ };
+ controller.set('controllers.kerberosWizardController', Em.Object.create({
+ skipClientInstall: true
+ }));
+ controller.tweakManualKdcProperties(properties);
+ expect(properties).to.be.eql({
+ 'kdc_type': 'p1',
+ 'manage_identities': 'false',
+ 'install_packages': 'false',
+ 'manage_krb5_conf': 'false'
+ });
+ });
+ });
+
+ describe("#tweakIpaKdcProperties()", function () {
+
+ beforeEach(function() {
+ sinon.stub(App.router, 'get').returns({'ipa': 'p1'});
+ });
+
+ afterEach(function() {
+ App.router.get.restore();
+ });
+
+ it("properties should be empty, kdc_type undefined", function() {
+ var properties = {};
+ controller.tweakIpaKdcProperties(properties);
+ expect(properties).to.be.empty;
+ });
+
+ it("properties should not be empty", function() {
+ var properties = {
+ kdc_type: 'p1'
+ };
+ controller.set('content.kerberosOption', 'p2');
+ controller.tweakIpaKdcProperties(properties);
+ expect(properties).to.be.eql({
+ kdc_type: 'p1'
+ });
+ });
+
+ it("properties should set config values", function() {
+ var properties = {
+ 'kdc_type': 'p1',
+ 'install_packages': 'true',
+ 'manage_krb5_conf': 'true'
+ };
+ controller.set('content.kerberosOption', 'p1');
+ controller.tweakIpaKdcProperties(properties);
+ expect(properties).to.be.eql({
+ 'kdc_type': 'p1',
+ 'install_packages': 'false',
+ 'manage_krb5_conf': 'false'
+ });
+ });
+ });
+
+ describe("#createKerberosAdminSession()", function () {
+
+ beforeEach(function() {
+ sinon.stub(controller, 'createKDCCredentials');
+ });
+
+ afterEach(function() {
+ controller.createKDCCredentials.restore();
+ });
+
+ it("createKDCCredentials should be called", function() {
+ controller.set('wizardController.skipClientInstall', false);
+ controller.createKerberosAdminSession([]);
+ expect(controller.createKDCCredentials.calledWith([])).to.be.true;
+ });
+
+ it("createKDCCredentials should be called, with non-empty configs", function() {
+ controller.set('stepConfigs', [Em.Object.create({configs: [{}]})]);
+ controller.set('wizardController.skipClientInstall', false);
+ controller.createKerberosAdminSession();
+ expect(controller.createKDCCredentials.calledWith([{}])).to.be.true;
+ });
+
+ it("App.ajax.send should be called", function() {
+ App.set('clusterName', 'c1');
+ var configs = [
+ {
+ name: 'admin_principal',
+ value: 'v1'
+ },
+ {
+ name: 'admin_password',
+ value: 'v2'
+ }
+ ];
+ controller.set('wizardController.skipClientInstall', true);
+
+ controller.createKerberosAdminSession(configs);
+ var args = testHelpers.findAjaxRequest('name', 'common.cluster.update');
+ expect(args[0]).to.be.eql({
+ name: 'common.cluster.update',
+ sender: controller,
+ data: {
+ clusterName: 'c1',
+ data: [{
+ session_attributes: {
+ kerberos_admin: {principal: 'v1', password: 'v2'}
+ }
+ }]
+ }
+ });
+ });
+ });
+
+ describe("#showConnectionInProgressPopup()", function () {
+
+ beforeEach(function() {
+ sinon.stub(App, 'showConfirmationPopup');
+ });
+
+ afterEach(function() {
+ App.showConfirmationPopup.restore();
+ });
+
+ it("App.showConfirmationPopup should be called", function() {
+ var primary = Em.K;
+ controller.showConnectionInProgressPopup(primary);
+ expect(App.showConfirmationPopup.calledWith(primary, Em.I18n.t('services.service.config.connection.exitPopup.msg'), null, null, Em.I18n.t('common.exitAnyway'))).to.be.true;
+ });
+ });
+
+
+ describe("#setKDCTypeProperty()", function () {
+
+ beforeEach(function() {
+ sinon.stub(App.router, 'get').returns({
+ 'k1': 'p1'
+ });
+ });
+
+ afterEach(function() {
+ App.router.get.restore();
+ });
+
+ it("kdcTypeProperty should be set", function() {
+ var configs = [{
+ filename: 'kerberos-env.xml',
+ name: 'kdc_type'
+ }];
+ controller.set('content.kerberosOption', 'p1');
+ controller.setKDCTypeProperty(configs);
+ expect(configs[0].value).to.be.equal('p1');
+ });
+ });
});
http://git-wip-us.apache.org/repos/asf/ambari/blob/5c782dd8/ambari-web/test/controllers/main/admin/kerberos/step3_controller_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/main/admin/kerberos/step3_controller_test.js b/ambari-web/test/controllers/main/admin/kerberos/step3_controller_test.js
index cd149f1..875e0bc 100644
--- a/ambari-web/test/controllers/main/admin/kerberos/step3_controller_test.js
+++ b/ambari-web/test/controllers/main/admin/kerberos/step3_controller_test.js
@@ -17,11 +17,16 @@
*/
var App = require('app');
+var testHelpers = require('test/helpers');
describe('App.KerberosWizardStep3Controller', function() {
+ var controller;
+
+ beforeEach(function() {
+ controller = App.KerberosWizardStep3Controller.create({});
+ });
describe('#onTestKerberosError', function() {
- var controller = App.KerberosWizardStep3Controller.create({});
beforeEach(function(){
sinon.stub(App.ajax, 'defaultErrorHandler', Em.K);
@@ -40,4 +45,187 @@ describe('App.KerberosWizardStep3Controller', function() {
});
});
+ describe("#loadStep()", function () {
+
+ beforeEach(function() {
+ sinon.stub(controller, 'enableDisablePreviousSteps');
+ });
+
+ afterEach(function() {
+ controller.enableDisablePreviousSteps.restore();
+ });
+
+ it("enableDisablePreviousSteps should be called", function() {
+ controller.loadStep();
+ expect(controller.enableDisablePreviousSteps.calledOnce).to.be.true;
+ });
+ });
+
+ describe("#installKerberos()", function () {
+
+ beforeEach(function() {
+ this.mock = sinon.stub(controller, 'getKerberosClientState');
+ sinon.stub(controller, 'updateComponent');
+ });
+
+ afterEach(function() {
+ this.mock.restore();
+ controller.updateComponent.restore();
+ });
+
+ it("not INIT state", function() {
+ this.mock.returns({
+ done: function(callback) {
+ callback({ServiceComponentInfo: {
+ state: ""
+ }});
+ }
+ });
+ App.set('allHostNames', ['host1']);
+ controller.installKerberos();
+ expect(controller.updateComponent.calledWith('KERBEROS_CLIENT', ['host1'], "KERBEROS", "Install")).to.be.true;
+ });
+
+ it("INIT state", function() {
+ this.mock.returns({
+ done: function(callback) {
+ callback({ServiceComponentInfo: {
+ state: "INIT"
+ }});
+ }
+ });
+ controller.installKerberos();
+ var args = testHelpers.findAjaxRequest('name', 'common.services.update');
+ expect(args[0]).to.be.eql({
+ name: 'common.services.update',
+ sender: controller,
+ data: {
+ context: Em.I18n.t('requestInfo.kerberosService'),
+ ServiceInfo: {"state": "INSTALLED"},
+ urlParams: "ServiceInfo/state=INSTALLED&ServiceInfo/service_name=KERBEROS"
+ },
+ success: 'startPolling',
+ error: 'onTaskError'
+ });
+ });
+ });
+
+ describe("#getKerberosClientState()", function () {
+
+ it("App.ajax.send should be called", function() {
+ controller.setProperties({
+ serviceName: 'S1',
+ componentName: 'C1'
+ });
+ controller.getKerberosClientState();
+ var args = testHelpers.findAjaxRequest('name', 'common.service_component.info');
+ expect(args[0]).to.be.eql({
+ name: 'common.service_component.info',
+ sender: controller,
+ data: {
+ serviceName: 'S1',
+ componentName: 'C1',
+ urlParams: "fields=ServiceComponentInfo/state"
+ }
+ });
+ });
+ });
+
+ describe("#testKerberos()", function () {
+
+ it("App.ajax.send should be called", function() {
+ controller.testKerberos();
+ var args = testHelpers.findAjaxRequest('name', 'service.item.smoke');
+ expect(args[0]).to.exists;
+ });
+ });
+
+ describe("#onTestKerberosError()", function () {
+
+ beforeEach(function() {
+ sinon.stub(App.ajax, 'defaultErrorHandler');
+ sinon.stub(controller, 'onTaskError');
+ controller.onTestKerberosError({status: 's1'}, {}, "error", {type: 't1', url: 'u1'});
+ });
+
+ afterEach(function() {
+ App.ajax.defaultErrorHandler.restore();
+ controller.onTaskError.restore();
+ });
+
+ it("App.ajax.defaultErrorHandler should be called", function() {
+ expect(App.ajax.defaultErrorHandler.calledWith({status: 's1'}, 'u1', 't1', 's1')).to.be.true;
+ });
+
+ it("onTaskError should be called", function() {
+ expect(controller.onTaskError.calledWith({status: 's1'}, {}, "error", {type: 't1', url: 'u1'})).to.be.true;
+ });
+ });
+
+ describe("#enableDisablePreviousSteps()", function () {
+ var mock = {
+ setStepsEnable: Em.K,
+ setLowerStepsDisable: Em.K
+ };
+
+ beforeEach(function() {
+ sinon.stub(App.router, 'get').returns(mock);
+ sinon.stub(mock, 'setStepsEnable');
+ sinon.stub(mock, 'setLowerStepsDisable');
+ });
+
+ afterEach(function() {
+ App.router.get.restore();
+ mock.setStepsEnable.restore();
+ mock.setLowerStepsDisable.restore();
+ });
+
+ it("setLowerStepsDisable should be called", function() {
+ controller.set('tasks', [{
+ status: 'COMPLETED'
+ }]);
+ controller.enableDisablePreviousSteps();
+ expect(mock.setLowerStepsDisable.calledWith(3)).to.be.true;
+ });
+
+ it("setStepsEnable should be called", function() {
+ controller.set('tasks', [{
+ status: 'FAILED'
+ }]);
+ controller.enableDisablePreviousSteps();
+ expect(mock.setStepsEnable.called).to.be.true;
+ });
+ });
+
+ describe("#ignoreAndProceed()", function () {
+
+ it("isSubmitDisabled should be true", function() {
+ controller.setProperties({
+ showIgnore: true,
+ ignore: false
+ });
+ controller.ignoreAndProceed();
+ expect(controller.get('isSubmitDisabled')).to.be.true;
+ });
+
+ it("isSubmitDisabled should be false", function() {
+ controller.setProperties({
+ showIgnore: true,
+ ignore: true
+ });
+ controller.ignoreAndProceed();
+ expect(controller.get('isSubmitDisabled')).to.be.true;
+ });
+
+ it("isSubmitDisabled should not be changed", function() {
+ controller.setProperties({
+ showIgnore: false,
+ ignore: true,
+ isSubmitDisabled: false
+ });
+ controller.ignoreAndProceed();
+ expect(controller.get('isSubmitDisabled')).to.be.false;
+ });
+
+ });
});
\ No newline at end of file