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 2014/05/06 16:33:42 UTC
git commit: AMBARI-5682 UI unit tests for Add Security controller.
(atkach)
Repository: ambari
Updated Branches:
refs/heads/trunk f475fc0b8 -> 06e2aeb53
AMBARI-5682 UI unit tests for Add Security controller. (atkach)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/06e2aeb5
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/06e2aeb5
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/06e2aeb5
Branch: refs/heads/trunk
Commit: 06e2aeb53762d30a358a0d04f51c086a4080b293
Parents: f475fc0
Author: atkach <at...@hortonworks.com>
Authored: Tue May 6 17:30:21 2014 +0300
Committer: atkach <at...@hortonworks.com>
Committed: Tue May 6 17:30:21 2014 +0300
----------------------------------------------------------------------
ambari-web/app/assets/test/tests.js | 1 +
.../security/add/addSecurity_controller.js | 98 ++++---
.../main/admin/security/add/step1.js | 8 +-
.../security/add/addSecurity_controller_test.js | 273 ++++++++++++++++++-
.../main/admin/security/add/step1_test.js | 59 ++++
5 files changed, 378 insertions(+), 61 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/06e2aeb5/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 6c8c0b7..07eb8a5 100644
--- a/ambari-web/app/assets/test/tests.js
+++ b/ambari-web/app/assets/test/tests.js
@@ -33,6 +33,7 @@ require('test/controllers/main/admin/security_test');
require('test/controllers/main/admin/security/disable_test');
require('test/controllers/main/admin/security/security_progress_controller_test');
require('test/controllers/main/admin/security/add/addSecurity_controller_test');
+require('test/controllers/main/admin/security/add/step1_test');
require('test/controllers/main/admin/security/add/step2_test');
require('test/controllers/main/admin/security/add/step3_test');
require('test/controllers/main/admin/security/add/step4_test');
http://git-wip-us.apache.org/repos/asf/ambari/blob/06e2aeb5/ambari-web/app/controllers/main/admin/security/add/addSecurity_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/admin/security/add/addSecurity_controller.js b/ambari-web/app/controllers/main/admin/security/add/addSecurity_controller.js
index e117eca..b7f5cb7 100644
--- a/ambari-web/app/controllers/main/admin/security/add/addSecurity_controller.js
+++ b/ambari-web/app/controllers/main/admin/security/add/addSecurity_controller.js
@@ -31,11 +31,23 @@ App.AddSecurityController = App.WizardController.extend({
controllerName: 'addSecurityController'
}),
- installedServices: function() {
+ /**
+ * installed services on cluster
+ */
+ installedServices: function () {
return App.Service.find().mapProperty('serviceName');
}.property(),
/**
+ * services with security configurations
+ */
+ secureServices: function () {
+ return (App.get('isHadoop2Stack')) ?
+ $.extend(true, [], require('data/HDP2/secure_configs')) :
+ $.extend(true, [], require('data/secure_configs'));
+ }.property('App.isHadoop2Stack'),
+
+ /**
* Loads all prior steps on refresh
*/
loadAllPriorSteps: function () {
@@ -47,29 +59,17 @@ App.AddSecurityController = App.WizardController.extend({
this.loadServiceConfigs();
case '1':
this.loadServices();
- this.loadNnHastatus();
- }
- },
-
- clearServices: function () {
- if (this.get('content.services')) {
- this.get('content.services').clear();
+ this.loadNnHaStatus();
}
},
-
/**
- * Loads all installed services
+ * Load installed services, which match secure services, to content
*/
loadServices: function () {
- this.clearServices();
- var secureServices;
- if(App.get('isHadoop2Stack')) {
- secureServices = $.extend(true, [], require('data/HDP2/secure_configs'));
- } else {
- secureServices = $.extend(true, [], require('data/secure_configs'));
- }
-
+ var secureServices = this.get('secureServices');
var installedServices = this.get('installedServices');
+
+ this.get('content.services').clear();
//General (only non service tab) tab is always displayed
this.get('content.services').push(secureServices.findProperty('serviceName', 'GENERAL'));
installedServices.forEach(function (_service) {
@@ -78,46 +78,35 @@ App.AddSecurityController = App.WizardController.extend({
this.get('content.services').push(secureService);
}
}, this);
-
},
-
- loadNnHastatus: function() {
- var isNnHa = App.db.getIsNameNodeHa();
- this.set('content.isNnHa', isNnHa);
+ /**
+ * identify whether NameNode in high availability mode
+ */
+ loadNnHaStatus: function () {
+ this.set('content.isNnHa', App.db.getIsNameNodeHa());
},
+ /**
+ * save service config properties to localStorage
+ * @param stepController
+ */
saveServiceConfigProperties: function (stepController) {
var serviceConfigProperties = [];
stepController.get('stepConfigs').forEach(function (_content) {
_content.get('configs').forEach(function (_configProperties) {
- _configProperties.set('value', App.config.trimProperty(_configProperties,true));
- var overrides = _configProperties.get('overrides');
- var overridesArray = [];
- if(overrides!=null){
- overrides.forEach(function(override){
- var overrideEntry = {
- value: override.get('value'),
- hosts: []
- };
- override.get('selectedHostOptions').forEach(function(host){
- overrideEntry.hosts.push(host);
- });
- overridesArray.push(overrideEntry);
- });
- }
- overridesArray = (overridesArray.length) ? overridesArray : null;
+ _configProperties.set('value', App.config.trimProperty(_configProperties, true));
var configProperty = {
id: _configProperties.get('id'),
name: _configProperties.get('name'),
value: _configProperties.get('value'),
defaultValue: _configProperties.get('defaultValue'),
serviceName: _configProperties.get('serviceName'),
- domain: _configProperties.get('domain'),
+ domain: _configProperties.get('domain'),
filename: _configProperties.get('filename'),
unit: _configProperties.get('unit'),
components: _configProperties.get('components'),
component: _configProperties.get('component'),
- overrides: overridesArray
+ overrides: this.getConfigOverrides(_configProperties)
};
serviceConfigProperties.push(configProperty);
}, this);
@@ -127,12 +116,33 @@ App.AddSecurityController = App.WizardController.extend({
},
/**
- * Loads all service config properties
+ * get overrides of config
+ * @param _configProperties
+ * @return {Array}
*/
+ getConfigOverrides: function (_configProperties) {
+ var overrides = _configProperties.get('overrides');
+ var overridesArray = [];
+ if (Array.isArray(overrides)) {
+ overrides.forEach(function (override) {
+ var overrideEntry = {
+ value: override.get('value'),
+ hosts: []
+ };
+ override.get('selectedHostOptions').forEach(function (host) {
+ overrideEntry.hosts.push(host);
+ });
+ overridesArray.push(overrideEntry);
+ });
+ }
+ return (overridesArray.length > 0) ? overridesArray : null;
+ },
+ /**
+ * Load service config properties from localStorage
+ */
loadServiceConfigs: function () {
- var serviceConfigProperties = App.db.getSecureConfigProperties();
- this.set('content.serviceConfigProperties', serviceConfigProperties);
+ this.set('content.serviceConfigProperties', App.db.getSecureConfigProperties());
}
});
http://git-wip-us.apache.org/repos/asf/ambari/blob/06e2aeb5/ambari-web/app/controllers/main/admin/security/add/step1.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/admin/security/add/step1.js b/ambari-web/app/controllers/main/admin/security/add/step1.js
index 28af926..e6c74eb 100644
--- a/ambari-web/app/controllers/main/admin/security/add/step1.js
+++ b/ambari-web/app/controllers/main/admin/security/add/step1.js
@@ -20,8 +20,12 @@ var App = require('app');
App.MainAdminSecurityAddStep1Controller = Em.Controller.extend({
name: 'mainAdminSecurityAddStep1Controller',
+ /**
+ * identify whether ATS(Application Timeline Server) is installed
+ * @return {Boolean}
+ */
isATSInstalled: function() {
- return this.get('content.services').findProperty('serviceName', 'YARN') &&
- App.Service.find('YARN').get('hostComponents').someProperty('componentName', 'APP_TIMELINE_SERVER')
+ return this.get('content.services').someProperty('serviceName', 'YARN') &&
+ App.Service.find('YARN').get('hostComponents').someProperty('componentName', 'APP_TIMELINE_SERVER');
}
});
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/06e2aeb5/ambari-web/test/controllers/main/admin/security/add/addSecurity_controller_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/main/admin/security/add/addSecurity_controller_test.js b/ambari-web/test/controllers/main/admin/security/add/addSecurity_controller_test.js
index e2c5ff9..6fab262 100644
--- a/ambari-web/test/controllers/main/admin/security/add/addSecurity_controller_test.js
+++ b/ambari-web/test/controllers/main/admin/security/add/addSecurity_controller_test.js
@@ -18,36 +18,279 @@
var App = require('app');
-require('models/host');
require('mixins/common/localStorage');
require('controllers/wizard');
require('controllers/main/admin/security/add/addSecurity_controller');
-require('models/host_component');
require('models/cluster');
require('models/service');
describe('App.AddSecurityController', function () {
- var addSecurityController = App.AddSecurityController.create();
+ var controller = App.AddSecurityController.create({
+ currentStep: null
+ });
+
+ describe('#installedServices', function () {
+
+ afterEach(function () {
+ App.Service.find.restore();
+ });
+
+ it('No installed services', function () {
+ sinon.stub(App.Service, 'find', function () {
+ return [];
+ });
+ expect(controller.get('installedServices')).to.eql([]);
+ });
+ it('One service installed', function () {
+ sinon.stub(App.Service, 'find', function () {
+ return [Em.Object.create({serviceName: 'HDFS'})];
+ });
+ Em.propertyDidChange(controller, 'installedServices');
+ expect(controller.get('installedServices')).to.eql(['HDFS']);
+ });
+ });
+
+ describe('#secureServices', function () {
+
+ afterEach(function () {
+ App.get.restore();
+ });
- describe('#clearServices', function() {
- addSecurityController.set('content.services', [{},{},{}]);
- it('clear all services', function() {
- addSecurityController.clearServices();
- expect(addSecurityController.get('content.services.length')).to.equal(0);
+ it('App.isHadoop2Stack = false', function () {
+ var result = [
+ "GENERAL",
+ "HDFS",
+ "MAPREDUCE",
+ "HIVE",
+ "WEBHCAT",
+ "HBASE",
+ "ZOOKEEPER",
+ "OOZIE",
+ "NAGIOS"
+ ];
+ sinon.stub(App, 'get', function () {
+ return false;
+ });
+ expect(controller.get('secureServices').mapProperty('serviceName')).to.eql(result);
+ });
+ it('App.isHadoop2Stack = true', function () {
+ var result = [
+ "GENERAL",
+ "HDFS",
+ "MAPREDUCE2",
+ "YARN",
+ "HIVE",
+ "WEBHCAT",
+ "HBASE",
+ "ZOOKEEPER",
+ "OOZIE",
+ "NAGIOS",
+ "STORM",
+ "FALCON"
+ ];
+ sinon.stub(App, 'get', function () {
+ return true;
+ });
+ Em.propertyDidChange(App, 'isHadoop2Stack');
+ expect(controller.get('secureServices').mapProperty('serviceName')).to.eql(result);
});
});
- describe('#loadServices', function() {
+ describe('#loadAllPriorSteps()', function () {
- it('NAGIOS, HIVE and GENERAL (by default). FAKE not loaded', function() {
- var ASC = App.AddSecurityController.extend({
- installedServices: ['NAGIOS', 'HIVE', 'FAKE']
+ beforeEach(function () {
+ sinon.stub(controller, 'loadServiceConfigs', Em.K);
+ sinon.stub(controller, 'loadServices', Em.K);
+ sinon.stub(controller, 'loadNnHaStatus', Em.K);
+ });
+ afterEach(function () {
+ controller.loadServiceConfigs.restore();
+ controller.loadServices.restore();
+ controller.loadNnHaStatus.restore();
+ });
+
+ var commonSteps = ['4', '3', '2'];
+ commonSteps.forEach(function (step) {
+ it('Current step - ' + step, function () {
+ controller.set('currentStep', step);
+ controller.loadAllPriorSteps();
+ expect(controller.loadServiceConfigs.calledOnce).to.be.true;
+ expect(controller.loadServices.calledOnce).to.be.true;
+ expect(controller.loadNnHaStatus.calledOnce).to.be.true;
});
- var c = ASC.create();
- c.loadServices();
- expect(c.get('content.services.length')).to.equal(3);
+ });
+ it('Current step - 1', function () {
+ controller.set('currentStep', '1');
+ controller.loadAllPriorSteps();
+ expect(controller.loadServiceConfigs.called).to.be.false;
+ expect(controller.loadServices.calledOnce).to.be.true;
+ expect(controller.loadNnHaStatus.calledOnce).to.be.true;
+ });
+ });
+
+ describe('#loadServices()', function () {
+ it('No installed services', function () {
+ controller.reopen({
+ installedServices: [],
+ secureServices: [
+ {serviceName: 'GENERAL'}
+ ]
+ });
+ controller.loadServices();
+ expect(controller.get('content.services').mapProperty('serviceName')).to.eql(['GENERAL']);
+ });
+ it('Installed service does not match the secure one', function () {
+ controller.set('installedServices', ["HDFS"]);
+ controller.loadServices();
+ expect(controller.get('content.services').mapProperty('serviceName')).to.eql(['GENERAL']);
+ });
+ it('Installed service matches the secure one', function () {
+ controller.set('secureServices', [
+ {serviceName: 'GENERAL'},
+ {serviceName: 'HDFS'}
+ ]);
+ controller.loadServices();
+ expect(controller.get('content.services').mapProperty('serviceName')).to.eql(['GENERAL', 'HDFS']);
});
});
+ describe('#loadNnHaStatus()', function () {
+ afterEach(function () {
+ App.db.getIsNameNodeHa.restore();
+ });
+ it('NameNode HA is off', function () {
+ sinon.stub(App.db, 'getIsNameNodeHa', function () {
+ return false;
+ });
+ controller.loadNnHaStatus();
+ expect(controller.get('content.isNnHa')).to.be.false;
+ });
+ it('NameNode HA is on', function () {
+ sinon.stub(App.db, 'getIsNameNodeHa', function () {
+ return true;
+ });
+ controller.loadNnHaStatus();
+ expect(controller.get('content.isNnHa')).to.be.true;
+ });
+ });
+
+ describe('#loadServiceConfigs()', function () {
+ afterEach(function () {
+ App.db.getSecureConfigProperties.restore();
+ });
+ it('SecureConfigProperties is empty', function () {
+ sinon.stub(App.db, 'getSecureConfigProperties', function () {
+ return [];
+ });
+ controller.loadServiceConfigs();
+ expect(controller.get('content.serviceConfigProperties')).to.eql([]);
+ });
+ it('SecureConfigProperties has one config', function () {
+ sinon.stub(App.db, 'getSecureConfigProperties', function () {
+ return [{}];
+ });
+ controller.loadServiceConfigs();
+ expect(controller.get('content.serviceConfigProperties')).to.eql([{}]);
+ });
+ });
+
+ describe('#getConfigOverrides()', function () {
+ var testCases = [
+ {
+ title: 'overrides is null',
+ configProperty: Em.Object.create({overrides: null}),
+ result: null
+ },
+ {
+ title: 'overrides is empty',
+ configProperty: Em.Object.create({overrides: []}),
+ result: null
+ },
+ {
+ title: 'overrides has one override',
+ configProperty: Em.Object.create({
+ overrides: [
+ Em.Object.create({
+ value: 'value1',
+ selectedHostOptions: []
+ })
+ ]
+ }),
+ result: [{
+ value: 'value1',
+ hosts: []
+ }]
+ },
+ {
+ title: 'overrides has one override with hosts',
+ configProperty: Em.Object.create({
+ overrides: [
+ Em.Object.create({
+ value: 'value1',
+ selectedHostOptions: ['host1']
+ })
+ ]
+ }),
+ result: [{
+ value: 'value1',
+ hosts: ['host1']
+ }]
+ }
+ ];
+
+ testCases.forEach(function(test){
+ it(test.title, function () {
+ expect(controller.getConfigOverrides(test.configProperty)).to.eql(test.result);
+ });
+ });
+ });
+
+ describe('#saveServiceConfigProperties()', function () {
+ var testCases = [
+ {
+ title: 'stepConfigs is empty',
+ stepController: Em.Object.create({
+ stepConfigs: []
+ }),
+ result: []
+ },
+ {
+ title: 'No configs in service',
+ stepController: Em.Object.create({
+ stepConfigs: [
+ Em.Object.create({configs: []})
+ ]
+ }),
+ result: []
+ }
+ ];
+
+ testCases.forEach(function (test) {
+ it(test.title, function () {
+ sinon.stub(App.db, 'setSecureConfigProperties', Em.K);
+ controller.saveServiceConfigProperties(test.stepController);
+ expect(App.db.setSecureConfigProperties.calledWith(test.result)).to.be.true;
+ expect(controller.get('content.serviceConfigProperties')).to.eql(test.result);
+ App.db.setSecureConfigProperties.restore();
+ });
+ });
+ it('Service has config', function () {
+ var stepController = Em.Object.create({
+ stepConfigs: [
+ Em.Object.create({configs: [
+ Em.Object.create({
+ name: 'config1',
+ value: 'value1'
+ })
+ ]})
+ ]
+ });
+ sinon.stub(App.db, 'setSecureConfigProperties', Em.K);
+ controller.saveServiceConfigProperties(stepController);
+ expect(App.db.setSecureConfigProperties.calledOnce).to.be.true;
+ expect(controller.get('content.serviceConfigProperties').mapProperty('name')).to.eql(['config1']);
+ App.db.setSecureConfigProperties.restore();
+ });
+ });
});
http://git-wip-us.apache.org/repos/asf/ambari/blob/06e2aeb5/ambari-web/test/controllers/main/admin/security/add/step1_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/main/admin/security/add/step1_test.js b/ambari-web/test/controllers/main/admin/security/add/step1_test.js
new file mode 100644
index 0000000..7672e86
--- /dev/null
+++ b/ambari-web/test/controllers/main/admin/security/add/step1_test.js
@@ -0,0 +1,59 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+var App = require('app');
+
+require('controllers/main/admin/security/add/step1');
+require('models/service');
+
+describe('App.MainAdminSecurityAddStep1Controller', function () {
+
+ var controller = App.MainAdminSecurityAddStep1Controller.create({
+ content: {}
+ });
+
+ describe('#isATSInstalled()', function() {
+ it('content.services is empty', function() {
+ controller.set('content.services', []);
+ expect(controller.isATSInstalled()).to.be.false;
+ });
+ it('content.services does not contain YARN', function() {
+ controller.set('content.services', [{serviceName: 'HDFS'}]);
+ expect(controller.isATSInstalled()).to.be.false;
+ });
+ it('YARN does not have ATS', function() {
+ sinon.stub(App.Service, 'find', function(){
+ return Em.Object.create({hostComponents: []})
+ });
+ controller.set('content.services', [{serviceName: 'YARN'}]);
+ expect(controller.isATSInstalled()).to.be.false;
+ App.Service.find.restore();
+ });
+ it('YARN has ATS', function() {
+ sinon.stub(App.Service, 'find', function(){
+ return Em.Object.create({hostComponents: [{
+ componentName: 'APP_TIMELINE_SERVER'
+ }]})
+ });
+ controller.set('content.services', [{serviceName: 'YARN'}]);
+ expect(controller.isATSInstalled()).to.be.true;
+ App.Service.find.restore();
+ });
+ });
+});