Przeglądaj źródła

AMBARI-6541 Update tests of general and admin part of application. (atkach)

atkach 11 lat temu
rodzic
commit
2b6482db3c

+ 13 - 13
ambari-web/app/app.js

@@ -56,7 +56,7 @@ module.exports = Em.Application.create({
   falconServerURL: function () {
     var falconService = this.Service.find().findProperty('serviceName', 'FALCON');
     if (falconService) {
-      return falconService.get('hostComponents').findProperty('componentName', 'FALCON_SERVER').get('host.hostName');
+      return falconService.get('hostComponents').findProperty('componentName', 'FALCON_SERVER').get('hostName');
     }
     return '';
   }.property().volatile(),
@@ -130,51 +130,51 @@ module.exports = Em.Application.create({
     }.property('App.router.clusterController.isLoaded'),
 
     reassignable: function () {
-      return App.StackServiceComponent.find().filterProperty('isReassignable', true).mapProperty('componentName')
+      return App.StackServiceComponent.find().filterProperty('isReassignable').mapProperty('componentName')
     }.property('App.router.clusterController.isLoaded'),
 
     restartable: function () {
-      return App.StackServiceComponent.find().filterProperty('isRestartable', true).mapProperty('componentName')
+      return App.StackServiceComponent.find().filterProperty('isRestartable').mapProperty('componentName')
     }.property('App.router.clusterController.isLoaded'),
 
     deletable: function () {
-      return App.StackServiceComponent.find().filterProperty('isDeletable', true).mapProperty('componentName')
+      return App.StackServiceComponent.find().filterProperty('isDeletable').mapProperty('componentName')
     }.property('App.router.clusterController.isLoaded'),
 
     rollinRestartAllowed: function () {
-      return App.StackServiceComponent.find().filterProperty('isRollinRestartAllowed', true).mapProperty('componentName')
+      return App.StackServiceComponent.find().filterProperty('isRollinRestartAllowed').mapProperty('componentName')
     }.property('App.router.clusterController.isLoaded'),
 
     decommissionAllowed: function () {
-      return App.StackServiceComponent.find().filterProperty('isDecommissionAllowed', true).mapProperty('componentName')
+      return App.StackServiceComponent.find().filterProperty('isDecommissionAllowed').mapProperty('componentName')
     }.property('App.router.clusterController.isLoaded'),
 
     refreshConfigsAllowed: function () {
-      return App.StackServiceComponent.find().filterProperty('isRefreshConfigsAllowed', true).mapProperty('componentName')
+      return App.StackServiceComponent.find().filterProperty('isRefreshConfigsAllowed').mapProperty('componentName')
     }.property('App.router.clusterController.isLoaded'),
 
     addableToHost: function () {
-      return App.StackServiceComponent.find().filterProperty('isAddableToHost', true).mapProperty('componentName')
+      return App.StackServiceComponent.find().filterProperty('isAddableToHost').mapProperty('componentName')
     }.property('App.router.clusterController.isLoaded'),
 
     addableMasterInstallerWizard: function () {
-      return App.StackServiceComponent.find().filterProperty('isMasterAddableInstallerWizard', true).mapProperty('componentName')
+      return App.StackServiceComponent.find().filterProperty('isMasterAddableInstallerWizard').mapProperty('componentName')
     }.property('App.router.clusterController.isLoaded'),
 
     multipleMasters: function () {
-      return App.StackServiceComponent.find().filterProperty('isMasterWithMultipleInstances', true).mapProperty('componentName')
+      return App.StackServiceComponent.find().filterProperty('isMasterWithMultipleInstances').mapProperty('componentName')
     }.property('App.router.clusterController.isLoaded'),
 
     slaves: function () {
-      return App.StackServiceComponent.find().filterProperty('isMaster', false).filterProperty('isClient', false).mapProperty('componentName')
+      return App.StackServiceComponent.find().filterProperty('isSlave').mapProperty('componentName')
     }.property('App.router.clusterController.isLoaded'),
 
     masters: function () {
-      return App.StackServiceComponent.find().filterProperty('isMaster', true).mapProperty('componentName')
+      return App.StackServiceComponent.find().filterProperty('isMaster').mapProperty('componentName')
     }.property('App.router.clusterController.isLoaded'),
 
     clients: function () {
-      return App.StackServiceComponent.find().filterProperty('isClient', true).mapProperty('componentName')
+      return App.StackServiceComponent.find().filterProperty('isClient').mapProperty('componentName')
     }.property('App.router.clusterController.isLoaded')
   })
 });

+ 1 - 0
ambari-web/app/assets/test/tests.js

@@ -32,6 +32,7 @@ require('views');
 require('router');
 require('mappers');
 
+require('test/init_router_test');
 require('test/init_model_test');
 require('test/app_test');
 require('test/data/HDP2/site_properties_test');

+ 13 - 12
ambari-web/app/controllers/global/cluster_controller.js

