Repository: ambari
Updated Branches:
  refs/heads/trunk a41198d50 -> 7e395b9bb


AMBARI-5733. Unit tests for step controllers (3), views (3, 9) with small 
refactor. (onechiporenko)


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

Branch: refs/heads/trunk
Commit: 7e395b9bbf05213f42079fa47bdb633d4cb6b624
Parents: a41198d
Author: Oleg Nechiporenko <onechipore...@apache.org>
Authored: Mon May 12 19:02:15 2014 +0300
Committer: Oleg Nechiporenko <onechipore...@apache.org>
Committed: Mon May 12 19:02:15 2014 +0300

----------------------------------------------------------------------
 .../app/controllers/wizard/step3_controller.js  | 134 ++++---
 .../wizard/step3/hostWarningPopupBody_view.js   |   9 +-
 ambari-web/app/views/wizard/step3_view.js       |  25 +-
 ambari-web/app/views/wizard/step9_view.js       |  45 ++-
 ambari-web/test/installer/step3_test.js         | 371 ++++++++++++++++++-
 ambari-web/test/views/wizard/step3_view_test.js |  14 +-
 ambari-web/test/views/wizard/step9_view_test.js |   6 +-
 7 files changed, 513 insertions(+), 91 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/7e395b9b/ambari-web/app/controllers/wizard/step3_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/wizard/step3_controller.js 
