ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akovale...@apache.org
Subject [1/4] git commit: AMBARI-5820. Add unit tests for mixins. (Max Shepel via akovalenko)
Date Tue, 20 May 2014 12:21:34 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 07193440d -> 82ffda436


AMBARI-5820. Add unit tests for mixins. (Max Shepel via akovalenko)


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

Branch: refs/heads/trunk
Commit: de9097218a6bdb9509bfe2f25c2436cb99b03def
Parents: 0719344
Author: Aleksandr Kovalenko <akovalenko@hortonworks.com>
Authored: Tue May 20 15:01:56 2014 +0300
Committer: Aleksandr Kovalenko <akovalenko@hortonworks.com>
Committed: Tue May 20 15:01:56 2014 +0300

----------------------------------------------------------------------
 ambari-web/app/assets/test/tests.js             |   3 +
 .../common/chart/storm_linear_time_test.js      |  77 +++++++++++
 .../test/mixins/common/localStorage_test.js     |  77 +++++++++++
 .../host_components/decommissionable_test.js    | 131 +++++++++++++++++++
 4 files changed, 288 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/de909721/ambari-web/app/assets/test/tests.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/assets/test/tests.js b/ambari-web/app/assets/test/tests.js
index ec8650e..d820fcd 100644
--- a/ambari-web/app/assets/test/tests.js
+++ b/ambari-web/app/assets/test/tests.js
@@ -97,6 +97,9 @@ require('test/mappers/runs_mapper_test');
 require('test/mappers/service_mapper_test');
 require('test/mappers/status_mapper_test');
 require('test/mappers/users_mapper_test');
+require('test/mixins/common/chart/storm_linear_time_test');
+require('test/mixins/common/localStorage_test');
+require('test/mixins/main/host/details/host_components/decommissionable_test');
 require('test/utils/configs/defaults_providers/yarn_defaults_provider_test');
 require('test/utils/configs/defaults_providers/tez_defaults_provider_test');
 require('test/utils/configs/defaults_providers/hive_defaults_provider_test');

http://git-wip-us.apache.org/repos/asf/ambari/blob/de909721/ambari-web/test/mixins/common/chart/storm_linear_time_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/mixins/common/chart/storm_linear_time_test.js b/ambari-web/test/mixins/common/chart/storm_linear_time_test.js
new file mode 100644
index 0000000..b9bc19b
--- /dev/null
+++ b/ambari-web/test/mixins/common/chart/storm_linear_time_test.js
@@ -0,0 +1,77 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var App = require('app');
+
+require('mixins/common/chart/storm_linear_time');
+
+var slt,
+  template,
+  series,
+  jsonDataFalse = {
+    metrics: {
+      id: 'metrics'
+    }
+  },
+  jsonDataTrue = {
+    metrics: {
+      storm: {
+        nimbus: {
+          name: 'nimbus'
+        }
+      }
+    }
+  };
+
+describe('App.StormLinearTimeChartMixin', function () {
+
+  beforeEach(function () {
+    slt = Em.Object.create(App.StormLinearTimeChartMixin, {
+      stormChartDefinition: [
+        {
+          field: 'name',
+          name: 'nimbus'
+        }
+      ]
+    });
+  });
+
+  describe('#getDataForAjaxRequest', function () {
+    it('should take data from stormChartDefinition', function () {
+      template = slt.getDataForAjaxRequest().metricsTemplate;
+      expect(template).to.contain('metrics');
+      expect(template).to.contain('storm');
+      expect(template).to.contain('nimbus');
+    });
+  });
+
+  describe('#transformToSeries', function () {
+    it('should be empty', function () {
+      expect(slt.transformToSeries(jsonDataFalse)).to.be.empty;
+    });
+    it('should take one element from data', function () {
+      slt.set('transformData', function (data, name) {
+        return name + ': ' + JSON.stringify(data);
+      });
+      series = slt.transformToSeries(jsonDataTrue);
+      expect(series).to.have.length(1);
+      expect(series[0]).to.equal('nimbus: "nimbus"');
+    });
+  });
+
+});