@@ -20,7 +20,6 @@ var App = require('app');
 
 App.ClusterController = Em.Controller.extend({
   name: 'clusterController',
-  cluster: null,
   isLoaded: false,
   ambariProperties: null,
   ambariViews: [],
@@ -45,6 +44,11 @@ App.ClusterController = Em.Controller.extend({
    * If null is returned, it means NAGIOS service is not installed.
    */
   nagiosUrl: null,
+
+  clusterName: function () {
+    return App.get('clusterName');
+  }.property('App.clusterName'),
+
   updateLoadStatus: function (item) {
     var loadList = this.get('dataLoadList');
     var loaded = true;
@@ -86,7 +90,7 @@ App.ClusterController = Em.Controller.extend({
   loadClusterName: function (reload) {
     var dfd = $.Deferred();
 
-    if (this.get('clusterName') && !reload) {
+    if (App.get('clusterName') && !reload) {
       dfd.resolve();
     } else {
       App.ajax.send({
@@ -105,7 +109,6 @@ App.ClusterController = Em.Controller.extend({
   },
 
   loadClusterNameSuccessCallback: function (data) {
-    this.set('cluster', data.items[0]);
     App.set('clusterName', data.items[0].Clusters.cluster_name);
     App.set('currentStackVersion', data.items[0].Clusters.version);
   },
@@ -147,17 +150,18 @@ App.ClusterController = Em.Controller.extend({
   },
 
   getUrl: function (testUrl, url) {
-    return (App.testMode) ? testUrl : App.apiPrefix + '/clusters/' + this.get('clusterName') + url;
+    return (App.testMode) ? testUrl : App.apiPrefix + '/clusters/' + App.get('clusterName') + url;
   },
 
   setGangliaUrl: function () {
     if (App.testMode) {
-      return 'http://gangliaserver/ganglia/?t=yes';
+      this.set('gangliaUrl', 'http://gangliaserver/ganglia/?t=yes');
+      this.set('isGangliaUrlLoaded', true);
     } else {
       // We want live data here
       var gangliaServer = App.HostComponent.find().findProperty('componentName', 'GANGLIA_SERVER');
       if (this.get('isLoaded') && gangliaServer) {
-        this.set('isGangliaUrlLoaded', true);
+        this.set('isGangliaUrlLoaded', false);
         App.ajax.send({
           name: 'hosts.for_quick_links',
           sender: this,
@@ -183,7 +187,8 @@ App.ClusterController = Em.Controller.extend({
 
   setNagiosUrl: function () {
     if (App.testMode) {
-      return 'http://nagiosserver/nagios';
+      this.set('nagiosUrl', 'http://nagiosserver/nagios');
+      this.set('isNagiosUrlLoaded', true);
     } else {
       // We want live data here
       var nagiosServer = App.HostComponent.find().findProperty('componentName', 'NAGIOS_SERVER');
@@ -245,7 +250,7 @@ App.ClusterController = Em.Controller.extend({
     var self = this;
     this.loadAmbariProperties();
     this.loadAmbariViews();
-    if (!this.get('clusterName')) {
+    if (!App.get('clusterName')) {
       return;
     }
 
@@ -427,10 +432,6 @@ App.ClusterController = Em.Controller.extend({
     console.warn('can\'t get ambari properties');
   },
 
-  clusterName: function () {
-    return (this.get('cluster')) ? this.get('cluster').Clusters.cluster_name : null;
-  }.property('cluster'),
-
   updateClusterData: function () {
     var testUrl = App.get('isHadoop2Stack') ? '/data/clusters/HDP2/cluster.json' : '/data/clusters/cluster.json';
     var clusterUrl = this.getUrl(testUrl, '?fields=Clusters');

+ 9 - 4
ambari-web/app/controllers/main/admin/highAvailability_controller.js

@@ -39,7 +39,7 @@ App.MainAdminHighAvailabilityController = Em.Controller.extend({
       this.showErrorPopup(Em.I18n.t('admin.highAvailability.error.security'));
       return false;
     } else {
-     if (hostComponents.findProperty('componentName', 'NAMENODE').get('workStatus') !== 'STARTED') {
+      if (hostComponents.findProperty('componentName', 'NAMENODE').get('workStatus') !== 'STARTED') {
         message.push(Em.I18n.t('admin.highAvailability.error.namenodeStarted'));
       }
       if (hostComponents.filterProperty('componentName', 'ZOOKEEPER_SERVER').length < 3) {
@@ -126,12 +126,17 @@ App.MainAdminHighAvailabilityController = Em.Controller.extend({
       }
     ];
     App.router.get('configurationController').getConfigsByTags(tags).done(function (data) {
-      var configs = data.findProperty('tag', self.get('tag')).properties;
-      var securityEnabled = !!(configs && (configs['security_enabled'] === 'true' || configs['security_enabled'] === true));
-      self.set('securityEnabled', securityEnabled);
+      self.set('securityEnabled', self.isSecurityEnabled(data.findProperty('tag', self.get('tag')).properties));
       self.set('dataIsLoaded', true);
     });
   },
+
+  /**
+   * identify whether security is enabled by security config
+   */
+  isSecurityEnabled: function(properties){
+    return !!(properties && (properties['security_enabled'] === 'true' || properties['security_enabled'] === true));
+  },
   /**
    * join or wrap message depending on whether it is array or string
    * @param message

+ 297 - 211
ambari-web/test/app_test.js

@@ -22,146 +22,13 @@ require('models/host_component');
 require('models/stack_service_component');
 var modelSetup = require('test/init_model_test');
 
-describe('#App', function() {
-
-  describe('App.isHadoop21Stack', function() {
-    var tests = [{
-      v:'',
-      e:false
-    }, {
-      v:'HDP',
-      e: false
-    }, {
-      v:'HDP1',
-      e: false
-    }, {
-      v:'HDP-1',
-      e: false
-    }, {
-      v:'HDP-2.0',
-      e: false
-    }, {
-      v:'HDP-2.0.1000',
-      e: false
-    }, {
-      v:'HDP-2.1',
-      e: true
-    }, {
-      v:'HDP-2.1.3434',
-      e: true
-    }, {
-      v:'HDP-2.2',
-      e: true
-    }, {
-      v:'HDP-2.2.1212',
-      e: true
-    }];
-    tests.forEach(function(test){
-      it(test.v, function() {
-        App.QuickViewLinks.prototype.setQuickLinks = function(){};
-        App.set('currentStackVersion', test.v);
-        var calculated = App.get('isHadoop21Stack');
-        var expected = test.e;
-        expect(calculated).to.equal(expected);
-      });
-    });
-  });
-
-  describe('Disable/enable components', function() {
-
-    App.set('handleStackDependencyTest', true);
-    modelSetup.setupStackVersion(this, 'HDP-2.1');
-
-    var testableComponent =  Em.Object.create({
-      componentName: 'APP_TIMELINE_SERVER',
-      serviceName: 'YARN'
-    });
-    var expectedInfo = {
-      componentName: 'APP_TIMELINE_SERVER',
-      properties: {
-        global_properties: ['ats_host', 'apptimelineserver_heapsize'],
-        site_properties: ['yarn.timeline-service.generic-application-history.store-class', 'yarn.timeline-service.store-class', 'yarn.timeline-service.leveldb-timeline-store.path']
-      },
-      reviewConfigs: {
-        component_name: 'APP_TIMELINE_SERVER'
-      },
-      configCategory: {
-        name: 'AppTimelineServer'
-      }
-    };
-
-    var globalProperties = require('data/HDP2/global_properties');
-    var siteProperties = require('data/HDP2/site_properties');
-
-    var reviewConfigs = require('data/review_configs');
-    var disableResult = App.disableComponent(testableComponent);
-
-
-    describe('#disableComponent()', function() {
-      // copy
-      var _globalProperties = $.extend({}, globalProperties);
-      var _siteProperties = $.extend({}, siteProperties);
-
-      describe('result validation', function() {
-
-        it('component name should be "' + expectedInfo.componentName + '"', function() {
-          expect(disableResult.get('componentName')).to.eql(expectedInfo.componentName);
-        });
-
-        it('config category name should be "' + expectedInfo.configCategory.name +'"', function() {
-          expect(disableResult.get('configCategory.name')).to.eql(expectedInfo.configCategory.name);
-        });
-
-        for(var siteName in expectedInfo.properties) {
-          (function(site) {
-            expectedInfo.properties[site].forEach(function(property) {
-              it(property + ' present in ' + site, function() {
-                expect(disableResult.get('properties.' + site).mapProperty('name')).to.include(property);
-              });
-            }, this);
-          })(siteName);
-        }
-
-        it('site and global properties should not be equal', function() {
-          expect(disableResult.get('properties.global_properties')).to.not.include.members(disableResult.get('properties.site_properties'));
-        });
-
-
-      });
-
-      describe('effect validation',function() {
-
-
-        it('should remove global properties of component', function() {
-          expect(_globalProperties.configProperties.mapProperty('name')).to.not.include.members(expectedInfo.properties.global_properties);
-        });
-
-        it('should remove site properties of component', function() {
-          expect(_siteProperties.configProperties.mapProperty('name')).to.not.include.members(expectedInfo.properties.site_properties);
-        });
-
-      });
-    });
-
-    describe('#enableComponent', function() {
-      App.enableComponent(disableResult);
-
-      it('should add global properties of component', function() {
-        expect(globalProperties.configProperties.mapProperty('name')).to.include.members(expectedInfo.properties.global_properties);
-      });
-
-      it('should add site properties of component', function() {
-        expect(siteProperties.configProperties.mapProperty('name')).to.include.members(expectedInfo.properties.site_properties);
-      });
-    });
-
-    modelSetup.restoreStackVersion(this);
-  });
+describe('App', function () {
 
   describe('#stackVersionURL', function () {
 
     App.QuickViewLinks.reopen({
-      loadTags: function () {}
+      loadTags: function () {
+      }
     });
 
     var testCases = [
@@ -169,37 +36,37 @@ describe('#App', function() {
         title: 'if currentStackVersion and defaultStackVersion are empty then stackVersionURL should contain prefix',
         currentStackVersion: '',
         defaultStackVersion: '',
-        result: '/stacks/HDP/version/'
+        result: '/stacks/HDP/versions/'
       },
       {
-        title: 'if currentStackVersion is "HDP-1.3.1" then stackVersionURL should be "/stacks/HDP/version/1.3.1"',
+        title: 'if currentStackVersion is "HDP-1.3.1" then stackVersionURL should be "/stacks/HDP/versions/1.3.1"',
         currentStackVersion: 'HDP-1.3.1',
         defaultStackVersion: '',
-        result: '/stacks/HDP/version/1.3.1'
+        result: '/stacks/HDP/versions/1.3.1'
       },
       {
-        title: 'if defaultStackVersion is "HDP-1.3.1" then stackVersionURL should be "/stacks/HDP/version/1.3.1"',
+        title: 'if defaultStackVersion is "HDP-1.3.1" then stackVersionURL should be "/stacks/HDP/versions/1.3.1"',
         currentStackVersion: '',
         defaultStackVersion: 'HDP-1.3.1',
-        result: '/stacks/HDP/version/1.3.1'
+        result: '/stacks/HDP/versions/1.3.1'
       },
       {
         title: 'if defaultStackVersion and currentStackVersion are different then stackVersionURL should have currentStackVersion value',
         currentStackVersion: 'HDP-1.3.2',
         defaultStackVersion: 'HDP-1.3.1',
-        result: '/stacks/HDP/version/1.3.2'
+        result: '/stacks/HDP/versions/1.3.2'
       },
       {
-        title: 'if defaultStackVersion is "HDPLocal-1.3.1" then stackVersionURL should be "/stacks/HDPLocal/version/1.3.1"',
+        title: 'if defaultStackVersion is "HDPLocal-1.3.1" then stackVersionURL should be "/stacks/HDPLocal/versions/1.3.1"',
         currentStackVersion: '',
         defaultStackVersion: 'HDPLocal-1.3.1',
-        result: '/stacks/HDPLocal/version/1.3.1'
+        result: '/stacks/HDPLocal/versions/1.3.1'
       },
       {
-        title: 'if currentStackVersion is "HDPLocal-1.3.1" then stackVersionURL should be "/stacks/HDPLocal/version/1.3.1"',
+        title: 'if currentStackVersion is "HDPLocal-1.3.1" then stackVersionURL should be "/stacks/HDPLocal/versions/1.3.1"',
         currentStackVersion: 'HDPLocal-1.3.1',
         defaultStackVersion: '',
-        result: '/stacks/HDPLocal/version/1.3.1'
+        result: '/stacks/HDPLocal/versions/1.3.1'
       }
     ];
 
@@ -266,6 +133,51 @@ describe('#App', function() {
     });
   });
 
+  describe('#falconServerURL', function () {
+
+    var testCases = [
+      {
+        title: 'No services installed, url should be empty',
+        service: Em.A([]),
+        result: ''
+      },
+      {
+        title: 'FALCON is not installed, url should be empty',
+        service: Em.A([
+          {
+            serviceName: 'HDFS'
+          }
+        ]),
+        result: ''
+      },
+      {
+        title: 'FALCON is installed, url should be "host1"',
+        service: Em.A([
+          Em.Object.create({
+            serviceName: 'FALCON',
+            hostComponents: [
+              Em.Object.create({
+                componentName: 'FALCON_SERVER',
+                hostName: 'host1'
+              })
+            ]
+          })
+        ]),
+        result: 'host1'
+      }
+    ];
+
+    testCases.forEach(function (test) {
+      it(test.title, function () {
+        sinon.stub(App.Service, 'find', function () {
+          return test.service;
+        });
+        expect(App.get('falconServerURL')).to.equal(test.result);
+        App.Service.find.restore();
+      });
+    });
+  });
+
   describe('#currentStackVersionNumber', function () {
 
     var testCases = [
@@ -329,6 +241,61 @@ describe('#App', function() {
     });
   });
 
+  describe('#isHadoop21Stack', function () {
+    var tests = [
+      {
+        v: '',
+        e: false
+      },
+      {
+        v: 'HDP',
+        e: false
+      },
+      {
+        v: 'HDP1',
+        e: false
+      },
+      {
+        v: 'HDP-1',
+        e: false
+      },
+      {
+        v: 'HDP-2.0',
+        e: false
+      },
+      {
+        v: 'HDP-2.0.1000',
+        e: false
+      },
+      {
+        v: 'HDP-2.1',
+        e: true
+      },
+      {
+        v: 'HDP-2.1.3434',
+        e: true
+      },
+      {
+        v: 'HDP-2.2',
+        e: true
+      },
+      {
+        v: 'HDP-2.2.1212',
+        e: true
+      }
+    ];
+    tests.forEach(function (test) {
+      it(test.v, function () {
+        App.QuickViewLinks.prototype.setQuickLinks = function () {
+        };
+        App.set('currentStackVersion', test.v);
+        var calculated = App.get('isHadoop21Stack');
+        var expected = test.e;
+        expect(calculated).to.equal(expected);
+      });
+    });
+  });
+
   describe('#isHaEnabled', function () {
 
     it('if hadoop stack version less than 2 then isHaEnabled should be false', function () {
@@ -352,78 +319,197 @@ describe('#App', function() {
     });
   });
 
-  describe('#handleStackDependedComponents()', function () {
+  describe('#services', function () {
+    var stackServices = [
+      Em.Object.create({
+        serviceName: 'S1',
+        isClientOnlyService: true
+      }),
+      Em.Object.create({
+        serviceName: 'S2',
+        hasClient: true
+      }),
+      Em.Object.create({
+        serviceName: 'S3',
+        hasMaster: true
+      }),
+      Em.Object.create({
+        serviceName: 'S4',
+        hasSlave: true
+      }),
+      Em.Object.create({
+        serviceName: 'S5',
+        isNoConfigTypes: true
+      }),
+      Em.Object.create({
+        serviceName: 'S6',
+        isMonitoringService: true
+      }),
+      Em.Object.create({
+        serviceName: 'S7'
+      })
+    ];
 
-    beforeEach(function(){
-      modelSetup.setupStackServiceComponent();
-    });
+    it('distribute services by categories', function () {
+      sinon.stub(App.StackService, 'find', function () {
+        return stackServices;
+      });
 
-    afterEach(function(){
-      modelSetup.cleanStackServiceComponent();
+      expect(App.get('services.all')).to.eql(['S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7']);
+      expect(App.get('services.clientOnly')).to.eql(['S1']);
+      expect(App.get('services.hasClient')).to.eql(['S2']);
+      expect(App.get('services.hasMaster')).to.eql(['S3']);
+      expect(App.get('services.hasSlave')).to.eql(['S4']);
+      expect(App.get('services.noConfigTypes')).to.eql(['S5']);
+      expect(App.get('services.monitoring')).to.eql(['S6']);
+      App.StackService.find.restore();
     });
+  });
 
-    it('if handleStackDependencyTest is true then stackDependedComponents should be unmodified', function () {
-      App.set('testMode', false);
-      App.set('handleStackDependencyTest', true);
-      App.handleStackDependedComponents();
-      expect(App.get('stackDependedComponents')).to.be.empty;
-    });
 
-    it('if testMode is true then stackDependedComponents should be unmodified', function () {
-      App.set('handleStackDependencyTest', false);
-      App.set('testMode', true);
-      App.handleStackDependedComponents();
-      expect(App.get('stackDependedComponents')).to.be.empty;
-    });
+  describe('#components', function () {
+    var testCases = [
+      {
+        key: 'allComponents',
+        data: [
+          Em.Object.create({
+            componentName: 'C1'
+          })
+        ],
+        result: ['C1']
+      },
+      {
+        key: 'reassignable',
+        data: [
+          Em.Object.create({
+            componentName: 'C2',
+            isReassignable: true
+          })
+        ],
+        result: ['C2']
+      },
+      {
+        key: 'restartable',
+        data: [
+          Em.Object.create({
+            componentName: 'C3',
+            isRestartable: true
+          })
+        ],
+        result: ['C3']
+      },
+      {
+        key: 'deletable',
+        data: [
+          Em.Object.create({
+            componentName: 'C4',
+            isDeletable: true
+          })
+        ],
+        result: ['C4']
+      },
+      {
+        key: 'rollinRestartAllowed',
+        data: [
+          Em.Object.create({
+            componentName: 'C5',
+            isRollinRestartAllowed: true
+          })
+        ],
+        result: ['C5']
+      },
+      {
+        key: 'decommissionAllowed',
+        data: [
+          Em.Object.create({
+            componentName: 'C6',
+            isDecommissionAllowed: true
+          })
+        ],
+        result: ['C6']
+      },
+      {
+        key: 'refreshConfigsAllowed',
+        data: [
+          Em.Object.create({
+            componentName: 'C7',
+            isRefreshConfigsAllowed: true
+          })
+        ],
+        result: ['C7']
+      },
+      {
+        key: 'addableToHost',
+        data: [
+          Em.Object.create({
+            componentName: 'C8',
+            isAddableToHost: true
+          })
+        ],
+        result: ['C8']
+      },
+      {
+        key: 'addableMasterInstallerWizard',
+        data: [
+          Em.Object.create({
+            componentName: 'C9',
+            isMasterAddableInstallerWizard: true
+          })
+        ],
+        result: ['C9']
+      },
+      {
+        key: 'multipleMasters',
+        data: [
+          Em.Object.create({
+            componentName: 'C10',
+            isMasterWithMultipleInstances: true
+          })
+        ],
+        result: ['C10']
+      },
+      {
+        key: 'slaves',
+        data: [
+          Em.Object.create({
+            componentName: 'C11',
+            isSlave: true
+          })
+        ],
+        result: ['C11']
+      },
+      {
+        key: 'masters',
+        data: [
+          Em.Object.create({
+            componentName: 'C12',
+            isMaster: true
+          })
+        ],
+        result: ['C12']
+      },
+      {
+        key: 'clients',
+        data: [
+          Em.Object.create({
+            componentName: 'C13',
+            isClient: true
+          })
+        ],
+        result: ['C13']
+      }
+    ];
 
-    it('if stack contains all components then stackDependedComponents should be empty', function () {
-      App.set('testMode', false);
-      App.set('handleStackDependencyTest', false);
-      App.handleStackDependedComponents();
-      expect(App.get('stackDependedComponents')).to.be.empty;
-    });
+    testCases.forEach(function (test) {
+      it(test.key + ' should contain ' + test.result, function () {
+        sinon.stub(App.StackServiceComponent, 'find', function () {
+          return test.data;
+        });
 
-    it('if stack is missing component then push it to stackDependedComponents', function () {
-      App.set('testMode', false);
-      App.set('handleStackDependencyTest', false);
-      var dtRecord = App.StackServiceComponent.find('DATANODE');
-      dtRecord.deleteRecord();
-      dtRecord.get('stateManager').transitionTo('loading');
-      App.handleStackDependedComponents();
-      expect(App.get('stackDependedComponents').mapProperty('componentName')).to.eql(["DATANODE"]);
-      App.store.load(App.StackServiceComponent, {
-        id: 'DATANODE',
-        component_name: 'DATANODE',
-        service_name: 'HDFS',
-        component_category: 'SLAVE',
-        is_master: false,
-        is_client: false,
-        stack_name: 'HDP',
-        stack_version: '2.1'
-      });
-    });
+        expect(App.get('components.' + test.key)).to.eql(test.result);
 
-    it('remove stack components from stackDependedComponents', function () {
-      App.set('testMode', false);
-      App.set('handleStackDependencyTest', false);
-      App.set('stackDependedComponents', [
-        Em.Object.create({
-          componentName: "DATANODE",
-          serviceName: "HDFS",
-          properties: {},
-          reviewConfigs: {},
-          configCategory: {}
-        }),
-        Em.Object.create({
-          componentName: "categoryComponent",
-          serviceName: "",
-          properties: {},
-          reviewConfigs: {},
-          configCategory: {}
-        })
-      ]);
-      App.handleStackDependedComponents();
-      expect(App.get('stackDependedComponents').mapProperty('componentName')).to.eql(["categoryComponent"]);
-    });
+        App.StackServiceComponent.find.restore();
+      })
+    })
   });
 });

+ 9 - 13
ambari-web/test/controllers/global/background_operations_test.js

@@ -52,7 +52,9 @@ describe('App.BackgroundOperationsController', function () {
         e: {
           name: 'background_operations.get_most_recent',
           successCallback: 'callBackForMostRecent',
-          data: {}
+          data: {
+            'operationsCount': 10
+          }
         },
         response: {items: []},
         m: '"Get Most Recent"'
@@ -61,16 +63,14 @@ describe('App.BackgroundOperationsController', function () {
         levelInfo: Em.Object.create({
           name: 'TASK_DETAILS',
           requestId: 1,
-          taskId: 1,
-          sync: false
+          taskId: 1
         }),
         e: {
           name: 'background_operations.get_by_task',
           successCallback: 'callBackFilteredByTask',
           data: {
             taskId: 1,
-            requestId: 1,
-            sync: false
+            requestId: 1
           }
         },
         response: {items: {Tasks: {request_id: 0}}},
@@ -80,15 +80,13 @@ describe('App.BackgroundOperationsController', function () {
         levelInfo: Em.Object.create({
           name: 'TASKS_LIST',
           requestId: 1,
-          taskId: 1,
-          sync: false
+          taskId: 1
         }),
         e: {
           name: 'background_operations.get_by_request',
           successCallback: 'callBackFilteredByRequest',
           data: {
-            requestId: 1,
-            sync: false
+            requestId: 1
           }
         },
         response: {items: {Requests: {id: 0}}},
@@ -98,15 +96,13 @@ describe('App.BackgroundOperationsController', function () {
         levelInfo: Em.Object.create({
           name: 'HOSTS_LIST',
           requestId: 1,
-          taskId: 1,
-          sync: false
+          taskId: 1
         }),
         e: {
           name: 'background_operations.get_by_request',
           successCallback: 'callBackFilteredByRequest',
           data: {
-            requestId: 1,
-            sync: false
+            requestId: 1
           }
         },
         response: {items: {Requests: {id: 0}}},

+ 148 - 141
ambari-web/test/controllers/global/cluster_controller_test.js

@@ -66,28 +66,40 @@ describe('App.clusterController', function () {
 
     beforeEach(function () {
       modelSetup.setupStackVersion(this, 'HDP-2.0.5');
-      sinon.spy(App.ajax, 'send');
+      sinon.stub(App.ajax, 'send', function () {
+        return {
+          complete: function (callback) {
+            App.set('clusterName', 'clusterNameFromServer');
+            App.set('currentStackVersion', 'HDP-2.0.5');
+            callback();
+          }
+        }
+      });
     });
     afterEach(function () {
       modelSetup.restoreStackVersion(this);
       App.ajax.send.restore();
     });
 
-    it('if clusterName is "mycluster" and reload is false then loadClusterName should return false', function () {
-      controller.set('cluster', {Clusters: {cluster_name: 'mycluster'}});
-      expect(controller.loadClusterName(false)).to.equal(false);
+    it('if clusterName is "mycluster" and reload is false then clusterName stays the same', function () {
+      App.set('clusterName', 'mycluster');
+      controller.loadClusterName(false);
+      expect(App.ajax.send.called).to.be.false;
+      expect(App.get('clusterName')).to.equal('mycluster');
     });
 
     it('reload is true and clusterName is not empty', function () {
       controller.loadClusterName(true);
-      expect(App.ajax.send.calledOnce).to.equal(true);
+      expect(App.ajax.send.calledOnce).to.be.true;
+      expect(App.get('clusterName')).to.equal('clusterNameFromServer');
       expect(App.get('currentStackVersion')).to.equal('HDP-2.0.5');
     });
 
     it('reload is false and clusterName is empty', function () {
-      controller.set('cluster', {Clusters: {cluster_name: ''}});
+      App.set('clusterName', '');
       controller.loadClusterName(false);
-      expect(App.ajax.send.calledOnce).to.equal(true);
+      expect(App.ajax.send.calledOnce).to.be.true;
+      expect(App.get('clusterName')).to.equal('clusterNameFromServer');
       expect(App.get('currentStackVersion')).to.equal('HDP-2.0.5');
     });
 
@@ -107,9 +119,8 @@ describe('App.clusterController', function () {
     };
     it('Check cluster', function () {
       controller.loadClusterNameSuccessCallback(test_data);
-      expect(controller.get('cluster.Clusters.cluster_name')).to.equal('tdk');
-      expect(controller.get('cluster.Clusters.version')).to.equal('HDP-1.3.0');
       expect(App.get('clusterName')).to.equal('tdk');
+      expect(App.get('currentStackVersion')).to.equal('HDP-1.3.0');
     });
   });
 
@@ -189,118 +200,96 @@ describe('App.clusterController', function () {
     });
   });
 
-  describe('#gangliaUrl', function () {
+  describe('#setGangliaUrl()', function () {
+    beforeEach(function () {
+      controller.set('gangliaUrl', null);
+    });
+
     it('testMode = true', function () {
       App.testMode = true;
+      controller.setGangliaUrl();
       expect(controller.get('gangliaUrl')).to.equal('http://gangliaserver/ganglia/?t=yes');
+      expect(controller.get('isGangliaUrlLoaded')).to.be.true;
     });
-    it('Ganglia service is absent', function () {
+    it('Cluster is not loaded', function () {
       App.testMode = false;
-      controller.set('gangliaWebProtocol', '');
+      controller.set('isLoaded', false);
+      controller.setGangliaUrl();
       expect(controller.get('gangliaUrl')).to.equal(null);
     });
-    it('Ganglia doesn\'t  have any components', function () {
-      App.store.load(App.Service, {
-        id: 'GANGLIA',
-        service_name: 'GANGLIA'
-      });
-      controller.set('gangliaWebProtocol', '');
-      expect(controller.get('gangliaUrl')).to.equal(null);
-      expect(controller.get('isGangliaInstalled')).to.equal(true);
-    });
-    it('Ganglia Server doesn\'t  have host', function () {
-      App.store.load(App.HostComponent, {
-        id: 'GANGLIA_SERVER_GANGLIA_host',
-        component_name: 'GANGLIA_SERVER',
-        service_id: 'GANGLIA',
-        host_id: 'GANGLIA_host'
-      });
-      App.store.load(App.Service, {
-        id: 'GANGLIA',
-        service_name: 'GANGLIA',
-        host_components: ['GANGLIA_SERVER_GANGLIA_host']
+    it('GANGLIA_SERVER component is absent', function () {
+      controller.set('isLoaded', true);
+      App.testMode = false;
+      sinon.stub(App.HostComponent, 'find', function(){
+        return [];
       });
-      controller.set('gangliaWebProtocol', '');
+      controller.setGangliaUrl();
       expect(controller.get('gangliaUrl')).to.equal(null);
+      App.HostComponent.find.restore();
     });
     it('Ganglia Server host is "GANGLIA_host"', function () {
-      App.store.load(App.Host, {
-        id: 'GANGLIA_host',
-        host_name: 'GANGLIA_host',
-        host_components: ['GANGLIA_SERVER_GANGLIA_host'],
-        public_host_name: 'GANGLIA_host'
+      controller.set('isLoaded', true);
+      App.testMode = false;
+      sinon.stub(App.HostComponent, 'find', function(){
+        return [Em.Object.create({
+          componentName: 'GANGLIA_SERVER',
+          hostName: 'GANGLIA_host'
+        })];
       });
-      controller.set('gangliaWebProtocol', '');
-      expect(controller.get('gangliaUrl')).to.equal("http://GANGLIA_host/ganglia");
-    });
-    it('singleNodeInstall = true', function () {
-      App.set('singleNodeInstall', true);
-      controller.set('gangliaWebProtocol', '');
-      expect(controller.get('gangliaUrl')).to.equal("http://" + location.hostname + ":42080/ganglia");
-    });
-    it('singleNodeAlias is "alias"', function () {
-      App.set('singleNodeAlias', 'alias');
-      controller.set('gangliaWebProtocol', '');
-      expect(controller.get('gangliaUrl')).to.equal("http://alias:42080/ganglia");
-      App.set('singleNodeInstall', false);
-      App.set('singleNodeAlias', '');
+      sinon.spy(App.ajax, 'send');
+
+      controller.setGangliaUrl();
+      expect(App.ajax.send.calledOnce).to.be.true;
+      expect(controller.get('isGangliaUrlLoaded')).to.be.false;
+
+      App.HostComponent.find.restore();
+      App.ajax.send.restore();
     });
   });
 
-  describe('#nagiosUrl', function () {
+  describe('#setNagiosUrl()', function () {
+    beforeEach(function () {
+      controller.set('nagiosUrl', null);
+    });
+
     it('testMode = true', function () {
       App.testMode = true;
-      controller.set('nagiosWebProtocol', '');
+      controller.setNagiosUrl();
       expect(controller.get('nagiosUrl')).to.equal('http://nagiosserver/nagios');
+      expect(controller.get('isNagiosUrlLoaded')).to.be.true;
+
     });
-    it('Nagios service is absent', function () {
+    it('Cluster is not loaded', function () {
       App.testMode = false;
-      controller.set('nagiosWebProtocol', '');
+      controller.set('isLoaded', false);
+      controller.setNagiosUrl();
       expect(controller.get('nagiosUrl')).to.equal(null);
     });
-    it('Nagios doesn\'t  have any components', function () {
-      App.store.load(App.Service, {
-        id: 'NAGIOS',
-        service_name: 'NAGIOS'
-      });
-      controller.set('nagiosWebProtocol', '');
-      expect(controller.get('nagiosUrl')).to.equal(null);
-      expect(controller.get('isNagiosInstalled')).to.equal(true);
-    });
-    it('NAGIOS Server doesn\'t  have host', function () {
-      App.store.load(App.HostComponent, {
-        id: 'NAGIOS_SERVER_NAGIOS_host',
-        component_name: 'NAGIOS_SERVER',
-        service_id: 'NAGIOS',
-        host_id: 'NAGIOS_host'
-      });
-      App.store.load(App.Service, {
-        id: 'NAGIOS',
-        service_name: 'NAGIOS',
-        host_components: ['NAGIOS_SERVER_NAGIOS_host']
+    it('GANGLIA_SERVER component is absent', function () {
+      controller.set('isLoaded', true);
+      App.testMode = false;
+      sinon.stub(App.HostComponent, 'find', function(){
+        return [];
       });
-      controller.set('nagiosWebProtocol', '');
+      controller.setNagiosUrl();
       expect(controller.get('nagiosUrl')).to.equal(null);
+      App.HostComponent.find.restore();
     });
-    it('NAGIOS Server host is "NAGIOS_host"', function () {
-      App.store.load(App.Host, {
-        id: 'NAGIOS_host',
-        host_name: 'NAGIOS_host',
-        host_components: ['NAGIOS_SERVER_NAGIOS_host'],
-        public_host_name: 'NAGIOS_host'
+    it('Ganglia Server host is "NAGIOS_host"', function () {
+      controller.set('isLoaded', true);
+      App.testMode = false;
+      sinon.stub(App.HostComponent, 'find', function(){
+        return [Em.Object.create({
+          componentName: 'NAGIOS_SERVER',
+          hostName: 'NAGIOS_host'
+        })];
       });
-      controller.set('nagiosWebProtocol', '');
-      expect(controller.get('nagiosUrl')).to.equal("http://NAGIOS_host/nagios");
-    });
-    it('singleNodeInstall = true', function () {
-      App.set('singleNodeInstall', true);
-      controller.set('nagiosWebProtocol', '');
-      expect(controller.get('nagiosUrl')).to.equal("http://:42080/nagios");
-    });
-    it('singleNodeAlias is "alias"', function () {
-      App.set('singleNodeAlias', 'alias');
-      controller.set('nagiosWebProtocol', '');
-      expect(controller.get('nagiosUrl')).to.equal("http://alias:42080/nagios");
+      sinon.spy(App.ajax, 'send');
+      controller.setNagiosUrl();
+      expect(App.ajax.send.calledOnce).to.be.true;
+      expect(controller.get('isNagiosUrlLoaded')).to.be.false;
+      App.ajax.send.restore();
+      App.HostComponent.find.restore();
     });
   });
 
@@ -368,60 +357,78 @@ describe('App.clusterController', function () {
     });
   });
 
-  describe('#startPolling()', function () {
 
-    beforeEach(function () {
-      sinon.spy(App.updater, 'run');
-    });
-    afterEach(function () {
-      App.updater.run.restore();
+  describe('#setGangliaUrlSuccessCallback()', function () {
+
+    it('Query return no hosts', function () {
+      controller.setGangliaUrlSuccessCallback({items: []});
+      expect(controller.get('gangliaUrl')).to.equal(null);
+      expect(controller.get('isGangliaUrlLoaded')).to.be.true;
     });
-    it('isWorking = false', function () {
-      controller.set('isWorking', false);
-      expect(App.updater.run.calledOnce).to.equal(false);
-      expect(controller.startPolling()).to.equal(false);
+    it('App.singleNodeInstall is true', function () {
+      controller.reopen({
+        gangliaWebProtocol: 'http'
+      });
+      App.set('singleNodeInstall', true);
+      App.set('singleNodeAlias', 'localhost');
+      controller.setGangliaUrlSuccessCallback({items: [{
+        Hosts: {
+          public_host_name: 'host1'
+        }
+      }]});
+      expect(controller.get('gangliaUrl')).to.equal('http://localhost:42080/ganglia');
+      expect(controller.get('isGangliaUrlLoaded')).to.be.true;
     });
-
-    it('isWorking = true', function () {
-      controller.set('isWorking', true);
-      expect(App.updater.run.calledOnce).to.equal(true);
-      expect(controller.startPolling()).to.equal(true);
+    it('App.singleNodeInstall is false', function () {
+      controller.reopen({
+        gangliaWebProtocol: 'http'
+      });
+      App.set('singleNodeInstall', false);
+      App.set('singleNodeAlias', 'localhost');
+      controller.setGangliaUrlSuccessCallback({items: [{
+        Hosts: {
+          public_host_name: 'host1'
+        }
+      }]});
+      expect(controller.get('gangliaUrl')).to.equal('http://host1/ganglia');
+      expect(controller.get('isGangliaUrlLoaded')).to.be.true;
     });
   });
 
-  describe('#clusterName', function () {
-    var testCases = [
-      {
-        title: 'if cluster is null then clusterName should be null',
-        data: null,
-        result: null
-      },
-      {
-        title: 'if cluster.Clusters.cluster_name is null then clusterName should be null',
-        data: {
-          Clusters: {
-            cluster_name: null
-          }
-        },
-        result: null
-      },
-      {
-        title: 'if cluster.Clusters.cluster_name is null then clusterName should be null',
-        data: {
-          Clusters: {
-            cluster_name: 'mycluster'
-          }
-        },
-        result: 'mycluster'
-      }
-    ];
+  describe('#setNagiosUrlSuccessCallback()', function () {
 
-    testCases.forEach(function (test) {
-      it(test.title, function () {
-        controller.set('cluster', test.data);
-        expect(controller.get('clusterName')).to.equal(test.result);
+    it('Query return no hosts', function () {
+      controller.setNagiosUrlSuccessCallback({items: []});
+      expect(controller.get('nagiosUrl')).to.equal(null);
+      expect(controller.get('isNagiosUrlLoaded')).to.be.true;
+    });
+    it('App.singleNodeInstall is true', function () {
+      controller.reopen({
+        nagiosWebProtocol: 'http'
       });
+      App.set('singleNodeInstall', true);
+      App.set('singleNodeAlias', 'localhost');
+      controller.setNagiosUrlSuccessCallback({items: [{
+        Hosts: {
+          public_host_name: 'host1'
+        }
+      }]});
+      expect(controller.get('nagiosUrl')).to.equal('http://localhost:42080/nagios');
+      expect(controller.get('isNagiosUrlLoaded')).to.be.true;
+    });
+    it('App.singleNodeInstall is false', function () {
+      controller.reopen({
+        nagiosWebProtocol: 'http'
+      });
+      App.set('singleNodeInstall', false);
+      App.set('singleNodeAlias', 'localhost');
+      controller.setNagiosUrlSuccessCallback({items: [{
+        Hosts: {
+          public_host_name: 'host1'
+        }
+      }]});
+      expect(controller.get('nagiosUrl')).to.equal('http://host1/nagios');
+      expect(controller.get('isNagiosUrlLoaded')).to.be.true;
     });
   });
-
 });

+ 0 - 46
ambari-web/test/controllers/global/update_controller_test.js

@@ -74,52 +74,6 @@ describe('App.UpdateController', function () {
     });
   });
 
-  describe('#updateHostConditionally()', function () {
-    var context = {
-      callback: function(){}
-    };
-
-    beforeEach(function () {
-      sinon.stub(controller, 'updateHost', Em.K);
-      sinon.spy(context, 'callback');
-    });
-    afterEach(function () {
-      controller.updateHost.restore();
-      context.callback.restore();
-    });
-
-    it('location is empty', function () {
-      controller.set('location', '');
-      controller.updateHostConditionally(context.callback);
-      expect(controller.updateHost.called).to.equal(false);
-      expect(context.callback.called).to.equal(true);
-    });
-    it('location is "/main/dashboard"', function () {
-      controller.set('location', '/main/dashboard');
-      controller.updateHostConditionally(context.callback);
-      expect(controller.updateHost.called).to.equal(false);
-      expect(context.callback.called).to.equal(true);
-    });
-    it('location is "/main/hosts"', function () {
-      controller.set('location', '/main/hosts');
-      controller.updateHostConditionally(context.callback);
-      expect(controller.updateHost.called).to.equal(true);
-      expect(context.callback.called).to.equal(false);
-    });
-    it('location is "/main/charts/heatmap"', function () {
-      controller.set('location', '/main/charts/heatmap');
-      controller.updateHostConditionally(context.callback);
-      expect(controller.updateHost.called).to.equal(true);
-      expect(context.callback.called).to.equal(false);
-    });
-    it('location is "/main/hosts/host1"', function () {
-      controller.set('location', '/main/hosts/host1');
-      controller.updateHostConditionally(context.callback);
-      expect(controller.updateHost.called).to.equal(true);
-      expect(context.callback.called).to.equal(false);
-    });
-  });
-
   describe('#updateServiceMetricConditionally()', function () {
     var context = {
       callback: function(){}

+ 136 - 102
ambari-web/test/controllers/main/admin/highAvailability_controller_test.js

@@ -29,11 +29,17 @@ describe('App.MainAdminHighAvailabilityController', function () {
 
   describe('#enableHighAvailability()', function () {
 
+    var hostComponents = [];
+
     beforeEach(function () {
+      sinon.stub(App.HostComponent, 'find', function(){
+        return hostComponents;
+      });
       sinon.spy(controller, "showErrorPopup");
     });
     afterEach(function () {
       controller.showErrorPopup.restore();
+      App.HostComponent.find.restore();
     });
 
     it('Security enabled', function () {
@@ -41,41 +47,105 @@ describe('App.MainAdminHighAvailabilityController', function () {
       expect(controller.enableHighAvailability()).to.be.false;
       expect(controller.showErrorPopup.calledOnce).to.be.true;
     });
-    it('less than 3 ZooKeeper Servers', function () {
+    it('NAMENODE in INSTALLED state', function () {
       controller.set('securityEnabled', false);
-      App.store.load(App.HostComponent, {
-        id: "NAMENODE_host1",
-        component_name: 'NAMENODE',
-        work_status: 'STARTED'
+      hostComponents = [
+        Em.Object.create({
+          componentName: 'NAMENODE',
+          workStatus: 'INSTALLED'
+        }),
+        Em.Object.create({
+          componentName: 'ZOOKEEPER_SERVER',
+          workStatus: 'INSTALLED'
+        }),
+        Em.Object.create({
+          componentName: 'ZOOKEEPER_SERVER',
+          workStatus: 'INSTALLED'
+        }),
+        Em.Object.create({
+          componentName: 'ZOOKEEPER_SERVER',
+          workStatus: 'INSTALLED'
+        })
+      ];
+
+      sinon.stub(App.router, 'get', function(){
+        return 3;
       });
       expect(controller.enableHighAvailability()).to.be.false;
       expect(controller.showErrorPopup.calledOnce).to.be.true;
-      App.store.loadMany(App.HostComponent, [
-        {
-          id: "ZOOKEEPER_SERVER_host1",
-          component_name: 'ZOOKEEPER_SERVER'
-        },
-        {
-          id: "ZOOKEEPER_SERVER_host2",
-          component_name: 'ZOOKEEPER_SERVER'
-        },
-        {
-          id: "ZOOKEEPER_SERVER_host3",
-          component_name: 'ZOOKEEPER_SERVER'
-        }
-      ]);
+      App.router.get.restore();
     });
-    it('Security disabled and all checks passed', function () {
-      App.router.set('transitionTo', function () {
+    it('Cluster has less than 3 ZOOKEPER_SERVER components', function () {
+      hostComponents = [
+        Em.Object.create({
+          componentName: 'NAMENODE',
+          workStatus: 'STARTED'
+        })
+      ];
+
+      sinon.stub(App.router, 'get', function(){
+        return 3;
       });
-      expect(controller.enableHighAvailability()).to.be.true;
-      expect(controller.showErrorPopup.called).to.be.false;
+      expect(controller.enableHighAvailability()).to.be.false;
+      expect(controller.showErrorPopup.called).to.be.true;
+      App.router.get.restore();
     });
-    it('NameNode is started', function () {
-      App.HostComponent.find('NAMENODE_host1').set('workStatus', 'INSTALLED');
+    it('total hosts number less than 3', function () {
+      controller.set('securityEnabled', false);
+      hostComponents = [
+        Em.Object.create({
+          componentName: 'NAMENODE',
+          workStatus: 'STARTED'
+        }),
+        Em.Object.create({
+          componentName: 'ZOOKEEPER_SERVER',
+          workStatus: 'INSTALLED'
+        }),
+        Em.Object.create({
+          componentName: 'ZOOKEEPER_SERVER',
+          workStatus: 'INSTALLED'
+        }),
+        Em.Object.create({
+          componentName: 'ZOOKEEPER_SERVER',
+          workStatus: 'INSTALLED'
+        })
+      ];
+      sinon.stub(App.router, 'get', function () {
+        return 1;
+      });
       expect(controller.enableHighAvailability()).to.be.false;
       expect(controller.showErrorPopup.calledOnce).to.be.true;
-      App.HostComponent.find('NAMENODE_host1').set('workStatus', 'STARTED');
+      App.router.get.restore();
+    });
+    it('All checks passed', function () {
+      controller.set('securityEnabled', false);
+      hostComponents = [
+        Em.Object.create({
+          componentName: 'NAMENODE',
+          workStatus: 'STARTED'
+        }),
+        Em.Object.create({
+          componentName: 'ZOOKEEPER_SERVER',
+          workStatus: 'INSTALLED'
+        }),
+        Em.Object.create({
+          componentName: 'ZOOKEEPER_SERVER',
+          workStatus: 'INSTALLED'
+        }),
+        Em.Object.create({
+          componentName: 'ZOOKEEPER_SERVER',
+          workStatus: 'INSTALLED'
+        })
+      ];
+      sinon.stub(App.router, 'get', function(){
+        return 3;
+      });
+      sinon.spy(App.router, 'transitionTo');
+      expect(controller.enableHighAvailability()).to.be.true;
+      expect(App.router.transitionTo.calledWith('main.admin.enableHighAvailability')).to.be.true;
+      expect(controller.showErrorPopup.calledOnce).to.be.false;
+      App.router.transitionTo.restore();
+      App.router.get.restore();
     });
   });
 
@@ -130,7 +200,7 @@ describe('App.MainAdminHighAvailabilityController', function () {
       controller.getSecurityStatusFromServerSuccessCallback(data);
       expect(controller.showErrorPopup.calledOnce).to.be.true;
     });
-    it('desired_configs does not have "global"', function () {
+    it('desired_configs does not have "hadoop-env"', function () {
       var data = {
         Clusters: {
           desired_configs: {
@@ -141,11 +211,11 @@ describe('App.MainAdminHighAvailabilityController', function () {
       controller.getSecurityStatusFromServerSuccessCallback(data);
       expect(controller.showErrorPopup.calledOnce).to.be.true;
     });
-    it('desired_configs does not have "global"', function () {
+    it('desired_configs has "hadoop-env"', function () {
       var data = {
         Clusters: {
           desired_configs: {
-            'global': {
+            'hadoop-env': {
               tag: 1
             }
           }
@@ -178,7 +248,7 @@ describe('App.MainAdminHighAvailabilityController', function () {
       controller.getSecurityStatusFromServerSuccessCallback(data);
       expect(controller.showErrorPopup.calledOnce).to.be.true;
     });
-    it('desired_configs does not have "global"', function () {
+    it('desired_configs does not have "hadoop-env"', function () {
       var data = {
         Clusters: {
           desired_configs: {
@@ -189,11 +259,11 @@ describe('App.MainAdminHighAvailabilityController', function () {
       controller.getSecurityStatusFromServerSuccessCallback(data);
       expect(controller.showErrorPopup.calledOnce).to.be.true;
     });
-    it('desired_configs does not have "global"', function () {
+    it('desired_configs has "hadoop-env"', function () {
       var data = {
         Clusters: {
           desired_configs: {
-            'global': {
+            'hadoop-env': {
               tag: 1
             }
           }
@@ -222,85 +292,49 @@ describe('App.MainAdminHighAvailabilityController', function () {
   });
 
   describe('#getServiceConfigsFromServer()', function () {
-
-    it('properties is null', function () {
-      App.router.set('configurationController', Em.Object.create({
-        getConfigsByTags: function () {
-          return this.get('data');
-        },
-        data: [
-          {
-            tag: 1,
-            properties: null
+    it('configs present', function () {
+      sinon.stub(App.router.get('configurationController'), 'getConfigsByTags', function () {
+        return {
+          done: function (callback) {
+            callback([{tag: '1'}]);
           }
-        ]
-      }));
-      controller.getServiceConfigsFromServer();
-      expect(controller.get('dataIsLoaded')).to.be.true;
-      expect(controller.get('securityEnabled')).to.be.false;
-    });
-    it('"security_enabled" config is absent', function () {
-      App.router.set('configurationController.data', [
-        {
-          tag: 1,
-          properties: {}
         }
-      ]);
+      });
+      sinon.stub(controller, 'isSecurityEnabled', function(){
+        return true;
+      });
+      controller.set('tag', '1');
       controller.getServiceConfigsFromServer();
-      expect(controller.get('dataIsLoaded')).to.be.true;
-      expect(controller.get('securityEnabled')).to.be.false;
-    });
-    it('"security_enabled" is false', function () {
-      App.router.set('configurationController.data', [
+
+      expect(App.router.get('configurationController').getConfigsByTags.calledWith([
         {
-          tag: 1,
-          properties: {
-            'security_enabled': false
-          }
+          siteName: "hadoop-env",
+          tagName: '1'
         }
-      ]);
-      controller.getServiceConfigsFromServer();
+      ])).to.be.true;
+      expect(controller.isSecurityEnabled.calledOnce).to.be.true;
       expect(controller.get('dataIsLoaded')).to.be.true;
-      expect(controller.get('securityEnabled')).to.be.false;
+      expect(controller.get('securityEnabled')).to.be.true;
+
+      App.router.get('configurationController').getConfigsByTags.restore();
+      controller.isSecurityEnabled.restore();
     });
-    it('"security_enabled" is "false"', function () {
-      App.router.set('configurationController.data', [
-        {
-          tag: 1,
-          properties: {
-            'security_enabled': "false"
-          }
-        }
-      ]);
-      controller.getServiceConfigsFromServer();
-      expect(controller.get('dataIsLoaded')).to.be.true;
-      expect(controller.get('securityEnabled')).to.be.false;
+  });
+  describe('#isSecurityEnabled()', function () {
+    it('properties is null', function () {
+      expect(controller.isSecurityEnabled(null)).to.be.false;
     });
-    it('"security_enabled" is "true"', function () {
-      App.router.set('configurationController.data', [
-        {
-          tag: 1,
-          properties: {
-            'security_enabled': "true"
-          }
-        }
-      ]);
-      controller.getServiceConfigsFromServer();
-      expect(controller.get('dataIsLoaded')).to.be.true;
-      expect(controller.get('securityEnabled')).to.be.true;
+    it('properties is empty object', function () {
+      expect(controller.isSecurityEnabled({})).to.be.false;
     });
-    it('"security_enabled" is true', function () {
-      App.router.set('configurationController.data', [
-        {
-          tag: 1,
-          properties: {
-            'security_enabled': true
-          }
-        }
-      ]);
-      controller.getServiceConfigsFromServer();
-      expect(controller.get('dataIsLoaded')).to.be.true;
-      expect(controller.get('securityEnabled')).to.be.true;
+    it('security_enabled is false', function () {
+      expect(controller.isSecurityEnabled({security_enabled: false})).to.be.false;
+    });
+    it('security_enabled is true', function () {
+      expect(controller.isSecurityEnabled({security_enabled: true})).to.be.true;
+    });
+    it('security_enabled is "true"', function () {
+      expect(controller.isSecurityEnabled({security_enabled: 'true'})).to.be.true;
     });
   });
 });

+ 11 - 14
ambari-web/test/controllers/main/admin/misc_controller_test.js

@@ -194,32 +194,29 @@ describe('App.MainAdminMiscController', function () {
       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 () {
+    it('proxyuser_group config defined and isHadoop21Stack is true', 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");
+      sinon.stub(App, 'get', function(){
+        return true;
+      });
       controller.setProxyUserGroupLabel(misc_configs);
       expect(misc_configs.findProperty('name', 'proxyuser_group').get('displayName')).to.equal('test');
+      App.get.restore();
     });
-    it('if currentStackVersionNumber higher than 2.1 then label should stay the same', function () {
+    it('proxyuser_group config defined and isHadoop21Stack is false', function () {
       var misc_configs = [Em.Object.create({
         name: 'proxyuser_group',
         displayName: 'test'
       })];
-      App.set('currentStackVersion', "HDP-2.2");
+      sinon.stub(App, 'get', function(){
+        return false;
+      });
       controller.setProxyUserGroupLabel(misc_configs);
-      expect(misc_configs.findProperty('name', 'proxyuser_group').get('displayName')).to.equal('test');
+      expect(misc_configs.findProperty('name', 'proxyuser_group').get('displayName')).to.equal('Proxy group for Hive, WebHCat and Oozie');
+      App.get.restore();
     });
   })
 });

+ 1 - 1
ambari-web/test/controllers/main/admin/security/add/step2_test.js

@@ -313,7 +313,7 @@ describe('App.MainAdminSecurityAddStep2Controller', function () {
           hostComponents: [
             Em.Object.create({
               componentName: 'comp1',
-              host: {hostName: 'host1'}
+              hostName: 'host1'
             })
           ]
         });

+ 4 - 7
ambari-web/test/controllers/main/admin/security/add/step3_test.js

@@ -21,6 +21,7 @@ var App = require('app');
 
 require('controllers/main/admin/security/add/step3');
 var stringUtils = require('utils/string_utils');
+var modelSetup = require('test/init_model_test');
 
 describe('App.MainAdminSecurityAddStep3Controller', function () {
 
@@ -67,21 +68,16 @@ describe('App.MainAdminSecurityAddStep3Controller', function () {
       });
     });
     afterEach(function(){
-      App.Host.find.restore();
       controller.getSecurityUsers.restore();
     });
 
     it('No hosts installed', function() {
-      sinon.stub(App.Host, 'find', function(){
-        return [];
-      });
+      controller.set('hosts', []);
       controller.loadStep();
       expect(controller.get('hostComponents')).to.be.empty;
     });
     it('One host installed', function () {
-      sinon.stub(App.Host, 'find', function () {
-        return [Em.Object.create({hostName: 'host1'})];
-      });
+      controller.set('hosts', [Em.Object.create({hostName: 'host1'})]);
       sinon.stub(controller, 'setMandatoryConfigs', function (result) {
         return result.push('setMandatoryConfigs');
       });
@@ -120,6 +116,7 @@ describe('App.MainAdminSecurityAddStep3Controller', function () {
   });
 
   describe('#setComponentsConfig()', function() {
+    modelSetup.setupStackServiceComponent();
 
     beforeEach(function(){
       controller.set('content.serviceConfigProperties', [

+ 5 - 1
ambari-web/test/controllers/main/admin/security/add/step4_test.js

@@ -151,6 +151,10 @@ describe('App.MainAdminSecurityAddStep4Controller', function () {
 
     beforeEach(function () {
       controller.get('commands').clear();
+      sinon.stub(App.clusterStatus, 'setClusterStatus', Em.K);
+    });
+    afterEach(function () {
+      App.clusterStatus.setClusterStatus.restore();
     });
 
     it('No YARN in secureServices', function() {
@@ -765,7 +769,7 @@ describe('App.MainAdminSecurityAddStep4Controller', function () {
           isLoaded: true,
           hostComponents: [Em.Object.create({
             componentName: 'comp1',
-            host: {hostName: 'host1'}
+            hostName: 'host1'
           })]
         });
       });

+ 3 - 8
ambari-web/test/controllers/main/admin/security/disable_test.js

@@ -150,11 +150,6 @@ describe('App.MainAdminSecurityDisableController', function () {
   });
 
   describe('#syncStopServicesCommand()', function () {
-    App.router = Em.Object.create({
-      backgroundOperationsController: Em.Object.create({
-        services: []
-      })
-    });
 
     it('No background operations', function () {
       controller.set('commands', [Em.Object.create({
@@ -262,17 +257,17 @@ describe('App.MainAdminSecurityDisableController', function () {
 
       expect(controller.manageSecureConfigs()).to.be.true;
     });
-    it('serviceConfigTags has global site', function () {
+    it('serviceConfigTags has hadoop-env site', function () {
       controller.set('serviceConfigTags', [
         {
-          siteName: 'global',
+          siteName: 'hadoop-env',
           configs: {}
         }
       ]);
 
       expect(controller.manageSecureConfigs()).to.be.true;
       expect(controller.deleteDisabledGlobalConfigs.calledOnce).to.be.true;
-      expect(controller.get('serviceConfigTags').findProperty('siteName', 'global').configs.security_enabled).to.equal('false');
+      expect(controller.get('serviceConfigTags').findProperty('siteName', 'hadoop-env').configs.security_enabled).to.equal('false');
     });
     it('serviceConfigTags has site.xml', function () {
       controller.set('serviceConfigTags', [

+ 4 - 4
ambari-web/test/controllers/main/admin/security_test.js

@@ -118,7 +118,7 @@ describe('App.MainAdminSecurityController', function () {
       expect(controller.showSecurityErrorPopup.called).to.equal(true);
     });
 
-    it('global is missing', function () {
+    it('hadoop-env is missing', function () {
       var data = {Clusters: {
         desired_configs: {
           'hdfs-site': {}
@@ -128,19 +128,19 @@ describe('App.MainAdminSecurityController', function () {
       expect(controller.showSecurityErrorPopup.called).to.equal(true);
     });
 
-    it('global and hdfs-site are correct', function () {
+    it('hadoop-env and hdfs-site are correct', function () {
       var data = {Clusters: {
         desired_configs: {
           'hdfs-site': {
             tag: 1
           },
-          'global': {
+          'hadoop-env': {
             tag: 2
           }
         }
       }};
       controller.getSecurityStatusFromServerSuccessCallback(data);
-      expect(controller.get('tag.global')).to.equal(2);
+      expect(controller.get('tag.hadoop-env')).to.equal(2);
       expect(controller.get('tag.hdfs-site')).to.equal(1);
       expect(controller.getServiceConfigsFromServer.called).to.equal(true);
     });

+ 30 - 0
ambari-web/test/init_router_test.js

@@ -0,0 +1,30 @@
+/**
+ * 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');
+
+//mock App.router object
+App.router = Em.Object.create({
+  transitionTo: Em.K,
+  configurationController: Em.Object.create({
+    getConfigsByTags: Em.K
+  }),
+  backgroundOperationsController: Em.Object.create({
+    services: []
+  })
+});