b/ambari-web/app/controllers/wizard/step3_controller.js
index 4fc095b..ba2e07d 100644
--- a/ambari-web/app/controllers/wizard/step3_controller.js
+++ b/ambari-web/app/controllers/wizard/step3_controller.js
@@ -160,7 +160,7 @@ App.WizardStep3Controller = Em.Controller.extend({
         }
       } else {
         this.set('bootHosts', this.get('hosts'));
-        if (App.testMode) {
+        if (App.get('testMode')) {
           this.getHostInfo();
           this.get('bootHosts').setEach('cpu', '2');
           this.get('bootHosts').setEach('memory', '2000000');
@@ -416,14 +416,15 @@ App.WizardStep3Controller = Em.Controller.extend({
   /**
    * Do bootstrap calls
    * @method doBootstrap
+   * @return {$.ajax|null}
    */
   doBootstrap: function () {
     if (this.get('stopBootstrap')) {
-      return;
+      return null;
     }
     this.incrementProperty('numPolls');
 
-    App.ajax.send({
+    return App.ajax.send({
       name: 'wizard.step3.bootstrap',
       sender: this,
       data: {
@@ -512,13 +513,14 @@ App.WizardStep3Controller = Em.Controller.extend({
 
   /**
    * Do requests to check if hosts are already registered
+   * @return {$.ajax|null}
    * @method isHostsRegistered
    */
   isHostsRegistered: function () {
     if (this.get('stopBootstrap')) {
-      return;
+      return null;
     }
-    App.ajax.send({
+    return App.ajax.send({
       name: 'wizard.step3.is_hosts_registered',
       sender: this,
       success: 'isHostsRegisteredSuccessCallback'
@@ -689,68 +691,56 @@ App.WizardStep3Controller = Em.Controller.extend({
    * @method getHostInfoSuccessCallback
    */
   getHostInfoSuccessCallback: function (jsonData) {
-    var hosts = this.get('bootHosts');
-    var self = this;
+    var hosts = this.get('bootHosts'),
+      self = this,
+      repoWarnings = [],
+      hostsContext = [],
+      diskWarnings = [],
+      hostsDiskContext = [],
+      hostsDiskNames = [],
+      hostsRepoNames = [];
     this.parseWarnings(jsonData);
-    var repoWarnings = [];
-    var hostsContext = [];
-    var diskWarnings = [];
-    var hostsDiskContext = [];
-    var hostsDiskNames = [];
-    var hostsRepoNames = [];
+
     hosts.forEach(function (_host) {
-      var host = (App.testMode) ? jsonData.items[0] : 
jsonData.items.findProperty('Hosts.host_name', _host.name);
-      if (App.skipBootstrap) {
-        _host.set('cpu', 2);
-        _host.set('memory', ((parseInt(2000000))).toFixed(2));
-        _host.set('disk_info', [
-          {"mountpoint": "/", "type": "ext4"},
-          {"mountpoint": "/grid/0", "type": "ext4"},
-          {"mountpoint": "/grid/1", "type": "ext4"},
-          {"mountpoint": "/grid/2", "type": "ext4"}
-        ]);
-      } else if (host) {
-        _host.set('cpu', host.Hosts.cpu_count);
-        _host.set('memory', ((parseInt(host.Hosts.total_mem))).toFixed(2));
-        _host.set('disk_info', host.Hosts.disk_info.filter(function (host) {
-          return host.mountpoint != "/boot"
-        }));
-        _host.set('os_type', host.Hosts.os_type);
-        _host.set('os_arch', host.Hosts.os_arch);
-        _host.set('ip', host.Hosts.ip);
-
-        var context = self.checkHostOSType(host.Hosts.os_type, 
host.Hosts.host_name);
-        if (context) {
-          hostsContext.push(context);
-          hostsRepoNames.push(host.Hosts.host_name);
-        }
-        var diskContext = self.checkHostDiskSpace(host.Hosts.host_name, 
host.Hosts.disk_info);
-        if (diskContext) {
-          hostsDiskContext.push(diskContext);
-          hostsDiskNames.push(host.Hosts.host_name);
+      var host = (App.get('testMode')) ? jsonData.items[0] : 
jsonData.items.findProperty('Hosts.host_name', _host.name);
+      if (App.get('skipBootstrap')) {
+        self._setHostDataWithSkipBootstrap(_host);
+      }
+      else {
+        if (host) {
+          self._setHostDataFromLoadedHostInfo(_host, host);
+
+          var host_name = Em.get(host, 'Hosts.host_name');
+          var context = self.checkHostOSType(host.Hosts.os_type, host_name);
+          if (context) {
+            hostsContext.push(context);
+            hostsRepoNames.push(host_name);
+          }
+          var diskContext = self.checkHostDiskSpace(host_name, 
host.Hosts.disk_info);
+          if (diskContext) {
+            hostsDiskContext.push(diskContext);
+            hostsDiskNames.push(host_name);
+          }
         }
-
       }
     });
     if (hostsContext.length > 0) { // warning exist
-      var repoWarning = {
+      repoWarnings.push({
         name: Em.I18n.t('installer.step3.hostWarningsPopup.repositories.name'),
         hosts: hostsContext,
         hostsNames: hostsRepoNames,
         category: 'repositories',
         onSingleHost: false
-      };
-      repoWarnings.push(repoWarning);
+      });
     }
     if (hostsDiskContext.length > 0) { // disk space warning exist
-      var diskWarning = {
+      diskWarnings.push({
         name: Em.I18n.t('installer.step3.hostWarningsPopup.disk.name'),
         hosts: hostsDiskContext,
         hostsNames: hostsDiskNames,
         category: 'disk',
         onSingleHost: false
-      };
-      diskWarnings.push(diskWarning);
+      });
     }
 
     this.set('repoCategoryWarnings', repoWarnings);
@@ -759,6 +749,46 @@ App.WizardStep3Controller = Em.Controller.extend({
   },
 
   /**
+   * Set metrics to host object
+   * Used when <code>App.skipBootstrap</code> is true
+   * @param {Ember.Object} host
+   * @returns {object}
+   * @private
+   * @methos _setHostDataWithSkipBootstrap
+   */
+  _setHostDataWithSkipBootstrap: function(host) {
+    host.set('cpu', 2);
+    host.set('memory', ((parseInt(2000000))).toFixed(2));
+    host.set('disk_info', [
+      {"mountpoint": "/", "type": "ext4"},
+      {"mountpoint": "/grid/0", "type": "ext4"},
+      {"mountpoint": "/grid/1", "type": "ext4"},
+      {"mountpoint": "/grid/2", "type": "ext4"}
+    ]);
+    return host;
+  },
+
+  /**
+   * Set loaded metrics to host object
+   * @param {object} host
+   * @param {object} hostInfo
+   * @returns {object}
+   * @method _setHostDataFromLoadedHostInfo
+   * @private
+   */
+  _setHostDataFromLoadedHostInfo: function(host, hostInfo) {
+    host.set('cpu', Em.get(hostInfo, 'Hosts.cpu_count'));
+    host.set('memory', ((parseInt(Em.get(hostInfo, 
'Hosts.total_mem')))).toFixed(2));
+    host.set('disk_info', Em.get(hostInfo, 'Hosts.disk_info').filter(function 
(h) {
+      return h.mountpoint != "/boot"
+    }));
+    host.set('os_type', Em.get(hostInfo, 'Hosts.os_type'));
+    host.set('os_arch', Em.get(hostInfo, 'Hosts.os_arch'));
+    host.set('ip', Em.get(hostInfo, 'Hosts.ip'));
+    return host;
+  },
+
+  /**
    * Error-callback for hosts info request
    * @method getHostInfoErrorCallback
    */
@@ -798,12 +828,12 @@ App.WizardStep3Controller = Em.Controller.extend({
         });
       }
 
-      if (!isValid) {
+      if (isValid) {
+        return '';
+      } else {
         console.log('WARNING: Getting host os type does NOT match the user 
selected os group in step1. ' +
           'Host Name: ' + hostName + '. Host os type:' + osType + '. Selected 
group:' + selectedOS);
         return 
Em.I18n.t('installer.step3.hostWarningsPopup.repositories.context').format(hostName,
 osType, selectedOS);
-      } else {
-        return '';
       }
     } else {
       return '';

http://git-wip-us.apache.org/repos/asf/ambari/blob/7e395b9b/ambari-web/app/views/wizard/step3/hostWarningPopupBody_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/wizard/step3/hostWarningPopupBody_view.js 
b/ambari-web/app/views/wizard/step3/hostWarningPopupBody_view.js
index abb29b9..d28fcf4 100644
--- a/ambari-web/app/views/wizard/step3/hostWarningPopupBody_view.js
+++ b/ambari-web/app/views/wizard/step3/hostWarningPopupBody_view.js
@@ -47,7 +47,9 @@ App.WizardStep3HostWarningPopupBody = Em.View.extend({
      * @type {string[]}
      */
     hosts: function () {
-      return this.get('parentView.warningsByHost').mapProperty('name');
+      var warningsByHost = this.get('parentView.warningsByHost');
+      if (Em.isNone(warningsByHost)) return [];
+      return warningsByHost.mapProperty('name');
     }.property('parentView.warningsByHost'),
 
     /**
@@ -130,7 +132,9 @@ App.WizardStep3HostWarningPopupBody = Em.View.extend({
    * @type {Ember.Enumerable}
    */
   categoryWarnings: function () {
-    return this.get('warningsByHost').findProperty('name', 
this.get('category')).warnings
+    var warningsByHost = this.get('warningsByHost');
+    if (Em.isNone(warningsByHost)) return [];
+    return warningsByHost.findProperty('name', this.get('category')).warnings
   }.property('warningsByHost', 'category'),
 
   /**
@@ -345,6 +349,7 @@ App.WizardStep3HostWarningPopupBody = Em.View.extend({
    */
   warningHostsNamesCount: function () {
     var hostNameMap = Em.Object.create();
+    if (Em.isNone(this.get('bodyController.warningsByHost'))) return 0;
     var warningsByHost = this.get('bodyController.warningsByHost').slice();
     warningsByHost.shift();
     warningsByHost.forEach(function (_host) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/7e395b9b/ambari-web/app/views/wizard/step3_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/wizard/step3_view.js 
b/ambari-web/app/views/wizard/step3_view.js
index f193ff7..3f60f6c 100644
--- a/ambari-web/app/views/wizard/step3_view.js
+++ b/ambari-web/app/views/wizard/step3_view.js
@@ -213,18 +213,27 @@ App.WizardStep3View = App.TableView.extend({
   filter: function () {
     var self = this;
     Em.run.next(function () {
-      var result = [];
-      var selectedCategory = self.get('selectedCategory');
-      if (!selectedCategory || selectedCategory.get('hostsBootStatus') === 
'ALL') {
-        result = self.get('content');
-      } else {
-        result = self.get('content').filterProperty('bootStatus', 
self.get('selectedCategory.hostsBootStatus'));
-      }
-      self.set('filteredContent', result);
+      self.doFilter();
     });
   }.observes('selectedCategory'),
 
   /**
+   * Real filter-method
+   * Called from <code>filter</code> in Em.run.next-wrapper
+   * @method doFilter
+   */
+  doFilter: function() {
+    var result = [];
+    var selectedCategory = this.get('selectedCategory');
+    if (!selectedCategory || selectedCategory.get('hostsBootStatus') === 
'ALL') {
+      result = this.get('content');
+    } else {
+      result = this.get('content').filterProperty('bootStatus', 
this.get('selectedCategory.hostsBootStatus'));
+    }
+    this.set('filteredContent', result);
+  },
+
+  /**
    * Trigger on Category click
    * @param {Object} event
    * @method selectCategory

http://git-wip-us.apache.org/repos/asf/ambari/blob/7e395b9b/ambari-web/app/views/wizard/step9_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/wizard/step9_view.js 
b/ambari-web/app/views/wizard/step9_view.js
index ec64530..996a7ab 100644
--- a/ambari-web/app/views/wizard/step9_view.js
+++ b/ambari-web/app/views/wizard/step9_view.js
@@ -182,28 +182,37 @@ App.WizardStep9View = App.TableView.extend({
   filter: function () {
     var self = this;
     Em.run.next(function () {
-      var result = [];
-      var content = self.get('content');
-      var selectedCategory = self.get('selectedCategory');
-      if (!selectedCategory || selectedCategory.get('hostStatus') === 'all') {
-        result = content;
-      } else if (selectedCategory.get('hostStatus') == 'inProgress') {
-        result = content.filter(function (_host) {
-          return (_host.get('status') == 'info' || _host.get('status') == 
'pending' || _host.get('status') == 'in_progress');
-        });
-      } else if (selectedCategory.get('hostStatus') == 'failed') {
-        result = content.filter(function (_host) {
-          return (_host.get('status') == 'failed' || _host.get('status') == 
'heartbeat_lost');
-        });
-      } else {
-        result = content.filterProperty('status', 
selectedCategory.get('hostStatus'));
-      }
-      self.set('filteredContent', result);
-      self.set('filteredHostsInfo', 
Em.I18n.t('installer.step9.hosts.filteredHostsInfo').format(result.get('length'),
 content.get('length')));
+      self.doFilter();
     });
   }.observes('selectedCategory'),
 
   /**
+   * Real filter-method
+   * Called from <code>filter</code> in Em.run.next-wrapper
+   * @method doFilter
+   */
+  doFilter: function() {
+    var result = [];
+    var content = this.get('content');
+    var selectedCategory = this.get('selectedCategory');
+    if (!selectedCategory || selectedCategory.get('hostStatus') === 'all') {
+      result = content;
+    } else if (selectedCategory.get('hostStatus') == 'inProgress') {
+      result = content.filter(function (_host) {
+        return (_host.get('status') == 'info' || _host.get('status') == 
'pending' || _host.get('status') == 'in_progress');
+      });
+    } else if (selectedCategory.get('hostStatus') == 'failed') {
+      result = content.filter(function (_host) {
+        return (_host.get('status') == 'failed' || _host.get('status') == 
'heartbeat_lost');
+      });
+    } else {
+      result = content.filterProperty('status', 
selectedCategory.get('hostStatus'));
+    }
+    this.set('filteredContent', result);
+    this.set('filteredHostsInfo', 
Em.I18n.t('installer.step9.hosts.filteredHostsInfo').format(result.get('length'),
 content.get('length')));
+  },
+
+  /**
    * On click handler for 'show all' link
    * @method showAllHosts
    */

http://git-wip-us.apache.org/repos/asf/ambari/blob/7e395b9b/ambari-web/test/installer/step3_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/installer/step3_test.js 
b/ambari-web/test/installer/step3_test.js
index 24a56af..88a06b4 100644
--- a/ambari-web/test/installer/step3_test.js
+++ b/ambari-web/test/installer/step3_test.js
@@ -487,7 +487,8 @@ describe('App.WizardStep3Controller', function () {
       });
       c = App.WizardStep3Controller.create({
         wizardController: App.InstallerController.create(),
-        bootHosts: Em.A([{name: 'c1', bootStatus: 'FAILED'}, {name: 'c2', 
bootStatus: 'REGISTERED'}]),
+        isRetryDisabled: false,
+        bootHosts: Em.A([Em.Object.create({name: 'c1', bootStatus: 'FAILED'}), 
Em.Object.create({name: 'c2', bootStatus: 'REGISTERED'})]),
         content: {installOptions: {}},
         doBootstrap: Em.K
       });
@@ -992,6 +993,21 @@ describe('App.WizardStep3Controller', function () {
       expect(App.ModalPopup.show.calledOnce).to.equal(true);
       App.ModalPopup.show.restore();
     });
+    it('should clear checksUpdateStatus on primary', function() {
+      c.set('checksUpdateStatus', 'not null value');
+      c.hostWarningsPopup().onPrimary();
+      expect(c.get('checksUpdateStatus')).to.be.null;
+    });
+    it('should clear checksUpdateStatus on close', function() {
+      c.set('checksUpdateStatus', 'not null value');
+      c.hostWarningsPopup().onClose();
+      expect(c.get('checksUpdateStatus')).to.be.null;
+    });
+    it('should rerunChecks onSecondary', function() {
+      sinon.stub(c, 'rerunChecks', Em.K);
+      c.hostWarningsPopup().onSecondary();
+      expect(c.rerunChecks.calledOnce).to.equal(true);
+    });
   });
 
   describe('#registeredHostsPopup', function() {
@@ -1304,4 +1320,357 @@ describe('App.WizardStep3Controller', function () {
 
   });
 
+  describe('#hostsInCluster', function() {
+    it('should load data from App.Host model', function() {
+      var hosts = [
+        Em.Object.create({hostName: 'h1'}),
+        Em.Object.create({hostName: 'h2'}),
+        Em.Object.create({hostName: 'h3'})
+      ], expected = ['h1', 'h2', 'h3'];
+      sinon.stub(App.Host, 'find', function() {
+        return hosts;
+      });
+      expect(c.get('hostsInCluster')).to.eql(expected);
+      App.Host.find.restore();
+    });
+  });
+
+  describe('#navigateStep', function() {
+    Em.A([
+        {
+          isLoaded: true,
+          manualInstall: false,
+          bootStatus: false,
+          m: 'should call startBootstrap',
+          e: true
+        },
+        {
+          isLoaded: true,
+          manualInstall: false,
+          bootStatus: true,
+          m: 'shouldn\'t call startBootstrap (1)',
+          e: false
+        },
+        {
+          isLoaded: false,
+          manualInstall: false,
+          bootStatus: false,
+          m: 'shouldn\'t call startBootstrap (2)',
+          e: false
+        },
+        {
+          isLoaded: false,
+          manualInstall: true,
+          bootStatus: false,
+          m: 'shouldn\'t call startBootstrap (3)',
+          e: false
+        }
+    ]).forEach(function(test) {
+        it(test.m, function() {
+          c.reopen({
+            isLoaded: test.isLoaded,
+            content: {
+              installOptions: {
+                manualInstall: test.manualInstall
+              }
+            },
+            wizardController: Em.Object.create({
+              getDBProperty: function() {
+                return test.bootStatus
+              }
+            })
+          });
+          sinon.stub(c, 'startBootstrap', Em.K);
+          c.navigateStep();
+          if(test.e) {
+            expect(c.startBootstrap.calledOnce).to.equal(true);
+          }
+          else {
+            expect(c.startBootstrap.called).to.equal(false);
+          }
+          c.startBootstrap.restore();
+        });
+      });
+
+    it('should set test data if testMode is true', function() {
+      c.reopen({
+        isLoaded: true,
+        hosts: [{}, {}, {}],
+        content: {
+          installOptions: {
+            manualInstall: true
+          }
+        },
+        setRegistrationInProgress: Em.K
+      });
+      sinon.stub(App, 'get', function(k) {
+        if('testMode' === k) return true;
+        return Em.get(App, k);
+      });
+      c.navigateStep();
+      App.get.restore();
+      expect(c.get('bootHosts.length')).to.equal(c.get('hosts.length'));
+      expect(c.get('bootHosts').everyProperty('cpu', '2')).to.equal(true);
+      expect(c.get('bootHosts').everyProperty('memory', 
'2000000')).to.equal(true);
+      expect(c.get('isSubmitDisabled')).to.equal(false);
+    });
+
+    it('should start registration', function() {
+      c.reopen({
+        isLoaded: true,
+        hosts: [{}, {}, {}],
+        content: {
+          installOptions: {
+            manualInstall: true
+          }
+        },
+        setRegistrationInProgress: Em.K,
+        startRegistration: Em.K
+      });
+      sinon.spy(c, 'startRegistration');
+      sinon.stub(App, 'get', function(k) {
+        if('testMode' === k) return false;
+        return Em.get(App, k);
+      });
+      c.navigateStep();
+      App.get.restore();
+      expect(c.startRegistration.calledOnce).to.equal(true);
+      expect(c.get('bootHosts.length')).to.equal(c.get('hosts.length'));
+      expect(c.get('registrationStartedAt')).to.be.null;
+      c.startRegistration.restore();
+    });
+
+  });
+
+  describe('#checkHostDiskSpace', function() {
+    Em.A([
+        {
+          diskInfo: [
+            {
+              available: App.minDiskSpace * 1024 * 1024 - 1024,
+              mountpoint: '/'
+            }
+          ],
+          m: 'available less than App.minDiskSpace',
+          e: false
+        },
+        {
+          diskInfo: [
+            {
+              available: App.minDiskSpaceUsrLib * 1024 * 1024 - 1024,
+              mountpoint: '/usr'
+            }
+          ],
+          m: 'available less than App.minDiskSpaceUsrLib (1)',
+          e: false
+        },
+        {
+          diskInfo: [
+            {
+              available: App.minDiskSpaceUsrLib * 1024 * 1024 - 1024,
+              mountpoint: '/usr/lib'
+            }
+          ],
+          m: 'available less than App.minDiskSpaceUsrLib (2)',
+          e: false
+        },
+        {
+          diskInfo: [
+            {
+              available: App.minDiskSpace * 1024 * 1024 + 1024,
+              mountpoint: '/'
+            }
+          ],
+          m: 'available greater than App.minDiskSpace',
+          e: true
+        },
+        {
+          diskInfo: [
+            {
+              available: App.minDiskSpaceUsrLib * 1024 * 1024 + 1024,
+              mountpoint: '/usr'
+            }
+          ],
+          m: 'available greater than App.minDiskSpaceUsrLib (1)',
+          e: true
+        },
+        {
+          diskInfo: [
+            {
+              available: App.minDiskSpaceUsrLib * 1024 * 1024 + 1024,
+              mountpoint: '/usr/lib'
+            }
+          ],
+          m: 'available greater than App.minDiskSpaceUsrLib (2)',
+          e: true
+        },
+        {
+          diskInfo: [
+            {
+              available: App.minDiskSpaceUsrLib * 1024 * 1024 + 1024,
+              mountpoint: '/home/tdk'
+            }
+          ],
+          m: 'mount point without free space checks',
+          e: true
+        }
+      ]).forEach(function (test) {
+        it(test.m, function () {
+          var r = c.checkHostDiskSpace('', test.diskInfo);
+          expect(Em.isEmpty(r)).to.equal(test.e);
+        });
+      });
+  });
+
+  describe('#checkHostOSType', function() {
+    it('should return empty string if no stacks provided', function() {
+      c.reopen({content: {stacks: null}});
+      expect(c.checkHostOSType()).to.equal('');
+    });
+    it('os type is valid', function() {
+      var osType = 'os1';
+      c.reopen({
+        content: {
+          stacks: [
+            Em.Object.create({isSelected: true, operatingSystems: [{selected: 
true, osType: osType}]})
+          ]
+        }
+      });
+      expect(c.checkHostOSType(osType, '')).to.equal('');
+    });
+    it('os type is invalid', function() {
+      var osType = 'os2';
+      c.reopen({
+        content: {
+          stacks: [
+            Em.Object.create({isSelected: true, operatingSystems: [{selected: 
true, osType: 'os1'}]})
+          ]
+        }
+      });
+      expect(Em.isEmpty(c.checkHostOSType(osType, ''))).to.equal(false);
+    });
+  });
+
+  describe('#getHostInfoSuccessCallback', function() {
+
+    beforeEach(function() {
+      sinon.stub(c, 'parseWarnings', Em.K);
+      sinon.stub(c, 'stopRegistration', Em.K);
+    });
+
+    afterEach(function() {
+      c.parseWarnings.restore();
+      c.stopRegistration.restore();
+    });
+
+    it('should call _setHostDataWithSkipBootstrap if skipBootstrap is true', 
function() {
+      sinon.spy(c, '_setHostDataWithSkipBootstrap');
+      sinon.stub(App, 'get', function(k) {
+        if ('skipBootstrap' === k) return true;
+        return Em.get(App, k);
+      });
+      c.reopen({
+        bootHosts: [Em.Object.create({name: 'h1'})]
+      });
+      var jsonData = {items: [{Hosts: {host_name: 'h1'}}]};
+      c.getHostInfoSuccessCallback(jsonData);
+      expect(c._setHostDataWithSkipBootstrap.calledOnce).to.equal(true);
+      App.get.restore();
+      c._setHostDataWithSkipBootstrap.restore();
+    });
+
+    it('should add repo warnings', function() {
+
+      var jsonData = {items: [{Hosts: {host_name: 'h1'}}]};
+
+      sinon.stub(c, 'checkHostOSType', function() {return 'not_null_value';});
+      sinon.stub(c, 'checkHostDiskSpace', Em.K);
+      sinon.stub(c, '_setHostDataFromLoadedHostInfo', Em.K);
+
+      sinon.stub(App, 'get', function(k) {
+        if ('skipBootstrap' === k) return false;
+        return Em.get(App, k);
+      });
+
+      c.reopen({
+        bootHosts: [Em.Object.create({name: 'h1'})]
+      });
+
+      c.getHostInfoSuccessCallback(jsonData);
+      expect(c.get('repoCategoryWarnings.length')).to.equal(1);
+      
expect(c.get('repoCategoryWarnings.firstObject.hostsNames').contains('h1')).to.equal(true);
+
+      c.checkHostOSType.restore();
+      c.checkHostDiskSpace.restore();
+      c._setHostDataFromLoadedHostInfo.restore();
+      App.get.restore();
+    });
+
+    it('should add disk warnings', function() {
+
+      var jsonData = {items: [{Hosts: {host_name: 'h1'}}]};
+
+      sinon.stub(c, 'checkHostDiskSpace', function() {return 
'not_null_value';});
+      sinon.stub(c, 'checkHostOSType', Em.K);
+      sinon.stub(c, '_setHostDataFromLoadedHostInfo', Em.K);
+
+      sinon.stub(App, 'get', function(k) {
+        if ('skipBootstrap' === k) return false;
+        return Em.get(App, k);
+      });
+
+      c.reopen({
+        bootHosts: [Em.Object.create({name: 'h1'})]
+      });
+
+      c.getHostInfoSuccessCallback(jsonData);
+      expect(c.get('diskCategoryWarnings.length')).to.equal(1);
+      
expect(c.get('diskCategoryWarnings.firstObject.hostsNames').contains('h1')).to.equal(true);
+
+      c.checkHostOSType.restore();
+      c.checkHostDiskSpace.restore();
+      c._setHostDataFromLoadedHostInfo.restore();
+      App.get.restore();
+    });
+
+  });
+
+  describe('#_setHostDataWithSkipBootstrap', function() {
+    it('should set mock-data', function() {
+      var host = Em.Object.create({});
+      c._setHostDataWithSkipBootstrap(host);
+      expect(host.get('cpu')).to.equal(2);
+      expect(host.get('memory')).to.equal('2000000.00');
+      expect(host.get('disk_info.length')).to.equal(4);
+    });
+  });
+
+  describe('#_setHostDataFromLoadedHostInfo', function() {
+    it('should set data from hostInfo', function() {
+      var host = Em.Object.create(),
+        hostInfo = {
+          Hosts: {
+            cpu_count: 2,
+            total_mem: 12345,
+            os_type: 't1',
+            os_arch: 'os1',
+            ip: '0.0.0.0',
+            disk_info: [
+              {mountpoint: '/boot'},
+              {mountpoint: '/usr'},
+              {mountpoint: '/no-boot'},
+              {mountpoint: '/boot'}
+            ]
+          }
+        };
+      c._setHostDataFromLoadedHostInfo(host, hostInfo);
+      expect(host.get('cpu')).to.equal(2);
+      expect(host.get('os_type')).to.equal('t1');
+      expect(host.get('os_arch')).to.equal('os1');
+      expect(host.get('ip')).to.equal('0.0.0.0');
+      expect(host.get('memory')).to.equal('12345.00');
+      expect(host.get('disk_info.length')).to.equal(2);
+    });
+  });
+
 });
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/7e395b9b/ambari-web/test/views/wizard/step3_view_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/wizard/step3_view_test.js 
b/ambari-web/test/views/wizard/step3_view_test.js
index e5fb996..9b74535 100644
--- a/ambari-web/test/views/wizard/step3_view_test.js
+++ b/ambari-web/test/views/wizard/step3_view_test.js
@@ -21,9 +21,7 @@ require('messages');
 require('views/wizard/step3_view');
 var v;
 describe('App.WizardStep3View', function () {
-  Em.run.next = function(callback){
-    callback()
-  };
+
   var view = App.WizardStep3View.create({
     monitorStatuses: function () {
     },
@@ -253,17 +251,19 @@ describe('App.WizardStep3View', function () {
     }, this);
   });
 
-  describe('#filter', function () {
+  describe('#doFilter', function () {
     testCases.forEach(function (test) {
       describe(test.title, function () {
         view.get('categories').forEach(function (category) {
           it('. Selected category - ' + category.get('hostsBootStatus'), 
function () {
             view.set('content', test.content);
-            view.selectCategory({context: category});
-            view.filter();
+            view.reopen({
+              selectedCategory: category
+            });
+            view.doFilter();
             
expect(view.get('filteredContent').length).to.equal(test.result[category.get('hostsBootStatus')])
           });
-        })
+        });
       });
     }, this);
   });

http://git-wip-us.apache.org/repos/asf/ambari/blob/7e395b9b/ambari-web/test/views/wizard/step9_view_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/wizard/step9_view_test.js 
b/ambari-web/test/views/wizard/step9_view_test.js
index 733c3f9..be527bd 100644
--- a/ambari-web/test/views/wizard/step9_view_test.js
+++ b/ambari-web/test/views/wizard/step9_view_test.js
@@ -204,14 +204,14 @@ describe('App.WizardStep9View', function () {
     }, this);
   });
 
-  describe('#filter', function () {
+  describe('#doFilter', function () {
     testCases.forEach(function (test) {
       describe(test.title, function () {
         view.get('categories').forEach(function (category) {
           it('. Selected category - ' + category.get('hostStatus'), function 
() {
             view.set('content', test.content);
-            view.selectCategory({context: category});
-            view.filter();
+            view.reopen({selectedCategory: category});
+            view.doFilter();
             
expect(view.get('filteredContent').length).to.equal(test.result[category.get('hostStatus')])
           });
         })

Reply via email to