Explorar o código

AMBARI-7013. Fix UI Unit tests. (onechiporenko)

Oleg Nechiporenko %!s(int64=10) %!d(string=hai) anos
pai
achega
6b7e796ab1

+ 1 - 0
ambari-web/app/controllers/wizard/step3_controller.js

@@ -1138,6 +1138,7 @@ App.WizardStep3Controller = Em.Controller.extend({
    * @method repoToAgentOsType
    */
   repoToAgentOsType : function (repoType) {
+    /* istanbul ignore next */
     switch (repoType) {
       case "redhat6":
         return ["redhat6", "centos6", "oraclelinux6", "rhel6"];

+ 5 - 33
ambari-web/test/controllers/main/dashboard/config_history_controller_test.js

@@ -28,26 +28,21 @@ describe('MainConfigHistoryController', function () {
   describe('#realUrl', function () {
     it('cluster name is empty', function () {
       App.set('clusterName', '');
-      expect(controller.get('realUrl')).to.equal('/api/v1/clusters//configurations/serviceconfigversions?<parameters>fields=serviceconfigversion,user,group_id,group_name,createtime,service_name,service_config_version_note&minimal_response=true');
+      expect(controller.get('realUrl')).to.equal('/api/v1/clusters//configurations/service_config_versions?<parameters>fields=service_config_version,user,group_id,group_name,is_current,createtime,service_name,service_config_version_note&minimal_response=true');
     });
     it('cluster name is "mycluster"', function () {
       App.set('clusterName', 'mycluster');
-      expect(controller.get('realUrl')).to.equal('/api/v1/clusters/mycluster/configurations/serviceconfigversions?<parameters>fields=serviceconfigversion,user,group_id,group_name,createtime,service_name,service_config_version_note&minimal_response=true');
+      expect(controller.get('realUrl')).to.equal('/api/v1/clusters/mycluster/configurations/service_config_versions?<parameters>fields=service_config_version,user,group_id,group_name,is_current,createtime,service_name,service_config_version_note&minimal_response=true');
     });
   });
   describe('#load()', function () {
     it('', function () {
       sinon.stub(controller, 'updateTotalCounter', Em.K);
-      sinon.stub(controller, 'loadCurrentVersions', function(){
-        return {complete: Em.K};
-      });
 
       controller.load();
       expect(controller.updateTotalCounter.calledOnce).to.be.true;
-      expect(controller.loadCurrentVersions.calledOnce).to.be.true;
 
       controller.updateTotalCounter.restore();
-      controller.loadCurrentVersions.restore();
     });
   });
   describe('#loadConfigVersionsToModel()', function () {
@@ -69,16 +64,7 @@ describe('MainConfigHistoryController', function () {
       App.HttpClient.get.restore();
     });
   });
-  describe('#loadCurrentVersions()', function () {
-    it('', function () {
-      sinon.stub(App.ajax, 'send', Em.K);
 
-      controller.loadCurrentVersions();
-      expect(App.ajax.send.calledOnce).to.be.true;
-
-      App.ajax.send.restore();
-    });
-  });
   describe('#updateTotalCounter()', function () {
     it('', function () {
       sinon.stub(App.ajax, 'send', Em.K);
@@ -89,21 +75,7 @@ describe('MainConfigHistoryController', function () {
       App.ajax.send.restore();
     });
   });
-  describe('#loadCurrentVersionsSuccess()', function () {
-    it('', function () {
-      var data = {
-        Clusters: {
-          desired_serviceconfigversions: {
-            'SERVICE': {
-              serviceconfigversion: 1
-            }
-          }
-        }
-      };
-      controller.loadCurrentVersionsSuccess(data);
-      expect(App.cache['currentConfigVersions']).to.eql({SERVICE_1: true});
-    });
-  });
+
   describe('#updateTotalCounterSuccess()', function () {
     it('', function () {
       controller.updateTotalCounterSuccess({itemTotal: 1});
@@ -136,14 +108,14 @@ describe('MainConfigHistoryController', function () {
         if ('testMode' === k) return false;
         return Em.get(App, k);
       });
-      expect(controller.getUrl()).to.equal('/api/v1/clusters/mycluster/configurations/serviceconfigversions?fields=serviceconfigversion,user,group_id,group_name,createtime,service_name,service_config_version_note&minimal_response=true');
+      expect(controller.getUrl()).to.equal('/api/v1/clusters/mycluster/configurations/service_config_versions?fields=service_config_version,user,group_id,group_name,is_current,createtime,service_name,service_config_version_note&minimal_response=true');
     });
     it('query params is correct', function () {
       sinon.stub(App, 'get', function(k) {
         if ('testMode' === k) return false;
         return Em.get(App, k);
       });
-      expect(controller.getUrl({})).to.equal('/api/v1/clusters/mycluster/configurations/serviceconfigversions?paramsfields=serviceconfigversion,user,group_id,group_name,createtime,service_name,service_config_version_note&minimal_response=true');
+      expect(controller.getUrl({})).to.equal('/api/v1/clusters/mycluster/configurations/service_config_versions?paramsfields=service_config_version,user,group_id,group_name,is_current,createtime,service_name,service_config_version_note&minimal_response=true');
     });
   });
 

+ 325 - 0
ambari-web/test/controllers/wizard/step3_test.js

@@ -1364,6 +1364,107 @@ describe('App.WizardStep3Controller', function () {
         });
       });
 
+    it('should parse umask warnings', function() {
+
+      var items = [
+        {Hosts:{host_name: 'c1', last_agent_env: {umask: 18}}},
+        {Hosts:{host_name: 'c2', last_agent_env: {umask: 1}}}
+      ];
+
+      c.parseWarnings({items: items});
+      var warnings = c.get('warnings');
+      expect(warnings.length).to.equal(1);
+      expect(warnings[0].hosts).to.eql(['c2']);
+      expect(warnings[0].onSingleHost).to.equal(true);
+
+    });
+
+    it('should parse umask warnings (2)', function() {
+
+      var items = [
+        {Hosts:{host_name: 'c1', last_agent_env: {umask: 8}}},
+        {Hosts:{host_name: 'c2', last_agent_env: {umask: 1}}}
+      ];
+
+      c.parseWarnings({items: items});
+      var warnings = c.get('warnings');
+      expect(warnings.length).to.equal(2);
+      expect(warnings.mapProperty('hosts')).to.eql([['c1'], ['c2']]);
+
+    });
+
+
+    it('should parse firewall warnings', function() {
+
+      var items = [
+        {Hosts:{host_name: 'c1', last_agent_env: {iptablesIsRunning: true}}},
+        {Hosts:{host_name: 'c2', last_agent_env: {iptablesIsRunning: false}}}
+      ];
+
+      c.parseWarnings({items: items});
+      var warnings = c.get('warnings');
+      expect(warnings.length).to.equal(1);
+      expect(warnings[0].hosts).to.eql(['c1']);
+      expect(warnings[0].onSingleHost).to.equal(true);
+
+    });
+
+    it('should parse firewall warnings (2)', function() {
+
+      var items = [
+        {Hosts:{host_name: 'c1', last_agent_env: {iptablesIsRunning: true}}},
+        {Hosts:{host_name: 'c2', last_agent_env: {iptablesIsRunning: true}}}
+      ];
+
+      c.parseWarnings({items: items});
+      var warnings = c.get('warnings');
+      expect(warnings.length).to.equal(1);
+      expect(warnings[0].hosts).to.eql(['c1','c2']);
+      expect(warnings[0].onSingleHost).to.equal(false);
+
+    });
+
+    it('should parse reverseLookup warnings', function() {
+
+      var items = [
+        {Hosts:{host_name: 'c1', last_agent_env: {reverseLookup: true}}}
+      ];
+
+      c.parseWarnings({items: items});
+      var warnings = c.get('warnings');
+      expect(warnings.length).to.equal(0);
+
+    });
+
+    it('should parse reverseLookup warnings (2)', function() {
+
+      var items = [
+        {Hosts:{host_name: 'c1', last_agent_env: {reverseLookup: false}}}
+      ];
+
+      c.parseWarnings({items: items});
+      var warnings = c.get('warnings');
+      expect(warnings.length).to.equal(1);
+      expect(warnings[0].hosts).to.eql(['c1']);
+      expect(warnings[0].onSingleHost).to.equal(true);
+
+    });
+
+    it('should parse reverseLookup warnings (3)', function() {
+
+      var items = [
+        {Hosts:{host_name: 'c1', last_agent_env: {reverseLookup: false}}},
+        {Hosts:{host_name: 'c2', last_agent_env: {reverseLookup: false}}}
+      ];
+
+      c.parseWarnings({items: items});
+      var warnings = c.get('warnings');
+      expect(warnings.length).to.equal(1);
+      expect(warnings[0].hosts).to.eql(['c1','c2']);
+      expect(warnings[0].onSingleHost).to.equal(false);
+
+    });
+
   });
 
   describe('#navigateStep', function() {
@@ -1710,4 +1811,228 @@ describe('App.WizardStep3Controller', function () {
     });
   });
 
+  describe('#getJDKName', function() {
+
+    beforeEach(function() {
+      sinon.stub($, 'ajax', Em.K);
+      sinon.stub(App, 'get', function(k) {
+        if ('testMode' === k) return false;
+        return Em.get(App, k);
+      });
+    });
+
+    afterEach(function() {
+      $.ajax.restore();
+      App.get.restore();
+    });
+
+    it('should do proper request to ambari-server', function() {
+      c.getJDKName();
+      expect($.ajax.args[0][0].type).to.contain('GET');
+      expect($.ajax.args[0][0].url).to.contain('/services/AMBARI/components/AMBARI_SERVER?fields=RootServiceComponents/properties/jdk.name,RootServiceComponents/properties/java.home,RootServiceComponents/properties/jdk_location');
+    });
+
+  });
+
+  describe('#getJDKNameSuccessCallback', function() {
+
+    it('should set proper data to controller properties', function() {
+
+      var expected = {
+          name: 'name',
+          home: 'home',
+          location: 'location'
+        },
+        data = {
+        RootServiceComponents: {
+          properties: {
+            'jdk.name': expected.name,
+            'java.home': expected.home,
+            'jdk_location': expected.location
+          }
+        }
+      };
+
+      c.getJDKNameSuccessCallback(data);
+      expect(c.get('needJDKCheckOnHosts')).to.equal(false);
+      expect(c.get('jdkLocation')).to.equal(expected.location);
+      expect(c.get('javaHome')).to.equal(expected.home);
+    });
+
+  });
+
+  describe('#doCheckJDK', function() {
+
+    beforeEach(function() {
+      sinon.stub($, 'ajax', Em.K);
+      sinon.stub(c, 'setRegistrationInProgressOnce', Em.K);
+      sinon.stub(App, 'get', function(k) {
+        if ('testMode' === k) return false;
+        return Em.get(App, k);
+      });
+    });
+
+    afterEach(function() {
+      $.ajax.restore();
+      c.setRegistrationInProgressOnce.restore();
+      App.get.restore();
+    });
+
+    it('should do proper request to the ambari-server', function() {
+
+      var bootHosts = [{name: 'n1'}, {name: 'n2'}],
+        javaHome = '/java',
+        jdkLocation = '/jdk';
+      c.reopen({
+        bootHosts: bootHosts,
+        javaHome: javaHome,
+        jdkLocation: jdkLocation
+      });
+      c.doCheckJDK();
+      var request = $.ajax.args[0][0], data = JSON.parse(request.data);
+      expect(request.type).to.equal('POST');
+      expect(request.url).to.contain('/requests');
+      expect(data.RequestInfo.parameters.java_home).to.equal(javaHome);
+      expect(data.RequestInfo.parameters.jdk_location).to.equal(jdkLocation);
+      expect(data['Requests/resource_filters'][0].hosts).to.equal('n1,n2');
+    });
+
+  });
+
+  describe('#doCheckJDKsuccessCallback', function() {
+
+    beforeEach(function() {
+      sinon.stub($, 'ajax', Em.K);
+      sinon.stub(App, 'get', function(k) {
+        if ('testMode' === k) return false;
+        return Em.get(App, k);
+      });
+    });
+
+    afterEach(function() {
+      $.ajax.restore();
+      App.get.restore();
+    });
+
+    it('should set jdkRequestIndex if data provided', function() {
+
+      var data = {
+          href: '/a/b/c'
+        },
+        expected = 'c';
+      c.set('jdkRequestIndex', null);
+      c.doCheckJDKsuccessCallback(data);
+      expect(c.get('jdkRequestIndex')).to.equal(expected);
+    });
+
+    it('should set isJDKWarningsLoaded to true if jdkCategoryWarnings is not null', function() {
+
+      var data = null,
+        expected = true;
+      c.set('isJDKWarningsLoaded', false);
+      c.set('jdkCategoryWarnings', {});
+      c.doCheckJDKsuccessCallback(data);
+      expect(c.get('isJDKWarningsLoaded')).to.equal(expected);
+    });
+
+    it('should do propert request to ambari-server', function() {
+
+      var data = null,
+        jdkRequestIndex = 'jdkRequestIndex',
+        url = '/requests/' + jdkRequestIndex + '?fields=*,tasks/Tasks/host_name,tasks/Tasks/status,tasks/Tasks/structured_out';
+      c.set('jdkRequestIndex', jdkRequestIndex);
+      c.set('jdkCategoryWarnings', null);
+      c.doCheckJDKsuccessCallback(data);
+      expect($.ajax.args[0][0].type).to.equal('GET');
+      expect($.ajax.args[0][0].url).to.contain(url);
+    });
+
+  });
+
+  describe('#doCheckJDKerrorCallback', function() {
+
+    it('should set isJDKWarningsLoaded to true', function() {
+
+      c.set('isJDKWarningsLoaded', false);
+      c.doCheckJDKerrorCallback();
+      c.set('isJDKWarningsLoaded', true);
+
+    });
+
+  });
+
+  describe('#parseJDKCheckResults', function() {
+
+    beforeEach(function() {
+      sinon.stub(c, 'doCheckJDKsuccessCallback', Em.K);
+    });
+
+    afterEach(function() {
+      c.doCheckJDKsuccessCallback.restore();
+    });
+
+    it('should set jdkCategoryWarnings to null if no data', function() {
+
+      var data = {Requests: {}};
+      c.set('jdkCategoryWarnings', {});
+      c.parseJDKCheckResults(data);
+      expect(c.get('jdkCategoryWarnings')).to.be.null;
+
+    });
+
+    it('should parse warnings (1)', function() {
+
+      var data = {
+        Requests: {
+          end_time: 1
+        },
+        tasks: []
+      };
+
+      c.set('jdkCategoryWarnings', {});
+      c.parseJDKCheckResults(data);
+      expect(c.get('jdkCategoryWarnings')).to.eql([]);
+
+    });
+
+    it('should parse warnings (2)', function() {
+
+      var data = {
+        Requests: {
+          end_time: 1
+        },
+        tasks: [
+          {
+            Tasks: {
+              host_name: 'h1',
+              structured_out: {
+                java_home_check: {
+                  exit_code: 1
+                }
+              }
+            }
+          },
+          {
+            Tasks: {
+              host_name: 'h2',
+              structured_out: {
+                java_home_check: {
+                  exit_code: 0
+                }
+              }
+            }
+          }
+        ]
+      };
+
+      c.set('jdkCategoryWarnings', {});
+      c.parseJDKCheckResults(data);
+      var result = c.get('jdkCategoryWarnings');
+      expect(result.length).to.equal(1);
+      expect(result[0].hostsNames).to.eql(['h1']);
+
+    });
+
+  });
+
 });

+ 0 - 19
ambari-web/test/controllers/wizard/step5_test.js

@@ -481,25 +481,6 @@ describe('App.WizardStep5Controller', function () {
     });
   });
 
