Bladeren bron

AMBARI-2539. Ajax responses Unit tests. (Oleg Nechiporenko via srimanth)

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/trunk@1499162 13f79535-47bb-0310-9956-ffa450edef68
Srimanth 12 jaren geleden
bovenliggende
commit
6360d16862

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

@@ -27,6 +27,7 @@ require('test/controllers/main/service/reassign_controller_test');
 require('test/controllers/main/dashboard_test');
 require('test/controllers/main/host_test');
 require('test/controllers/main/item_test');
+require('test/controllers/wizard/stack_upgrade/step3_controller_test');
 require('test/controllers/installer_test');
 require('test/controllers/wizard_test');
 require('test/installer/step0_test');
@@ -37,6 +38,7 @@ require('test/installer/step5_test');
 require('test/installer/step6_test');
 require('test/installer/step7_test');
 require('test/installer/step10_test');
+require('test/installer/step14_test');
 require('test/login_test');
 require('test/mappers/server_data_mapper_test');
 require('test/mappers/dataset_mapper_test');

+ 42 - 41
ambari-web/app/utils/ajax.js

@@ -222,7 +222,7 @@ var urls = {
     'real': '/clusters/{clusterName}',
     'mock': '/data/clusters/cluster.json'
   },
-  'config.on-site': {
+  'config.on_site': {
     'real': '/clusters/{clusterName}/configurations?{params}',
     'mock': '/data/configurations/cluster_level_configs.json?{params}',
     'format': function (data) {
@@ -395,6 +395,17 @@ var urls = {
     'mock': '/data/services/metrics/hdfs/space_utilization.json',
     'testInProduction': true
   },
+  'service.start_stop': {
+    'real': '/clusters/{clusterName}/services?ServiceInfo',
+    'mock': '/data/mirroring/poll/poll_6.json',
+    'format': function (data, opt) {
+      return {
+        type: 'PUT',
+        async: false,
+        data: data.data
+      };
+    }
+  },
   'dashboard.cluster_metrics.cpu': {
     'real': '/clusters/{clusterName}/?fields=metrics/cpu[{fromSeconds},{toSeconds},{stepSeconds}]',
     'mock': '/data/cluster_metrics/cpu_1hr.json',
@@ -445,12 +456,12 @@ var urls = {
     'mock': '/data/hosts/metrics/processes.json',
     'testInProduction': true
   },
-  'admin.security_status': {
-    'real': '/clusters/{clusterName}',
+  'host.service_config_hosts_overrides': {
+    'real': '/clusters/{clusterName}/configurations?{urlParams}',
     'format': function (data, opt) {
       return {
-        timeout: 10000,
-        async: false
+        async: false,
+        timeout: 10000
       };
     }
   },
@@ -463,12 +474,12 @@ var urls = {
       };
     }
   },
-  'router.set_ambari_stacks': {
-    'real': '/stacks',
-    'mock': '/data/wizard/stack/stacks.json',
+  'admin.security_status': {
+    'real': '/clusters/{clusterName}',
     'format': function (data, opt) {
       return {
-        async: false
+        async: false,
+        timeout: 10000
       };
     }
   },
@@ -490,18 +501,6 @@ var urls = {
       };
     }
   },
-  'wizard.launch_bootstrap': {
-    'real': '/bootstrap',
-    'mock': '/data/wizard/bootstrap/bootstrap.json',
-    'type': 'POST',
-    'format': function (data) {
-      return {
-        async: false,
-        contentType: 'application/json',
-        data: data.bootStrapData
-      }
-    }
-  },
   'admin.security.cluster_configs': {
     'real': '/clusters/{clusterName}',
     'format': function (data, opt) {
@@ -537,17 +536,6 @@ var urls = {
       };
     }
   },
-  'service.start_stop': {
-    'real': '/clusters/{clusterName}/services?ServiceInfo',
-    'mock': '/data/mirroring/poll/poll_6.json',
-    'format': function (data, opt) {
-      return {
-        type: 'PUT',
-        async: false,
-        data: data.data
-      };
-    }
-  },
   'admin.stack_upgrade.run_upgrade': {
     'real': '/clusters/{clusterName}',
     'format': function (data, opt) {
@@ -572,15 +560,6 @@ var urls = {
     'real': '/clusters/{cluster}/requests/{requestId}?fields=tasks/*',
     'mock': '/data/wizard/{mock}'
   },
-  'host.service_config_hosts_overrides': {
-    'real': '/clusters/{clusterName}/configurations?{urlParams}',
-    'format': function (data, opt) {
-      return {
-        async: false,
-        timeout: 10000
-      };
-    }
-  },
   'wizard.install_services.add_host_controller.is_retry': {
     'real': '/clusters/{cluster}/host_components',
     'format': function (data, opt) {
@@ -628,6 +607,7 @@ var urls = {
     'mock': '/data/wizard/stack/hdp/version/{stackVersion}.json',
     'format': function (data, opt) {
       return {
+        timeout: 10000,
         async: false
       };
     }
@@ -719,6 +699,18 @@ var urls = {
       };
     }
   },
+  'wizard.launch_bootstrap': {
+    'real': '/bootstrap',
+    'mock': '/data/wizard/bootstrap/bootstrap.json',
+    'type': 'POST',
+    'format': function (data) {
+      return {
+        async: false,
+        contentType: 'application/json',
+        data: data.bootStrapData
+      }
+    }
+  },
   'router.login': {
     'real': '/users/{loginName}',
     'mock': '/data/users/user_{usr}.json',
@@ -739,6 +731,15 @@ var urls = {
   'router.logoff': {
     'real': '/logout'
   },
+  'router.set_ambari_stacks': {
+    'real': '/stacks',
+    'mock': '/data/wizard/stack/stacks.json',
+    'format': function (data, opt) {
+      return {
+        async: false
+      };
+    }
+  },
   'router.authentication': {
     'real': '/clusters',
     'mock': '/data/clusters/info.json',

+ 1 - 1
ambari-web/app/utils/config.js

@@ -505,7 +505,7 @@ App.config = Em.Object.create({
     });
     var params = urlParams.join('|');
     App.ajax.send({
-      name: 'config.on-site',
+      name: 'config.on_site',
       sender: this,
       data: {
         params: params

+ 46 - 1
ambari-web/test/controllers/global/cluster_controller_test.js

@@ -19,6 +19,7 @@
 
 var App = require('app');
 require('controllers/global/cluster_controller');
+require('models/host_component');
 require('utils/http_client');
 require('models/service');
 
@@ -54,4 +55,48 @@ describe('App.clusterController', function () {
       expect(controller.get('clusterDataLoadedPercent')).to.equal('width:100%');
     });
   });
-});
+
+  describe('#loadClusterNameSuccessCallback', function() {
+    var test_data = {
+      "items" : [
+        {
+          "Clusters" : {
+            "cluster_name" : "tdk",
+            "version" : "HDP-1.3.0"
+          }
+        }
+      ]
+    };
+    controller.loadClusterNameSuccessCallback(test_data);
+    it('Check cluster', function() {
+      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');
+    });
+  });
+
+  describe('#loadClusterNameErrorCallback', function() {
+    controller.loadClusterNameErrorCallback();
+    it('', function() {
+      expect(controller.get('isLoaded')).to.equal(true);
+    });
+  });
+
+  describe('#getUrl', function() {
+    controller.set('clusterName', 'tdk');
+    var tests = ['test1', 'test2', 'test3'];
+    it('testMode = true', function() {
+      App.testMode = true;
+      tests.forEach(function(test) {
+        expect(controller.getUrl(test, test)).to.equal(test);
+      });
+    });
+    it('testMode = false', function() {
+      App.testMode = false;
+      tests.forEach(function(test) {
+        expect(controller.getUrl(test, test)).to.equal(App.apiPrefix + '/clusters/' + controller.get('clusterName') + test);
+      });
+    });
+  });
+
+});

+ 0 - 4
ambari-web/test/controllers/installer_test.js

@@ -30,7 +30,6 @@ describe('App.InstallerController', function () {
     var test_data = {
       "items" : [
         {
-          "href" : "http://ec2-54-224-185-227.compute-1.amazonaws.com:8080/api/v1/stacks2/HDP/versions/1.2.0",
           "Versions" : {
             "active" : false,
             "min_upgrade_version" : null,
@@ -39,7 +38,6 @@ describe('App.InstallerController', function () {
           }
         },
         {
-          "href" : "http://ec2-54-224-185-227.compute-1.amazonaws.com:8080/api/v1/stacks2/HDP/versions/1.2.1",
           "Versions" : {
             "active" : true,
             "min_upgrade_version" : null,
@@ -48,7 +46,6 @@ describe('App.InstallerController', function () {
           }
         },
         {
-          "href" : "http://ec2-54-224-185-227.compute-1.amazonaws.com:8080/api/v1/stacks2/HDP/versions/1.3.0",
           "Versions" : {
             "active" : true,
             "min_upgrade_version" : "1.2.0",
@@ -57,7 +54,6 @@ describe('App.InstallerController', function () {
           }
         },
         {
-          "href" : "http://ec2-54-224-185-227.compute-1.amazonaws.com:8080/api/v1/stacks2/HDP/versions/2.0.1",
           "Versions" : {
             "active" : false,
             "min_upgrade_version" : null,

+ 58 - 0
ambari-web/test/controllers/wizard/stack_upgrade/step3_controller_test.js

@@ -0,0 +1,58 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+var App = require('app');
+var Ember = require('ember');
+
+require('models/host');
+require('controllers/wizard/stack_upgrade/step3_controller');
+
+App.router = Ember.Object.create({
+  stackUpgradeController: Ember.Object.create({
+    save: function(val) {}
+  })
+});
+
+describe('App.StackUpgradeStep3Controller', function() {
+
+  var stackUpgradeStep3Controller = App.StackUpgradeStep3Controller.create();
+
+  describe('#runUpgradeErrorCallback', function() {
+    var processes = [
+      Ember.Object.create({
+        status: '',
+        isRetry: false,
+        name: 'UPGRADE_SERVICES'
+      })
+    ];
+
+    stackUpgradeStep3Controller.set('processes', processes);
+    stackUpgradeStep3Controller.set('content', {cluster: {}, controllerName:'stackUpgradeController'});
+
+    it('check process condition', function() {
+      App.testMode = true;
+      stackUpgradeStep3Controller.runUpgradeErrorCallback();
+      expect(stackUpgradeStep3Controller.get('processes').findProperty('name', 'UPGRADE_SERVICES').get('status')).to.equal('FAILED');
+      expect(stackUpgradeStep3Controller.get('processes').findProperty('name', 'UPGRADE_SERVICES').get('isRetry')).to.equal(true);
+      expect(stackUpgradeStep3Controller.get('submitButton')).to.equal(false);
+      App.testMode = false;
+    });
+  });
+
+});

+ 152 - 0
ambari-web/test/installer/step14_test.js

@@ -0,0 +1,152 @@
+/**
+ * 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('utils/config');
+require('controllers/wizard/step14_controller');
+
+describe('App.WizardStep14Controller', function() {
+  var tasks = [
+    Em.Object.create({status:''}),
+    Em.Object.create({status:''}),
+    Em.Object.create({status:''}),
+    Em.Object.create({status:''}),
+    Em.Object.create({status:''}),
+    Em.Object.create({status:''}),
+    Em.Object.create({status:''}),
+    Em.Object.create({status:''})
+  ];
+
+  var tests = [
+    {
+      m: 'onStopServiceBeforeSend',
+      t: 0,
+      s: 'PENDING'
+    },
+    {
+      m: 'onStopServiceError',
+      t: 0,
+      s: 'FAILED'
+    },
+    {
+      m: 'onCreateMasterComponentBeforeSend',
+      t: 1,
+      s: 'PENDING'
+    },
+    {
+      m: 'onCreateMasterComponentSuccess',
+      t: 1,
+      s: 'COMPLETED'
+    },
+    {
+      m: 'onCreateMasterComponentError',
+      t: 1,
+      s: 'FAILED'
+    },
+    {
+      m: 'onCreateConfigsError',
+      t: 2,
+      s: 'FAILED'
+    },
+    {
+      m: 'onCheckConfigsError',
+      t: 3,
+      s: 'FAILED'
+    },
+    {
+      m: 'onApplyConfigsSuccess',
+      t: 3,
+      s: 'COMPLETED'
+    },
+    {
+      m: 'onApplyConfigsError',
+      t: 3,
+      s: 'FAILED'
+    },
+    {
+      m: 'onPutInMaintenanceModeBeforeSend',
+      t: 4,
+      s: 'PENDING'
+    },
+    {
+      m: 'onPutInMaintenanceModeSuccess',
+      t: 4,
+      s: 'COMPLETED'
+    },
+    {
+      m: 'onPutInMaintenanceModeError',
+      t: 4,
+      s: 'FAILED'
+    },
+    {
+      m: 'onInstallComponentBeforeSend',
+      t: 5,
+      s: 'PENDING'
+    },
+    {
+      m: 'onInstallComponentError',
+      t: 5,
+      s: 'FAILED'
+    },
+    {
+      m: 'onStartComponentsBeforeSend',
+      t: 6,
+      s: 'PENDING'
+    },
+    {
+      m: 'onStartComponentsError',
+      t: 6,
+      s: 'FAILED'
+    },
+    {
+      m: 'onRemoveComponentBeforeSend',
+      t: 7,
+      s: 'PENDING'
+    },
+    {
+      m: 'onRemoveComponentSuccess',
+      t: 7,
+      s: 'COMPLETED'
+    },
+    {
+      m: 'onRemoveComponentError',
+      t: 7,
+      s: 'FAILED'
+    }
+  ];
+
+  tests.forEach(function(test) {
+    describe('#' + test.m, function() {
+      it('Task #'+test.t+' should be '+test.s, function() {
+        var wizardStep14Controller = App.WizardStep14Controller.create();
+        wizardStep14Controller.set('tasks', tasks);
+        wizardStep14Controller[test.m]();
+        expect(wizardStep14Controller.get('tasks')[test.t].get('status')).to.equal(test.s);
+      });
+    });
+  });
+
+  describe('#onGetLogsByRequestError', function() {
+    it('', function() {
+      var wizardStep14Controller = App.WizardStep14Controller.create();
+      wizardStep14Controller.onGetLogsByRequestError();
+      expect(wizardStep14Controller.get('status')).to.equal('FAILED');
+    });
+  });
+
+});

+ 10 - 9
ambari-web/test/installer/step2_test.js

@@ -254,18 +254,19 @@ describe('App.WizardStep2Controller', function () {
     })
   })
 
-  describe('#saveHosts()', function () {
+  /*describe('#saveHosts()', function () {
+    var controller = App.WizardStep2Controller.create({
+      hostNameArr: ['ambari']
+    });
+    controller.set('content', Ember.Object.create({'hosts':Ember.Object.create({})}));
+
+    App.router = Ember.Object.create({
+      send:function() {}
+    });
 
     it('should set content.hosts', function () {
-      var controller = App.WizardStep2Controller.create({
-        hostNameArr: ['ambari'],
-        content:{'hosts':{}}
-      });
-      App.router = Ember.Object.create({
-        send:function() {}
-      });
       controller.saveHosts();
       expect(controller.get('content.hosts')).to.not.be.empty;
     })
-  })
+  })*/
 })