http://git-wip-us.apache.org/repos/asf/ambari/blob/de909721/ambari-web/test/mixins/common/localStorage_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/mixins/common/localStorage_test.js b/ambari-web/test/mixins/common/localStorage_test.js
new file mode 100644
index 0000000..e96f1fb
--- /dev/null
+++ b/ambari-web/test/mixins/common/localStorage_test.js
@@ -0,0 +1,77 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var App = require('app');
+
+require('mixins/common/localStorage');
+
+var localStorage,
+  nameCases = [
+    {
+      toSet: {
+        name: 'name'
+      },
+      toExpect: 'Name'
+    },
+    {
+      toSet: {
+        name: null,
+        controller: {
+          name: 'samplecontroller'
+        }
+      },
+      toExpect: 'Samplecontroller'
+    },
+    {
+      toSet: {
+        controller: {
+          name: 'sampleController'
+        }
+      },
+      toExpect: 'Sample'
+    }
+  ];
+
+describe('App.LocalStorage', function () {
+
+  beforeEach(function () {
+    localStorage = Em.Object.create(App.LocalStorage);
+  });
+
+  after(function () {
+    App.db.cleanUp();
+  });
+
+  describe('#dbNamespace', function () {
+    nameCases.forEach(function (item) {
+      it('should be ' + item.toExpect, function () {
+        localStorage.setProperties(item.toSet);
+        expect(localStorage.get('dbNamespace')).to.equal(item.toExpect)
+      });
+    });
+  });
+
+  describe('#getDBProperty', function () {
+    it('should take value from DB', function () {
+      localStorage.set('name', 'name');
+      localStorage.setDBProperty('key', 'value');
+      expect(localStorage.getDBProperty('key')).to.equal('value');
+    });
+  });
+
+});

http://git-wip-us.apache.org/repos/asf/ambari/blob/de909721/ambari-web/test/mixins/main/host/details/host_components/decommissionable_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/mixins/main/host/details/host_components/decommissionable_test.js
b/ambari-web/test/mixins/main/host/details/host_components/decommissionable_test.js
new file mode 100644
index 0000000..c175dad
--- /dev/null
+++ b/ambari-web/test/mixins/main/host/details/host_components/decommissionable_test.js
@@ -0,0 +1,131 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var App = require('app');
+
+require('mixins/main/host/details/host_components/decommissionable');
+
+var decommissionable,
+  view,
+  statusCases = [
+    {
+      status: App.HostComponentStatus.started,
+      expected: false
+    },
+    {
+      status: 'status',
+      expected: true
+    }
+  ],
+  responseCases = [
+    {
+      HostRoles: {
+        desired_admin_state: 'state'
+      },
+      ServiceComponentInfo: 'info'
+    },
+    {
+      HostRoles: {
+        desired_admin_state: null
+      },
+      ServiceComponentInfo: null
+    }
+  ],
+  textCases = [
+    {
+      available: true,
+      text: Em.I18n.t('common.decommission')
+    },
+    {
+      available: false,
+      text: Em.I18n.t('common.recommission')
+    }
+  ];
+
+describe('App.Decommissionable', function () {
+
+  beforeEach(function () {
+    decommissionable = Em.Object.create(App.Decommissionable);
+  });
+
+  describe('#isComponentDecommissionDisable', function () {
+    statusCases.forEach(function (item) {
+      it('should be ' + item.expected, function () {
+        decommissionable.set('content', {
+          service: {
+            workStatus: item.status
+          }
+        });
+        expect(decommissionable.get('isComponentDecommissionDisable')).to.equal(item.expected);
+      });
+    });
+  });
+
+  describe('#getDesiredAdminStateSuccessCallback', function () {
+    responseCases.forEach(function (item) {
+      var state = item.HostRoles.desired_admin_state;
+      it('should return ' + state, function () {
+        decommissionable.getDesiredAdminStateSuccessCallback(item);
+        expect(decommissionable.get('desiredAdminState')).to.equal(state);
+      });
+    });
+  });
+
+  describe('#getDesiredAdminStateErrorCallback', function () {
+    it('should return null', function () {
+      decommissionable.getDesiredAdminStateErrorCallback();
+      expect(decommissionable.get('desiredAdminState')).to.be.a('null');
+    });
+  });
+
+  describe('#getDecommissionStatusSuccessCallback', function () {
+    responseCases.forEach(function (item) {
+      var state = item.ServiceComponentInfo;
+      it('should return ' + state, function () {
+        decommissionable.getDecommissionStatusSuccessCallback(item);
+        expect(decommissionable.get('decommissionedStatusObject')).to.equal(state);
+      });
+    });
+  });
+
+  describe('#getDecommissionStatusErrorCallback', function () {
+    it('should return null', function () {
+      decommissionable.getDecommissionStatusErrorCallback();
+      expect(decommissionable.get('decommissionedStatusObject')).to.be.a('null');
+    });
+  });
+
+  describe('#decommissionView.text', function () {
+
+    beforeEach(function () {
+      view = decommissionable.decommissionView.create();
+      view.reopen({
+        parentView: decommissionable
+      });
+    });
+
+    textCases.forEach(function (item) {
+      it('should be ' + item.text, function () {
+        view.set('parentView.isComponentDecommissionAvailable', item.available);
+        expect(view.get('text')).to.equal(item.text);
+      });
+    });
+
+  });
+
+});


Mime
View raw message