Repository: ambari
Updated Branches:
  refs/heads/trunk 5c0e09ca9 -> a3be8c960


AMBARI-5471 UI unit tests for misc and security controllers. (atkach)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/a3be8c96
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/a3be8c96
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/a3be8c96

Branch: refs/heads/trunk
Commit: a3be8c9600cc8280feab3c75da27122a67dcf243
Parents: 5c0e09c
Author: atkach <atk...@hortonworks.com>
Authored: Tue Apr 15 12:53:45 2014 +0300
Committer: atkach <atk...@hortonworks.com>
Committed: Tue Apr 15 12:53:45 2014 +0300

----------------------------------------------------------------------
 ambari-web/app/assets/test/tests.js             |   2 +
 .../controllers/main/admin/misc_controller.js   |  79 ++++--
 .../app/controllers/main/admin/security.js      |  94 +++-----
 .../main/admin/misc_controller_test.js          | 225 +++++++++++++++++
 .../controllers/main/admin/security_test.js     | 241 +++++++++++++++++++
 .../hive_defaults_provider_test.js              |   6 +-
 6 files changed, 564 insertions(+), 83 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/a3be8c96/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 1dc66f9..a4becdb 100644
--- a/ambari-web/app/assets/test/tests.js
+++ b/ambari-web/app/assets/test/tests.js
@@ -27,6 +27,8 @@ require('test/controllers/global/update_controller_test');
 require('test/controllers/global/configuration_controller_test');
 require('test/controllers/main/app_contoller_test');
 require('test/controllers/main/admin/cluster_test');
+require('test/controllers/main/admin/misc_controller_test');
+require('test/controllers/main/admin/security_test');
 
require('test/controllers/main/admin/security/add/addSecurity_controller_test');
 require('test/controllers/main/admin/security/add/step2_test');
 require('test/controllers/main/admin/security/add/step3_test');

