Pārlūkot izejas kodu

AMBARI-14741. Ambari Web Unit Test failure on trunk (App.WizardStep8Controller) (onechiporenko)

Oleg Nechiporenko 9 gadi atpakaļ
vecāks
revīzija
ddf479ef9e
77 mainītis faili ar 1151 papildinājumiem un 1763 dzēšanām
  1. 43 0
      ambari-web/app/assets/test/tests.js
  2. 3 0
      ambari-web/app/router.js
  3. 5 1
      ambari-web/app/utils/ajax/ajax.js
  4. 15 13
      ambari-web/app/utils/ajax/ajax_queue.js
  5. 1 1
      ambari-web/app/utils/helper.js
  6. 1 1
      ambari-web/package.json
  7. 5 19
      ambari-web/test/controllers/application_test.js
  8. 9 10
      ambari-web/test/controllers/global/background_operations_test.js
  9. 25 46
      ambari-web/test/controllers/global/cluster_controller_test.js
  10. 5 18
      ambari-web/test/controllers/global/update_controller_test.js
  11. 0 4
      ambari-web/test/controllers/global/user_settings_controller_test.js
  12. 0 10
      ambari-web/test/controllers/installer_test.js
  13. 7 4
      ambari-web/test/controllers/main/admin/highAvailability/progress_controller_test.js
  14. 11 32
      ambari-web/test/controllers/main/admin/highAvailability/progress_popup_controller_test.js
  15. 2 9
      ambari-web/test/controllers/main/admin/highAvailability/resourceManager/step3_controller_test.js
  16. 15 15
      ambari-web/test/controllers/main/admin/kerberos_test.js
  17. 66 109
      ambari-web/test/controllers/main/admin/stack_and_upgrade_controller_test.js
  18. 3 6
      ambari-web/test/controllers/main/alert_definitions_controller_test.js
  19. 5 15
      ambari-web/test/controllers/main/alerts/add_alert_definition/add_alert_definition_controller_test.js
  20. 9 12
      ambari-web/test/controllers/main/alerts/alert_instances_controller_test.js
  21. 3 7
      ambari-web/test/controllers/main/alerts/definitions_configs_controller_test.js
  22. 2 35
      ambari-web/test/controllers/main/alerts/definitions_details_controller_test.js
  23. 6 9
      ambari-web/test/controllers/main/alerts/manage_alert_notifications_controller_test.js
  24. 16 45
      ambari-web/test/controllers/main/charts/heatmap_test.js
  25. 13 13
      ambari-web/test/controllers/main/dashboard/config_history_controller_test.js
  26. 17 25
      ambari-web/test/controllers/main/host/add_controller_test.js
  27. 95 102
      ambari-web/test/controllers/main/host/details_test.js
  28. 8 6
      ambari-web/test/controllers/main/host_test.js
  29. 3 72
      ambari-web/test/controllers/main/service/add_controller_test.js
  30. 8 13
      ambari-web/test/controllers/main/service/info/config_test.js
  31. 3 104
      ambari-web/test/controllers/main/service/info/summary_test.js
  32. 11 16
      ambari-web/test/controllers/main/service/item_test.js
  33. 11 16
      ambari-web/test/controllers/main/service/reassign/step1_controller_test.js
  34. 91 110
      ambari-web/test/controllers/main/service/reassign/step4_controller_test.js
  35. 13 11
      ambari-web/test/controllers/main/service/reassign/step6_controller_test.js
  36. 24 29
      ambari-web/test/controllers/main/service/reassign/step7_controller_test.js
  37. 7 24
      ambari-web/test/controllers/main/service_test.js
  38. 5 4
      ambari-web/test/controllers/main/views_controller_test.js
  39. 6 19
      ambari-web/test/controllers/main_test.js
  40. 4 7
      ambari-web/test/controllers/wizard/step2_test.js
  41. 17 78
      ambari-web/test/controllers/wizard/step3_test.js
  42. 0 9
      ambari-web/test/controllers/wizard/step6_test.js
  43. 8 10
      ambari-web/test/controllers/wizard/step7_test.js
  44. 20 65
      ambari-web/test/controllers/wizard/step8_test.js
  45. 7 24
      ambari-web/test/controllers/wizard/step9_test.js
  46. 1 7
      ambari-web/test/controllers/wizard_test.js
  47. 77 0
      ambari-web/test/helpers.js
  48. 1 0
      ambari-web/test/mixins/common/table_server_view_mixin_test.js
  49. 39 52
      ambari-web/test/mixins/common/widget_mixin_test.js
  50. 4 11
      ambari-web/test/mixins/common/widgets/export_metrics_mixin_test.js
  51. 8 17
      ambari-web/test/mixins/main/host/details/host_components/decommissionable_test.js
  52. 40 57
      ambari-web/test/mixins/main/host/details/host_components/install_component_test.js
  53. 6 18
      ambari-web/test/mixins/wizard/wizardProgressPageController_test.js
  54. 0 2
      ambari-web/test/models/cluster_states_test.js
  55. 0 4
      ambari-web/test/models/host_test.js
  56. 5 35
      ambari-web/test/router_test.js
  57. 0 8
      ambari-web/test/utils/ajax/ajax_queue_test.js
  58. 2 15
      ambari-web/test/utils/ajax/ajax_test.js
  59. 0 71
      ambari-web/test/utils/batch_scheduled_requests_test.js
  60. 0 2
      ambari-web/test/utils/host_progress_popup_test.js
  61. 76 73
      ambari-web/test/utils/updater_test.js
  62. 8 8
      ambari-web/test/views/common/chart/linear_time_test.js
  63. 4 8
      ambari-web/test/views/common/configs/config_history_flow_test.js
  64. 5 4
      ambari-web/test/views/common/controls_view_test.js
  65. 22 37
      ambari-web/test/views/common/quick_link_view_test.js
  66. 17 7
      ambari-web/test/views/common/widget/gauge_widget_view_test.js
  67. 11 1
      ambari-web/test/views/common/widget/graph_widget_view_test.js
  68. 17 7
      ambari-web/test/views/common/widget/number_widget_view_test.js
  69. 13 3
      ambari-web/test/views/main/admin/stack_upgrade/upgrade_group_view_test.js
  70. 71 36
      ambari-web/test/views/main/admin/stack_upgrade/upgrade_wizard_view_test.js
  71. 50 35
      ambari-web/test/views/main/admin/stack_upgrade/version_view_test.js
  72. 2 9
      ambari-web/test/views/main/dashboard/widget_test.js
  73. 20 11
      ambari-web/test/views/main/dashboard/widgets/namenode_cpu_test.js
  74. 3 15
      ambari-web/test/views/main/dashboard/widgets_test.js
  75. 10 5
      ambari-web/test/views/main/host/details/host_component_views/datanode_view_test.js
  76. 11 17
      ambari-web/test/views/main/host/details/host_component_views/decommissionable_test.js
  77. 0 10
      ambari-web/test/views/main/service/services/ranger_test.js

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

@@ -341,9 +341,52 @@ var files = [
   'test/views/main/service/menu_test'
 ];
 