-  describe('#submit', function () {
-    beforeEach(function () {
-      sinon.stub(App.router, 'send', Em.K);
-    });
-    afterEach(function () {
-      App.router.send.restore();
-    });
-    it('should go next if not isSubmitDisabled', function () {
-      c.reopen({submitDisabled: false});
-      c.submit();
-      expect(App.router.send.calledWith('next')).to.equal(true);
-    });
-    it('shouldn\'t go next if submitDisabled true', function () {
-      c.reopen({submitDisabled: true});
-      c.submit();
-      expect(App.router.send.called).to.equal(false);
-    });
-  });
-
   describe('#removeComponent', function () {
     var tests = Em.A([
       {

+ 0 - 34
ambari-web/test/controllers/wizard/step6_test.js

@@ -141,40 +141,6 @@ describe('App.WizardStep6Controller', function () {
     });
   });
 
-  describe('#selectAllNodes', function () {
-    beforeEach(function () {
-      sinon.stub(controller, 'setAllNodes', Em.K);
-    });
-    afterEach(function () {
-      controller.setAllNodes.restore();
-    });
-    it('should call setAllNodes', function () {
-      controller.selectAllNodes({context: {name: 'name'}});
-      expect(controller.setAllNodes.calledWith('name', true)).to.equal(true);
-    });
-    it('shouldn\'t call setAllNodes', function () {
-      controller.selectAllNodes();
-      expect(controller.setAllNodes.called).to.equal(false);
-    });
-  });
-
-  describe('#deselectAllNodes', function () {
-    beforeEach(function () {
-      sinon.stub(controller, 'setAllNodes', Em.K);
-    });
-    afterEach(function () {
-      controller.setAllNodes.restore();
-    });
-    it('should call setAllNodes', function () {
-      controller.deselectAllNodes({context: {name: 'name'}});
-      expect(controller.setAllNodes.calledWith('name', false)).to.equal(true);
-    });
-    it('shouldn\'t call setAllNodes', function () {
-      controller.deselectAllNodes();
-      expect(controller.setAllNodes.called).to.equal(false);
-    });
-  });
-
   describe('#checkCallback', function () {
     beforeEach(function () {
       sinon.stub(controller, 'clearError', Em.K);

+ 12 - 80
ambari-web/test/controllers/wizard/step7_test.js

@@ -27,7 +27,18 @@ var installerStep7Controller;
 describe('App.InstallerStep7Controller', function () {
 
   beforeEach(function () {
-    installerStep7Controller = App.WizardStep7Controller.create();
+    sinon.stub(App.config, 'setPreDefinedServiceConfigs', Em.K);
+    installerStep7Controller = App.WizardStep7Controller.create({
+      content: {
+        advancedServiceConfig: [],
+        serviceConfigProperties: []
+      },
+      applyServicesConfigs: Em.K
+    });
+  });
+
+  afterEach(function() {
+    App.config.setPreDefinedServiceConfigs.restore();
   });
 
   describe('#installedServiceNames', function () {
@@ -1002,85 +1013,6 @@ describe('App.InstallerStep7Controller', function () {
       installerStep7Controller.loadStep();
       expect(installerStep7Controller.setInstalledServiceConfigs.calledOnce).to.equal(true);
     });
-    Em.A([
-        {
-          allSelectedServiceNames: ['STORM'],
-          installedServiceNames: ['STORM'],
-          m: 'allSelectedServiceNames contains STORM, installedServiceNames contains STORM',
-          e: true
-        },
-        {
-          allSelectedServiceNames: [],
-          installedServiceNames: ['STORM'],
-          m: 'allSelectedServiceNames doesn\'t contain STORM, installedServiceNames contains STORM',
-          e: true
-        },
-        {
-          allSelectedServiceNames: ['STORM'],
-          installedServiceNames: [],
-          m: 'allSelectedServiceNames contains STORM, installedServiceNames doesn\'t contain STORM',
-          e: true
-        },
-        {
-          allSelectedServiceNames: [],
-          installedServiceNames: [],
-          m: 'allSelectedServiceNames doesn\'t contain STORM, installedServiceNames doesn\'t contain STORM',
-          e: false
-        }
-      ]).forEach(function (test) {
-        it(test.m, function () {
-          installerStep7Controller.reopen({
-            allSelectedServiceNames: test.allSelectedServiceNames,
-            installedServiceNames: test.installedServiceNames
-          });
-          installerStep7Controller.loadStep();
-          if (test.e) {
-            expect(installerStep7Controller.resolveServiceDependencyConfigs.calledOnce).to.equal(true);
-          }
-          else {
-            expect(installerStep7Controller.resolveServiceDependencyConfigs.called).to.equal(false);
-          }
-        });
-      });
-    it('should call setStepConfigs', function () {
-      installerStep7Controller.loadStep();
-      expect(installerStep7Controller.setStepConfigs.calledOnce).to.equal(true);
-    });
-    it('should call checkHostOverrideInstaller', function () {
-      installerStep7Controller.loadStep();
-      expect(installerStep7Controller.checkHostOverrideInstaller.calledOnce).to.equal(true);
-    });
-    it('should call activateSpecialConfigs', function () {
-      installerStep7Controller.loadStep();
-      expect(installerStep7Controller.activateSpecialConfigs.calledOnce).to.equal(true);
-    });
-    it('should call selectProperService', function () {
-      installerStep7Controller.loadStep();
-      expect(installerStep7Controller.selectProperService.calledOnce).to.equal(true);
-    });
-    Em.A([
-        {
-          m: 'should skip config step',
-          skipConfigStep: true,
-          e: true
-        },
-        {
-          m: 'shouldn\'t skip config step',
-          skipConfigStep: false,
-          e: false
-        }
-      ]).forEach(function (test) {
-        it(test.m, function () {
-          installerStep7Controller.set('content.skipConfigStep', test.skipConfigStep);
-          installerStep7Controller.loadStep();
-          if (test.e) {
-            expect(App.router.send.calledWith('next')).to.equal(true);
-          }
-          else {
-            expect(App.router.send.called).to.equal(false);
-          }
-        });
-      });
   });
 
   describe('#_updateValueForCheckBoxConfig', function () {

+ 1 - 51
ambari-web/test/models/stack_service_test.js

@@ -75,7 +75,7 @@ describe('App.StackService', function () {
     it('service name is "GLUSTERFS"', function () {
       ss.set('serviceName', 'GLUSTERFS');
       ss.propertyDidChange('configTypesRendered');
-      expect(ss.get('configTypesRendered')).to.eql({'core-site': {}, 'hdfs-site': {}});
+      expect(ss.get('configTypesRendered')).to.eql({'hdfs-site': {}});
     });
     it('service name is "HDFS"', function () {
       ss.set('serviceName', 'HDFS');
@@ -128,56 +128,6 @@ describe('App.StackService', function () {
     });
   });
 
-  describe('#dependentServices', function () {
-    var mock = {
-      isHadoop2Stack: false
-    };
-    beforeEach(function () {
-      sinon.stub(App, 'get', function () {
-        return mock.isHadoop2Stack;
-      })
-    });
-    afterEach(function () {
-      App.get.restore();
-    });
-    it('isHadoop2Stack is false', function () {
-      ss.set('serviceName', 'HDFS');
-      ss.propertyDidChange('dependentServices');
-      expect(ss.get('dependentServices')).to.eql(['MAPREDUCE', 'HBASE', 'SQOOP']);
-    });
-    it('isHadoop2Stack is true', function () {
-      mock.isHadoop2Stack = true;
-      ss.set('serviceName', 'HDFS');
-      ss.propertyDidChange('dependentServices');
-      expect(ss.get('dependentServices')).to.eql(['YARN', 'HBASE', 'FLUME', 'SQOOP']);
-    });
-  });
-
-  describe('#serviceDependency', function () {
-    var mock = {
-      isHadoop2Stack: false
-    };
-    beforeEach(function () {
-      sinon.stub(App, 'get', function () {
-        return mock.isHadoop2Stack;
-      })
-    });
-    afterEach(function () {
-      App.get.restore();
-    });
-    it('isHadoop2Stack is false', function () {
-      ss.set('serviceName', 'HDFS');
-      ss.propertyDidChange('serviceDependency');
-      expect(ss.get('serviceDependency')).to.eql([]);
-    });
-    it('isHadoop2Stack is true', function () {
-      mock.isHadoop2Stack = true;
-      ss.set('serviceName', 'HDFS');
-      ss.propertyDidChange('serviceDependency');
-      expect(ss.get('serviceDependency')).to.eql(["ZOOKEEPER"]);
-    });
-  });
-
   describe('#isMonitoringService', function () {
     var testCases = [
       {