http://git-wip-us.apache.org/repos/asf/ambari/blob/a3be8c96/ambari-web/app/controllers/main/admin/misc_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/admin/misc_controller.js 
b/ambari-web/app/controllers/main/admin/misc_controller.js
index 57de024..6ebdd7c 100644
--- a/ambari-web/app/controllers/main/admin/misc_controller.js
+++ b/ambari-web/app/controllers/main/admin/misc_controller.js
@@ -22,16 +22,16 @@ var stringUtils = require('utils/string_utils');
 require('controllers/main/service/info/configs');
 
 App.MainAdminMiscController = App.MainServiceInfoConfigsController.extend({
-  name:'mainAdminMiscController',
+  name: 'mainAdminMiscController',
   users: null,
-  content: {
+  content: Em.Object.create({
     serviceName: 'MISC'
-  },
-  loadUsers: function() {
+  }),
+  loadUsers: function () {
     this.set('selectedService', this.get('content.serviceName'));
     this.loadServiceConfig();
   },
-  loadServiceConfig: function() {
+  loadServiceConfig: function () {
     App.ajax.send({
       name: 'config.tags',
       sender: this,
@@ -42,13 +42,13 @@ App.MainAdminMiscController = 
App.MainServiceInfoConfigsController.extend({
       success: 'loadServiceTagSuccess'
     });
   },
-  loadServiceTagSuccess: function(data, opt, params) {
+  loadServiceTagSuccess: function (data, opt, params) {
     var installedServices = App.Service.find().mapProperty("serviceName");
     var serviceConfigsDef = params.serviceConfigsDef;
     var serviceName = this.get('content.serviceName');
     var loadedClusterSiteToTagMap = {};
 
-    for ( var site in data.Clusters.desired_configs) {
+    for (var site in data.Clusters.desired_configs) {
       if (serviceConfigsDef.sites.indexOf(site) > -1) {
         loadedClusterSiteToTagMap[site] = 
data.Clusters.desired_configs[site]['tag'];
       }
@@ -63,17 +63,42 @@ App.MainAdminMiscController = 
App.MainServiceInfoConfigsController.extend({
 
     var sortOrder = this.get('configs').filterProperty('serviceName', 
this.get('selectedService')).filterProperty('category', 'Users and 
Groups').filterProperty('isVisible', true).mapProperty('name');
 
-    var sorted = [];
-
     //stack, with version lower than 2.1, doesn't have Falcon service
-    var proxyUserGroup = misc_configs.findProperty('name', 'proxyuser_group');
-    if (proxyUserGroup && 
stringUtils.compareVersions(App.get('currentStackVersionNumber'), "2.1") !== 1) 
{
-      proxyUserGroup.set('displayName', "Proxy group for Hive, WebHCat and 
Oozie");
-    }
+    this.setProxyUserGroupLabel(misc_configs);
+
+    this.set('users', this.sortByOrder(sortOrder, misc_configs));
+
+    this.setContentProperty('hdfsUser', 'hdfs_user', misc_configs);
+    this.setContentProperty('group', 'user_group', misc_configs);
 
-    if(sortOrder) {
-      sortOrder.forEach(function(name) {
-        var user = misc_configs.findProperty('name', name);
+    this.set('dataIsLoaded', true);
+  },
+  /**
+   * set config value to property of "content"
+   * @param key
+   * @param configName
+   * @param misc_configs
+   * @return {Boolean}
+   */
+  setContentProperty: function (key, configName, misc_configs) {
+    var content = this.get('content');
+    if (key && configName && misc_configs.someProperty('name', configName) && 
content.get(key)) {
+      content.set(key, misc_configs.findProperty('name', 
configName).get("value"));
+      return true;
+    }
+    return false;
+  },
+  /**
+   * sort miscellaneous configs by specific order
+   * @param sortOrder
+   * @param arrayToSort
+   * @return {Array}
+   */
+  sortByOrder: function (sortOrder, arrayToSort) {
+    var sorted = [];
+    if (sortOrder && sortOrder.length > 0) {
+      sortOrder.forEach(function (name) {
+        var user = arrayToSort.findProperty('name', name);
         if (user) {
           sorted.push({
             isVisible: user.get('isVisible'),
@@ -82,17 +107,19 @@ App.MainAdminMiscController = 
App.MainServiceInfoConfigsController.extend({
           });
         }
       });
-      this.set('users', sorted);
-    }
-    else {
-      this.set('users', misc_configs);
-    }
-    if(this.get("content.hdfsUser")){
-      this.get('content').set('hdfsUser', 
misc_configs.findProperty('name','hdfs_user').get("value"));
+      return sorted;
+    } else {
+      return arrayToSort;
     }
-    if (this.get("content.group")) {
-      this.get('content').set('group', 
misc_configs.findProperty('name','user_group').get("value"));
+  },
+  /**
+   * set displayName of "proxyuser_group" depending on stack version
+   * @param misc_configs
+   */
+  setProxyUserGroupLabel: function (misc_configs) {
+    var proxyUserGroup = misc_configs.findProperty('name', 'proxyuser_group');
+    if (proxyUserGroup && !App.get('isHadoop21Stack')) {
+      proxyUserGroup.set('displayName', "Proxy group for Hive, WebHCat and 
Oozie");
     }
-    this.set('dataIsLoaded', true);
   }
 });

http://git-wip-us.apache.org/repos/asf/ambari/blob/a3be8c96/ambari-web/app/controllers/main/admin/security.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/admin/security.js 
b/ambari-web/app/controllers/main/admin/security.js
index d4c9982..6db3671 100644
--- a/ambari-web/app/controllers/main/admin/security.js
+++ b/ambari-web/app/controllers/main/admin/security.js
@@ -47,10 +47,10 @@ App.MainAdminSecurityController = Em.Controller.extend({
   serviceConfigTags: [],
   selectedService: null,
   isNotEditable: true,
-  services: function(){
+  services: function () {
     var secureServices;
     var services = [];
-    if(App.get('isHadoop2Stack')) {
+    if (App.get('isHadoop2Stack')) {
       secureServices = $.extend(true, [], require('data/HDP2/secure_configs'));
     } else {
       secureServices = $.extend(true, [], require('data/secure_configs'));
@@ -68,7 +68,26 @@ App.MainAdminSecurityController = Em.Controller.extend({
     return services;
   }.property(),
 
-  loadStep: function(){
+  /**
+   * default values of configs, which contains user names
+   */
+  defaultUserNameMap: {
+    'hdfs_user': 'hdfs',
+    'yarn_user': 'yarn',
+    'mapred_user': 'mapred',
+    'hbase_user': 'hbase',
+    'hive_user': 'hive',
+    'proxyuser_group': 'users',
+    'smokeuser': 'ambari-qa',
+    'zk_user': 'zookeeper',
+    'oozie_user': 'oozie',
+    'nagios_user': 'nagios',
+    'user_group': 'hadoop',
+    'storm_user': 'storm',
+    'falcon_user': 'falcon'
+  },
+
+  loadStep: function () {
     var step2Controller = 
App.router.get('mainAdminSecurityAddStep2Controller');
     var services = this.get('services');
     this.get('stepConfigs').clear();
@@ -96,9 +115,9 @@ App.MainAdminSecurityController = Em.Controller.extend({
    * @param stepConfigs
    * @param serverConfigs
    */
-  setConfigValuesFromServer: function(stepConfigs, serverConfigs){
+  setConfigValuesFromServer: function (stepConfigs, serverConfigs) {
     var allConfigs = {};
-    serverConfigs.mapProperty('properties').forEach(function(_properties){
+    serverConfigs.mapProperty('properties').forEach(function (_properties) {
       allConfigs = $.extend(allConfigs, _properties);
     }, this);
     // for all services`
@@ -114,7 +133,6 @@ App.MainAdminSecurityController = Em.Controller.extend({
         }
       }, this);
     }, this);
-
   },
 
   /**
@@ -133,7 +151,6 @@ App.MainAdminSecurityController = Em.Controller.extend({
           newTagName: null,
           configs: {}
         };
-        console.log("The value of serviceConfigTags[index]: " + 
configs[index]);
         this.get('serviceConfigTags').pushObject(serviceConfigObj);
       }
     }
@@ -157,24 +174,6 @@ App.MainAdminSecurityController = Em.Controller.extend({
     this.set('securityUsers', securityUsers);
   },
   /**
-   * fill config with hosts of component
-   * @param service
-   * @param configName
-   * @param componentName
-   */
-  setHostsToConfig: function (service, configName, componentName) {
-    if (service) {
-      var hosts = service.configs.findProperty('name', configName);
-      if (hosts) {
-        hosts.defaultValue = App.Service.find(service.serviceName)
-          .get('hostComponents')
-          .filterProperty('componentName', componentName)
-          .mapProperty('host.hostName');
-      }
-    }
-  },
-
-  /**
    * Load child components to service config object
    * @param _componentConfig
    * @param componentConfig
@@ -297,49 +296,36 @@ App.MainAdminSecurityController = Em.Controller.extend({
     this.set('dataIsLoaded', true);
   },
 
-  setNnHaStatus: function(hdfsConfigs) {
+  setNnHaStatus: function (hdfsConfigs) {
     var nnHaStatus = hdfsConfigs && hdfsConfigs['dfs.nameservices'];
     var namenodesKey;
     if (nnHaStatus) {
       namenodesKey = 'dfs.ha.namenodes.' + hdfsConfigs['dfs.nameservices'];
     }
-    if(nnHaStatus && hdfsConfigs[namenodesKey]) {
+    if (nnHaStatus && hdfsConfigs[namenodesKey]) {
       App.db.setIsNameNodeHa('true');
     } else {
       App.db.setIsNameNodeHa('false');
     }
   },
 
-  loadUsers: function (configs) {
-    this.setUserName('hdfs_user',configs, 'hdfs');
-    this.setUserName('yarn_user',configs, 'yarn');
-    this.setUserName('mapred_user',configs, 'mapred');
-    this.setUserName('hbase_user',configs, 'hbase');
-    this.setUserName('hive_user',configs, 'hive');
-    this.setUserName('proxyuser_group',configs, 'users');
-    this.setUserName('smokeuser',configs, 'ambari-qa');
-    this.setUserName('zk_user',configs, 'zookeeper');
-    this.setUserName('oozie_user',configs, 'oozie');
-    this.setUserName('nagios_user',configs, 'nagios');
-    this.setUserName('user_group',configs, 'hadoop');
-    this.setUserName('storm_user',configs, 'storm');
-    this.setUserName('falcon_user',configs,'falcon');
-    App.db.setSecureUserInfo(this.get('serviceUsers'));
-  },
-
   /**
-   *
-   * @param name
-   * @param configs
-   * @param defaultValue
+   * load users names,
+   * substitute missing values with default
+   * @param configs {Object}
    */
-  setUserName: function(name,configs,defaultValue) {
+  loadUsers: function (configs) {
+    var defaultUserNameMap = this.get('defaultUserNameMap');
     var serviceUsers = this.get('serviceUsers');
-    serviceUsers.pushObject({
-      id: 'puppet var',
-      name: name,
-      value: configs[name] ? configs[name] : defaultValue
-    });
+
+    for (var configName in defaultUserNameMap) {
+      serviceUsers.push({
+        id: 'puppet var',
+        name: configName,
+        value: configs[configName] || defaultUserNameMap[configName]
+      });
+    }
+    App.db.setSecureUserInfo(this.get('serviceUsers'));
   },
 
   showSecurityErrorPopup: function () {

http://git-wip-us.apache.org/repos/asf/ambari/blob/a3be8c96/ambari-web/test/controllers/main/admin/misc_controller_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/main/admin/misc_controller_test.js 
b/ambari-web/test/controllers/main/admin/misc_controller_test.js
new file mode 100644
index 0000000..78d80b8
--- /dev/null
+++ b/ambari-web/test/controllers/main/admin/misc_controller_test.js
@@ -0,0 +1,225 @@
+/**
+ * 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/misc_controller');
+
+
+describe('App.MainAdminMiscController', function () {
+
+  var controller = App.MainAdminMiscController.create();
+
+  describe('#setContentProperty()', function () {
+    var testCases = [
+      {
+        title: 'key is null',
+        content: {
+          key: null,
+          configName: 'cc',
+          miscConfigs: []
+        },
+        result: {
+          output: false,
+          configValue: 'test'
+        }
+      },
+      {
+        title: 'configName is null',
+        content: {
+          key: 'key',
+          configName: null,
+          miscConfigs: []
+        },
+        result: {
+          output: false,
+          configValue: 'test'
+        }
+      },
+      {
+        title: 'misc configs array doesn\'t contain such a config',
+        content: {
+          key: 'key',
+          configName: 'config1',
+          miscConfigs: []
+        },
+        result: {
+          output: false,
+          configValue: 'test'
+        }
+      },
+      {
+        title: 'content doesn\'t contain such a key',
+        content: {
+          key: 'key',
+          configName: 'config1',
+          miscConfigs: [
+            Em.Object.create({
+              name: 'test_key'
+            })
+          ]
+        },
+        result: {
+          output: false,
+          configValue: 'test'
+        }
+      },
+      {
+        title: 'content property match config',
+        content: {
+          key: 'testKey',
+          configName: 'test_key',
+          miscConfigs: [
+            Em.Object.create({
+              name: 'test_key',
+              value: 'testValue'
+            })
+          ]
+        },
+        result: {
+          output: true,
+          configValue: 'testValue'
+        }
+      }
+    ];
+    controller.set('content', Em.Object.create({testKey: 'test'}));
+    testCases.forEach(function (test) {
+      it(test.title, function () {
+        var content = controller.get('content');
+        expect(controller.setContentProperty(test.content.key, 
test.content.configName, 
test.content.miscConfigs)).to.equal(test.result.output);
+        expect(content.get('testKey')).to.equal(test.result.configValue);
+      });
+    });
+  });
+
+  describe('#sortByOrder()', function () {
+    var testCases = [
+      {
+        title: 'sortOrder is null',
+        content: {
+          sortOrder: null,
+          arrayToSort: [
+            {
+              name: 'one',
+              displayName: 'one'
+            }
+          ]
+        },
+        result: ['one']
+      },
+      {
+        title: 'sortOrder is empty',
+        content: {
+          sortOrder: [],
+          arrayToSort: [
+            {
+              name: 'one',
+              displayName: 'one'
+            }
+          ]
+        },
+        result: ['one']
+      },
+      {
+        title: 'sortOrder items don\'t match items of array',
+        content: {
+          sortOrder: ['one'],
+          arrayToSort: [
+            {name: 'two'}
+          ]
+        },
+        result: []
+      },
+      {
+        title: 'sort items in reverse order',
+        content: {
+          sortOrder: ['two', 'one'],
+          arrayToSort: [
+            Em.Object.create({
+              name: 'one',
+              displayName: 'one'
+            }),
+            Em.Object.create({
+              name: 'two',
+              displayName: 'two'
+            })
+          ]
+        },
+        result: ['two', 'one']
+      },
+      {
+        title: 'sort items in correct order',
+        content: {
+          sortOrder: ['one', 'two'],
+          arrayToSort: [
+            Em.Object.create({
+              name: 'one',
+              displayName: 'one'
+            }),
+            Em.Object.create({
+              name: 'two',
+              displayName: 'two'
+            })
+          ]
+        },
+        result: ['one', 'two']
+      }
+    ];
+    testCases.forEach(function (test) {
+      it(test.title, function () {
+        expect(controller.sortByOrder(test.content.sortOrder, 
test.content.arrayToSort).mapProperty('displayName')).to.eql(test.result);
+      });
+    });
+  });
+
+  describe('#setProxyUserGroupLabel()', function () {
+
+    it('proxyuser_group config is absent', function () {
+      var misc_configs = [];
+      controller.setProxyUserGroupLabel(misc_configs);
+      expect(misc_configs.findProperty('name', 
'proxyuser_group')).to.be.undefined;
+    });
+    it('if currentStackVersionNumber less than 2.1 then label should be 
omitting "FALCON" service', function () {
+      var misc_configs = [Em.Object.create({
+        name: 'proxyuser_group',
+        displayName: 'test'
+      })];
+      App.set('currentStackVersion', "HDP-2.0");
+      controller.setProxyUserGroupLabel(misc_configs);
+      expect(misc_configs.findProperty('name', 
'proxyuser_group').get('displayName')).to.equal('Proxy group for Hive, WebHCat 
and Oozie');
+    });
+    it('if currentStackVersionNumber equal 2.1 then label should stay the 
same', function () {
+      var misc_configs = [Em.Object.create({
+        name: 'proxyuser_group',
+        displayName: 'test'
+      })];
+      App.set('currentStackVersion', "HDP-2.1");
+      controller.setProxyUserGroupLabel(misc_configs);
+      expect(misc_configs.findProperty('name', 
'proxyuser_group').get('displayName')).to.equal('test');
+    });
+    it('if currentStackVersionNumber higher than 2.1 then label should stay 
the same', function () {
+      var misc_configs = [Em.Object.create({
+        name: 'proxyuser_group',
+        displayName: 'test'
+      })];
+      App.set('currentStackVersion', "HDP-2.2");
+      controller.setProxyUserGroupLabel(misc_configs);
+      expect(misc_configs.findProperty('name', 
'proxyuser_group').get('displayName')).to.equal('test');
+    });
+  })
+});

http://git-wip-us.apache.org/repos/asf/ambari/blob/a3be8c96/ambari-web/test/controllers/main/admin/security_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/main/admin/security_test.js 
b/ambari-web/test/controllers/main/admin/security_test.js
new file mode 100644
index 0000000..fc3dfc0
--- /dev/null
+++ b/ambari-web/test/controllers/main/admin/security_test.js
@@ -0,0 +1,241 @@
+/**
+ * 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');
+
+
+describe('App.MainAdminSecurityController', function () {
+
+  var controller = App.MainAdminSecurityController.create({
+    getServiceConfigsFromServer: function () {
+    }
+  });
+
+  describe('#setServiceTagNames()', function () {
+    var testCases = [
+      {
+        title: 'configs is empty object',
+        content: {
+          secureService: {},
+          configs: {}
+        },
+        result: undefined
+      },
+      {
+        title: 'secureService.sites is null',
+        content: {
+          secureService: {
+            sites: null
+          },
+          configs: {
+            site1: {}
+          }
+        },
+        result: undefined
+      },
+      {
+        title: 'secureService.sites doesn\'t contain required config tag',
+        content: {
+          secureService: {
+            sites: []
+          },
+          configs: {
+            site1: {}
+          }
+        },
+        result: undefined
+      },
+      {
+        title: 'secureService.sites contains required config tag',
+        content: {
+          secureService: {
+            sites: ['site1']
+          },
+          configs: {
+            site1: {
+              tag: 'tag1'
+            }
+          }
+        },
+        result: {
+          siteName: 'site1',
+          tagName: 'tag1',
+          newTagName: null,
+          configs: {}
+        }
+      }
+    ];
+    testCases.forEach(function (test) {
+      it(test.title, function () {
+        expect(controller.setServiceTagNames(test.content.secureService, 
test.content.configs)).to.eql(test.result);
+      });
+    });
+  });
+
+  describe('#getSecurityStatusFromServerSuccessCallback()', function () {
+
+    beforeEach(function () {
+      sinon.spy(controller, 'showSecurityErrorPopup');
+      sinon.spy(controller, 'getServiceConfigsFromServer');
+    });
+    afterEach(function () {
+      controller.showSecurityErrorPopup.restore();
+      controller.getServiceConfigsFromServer.restore();
+    });
+
+    it('desired_configs is empty', function () {
+      var data = {Clusters: {
+        desired_configs: {}
+      }};
+      controller.getSecurityStatusFromServerSuccessCallback(data);
+      expect(controller.showSecurityErrorPopup.called).to.equal(true);
+    });
+
+    it('hdfs-site is missing', function () {
+      var data = {Clusters: {
+        desired_configs: {
+          'global': {}
+        }
+      }};
+      controller.getSecurityStatusFromServerSuccessCallback(data);
+      expect(controller.showSecurityErrorPopup.called).to.equal(true);
+    });
+
+    it('global is missing', function () {
+      var data = {Clusters: {
+        desired_configs: {
+          'hdfs-site': {}
+        }
+      }};
+      controller.getSecurityStatusFromServerSuccessCallback(data);
+      expect(controller.showSecurityErrorPopup.called).to.equal(true);
+    });
+
+    it('global and hdfs-site are correct', function () {
+      var data = {Clusters: {
+        desired_configs: {
+          'hdfs-site': {
+            tag: 1
+          },
+          'global': {
+            tag: 2
+          }
+        }
+      }};
+      controller.getSecurityStatusFromServerSuccessCallback(data);
+      expect(controller.get('tag.global')).to.equal(2);
+      expect(controller.get('tag.hdfs-site')).to.equal(1);
+      expect(controller.getServiceConfigsFromServer.called).to.equal(true);
+    });
+  });
+
+
+  describe('#setNnHaStatus()', function () {
+
+    beforeEach(function () {
+      sinon.stub(App.db, "setIsNameNodeHa", Em.K);
+    });
+    afterEach(function () {
+      App.db.setIsNameNodeHa.restore();
+    });
+
+
+    it('hdfsConfigs is null', function () {
+      var hdfsConfigs = null;
+      controller.setNnHaStatus(hdfsConfigs);
+      expect(App.db.setIsNameNodeHa.withArgs('false').called).to.equal(true);
+    });
+
+    it('"dfs.nameservices" is absent in hdfsConfigs', function () {
+      var hdfsConfigs = {};
+      controller.setNnHaStatus(hdfsConfigs);
+      expect(App.db.setIsNameNodeHa.withArgs('false').called).to.equal(true);
+    });
+
+    it('namenodesKey is absent in hdfsConfigs', function () {
+      var hdfsConfigs = {
+        'dfs.nameservices': 'key'
+      };
+      controller.setNnHaStatus(hdfsConfigs);
+      expect(App.db.setIsNameNodeHa.withArgs('false').called).to.equal(true);
+    });
+
+    it('namenodesKey is present in hdfsConfigs', function () {
+      var hdfsConfigs = {
+        'dfs.nameservices': 'key',
+        'dfs.ha.namenodes.key': 'true'
+      };
+      controller.setNnHaStatus(hdfsConfigs);
+      expect(App.db.setIsNameNodeHa.withArgs('true').called).to.equal(true);
+    });
+  });
+
+  describe('#loadUsers()', function () {
+
+    beforeEach(function () {
+      sinon.stub(App.db, "setSecureUserInfo", Em.K);
+    });
+    afterEach(function () {
+      App.db.setSecureUserInfo.restore();
+    });
+
+    it('if defaultUserNameMap is empty then serviceUsers stays the same', 
function () {
+      var configs = {};
+      controller.set('serviceUsers', []);
+      controller.set('defaultUserNameMap', {});
+      controller.loadUsers(configs);
+      expect(controller.get('serviceUsers')).to.be.empty;
+    });
+
+    it('if user config value is missing then use default', function () {
+      var configs = {};
+      controller.set('serviceUsers', []);
+      controller.set('defaultUserNameMap', {
+        'test_user': 'test'
+      });
+      controller.loadUsers(configs);
+      expect(controller.get('serviceUsers')).to.eql([
+        {
+          "id": "puppet var",
+          "name": "test_user",
+          "value": "test"
+        }
+      ]);
+    });
+
+    it('user config value has value', function () {
+      var configs = {
+        'test_user': 'config-value'
+      };
+      controller.set('serviceUsers', []);
+      controller.set('defaultUserNameMap', {
+        'test_user': 'test'
+      });
+      controller.loadUsers(configs);
+      expect(controller.get('serviceUsers')).to.eql([
+        {
+          "id": "puppet var",
+          "name": "test_user",
+          "value": "config-value"
+        }
+      ]);
+    });
+  });
+});
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/a3be8c96/ambari-web/test/utils/configs/defaults_providers/hive_defaults_provider_test.js
----------------------------------------------------------------------
diff --git 
a/ambari-web/test/utils/configs/defaults_providers/hive_defaults_provider_test.js
 
b/ambari-web/test/utils/configs/defaults_providers/hive_defaults_provider_test.js
index 4c0c805..e7009f4 100644
--- 
a/ambari-web/test/utils/configs/defaults_providers/hive_defaults_provider_test.js
+++ 
b/ambari-web/test/utils/configs/defaults_providers/hive_defaults_provider_test.js
@@ -70,7 +70,7 @@ describe('HiveDefaultsProvider', function() {
           'mapreduce.task.io.sort.mb': 1024,
           'hive.tez.container.size': 2560,
           'hive.auto.convert.join.noconditionaltask.size': 894435328,
-          'hive.tez.java.opts': '-server -Xmx2560m 
-Djava.net.preferIPv4Stack=true'
+          'hive.tez.java.opts': '-server -Xmx2048m 
-Djava.net.preferIPv4Stack=true -XX:NewRatio=8 -XX:+UseNUMA -XX:+UseParallelGC'
         }
       },
       {
@@ -103,7 +103,7 @@ describe('HiveDefaultsProvider', function() {
           'mapreduce.task.io.sort.mb': 410,
           'hive.tez.container.size': 1024,
           'hive.auto.convert.join.noconditionaltask.size': 357564416,
-          'hive.tez.java.opts': '-server -Xmx1024m 
-Djava.net.preferIPv4Stack=true'
+          'hive.tez.java.opts': '-server -Xmx819m 
-Djava.net.preferIPv4Stack=true -XX:NewRatio=8 -XX:+UseNUMA -XX:+UseParallelGC'
         }
       },
       {
@@ -136,7 +136,7 @@ describe('HiveDefaultsProvider', function() {
           'mapreduce.task.io.sort.mb': 1024,
           'hive.tez.container.size': 8704,
           'hive.auto.convert.join.noconditionaltask.size': 3041918976,
-          'hive.tez.java.opts': '-server -Xmx8704m 
-Djava.net.preferIPv4Stack=true'
+          'hive.tez.java.opts': '-server -Xmx6963m 
-Djava.net.preferIPv4Stack=true -XX:NewRatio=8 -XX:+UseNUMA -XX:+UseParallelGC'
         }
       }
     ]);

Reply via email to