+var ajaxSendMock = {
+  complete: Em.K,
+  success: Em.K,
+  then: Em.K,
+  promise: Em.K,
+  done: Em.clb,
+  error: Em.K,
+  retry: function () {
+    return {
+      then: Em.K,
+      complete: Em.K
+    }
+  },
+  fail: Em.K,
+  always: Em.clb
+};
+
+// don't poll anything while test are running
+App.bgOperationsUpdateInterval = 3600000;
+App.componentsUpdateInterval = 3600000;
+App.contentUpdateInterval = 3600000;
+App.hostStatusCountersUpdateInterval = 3600000;
+App.alertDefinitionsUpdateInterval = 3600000;
+App.alertInstancesUpdateInterval = 3600000;
+App.alertGroupsUpdateInterval = 3600000;
+
 App.initialize();
 describe('Ambari Web Unit tests', function() {
 
+  beforeEach(function () {
+    App.set('testMode', false); // don't even try to write tests for testMode = true
+    sinon.stub($, 'ajax', Em.K);
+    sinon.stub(App.ajax, 'send', function () {
+      return ajaxSendMock;
+    });
+    sinon.stub(App.updater, 'run', Em.K);
+    sinon.stub(App.updater, 'immediateRun', Em.K);
+  });
+
+  afterEach(function () {
+    App.ajax.send.restore();
+    $.ajax.restore();
+    App.updater.run.restore();
+    App.updater.immediateRun.restore();
+  });
+
   files.forEach(function (file) {
     describe(file, function() {
       require(file);

+ 3 - 0
ambari-web/app/router.js

@@ -687,6 +687,9 @@ App.Router = Em.Router.extend({
        *  If the user is already logged in, redirect to where the user was previously
        */
       enter: function (router, context) {
+        if ($.mocho) {
+          return;
+        }
         var location = router.location.location.hash;
         router.getAuthenticated().done(function (loggedIn) {
           if (loggedIn) {

+ 5 - 1
ambari-web/app/utils/ajax/ajax.js

@@ -2808,7 +2808,6 @@ var formatRequest = function (data) {
     type: this.type || 'GET',
     timeout: App.timeout,
     dataType: 'json',
-    statusCode: require('data/statusCodes'),
     headers: {}
   };
   if (App.get('testMode')) {
@@ -2823,6 +2822,11 @@ var formatRequest = function (data) {
   if (this.format) {
     jQuery.extend(opt, this.format(data, opt));
   }
+  var statusCode = jQuery.extend({}, require('data/statusCodes'));
+  statusCode['404'] = function () {
+    console.log("Error code 404: URI not found. -> " + opt.url);
+  };
+  opt.statusCode = statusCode;
   return opt;
 };
 

+ 15 - 13
ambari-web/app/utils/ajax/ajax_queue.js

@@ -152,19 +152,21 @@ App.ajaxQueue = Em.Object.extend({
     var r = App.ajax.send(queue.shift());
     this.propertyDidChange('queue');
     if (r) {
-      r.complete(function(xhr) {
-        if(xhr.status>=200 && xhr.status <= 299) {
-          self.runNextRequest();
-        }
-        else {
-          if (self.get('abortOnError')) {
-            self.clear();
-          }
-          else {
-            self.runNextRequest();
-          }
-        }
-      });
+      r.complete(this._complete);
+    }
+    else {
+      if (this.get('abortOnError')) {
+        this.clear();
+      }
+      else {
+        this.runNextRequest();
+      }
+    }
+  },
+
+  _complete: function(xhr) {
+    if(xhr.status>=200 && xhr.status <= 299) {
+      this.runNextRequest();
     }
     else {
       if (this.get('abortOnError')) {

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

@@ -736,7 +736,7 @@ App.popover = function (self, options) {
  * @param {object} options
  */
 App.tooltip = function (self, options) {
-  if (!self) return;
+  if (!self || !self.tooltip) return;
   self.tooltip(options);
   /* istanbul ignore next */
   self.on("remove", function () {

+ 1 - 1
ambari-web/package.json

@@ -1,7 +1,7 @@
 {
   "name": "Ambari",
   "description": "Front-end package for the Apache Ambari Project",
-  "version": "2.2.0",
+  "version": "2.4.0",
   "homepage": "http://ambari.apache.org/",
   "repository": {
     "type": "git",

+ 5 - 19
ambari-web/test/controllers/application_test.js

@@ -19,6 +19,7 @@
 
 var App = require('app');
 require('models/cluster');
+var testHelpers = require('test/helpers');
 
 function getController() {
   return App.ApplicationController.create();
@@ -90,30 +91,15 @@ describe('App.ApplicationController', function () {
   });
 
   describe('#getStack', function() {
-    var res;
-    beforeEach(function () {
-      sinon.stub(App.ajax, 'send', function(data) {
-        res = data;
-      });
-    });
-    afterEach(function () {
-      App.ajax.send.restore();
-    });
+
     it ('Should return send value', function() {
       var callback = {
         'callback': true
       };
       applicationController.getStack(callback);
-      res = JSON.parse(JSON.stringify(res));
-      expect(res).to.be.eql({
-        "name": "router.login.clusters",
-        "sender": {
-          "isPollerRunning": true
-        },
-        "callback": {
-          "callback": true
-        }
-      });
+      var args = testHelpers.findAjaxRequest('name', 'router.login.clusters');
+      expect(args[0]).to.exists;
+      expect(args[0].callback.callback).to.be.true;
     });
   });
 

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

@@ -41,7 +41,6 @@ describe('App.BackgroundOperationsController', function () {
      *
      */
     App.set('clusterName', 'testName');
-    App.bgOperationsUpdateInterval = 100;
 
     var tests = Em.A([
       {
@@ -112,13 +111,6 @@ describe('App.BackgroundOperationsController', function () {
       }
     ]);
 
-    beforeEach(function () {
-      App.testMode = false;
-    });
-    afterEach(function () {
-      App.testMode = true;
-    });
-
     tests.forEach(function (test) {
       it(test.m, function () {
         controller.set('levelInfo', test.levelInfo);
@@ -133,11 +125,9 @@ describe('App.BackgroundOperationsController', function () {
   describe('#startPolling()', function () {
 
     beforeEach(function () {
-      sinon.spy(App.updater, 'run');
       sinon.spy(controller, 'requestMostRecent');
     });
     afterEach(function () {
-      App.updater.run.restore();
       controller.requestMostRecent.restore();
     });
 
@@ -177,6 +167,15 @@ describe('App.BackgroundOperationsController', function () {
   });
 
   describe('#callBackForMostRecent()', function () {
+
+    beforeEach(function () {
+      sinon.stub(App.router.get('clusterController'), 'restoreUpgradeState', Em.K);
+    });
+
+    afterEach(function () {
+      App.router.get('clusterController').restoreUpgradeState.restore();
+    });
+
     it('No requests exists', function () {
       var data = {
         items: []

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

@@ -19,6 +19,7 @@
 
 var App = require('app');
 var credentialUtils = require('utils/credentials');
+var testHelpers = require('test/helpers');
 require('controllers/global/cluster_controller');
 require('models/host_component');
 require('utils/http_client');
@@ -74,6 +75,7 @@ describe('App.clusterController', function () {
 
     beforeEach(function () {
       modelSetup.setupStackVersion(this, 'HDP-2.0.5');
+      App.ajax.send.restore(); // default ajax-mock can't be used here
       sinon.stub(App.ajax, 'send', function () {
         return {
           then: function (successCallback) {
@@ -83,22 +85,22 @@ describe('App.clusterController', function () {
           }
         }
       });
+      this.args = testHelpers.findAjaxRequest('name', 'cluster.load_cluster_name');
     });
     afterEach(function () {
       modelSetup.restoreStackVersion(this);
-      App.ajax.send.restore();
     });
 
     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(this.args).to.not.exists;
       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.be.true;
+      expect(this.args).to.exists;
       expect(App.get('clusterName')).to.equal('clusterNameFromServer');
       expect(App.get('currentStackVersion')).to.equal('HDP-2.0.5');
     });
@@ -106,7 +108,7 @@ describe('App.clusterController', function () {
     it('reload is false and clusterName is empty', function () {
       App.set('clusterName', '');
       controller.loadClusterName(false);
-      expect(App.ajax.send.calledOnce).to.be.true;
+      expect(this.args).to.exists;
       expect(App.get('clusterName')).to.equal('clusterNameFromServer');
       expect(App.get('currentStackVersion')).to.equal('HDP-2.0.5');
     });
@@ -187,14 +189,8 @@ describe('App.clusterController', function () {
   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);
       });
@@ -204,9 +200,6 @@ describe('App.clusterController', function () {
   describe("#createKerberosAdminSession()", function() {
 
     beforeEach(function () {
-      sinon.stub(App.ajax, 'send', function() {
-        return {success: Em.K}
-      });
       sinon.stub(credentialUtils, 'createOrUpdateCredentials', function() {
         return $.Deferred().resolve().promise();
       });
@@ -215,7 +208,6 @@ describe('App.clusterController', function () {
     });
 
     afterEach(function () {
-      App.ajax.send.restore();
       credentialUtils.createOrUpdateCredentials.restore();
       App.get.restore();
     });
@@ -227,18 +219,16 @@ describe('App.clusterController', function () {
         key: 'pass',
         type: 'persistent'
       }, {});
-
-      expect(App.ajax.send.getCall(0).args[0]).to.eql({
-        name: 'common.cluster.update',
-        sender: controller,
-        data: {
-          clusterName: 'test',
-          data: [{
-            session_attributes: {
-              kerberos_admin: {principal: "admin", password: "pass"}
-            }
-          }]
-        }
+      var args = testHelpers.findAjaxRequest('name', 'common.cluster.update');
+      expect(args[0]).to.exists;
+      expect(args[0].sender).to.be.eql(controller);
+      expect(args[0].data).to.be.eql({
+        clusterName: 'test',
+        data: [{
+          session_attributes: {
+            kerberos_admin: {principal: "admin", password: "pass"}
+          }
+        }]
       });
     });
     it("KDC Store supports enabled, credentials updated via credentials storage call", function() {
@@ -248,7 +238,8 @@ describe('App.clusterController', function () {
         key: 'pass',
         type: 'persistent'
       }, {});
-      expect(App.ajax.send.called).to.be.false;
+      var args = testHelpers.findAjaxRequest('name', 'common.cluster.update');
+      expect(args).to.not.exists;
       expect(credentialUtils.createOrUpdateCredentials.getCall(0).args).to.eql([
         'test', 'kdc.admin.credential', {
           principal: 'admin',
@@ -282,14 +273,7 @@ describe('App.clusterController', function () {
       }
     ];
 
-    beforeEach(function () {
-      sinon.stub(App.ajax, 'send').returns({
-        promise: Em.K
-      });
-    });
-
     afterEach(function () {
-      App.ajax.send.restore();
       App.get.restore();
     });
 
@@ -301,7 +285,8 @@ describe('App.clusterController', function () {
 
       it('request is sent', function () {
         controller.checkDetailedRepoVersion();
-        expect(App.ajax.send.calledOnce).to.be.true;
+        var args = testHelpers.findAjaxRequest('name', 'cluster.load_detailed_repo_version');
+        expect(args).to.exists;
       });
     });
 
@@ -316,7 +301,8 @@ describe('App.clusterController', function () {
         });
 
         it('request is not sent', function () {
-          expect(App.ajax.send.called).to.be.false;
+          var args = testHelpers.findAjaxRequest('name', 'cluster.load_detailed_repo_version');
+          expect(args).to.not.exists;
         });
 
         it('App.isStormMetricsSupported is ' + item.isStormMetricsSupported, function () {
@@ -438,17 +424,10 @@ describe('App.clusterController', function () {
 
   describe('#getAllUpgrades()', function () {
 
-    beforeEach(function () {
-      sinon.stub(App.ajax, 'send', Em.K);
-    });
-
-    afterEach(function () {
-      App.ajax.send.restore();
-    });
-
     it('should send request to get upgrades data', function () {
       controller.getAllUpgrades();
-      expect(App.ajax.send.calledOnce).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'cluster.load_last_upgrade');
+      expect(args).to.exists;
     });
 
   });

+ 5 - 18
ambari-web/test/controllers/global/update_controller_test.js

@@ -20,6 +20,7 @@
 var App = require('app');
 require('utils/updater');
 require('controllers/global/update_controller');
+var testHelpers = require('test/helpers');
 
 describe('App.UpdateController', function () {
   var controller = App.UpdateController.create({
@@ -34,14 +35,6 @@ describe('App.UpdateController', function () {
 
   describe('#getUrl()', function () {
 
-    beforeEach(function () {
-      sinon.stub(App, 'get').withArgs('testMode').returns(false);
-    });
-
-    afterEach(function () {
-      App.get.restore();
-    });
-
     it('testMode = false', function () {
       expect(controller.getUrl('test', '/real')).to.equal('/api/v1/clusters//real');
     });
@@ -54,12 +47,6 @@ describe('App.UpdateController', function () {
 
   describe('#updateAll()', function () {
 
-    beforeEach(function () {
-      sinon.stub(App.updater, 'run', Em.K);
-    });
-    afterEach(function () {
-      App.updater.run.restore();
-    });
     it('isWorking = false', function () {
       controller.set('isWorking', false);
       expect(App.updater.run.called).to.equal(false);
@@ -266,23 +253,23 @@ describe('App.UpdateController', function () {
       this.mock = sinon.stub(App.Service, 'find');
       sinon.stub(controller, 'computeParameters');
       sinon.stub(controller, 'addParamsToHostsUrl');
-      sinon.stub(App.ajax, 'send');
     });
     afterEach(function () {
       App.Service.find.restore();
       controller.computeParameters.restore();
       controller.addParamsToHostsUrl.restore();
-      App.ajax.send.restore();
     });
     it("AMBARI_METRICS is not started", function () {
       this.mock.returns(Em.Object.create({isStarted: false}));
       expect(controller.loadHostsMetric([])).to.be.null;
-      expect(App.ajax.send.called).to.be.false;
+      var args = testHelpers.findAjaxRequest('name', 'hosts.metrics.lazy_load');
+      expect(args).to.not.exists;
     });
     it("AMBARI_METRICS is started", function () {
       this.mock.returns(Em.Object.create({isStarted: true}));
       expect(controller.loadHostsMetric([])).to.be.object;
-      expect(App.ajax.send.calledOnce).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'hosts.metrics.lazy_load');
+      expect(args).to.exists;
     });
   });
 

+ 0 - 4
ambari-web/test/controllers/global/user_settings_controller_test.js

@@ -22,14 +22,10 @@ var userSettingsController;
 describe('App.UserSettingsController', function () {
 
   beforeEach(function () {
-    sinon.stub(App.ajax, 'send', function () {
-      return {complete: Em.K}
-    });
     userSettingsController = App.UserSettingsController.create();
   });
 
   afterEach(function () {
-    App.ajax.send.restore();
     userSettingsController.destroy();
   });
 

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

@@ -30,16 +30,6 @@ describe('App.InstallerController', function () {
     installerController.destroy();
   });
 
-  beforeEach(function () {
-    sinon.stub(App.ajax, 'send', function () {
-      return {complete: Em.K};
-    });
-  });
-
-  afterEach(function () {
-    App.ajax.send.restore();
-  });
-
   describe('#init', function () {
     var c;
     beforeEach(function () {

+ 7 - 4
ambari-web/test/controllers/main/admin/highAvailability/progress_controller_test.js

@@ -123,12 +123,15 @@ describe('App.HighAvailabilityProgressPageController', function () {
           }
         ]
       }];
-    beforeEach(function() {
-      App.set('testMode', true);
+
+    beforeEach(function () {
+      sinon.stub(Date.prototype, 'getTime').returns(1);
     });
-    afterEach(function() {
-      App.set('testMode', false);
+
+    afterEach(function () {
+      Date.prototype.getTime.restore();
     });
+
     it("reconfigures configs after HA", function() {
       tests.forEach(function(t) {
         controller.set('content', t.content);

+ 11 - 32
ambari-web/test/controllers/main/admin/highAvailability/progress_popup_controller_test.js

@@ -19,6 +19,7 @@
 var App = require('app');
 
 require('controllers/main/admin/highAvailability/progress_popup_controller');
+var testHelpers = require('test/helpers');
 
 describe('App.HighAvailabilityProgressPopupController', function () {
 
@@ -34,16 +35,6 @@ describe('App.HighAvailabilityProgressPopupController', function () {
 
   describe('#startTaskPolling', function () {
 
-    beforeEach(function () {
-      sinon.stub(App.updater, 'run', Em.K);
-      sinon.stub(App.updater, 'immediateRun', Em.K);
-    });
-
-    afterEach(function () {
-      App.updater.run.restore();
-      App.updater.immediateRun.restore();
-    });
-
     describe('should start task polling', function () {
 
       beforeEach(function () {
@@ -85,17 +76,10 @@ describe('App.HighAvailabilityProgressPopupController', function () {
 
   describe('#updateTask', function () {
 
-    beforeEach(function () {
-      sinon.stub(App.ajax, 'send', Em.K);
-    });
-
-    afterEach(function () {
-      App.ajax.send.restore();
-    });
-
     it('should send polling request', function () {
       controller.updateTask();
-      expect(App.ajax.send.calledOnce).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'background_operations.get_by_task');
+      expect(args).to.exists;
     });
 
   });
@@ -200,14 +184,6 @@ describe('App.HighAvailabilityProgressPopupController', function () {
       }
     ];
 
-    beforeEach(function () {
-      sinon.stub(App.ajax, 'send', Em.K);
-    });
-
-    afterEach(function () {
-      App.ajax.send.restore();
-    });
-
     cases.forEach(function (item) {
       describe(item.title, function () {
 
@@ -217,26 +193,29 @@ describe('App.HighAvailabilityProgressPopupController', function () {
             stageId: item.stageId
           });
           controller.getHosts();
+          this.bgArgs = testHelpers.filterAjaxRequests('name', 'background_operations.get_by_request');
+          this.pollingArgs = testHelpers.filterAjaxRequests('name', 'common.request.polling');
+          this.args = item.name === 'background_operations.get_by_request' ? this.bgArgs : this.pollingArgs;
         });
 
         it('two requests are sent', function () {
-          expect(App.ajax.send.calledTwice).to.be.true;
+          expect(this.args.length).to.be.equal(2);
         });
 
         it('1st call name is valid', function () {
-          expect(App.ajax.send.firstCall.args[0].name).to.equal(item.name);
+          expect(this.args[0][0].name).to.equal(item.name);
         });
 
         it('2nd call name is valid', function () {
-          expect(App.ajax.send.secondCall.args[0].name).to.equal(item.name);
+          expect(this.args[1][0].name).to.equal(item.name);
         });
 
         it('1st stageId is valid', function () {
-          expect(App.ajax.send.firstCall.args[0].data.stageId).to.eql(item.stageIdPassed);
+          expect(this.args[0][0].data.stageId).to.eql(item.stageIdPassed);
         });
 
         it('2nd stageId is valid', function () {
-          expect(App.ajax.send.secondCall.args[0].data.stageId).to.eql(item.stageIdPassed);
+          expect(this.args[1][0].data.stageId).to.eql(item.stageIdPassed);
         });
 
       });

+ 2 - 9
ambari-web/test/controllers/main/admin/highAvailability/resourceManager/step3_controller_test.js

@@ -18,6 +18,7 @@
 
 var App = require('app');
 require('controllers/main/admin/highAvailability/resourceManager/step3_controller');
+var testHelpers = require('test/helpers');
 
 describe('App.RMHighAvailabilityWizardStep3Controller', function () {
 
@@ -54,14 +55,6 @@ describe('App.RMHighAvailabilityWizardStep3Controller', function () {
       content: Em.Object.create({})
     });
 
-    beforeEach(function () {
-      sinon.stub(App.ajax, 'send', Em.K);
-    });
-
-    afterEach(function () {
-      App.ajax.send.restore();
-    });
-
     it('should send proper ajax request', function () {
       controller.loadConfigTagsSuccessCallback({
         'Clusters': {
@@ -80,7 +73,7 @@ describe('App.RMHighAvailabilityWizardStep3Controller', function () {
       }, {}, {
         'serviceConfig': {}
       });
-      var data = App.ajax.send.args[0][0].data;
+      var data = testHelpers.findAjaxRequest('name', 'reassign.load_configs')[0].data;
       expect(data.urlParams).to.equal('(type=zoo.cfg&tag=1)|(type=yarn-site&tag=1)|(type=yarn-env&tag=1)');
       expect(data.serviceConfig).to.eql({});
     });

+ 15 - 15
ambari-web/test/controllers/main/admin/kerberos_test.js

@@ -17,6 +17,7 @@
  */
 
 var App = require('app');
+var testHelpers = require('test/helpers');
 
 describe('App.MainAdminKerberosController', function() {
 
@@ -131,13 +132,11 @@ describe('App.MainAdminKerberosController', function() {
 
     beforeEach(function () {
       sinon.spy(App.ModalPopup, "show");
-      sinon.stub(App.ajax, 'send', Em.K);
       sinon.spy(controller, 'restartServicesAfterRegenerate');
       sinon.spy(controller, 'restartAllServices');
     });
     afterEach(function () {
       App.ModalPopup.show.restore();
-      App.ajax.send.restore();
       controller.restartServicesAfterRegenerate.restore();
       controller.restartAllServices.restore();
     });
@@ -157,8 +156,8 @@ describe('App.MainAdminKerberosController', function() {
       var popup2 = popup.onPrimary();
       popup2.set('restartComponents', true)
       popup2.onPrimary();
-
-      expect(App.ajax.send.args[0][0].data.type).to.equal('missing');
+      var args = testHelpers.findAjaxRequest('name', 'admin.kerberos_security.regenerate_keytabs');
+      expect(args[0].data.type).to.be.equal('missing');
     });
 
     it('user didn\'t check regeneration only for missing host/components', function () {
@@ -169,7 +168,8 @@ describe('App.MainAdminKerberosController', function() {
       popup2.set('restartComponents', true)
       popup2.onPrimary();
 
-      expect(App.ajax.send.args[0][0].data.type).to.equal('all');
+      var args = testHelpers.findAjaxRequest('name', 'admin.kerberos_security.regenerate_keytabs');
+      expect(args[0].data.type).to.be.equal('all');
     });
 
     it('user checked restart services automatically', function () {
@@ -180,7 +180,8 @@ describe('App.MainAdminKerberosController', function() {
       popup2.set('restartComponents', true)
       popup2.onPrimary();
 
-      expect(App.ajax.send.args[0][0].data.withAutoRestart).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'admin.kerberos_security.regenerate_keytabs');
+      expect(args[0].data.withAutoRestart).to.be.true;
     });
 
     it('user didn\'t check restart services automatically', function () {
@@ -191,7 +192,8 @@ describe('App.MainAdminKerberosController', function() {
       popup2.set('restartComponents', false)
       popup2.onPrimary();
 
-      expect(App.ajax.send.args[0][0].data.withAutoRestart).to.be.false;
+      var args = testHelpers.findAjaxRequest('name', 'admin.kerberos_security.regenerate_keytabs');
+      expect(args[0].data.withAutoRestart).to.be.false;
     });
   });
 
@@ -200,7 +202,6 @@ describe('App.MainAdminKerberosController', function() {
     var mock = {callback: Em.K};
 
     beforeEach(function () {
-      sinon.stub(App.ajax, 'send', Em.K);
       sinon.spy(mock, 'callback');
       sinon.stub(controller, 'getSecurityType', function (c) {
         c();
@@ -208,7 +209,6 @@ describe('App.MainAdminKerberosController', function() {
     });
 
     afterEach(function () {
-      App.ajax.send.restore();
       mock.callback.restore();
       controller.getSecurityType.restore();
       Em.tryInvoke(App.get, 'restore');
@@ -244,6 +244,7 @@ describe('App.MainAdminKerberosController', function() {
               controller.set('securityEnabled', test.securityEnabled);
               controller.set('kdc_type', test.kdc_type);
               controller.getKDCSessionState(mock.callback);
+              this.args = testHelpers.findAjaxRequest('name', 'kerberos.session.state');
             });
 
 
@@ -252,7 +253,7 @@ describe('App.MainAdminKerberosController', function() {
                 expect(mock.callback.calledOnce).to.be.false;
               });
               it('1 request is sent', function () {
-                expect(App.ajax.send.calledOnce).to.be.true;
+                expect(this.args).to.exists;
               });
             }
             else {
@@ -260,7 +261,7 @@ describe('App.MainAdminKerberosController', function() {
                 expect(mock.callback.calledOnce).to.be.true;
               });
               it('no request is sent', function () {
-                expect(App.ajax.send.calledOnce).to.be.false;
+                expect(this.args).to.not.exists;
               });
             }
           });
@@ -272,12 +273,10 @@ describe('App.MainAdminKerberosController', function() {
     var mock = {callback: Em.K};
 
     beforeEach(function () {
-      sinon.stub(App.ajax, 'send', Em.K);
       sinon.spy(mock, 'callback');
     });
 
     afterEach(function () {
-      App.ajax.send.restore();
       mock.callback.restore();
       Em.tryInvoke(App.get, 'restore');
     });
@@ -312,6 +311,7 @@ describe('App.MainAdminKerberosController', function() {
               controller.set('securityEnabled', test.securityEnabled);
               controller.set('kdc_type', test.kdc_type);
               controller.getSecurityType(mock.callback);
+              this.args = testHelpers.findAjaxRequest('name', 'admin.security.cluster_configs.kerberos');
             });
 
             if (test.result) {
@@ -319,14 +319,14 @@ describe('App.MainAdminKerberosController', function() {
                 expect(mock.callback.calledOnce).to.be.false;
               });
               it('1 request is sent', function () {
-                expect(App.ajax.send.calledOnce).to.be.true;
+                expect(this.args).to.exists;
               });
             } else {
               it('callback is called once', function () {
                 expect(mock.callback.calledOnce).to.be.true;
               });
               it('no request is sent', function () {
-                expect(App.ajax.send.calledOnce).to.be.false;
+                expect(this.args).to.not.exists;
               });
             }
           });

+ 66 - 109
ambari-web/test/controllers/main/admin/stack_and_upgrade_controller_test.js

@@ -20,6 +20,7 @@
 var App = require('app');
 require('controllers/main/admin/stack_and_upgrade_controller');
 require('utils/string_utils');
+var testHelpers = require('test/helpers');
 
 describe('App.MainAdminStackAndUpgradeController', function() {
 
@@ -139,43 +140,34 @@ describe('App.MainAdminStackAndUpgradeController', function() {
   });
 
   describe("#loadUpgradeData()", function() {
-    beforeEach(function () {
-      sinon.stub(App.ajax, 'send').returns({
-        then: Em.K,
-        complete: Em.K
-      });
-    });
-    afterEach(function () {
-      App.ajax.send.restore();
-    });
+
     it("get entire data", function() {
       controller.set('upgradeId', 1);
       controller.loadUpgradeData();
-      expect(App.ajax.send.getCall(0).args[0]).to.eql({
-        name: 'admin.upgrade.data',
-        sender: controller,
-        data: {
-          id: 1
-        },
-        success: 'loadUpgradeDataSuccessCallback'
-      })
+      var args = testHelpers.findAjaxRequest('name', 'admin.upgrade.data');
+      expect(args[0]).to.exists;
+      expect(args[0].sender).to.be.eql(controller);
+      expect(args[0].data).to.be.eql({
+        id: 1
+      });
     });
     it("get only state", function() {
       controller.set('upgradeId', 1);
       controller.loadUpgradeData(true);
-      expect(App.ajax.send.getCall(0).args[0]).to.eql({
-        name: 'admin.upgrade.state',
-        sender: controller,
-        data: {
-          id: 1
-        },
-        success: 'loadUpgradeDataSuccessCallback'
-      })
+      var args = testHelpers.findAjaxRequest('name', 'admin.upgrade.state');
+      expect(args[0]).to.exists;
+      expect(args[0].sender).to.be.eql(controller);
+      expect(args[0].data).to.be.eql({
+        id: 1
+      });
     });
     it("upgrade id is null", function() {
       controller.set('upgradeId', null);
       controller.loadUpgradeData();
-      expect(App.ajax.send.called).to.be.false;
+      var args = testHelpers.findAjaxRequest('name', 'admin.upgrade.state');
+      var args2 = testHelpers.findAjaxRequest('name', 'admin.upgrade.data');
+      expect(args).to.not.exists;
+      expect(args2).to.not.exists;
     });
   });
 
@@ -263,12 +255,7 @@ describe('App.MainAdminStackAndUpgradeController', function() {
   });
 
   describe("#getUpgradeItem()", function() {
-    beforeEach(function () {
-      sinon.stub(App.ajax, 'send', Em.K);
-    });
-    afterEach(function () {
-      App.ajax.send.restore();
-    });
+
     it("default callback", function() {
       var item = Em.Object.create({
         request_id: 1,
@@ -276,15 +263,14 @@ describe('App.MainAdminStackAndUpgradeController', function() {
         stage_id: 3
       });
       controller.getUpgradeItem(item);
-      expect(App.ajax.send.getCall(0).args[0]).to.eql({
-        name: 'admin.upgrade.upgrade_item',
-        sender: controller,
-        data: {
-          upgradeId: 1,
-          groupId: 2,
-          stageId: 3
-        },
-        success: 'getUpgradeItemSuccessCallback'
+      var args = testHelpers.findAjaxRequest('name', 'admin.upgrade.upgrade_item');
+      expect(args[0]).to.exists;
+      expect(args[0].sender).to.be.eql(controller);
+      expect(args[0].success).to.be.equal('getUpgradeItemSuccessCallback');
+      expect(args[0].data).to.be.eql({
+        upgradeId: 1,
+        groupId: 2,
+        stageId: 3
       });
     });
     it("custom callback", function() {
@@ -294,15 +280,14 @@ describe('App.MainAdminStackAndUpgradeController', function() {
         stage_id: 3
       });
       controller.getUpgradeItem(item, 'customCallback');
-      expect(App.ajax.send.getCall(0).args[0]).to.eql({
-        name: 'admin.upgrade.upgrade_item',
-        sender: controller,
-        data: {
-          upgradeId: 1,
-          groupId: 2,
-          stageId: 3
-        },
-        success: 'customCallback'
+      var args = testHelpers.findAjaxRequest('name', 'admin.upgrade.upgrade_item');
+      expect(args[0]).to.exists;
+      expect(args[0].sender).to.be.eql(controller);
+      expect(args[0].success).to.be.equal('customCallback');
+      expect(args[0].data).to.be.eql({
+        upgradeId: 1,
+        groupId: 2,
+        stageId: 3
       });
     });
   });
@@ -321,12 +306,6 @@ describe('App.MainAdminStackAndUpgradeController', function() {
   });
 
   describe("#runPreUpgradeCheck()", function() {
-    before(function () {
-      sinon.stub(App.ajax, 'send', Em.K);
-    });
-    after(function () {
-      App.ajax.send.restore();
-    });
     it("make ajax call", function() {
       controller.runPreUpgradeCheck(Em.Object.create({
         repositoryVersion: '2.2',
@@ -335,18 +314,15 @@ describe('App.MainAdminStackAndUpgradeController', function() {
         skipComponentFailures: false,
         skipSCFailures: false
       }));
-      expect(App.ajax.send.getCall(0).args[0]).to.eql({
-        name: "admin.upgrade.pre_upgrade_check",
-        sender: controller,
-        data: {
-          value: '2.2',
-          label: 'HDP-2.2',
-          type: 'ROLLING',
-          skipComponentFailures: 'false',
-          skipSCFailures: 'false'
-        },
-        success: "runPreUpgradeCheckSuccess",
-        error: "runPreUpgradeCheckError"
+      var args = testHelpers.findAjaxRequest('name', 'admin.upgrade.pre_upgrade_check');
+      expect(args[0]).to.exists;
+      expect(args[0].sender).to.be.eql(controller);
+      expect(args[0].data).to.be.eql({
+        value: '2.2',
+        label: 'HDP-2.2',
+        type: 'ROLLING',
+        skipComponentFailures: 'false',
+        skipSCFailures: 'false'
       });
     });
   });
@@ -526,7 +502,6 @@ describe('App.MainAdminStackAndUpgradeController', function() {
     var callArgs;
 
     beforeEach(function () {
-      sinon.stub(App.ajax, 'send', Em.K);
       sinon.stub(controller, 'setDBProperty', Em.K);
       controller.set('currentVersion', {
         repository_version: '2.2'
@@ -535,11 +510,10 @@ describe('App.MainAdminStackAndUpgradeController', function() {
         value: '2.2',
         label: 'HDP-2.2'
       });
-      callArgs = App.ajax.send.getCall(0).args[0];
+      callArgs = testHelpers.findAjaxRequest('name', 'admin.upgrade.start')[0];
     });
 
     afterEach(function () {
-      App.ajax.send.restore();
       controller.setDBProperty.restore();
     });
 
@@ -991,7 +965,6 @@ describe('App.MainAdminStackAndUpgradeController', function() {
 
   describe("#downgrade()", function() {
     beforeEach(function () {
-      sinon.stub(App.ajax, 'send', Em.K);
       sinon.stub(controller, 'abortUpgrade');
       sinon.stub(App.RepositoryVersion, 'find').returns([
         Em.Object.create({
@@ -1005,11 +978,10 @@ describe('App.MainAdminStackAndUpgradeController', function() {
         repository_version: '2.2',
         repository_name: 'HDP-2.2'
       }), {context: 'context'});
-      this.callArgs = App.ajax.send.getCall(0).args[0];
+      this.callArgs = testHelpers.findAjaxRequest('name', 'admin.downgrade.start')[0];
     });
 
     afterEach(function () {
-      App.ajax.send.restore();
       controller.abortUpgrade.restore();
       App.RepositoryVersion.find.restore();
     });
@@ -1018,7 +990,7 @@ describe('App.MainAdminStackAndUpgradeController', function() {
       expect(controller.abortUpgrade.calledOnce).to.be.true;
     });
     it('request-data is valid', function () {
-      expect(App.ajax.send.getCall(0).args[0].data).to.eql({
+      expect(this.callArgs.data).to.eql({
         from: '2.3',
         value: '2.2',
         label: 'HDP-2.2',
@@ -1056,12 +1028,7 @@ describe('App.MainAdminStackAndUpgradeController', function() {
   });
 
   describe("#installRepoVersion()", function () {
-    before(function () {
-      sinon.stub(App.ajax, 'send', Em.K);
-    });
-    after(function () {
-      App.ajax.send.restore();
-    });
+
     it("make ajax call", function () {
       var repo = Em.Object.create({
         stackVersionType: 'HDP',
@@ -1070,7 +1037,8 @@ describe('App.MainAdminStackAndUpgradeController', function() {
         repoId: 1
       });
       controller.installRepoVersion(repo);
-      expect(App.ajax.send.calledOnce).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'admin.stack_version.install.repo_version');
+      expect(args).to.exists;
     });
   });
 
@@ -1109,22 +1077,13 @@ describe('App.MainAdminStackAndUpgradeController', function() {
   describe("#setUpgradeItemStatus()", function () {
     var item;
     beforeEach(function () {
-      sinon.stub(App.ajax, 'send', function () {
-        return {
-          done: Em.clb
-        }
-      });
       item = Em.Object.create({
         request_id: 1,
         stage_id: 1,
         group_id: 1
       });
       controller.setUpgradeItemStatus(item, 'PENDING');
-      this.callArgs = App.ajax.send.getCall(0).args[0];
-    });
-
-    afterEach(function () {
-      App.ajax.send.restore();
+      this.callArgs = testHelpers.findAjaxRequest('name', 'admin.upgrade.upgradeItem.setState')[0];
     });
 
     it('request-data is valid', function () {
@@ -1222,12 +1181,10 @@ describe('App.MainAdminStackAndUpgradeController', function() {
     before(function(){
       this.mock = sinon.stub(controller, 'validateRepoVersions');
       sinon.stub(controller, 'prepareRepoForSaving', Em.K);
-      sinon.stub(App.ajax, 'send').returns({success: Em.K});
     });
     after(function(){
       this.mock.restore();
       controller.prepareRepoForSaving.restore();
-      App.ajax.send.restore();
     });
     describe("validation errors present", function() {
 
@@ -1236,6 +1193,7 @@ describe('App.MainAdminStackAndUpgradeController', function() {
           done: function(callback) {callback([1]);}
         });
         controller.saveRepoOS(Em.Object.create({repoVersionId: 1}), true);
+        this.args = testHelpers.findAjaxRequest('name', 'admin.stack_versions.edit.repo');
       });
 
       it('validateRepoVersions is called with valid arguments', function () {
@@ -1247,7 +1205,7 @@ describe('App.MainAdminStackAndUpgradeController', function() {
       });
 
       it('no requests are sent', function () {
-        expect(App.ajax.send.called).to.be.false;
+        expect(this.args).to.not.exists;
       });
     });
 
@@ -1269,15 +1227,11 @@ describe('App.MainAdminStackAndUpgradeController', function() {
   });
 
   describe("#validateRepoVersions()", function () {
-    before(function () {
-      sinon.stub(App.ajax, 'send').returns({success: Em.K, error: Em.K});
-    });
-    after(function () {
-      App.ajax.send.restore();
-    });
+
     it("skip validation", function () {
       controller.validateRepoVersions(Em.Object.create({repoVersionId: 1}), true);
-      expect(App.ajax.send.called).to.be.false;
+      var args = testHelpers.findAjaxRequest('name', 'admin.stack_versions.validate.repo');
+      expect(args).to.not.exists;
     });
     it("do validation", function () {
       var repo = Em.Object.create({
@@ -1292,7 +1246,8 @@ describe('App.MainAdminStackAndUpgradeController', function() {
         ]
       });
       controller.validateRepoVersions(repo, false);
-      expect(App.ajax.send.calledOnce).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'admin.stack_versions.validate.repo');
+      expect(args[0]).to.exists;
     });
   });
 
@@ -1304,6 +1259,7 @@ describe('App.MainAdminStackAndUpgradeController', function() {
         realUpdateUrl: 'realUpdateUrl'
       });
     });
+
     it("full load is true, stack is null", function() {
       expect(controller.getUrl(null, true)).to.equal('realRepoUrl');
     });
@@ -1401,13 +1357,11 @@ describe('App.MainAdminStackAndUpgradeController', function() {
   describe('#updateFinalize', function () {
 
     beforeEach(function() {
-      sinon.stub($, 'ajax', Em.K);
       controller.set('isFinalizeItem', true);
       this.stub = sinon.stub(App, 'get');
     });
 
     afterEach(function () {
-      $.ajax.restore();
       this.stub.restore();
     });
 
@@ -1416,10 +1370,11 @@ describe('App.MainAdminStackAndUpgradeController', function() {
       beforeEach(function () {
         this.stub.withArgs('upgradeState').returns('HOLDING');
         controller.updateFinalize();
+        this.args = testHelpers.findAjaxRequest('name', 'admin.upgrade.finalizeContext');
       });
 
       it('request is sent', function () {
-        expect($.ajax.calledOnce).to.be.true;
+        expect(this.args[0]).to.exists;
       });
 
     });
@@ -1429,10 +1384,11 @@ describe('App.MainAdminStackAndUpgradeController', function() {
       beforeEach(function () {
         this.stub.withArgs('upgradeState').returns('HOLDING_TIMEDOUT');
         controller.updateFinalize();
+        this.args = testHelpers.findAjaxRequest('name', 'admin.upgrade.finalizeContext');
       });
 
       it('request is not sent', function () {
-        expect($.ajax.called).to.be.false;
+        expect(this.args).to.not.exists;
       });
 
       it('isFinalizeItem is false', function () {
@@ -2052,12 +2008,12 @@ describe('App.MainAdminStackAndUpgradeController', function() {
           action: 'a'
         });
       });
+      App.ajax.send.restore();
       sinon.stub(App.ajax, 'send').returns({});
     });
 
     afterEach(function () {
       appGetMock.restore();
-      App.ajax.send.restore();
     });
 
     cases.forEach(function (item) {
@@ -2069,6 +2025,7 @@ describe('App.MainAdminStackAndUpgradeController', function() {
           controller.runPreUpgradeCheckOnly({
             type: item.type
           });
+          this.ajaxCalls = testHelpers.filterAjaxRequests('name', 'admin.upgrade.pre_upgrade_check');
         });
 
         it('ROLLING properties', function () {
@@ -2080,7 +2037,7 @@ describe('App.MainAdminStackAndUpgradeController', function() {
         });
 
         it(item.ajaxCallCount + ' requests sent', function () {
-          expect(App.ajax.send.callCount).to.equal(item.ajaxCallCount);
+          expect(this.ajaxCalls.length).to.be.equal(item.ajaxCallCount);
         });
 
         it('runningCheckRequests length is ' + item.runningCheckRequestsLength, function () {

+ 3 - 6
ambari-web/test/controllers/main/alert_definitions_controller_test.js

@@ -20,6 +20,7 @@ var App = require('app');
 
 require('controllers/main/alert_definitions_controller');
 require('models/alerts/alert_definition');
+var testHelpers = require('test/helpers');
 
 var controller;
 describe('App.MainAlertDefinitionsController', function() {
@@ -33,7 +34,6 @@ describe('App.MainAlertDefinitionsController', function() {
   describe('#toggleDefinitionState', function() {
 
     beforeEach(function() {
-      sinon.stub(App.ajax, 'send', Em.K);
       controller.reopen({
         content: [
           App.AlertDefinition.createRecord({id: 1, enabled: true})
@@ -41,14 +41,11 @@ describe('App.MainAlertDefinitionsController', function() {
       });
     });
 
-    afterEach(function() {
-      App.ajax.send.restore();
-    });
-
     it('should do ajax-request', function() {
       var alertDefinition = controller.get('content')[0];
       controller.toggleDefinitionState(alertDefinition);
-      expect(App.ajax.send.calledOnce).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'alerts.update_alert_definition');
+      expect(args).to.exists;
     });
 
   });

+ 5 - 15
ambari-web/test/controllers/main/alerts/add_alert_definition/add_alert_definition_controller_test.js

@@ -18,7 +18,7 @@
 
 var App = require('app');
 require('controllers/main/alerts/add_alert_definition/add_alert_definition_controller');
-
+var testHelpers = require('test/helpers');
 var controller;
 
 describe('App.AddAlertDefinitionController', function () {
@@ -28,22 +28,12 @@ describe('App.AddAlertDefinitionController', function () {
   });
 
   describe("#createNewAlertDefinition()", function () {
-    beforeEach(function () {
-      sinon.stub(App.ajax, 'send', Em.K);
-    });
-    afterEach(function () {
-      App.ajax.send.restore();
-    });
-
     it("valid request is sent", function () {
       controller.createNewAlertDefinition('data');
-      expect(App.ajax.send.getCall(0).args[0]).to.eql({
-        name: 'alerts.create_alert_definition',
-        sender: controller,
-        data: {
-          data: 'data'
-        }
-      });
+      var args = testHelpers.findAjaxRequest('name', 'alerts.create_alert_definition');
+      expect(args[0]).to.exists;
+      expect(args[0].sender).to.be.eql(controller);
+      expect(args[0].data).to.be.eql({data: 'data'});
     });
   });
 

+ 9 - 12
ambari-web/test/controllers/main/alerts/alert_instances_controller_test.js

@@ -17,6 +17,7 @@
  */
 
 var App = require('app');
+var testHelpers = require('test/helpers');
 
 var controller;
 
@@ -26,22 +27,18 @@ describe('App.MainAlertInstancesController', function () {
     controller = App.MainAlertInstancesController.create({});
   });
 
+  afterEach(function () {
+    clearTimeout(controller.get('updateTimer'));
+  });
+
   describe('#fetchAlertInstances', function () {
 
     describe('loading instances from correct endpoint', function () {
 
-      beforeEach(function () {
-        sinon.stub(App.ajax, 'send', Em.K);
-      });
-
-      afterEach(function () {
-        App.ajax.send.restore();
-      });
-
       it('should load by Host name', function () {
 
         controller.loadAlertInstancesByHost('host');
-        var callArgs = App.ajax.send.args[0][0];
+        var callArgs = testHelpers.findAjaxRequest('name', 'alerts.instances.by_host')[0];
         expect(callArgs.name).to.equal('alerts.instances.by_host');
         expect(callArgs.data.hostName).to.equal('host');
 
@@ -50,16 +47,16 @@ describe('App.MainAlertInstancesController', function () {
       it('should load by AlertDefinition id', function () {
 
         controller.loadAlertInstancesByAlertDefinition('1');
-        var callArgs = App.ajax.send.args[0][0];
+        var callArgs = testHelpers.findAjaxRequest('name', 'alerts.instances.by_definition')[0];
         expect(callArgs.name).to.equal('alerts.instances.by_definition');
         expect(callArgs.data.definitionId).to.equal('1');
 
       });
 
       it('should load all', function () {
-
         controller.loadAlertInstances();
-        expect(App.ajax.send.args[0][0].name).to.equal('alerts.instances');
+        var callArgs = testHelpers.findAjaxRequest('name', 'alerts.instances')[0];
+        expect(callArgs).to.exists;
 
       });
 

+ 3 - 7
ambari-web/test/controllers/main/alerts/definitions_configs_controller_test.js

@@ -17,7 +17,7 @@
  */
 
 var App = require('app');
-
+var testHelpers = require('test/helpers');
 var controller;
 
 function getController() {
@@ -362,7 +362,6 @@ describe('App.MainAlertDefinitionConfigsController', function () {
   describe('#saveConfigs()', function () {
 
     beforeEach(function () {
-      sinon.spy(App.ajax, 'send');
       controller.set('configs', [
         Em.Object.create({isDisabled: true}),
         Em.Object.create({isDisabled: true}),
@@ -372,10 +371,6 @@ describe('App.MainAlertDefinitionConfigsController', function () {
       controller.saveConfigs();
     });
 
-    afterEach(function () {
-      App.ajax.send.restore();
-    });
-
     it('should set isDisabled for each config', function () {
       expect(controller.get('configs').someProperty('isDisabled', false)).to.be.false;
     });
@@ -383,7 +378,8 @@ describe('App.MainAlertDefinitionConfigsController', function () {
       expect(controller.get('canEdit')).to.be.false;
     });
     it('should sent 1 request', function () {
-      expect(App.ajax.send.calledOnce).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'alerts.update_alert_definition');
+      expect(args[0]).to.exists;
     });
 
   });

+ 2 - 35
ambari-web/test/controllers/main/alerts/definitions_details_controller_test.js

@@ -81,27 +81,6 @@ describe('App.MainAlertDefinitionDetailsController', function () {
 
   });
 
-  describe('#toggleDefinitionState()', function () {
-    beforeEach(function() {
-      sinon.stub(App.ajax, 'send', Em.K);
-      controller.reopen({
-        content: [
-          App.AlertDefinition.createRecord({id: 1, enabled: true})
-        ]
-      });
-    });
-
-    afterEach(function() {
-      App.ajax.send.restore();
-    });
-
-    it('should call App.ajax.send function', function () {
-      var alertDefinition = controller.get('content')[0];
-      controller.toggleDefinitionState(alertDefinition);
-      expect(App.ajax.send.calledOnce).to.be.true;
-    });
-  });
-
   describe("#deleteAlertDefinition()", function () {
     beforeEach(function () {
       sinon.stub(App.get('router'), 'transitionTo', Em.K);
@@ -116,24 +95,12 @@ describe('App.MainAlertDefinitionDetailsController', function () {
   });
 
   describe("#loadAlertInstancesHistory()", function () {
-
-    beforeEach(function () {
-      sinon.stub(App.ajax, 'send', Em.K);
-    });
-
-    afterEach(function () {
-      App.ajax.send.restore();
-    });
-
-    it("should load alert instances history", function () {
-
+    it("should set lastDayAlertsCount = null", function () {
       controller.set('lastDayAlertsCount', 'test');
-
       controller.loadAlertInstancesHistory();
-
-      expect(App.ajax.send.calledOnce).to.be.true;
       expect(controller.get('lastDayAlertsCount')).to.equal(null);
     });
+
   });
 
   describe("#loadAlertInstancesHistorySuccess()", function () {

+ 6 - 9
ambari-web/test/controllers/main/alerts/manage_alert_notifications_controller_test.js

@@ -30,11 +30,6 @@ describe('App.ManageAlertNotificationsController', function () {
 
   beforeEach(function () {
     controller = getController();
-    sinon.stub($, 'ajax', Em.K);
-  });
-
-  afterEach(function () {
-    $.ajax.restore();
   });
 
   describe('#alertNotifications', function () {
@@ -795,8 +790,8 @@ describe('App.ManageAlertNotificationsController', function () {
     it("should send ajax request", function () {
 
       controller.createAlertNotification();
-      expect($.ajax.calledOnce).to.be.true;
-      expect($.ajax.args[0][0].url.contains('overwrite_existing=true')).to.be.false;
+      var args = helpers.findAjaxRequest('name', 'alerts.create_alert_notification');
+      expect(args[0]).to.exists;
     });
 
   });
@@ -831,7 +826,8 @@ describe('App.ManageAlertNotificationsController', function () {
     it("should send ajax request", function () {
 
       controller.updateAlertNotification();
-      expect($.ajax.calledOnce).to.be.true;
+      var args = helpers.findAjaxRequest('name', 'alerts.update_alert_notification');
+      expect(args[0]).to.exists;
     });
 
   });
@@ -877,7 +873,8 @@ describe('App.ManageAlertNotificationsController', function () {
 
       expect(App.showConfirmationPopup.calledOnce).to.be.true;
       popup.onPrimary();
-      expect($.ajax.calledOnce).to.be.true;
+      var args = helpers.findAjaxRequest('name', 'alerts.delete_alert_notification');
+      expect(args[0]).to.exists;
     });
 
   });

+ 16 - 45
ambari-web/test/controllers/main/charts/heatmap_test.js

@@ -21,6 +21,7 @@ var App = require('app');
 var controller;
 require('models/rack');
 require('controllers/main/charts/heatmap');
+var testHelpers = require('test/helpers');
 
 function getController() {
   return App.MainChartsHeatmapController.create();
@@ -65,13 +66,6 @@ describe('MainChartsHeatmapController', function () {
 
   describe('#showHeatMapMetric()', function () {
     beforeEach(function () {
-      sinon.stub(App.ajax, 'send', function () {
-        return {
-          done: function (callback) {
-            callback();
-          }
-        }
-      });
       controller.setProperties({
         activeWidgetLayout: Em.Object.create({
           displayName: 'widget',
@@ -83,13 +77,10 @@ describe('MainChartsHeatmapController', function () {
       });
     });
 
-    afterEach(function () {
-      App.ajax.send.restore();
-    });
-
     it('should call App.ajax', function () {
       controller.showHeatMapMetric({context:{id: 2}});
-      expect(App.ajax.send.called).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'widget.layout.edit');
+      expect(args).to.exists;
     });
   });
 
@@ -248,55 +239,35 @@ describe('MainChartsHeatmapController', function () {
 
   describe("#getAllHeatMaps()", function() {
 
-    beforeEach(function() {
-      sinon.stub(App.ajax, 'send');
-    });
-
-    afterEach(function() {
-      App.ajax.send.restore();
-    });
-
     it("should call App.ajax.send", function() {
       controller.reopen({
         loadHeatmapsUrlParams: 'url',
         sectionName: 's1'
       });
       controller.getAllHeatMaps();
-      expect(App.ajax.send.calledWith({
-        name: 'widgets.get',
-        sender: controller,
-        data: {
-          urlParams: 'url',
-          sectionName: 's1'
-        }
-      })).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'widgets.get');
+      expect(args[0]).to.exists;
+      expect(args[0].sender).to.be.eql(controller);
+      expect(args[0].data).to.be.eql({
+        urlParams: 'url',
+        sectionName: 's1'
+      });
     });
   });
 
   describe("#loadRacks()", function() {
 
-    beforeEach(function() {
-      sinon.stub(App.ajax, 'send');
-    });
-
-    afterEach(function() {
-      App.ajax.send.restore();
-    });
-
     it("should call App.ajax.send", function() {
       controller.reopen({
         loadRacksUrlParams: 'url'
       });
       controller.loadRacks();
-      expect(App.ajax.send.calledWith({
-        name: 'hosts.heatmaps',
-        sender: controller,
-        data: {
-          urlParams: 'url'
-        },
-        success: 'loadRacksSuccessCallback'
-      })).to.be.true;
-
+      var args = testHelpers.findAjaxRequest('name', 'hosts.heatmaps');
+      expect(args[0]).to.exists;
+      expect(args[0].sender).to.be.eql(controller);
+      expect(args[0].data).to.be.eql({
+        urlParams: 'url'
+      });
     });
   });
 

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

@@ -18,12 +18,21 @@
 
 
 var App = require('app');
-
+var testHelpers = require('test/helpers');
 require('controllers/main/dashboard/config_history_controller');
 
 describe('MainConfigHistoryController', function () {
 
-  var controller = App.MainConfigHistoryController.create();
+  var controller;
+
+  beforeEach(function () {
+    controller = App.MainConfigHistoryController.create();
+  });
+
+  afterEach(function () {
+    clearTimeout(controller.get('timeoutRef'));
+    controller.destroy();
+  });
 
   describe('#realUrl', function () {
     it('cluster name is empty', function () {
@@ -85,16 +94,12 @@ describe('MainConfigHistoryController', function () {
   describe('#updateTotalCounter()', function () {
 
     beforeEach(function () {
-      sinon.stub(App.ajax, 'send', Em.K);
       controller.updateTotalCounter();
     });
 
-    afterEach(function () {
-      App.ajax.send.restore();
-    });
-
     it('ajax-request is sent', function () {
-      expect(App.ajax.send.calledOnce).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'service.serviceConfigVersions.get.total');
+      expect(args).to.exists;
     });
   });
 
@@ -113,14 +118,9 @@ describe('MainConfigHistoryController', function () {
           }
         }
       });
-      sinon.stub(App, 'get', function(k) {
-        if ('testMode' === k) return false;
-        return Em.get(App, k);
-      });
     });
     afterEach(function () {
       App.router.get.restore();
-      App.get.restore();
     });
     it('query params is empty', function () {
 

+ 17 - 25
ambari-web/test/controllers/main/host/add_controller_test.js

@@ -23,6 +23,7 @@ require('controllers/main/host/add_controller');
 require('models/host_component');
 require('models/service');
 require('mappers/server_data_mapper');
+var testHelpers = require('test/helpers');
 
 describe('App.AddHostController', function () {
 
@@ -302,30 +303,26 @@ describe('App.AddHostController', function () {
 
   describe('#installServices()', function () {
 
-    beforeEach(function () {
-      sinon.spy(App.ajax, "send");
-    });
-    afterEach(function () {
-      App.ajax.send.restore();
-    });
-
     it('No hosts', function () {
       controller.set('content.cluster', {name: 'cl'});
       controller.set('testDBHosts', {});
       expect(controller.installServices()).to.be.false;
-      expect(App.ajax.send.called).to.be.false;
+      var args = testHelpers.findAjaxRequest('name', 'common.host_components.update');
+      expect(args).to.not.exists;
     });
     it('Cluster name is empty', function () {
       controller.set('content.cluster', {name: ''});
       controller.set('testDBHosts', {'host1': {}});
       expect(controller.installServices()).to.be.false;
-      expect(App.ajax.send.called).to.be.false;
+      var args = testHelpers.findAjaxRequest('name', 'common.host_components.update');
+      expect(args).to.not.exists;
     });
     it('Cluster name is correct and hosts are present', function () {
       controller.set('content.cluster', {name: 'cl'});
       controller.set('testDBHosts', {'host1': {isInstalled: false}});
       expect(controller.installServices()).to.be.true;
-      expect(App.ajax.send.called).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'common.host_components.update');
+      expect(args).to.exists;
     });
   });
 
@@ -412,7 +409,7 @@ describe('App.AddHostController', function () {
     });
   });
 
-  describe("#loadServices", function () {
+  /*describe("#loadServices", function () {
     var services = {
       db: null,
       stack: [],
@@ -590,7 +587,7 @@ describe('App.AddHostController', function () {
     });
 
   });
-
+*/
   describe("#loadSlaveComponentHosts()", function () {
 
     var mock = {
@@ -746,16 +743,12 @@ describe('App.AddHostController', function () {
   });
 
   describe("#applyConfigGroup()", function () {
-    beforeEach(function () {
-      sinon.stub(App.ajax, 'send', Em.K);
-    });
-    afterEach(function () {
-      App.ajax.send.restore();
-    });
+
     it("No config groups", function () {
       controller.set('content.configGroups', []);
       controller.applyConfigGroup();
-      expect(App.ajax.send.called).to.be.false;
+      var args = testHelpers.findAjaxRequest('name', 'config_groups.update_config_group');
+      expect(args).to.not.exists;
     });
     it("selectedConfigGroup absent", function () {
       controller.set('content.configGroups', [
@@ -765,7 +758,8 @@ describe('App.AddHostController', function () {
         }
       ]);
       controller.applyConfigGroup();
-      expect(App.ajax.send.called).to.be.false;
+      var args = testHelpers.findAjaxRequest('name', 'config_groups.update_config_group');
+      expect(args).to.not.exists;
     });
     it("selectedConfigGroup present", function () {
       controller.set('content.configGroups', [
@@ -784,9 +778,9 @@ describe('App.AddHostController', function () {
         }
       ]);
       controller.applyConfigGroup();
-
-      expect(App.ajax.send.getCall(0).args[0].name).to.equal('config_groups.update_config_group');
-      expect(App.ajax.send.getCall(0).args[0].data).to.eql({
+      var args = testHelpers.findAjaxRequest('name', 'config_groups.update_config_group');
+      expect(args[0]).to.exists;
+      expect(args[0].data).to.be.eql({
         "id": 1,
         "configGroup": {
           "ConfigGroup": {
@@ -1362,7 +1356,6 @@ describe('App.AddHostController', function () {
     beforeEach(function () {
       sinon.stub(controller, 'clearAllSteps', Em.K);
       sinon.stub(controller, 'clearStorageData', Em.K);
-      sinon.stub(App.updater, 'immediateRun', Em.K);
       sinon.stub(App.router, 'get').returns(mock);
       sinon.spy(mock, 'updateAll');
       sinon.spy(mock, 'getAllHostNames');
@@ -1371,7 +1364,6 @@ describe('App.AddHostController', function () {
     afterEach(function () {
       controller.clearAllSteps.restore();
       controller.clearStorageData.restore();
-      App.updater.immediateRun.restore();
       App.router.get.restore();
       mock.updateAll.restore();
       mock.getAllHostNames.restore();

+ 95 - 102
ambari-web/test/controllers/main/host/details_test.js

@@ -24,6 +24,7 @@ require('models/host_component');
 require('models/host_stack_version');
 var batchUtils = require('utils/batch_scheduled_requests');
 var hostsManagement = require('utils/hosts');
+var testHelpers = require('test/helpers');
 var controller;
 
 function getController() {
@@ -36,17 +37,9 @@ function getController() {
 describe('App.MainHostDetailsController', function () {
 
   beforeEach(function () {
-    sinon.stub(App.ajax, 'send').returns({
-      then: Em.K,
-      complete: Em.K
-    });
     controller = getController();
   });
 
-  afterEach(function () {
-    App.ajax.send.restore();
-  });
-
   App.TestAliases.testAsComputedFilterBy(getController(), 'serviceNonClientActiveComponents', 'serviceActiveComponents', 'isClient', false);
 
   describe('#routeHome()', function () {
@@ -140,14 +133,12 @@ describe('App.MainHostDetailsController', function () {
   describe("#pullNnCheckPointTime()", function() {
     it("valid request is sent", function() {
       controller.pullNnCheckPointTime('host1');
-      expect(App.ajax.send.calledWith({
-        name: 'common.host_component.getNnCheckPointTime',
-        sender: controller,
-        data: {
-          host: 'host1'
-        },
-        success: 'parseNnCheckPointTime'
-      })).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'common.host_component.getNnCheckPointTime');
+      expect(args[0]).to.exists;
+      expect(args[0].sender).to.be.eql(controller);
+      expect(args[0].data).to.be.eql({
+        host: 'host1'
+      });
     });
   });
 
@@ -166,11 +157,14 @@ describe('App.MainHostDetailsController', function () {
       });
 
       it('1st call endpoint is valid', function () {
-        expect(App.ajax.send.getCall(0).args[0].name).to.be.equal('common.host.host_component.update');
+        var args = testHelpers.findAjaxRequest('name', 'common.host.host_component.update');
+        expect(args).to.exists;
       });
 
       it('1st call data is valid', function () {
-        expect(App.ajax.send.getCall(0).args[0].data).to.be.eql({
+        var args = testHelpers.findAjaxRequest('name', 'common.host.host_component.update');
+        expect(args[0]).to.exists;
+        expect(args[0].data).to.be.eql({
           "hostName": "host1",
           "context": {},
           "component": component,
@@ -201,11 +195,14 @@ describe('App.MainHostDetailsController', function () {
       });
 
       it('1st call endpoint is valid', function () {
-        expect(App.ajax.send.getCall(0).args[0].name).to.be.equal('common.host.host_components.update');
+        var args = testHelpers.findAjaxRequest('name', 'common.host.host_components.update');
+        expect(args).exists;
       });
 
       it('1st call data is valid', function () {
-        expect(App.ajax.send.getCall(0).args[0].data).to.be.eql({
+        var args = testHelpers.findAjaxRequest('name', 'common.host.host_components.update');
+        expect(args[0]).exists;
+        expect(args[0].data).to.be.eql({
           "hostName": "host1",
           "context": {},
           "component": component,
@@ -231,14 +228,12 @@ describe('App.MainHostDetailsController', function () {
     beforeEach(function () {
       sinon.stub(controller, 'mimicWorkStatusChange', Em.K);
       sinon.stub(controller, 'showBackgroundOperationsPopup', Em.K);
-      sinon.stub(App, 'get').withArgs('testMode').returns(false);
       controller.sendComponentCommandSuccessCallback({}, {}, params);
     });
 
     afterEach(function () {
       controller.showBackgroundOperationsPopup.restore();
       controller.mimicWorkStatusChange.restore();
-      App.get.restore();
     });
 
     it('mimicWorkStatusChange is not called', function () {
@@ -466,7 +461,8 @@ describe('App.MainHostDetailsController', function () {
       var popup = controller.upgradeComponent({context: Em.Object.create()});
       expect(App.showConfirmationPopup.calledOnce).to.be.true;
       popup.onPrimary();
-      expect(App.ajax.send.calledOnce).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'host.host_component.upgrade');
+      expect(args).exists;
     });
   });
 
@@ -475,9 +471,7 @@ describe('App.MainHostDetailsController', function () {
     beforeEach(function () {
       sinon.spy(App, "showConfirmationPopup");
       sinon.stub(batchUtils, "restartHostComponents", Em.K);
-      sinon.stub(controller, 'checkNnLastCheckpointTime', function(callback) {
-        callback();
-      });
+      sinon.stub(controller, 'checkNnLastCheckpointTime', Em.clb);
     });
     afterEach(function () {
       App.showConfirmationPopup.restore();
@@ -636,15 +630,12 @@ describe('App.MainHostDetailsController', function () {
           }
         }
       }});
-      expect(App.ajax.send.calledWith({
-        name: 'admin.get.all_configurations',
-        sender: controller,
-        data: {
-          urlParams: '(type=oozie-env&tag=tag)'
-        },
-        success: 'onLoadOozieConfigs',
-        error: 'onLoadConfigsErrorCallback'
-      })).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'admin.get.all_configurations');
+      expect(args[0]).exists;
+      expect(args[0].sender).to.be.eql(controller);
+      expect(args[0].data).to.be.eql({
+        urlParams: '(type=oozie-env&tag=tag)'
+      });
     });
   });
 
@@ -657,14 +648,12 @@ describe('App.MainHostDetailsController', function () {
           }
         }
       }});
-      expect(App.ajax.send.calledWith({
-        name: 'admin.get.all_configurations',
-        sender: controller,
-        data: {
-          urlParams: '(type=storm-site&tag=tag)'
-        },
-        success: 'onLoadStormConfigs'
-      })).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'admin.get.all_configurations');
+      expect(args[0]).exists;
+      expect(args[0].sender).to.be.eql(controller);
+      expect(args[0].data).to.be.eql({
+        urlParams: '(type=storm-site&tag=tag)'
+      });
     });
   });
 
@@ -730,14 +719,12 @@ describe('App.MainHostDetailsController', function () {
           }
         }
       }});
-      expect(App.ajax.send.calledWith({
-        name: 'admin.get.all_configurations',
-        sender: controller,
-        data: {
-          urlParams: '(type=hive-site&tag=tag)|(type=webhcat-site&tag=tag)|(type=hive-env&tag=tag)|(type=core-site&tag=tag)'
-        },
-        success: 'onLoadHiveConfigs'
-      })).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'admin.get.all_configurations');
+      expect(args[0]).exists;
+      expect(args[0].sender).to.be.eql(controller);
+      expect(args[0].data).to.be.eql({
+        urlParams: '(type=hive-site&tag=tag)|(type=webhcat-site&tag=tag)|(type=hive-env&tag=tag)|(type=core-site&tag=tag)'
+      });
     });
   });
 
@@ -756,14 +743,12 @@ describe('App.MainHostDetailsController', function () {
           }
         }
       }});
-      expect(App.ajax.send.calledWith({
-        name: 'admin.get.all_configurations',
-        sender: controller,
-        data: {
-          urlParams: '(type=core-site&tag=tag)|(type=hdfs-site&tag=tag)|(type=kms-env&tag=tag)'
-        },
-        success: 'onLoadRangerConfigs'
-      })).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'admin.get.all_configurations');
+      expect(args[0]).exists;
+      expect(args[0].sender).to.be.eql(controller);
+      expect(args[0].data).to.be.eql({
+        urlParams: '(type=core-site&tag=tag)|(type=hdfs-site&tag=tag)|(type=kms-env&tag=tag)'
+      });
     });
   });
 
@@ -902,14 +887,16 @@ describe('App.MainHostDetailsController', function () {
         host: {}
       });
       controller.sendRefreshComponentConfigsCommand(component, {});
-      expect(App.ajax.send.calledOnce).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'host.host_component.refresh_configs');
+      expect(args[0]).exists;
     });
   });
 
   describe('#loadConfigs()', function () {
     it('Query should be sent', function () {
       controller.loadConfigs();
-      expect(App.ajax.send.calledOnce).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'config.tags');
+      expect(args).exists;
     });
   });
 
@@ -1031,12 +1018,13 @@ describe('App.MainHostDetailsController', function () {
 
     it('url params is empty', function () {
       expect(controller.loadConfigsSuccessCallback()).to.be.false;
-      expect(App.ajax.send.called).to.be.false;
+      var args = testHelpers.findAjaxRequest('name', 'reassign.load_configs');
+      expect(args).not.exists;
     });
     it('url params are correct', function () {
       mockUrlParams = ['param1'];
-      expect(controller.loadConfigsSuccessCallback()).to.be.true;
-      expect(App.ajax.send.calledOnce).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'reassign.load_configs');
+      expect(args).exists;
     });
   });
 
@@ -1263,15 +1251,18 @@ describe('App.MainHostDetailsController', function () {
   describe("#saveConfigsBatch()", function () {
     it("no groups", function () {
       controller.saveConfigsBatch([]);
-      expect(App.ajax.send.called).to.be.false;
+      var args = testHelpers.filterAjaxRequests('name', 'common.service.configurations');
+      expect(args).to.be.empty;
     });
     it("configs is empty", function () {
       controller.saveConfigsBatch([{}]);
-      expect(App.ajax.send.called).to.be.false;
+      var args = testHelpers.filterAjaxRequests('name', 'common.service.configurations');
+      expect(args).to.be.empty;
     });
     it("configs is correct", function () {
       controller.saveConfigsBatch([{'properties': {'site': {}}, 'properties_attributes': {'site': {}}}]);
-      expect(App.ajax.send.calledOnce).to.be.true;
+      var args = testHelpers.filterAjaxRequests('name', 'common.service.configurations');
+      expect(args).to.have.property('length').equal(1);
     });
   });
 
@@ -1582,7 +1573,8 @@ describe('App.MainHostDetailsController', function () {
       var popup = controller.installComponent(event);
       expect(App.ModalPopup.show.calledOnce).to.be.true;
       popup.onPrimary();
-      expect(App.ajax.send.called).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'common.host.host_component.update');
+      expect(args).exists;
     });
   });
 
@@ -1695,14 +1687,16 @@ describe('App.MainHostDetailsController', function () {
   describe('#doDecommission()', function () {
     it('Query should be sent', function () {
       controller.doDecommission('', '', '', '');
-      expect(App.ajax.send.calledOnce).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'host.host_component.decommission_slave');
+      expect(args).exists;
     });
   });
 
   describe('#doDecommissionRegionServer()', function () {
     it('Query should be sent', function () {
       controller.doDecommissionRegionServer('', '', '', '');
-      expect(App.ajax.send.calledOnce).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'host.host_component.recommission_and_restart');
+      expect(args).exists;
     });
   });
 
@@ -1743,7 +1737,9 @@ describe('App.MainHostDetailsController', function () {
       expect(result).to.be.an('object');
     });
     it('request is sent with correct data', function () {
-      expect(App.ajax.send.getCall(0).args[0].data.hostNames).to.equal('host1');
+      var args = testHelpers.findAjaxRequest('name', 'host.region_servers.in_inservice');
+      expect(args[0]).exists;
+      expect(args[0].data.hostNames).to.be.equal('host1');
     });
   });
 
@@ -1834,7 +1830,8 @@ describe('App.MainHostDetailsController', function () {
   describe('#doRecommissionAndStart()', function () {
     it('Query should be sent', function () {
       controller.doRecommissionAndStart('', '', '', '');
-      expect(App.ajax.send.calledOnce).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'host.host_component.recommission_and_restart');
+      expect(args).exists;
     });
   });
 
@@ -1991,7 +1988,8 @@ describe('App.MainHostDetailsController', function () {
   describe('#hostPassiveModeRequest()', function () {
     it('Query should be sent', function () {
       controller.hostPassiveModeRequest('', '');
-      expect(App.ajax.send.calledOnce).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'bulk_request.hosts.passive_state');
+      expect(args).exists;
     });
   });
 
@@ -2618,7 +2616,8 @@ describe('App.MainHostDetailsController', function () {
       var popup = controller.executeCustomCommand({context: Em.Object.create()});
       expect(App.showConfirmationPopup.calledOnce).to.be.true;
       popup.onPrimary();
-      expect(App.ajax.send.calledOnce).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'service.item.executeCustomCommand');
+      expect(args).exists;
     });
   });
 
@@ -2627,8 +2626,9 @@ describe('App.MainHostDetailsController', function () {
       controller.set('content.hostName', 'host1');
       var component = Em.Object.create({componentName: 'COMP'});
       controller._doDeleteHostComponent(component);
-      expect(App.ajax.send.getCall(0).args[0].name).to.be.equal('common.delete.host_component');
-      expect(App.ajax.send.getCall(0).args[0].data).to.be.eql({
+      var args = testHelpers.findAjaxRequest('name', 'common.delete.host_component');
+      expect(args[0]).exists;
+      expect(args[0].data).to.be.eql({
         componentName: 'COMP',
         hostName: 'host1'
       });
@@ -2636,8 +2636,9 @@ describe('App.MainHostDetailsController', function () {
     it('all components', function () {
       controller.set('content.hostName', 'host1');
       controller._doDeleteHostComponent(null);
-      expect(App.ajax.send.getCall(0).args[0].name).to.be.equal('common.delete.host');
-      expect(App.ajax.send.getCall(0).args[0].data).to.be.eql({
+      var args = testHelpers.findAjaxRequest('name', 'common.delete.host');
+      expect(args[0]).exists;
+      expect(args[0].data).to.be.eql({
         componentName: '',
         hostName: 'host1'
       });
@@ -2723,16 +2724,7 @@ describe('App.MainHostDetailsController', function () {
       controller.mimicWorkStatusChange.restore();
       controller.showBackgroundOperationsPopup.restore();
     });
-    it('testMode is true', function () {
-      App.set('testMode', true);
-
-      controller.upgradeComponentSuccessCallback({}, {}, {component: "COMP"});
-      expect(controller.mimicWorkStatusChange.calledWith("COMP", App.HostComponentStatus.starting, App.HostComponentStatus.started)).to.be.true;
-      expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
-    });
     it('testMode is false', function () {
-      App.set('testMode', false);
-
       controller.upgradeComponentSuccessCallback({}, {}, {component: "COMP"});
       expect(controller.mimicWorkStatusChange.called).to.be.false;
       expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
@@ -2822,12 +2814,10 @@ describe('App.MainHostDetailsController', function () {
     beforeEach(function () {
       sinon.stub(controller, 'showBackgroundOperationsPopup', Em.K);
       sinon.stub(controller, 'mimicWorkStatusChange', Em.K);
-      sinon.stub(App, 'get').withArgs('testMode').returns(false);
     });
     afterEach(function () {
       controller.mimicWorkStatusChange.restore();
       controller.showBackgroundOperationsPopup.restore();
-      App.get.restore();
     });
 
     it('testMode is false', function () {
@@ -2877,7 +2867,9 @@ describe('App.MainHostDetailsController', function () {
         componentName: 'COMP1'
       });
       controller.updateComponentPassiveState(component, 'state', 'message');
-      expect(App.ajax.send.getCall(0).args[0].data).to.be.eql({
+      var args = testHelpers.findAjaxRequest('name', 'common.host.host_component.passive');
+      expect(args[0]).exists;
+      expect(args[0].data).to.be.eql({
         "hostName": "host1",
         "componentName": "COMP1",
         "component": component,
@@ -3174,16 +3166,17 @@ describe('App.MainHostDetailsController', function () {
       beforeEach(function () {
         controller.set('content.hostComponents', Em.A([]));
         controller.doDeleteHost(Em.K);
+        this.args = testHelpers.findAjaxRequest('name', 'common.delete.host');
       });
 
       it('fromDeleteHost is true', function () {
         expect(controller.get('fromDeleteHost')).to.be.true;
       });
       it('1st request is to delete host', function () {
-        expect(App.ajax.send.getCall(0).args[0].name).to.be.equal('common.delete.host');
+        expect(this.args[0]).exists;
       });
       it('1st request is done with valid hostName', function () {
-        expect(App.ajax.send.getCall(0).args[0].data.hostName).to.be.equal('host1');
+        expect(this.args[0].data.hostName).to.be.equal('host1');
       });
     });
 
@@ -3205,10 +3198,12 @@ describe('App.MainHostDetailsController', function () {
         expect(controller.get('fromDeleteHost')).to.be.true;
       });
       it('1st request is to delete host', function () {
-        expect(App.ajax.send.getCall(0).args[0].name).to.be.equal('common.delete.host');
+        var args = testHelpers.findAjaxRequest('name', 'common.delete.host');
+        expect(args[0]).exists;
       });
       it('1st request is done with valid hostName', function () {
-        expect(App.ajax.send.getCall(0).args[0].data.hostName).to.be.equal('host1');
+        var args = testHelpers.findAjaxRequest('name', 'common.delete.host');
+        expect(args[0].data.hostName).to.be.equal('host1');
       });
 
     });
@@ -3311,14 +3306,12 @@ describe('App.MainHostDetailsController', function () {
     it("call App.ajax.send", function () {
       controller.set('content.hostName', 'host1');
       controller.installVersion({context: {}});
-      expect(App.ajax.send.getCall(0).args[0]).to.eql({
-        name: 'host.stack_versions.install',
-        sender: controller,
-        data: {
-          hostName: 'host1',
-          version: {}
-        },
-        success: 'installVersionSuccessCallback'
+      var args = testHelpers.findAjaxRequest('name', 'host.stack_versions.install');
+      expect(args[0]).exists;
+      expect(args[0].sender).to.be.eql(controller);
+      expect(args[0].data).to.be.eql({
+        hostName: 'host1',
+        version: {}
       });
     });
   });

+ 8 - 6
ambari-web/test/controllers/main/host_test.js

@@ -25,11 +25,15 @@ describe('MainHostController', function () {
 
   var hostController, db;
 
-  describe('#getRegExp()', function() {
-    before(function() {
-      hostController = App.MainHostController.create({});
-    });
+  beforeEach(function () {
+    hostController = App.MainHostController.create({});
+  });
 
+  afterEach(function () {
+    hostController.destroy();
+  });
+
+  describe('#getRegExp()', function() {
     var message = '`{0}` should convert to `{1}`',
       tests = [
         { value: '.*', expected: '.*' },
@@ -55,7 +59,6 @@ describe('MainHostController', function () {
 
   describe('#getQueryParameters', function() {
     beforeEach(function() {
-      hostController = App.MainHostController.create({});
       sinon.spy(hostController, 'getRegExp');
       sinon.stub(App.db, 'getFilterConditions', function() {
         return [{
@@ -88,7 +91,6 @@ describe('MainHostController', function () {
       db = {mainHostController: [
         {name: 'hostName', status: 'sorting'}
       ]};
-      hostController = App.MainHostController.create({});
       sinon.stub(App.db, 'getSortingStatuses', function (k) {
         return db[k];
       });

+ 3 - 72
ambari-web/test/controllers/main/service/add_controller_test.js

@@ -20,6 +20,7 @@ var App = require('app');
 require('controllers/wizard');
 require('controllers/main/service/add_controller');
 var addServiceController = null;
+var testHelpers = require('test/helpers');
 
 describe('App.AddServiceController', function() {
 
@@ -27,68 +28,6 @@ describe('App.AddServiceController', function() {
     addServiceController = App.AddServiceController.create({});
   });
 
-  describe('#installAdditionalClients', function() {
-
-    var t = {
-      additionalClients: {
-        componentName: "TEZ_CLIENT",
-        hostNames: ["hostName1", "hostName2"]
-      },
-      additionalClientsWithoutHosts: {
-        componentName: "TEZ_CLIENT",
-        hostNames: []
-      },
-      RequestInfo: {
-        "context": Em.I18n.t('requestInfo.installHostComponent') + ' ' + App.format.role("TEZ_CLIENT"),
-        "query": "HostRoles/component_name=TEZ_CLIENT&HostRoles/host_name.in(hostName1,hostName2)"
-      },
-      Body: {
-        HostRoles: {
-          state: 'INSTALLED'
-        }
-      }
-    };
-
-    beforeEach(function () {
-      sinon.spy($, 'ajax');
-      sinon.stub(App, 'get', function(k) {
-        if ('clusterName' === k) return 'tdk';
-        return Em.get(App, k);
-      });
-      addServiceController.set('installClietsQueue', App.ajaxQueue.create())
-    });
-
-    afterEach(function () {
-      $.ajax.restore();
-      App.get.restore();
-    });
-
-    describe('send request to install client', function () {
-
-      beforeEach(function () {
-        addServiceController.set("content.additionalClients", [t.additionalClients]);
-        addServiceController.installAdditionalClients();
-      });
-
-      it('1 request is sent', function () {
-        expect($.ajax.calledOnce).to.equal(true);
-      });
-      it('data.Body is valid', function () {
-        expect(JSON.parse($.ajax.args[0][0].data).Body).to.deep.eql(t.Body);
-      });
-      it('data.RequestInfo is valid', function () {
-        expect(JSON.parse($.ajax.args[0][0].data).RequestInfo).to.eql(t.RequestInfo);
-      });
-
-    });
-
-    it('should not send request to install client', function () {
-      addServiceController.set("content.additionalClients", [t.additionalClientsWithoutHosts]);
-      expect($.ajax.called).to.be.false;
-    });
-
-  });
-
   describe('#generateDataForInstallServices', function() {
     var tests = [{
       selected: ["YARN","HBASE"],
@@ -204,17 +143,8 @@ describe('App.AddServiceController', function() {
       }
     ];
 
-    beforeEach(function () {
-      sinon.stub(App.ajax, 'send', function () {
-        return {
-          promise: Em.K
-        };
-      });
-    });
-
     afterEach(function () {
       addServiceController.getDBProperty.restore();
-      App.ajax.send.restore();
     });
 
     cases.forEach(function (item) {
@@ -223,10 +153,11 @@ describe('App.AddServiceController', function() {
         beforeEach(function () {
           sinon.stub(addServiceController, 'getDBProperty').withArgs('hosts').returns(item.hosts);
           addServiceController.loadHosts();
+          this.args = testHelpers.findAjaxRequest('name', 'hosts.confirmed');
         });
 
         it('request is ' + (item.isAjaxRequestSent ? '' : 'not') + ' sent', function () {
-          expect(App.ajax.send.calledOnce).to.equal(item.isAjaxRequestSent);
+          expect(Em.isNone(this.args)).to.be.equal(!item.isAjaxRequestSent);
         });
       });
     });

+ 8 - 13
ambari-web/test/controllers/main/service/info/config_test.js

@@ -20,6 +20,7 @@ var App = require('app');
 require('controllers/main/service/info/configs');
 var batchUtils = require('utils/batch_scheduled_requests');
 var mainServiceInfoConfigsController = null;
+var testHelpers = require('test/helpers');
 
 function getController() {
   return App.MainServiceInfoConfigsController.create({
@@ -471,16 +472,15 @@ describe("App.MainServiceInfoConfigsController", function () {
       sinon.stub(App.router, 'getClusterName', function() {
         return 'clName';
       });
-      sinon.stub(App.ajax, "send", Em.K);
     });
     afterEach(function () {
-      App.ajax.send.restore();
       App.router.getClusterName.restore();
     });
     it("ajax request to put cluster cfg", function () {
       mainServiceInfoConfigsController.set('stepConfigs', sc);
       expect(mainServiceInfoConfigsController.putChangedConfigurations([]));
-      expect(App.ajax.send.calledOnce).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'common.across.services.configurations');
+      expect(args[0]).exists;
     });
     it('values should be parsed', function () {
       mainServiceInfoConfigsController.set('stepConfigs', sc);
@@ -624,16 +624,12 @@ describe("App.MainServiceInfoConfigsController", function () {
       }]
     };
 
-    beforeEach(function() {
-      sinon.spy($,"ajax");
-    });
-    afterEach(function() {
-      $.ajax.restore();
-    });
-
     it("updates configs groups", function() {
       mainServiceInfoConfigsController.putConfigGroupChanges(t.data);
-      expect(JSON.parse($.ajax.args[0][0].data)).to.deep.equal(t.request);
+      var args = testHelpers.findAjaxRequest('name', 'config_groups.update_config_group');
+      expect(args[0]).exists;
+      var data = JSON.parse(App.ajax.fakeGetUrl('config_groups.update_config_group').format(args[0].data).data);
+      expect(data).to.deep.equal(t.request);
     });
   });
 
@@ -770,7 +766,6 @@ describe("App.MainServiceInfoConfigsController", function () {
     describe('#bodyClass', function () {
       beforeEach(function() {
         sinon.stub(App.StackService, 'find').returns([{dependentServiceNames: []}]);
-        sinon.stub(App.ajax, 'send', Em.K);
         // default implementation
         bodyView = mainServiceInfoConfigsController.showSaveConfigsPopup().get('bodyClass').create({
           parentView: Em.View.create()
@@ -778,13 +773,13 @@ describe("App.MainServiceInfoConfigsController", function () {
       });
 
       afterEach(function() {
-        App.ajax.send.restore();
         App.StackService.find.restore();
       });
 
       describe('#componentsFilterSuccessCallback', function () {
         it('check components with unknown state', function () {
           bodyView = mainServiceInfoConfigsController.showSaveConfigsPopup('', true, '', {}, '', 'unknown', '').get('bodyClass').create({
+            didInsertElement: Em.K,
             parentView: Em.View.create()
           });
           bodyView.componentsFilterSuccessCallback({

+ 3 - 104
ambari-web/test/controllers/main/service/info/summary_test.js

@@ -18,7 +18,7 @@
 
 var App = require('app');
 require('controllers/main/service/info/summary');
-
+var testHelpers = require('test/helpers');
 function getController() {
   return App.MainServiceInfoSummaryController.create();
 }
@@ -134,102 +134,6 @@ App.TestAliases.testAsComputedOr(getController(), 'showTimeRangeControl', ['!isS
 
   });
 
-  describe('#getRangerPluginsStatus', function () {
-
-    var data = {
-        'Clusters': {
-          'desired_configs': {
-            'ranger-hdfs-plugin-properties': {
-              'tag': 'version1'
-            },
-            'hive-env': {
-              'tag': 'version2'
-            },
-            'ranger-hbase-plugin-properties': {
-              'tag': 'version3'
-            }
-          }
-        }
-      },
-      cases = [
-        {
-          isPreviousRangerConfigsCallFailed: false,
-          ajaxRequestSent: true,
-          title: 'initial case'
-        },
-        {
-          isPreviousRangerConfigsCallFailed: true,
-          hdfsTag: 'version1',
-          hiveTag: 'version2',
-          hbaseTag: 'version3',
-          ajaxRequestSent: true,
-          title: 'previous call failed'
-        },
-        {
-          isPreviousRangerConfigsCallFailed: false,
-          hdfsTag: 'version2',
-          hiveTag: 'version2',
-          hbaseTag: 'version3',
-          ajaxRequestSent: true,
-          title: 'configs changed'
-        },
-        {
-          isPreviousRangerConfigsCallFailed: false,
-          hdfsTag: 'version1',
-          hiveTag: 'version2',
-          hbaseTag: 'version3',
-          ajaxRequestSent: false,
-          title: 'configs unchanged'
-        }
-      ];
-
-    beforeEach(function () {
-      sinon.stub(App.ajax, 'send', Em.K);
-      sinon.stub(App.Service, 'find').returns([
-        Em.Object.create({
-          serviceName: 'HDFS'
-        }),
-        Em.Object.create({
-          serviceName: 'HIVE'
-        }),
-        Em.Object.create({
-          serviceName: 'HBASE'
-        }),
-        Em.Object.create({
-          serviceName: 'YARN'
-        })
-      ]);
-    });
-
-    afterEach(function () {
-      App.ajax.send.restore();
-      App.Service.find.restore();
-    });
-
-    cases.forEach(function (item) {
-      describe(item.title, function () {
-
-        beforeEach(function () {
-          controller.set('isPreviousRangerConfigsCallFailed', item.isPreviousRangerConfigsCallFailed);
-          controller.get('rangerPlugins').findProperty('serviceName', 'HDFS').tag = item.hdfsTag;
-          controller.get('rangerPlugins').findProperty('serviceName', 'HBASE').tag = item.hbaseTag;
-          controller.getRangerPluginsStatus(data);
-        });
-
-        it('1 request is ' + item.ajaxRequestSent + ' sent', function () {
-          expect(App.ajax.send.calledOnce).to.equal(item.ajaxRequestSent);
-        });
-
-        if (item.ajaxRequestSent) {
-          it('request does not contains `ranger-yarn-plugin-properties`', function () {
-            expect(App.ajax.send.getCall(0).args[0].data.urlParams.contains('ranger-yarn-plugin-properties')).to.be.false;
-          });
-        }
-      });
-    });
-
-  });
-
   describe('#getRangerPluginsStatusSuccess', function () {
 
     beforeEach(function () {
@@ -281,19 +185,14 @@ App.TestAliases.testAsComputedOr(getController(), 'showTimeRangeControl', ['!isS
   });
 
   describe("#getActiveWidgetLayout() for Enhanced Dashboard", function () {
-    before(function () {
-      sinon.stub(App.ajax, 'send');
-    });
-    after(function () {
-      App.ajax.send.restore();
-    });
+
     it("make GET call", function () {
       var _controller = App.MainServiceInfoSummaryController.create({
         isServiceWithEnhancedWidgets: true,
         content: Em.Object.create({serviceName: 'HDFS'})
       });
       _controller.getActiveWidgetLayout();
-      expect(App.ajax.send.getCall(0).args[0].name).to.equal('widgets.layouts.active.get');
+      expect(testHelpers.findAjaxRequest('name', 'widgets.layouts.active.get')).to.exists;
     });
   });
 

+ 11 - 16
ambari-web/test/controllers/main/service/item_test.js

@@ -27,6 +27,7 @@ require('controllers/global/cluster_controller');
 require('controllers/main/service/reassign_controller');
 require('controllers/main/service/item');
 var batchUtils = require('utils/batch_scheduled_requests');
+var testHelpers = require('test/helpers');
 
 describe('App.MainServiceItemController', function () {
 
@@ -977,12 +978,10 @@ describe('App.MainServiceItemController', function () {
   describe("#runSmokeTestPrimary", function () {
     beforeEach(function () {
       sinon.stub(App, 'get').withArgs('clusterName').returns('myCluster');
-      sinon.spy($, 'ajax');
     });
 
     afterEach(function () {
       App.get.restore();
-      $.ajax.restore();
     });
 
     var tests = [
@@ -1026,11 +1025,13 @@ describe('App.MainServiceItemController', function () {
           mainServiceItemController.set("runSmokeTestErrorCallBack", Em.K);
           mainServiceItemController.set("runSmokeTestSuccessCallBack", Em.K);
           mainServiceItemController.runSmokeTestPrimary(test.data.query);
-          this.data = JSON.parse($.ajax.args[0][0].data);
+          this.args = testHelpers.findAjaxRequest('name', 'service.item.smoke')[0];
+          this.data = this.args.data;
+          this.data = JSON.parse(App.ajax.fakeGetUrl('service.item.smoke').format(this.data).data);
         });
 
         it('ajax request is sent', function () {
-          expect($.ajax.calledOnce).to.equal(true);
+          expect(this.args).exists;
         });
 
         it('RequestInfo.context is valid', function () {
@@ -1284,22 +1285,16 @@ describe('App.MainServiceItemController', function () {
 
     beforeEach(function() {
       mainServiceItemController = App.MainServiceItemController.create({});
-      sinon.stub(App.ajax, 'send');
-    });
-    afterEach(function() {
-      App.ajax.send.restore();
     });
 
     it("App.ajax.send should be called", function() {
       mainServiceItemController.deleteServiceCall('S1');
-      expect(App.ajax.send.getCall(0).args[0]).to.eql({
-        name : 'service.item.delete',
-        sender: mainServiceItemController,
-        data : {
-          serviceName : 'S1'
-        },
-        success : 'deleteServiceCallSuccessCallback'
-      })
+      var args = testHelpers.findAjaxRequest('name', 'service.item.delete');
+      expect(args[0]).exists;
+      expect(args[0].sender).to.be.eql(mainServiceItemController);
+      expect(args[0].data).to.be.eql({
+        serviceName : 'S1'
+      });
     });
   });
 

+ 11 - 16
ambari-web/test/controllers/main/service/reassign/step1_controller_test.js

@@ -20,6 +20,7 @@ var App = require('app');
 
 require('controllers/main/service/reassign/step1_controller');
 require('models/host_component');
+var testHelpers = require('test/helpers');
 
 describe('App.ReassignMasterWizardStep1Controller', function () {
 
@@ -34,19 +35,17 @@ describe('App.ReassignMasterWizardStep1Controller', function () {
 
   describe('#loadConfigTags', function() {
     beforeEach(function() {
-      sinon.stub(App.ajax, 'send', Em.K);
       this.stub = sinon.stub(App.router, 'get');
     });
 
     afterEach(function() {
-      App.ajax.send.restore();
       this.stub.restore();
     });
 
     it('tests loadConfigTags', function() {
       controller.loadConfigsTags();
-
-      expect(App.ajax.send.calledOnce).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'config.tags');
+      expect(args).exists;
     });
 
     it('tests saveDatabaseType with type', function() {
@@ -203,29 +202,25 @@ describe('App.ReassignMasterWizardStep1Controller', function () {
   describe("#onLoadConfigsTags()", function () {
     beforeEach(function () {
       this.mock = sinon.stub(controller, 'getConfigUrlParams');
-      sinon.stub(App.ajax, 'send');
     });
     afterEach(function () {
       this.mock.restore();
-      App.ajax.send.restore();
     });
     it("empty params", function () {
       this.mock.returns([]);
       controller.onLoadConfigsTags();
-      expect(App.ajax.send.called).to.be.false;
+      var args = testHelpers.findAjaxRequest('name', 'reassign.load_configs');
+      expect(args).not.exists;
     });
     it("correct params", function () {
       this.mock.returns(['p1', 'p2']);
       controller.onLoadConfigsTags();
-      expect(App.ajax.send.calledWith({
-        name: 'reassign.load_configs',
-        sender: controller,
-        data: {
-          urlParams: 'p1|p2'
-        },
-        success: 'onLoadConfigs',
-        error: ''
-      })).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'reassign.load_configs');
+      expect(args[0]).exists;
+      expect(args[0].sender).to.be.eql(controller);
+      expect(args[0].data).to.be.eql({
+        urlParams: 'p1|p2'
+      });
     });
   });
 });

+ 91 - 110
ambari-web/test/controllers/main/service/reassign/step4_controller_test.js

@@ -19,6 +19,7 @@
 var App = require('app');
 
 require('controllers/main/service/reassign/step4_controller');
+var testHelpers = require('test/helpers');
 
 describe('App.ReassignMasterWizardStep4Controller', function () {
 
@@ -29,13 +30,6 @@ describe('App.ReassignMasterWizardStep4Controller', function () {
     })
   });
 
-  beforeEach(function () {
-    sinon.stub(App.ajax, 'send', Em.K);
-  });
-  afterEach(function () {
-    App.ajax.send.restore();
-  });
-
   describe('#setAdditionalConfigs()', function () {
 
     beforeEach(function () {
@@ -149,8 +143,8 @@ describe('App.ReassignMasterWizardStep4Controller', function () {
 
     it('tests prepareDBCheckAction', function() {
       controller.prepareDBCheckAction();
-
-      expect(App.ajax.send.calledOnce).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'cluster.custom_action.create');
+      expect(args).exists;
     });
 
   });
@@ -427,7 +421,8 @@ describe('App.ReassignMasterWizardStep4Controller', function () {
   describe('#stopServices()', function () {
     it('request is sent', function () {
       controller.stopServices();
-      expect(App.ajax.send.calledOnce).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'common.services.update');
+      expect(args).exists;
     });
   });
 
@@ -486,13 +481,15 @@ describe('App.ReassignMasterWizardStep4Controller', function () {
     it('No host-components', function () {
       controller.set('hostComponents', []);
       controller.putHostComponentsInMaintenanceMode();
-      expect(App.ajax.send.called).to.be.false;
+      var args = testHelpers.findAjaxRequest('name', 'common.host.host_component.passive');
+      expect(args).not.exists;
       expect(controller.get('multiTaskCounter')).to.equal(0);
     });
     it('One host-components', function () {
       controller.set('hostComponents', [{}]);
       controller.putHostComponentsInMaintenanceMode();
-      expect(App.ajax.send.calledOnce).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'common.host.host_component.passive');
+      expect(args).exists;
       expect(controller.get('multiTaskCounter')).to.equal(0);
     });
   });
@@ -544,7 +541,8 @@ describe('App.ReassignMasterWizardStep4Controller', function () {
   describe('#loadConfigsTags()', function () {
     it('request is sent', function () {
       controller.loadConfigsTags();
-      expect(App.ajax.send.calledOnce).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'config.tags');
+      expect(args).exists;
     });
   });
 
@@ -700,6 +698,7 @@ describe('App.ReassignMasterWizardStep4Controller', function () {
       });
       controller.set('content.reassign.component_name', 'COMP1');
       controller.onLoadConfigsTags({});
+      this.args = testHelpers.findAjaxRequest('name', 'reassign.load_configs');
     });
 
     afterEach(function () {
@@ -707,7 +706,7 @@ describe('App.ReassignMasterWizardStep4Controller', function () {
     });
 
     it('request is sent', function () {
-      expect(App.ajax.send.calledOnce).to.be.true;
+      expect(this.args).exists;
     });
 
     it('getConfigUrlParams is called with correct data', function () {
@@ -770,6 +769,7 @@ describe('App.ReassignMasterWizardStep4Controller', function () {
     beforeEach(function () {
       sinon.stub(controller, 'getServiceConfigData', Em.K);
       controller.saveConfigsToServer([1]);
+      this.args = testHelpers.findAjaxRequest('name', 'common.across.services.configurations');
     });
     afterEach(function () {
       controller.getServiceConfigData.restore();
@@ -778,7 +778,7 @@ describe('App.ReassignMasterWizardStep4Controller', function () {
       expect(controller.getServiceConfigData.calledWith([1])).to.be.true;
     });
     it('request is sent', function () {
-      expect(App.ajax.send.calledOnce).to.be.true;
+      expect(this.args).exists;
     });
   });
 
@@ -966,12 +966,13 @@ describe('App.ReassignMasterWizardStep4Controller', function () {
     beforeEach(function () {
       sinon.stub(App.router, 'get').returns({"skip.service.checks": "false"});
       controller.startServices();
+      this.args = testHelpers.findAjaxRequest('name', 'common.services.update');
     });
     afterEach(function () {
       App.router.get.restore();
     });
     it('request is sent', function () {
-      expect(App.ajax.send.calledOnce).to.be.true;
+      expect(this.args).exists;
     });
   });
 
@@ -981,17 +982,20 @@ describe('App.ReassignMasterWizardStep4Controller', function () {
       controller.set('hostComponents', []);
       controller.set('content.reassignHosts.source', 'host1');
       controller.deleteHostComponents();
-      expect(App.ajax.send.called).to.be.false;
+      var args = testHelpers.findAjaxRequest('name', 'common.delete.host_component');
+      expect(args).not.exists;
     });
     it('delete two components', function () {
       controller.set('hostComponents', [1, 2]);
       controller.set('content.reassignHosts.source', 'host1');
       controller.deleteHostComponents();
-      expect(App.ajax.send.getCall(0).args[0].data).to.eql({
+      var args = testHelpers.filterAjaxRequests('name', 'common.delete.host_component');
+      expect(args).to.have.property('length').equal(2);
+      expect(args[0][0].data).to.eql({
         "hostName": "host1",
         "componentName": 1
       });
-      expect(App.ajax.send.getCall(1).args[0].data).to.eql({
+      expect(args[1][0].data).to.eql({
         "hostName": "host1",
         "componentName": 2
       });
@@ -1138,30 +1142,24 @@ describe('App.ReassignMasterWizardStep4Controller', function () {
     it('component_name is C1', function () {
       controller.set('content.reassign.component_name', 'C1');
       controller.cleanMySqlServer();
-      expect(App.ajax.send.calledWith({
-        name: 'service.mysql.clean',
-        sender: controller,
-        data: {
-          host: 'host1'
-        },
-        success: 'startPolling',
-        error: 'onTaskError'
-      })).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'service.mysql.clean');
+      expect(args[0]).exists;
+      expect(args[0].sender).to.be.eql(controller);
+      expect(args[0].data).to.be.eql({
+        host: 'host1'
+      });
     });
 
     it('component_name is MYSQL_SERVER', function () {
       controller.set('content.reassign.component_name', 'MYSQL_SERVER');
       controller.set('content.reassignHosts.target', 'host2');
       controller.cleanMySqlServer();
-      expect(App.ajax.send.calledWith({
-        name: 'service.mysql.clean',
-        sender: controller,
-        data: {
-          host: 'host2'
-        },
-        success: 'startPolling',
-        error: 'onTaskError'
-      })).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'service.mysql.clean');
+      expect(args[0]).exists;
+      expect(args[0].sender).to.be.eql(controller);
+      expect(args[0].data).to.be.eql({
+        host: 'host2'
+      });
     });
   });
 
@@ -1183,30 +1181,24 @@ describe('App.ReassignMasterWizardStep4Controller', function () {
     it('component_name is C1', function () {
       controller.set('content.reassign.component_name', 'C1');
       controller.configureMySqlServer();
-      expect(App.ajax.send.calledWith({
-        name: 'service.mysql.configure',
-        sender: controller,
-        data: {
-          host: 'host1'
-        },
-        success: 'startPolling',
-        error: 'onTaskError'
-      })).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'service.mysql.configure');
+      expect(args[0]).exists;
+      expect(args[0].sender).to.be.eql(controller);
+      expect(args[0].data).to.be.eql({
+        host: 'host1'
+      });
     });
 
     it('component_name is MYSQL_SERVER', function () {
       controller.set('content.reassign.component_name', 'MYSQL_SERVER');
       controller.set('content.reassignHosts.target', 'host2');
       controller.configureMySqlServer();
-      expect(App.ajax.send.calledWith({
-        name: 'service.mysql.configure',
-        sender: controller,
-        data: {
-          host: 'host2'
-        },
-        success: 'startPolling',
-        error: 'onTaskError'
-      })).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'service.mysql.configure');
+      expect(args[0]).exists;
+      expect(args[0].sender).to.be.eql(controller);
+      expect(args[0].data).to.be.eql({
+        host: 'host2'
+      });
     });
   });
 
@@ -1243,21 +1235,18 @@ describe('App.ReassignMasterWizardStep4Controller', function () {
     });
     it("valid request is sent", function() {
       controller.startMySqlServer();
-      expect(App.ajax.send.calledWith({
-        name: 'common.host.host_component.update',
-        sender: controller,
-        data: {
-          context: "Start MySQL Server",
-          hostName: 'host1',
-          serviceName: "HIVE",
-          componentName: "MYSQL_SERVER",
-          HostRoles: {
-            state: "STARTED"
-          }
-        },
-        success: 'startPolling',
-        error: 'onTaskError'
-      })).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'common.host.host_component.update');
+      expect(args[0]).exists;
+      expect(args[0].sender).to.be.eql(controller);
+      expect(args[0].data).to.be.eql({
+        context: "Start MySQL Server",
+        hostName: 'host1',
+        serviceName: "HIVE",
+        componentName: "MYSQL_SERVER",
+        HostRoles: {
+          state: "STARTED"
+        }
+      });
     });
   });
 
@@ -1280,26 +1269,23 @@ describe('App.ReassignMasterWizardStep4Controller', function () {
         })
       }));
       controller.restartMySqlServer();
-      expect(App.ajax.send.calledWith({
-        name: 'restart.hostComponents',
-        sender: controller,
-        data: {
-          context: 'Restart MySql Server',
-          resource_filters: [{
-            component_name: "MYSQL_SERVER",
-            hosts: 'host1',
-            service_name: "HIVE"
-          }],
-          operation_level: {
-            level: "HOST_COMPONENT",
-            cluster_name: 'cl1',
-            service_name: "HIVE",
-            hostcomponent_name: "MYSQL_SERVER"
-          }
-        },
-        success: 'startPolling',
-        error: 'onTaskError'
-      })).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'restart.hostComponents');
+      expect(args[0]).exists;
+      expect(args[0].sender).to.be.eql(controller);
+      expect(args[0].data).to.be.eql({
+        context: 'Restart MySql Server',
+        resource_filters: [{
+          component_name: "MYSQL_SERVER",
+          hosts: 'host1',
+          service_name: "HIVE"
+        }],
+        operation_level: {
+          level: "HOST_COMPONENT",
+          cluster_name: 'cl1',
+          service_name: "HIVE",
+          hostcomponent_name: "MYSQL_SERVER"
+        }
+      });
     });
   });
 
@@ -1312,24 +1298,21 @@ describe('App.ReassignMasterWizardStep4Controller', function () {
         })
       }));
       controller.startNewMySqlServer();
+      this.args = testHelpers.findAjaxRequest('name', 'common.host.host_component.update');
     });
 
     it('valid request is sent', function() {
-      expect(App.ajax.send.calledWith({
-        name: 'common.host.host_component.update',
-        sender: controller,
-        data: {
-          context: "Start MySQL Server",
-          hostName: 'host1',
-          serviceName: "HIVE",
-          componentName: "MYSQL_SERVER",
-          HostRoles: {
-            state: "STARTED"
-          }
-        },
-        success: 'startPolling',
-        error: 'onTaskError'
-      })).to.be.true;
+      expect(this.args[0]).exists;
+      expect(this.args[0].sender).to.be.eql(controller);
+      expect(this.args[0].data).to.be.eql({
+        context: "Start MySQL Server",
+        hostName: 'host1',
+        serviceName: "HIVE",
+        componentName: "MYSQL_SERVER",
+        HostRoles: {
+          state: "STARTED"
+        }
+      });
     });
   });
 
@@ -1598,17 +1581,15 @@ describe('App.ReassignMasterWizardStep4Controller', function () {
         preparedDBProperties: {}
       });
       controller.prepareDBCheckAction();
+      this.args = testHelpers.findAjaxRequest('name', 'cluster.custom_action.create');
     });
     afterEach(function () {
       App.router.get.restore();
       controller.getConnectionProperty.restore();
     });
     it('valid request is sent', function () {
-      var callArgs = App.ajax.send.getCall(0).args[0];
-      expect(callArgs.name).to.equal('cluster.custom_action.create');
-      expect(callArgs.success).to.equal('onCreateActionSuccess');
-      expect(callArgs.error).to.equal('onTaskError');
-      expect(callArgs.data).to.eql({
+      expect(this.args[0]).exists;
+      expect(this.args[0].data).to.eql({
         requestInfo: {
           "context": "Check host",
           "action": "check_host",

+ 13 - 11
ambari-web/test/controllers/main/service/reassign/step6_controller_test.js

@@ -20,6 +20,7 @@ App = require('app');
 
 require('controllers/main/service/reassign/step6_controller');
 var controller;
+var testHelpers = require('test/helpers');
 
 describe('App.ReassignMasterWizardStep6Controller', function () {
 
@@ -31,12 +32,7 @@ describe('App.ReassignMasterWizardStep6Controller', function () {
       }),
       startServices: Em.K
     });
-    sinon.stub(App.ajax, 'send', Em.K);
   });
-  afterEach(function () {
-    App.ajax.send.restore();
-  });
-
 
   describe('#initializeTasks()', function () {
     it('No commands', function () {
@@ -155,17 +151,20 @@ describe('App.ReassignMasterWizardStep6Controller', function () {
       controller.set('hostComponents', []);
       controller.set('content.reassignHosts.source', 'host1');
       controller.deleteHostComponents();
-      expect(App.ajax.send.called).to.be.false;
+      var args = testHelpers.findAjaxRequest('name', 'common.delete.host_component');
+      expect(args).not.exists;
     });
     it('delete two components', function () {
       controller.set('hostComponents', [1, 2]);
       controller.set('content.reassignHosts.source', 'host1');
       controller.deleteHostComponents();
-      expect(App.ajax.send.getCall(0).args[0].data).to.eql({
+      var args = testHelpers.filterAjaxRequests('name', 'common.delete.host_component');
+      expect(args).to.have.property('length').equal(2);
+      expect(args[0][0].data).to.eql({
         "hostName": "host1",
         "componentName": 1
       });
-      expect(App.ajax.send.getCall(1).args[0].data).to.eql({
+      expect(args[1][0].data).to.eql({
         "hostName": "host1",
         "componentName": 2
       });
@@ -201,7 +200,8 @@ describe('App.ReassignMasterWizardStep6Controller', function () {
   describe('#stopMysqlService()', function () {
     it('stopMysqlService', function () {
       controller.stopMysqlService();
-      expect(App.ajax.send.calledOnce).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'common.host.host_component.update');
+      expect(args[0]).exists;
     });
   });
 
@@ -216,13 +216,15 @@ describe('App.ReassignMasterWizardStep6Controller', function () {
     it('No host-components', function () {
       controller.set('hostComponents', []);
       controller.putHostComponentsInMaintenanceMode();
-      expect(App.ajax.send.called).to.be.false;
+      var args = testHelpers.findAjaxRequest('name', 'common.host.host_component.passive');
+      expect(args).not.exists;
       expect(controller.get('multiTaskCounter')).to.equal(0);
     });
     it('One host-components', function () {
       controller.set('hostComponents', [{}]);
       controller.putHostComponentsInMaintenanceMode();
-      expect(App.ajax.send.calledOnce).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'common.host.host_component.passive');
+      expect(args).exists;
       expect(controller.get('multiTaskCounter')).to.equal(0);
     });
   });

+ 24 - 29
ambari-web/test/controllers/main/service/reassign/step7_controller_test.js

@@ -20,11 +20,11 @@ App = require('app');
 
 require('controllers/main/service/reassign/step7_controller');
 var controller;
+var testHelpers = require('test/helpers');
 
 describe('App.ReassignMasterWizardStep7Controller', function () {
 
   beforeEach(function () {
-    sinon.stub(App.ajax, 'send', Em.K);
     controller = App.ReassignMasterWizardStep7Controller.create({
       content: Em.Object.create({
         reassign: Em.Object.create(),
@@ -32,9 +32,6 @@ describe('App.ReassignMasterWizardStep7Controller', function () {
       })
     });
   });
-  afterEach(function () {
-    App.ajax.send.restore();
-  });
 
   describe('#initializeTasks()', function () {
     it('should set isLoaded to true', function () {
@@ -49,30 +46,29 @@ describe('App.ReassignMasterWizardStep7Controller', function () {
     it("no host-components", function() {
       controller.set('hostComponents', []);
       controller.putHostComponentsInMaintenanceMode();
-      expect(App.ajax.send.called).to.be.false;
+      var args = testHelpers.findAjaxRequest('name', 'common.host.host_component.passive');
+      expect(args).not.exists;
       expect(controller.get('multiTaskCounter')).to.equal(0);
     });
     it("one host-component", function() {
       controller.set('hostComponents', ['C1']);
       controller.set('content.reassignHosts.target', 'host1');
       controller.putHostComponentsInMaintenanceMode();
-      expect(App.ajax.send.calledWith({
-        name: 'common.host.host_component.passive',
-        sender: controller,
-        data: {
-          hostName: 'host1',
-          passive_state: "ON",
-          componentName: 'C1'
-        },
-        success: 'onComponentsTasksSuccess',
-        error: 'onTaskError'
-      })).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'common.host.host_component.passive');
+      expect(args[0]).exists;
+      expect(args[0].sender).to.be.eql(controller);
+      expect(args[0].data).to.be.eql({
+        hostName: 'host1',
+        passive_state: "ON",
+        componentName: 'C1'
+      });
       expect(controller.get('multiTaskCounter')).to.equal(0);
     });
     it("two host-components", function() {
       controller.set('hostComponents', ['C1', 'C2']);
       controller.putHostComponentsInMaintenanceMode();
-      expect(App.ajax.send.calledTwice).to.be.true;
+      var args = testHelpers.filterAjaxRequests('name', 'common.host.host_component.passive');
+      expect(args).to.have.property('length').equal(2);
       expect(controller.get('multiTaskCounter')).to.equal(0);
     });
   });
@@ -81,29 +77,28 @@ describe('App.ReassignMasterWizardStep7Controller', function () {
     it("no host-components", function() {
       controller.set('hostComponents', []);
       controller.deleteHostComponents();
-      expect(App.ajax.send.called).to.be.false;
+      var args = testHelpers.findAjaxRequest('name', 'common.delete.host_component');
+      expect(args).not.exists;
       expect(controller.get('multiTaskCounter')).to.equal(0);
     });
     it("one host-component", function() {
       controller.set('hostComponents', ['C1']);
       controller.set('content.reassignHosts.target', 'host1');
       controller.deleteHostComponents();
-      expect(App.ajax.send.calledWith({
-        name: 'common.delete.host_component',
-        sender: controller,
-        data: {
-          hostName: 'host1',
-          componentName: 'C1'
-        },
-        success: 'onComponentsTasksSuccess',
-        error: 'onDeleteHostComponentsError'
-      })).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'common.delete.host_component');
+      expect(args[0]).exists;
+      expect(args[0].sender).to.be.eql(controller);
+      expect(args[0].data).to.be.eql({
+        hostName: 'host1',
+        componentName: 'C1'
+      });
       expect(controller.get('multiTaskCounter')).to.equal(0);
     });
     it("two host-components", function() {
       controller.set('hostComponents', ['C1', 'C2']);
       controller.deleteHostComponents();
-      expect(App.ajax.send.calledTwice).to.be.true;
+      var args = testHelpers.filterAjaxRequests('name', 'common.delete.host_component');
+      expect(args).to.have.property('length').equal(2);
       expect(controller.get('multiTaskCounter')).to.equal(0);
     });
   });

+ 7 - 24
ambari-web/test/controllers/main/service_test.js

@@ -19,6 +19,7 @@
 var App = require('app');
 require('controllers/main/service');
 
+var testHelpers = require('test/helpers');
 var mainServiceController;
 
 function getController() {
@@ -82,6 +83,10 @@ describe('App.MainServiceController', function () {
     mainServiceController = getController();
   });
 
+  afterEach(function () {
+    mainServiceController.destroy();
+  });
+
   App.TestAliases.testAsComputedNotEqual(getController(), 'isStartStopAllClicked', 'App.router.backgroundOperationsController.allOperationsCount', 0);
 
   describe('#isStartAllDisabled', function () {
@@ -277,28 +282,23 @@ describe('App.MainServiceController', function () {
       query = 'some query';
 
     beforeEach(function() {
-      sinon.stub($, 'ajax', Em.K);
       sinon.stub(App, 'get', function(k) {
-        if ('testMode' === k) return false;
         if ('clusterName' === k) return 'tdk';
         return Em.get(App, k);
       });
       mainServiceController.allServicesCall(state, query);
-      this.params = $.ajax.args[0][0];
+      var args = testHelpers.findAjaxRequest('name', 'common.services.update');
+      this.params = App.ajax.fakeGetUrl('common.services.update').format(args[0].data);
       this.data = JSON.parse(this.params.data);
     });
 
     afterEach(function() {
-      $.ajax.restore();
       App.get.restore();
     });
 
     it('PUT request is sent', function() {
       expect(this.params.type).to.equal('PUT');
     });
-    it('request is sent to `/services`', function() {
-      expect(this.params.url.contains('/clusters/tdk/services?')).to.be.true;
-    });
     it('Body.ServiceInfo.state is ' + state, function() {
       expect(this.data.Body.ServiceInfo.state).to.equal(state);
     });
@@ -408,21 +408,4 @@ describe('App.MainServiceController', function () {
 
   });
 
-  describe('#restartHostComponents', function () {
-
-    beforeEach(function () {
-      sinon.stub(App.ajax, 'send', Em.K);
-    });
-
-    afterEach(function () {
-      App.ajax.send.restore();
-    });
-
-    it('should send ajax request', function () {
-      mainServiceController.restartHostComponents();
-      expect(App.ajax.send.calledOnce).to.be.true;
-    });
-
-  });
-
 });

+ 5 - 4
ambari-web/test/controllers/main/views_controller_test.js

@@ -18,6 +18,7 @@
 
 var App = require('app');
 require('controllers/main/views_controller');
+var testHelpers = require('test/helpers');
 
 var mainViewsController;
 describe('MainViewsController', function () {
@@ -28,24 +29,24 @@ describe('MainViewsController', function () {
 
   describe('#loadAmbariViews()', function () {
     beforeEach(function () {
-      sinon.stub(App.ajax, 'send', Em.K);
       this.stub = sinon.stub(App.router, 'get');
     });
     afterEach(function () {
       App.router.get.restore();
-      App.ajax.send.restore();
     });
 
     it('should load views if the user is logged in', function () {
       this.stub.withArgs('loggedIn').returns(true);
       mainViewsController.loadAmbariViews();
-      expect(App.ajax.send.calledOnce).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'views.info');
+      expect(args).to.exists;
     });
 
     it('should not load views if the user is not logged in', function () {
       this.stub.withArgs('loggedIn').returns(false);
       mainViewsController.loadAmbariViews();
-      expect(App.ajax.send.notCalled).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'views.info');
+      expect(args).to.not.exists;
     })
   });
 

+ 6 - 19
ambari-web/test/controllers/main_test.js

@@ -16,8 +16,8 @@
  * limitations under the License.
  */
 
-
 var App = require('app');
+var testHelpers = require('test/helpers');
 
 describe('App.MainController', function () {
   var mainController = App.MainController.create();
@@ -132,26 +132,13 @@ describe('App.MainController', function () {
   });
 
   describe('#getServerVersion', function() {
-    var res;
-    beforeEach(function () {
-      sinon.stub(App.ajax, 'send', function(data) {
-        res = JSON.parse(JSON.stringify(data));
-      });
-    });
-    afterEach(function () {
-      App.ajax.send.restore();
-    });
+
     it ('Should send data', function() {
       mainController.getServerVersion();
-      expect(res).to.be.eql({
-        "name": "ambari.service",
-        "sender": {},
-        "data": {
-          "fields": "?fields=RootServiceComponents/component_version,RootServiceComponents/properties/server.os_family&minimal_response=true"
-        },
-        "success": "getServerVersionSuccessCallback",
-        "error": "getServerVersionErrorCallback"
-      });
+      var args = testHelpers.findAjaxRequest('name', 'ambari.service');
+      expect(args[0]).to.exists;
+      expect(args[0].sender).to.be.eql(mainController);
+      expect(args[0].data.fields).to.be.eql('?fields=RootServiceComponents/component_version,RootServiceComponents/properties/server.os_family&minimal_response=true');
     });
   });
 

+ 4 - 7
ambari-web/test/controllers/wizard/step2_test.js

@@ -21,6 +21,7 @@ require('controllers/wizard/step2_controller');
 require('models/host');
 require('models/host_component');
 require('messages');
+var testHelpers = require('test/helpers');
 var c;
 
 function getController() {
@@ -582,16 +583,12 @@ describe('App.WizardStep2Controller', function () {
   });
 
   describe('#setAmbariJavaHome', function() {
-    beforeEach(function() {
-      sinon.stub($, 'ajax', Em.K);
-    });
-    afterEach(function() {
-      $.ajax.restore();
-    });
+
     it('should do ajax-request', function() {
       var controller = App.WizardStep2Controller.create({onGetAmbariJavaHomeSuccess: Em.K, onGetAmbariJavaHomeError: Em.K});
       controller.setAmbariJavaHome();
-      expect($.ajax.calledOnce).to.equal(true);
+      var args = testHelpers.findAjaxRequest('name', 'ambari.service');
+      expect(args).exists;
     });
   });
 

+ 17 - 78
ambari-web/test/controllers/wizard/step3_test.js

@@ -22,6 +22,7 @@ require('utils/ajax/ajax');
 require('utils/http_client');
 require('models/host');
 require('controllers/wizard/step3_controller');
+var testHelpers = require('test/helpers');
 
 function getController() {
   return App.WizardStep3Controller.create({
@@ -41,16 +42,12 @@ describe('App.WizardStep3Controller', function () {
     sinon.stub(App.db, 'getDisplayLength', Em.K);
     sinon.stub(App.db, 'getFilterConditions').returns([]);
     sinon.stub(App.router, 'send', Em.K);
-    sinon.stub(App.ajax, 'send', function () {
-      return {done: Em.K}
-    });
   });
 
   afterEach(function () {
     App.db.getDisplayLength.restore();
     App.router.send.restore();
     App.db.getFilterConditions.restore();
-    App.ajax.send.restore();
   });
 
   App.TestAliases.testAsComputedGt(getController(), 'isHostHaveWarnings', 'warnings.length', 0);
@@ -153,14 +150,6 @@ describe('App.WizardStep3Controller', function () {
 
   describe('#isWarningsBoxVisible', function () {
 
-    beforeEach(function () {
-      sinon.stub(App, 'get').withArgs('testMode').returns(false);
-    });
-
-    afterEach(function () {
-      App.get.restore();
-    });
-
     it('for "real" mode should be based on isRegistrationInProgress', function () {
       c.set('isRegistrationInProgress', false);
       expect(c.get('isWarningsBoxVisible')).to.equal(true);
@@ -259,25 +248,9 @@ describe('App.WizardStep3Controller', function () {
 
     afterEach(function () {
       c.navigateStep.restore();
-      App.set('testMode', false);
-    });
-
-    it('should set isLoaded to true', function () {
-      App.set('testMode', true);
-      c.set('content', {hosts: {}});
-      c.loadHosts();
-      expect(c.get('isLoaded')).to.equal(true);
-    });
-
-    it('should set bootStatus REGISTERED on testMode', function () {
-      App.set('testMode', true);
-      c.set('content', {hosts: {c: {name: 'name'}}});
-      c.loadHosts();
-      expect(c.get('hosts').everyProperty('bootStatus', 'REGISTERED')).to.equal(true);
     });
 
     it('should set bootStatus DONE on "real" mode and when installOptions.manualInstall is selected', function () {
-      App.set('testMode', false);
       c.set('content.installOptions', {manualInstall: true});
       c.set('content.hosts', {c: {name: 'name'}});
       c.loadHosts();
@@ -285,14 +258,12 @@ describe('App.WizardStep3Controller', function () {
     });
 
     it('should set bootStatus PENDING on "real" mode and when installOptions.manualInstall is not selected', function () {
-      App.set('testMode', false);
       c.set('content', {installOptions: {manualInstall: false}, hosts: {c: {name: 'name'}}});
       c.loadHosts();
       expect(c.get('hosts').everyProperty('bootStatus', 'PENDING')).to.equal(true);
     });
 
     it('should set bootStatus PENDING on "real" mode and when installOptions.manualInstall is not selected (2)', function () {
-      App.set('testMode', true);
       c.set('content', {hosts: {c: {name: 'name'}, d: {name: 'name1'}}});
       c.loadHosts();
       expect(c.get('hosts').everyProperty('isChecked', false)).to.equal(true);
@@ -754,14 +725,16 @@ describe('App.WizardStep3Controller', function () {
     it('shouldn\'t do nothing if stopBootstrap is true', function () {
       c.set('stopBootstrap', true);
       c.doBootstrap();
-      expect(App.ajax.send.called).to.equal(false);
+      var args = testHelpers.findAjaxRequest('name', 'wizard.step3.bootstrap');
+      expect(args).not.exists;
     });
 
     it('should increment numPolls if stopBootstrap is false', function () {
       c.set('numPolls', 0);
       c.set('stopBootstrap', false);
       c.doBootstrap();
-      expect(App.ajax.send.calledOnce).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'wizard.step3.bootstrap');
+      expect(args).exists;
       expect(c.get('numPolls')).to.equal(1);
     });
 
@@ -796,13 +769,15 @@ describe('App.WizardStep3Controller', function () {
     it('shouldn\'t do nothing if stopBootstrap is true', function () {
       c.set('stopBootstrap', true);
       c.isHostsRegistered();
-      expect(App.ajax.send.called).to.equal(false);
+      var args = testHelpers.findAjaxRequest('name', 'wizard.step3.is_hosts_registered');
+      expect(args).not.exists;
     });
 
     it('should do ajax call if stopBootstrap is false', function () {
       c.set('stopBootstrap', false);
       c.isHostsRegistered();
-      expect(App.ajax.send.called).to.equal(true);
+      var args = testHelpers.findAjaxRequest('name', 'wizard.step3.is_hosts_registered');
+      expect(args).exists;
 
     });
   });
@@ -905,7 +880,8 @@ describe('App.WizardStep3Controller', function () {
 
     it('should call App.ajax.send', function () {
       c.getAllRegisteredHosts();
-      expect(App.ajax.send.calledOnce).to.equal(true);
+      var args = testHelpers.findAjaxRequest('name', 'wizard.step3.is_hosts_registered');
+      expect(args).exists;
     });
   });
 
@@ -1009,7 +985,8 @@ describe('App.WizardStep3Controller', function () {
 
     it('should do ajax request', function () {
       c.getHostInfo();
-      expect(App.ajax.send.calledOnce).to.equal(true);
+      var args = testHelpers.findAjaxRequest('name', 'wizard.step3.host_info');
+      expect(args).exists;
     });
 
   });
@@ -1277,17 +1254,12 @@ describe('App.WizardStep3Controller', function () {
   describe('#parseHostCheckWarnings', function () {
 
     beforeEach(function () {
-      sinon.stub(App, 'get', function (k) {
-        if ('testMode' === k) return false;
-        return Em.get(App, k);
-      });
       sinon.stub(c, 'filterHostsData', function (k) {
         return k;
       });
     });
 
     afterEach(function () {
-      App.get.restore();
       c.filterHostsData.restore();
     });
 
@@ -1775,17 +1747,12 @@ describe('App.WizardStep3Controller', function () {
   describe('#parseWarnings', function () {
 
     beforeEach(function () {
-      sinon.stub(App, 'get', function (k) {
-        if ('testMode' === k) return false;
-        return Em.get(App, k);
-      });
       sinon.stub(c, 'filterBootHosts', function (k) {
         return k;
       });
     });
 
     afterEach(function () {
-      App.get.restore();
       c.filterBootHosts.restore();
     });
 
@@ -2327,17 +2294,12 @@ describe('App.WizardStep3Controller', function () {
           setRegistrationInProgress: Em.K,
           startRegistration: Em.K
         });
-        sinon.stub(App, 'get', function (k) {
-          if ('testMode' === k) return false;
-          return Em.get(App, k);
-        });
         sinon.spy(c, 'startRegistration');
         c.navigateStep();
       });
 
 
       afterEach(function () {
-        App.get.restore();
         c.startRegistration.restore();
       });
 
@@ -2540,7 +2502,6 @@ describe('App.WizardStep3Controller', function () {
       sinon.spy(c, '_setHostDataWithSkipBootstrap');
       sinon.stub(App, 'get', function (k) {
         if ('skipBootstrap' === k) return skipBootstrap;
-        if ('testMode' === k) return false;
         return Em.get(App, k);
       });
       c.reopen({
@@ -2671,17 +2632,6 @@ describe('App.WizardStep3Controller', function () {
 
   describe('#doCheckJDK', function () {
 
-    beforeEach(function () {
-      sinon.stub(App, 'get', function (k) {
-        if ('testMode' === k) return false;
-        return Em.get(App, k);
-      });
-    });
-
-    afterEach(function () {
-      App.get.restore();
-    });
-
     it('should do request to the ambari-server', function () {
 
       var bootHosts = [
@@ -2696,24 +2646,14 @@ describe('App.WizardStep3Controller', function () {
         jdkLocation: jdkLocation
       });
       c.doCheckJDK();
-      expect(App.ajax.send.calledOnce).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'wizard.step3.jdk_check');
+      expect(args).exists;
     });
 
   });
 
   describe('#doCheckJDKsuccessCallback', function () {
 
-    beforeEach(function () {
-      sinon.stub(App, 'get', function (k) {
-        if ('testMode' === k) return false;
-        return Em.get(App, k);
-      });
-    });
-
-    afterEach(function () {
-      App.get.restore();
-    });
-
     it('should set jdkRequestIndex if data provided', function () {
 
       var data = {
@@ -2742,7 +2682,8 @@ describe('App.WizardStep3Controller', function () {
       c.set('jdkRequestIndex', jdkRequestIndex);
       c.set('jdkCategoryWarnings', null);
       c.doCheckJDKsuccessCallback(data);
-      expect(App.ajax.send.calledOnce).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'wizard.step3.jdk_check.get_results');
+      expect(args).exists;
     });
 
   });
@@ -2834,7 +2775,6 @@ describe('App.WizardStep3Controller', function () {
   describe('#getHostCheckTasksSuccess', function() {
 
     beforeEach(function() {
-      sinon.stub($, 'ajax', Em.K);
       sinon.stub(c, 'getHostInfo', Em.K);
       sinon.stub(c, 'parseHostNameResolution', Em.K);
       sinon.stub(c, 'getGeneralHostCheck', Em.K);
@@ -2843,7 +2783,6 @@ describe('App.WizardStep3Controller', function () {
     });
 
     afterEach(function() {
-      $.ajax.restore();
       c.getHostInfo.restore();
       c.parseHostNameResolution.restore();
       c.getGeneralHostCheck.restore();

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

@@ -75,15 +75,6 @@ describe('App.WizardStep6Controller', function () {
 
   beforeEach(function () {
     controller = getController();
-    sinon.stub(App.ajax, 'send', function () {
-      return {
-        then: Em.K
-      };
-    });
-  });
-
-  afterEach(function () {
-    App.ajax.send.restore();
   });
 
   App.TestAliases.testAsComputedEqual(getController(), 'isAddHostWizard', 'content.controllerName', 'addHostController');

+ 8 - 10
ambari-web/test/controllers/wizard/step7_test.js

@@ -19,6 +19,7 @@
 var App = require('app');
 require('mixins/common/localStorage');
 require('controllers/wizard/step7_controller');
+var testHelpers = require('test/helpers');
 
 var installerStep7Controller,
   issuesFilterCases = [
@@ -108,17 +109,11 @@ function getController() {
 describe('App.InstallerStep7Controller', function () {
 
   beforeEach(function () {
-    sinon.stub(App.ajax, 'send', function () {
-      return {
-        then: Em.K
-      }
-    });
     sinon.stub(App.config, 'setPreDefinedServiceConfigs', Em.K);
     installerStep7Controller = getController();
   });
 
   afterEach(function() {
-    App.ajax.send.restore();
     App.config.setPreDefinedServiceConfigs.restore();
     installerStep7Controller.destroy();
   });
@@ -434,14 +429,16 @@ describe('App.InstallerStep7Controller', function () {
     it('should do ajax request for each received service name', function () {
       var serviceNames = ['s1', 's2', 's3'];
       installerStep7Controller.loadInstalledServicesConfigGroups(serviceNames);
-      expect(App.ajax.send.callCount).to.equal(serviceNames.length);
+      var args = testHelpers.filterAjaxRequests('name', 'config.tags_and_groups');
+      expect(args).to.have.property('length').equal(serviceNames.length);
     });
   });
 
   describe('#getConfigTags', function () {
     it('should do ajax-request', function () {
       installerStep7Controller.getConfigTags();
-      expect(App.ajax.send.calledOnce).to.equal(true);
+      var args = testHelpers.findAjaxRequest('name', 'config.tags');
+      expect(args).exists;
     });
   });
 
@@ -475,7 +472,8 @@ describe('App.InstallerStep7Controller', function () {
   describe('#checkMySQLHost', function () {
     it('should send query', function () {
       installerStep7Controller.checkMySQLHost();
-      expect(App.ajax.send.calledOnce).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'ambari.service');
+      expect(args).exists;
     });
   });
 
@@ -2179,7 +2177,7 @@ describe('App.InstallerStep7Controller', function () {
 
     beforeEach(function () {
       installerStep7Controller.loadServiceConfigGroupOverrides(serviceConfigs, loadedGroupToOverrideSiteToTagMap, configGroups);
-      this.args = App.ajax.send.args[0][0].data;
+      this.args = testHelpers.findAjaxRequest('name', 'config.host_overrides')[0].data;
     });
 
     it('url params are valid', function () {

+ 20 - 65
ambari-web/test/controllers/wizard/step8_test.js

@@ -21,6 +21,7 @@ require('utils/ajax/ajax_queue');
 require('controllers/main/service/info/configs');
 require('controllers/wizard/step8_controller');
 var installerStep8Controller, configurationController;
+var testHelpers = require('test/helpers');
 
 var configs = Em.A([
   Em.Object.create({filename: 'hdfs-site.xml', name: 'p1', value: 'v1'}),
@@ -867,7 +868,6 @@ describe('App.WizardStep8Controller', function () {
 
     beforeEach(function () {
       sinon.stub(App, 'get').withArgs('currentStackName').returns('HDP');
-      sinon.stub(App.ajax, 'send', Em.K);
       sinon.stub(App.StackVersion, 'find', function() {
         return [
           Em.Object.create({state: 'CURRENT', repositoryVersion: {repositoryVersion: '2.3.0.0-2208'}})
@@ -876,14 +876,13 @@ describe('App.WizardStep8Controller', function () {
     });
 
     afterEach(function () {
-      App.ajax.send.restore();
       App.get.restore();
       App.StackVersion.find.restore();
     });
     it('should use current StackVersion', function() {
       installerStep8Controller.loadRepoInfo();
-      var data = App.ajax.send.args[0][0].data;
-      expect(data).to.eql({stackName: 'HDP', repositoryVersion: '2.3.0.0-2208'});
+      var args = testHelpers.findAjaxRequest('name', 'cluster.load_repo_version');
+      expect(args[0].data).to.eql({stackName: 'HDP', repositoryVersion: '2.3.0.0-2208'});
     });
   });
 
@@ -1172,20 +1171,13 @@ describe('App.WizardStep8Controller', function () {
 
   describe('#deleteClusters', function() {
 
-    beforeEach(function () {
-      sinon.stub(App.ajax, 'send', Em.K);
-    });
-
-    afterEach(function () {
-      App.ajax.send.restore();
-    });
-
     it('should call App.ajax.send for each provided clusterName', function() {
       var clusterNames = ['h1', 'h2', 'h3'];
       installerStep8Controller.deleteClusters(clusterNames);
-      expect(App.ajax.send.callCount).to.equal(clusterNames.length);
+      var args = testHelpers.filterAjaxRequests('name', 'common.delete.cluster');
+      expect(args).to.have.property('length').equal(clusterNames.length);
       clusterNames.forEach(function(n, i) {
-        expect(App.ajax.send.getCall(i).args[0].data).to.eql({name: n, isLast: i === clusterNames.length - 1});
+        expect(args[i][0].data).to.eql({name: n, isLast: i === clusterNames.length - 1});
       });
     });
 
@@ -1249,24 +1241,8 @@ describe('App.WizardStep8Controller', function () {
   });
 
   describe('#addRequestToAjaxQueue', function() {
-    describe('testMode = true', function() {
-      before(function() {
-        App.set('testMode', true);
-      });
-      after(function() {
-        App.set('testMode', false);
-      });
-      it('shouldn\'t do nothing', function() {
-        installerStep8Controller.set('ajaxRequestsQueue', App.ajaxQueue.create());
-        installerStep8Controller.get('ajaxRequestsQueue').clear();
-        installerStep8Controller.addRequestToAjaxQueue({});
-        expect(installerStep8Controller.get('ajaxRequestsQueue.queue.length')).to.equal(0);
-      });
-    });
-    describe('testMode = true', function() {
-      before(function() {
-        App.set('testMode', false);
-      });
+
+    describe('testMode = false', function() {
       it('should add request', function() {
         var clusterName = 'c1';
         installerStep8Controller.reopen({clusterName: clusterName});
@@ -1338,39 +1314,27 @@ describe('App.WizardStep8Controller', function () {
 
   describe('#applyInstalledServicesConfigurationGroup', function() {
     beforeEach(function() {
-      sinon.stub($, 'ajax', function () {
-        return {
-          then: Em.K,
-          retry: function () {
-            return {then: Em.K}
-          }
-        }
-      });
       sinon.stub(App.router, 'get', function() {
         return configurationController;
       });
     });
     afterEach(function() {
-      $.ajax.restore();
       App.router.get.restore();
     });
     it('should do ajax request for each config group', function() {
       var configGroups = [{ConfigGroup: {id:''}}, {ConfigGroup: {id:''}}];
       installerStep8Controller.applyInstalledServicesConfigurationGroup(configGroups);
-      expect($.ajax.callCount).to.equal(configGroups.length);
+      var args = testHelpers.filterAjaxRequests('name', 'config_groups.update_config_group');
+      expect(args).to.have.property('length').equal(configGroups.length);
     });
   });
 
   describe('#getExistingClusterNames', function() {
-    beforeEach(function() {
-      sinon.stub(App.ajax, 'send', Em.K);
-    });
-    afterEach(function() {
-      App.ajax.send.restore();
-    });
+
     it('should do ajax request', function() {
       installerStep8Controller.getExistingClusterNames();
-      expect(App.ajax.send.calledOnce).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'wizard.step8.existing_cluster_names');
+      expect(args).exists;
     });
   });
 
@@ -1892,8 +1856,6 @@ describe('App.WizardStep8Controller', function () {
     describe('#createNotification', function () {
 
       beforeEach(function () {
-        var stub = sinon.stub(App, 'get');
-        stub.withArgs('testMode').returns(false);
         installerStep8Controller.clearStep();
         installerStep8Controller.set('content', {controllerName: 'installerController'});
         installerStep8Controller.set('configs', [
@@ -1910,21 +1872,14 @@ describe('App.WizardStep8Controller', function () {
           {name: 'some_p', value: 'some_v', serviceName: 'MISC', filename: 'alert_notification'}
         ]);
         installerStep8Controller.get('ajaxRequestsQueue').clear();
-        sinon.stub(App.ajax, 'send', function () {
-          return {complete: Em.K}
-        });
-      });
-
-      afterEach(function () {
-        App.get.restore();
-        App.ajax.send.restore();
       });
 
       it('should add request to queue', function () {
         installerStep8Controller.createNotification();
         expect(installerStep8Controller.get('ajaxRequestsQueue.queue.length')).to.equal(1);
         installerStep8Controller.get('ajaxRequestsQueue').runNextRequest();
-        expect(App.ajax.send.calledOnce).to.be.true;
+        var args = testHelpers.findAjaxRequest('name', 'alerts.create_alert_notification');
+        expect(args).exists;
       });
 
       describe('sent data should be valid', function () {
@@ -2443,7 +2398,6 @@ describe('App.WizardStep8Controller', function () {
 
     beforeEach(function () {
       sinon.stub(App.db, 'get').withArgs('KerberosWizard', 'kerberosDescriptorConfigs').returns(1234);
-      sinon.stub(App.ajax, 'send', Em.K);
       sinon.stub(installerStep8Controller, 'addRequestToAjaxQueue', Em.K);
       sinon.stub(installerStep8Controller, 'get').withArgs('wizardController').returns(Em.Object.create({
         getDBProperty: function() { return true; }
@@ -2452,21 +2406,22 @@ describe('App.WizardStep8Controller', function () {
 
     afterEach(function () {
       App.db.get.restore();
-      App.ajax.send.restore();
       installerStep8Controller.addRequestToAjaxQueue.restore();
       installerStep8Controller.get.restore();
     });
 
     it('should send request instantly', function () {
       installerStep8Controller.updateKerberosDescriptor(true);
-      expect(App.ajax.send.calledOnce).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'admin.kerberos.cluster.artifact.update');
+      expect(args[0]).exists;
+      expect(args[0].data).to.be.eql(requestData);
       expect(installerStep8Controller.addRequestToAjaxQueue.called).to.be.false;
-      expect(App.ajax.send.args[0][0].data).to.be.eql(requestData);
     });
 
     it('should add request to the queue', function () {
       installerStep8Controller.updateKerberosDescriptor(false);
-      expect(App.ajax.send.called).to.be.false;
+      var args = testHelpers.findAjaxRequest('name', 'admin.kerberos.cluster.artifact.update');
+      expect(args).not.exists;
       expect(installerStep8Controller.addRequestToAjaxQueue.calledOnce).to.be.true;
       expect(installerStep8Controller.addRequestToAjaxQueue.args[0][0].data).to.be.eql(requestData);
     });

+ 7 - 24
ambari-web/test/controllers/wizard/step9_test.js

@@ -24,6 +24,7 @@ require('controllers/installer');
 require('controllers/wizard/step9_controller');
 require('utils/helper');
 require('utils/ajax/ajax');
+var testHelpers = require('test/helpers');
 
 var modelSetup = require('test/init_model_test');
 var c, obj;
@@ -54,6 +55,7 @@ describe('App.InstallerStep9Controller', function () {
     modelSetup.setupStackServiceComponent();
     c = getController();
     obj = App.InstallerController.create();
+    App.ajax.send.restore();
     sinon.stub(App.ajax, 'send', function() {
       return {
         then: function() { 
@@ -72,7 +74,6 @@ describe('App.InstallerStep9Controller', function () {
 
   afterEach(function () {
     modelSetup.cleanStackServiceComponent();
-    App.ajax.send.restore();
   });
 
   App.TestAliases.testAsComputedEqual(getController(), 'showRetry', 'content.cluster.status', 'INSTALL FAILED');
@@ -1340,17 +1341,6 @@ describe('App.InstallerStep9Controller', function () {
 
   describe('#launchStartServicesErrorCallback', function () {
 
-    beforeEach(function() {
-      sinon.stub(App, 'get', function(k) {
-        if ('testMode' === k) return true;
-        return Em.get(App, k);
-      });
-    });
-
-    afterEach(function() {
-      App.get.restore();
-    });
-
     it('Main progress bar on the screen should be finished (100%) with red color', function () {
       var hosts = Em.A([Em.Object.create({name: 'host1', progress: '33', status: 'info'}), Em.Object.create({name: 'host2', progress: '33', status: 'info'})]);
       c.reopen({hosts: hosts, content: {controllerName: 'installerController', cluster: {status: 'PENDING', name: 'c1'}}});
@@ -1492,7 +1482,8 @@ describe('App.InstallerStep9Controller', function () {
     it('shouldn\'t call App.ajax.send if no currentOpenTaskId', function () {
       c.set('currentOpenTaskId', null);
       c.loadCurrentTaskLog();
-      expect(App.ajax.send.called).to.equal(false);
+      var args = testHelpers.findAjaxRequest('name', 'background_operations.get_by_task');
+      expect(args).not.exists;
     });
 
     it('should call App.ajax.send with provided data', function () {
@@ -1500,7 +1491,9 @@ describe('App.InstallerStep9Controller', function () {
       c.set('currentOpenTaskRequestId', 2);
       c.set('content', {cluster: {name: 3}});
       c.loadCurrentTaskLog();
-      expect(App.ajax.send.args[0][0].data).to.eql({taskId: 1, requestId: 2, clusterName: 3});
+      var args = testHelpers.findAjaxRequest('name', 'background_operations.get_by_task');
+      expect(args[0]).exists;
+      expect(args[0].data).to.be.eql({taskId: 1, requestId: 2, clusterName: 3});
     });
   });
 
@@ -1597,14 +1590,6 @@ describe('App.InstallerStep9Controller', function () {
       c.togglePreviousSteps.restore();
     });
 
-    it('should increment numPolls if testMode', function () {
-      App.set('testMode', true);
-      c.set('numPolls', 0);
-      c.doPolling();
-      expect(c.get('numPolls')).to.equal(1);
-      App.set('testMode', false);
-    });
-
     it('should call getLogsByRequest', function () {
       c.set('content', {cluster: {requestId: 1}});
       c.doPolling();
@@ -1635,7 +1620,6 @@ describe('App.InstallerStep9Controller', function () {
       sinon.stub(c, 'loadStep', Em.K);
       sinon.stub(c, 'loadLogData', Em.K);
       sinon.stub(c, 'startPolling', Em.K);
-      sinon.stub(App, 'get', function(k) {if('testMode' === k) return false; return Em.get(App, k);});
     });
 
     afterEach(function () {
@@ -1643,7 +1627,6 @@ describe('App.InstallerStep9Controller', function () {
       c.loadStep.restore();
       c.loadLogData.restore();
       c.startPolling.restore();
-      App.get.restore();
     });
 
     it('isCompleted = true, requestId = 1', function () {

+ 1 - 7
ambari-web/test/controllers/wizard_test.js

@@ -612,11 +612,9 @@ describe('App.WizardController', function () {
       sinon.stub(wizardController,'showLaunchBootstrapPopup').returns({
         name: 'popup'
       });
-      sinon.stub(App.ajax,'send', Em.K);
     });
     afterEach(function(){
       wizardController.showLaunchBootstrapPopup.restore();
-      App.ajax.send.restore();
     });
     it('should return popup', function () {
       expect(wizardController.launchBootstrap()).to.be.eql({
@@ -680,13 +678,9 @@ describe('App.WizardController', function () {
       sinon.stub(wizardController,'saveClusterStatus', function(data){
         res = JSON.parse(JSON.stringify(data));
       });
-      sinon.stub(App.ajax,'send').returns({
-        then: function() {}
-      });
     });
     afterEach(function(){
       wizardController.saveClusterStatus.restore();
-      App.ajax.send.restore();
     });
     it('should call callbeck with data', function () {
       wizardController.set('content', Em.Object.create({
@@ -1491,7 +1485,7 @@ describe('App.WizardController', function () {
   describe('#loadConfigThemes', function() {
     beforeEach(function () {
       sinon.stub(wizardController, 'loadConfigThemeForServices').returns({
-        always: function(callback) {callback();}
+        always: Em.clb
       });
       sinon.stub(App.themesMapper, 'generateAdvancedTabs').returns(true);
       sinon.stub(App.config, 'loadConfigsFromStack').returns({

+ 77 - 0
ambari-web/test/helpers.js

@@ -47,6 +47,83 @@ module.exports = {
         }
       });
     });
+  },
+
+  /**
+   * Get arguments for one <code>App.ajax.send</code> call according to the criteria
+   * Example:
+   * <pre>
+   *  sinon.stub(App.ajax, 'send', Em.K);
+   *  App.ajax.send({
+   *    name: 'n1',
+   *    sender: {},
+   *    data: {
+   *      f1: 'v1',
+   *      f2: 'v2'
+   *    }
+   *  });
+   *  App.ajax.send({
+   *    name: 'n2',
+   *    sender: {}
+   *  });
+   *  var args = findAjaxRequest('name', 'n1');
+   *  console.log(args); // [{name: 'n1', sender: {}, data: {f1: 'v1', f2: 'v2'}}]
+   *  App.ajax.send.restore();
+   * </pre>
+   *
+   * @param {string} property field to find
+   * @param {*} value value to find
+   * @returns {array|null}
+   */
+  findAjaxRequest: function(property, value) {
+    if (Em.typeOf(App.ajax.send.args) !== 'array') {
+      return null;
+    }
+    return App.ajax.send.args.find(function (request) {
+      return Em.get(request[0], property) === value;
+    });
+  },
+
+  /**
+   * Get arguments for several <code>App.ajax.send</code> calls according to the criteria
+   * Example:
+   * <pre>
+   *  sinon.stub(App.ajax, 'send', Em.K);
+   *  App.ajax.send({
+   *    name: 'n1',
+   *    sender: {},
+   *    data: {
+   *      f1: 'v1',
+   *      f2: 'v2'
+   *    }
+   *  });
+   *  App.ajax.send({
+   *    name: 'n2',
+   *    sender: {}
+   *  });
+   *  App.ajax.send({
+   *    name: 'n2',
+   *    sender: {},
+   *    data: {
+   *      d1: 1234
+   *    }
+   *  });
+   *  var args = filterAjaxRequests('name', 'n2');
+   *  console.log(args); // [[{name: 'n1', sender: {}}], [{name: 'n2', sender: {}, data: {d1: 1234}}]]
+   *  App.ajax.send.restore();
+   * </pre>
+   *
+   * @param {string} property field to filter
+   * @param {*} value value to filter
+   * @returns {array}
+   */
+  filterAjaxRequests: function (property, value) {
+    if (Em.typeOf(App.ajax.send.args) !== 'array') {
+      return [];
+    }
+    return App.ajax.send.args.filter(function (request) {
+      return Em.get(request[0], property) === value;
+    });
   }
 
 };

+ 1 - 0
ambari-web/test/mixins/common/table_server_view_mixin_test.js

@@ -18,6 +18,7 @@
 
 var App = require('app');
 require('mixins/common/table_server_view_mixin');
+require('utils/load_timer');
 
 describe('App.MainConfigHistoryView', function() {
   var view = Em.View.create(App.TableServerViewMixin, {

+ 39 - 52
ambari-web/test/mixins/common/widget_mixin_test.js

@@ -17,12 +17,22 @@
  */
 
 var App = require('app');
+var testHelpers = require('test/helpers');
 
 describe('App.WidgetMixin', function () {
   var mixinClass = Em.Object.extend(App.WidgetMixin, {metrics: [], content: {}});
+  var mixinObject;
+
+  beforeEach(function () {
+    mixinObject = mixinClass.create();
+  });
+
+  afterEach(function () {
+    clearTimeout(mixinObject.get('timeoutId'));
+    mixinObject.destroy();
+  });
 
   describe('#loadMetrics()', function () {
-    var mixinObject = mixinClass.create();
     beforeEach(function () {
       this.mock = sinon.stub(mixinObject, 'getRequestData');
       sinon.stub(App.WidgetLoadAggregator, 'add');
@@ -48,7 +58,6 @@ describe('App.WidgetMixin', function () {
   });
 
   describe("#extractExpressions()", function () {
-    var mixinObject = mixinClass.create();
     var testCases = [
       {
         data: '',
@@ -179,13 +188,7 @@ describe('App.WidgetMixin', function () {
   });
 
   describe("#getServiceComponentMetrics()", function () {
-    var mixinObject = mixinClass.create();
-    before(function () {
-      sinon.stub(App.ajax, 'send');
-    });
-    after(function () {
-      App.ajax.send.restore();
-    });
+
     it("valid request is sent", function () {
       var request = {
         service_name: 'S1',
@@ -206,20 +209,18 @@ describe('App.WidgetMixin', function () {
         ]
       };
       mixinObject.getServiceComponentMetrics(request);
-      expect(App.ajax.send.getCall(0).args[0]).to.eql({
-        name: 'widgets.serviceComponent.metrics.get',
-        sender: mixinObject,
-        data: {
-          serviceName: 'S1',
-          componentName: 'C1',
-          metricPaths: 'w1,w2'
-        }
-      })
+      var args = testHelpers.findAjaxRequest('name', 'widgets.serviceComponent.metrics.get');
+      expect(args[0]).exists;
+      expect(args[0].sender).to.be.eql(mixinObject);
+      expect(args[0].data).to.be.eql({
+        serviceName: 'S1',
+        componentName: 'C1',
+        metricPaths: 'w1,w2'
+      });
     });
   });
 
   describe("#getMetricsSuccessCallback()", function () {
-    var mixinObject = mixinClass.create();
     it("metric is mapped from provided path", function () {
       var data = {
         metrics: {
@@ -243,13 +244,10 @@ describe('App.WidgetMixin', function () {
   });
 
   describe("#getHostComponentMetrics()", function () {
-    var mixinObject = mixinClass.create();
-    before(function () {
-      sinon.stub(App.ajax, 'send');
+    beforeEach(function () {
       sinon.stub(mixinObject, 'computeHostComponentCriteria').returns('criteria')
     });
-    after(function () {
-      App.ajax.send.restore();
+    afterEach(function () {
       mixinObject.computeHostComponentCriteria.restore();
     });
     it("valid request is sent", function () {
@@ -272,20 +270,18 @@ describe('App.WidgetMixin', function () {
         host_component_criteria: 'c1'
       };
       mixinObject.getHostComponentMetrics(request);
-      expect(App.ajax.send.getCall(0).args[0]).to.eql({
-        name: 'widgets.hostComponent.metrics.get',
-        sender: mixinObject,
-        data: {
-          componentName: 'C1',
-          metricPaths: 'w1,w2',
-          hostComponentCriteria: 'criteria'
-        }
-      })
+      var args = testHelpers.findAjaxRequest('name', 'widgets.hostComponent.metrics.get');
+      expect(args[0]).exists;
+      expect(args[0].sender).to.be.eql(mixinObject);
+      expect(args[0].data).to.be.eql({
+        componentName: 'C1',
+        metricPaths: 'w1,w2',
+        hostComponentCriteria: 'criteria'
+      });
     });
   });
 
   describe("#calculateValues()", function () {
-    var mixinObject = mixinClass.create();
 
     beforeEach(function () {
       sinon.stub(mixinObject, 'extractExpressions');
@@ -322,8 +318,6 @@ describe('App.WidgetMixin', function () {
   });
 
   describe("#computeExpression()", function () {
-    var mixinObject = mixinClass.create();
-
     it("expression missing metrics", function () {
       var expressions = ['e.m1'];
       var metrics = [];
@@ -354,14 +348,13 @@ describe('App.WidgetMixin', function () {
   });
 
   describe("#cloneWidget()", function () {
-    var mixinObject = mixinClass.create();
     var popup;
-    before(function () {
+    beforeEach(function () {
       sinon.spy(App, 'showConfirmationPopup');
       sinon.stub(mixinObject, 'postWidgetDefinition', Em.K);
       popup = mixinObject.cloneWidget();
     });
-    after(function () {
+    afterEach(function () {
       App.showConfirmationPopup.restore();
       mixinObject.postWidgetDefinition.restore();
     });
@@ -375,25 +368,19 @@ describe('App.WidgetMixin', function () {
   });
 
   describe("#postWidgetDefinition()", function () {
-    var mixinObject = mixinClass.create();
-
-    before(function () {
-      sinon.spy(App.ajax, 'send');
+    beforeEach(function () {
       sinon.stub(mixinObject, 'collectWidgetData').returns({});
     });
-    after(function () {
-      App.ajax.send.restore();
+    afterEach(function () {
       mixinObject.collectWidgetData.restore();
     });
     it("valid request is sent", function () {
       mixinObject.postWidgetDefinition();
-      expect(App.ajax.send.getCall(0).args[0]).to.eql({
-        name: 'widgets.wizard.add',
-        sender: mixinObject,
-        data: {
-          data: {}
-        },
-        success: 'postWidgetDefinitionSuccessCallback'
+      var args = testHelpers.findAjaxRequest('name', 'widgets.wizard.add');
+      expect(args[0]).exists;
+      expect(args[0].sender).to.be.eql(mixinObject);
+      expect(args[0].data).to.be.eql({
+        data: {}
       });
     });
   });

+ 4 - 11
ambari-web/test/mixins/common/widgets/export_metrics_mixin_test.js

@@ -20,6 +20,7 @@ var App = require('app');
 
 require('mixins/common/widgets/export_metrics_mixin');
 var fileUtils = require('utils/file_utils');
+var testHelpers = require('test/helpers');
 
 describe('App.ExportMetricsMixin', function () {
 
@@ -72,7 +73,6 @@ describe('App.ExportMetricsMixin', function () {
     ];
 
     beforeEach(function () {
-      sinon.stub(App.ajax, 'send', Em.K);
       obj.reopen({
         targetView: {
           ajaxIndex: 'index',
@@ -85,30 +85,23 @@ describe('App.ExportMetricsMixin', function () {
       });
     });
 
-    afterEach(function () {
-      App.ajax.send.restore();
-    });
-
     cases.forEach(function (item) {
       describe(item.title, function () {
 
         beforeEach(function () {
           obj.set('isExportMenuHidden', item.isExportMenuHidden);
           obj.exportGraphData(item.event);
-          this.ajaxParams = App.ajax.send.firstCall.args[0];
+          this.ajaxParams = testHelpers.findAjaxRequest('name', 'index');
         });
 
         it('isExportMenuHidden is true', function () {
           expect(obj.get('isExportMenuHidden')).to.be.true;
         });
         it('one request was done', function () {
-          expect(App.ajax.send.calledOnce).to.be.true;
-        });
-        it('request to the valid end-point', function () {
-          expect(this.ajaxParams.name).to.equal('index');
+          expect(this.ajaxParams[0]).exists;
         });
         it('ajax-request with correct data', function () {
-          expect(this.ajaxParams.data).to.eql({
+          expect(this.ajaxParams[0].data).to.eql({
             p: 'v',
             isCSV: item.isCSV
           });

+ 8 - 17
ambari-web/test/mixins/main/host/details/host_components/decommissionable_test.js

@@ -18,6 +18,7 @@
 
 var App = require('app');
 var uiEffects = require('utils/ui_effects');
+var testHelpers = require('test/helpers');
 
 require('mixins/main/host/details/host_components/decommissionable');
 
@@ -259,13 +260,6 @@ describe('App.Decommissionable', function () {
 
   describe("#getDecommissionStatus()", function() {
 
-    beforeEach(function() {
-      sinon.stub(App.ajax, 'send');
-    });
-    afterEach(function() {
-      App.ajax.send.restore();
-    });
-
     it("App.ajax.send should be called", function() {
       decommissionable.setProperties({
         componentForCheckDecommission: 'C1',
@@ -277,16 +271,13 @@ describe('App.Decommissionable', function () {
         })
       });
       decommissionable.getDecommissionStatus();
-      expect(App.ajax.send.getCall(0).args[0]).to.eql({
-        name: 'host.host_component.decommission_status',
-        sender: decommissionable,
-        data: {
-          hostName: 'host1',
-          componentName: 'C1',
-          serviceName: 'S1'
-        },
-        success: 'getDecommissionStatusSuccessCallback',
-        error: 'getDecommissionStatusErrorCallback'
+      var args = testHelpers.findAjaxRequest('name', 'host.host_component.decommission_status');
+      expect(args[0]).exists;
+      expect(args[0].sender).to.be.eql(decommissionable);
+      expect(args[0].data).to.be.eql({
+        hostName: 'host1',
+        componentName: 'C1',
+        serviceName: 'S1'
       });
     });
   });

+ 40 - 57
ambari-web/test/mixins/main/host/details/host_components/install_component_test.js

@@ -18,7 +18,7 @@
 
 var App = require('app');
 require('mixins/main/host/details/host_components/install_component');
-
+var testHelpers = require('test/helpers');
 var installComponent;
 
 describe('App.InstallComponent', function () {
@@ -35,12 +35,11 @@ describe('App.InstallComponent', function () {
 
     beforeEach(function() {
       sinon.stub(installComponent, 'updateAndCreateServiceComponent').returns({done: Em.clb});
-      sinon.stub(App.ajax, 'send');
       installComponent.installHostComponentCall('host1', component);
+      this.args = testHelpers.findAjaxRequest('name', 'host.host_component.add_new_component');
     });
     afterEach(function() {
       installComponent.updateAndCreateServiceComponent.restore();
-      App.ajax.send.restore();
     });
 
     it("updateAndCreateServiceComponent should be called", function() {
@@ -48,29 +47,25 @@ describe('App.InstallComponent', function () {
     });
 
     it("App.ajax.send should be called", function() {
-      expect(App.ajax.send.getCall(0).args[0]).to.eql({
-        name: 'host.host_component.add_new_component',
-        sender: installComponent,
-        data: {
-          hostName: 'host1',
-          component: component,
-          data: JSON.stringify({
-            RequestInfo: {
-              "context": Em.I18n.t('requestInfo.installHostComponent') + ' c1'
-            },
-            Body: {
-              host_components: [
-                {
-                  HostRoles: {
-                    component_name: 'C1'
-                  }
+      expect(this.args[0]).exists;
+      expect(this.args[0].sender).to.be.eql(installComponent);
+      expect(this.args[0].data).to.be.eql({
+        hostName: 'host1',
+        component: component,
+        data: JSON.stringify({
+          RequestInfo: {
+            "context": Em.I18n.t('requestInfo.installHostComponent') + ' c1'
+          },
+          Body: {
+            host_components: [
+              {
+                HostRoles: {
+                  component_name: 'C1'
                 }
-              ]
-            }
-          })
-        },
-        success: 'addNewComponentSuccessCallback',
-        error: 'ajaxErrorCallback'
+              }
+            ]
+          }
+        })
       });
     });
   });
@@ -85,32 +80,20 @@ describe('App.InstallComponent', function () {
       })
     };
 
-    beforeEach(function() {
-      sinon.stub(App.ajax, 'send');
-    });
-    afterEach(function() {
-      App.ajax.send.restore();
-    });
-
-
     it("App.ajax.send should be called", function() {
       installComponent.addNewComponentSuccessCallback({}, {}, params);
-      expect(App.ajax.send.getCall(0).args[0]).to.eql({
-        name: 'common.host.host_component.update',
-        sender: App.router.get('mainHostDetailsController'),
-        data: {
-          hostName: 'host1',
-          componentName: 'C1',
-          serviceName: 'S1',
-          component: params.component,
-          "context": Em.I18n.t('requestInfo.installNewHostComponent') + ' c1',
-          HostRoles: {
-            state: 'INSTALLED'
-          },
-          urlParams: "HostRoles/state=INIT"
+      var args = testHelpers.findAjaxRequest('name', 'common.host.host_component.update');
+      expect(args[0]).exists;
+      expect(args[0].data).to.be.eql({
+        hostName: 'host1',
+        componentName: 'C1',
+        serviceName: 'S1',
+        component: params.component,
+        "context": Em.I18n.t('requestInfo.installNewHostComponent') + ' c1',
+        HostRoles: {
+          state: 'INSTALLED'
         },
-        success: 'installNewComponentSuccessCallback',
-        error: 'ajaxErrorCallback'
+        urlParams: "HostRoles/state=INIT"
       });
     });
   });
@@ -118,7 +101,7 @@ describe('App.InstallComponent', function () {
   describe("#ajaxErrorCallback()", function() {
 
     beforeEach(function() {
-      sinon.stub(App.ajax, 'defaultErrorHandler');
+      sinon.stub(App.ajax, 'defaultErrorHandler', Em.K);
     });
     afterEach(function() {
       App.ajax.defaultErrorHandler.restore();
@@ -173,6 +156,8 @@ describe('App.InstallComponent', function () {
         serviceName: 'S1'
       })]);
       sinon.spy(dfd, 'resolve');
+
+      App.ajax.send.restore();
       sinon.stub(App.ajax, 'send').returns({complete: Em.clb});
       this.mock = sinon.stub(App.Service, 'find');
       this.mock.returns([{serviceName: "S1"}]);
@@ -183,7 +168,6 @@ describe('App.InstallComponent', function () {
       App.StackServiceComponent.find.restore();
       dfd.resolve.restore();
       this.mock.restore();
-      App.ajax.send.restore();
     });
 
     it("component already created", function() {
@@ -193,13 +177,12 @@ describe('App.InstallComponent', function () {
 
     it("component not created", function() {
       installComponent.createServiceComponent('C2', dfd);
-      expect(App.ajax.send.getCall(0).args[0]).to.eql({
-        name: 'common.create_component',
-        sender: installComponent,
-        data: {
-          componentName: 'C2',
-          serviceName: 'S1'
-        }
+      var args = testHelpers.findAjaxRequest('name', 'common.create_component');
+      expect(args[0]).exists;
+      expect(args[0].sender).to.be.eql(installComponent);
+      expect(args[0].data).to.be.eql({
+        componentName: 'C2',
+        serviceName: 'S1'
       });
       expect(dfd.resolve.calledOnce).to.be.true;
     });

+ 6 - 18
ambari-web/test/mixins/wizard/wizardProgressPageController_test.js

@@ -17,6 +17,7 @@
  */
 
 var App = require('app');
+var testHelpers = require('test/helpers');
 
 describe('App.wizardProgressPageControllerMixin', function() {
   var mixedObject = Em.Object.extend(App.wizardProgressPageControllerMixin, {});
@@ -25,15 +26,8 @@ describe('App.wizardProgressPageControllerMixin', function() {
     var mixedObjectInstance;
     beforeEach(function() {
       mixedObjectInstance = mixedObject.create({});
-      sinon.stub(App.ajax, 'send', function(params) {
-        return $.extend(params,{complete: function(callback){
-          callback();
-        }});
-      });
       sinon.stub(mixedObjectInstance, "updateAndCreateServiceComponent").returns({
-        done: function(callback) {
-          return callback();
-        }
+        done: Em.clb
       });
       sinon.spy(mixedObjectInstance, 'onCreateComponent');
       sinon.spy(mixedObjectInstance, 'updateComponent');
@@ -68,7 +62,6 @@ describe('App.wizardProgressPageControllerMixin', function() {
     });
     
     afterEach(function() {
-      App.ajax.send.restore();
       App.StackServiceComponent.find.restore();
       mixedObjectInstance.updateAndCreateServiceComponent.restore();
       mixedObjectInstance.onCreateComponent.restore();
@@ -89,7 +82,7 @@ describe('App.wizardProgressPageControllerMixin', function() {
     describe('no ZooKeeper Servers installed. install on host1, host2. ajax request should be called with appropriate params', function() {
       beforeEach(function () {
         mixedObjectInstance.createComponent('ZOOKEEPER_SERVER', ['host1', 'host2'], 'ZOOKEEPER');
-        this.args = App.ajax.send.args[0][0];
+        this.args = testHelpers.findAjaxRequest('name', 'wizard.step8.register_host_to_component')[0];
         this.queryObject = JSON.parse(this.args.data.data);
       });
       it('hostName is valid array', function () {
@@ -114,7 +107,7 @@ describe('App.wizardProgressPageControllerMixin', function() {
     describe('ZooKeeper Client installed on host1. install on host1, host2. ajax request should be called with appropriate params', function() {
       beforeEach(function () {
         mixedObjectInstance.createComponent('ZOOKEEPER_CLIENT', ['host1', 'host2'], 'ZOOKEEPER');
-        this.args = App.ajax.send.args[0][0];
+        this.args = testHelpers.findAjaxRequest('name', 'wizard.step8.register_host_to_component')[0];
         this.queryObject = JSON.parse(this.args.data.data);
       });
       it('hostName is valid array', function () {
@@ -160,19 +153,14 @@ describe('App.wizardProgressPageControllerMixin', function() {
     
     testsAjax.forEach(function(test) {
       describe('called with params: ' + JSON.stringify(test.callParams), function() {
-        before(function() {
-          sinon.stub(App.ajax, 'send', Em.K);
+        beforeEach(function() {
           var mixedObjectInstance = mixedObject.create({});
           mixedObjectInstance.updateComponent.apply(mixedObjectInstance, test.callParams);
         });
 
-        after(function() {
-          App.ajax.send.restore();
-        });
-        
         test.e.forEach(function(eKey) {
           it('key: {0} should have value: {1}'.format(eKey.key, eKey.value), function() {
-            var args = App.ajax.send.args[0][0];
+            var args = testHelpers.findAjaxRequest('name', 'common.host_components.update')[0];
             expect(args).to.have.deep.property(eKey.key, eKey.value);
           });
         });

+ 0 - 2
ambari-web/test/models/cluster_states_test.js

@@ -72,7 +72,6 @@ describe('App.clusterStatus', function () {
   describe('#setClusterStatus', function () {
 
     beforeEach(function() {
-      sinon.stub(App, 'get').withArgs('testMode').returns(false);
       sinon.stub(status, 'postUserPref', function() {
         return $.ajax();
       });
@@ -80,7 +79,6 @@ describe('App.clusterStatus', function () {
 
     afterEach(function () {
       status.postUserPref.restore();
-      App.get.restore();
     });
 
     it('should set cluster status in non-test mode', function () {

+ 0 - 4
ambari-web/test/models/host_test.js

@@ -53,10 +53,6 @@ describe('App.Host', function () {
     }
   ];
 
-  before(function() {
-    App.set('testMode', false);
-  });
-
   App.Host.reopen({
     hostComponents: []
   });

+ 5 - 35
ambari-web/test/router_test.js

@@ -17,34 +17,13 @@
  */
 
 var App = require('app');
+var testHelpers = require('test/helpers');
 
 require('router');
 
 describe('App.Router', function () {
   var router = App.Router.create();
 
-  describe.skip('#loginSuccessCallback()', function() {
-
-    beforeEach(function () {
-      sinon.stub(App.usersMapper, 'map');
-      sinon.stub(router, 'setUserLoggedIn');
-      sinon.stub(App.ajax, 'send');
-    });
-
-    afterEach(function() {
-      App.usersMapper.map.restore();
-      router.setUserLoggedIn.restore();
-      App.ajax.send.restore();
-    });
-
-    it('should log in user and load views', function () {
-      var userName = 'test';
-      router.loginSuccessCallback({},{},{loginName: userName});
-      expect(router.setUserLoggedIn.calledOnce).to.be.true;
-      expect(router.setUserLoggedIn.calledWith(userName)).to.be.true;
-    })
-  });
-
   describe('#initAdmin()', function () {
 
     var cases = [
@@ -373,20 +352,11 @@ describe('App.Router', function () {
   });
 
   describe("#transitionToAdminView()", function () {
-    beforeEach(function () {
-      sinon.stub(App.ajax, 'send');
-    });
-    afterEach(function () {
-      App.ajax.send.restore();
-    });
+
     it("valid request is sent", function () {
       router.transitionToAdminView();
-      expect(App.ajax.send.calledWith({
-        name: 'ambari.service.load_server_version',
-        sender: router,
-        success: 'adminViewInfoSuccessCallback',
-        error: 'adminViewInfoErrorCallback'
-      })).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'ambari.service.load_server_version');
+      expect(args[0]).to.exists;
     });
   });
 
@@ -457,7 +427,6 @@ describe('App.Router', function () {
     });
 
     afterEach(function () {
-      App.ajax.send.restore();
       router.getCurrentLocationUrl.restore();
       router.redirectByURL.restore();
       this.mockGetCurrentLocationUrl.restore();
@@ -500,6 +469,7 @@ describe('App.Router', function () {
         beforeEach(function () {
           mockCurrentUrl = 'http://localhost:3333/#/some/hash';
           router.set('location.lastSetURL', test.lastSetURL);
+          App.ajax.send.restore(); // default ajax-mock can't be used here
           sinon.stub(App.ajax, 'send', function() {
             if (!test.isResolved) {
               router.onAuthenticationError(test.responseData);

+ 0 - 8
ambari-web/test/utils/ajax/ajax_queue_test.js

@@ -26,14 +26,12 @@ describe('App.ajaxQueue', function () {
     ajaxQueue = App.ajaxQueue.create();
     sinon.spy(ajaxQueue, 'runNextRequest');
     sinon.spy(ajaxQueue, 'finishedCallback');
-    sinon.spy(App.ajax, 'send');
   });
 
   afterEach(function() {
     ajaxQueue.clear();
     ajaxQueue.runNextRequest.restore();
     ajaxQueue.finishedCallback.restore();
-    App.ajax.send.restore();
   });
 
   describe('#clear', function() {
@@ -100,12 +98,6 @@ describe('App.ajaxQueue', function () {
       ajaxQueue.runNextRequest();
       expect(ajaxQueue.finishedCallback.called).to.equal(true);
     });
-    it('if abortOnError is false queue shouldn\'t be interrupted', function() {
-      ajaxQueue.clear();
-      ajaxQueue.set('abortOnError', false);
-      ajaxQueue.addRequest({name:'some_fake', sender: Em.Object.create()}).addRequest({name: 'some_fake2', sender: Em.Object.create()}).start();
-      expect(ajaxQueue.runNextRequest.callCount).to.equal(3); // One for empty-queue
-    });
   });
 
 });

+ 2 - 15
ambari-web/test/utils/ajax/ajax_test.js

@@ -22,18 +22,13 @@ require('utils/ajax/ajax');
 describe('App.ajax', function() {
 
   beforeEach(function() {
+    App.ajax.send.restore();
+    sinon.spy(App.ajax, 'send'); // no sense to test stubbed function, so going to spy on it
     App.set('apiPrefix', '/api/v1');
     App.set('clusterName', 'tdk');
   });
 
   describe('#send', function() {
-    beforeEach(function() {
-      sinon.spy($, 'ajax');
-    });
-
-    afterEach(function() {
-      $.ajax.restore();
-    });
     it('Without sender', function() {
       expect(App.ajax.send({})).to.equal(null);
       expect($.ajax.called).to.equal(false);
@@ -110,14 +105,6 @@ describe('App.ajax', function() {
 
   describe('#formatRequest', function() {
 
-    beforeEach(function () {
-      sinon.stub(App, 'get').withArgs('testMode').returns(false);
-    });
-
-    afterEach(function () {
-      App.get.restore();
-    });
-
     var tests = [
       {
         urlObj: {

+ 0 - 71
ambari-web/test/utils/batch_scheduled_requests_test.js

@@ -131,75 +131,4 @@ describe('batch_scheduled_requests', function() {
 
   });
 
-  describe('#restartHostComponents', function() {
-
-    beforeEach(function() {
-      sinon.spy($, 'ajax');
-      sinon.stub(App, 'get', function(k) {
-        if ('testMode' === k) return true;
-        return Em.get(App, k);
-      });
-    });
-
-    afterEach(function() {
-      $.ajax.restore();
-      App.get.restore();
-    });
-
-    var tests = Em.A([
-      {
-        hostComponentList: Em.A([
-          Em.Object.create({
-            componentName: 'NAMENODE',
-            hostName: 'h1'
-          }),
-          Em.Object.create({
-            componentName: 'NAMENODE',
-            hostName: 'h2'
-          })
-        ]),
-        e: {
-          ajaxCalledOnce: true,
-          resource_filters: [{"service_name": "HDFS", "component_name":"NAMENODE","hosts":"h1,h2"}]
-        },
-        m: '1 component on 2 hosts'
-      },
-      {
-        hostComponentList: Em.A([
-          Em.Object.create({
-            componentName: 'NAMENODE',
-            hostName: 'h1'
-          }),
-          Em.Object.create({
-            componentName: 'NAMENODE',
-            hostName: 'h2'
-          }),
-          Em.Object.create({
-            componentName: 'HBASE_MASTER',
-            hostName: 'h2'
-          })
-        ]),
-        e: {
-          ajaxCalledOnce: true,
-          resource_filters: [{"service_name": "HDFS", "component_name":"NAMENODE","hosts":"h1,h2"},{"service_name": "HBASE", "component_name":"HBASE_MASTER","hosts":"h2"}]
-        },
-        m: '1 component on 2 hosts, 1 on 1 host'
-      }
-    ]);
-
-    tests.forEach(function(test) {
-      it(test.m, function() {
-        batchUtils.restartHostComponents(test.hostComponentList);
-        expect($.ajax.calledOnce).to.equal(test.e.ajaxCalledOnce);
-        expect( JSON.parse($.ajax.args[0][0].data)['Requests/resource_filters']).to.eql(test.e.resource_filters);
-      });
-    });
-
-    it('Empty data', function() {
-      batchUtils.restartHostComponents([]);
-      expect($.ajax.called).to.equal(false);
-    });
-
-  });
-
 });

+ 0 - 2
ambari-web/test/utils/host_progress_popup_test.js

@@ -302,11 +302,9 @@ describe('App.HostPopup', function () {
 
   describe('#abortRequest', function () {
     beforeEach(function () {
-      sinon.stub(App.ajax, 'send', Em.K);
       sinon.spy(App, 'showConfirmationPopup');
     });
     afterEach(function () {
-      App.ajax.send.restore();
       App.showConfirmationPopup.restore();
     });
     it('should show confirmation popup', function () {

+ 76 - 73
ambari-web/test/utils/updater_test.js

@@ -18,84 +18,87 @@
 
 var App = require('app');
 require('utils/updater');
-describe('utils/updater', function() {
-  describe('#App.updater', function() {
-    beforeEach(function() {
-      this.clock = sinon.useFakeTimers();
-      sinon.stub(App.router, "get").returns('test');
-    });
+describe('utils/updater', function () {
+  beforeEach(function () {
+    this.clock = sinon.useFakeTimers();
+    sinon.stub(App.router, "get").returns('test');
+    App.updater.run.restore();
+    sinon.spy(App.updater, 'run');
+    App.updater.immediateRun.restore();
+    sinon.spy(App.updater, 'immediateRun');
+  });
 
-    var tests = {
-      t1: {
-        obj: Em.Object.create({
-          method: sinon.spy(),
-          isWorking: true
-        }),
-        m: 'method called once with default interval in 15 000 ms'
-      },
-      t2: {
-        obj: Em.Object.create({
-          method: function() {}
-        }),
-        m: 'should return false if key name is invalid or absent'
-      },
-      t3: {
-        obj: Em.Object.create({
-          method2: sinon.spy(),
-          isWorking: true
-        }),
-        m: 'method should be called immediately'
-      },
-      t4: {
-        obj: Em.Object.create({
-          method3: sinon.spy(),
-          isWorking: true
-        }),
-        m: 'method call should be ignored if `isWorking` set to false'
-      },
-      t5: {
-        obj: Em.Object.create({
-          method4: sinon.spy(),
-          isWorking: true
-        }),
-        m: 'method call should be ignored if urlPattern is not matching router location'
-      }
-    };
+  var tests = {
+    t1: {
+      obj: Em.Object.create({
+        method: sinon.spy(),
+        isWorking: true
+      }),
+      m: 'method called once with default interval in 15 000 ms'
+    },
+    t2: {
+      obj: Em.Object.create({
+        method: function () {
+        }
+      }),
+      m: 'should return false if key name is invalid or absent'
+    },
+    t3: {
+      obj: Em.Object.create({
+        method2: sinon.spy(),
+        isWorking: true
+      }),
+      m: 'method should be called immediately'
+    },
+    t4: {
+      obj: Em.Object.create({
+        method3: sinon.spy(),
+        isWorking: true
+      }),
+      m: 'method call should be ignored if `isWorking` set to false'
+    },
+    t5: {
+      obj: Em.Object.create({
+        method4: sinon.spy(),
+        isWorking: true
+      }),
+      m: 'method call should be ignored if urlPattern is not matching router location'
+    }
+  };
 
-    it(tests.t1.m, function() {
-      App.updater.run(tests.t1.obj, 'method', 'isWorking');
-      this.clock.tick(15000);
-      expect(tests.t1.obj.method.called).to.be.ok;
-    });
+  it(tests.t1.m, function () {
+    App.updater.run(tests.t1.obj, 'method', 'isWorking');
+    this.clock.tick(3600000 * 1.5);
+    expect(tests.t1.obj.method.called).to.be.ok;
+  });
 
-    it(tests.t2.m, function() {
-      var methodCall = App.updater.run(tests.t2.obj, 'method', 'isWorking');
-      expect(methodCall).to.be.false;
-    });
+  it(tests.t2.m, function () {
+    var methodCall = App.updater.run(tests.t2.obj, 'method', 'isWorking');
+    expect(methodCall).to.be.false;
+  });
 
-    it(tests.t3.m, function() {
-      App.updater.run(tests.t3.obj, 'method2', 'isWorking');
-      App.updater.immediateRun('method2');
-      expect(tests.t3.obj.method2.called).to.be.ok;
-    });
+  it(tests.t3.m, function () {
+    App.updater.run(tests.t3.obj, 'method2', 'isWorking');
+    App.updater.immediateRun('method2');
+    expect(tests.t3.obj.method2.called).to.be.ok;
+  });
 
-    it(tests.t4.m, function() {
-      App.updater.run(tests.t4.obj, 'method3', 'isWorking');
-      this.clock.tick(10000);
-      tests.t4.obj.set('isWorking', false);
-      this.clock.tick(5000);
-      expect(tests.t4.obj.method3.called).to.be.false;
-    });
+  it(tests.t4.m, function () {
+    App.updater.run(tests.t4.obj, 'method3', 'isWorking');
+    this.clock.tick(10000);
+    tests.t4.obj.set('isWorking', false);
+    this.clock.tick(5000);
+    expect(tests.t4.obj.method3.called).to.be.false;
+  });
 
-    it(tests.t5.m, function () {
-      App.updater.run(tests.t5.obj, 'method4', 'isWorking', 15000, 'pattern');
-      this.clock.tick(15000);
-      expect(tests.t5.obj.method4.called).to.be.false;
-    });
+  it(tests.t5.m, function () {
+    App.updater.run(tests.t5.obj, 'method4', 'isWorking', 15000, 'pattern');
+    this.clock.tick(15000);
+    expect(tests.t5.obj.method4.called).to.be.false;
+  });
 
-    afterEach(function() {
-      this.clock.restore();
-      App.router.get.restore();
-    });
+  afterEach(function () {
+    this.clock.restore();
+    App.router.get.restore();
   });
-});
+});

+ 8 - 8
ambari-web/test/views/common/chart/linear_time_test.js

@@ -18,6 +18,7 @@
 
 var App = require('app');
 require('views/common/chart/linear_time');
+var testHelpers = require('test/helpers');
 
 describe('App.ChartLinearTimeView', function () {
 
@@ -464,6 +465,7 @@ describe('App.ChartLinearTimeView.LoadAggregator', function () {
       sinon.stub(aggregator, 'formatRequestData', function(_request){
         return _request.fields;
       });
+      App.ajax.send.restore();
       sinon.stub(App.ajax, 'send', function(){
         return {
           done: Em.K,
@@ -473,7 +475,6 @@ describe('App.ChartLinearTimeView.LoadAggregator', function () {
     });
     afterEach(function () {
       aggregator.groupRequests.restore();
-      App.ajax.send.restore();
       aggregator.formatRequestData.restore();
     });
     it("valid request is sent", function () {
@@ -486,13 +487,12 @@ describe('App.ChartLinearTimeView.LoadAggregator', function () {
         }
       };
       aggregator.runRequests(requests);
-      expect(App.ajax.send.getCall(0).args[0]).to.eql({
-        name: 'r1',
-        sender: context,
-        data: {
-          fields: ['f3', 'f4'],
-          hostName: 'host1'
-        }
+      var args = testHelpers.findAjaxRequest('name', 'r1');
+      expect(args[0]).exists;
+      expect(args[0].sender).to.be.eql(context);
+      expect(args[0].data).to.be.eql({
+        fields: ['f3', 'f4'],
+        hostName: 'host1'
       });
     });
   });

+ 4 - 8
ambari-web/test/views/common/configs/config_history_flow_test.js

@@ -18,7 +18,7 @@
 
 var App = require('app');
 require('views/common/configs/config_history_flow');
-
+var testHelpers = require('test/helpers');
 
 describe.skip('App.ConfigHistoryFlowView', function () {
 
@@ -299,7 +299,7 @@ describe.skip('App.ConfigHistoryFlowView', function () {
       App.tooltip.restore();
     });
 
-    it('App.tooltip is called onñe', function () {
+    it('App.tooltip is called on�e', function () {
       expect(App.tooltip.calledOnce).to.be.true;
     });
   });
@@ -624,16 +624,12 @@ describe.skip('App.ConfigHistoryFlowView', function () {
   describe('#sendRevertCall()', function () {
 
     beforeEach(function () {
-      sinon.stub(App.ajax, 'send', Em.K);
       view.sendRevertCall(Em.Object.create());
     });
 
-    afterEach(function () {
-      App.ajax.send.restore();
-    });
-
     it('request is sent', function () {
-      expect(App.ajax.send.calledOnce).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'service.serviceConfigVersion.revert');
+      expect(args).exists;
     });
   });
 

+ 5 - 4
ambari-web/test/views/common/controls_view_test.js

@@ -19,6 +19,7 @@
 var App = require('app');
 require('views/common/controls_view');
 var validator = require('utils/validator');
+var testHelpers = require('test/helpers');
 
 describe('App.ServiceConfigRadioButtons', function () {
 
@@ -793,23 +794,23 @@ describe('App.CheckDBConnectionView', function () {
         getConnectionProperty: Em.K,
         masterHostName: 'host1'
       });
-      sinon.stub(App.ajax, 'send');
       this.mock = sinon.stub(App.Service, 'find');
     });
     afterEach(function () {
-      App.ajax.send.restore();
       this.mock.restore();
     });
 
     it("service not installed", function() {
       this.mock.returns(Em.Object.create({isLoaded: false}));
       view.createCustomAction();
-      expect(App.ajax.send.getCall(0).args[0].name).to.equal('custom_action.create');
+      var args = testHelpers.findAjaxRequest('name', 'custom_action.create');
+      expect(args[0]).exists;
     });
     it("service is installed", function() {
       this.mock.returns(Em.Object.create({isLoaded: true}));
       view.createCustomAction();
-      expect(App.ajax.send.getCall(0).args[0].name).to.equal('cluster.custom_action.create');
+      var args = testHelpers.findAjaxRequest('name', 'cluster.custom_action.create');
+      expect(args[0]).exists;
     });
   });
 });

+ 22 - 37
ambari-web/test/views/common/quick_link_view_test.js

@@ -18,6 +18,7 @@
 
 var App = require('app');
 require('views/common/quick_view_link_view');
+var testHelpers = require('test/helpers');
 
 describe('App.QuickViewLinks', function () {
 
@@ -111,20 +112,12 @@ describe('App.QuickViewLinks', function () {
   });
 
   describe("#loadTags()", function () {
-    beforeEach(function () {
-      sinon.stub(App.ajax, 'send');
-    });
-    afterEach(function () {
-      App.ajax.send.restore();
-    });
+
     it("call $.ajax", function () {
       quickViewLinks.loadTags();
-      expect(App.ajax.send.calledWith({
-        name: 'config.tags',
-        sender: quickViewLinks,
-        success: 'loadTagsSuccess',
-        error: 'loadTagsError'
-      })).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'config.tags');
+      expect(args[0]).exists;
+      expect(args[0].sender).to.be.eql(quickViewLinks);
     });
   });
 
@@ -132,9 +125,7 @@ describe('App.QuickViewLinks', function () {
     beforeEach(function () {
       sinon.stub(quickViewLinks, 'setConfigProperties', function () {
         return {
-          done: function (callback) {
-            callback();
-          }
+          done: Em.clb
         }
       });
       sinon.stub(quickViewLinks, 'getQuickLinksHosts');
@@ -233,7 +224,6 @@ describe('App.QuickViewLinks', function () {
 
   describe("#getQuickLinksHosts()", function () {
     beforeEach(function () {
-      sinon.stub(App.ajax, 'send');
       sinon.stub(App.HostComponent, 'find').returns([
         Em.Object.create({
           isMaster: true,
@@ -242,35 +232,30 @@ describe('App.QuickViewLinks', function () {
       ]);
     });
     afterEach(function () {
-      App.ajax.send.restore();
       App.HostComponent.find.restore();
     });
     it("call $.ajax", function () {
       quickViewLinks.getQuickLinksHosts();
-      expect(App.ajax.send.calledWith({
-        name: 'hosts.for_quick_links',
-        sender: quickViewLinks,
-        data: {
-          clusterName: App.get('clusterName'),
-          masterHosts: 'host1',
-          urlParams: ''
-        },
-        success: 'setQuickLinksSuccessCallback'
-      })).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'hosts.for_quick_links');
+      expect(args[0]).exists;
+      expect(args[0].sender).to.be.eql(quickViewLinks);
+      expect(args[0].data).to.be.eql({
+        clusterName: App.get('clusterName'),
+        masterHosts: 'host1',
+        urlParams: ''
+      });
     });
     it("call $.ajax, HBASE service", function () {
       quickViewLinks.set('content.serviceName', 'HBASE');
       quickViewLinks.getQuickLinksHosts();
-      expect(App.ajax.send.calledWith({
-        name: 'hosts.for_quick_links',
-        sender: quickViewLinks,
-        data: {
-          clusterName: App.get('clusterName'),
-          masterHosts: 'host1',
-          urlParams: ',host_components/metrics/hbase/master/IsActiveMaster'
-        },
-        success: 'setQuickLinksSuccessCallback'
-      })).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'hosts.for_quick_links');
+      expect(args[0]).exists;
+      expect(args[0].sender).to.be.eql(quickViewLinks);
+      expect(args[0].data).to.be.eql({
+        clusterName: App.get('clusterName'),
+        masterHosts: 'host1',
+        urlParams: ',host_components/metrics/hbase/master/IsActiveMaster'
+      });
     });
   });
 

+ 17 - 7
ambari-web/test/views/common/widget/gauge_widget_view_test.js

@@ -20,14 +20,24 @@ var App = require('app');
 require('views/common/widget/gauge_widget_view');
 
 describe('App.GaugeWidgetView', function () {
-  var view = App.GaugeWidgetView.create({
-    value: 0,
-    content: {
-      properties: {
-        warning_threshold: 0,
-        critical_threshold: 0
+
+  var view;
+
+  beforeEach(function () {
+    view = App.GaugeWidgetView.create({
+      value: 0,
+      content: {
+        properties: {
+          warning_threshold: 0,
+          critical_threshold: 0
+        }
       }
-    }
+    });
+  });
+
+  afterEach(function () {
+    clearTimeout(view.get('timeoutId'));
+    view.destroy();
   });
 
   describe("#chartView.contentColor()", function() {

+ 11 - 1
ambari-web/test/views/common/widget/graph_widget_view_test.js

@@ -21,7 +21,17 @@ require('views/common/widget/graph_widget_view');
 var fileUtils = require('utils/file_utils');
 
 describe('App.GraphWidgetView', function () {
-  var view = App.GraphWidgetView.create();
+
+  var view;
+
+  beforeEach(function () {
+    view = App.GraphWidgetView.create();
+  });
+
+  afterEach(function () {
+    clearTimeout(view.get('timeoutId'));
+    view.destroy();
+  });
 
   describe("#adjustData()", function() {
     var testCases = [

+ 17 - 7
ambari-web/test/views/common/widget/number_widget_view_test.js

@@ -20,14 +20,24 @@ var App = require('app');
 require('views/common/widget/number_widget_view');
 
 describe('App.NumberWidgetView', function () {
-  var view = App.NumberWidgetView.create({
-    value: 0,
-    content: {
-      properties: {
-        warning_threshold: 0,
-        critical_threshold: 0
+
+  var view;
+
+  beforeEach(function () {
+    view = App.NumberWidgetView.create({
+      value: 0,
+      content: {
+        properties: {
+          warning_threshold: 0,
+          critical_threshold: 0
+        }
       }
-    }
+    });
+  });
+
+  afterEach(function () {
+    clearTimeout(view.get('timeoutId'));
+    view.destroy();
   });
 
   describe("#contentColor()", function() {

+ 13 - 3
ambari-web/test/views/main/admin/stack_upgrade/upgrade_group_view_test.js

@@ -21,9 +21,19 @@ var App = require('app');
 require('views/main/admin/stack_upgrade/upgrade_group_view');
 
 describe('App.upgradeGroupView', function () {
-  var view = App.upgradeGroupView.create({
-    content: Em.Object.create({}),
-    failedStatuses: ['FAILED']
+  var view;
+
+  beforeEach(function () {
+    view = App.upgradeGroupView.create({
+      content: Em.Object.create({}),
+      failedStatuses: ['FAILED']
+    });
+  });
+
+  afterEach(function () {
+    clearTimeout(view.get('timer'));
+    clearTimeout(view.get('upgradeItemTimer'));
+    view.destroy();
   });
 
   describe("#toggleExpanded()", function () {

+ 71 - 36
ambari-web/test/views/main/admin/stack_upgrade/upgrade_wizard_view_test.js

@@ -19,12 +19,13 @@
 
 var App = require('app');
 require('views/main/admin/stack_upgrade/upgrade_wizard_view');
+var testHelpers = require('test/helpers');
 
-describe('App.upgradeWizardView', function () {
-  var view = App.upgradeWizardView.create({
+function getView() {
+  var v = App.upgradeWizardView.create({
     failedStatuses: ['FAILED']
   });
-  view.reopen({
+  v.reopen({
     controller: Em.Object.create({
       finalizeContext: 'Confirm Finalize',
       upgradeData: Em.Object.create(),
@@ -35,21 +36,29 @@ describe('App.upgradeWizardView', function () {
       }
     })
   });
-  view.removeObserver('App.clusterName', view, 'startPolling');
+  v.removeObserver('App.clusterName', v, 'startPolling');
+  return v;
+}
+
+describe('App.upgradeWizardView', function () {
+  var view;
 
   beforeEach(function () {
+    App.ajax.send.restore();
     sinon.stub(App.ajax, 'send').returns({
       complete: Em.clb
     });
+    view = getView();
   });
 
   afterEach(function () {
-    App.ajax.send.restore();
+    clearTimeout(view.get('upgradeItemTimer'));
+    view.destroy();
   });
 
-  App.TestAliases.testAsComputedOr(view, 'isManualProceedDisabled', ['!isManualDone', 'controller.requestInProgress']);
+  App.TestAliases.testAsComputedOr(getView(), 'isManualProceedDisabled', ['!isManualDone', 'controller.requestInProgress']);
 
-  App.TestAliases.testAsComputedEqualProperties(view, 'isFinalizeItem', 'manualItem.context', 'controller.finalizeContext');
+  App.TestAliases.testAsComputedEqualProperties(getView(), 'isFinalizeItem', 'manualItem.context', 'controller.finalizeContext');
 
   describe("#upgradeGroups", function () {
     it("upgradeGroups is null", function () {
@@ -107,9 +116,7 @@ describe('App.upgradeWizardView', function () {
     beforeEach(function () {
       sinon.stub(view.get('controller'), 'loadUpgradeData', function () {
         return {
-          done: function (callback) {
-            callback();
-          }
+          done: Em.clb
         }
       });
       sinon.stub(view, 'doPolling', Em.K);
@@ -135,10 +142,10 @@ describe('App.upgradeWizardView', function () {
   });
 
   describe("#willInsertElement()", function () {
-    before(function () {
+    beforeEach(function () {
       sinon.stub(view, 'startPolling', Em.K);
     });
-    after(function () {
+    afterEach(function () {
       view.startPolling.restore();
     });
     it("call startPolling()", function () {
@@ -159,9 +166,7 @@ describe('App.upgradeWizardView', function () {
     beforeEach(function () {
       sinon.stub(view.get('controller'), 'loadUpgradeData', function () {
         return {
-          done: function (callback) {
-            callback();
-          }
+          done: Em.clb
         }
       });
       sinon.spy(view, 'doPolling');
@@ -231,6 +236,13 @@ describe('App.upgradeWizardView', function () {
   });
 
   describe("#manualItem", function () {
+
+    beforeEach(function () {
+      view.reopen({
+        activeGroup: Em.Object.create()
+      });
+    });
+
     it("no running item", function () {
       view.set('activeGroup.upgradeItems', []);
       view.propertyDidChange('manualItem');
@@ -252,6 +264,13 @@ describe('App.upgradeWizardView', function () {
   });
 
   describe("#failedItem", function () {
+
+    beforeEach(function () {
+      view.reopen({
+        activeGroup: Em.Object.create()
+      });
+    });
+
     it("no running item", function () {
       view.set('activeGroup.upgradeItems', []);
       view.propertyDidChange('failedItem');
@@ -265,6 +284,13 @@ describe('App.upgradeWizardView', function () {
   });
 
   describe("#runningItem", function () {
+
+    beforeEach(function () {
+      view.reopen({
+        activeGroup: Em.Object.create()
+      });
+    });
+
     it("no running item", function () {
       view.set('activeGroup.upgradeItems', []);
       view.propertyDidChange('runningItem');
@@ -395,7 +421,7 @@ describe('App.upgradeWizardView', function () {
     });
   });
 
-  App.TestAliases.testAsComputedAnd(view, 'isDowngradeAvailable', ['!controller.isDowngrade', 'controller.downgradeAllowed']);
+  App.TestAliases.testAsComputedAnd(getView(), 'isDowngradeAvailable', ['!controller.isDowngrade', 'controller.downgradeAllowed']);
 
   describe("#taskDetails", function () {
     it("runningItem present", function () {
@@ -429,10 +455,10 @@ describe('App.upgradeWizardView', function () {
   });
 
   describe("#toggleDetails()", function () {
-    before(function () {
+    beforeEach(function () {
       sinon.stub(view, 'toggleProperty', Em.K);
     });
-    after(function () {
+    afterEach(function () {
       view.toggleProperty.restore();
     });
     it("isDetailsOpened is toggled", function () {
@@ -442,6 +468,11 @@ describe('App.upgradeWizardView', function () {
   });
 
   describe("#upgradeStatusLabel", function () {
+
+    beforeEach(function () {
+      Em.setFullPath(view, 'controller.upgradeData.Upgrade', {});
+    });
+
     [
       {
         data: {
@@ -604,19 +635,19 @@ describe('App.upgradeWizardView', function () {
     beforeEach(function () {
       sinon.stub(view.get('controller'), 'getUpgradeItem', function () {
         return {
-          complete: function (callback) {
-            callback();
-          }
+          complete: Em.clb
         }
       });
       sinon.spy(view, 'doUpgradeItemPolling');
       this.clock = sinon.useFakeTimers();
     });
+
     afterEach(function () {
       view.get('controller').getUpgradeItem.restore();
       view.doUpgradeItemPolling.restore();
       this.clock.restore();
     });
+
     it("running item details", function () {
       view.reopen({
         runningItem: {},
@@ -628,24 +659,24 @@ describe('App.upgradeWizardView', function () {
       this.clock.tick(App.bgOperationsUpdateInterval);
       expect(view.doUpgradeItemPolling.calledTwice).to.be.true;
     });
+
     it("failed item details", function () {
       view.reopen({
         failedItem: {},
         runningItem: null
       });
       view.set('isDetailsOpened', true);
-      view.doUpgradeItemPolling();
       expect(view.get('controller').getUpgradeItem.calledOnce).to.be.true;
       this.clock.tick(App.bgOperationsUpdateInterval);
       expect(view.doUpgradeItemPolling.calledTwice).to.be.true;
     });
+
     it("details not opened", function () {
       view.set('isDetailsOpened', false);
       //doUpgradeItemPolling triggered by observer
-      expect(view.get('controller').getUpgradeItem.calledOnce).to.be.false;
-      this.clock.tick(App.bgOperationsUpdateInterval);
-      expect(view.doUpgradeItemPolling.calledOnce).to.be.true;
+      expect(view.get('controller').getUpgradeItem.called).to.be.false;
     });
+
   });
 
   describe('#getSkippedServiceChecks()', function () {
@@ -689,17 +720,25 @@ describe('App.upgradeWizardView', function () {
           view.propertyDidChange('isFinalizeItem');
         });
 
-        it('request is sent ' + item.ajaxSendCallCount + ' times', function (){
-          expect(App.ajax.send.callCount).to.equal(item.ajaxSendCallCount);
-        });
-
         it('areSkippedServiceChecksLoaded is ' + item.areSkippedServiceChecksLoaded, function () {
           expect(view.get('controller.areSkippedServiceChecksLoaded')).to.equal(item.areSkippedServiceChecksLoadedResult);
         });
 
         if (item.ajaxSendCallCount) {
+          it('request is sent ' + item.ajaxSendCallCount + ' times', function (){
+            var args = testHelpers.findAjaxRequest('name', 'admin.upgrade.service_checks');
+            expect(args).to.have.property('length').equal(item.ajaxSendCallCount);
+          });
+
           it('upgradeId is 1', function () {
-            expect(App.ajax.send.firstCall.args[0].data.upgradeId).to.equal(1);
+            var args = testHelpers.findAjaxRequest('name', 'admin.upgrade.service_checks');
+            expect(args[0].data.upgradeId).to.equal(1);
+          });
+        }
+        else {
+          it('request is not sent times', function () {
+            var args = testHelpers.findAjaxRequest('name', 'admin.upgrade.service_checks');
+            expect(args).not.exists;
           });
         }
       });
@@ -809,9 +848,7 @@ describe('App.upgradeWizardView', function () {
     beforeEach(function () {
       sinon.stub(view.get('controller'), 'getUpgradeItem', function () {
         return {
-          complete: function (callback) {
-            callback();
-          }
+          complete: Em.clb
         }
       });
       view.set('controller.areSlaveComponentFailuresHostsLoaded', false);
@@ -841,9 +878,7 @@ describe('App.upgradeWizardView', function () {
     beforeEach(function () {
       sinon.stub(view.get('controller'), 'getUpgradeItem', function () {
         return {
-          complete: function (callback) {
-            callback();
-          }
+          complete: Em.clb
         }
       });
       view.set('controller.areServiceCheckFailuresServicenamesLoaded', false);

+ 50 - 35
ambari-web/test/views/main/admin/stack_upgrade/version_view_test.js

@@ -19,16 +19,26 @@
 
 var App = require('app');
 require('views/main/admin/stack_upgrade/upgrade_wizard_view');
+var testHelpers = require('test/helpers');
 
 describe('App.mainAdminStackVersionsView', function () {
-  var view = App.MainAdminStackVersionsView.create({
-    controller: {
-      currentVersion: {
-        repository_version: "2.2.1.0",
-        runningCheckRequests: []
-      },
-      load: Em.K
-    }
+  var view;
+
+  beforeEach(function () {
+    view = App.MainAdminStackVersionsView.create({
+      controller: {
+        currentVersion: {
+          repository_version: "2.2.1.0",
+          runningCheckRequests: []
+        },
+        load: Em.K
+      }
+    });
+  });
+
+  afterEach(function () {
+    clearTimeout(view.get('updateTimer'));
+    view.destroy();
   });
 
   describe("#filterBy()", function () {
@@ -226,10 +236,10 @@ describe('App.mainAdminStackVersionsView', function () {
   });
 
   describe("#didInsertElement()", function() {
-    before(function () {
+    beforeEach(function () {
       sinon.stub(view, 'observesCategories', Em.K);
     });
-    after(function () {
+    afterEach(function () {
       view.observesCategories.restore();
     });
     it("observesCategories is called once", function() {
@@ -300,11 +310,11 @@ describe('App.mainAdminStackVersionsView', function () {
   });
 
   describe("#filterVersions()", function() {
-    before(function () {
+    beforeEach(function () {
       sinon.stub(view, 'filterBy').returns([{id: 1}]);
       sinon.stub(view, 'observesCategories', Em.K);
     });
-    after(function () {
+    afterEach(function () {
       view.filterBy.restore();
       view.observesCategories.restore();
     });
@@ -316,49 +326,54 @@ describe('App.mainAdminStackVersionsView', function () {
   });
 
   describe("#goToVersions()", function() {
+    var data = {
+      components: [{
+        'RootServiceComponents': {
+          'component_version': '1.9.0'
+        }
+      }, {
+        'RootServiceComponents': {
+          'component_version': '2.1.0'
+        }
+      }, {
+        'RootServiceComponents': {
+          'component_version': '2.0.0'
+        }
+      }]
+    };
     before(function () {
       sinon.spy(App, 'showConfirmationPopup');
       sinon.stub(window.location, 'replace', Em.K);
-      var data = {
-        components: [{
-          'RootServiceComponents': {
-            'component_version': '1.9.0'
-          }
-        }, {
-          'RootServiceComponents': {
-            'component_version': '2.1.0'
-          }
-        }, {
-          'RootServiceComponents': {
-            'component_version': '2.0.0'
-          }
-        }]
-      };
-      sinon.stub(App.ajax, 'send').returns({
-        then: function(callback) {
-          callback(data);
-        }
-      });
     });
     after(function () {
       App.showConfirmationPopup.restore();
       window.location.replace.restore();
+    });
+
+    beforeEach(function () {
       App.ajax.send.restore();
+      sinon.stub(App.ajax, 'send').returns({
+        then: function(callback) {
+          callback(data);
+        }
+      });
     });
+
     it("should go to link using the version retrieved by query", function() {
       var popup = view.goToVersions();
       expect(App.showConfirmationPopup.calledOnce).to.be.true;
       popup.onPrimary();
-      expect(App.ajax.send.calledOnce).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'ambari.service.load_server_version');
+      expect(args[0]).exists;
       expect(window.location.replace.calledWith('/views/ADMIN_VIEW/2.1.0/INSTANCE/#/stackVersions')).to.be.true;
     });
   });
 
   describe("#willInsertElement()", function() {
-    before(function () {
+    beforeEach(function () {
       sinon.stub(view, 'poll', Em.K);
     });
-    after(function () {
+    afterEach(function () {
       view.poll.restore();
     });
     it("poll is called once", function() {

+ 2 - 9
ambari-web/test/views/main/dashboard/widget_test.js

@@ -72,20 +72,13 @@ describe('App.DashboardWidgetView', function () {
         complete: Em.K
       });
     });
+
     afterEach(function () {
       dashboardWidgetView.get('parentView').widgetsMapper.restore();
       dashboardWidgetView.get('parentView').getUserPref.restore();
     });
-    it("testMode is on", function () {
-      App.set('testMode', true);
-      dashboardWidgetView.set('id', '1');
-      dashboardWidgetView.deleteWidget();
-      expect(dashboardWidgetView.get('parentView').widgetsMapper.calledWith('1')).to.be.true;
-      expect(dashboardWidgetView.get('parentView.visibleWidgets')).to.be.empty;
-      expect(dashboardWidgetView.get('parentView.hiddenWidgets')).to.not.be.empty;
-    });
+
     it("testMode is off", function () {
-      App.set('testMode', false);
       dashboardWidgetView.set('parentView.persistKey', 'key');
       dashboardWidgetView.deleteWidget();
       expect(dashboardWidgetView.get('parentView').getUserPref.calledWith('key')).to.be.true;

+ 20 - 11
ambari-web/test/views/main/dashboard/widgets/namenode_cpu_test.js

@@ -26,19 +26,28 @@ require('views/main/dashboard/widgets/namenode_cpu');
 
 describe('App.NameNodeCpuPieChartView', function() {
 
-  var model = Em.Object.create({
-    used: null,
-    max: null
-  });
-  var nameNodeCpuPieChartView = App.NameNodeCpuPieChartView.create({
-    model_type: null,
-    model: model,
-    modelFieldUsed: 'used',
-    modelFieldMax: 'max',
-    widgetHtmlId: 'fake'
+  var model;
+  var nameNodeCpuPieChartView;
+
+  beforeEach(function () {
+    model = Em.Object.create({
+      used: null,
+      max: null
+    });
+    nameNodeCpuPieChartView = App.NameNodeCpuPieChartView.create({
+      model_type: null,
+      model: model,
+      modelFieldUsed: 'used',
+      modelFieldMax: 'max',
+      widgetHtmlId: 'fake'
+    });
+    nameNodeCpuPieChartView.calc();
   });
 
-  nameNodeCpuPieChartView.calc();
+  afterEach(function () {
+    nameNodeCpuPieChartView.destroy();
+    clearTimeout(nameNodeCpuPieChartView.get('intervalId'));
+  });
 
   describe('#calcIsPieExists', function() {
     var tests = [

+ 3 - 15
ambari-web/test/views/main/dashboard/widgets_test.js

@@ -232,20 +232,13 @@ describe('App.MainDashboardWidgetsView', function () {
         });
         sinon.stub(view, 'widgetsMapper').returns(widget);
       });
+
       afterEach(function () {
         view.getUserPref.restore();
         view.widgetsMapper.restore();
       });
-      it("testMode is on", function () {
-        App.set('testMode', true);
-        plusButtonFilterView.set('hiddenWidgets', [widget]);
-        plusButtonFilterView.applyFilter();
-        expect(view.getUserPref.called).to.be.false;
-        expect(plusButtonFilterView.get('visibleWidgets')).not.to.be.empty;
-        expect(plusButtonFilterView.get('hiddenWidgets')).to.be.empty;
-      });
+
       it("testMode is off", function () {
-        App.set('testMode', false);
         plusButtonFilterView.applyFilter();
         expect(view.getUserPref.calledOnce).to.be.true;
       });
@@ -350,18 +343,13 @@ describe('App.MainDashboardWidgetsView', function () {
       sinon.stub(view, 'translateToReal', Em.K);
       sinon.stub(view, 'getUserPref').returns({complete: Em.K});
     });
+
     afterEach(function () {
       view.translateToReal.restore();
       view.getUserPref.restore();
     });
 
-    it("testMode is true", function () {
-      App.set('testMode', true);
-      view.setOnLoadVisibleWidgets();
-      expect(view.translateToReal.calledOnce).to.be.true;
-    });
     it("testMode is false", function () {
-      App.set('testMode', false);
       view.setOnLoadVisibleWidgets();
       expect(view.getUserPref.calledOnce).to.be.true;
     });

+ 10 - 5
ambari-web/test/views/main/host/details/host_component_views/datanode_view_test.js

@@ -18,6 +18,7 @@
 
 var App = require('app');
 require('views/main/host/details/host_component_views/datanode_view');
+var testHelpers = require('test/helpers');
 
 describe('App.DataNodeComponentView', function () {
   var view = App.DataNodeComponentView.create({
@@ -30,11 +31,9 @@ describe('App.DataNodeComponentView', function () {
 
     beforeEach(function () {
       this.stub = sinon.stub(App.HDFSService, 'find');
-      sinon.stub(App.ajax, 'send');
     });
 
     afterEach(function () {
-      App.ajax.send.restore();
       this.stub.restore();
     });
 
@@ -47,7 +46,9 @@ describe('App.DataNodeComponentView', function () {
         })
       ]);
       view.getDNDecommissionStatus();
-      expect(App.ajax.send.getCall(0).args[0].data).to.eql({
+      var args = testHelpers.findAjaxRequest('name', 'host.host_component.decommission_status_datanode');
+      expect(args[0]).exists;
+      expect(args[0].data).to.be.eql({
         "hostName": "host1",
         "componentName": "NAMENODE"
       });
@@ -62,7 +63,9 @@ describe('App.DataNodeComponentView', function () {
         })
       ]);
       view.getDNDecommissionStatus();
-      expect(App.ajax.send.getCall(0).args[0].data).to.eql({
+      var args = testHelpers.findAjaxRequest('name', 'host.host_component.decommission_status_datanode');
+      expect(args[0]).exists;
+      expect(args[0].data).to.be.eql({
         "hostName": "host1",
         "componentName": "NAMENODE"
       });
@@ -77,7 +80,9 @@ describe('App.DataNodeComponentView', function () {
         })
       ]);
       view.getDNDecommissionStatus();
-      expect(App.ajax.send.getCall(0).args[0].data).to.eql({
+      var args = testHelpers.findAjaxRequest('name', 'host.host_component.decommission_status_datanode');
+      expect(args[0]).exists;
+      expect(args[0].data).to.be.eql({
         "hostName": "host2",
         "componentName": "NAMENODE"
       });

+ 11 - 17
ambari-web/test/views/main/host/details/host_component_views/decommissionable_test.js

@@ -21,6 +21,7 @@ require('models/host_component');
 require('views/main/host/details/host_component_view');
 require('mixins');
 require('mixins/main/host/details/host_components/decommissionable');
+var testHelpers = require('test/helpers');
 
 var hostComponentView;
 
@@ -223,18 +224,14 @@ describe('App.Decommissionable', function() {
   });
 
   describe("#getDesiredAdminState()", function() {
-    beforeEach(function () {
-      sinon.stub(App.ajax, 'send', Em.K);
-    });
-    afterEach(function () {
-      App.ajax.send.restore();
-    });
+
     it("content is null", function() {
       hostComponentView = Em.View.create(App.Decommissionable, {
         content: null
       });
       hostComponentView.getDesiredAdminState();
-      expect(App.ajax.send.called).to.be.false;
+      var args = testHelpers.findAjaxRequest('name', 'host.host_component.slave_desired_admin_state');
+      expect(args).not.exists;
     });
     it("content is correct", function() {
       hostComponentView = Em.View.create(App.Decommissionable, {
@@ -244,16 +241,13 @@ describe('App.Decommissionable', function() {
         })
       });
       hostComponentView.getDesiredAdminState();
-      expect(App.ajax.send.calledWith({
-        name: 'host.host_component.slave_desired_admin_state',
-        sender: hostComponentView,
-        data: {
-          hostName: 'host1',
-          componentName: 'C1'
-        },
-        success: 'getDesiredAdminStateSuccessCallback',
-        error: 'getDesiredAdminStateErrorCallback'
-      })).to.be.true;
+      var args = testHelpers.findAjaxRequest('name', 'host.host_component.slave_desired_admin_state');
+      expect(args[0]).exists;
+      expect(args[0].sender).to.be.eql(hostComponentView);
+      expect(args[0].data).to.be.eql({
+        hostName: 'host1',
+        componentName: 'C1'
+      });
     });
   });
 });

+ 0 - 10
ambari-web/test/views/main/service/services/ranger_test.js

@@ -31,16 +31,6 @@ describe('App.MainDashboardServiceRangerView', function () {
 
   describe('#didInsertElement', function () {
 
-    beforeEach(function () {
-      sinon.stub(App.updater, 'run', Em.K);
-      sinon.stub(App.updater, 'immediateRun', Em.K);
-    });
-
-    afterEach(function () {
-      App.updater.run.restore();
-      App.updater.immediateRun.restore();
-    });
-
     it('should run updater', function () {
       view.didInsertElement();
       expect(App.updater.run.calledOnce).to.be.true;