Author: yusaku
Date: Thu Apr 18 23:39:55 2013
New Revision: 1469636
URL: http://svn.apache.org/r1469636
Log:
AMBARI-1987. Add unit tests for admin/cluster page and cluster loading. (yusaku)
Added:
incubator/ambari/trunk/ambari-web/test/controllers/global/cluster_controller_test.js
incubator/ambari/trunk/ambari-web/test/controllers/main/admin/
incubator/ambari/trunk/ambari-web/test/controllers/main/admin/cluster_test.js
Modified:
incubator/ambari/trunk/CHANGES.txt
incubator/ambari/trunk/ambari-web/app/assets/test/tests.js
incubator/ambari/trunk/ambari-web/app/controllers/global/cluster_controller.js
incubator/ambari/trunk/ambari-web/test/utils/validator_test.js
Modified: incubator/ambari/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1469636&r1=1469635&r2=1469636&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Thu Apr 18 23:39:55 2013
@@ -269,6 +269,9 @@ Trunk (unreleased changes):
IMPROVEMENTS
+ AMBARI-1987. Add unit tests for admin/cluster page and cluster loading.
+ (yusaku)
+
AMBARI-1929. Make the default stack and version configurable via mvn build.
(yusaku)
Modified: incubator/ambari/trunk/ambari-web/app/assets/test/tests.js
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/app/assets/test/tests.js?rev=1469636&r1=1469635&r2=1469636&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-web/app/assets/test/tests.js (original)
+++ incubator/ambari/trunk/ambari-web/app/assets/test/tests.js Thu Apr 18
23:39:55 2013
@@ -18,8 +18,10 @@
require('test/utils/ajax_test');
require('test/controllers/global/background_operations_test');
+require('test/controllers/global/cluster_controller_test');
require('test/controllers/main/app_contoller_test');
require('test/controllers/main/charts/heatmap_metrics/heatmap_metric_test');
+require('test/controllers/main/admin/cluster_test');
require('test/installer/step1_test');
require('test/installer/step2_test');
require('test/installer/step3_test');
Modified:
incubator/ambari/trunk/ambari-web/app/controllers/global/cluster_controller.js
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/app/controllers/global/cluster_controller.js?rev=1469636&r1=1469635&r2=1469636&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-web/app/controllers/global/cluster_controller.js
(original)
+++
incubator/ambari/trunk/ambari-web/app/controllers/global/cluster_controller.js
Thu Apr 18 23:39:55 2013
@@ -30,11 +30,15 @@ App.ClusterController = Em.Controller.ex
updateLoadStatus:function (item) {
var loadList = this.get('dataLoadList');
var loaded = true;
- var numLoaded= 0;
+ var numLoaded = 0;
+ var loadListLength = 0;
loadList.set(item, true);
for (var i in loadList) {
- if (loadList.hasOwnProperty(i) && !loadList[i] && loaded) {
- loaded = false;
+ if (loadList.hasOwnProperty(i)) {
+ loadListLength++;
+ if(!loadList[i] && loaded){
+ loaded = false;
+ }
}
// calculate the number of true
if (loadList.hasOwnProperty(i) && loadList[i]){
@@ -42,7 +46,7 @@ App.ClusterController = Em.Controller.ex
}
}
this.set('isLoaded', loaded);
- this.set('clusterDataLoadedPercent', 'width:' +
(Math.floor(numLoaded/8*100)).toString() + '%');
+ this.set('clusterDataLoadedPercent', 'width:' + (Math.floor(numLoaded /
loadListLength * 100)).toString() + '%');
},
dataLoadList:Em.Object.create({
Added:
incubator/ambari/trunk/ambari-web/test/controllers/global/cluster_controller_test.js
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/test/controllers/global/cluster_controller_test.js?rev=1469636&view=auto
==============================================================================
---
incubator/ambari/trunk/ambari-web/test/controllers/global/cluster_controller_test.js
(added)
+++
incubator/ambari/trunk/ambari-web/test/controllers/global/cluster_controller_test.js
Thu Apr 18 23:39:55 2013
@@ -0,0 +1,50 @@
+/**
+ * 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('controllers/global/cluster_controller');
+require('utils/http_client');
+
+describe('App.clusterController', function () {
+
+ /**
+ * Test object
+ */
+ var controller = App.ClusterController.create();
+ describe('#updateLoadStatus()', function () {
+ it('all items are loaded', function(){
+ controller.set('dataLoadList', Em.Object.create({
+ 'item1':true,
+ 'item2':false
+ }));
+ controller.updateLoadStatus.call(controller, 'item2');
+ expect(controller.get('isLoaded')).to.equal(true);
+
expect(controller.get('clusterDataLoadedPercent')).to.equal('width:100%');
+ })
+ it('one item of two is loaded', function(){
+ controller.set('dataLoadList', Em.Object.create({
+ 'item1':false,
+ 'item2':false
+ }));
+ controller.updateLoadStatus.call(controller, 'item1');
+ expect(controller.get('isLoaded')).to.equal(false);
+ expect(controller.get('clusterDataLoadedPercent')).to.equal('width:50%');
+ })
+ })
+})
Added:
incubator/ambari/trunk/ambari-web/test/controllers/main/admin/cluster_test.js
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/test/controllers/main/admin/cluster_test.js?rev=1469636&view=auto
==============================================================================
---
incubator/ambari/trunk/ambari-web/test/controllers/main/admin/cluster_test.js
(added)
+++
incubator/ambari/trunk/ambari-web/test/controllers/main/admin/cluster_test.js
Thu Apr 18 23:39:55 2013
@@ -0,0 +1,72 @@
+/**
+ * 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('controllers/main/admin/cluster');
+
+
+describe('App.MainAdminClusterController', function () {
+
+ /**
+ * Predefined data
+ *
+ */
+ App.set('currentStackVersion', 'HDP-1.2.2');
+ App.set('defaultStackVersion', 'HDP-1.2.2');
+ /**
+ * Test object
+ */
+ var controller = App.MainAdminClusterController.create({
+ parseServicesInfo:function(){}
+ });
+ var data = {
+ "items" : [
+ {
+ "Versions" : {
+ "stack_version" : "1.3.0",
+ "min_upgrade_version" : "1.2.0"
+ }
+ },
+ {
+ "Versions" : {
+ "stack_version" : "1.2.2",
+ "min_upgrade_version" : "1.2.0"
+ }
+ },
+ {
+ "Versions" : {
+ "stack_version" : "1.2.0",
+ "min_upgrade_version" : "1.2.0"
+ }
+ }
+ ]
+ };
+
+ describe('#updateUpgradeVersionSuccessCallback()', function () {
+ it('upgrade version of stack should be "HDP-1.3.0"', function(){
+ controller.updateUpgradeVersionSuccessCallback.call(controller, data);
+ expect(controller.get('upgradeVersion')).to.equal('HDP-1.3.0');
+ })
+ it('if min upgrade version less then current then upgrade version equal
current', function(){
+ data.items[0].Versions.min_upgrade_version = "1.2.3";
+ controller.updateUpgradeVersionSuccessCallback.call(controller, data);
+ expect(controller.get('upgradeVersion')).to.equal('HDP-1.2.2');
+ })
+ })
+})
Modified: incubator/ambari/trunk/ambari-web/test/utils/validator_test.js
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/test/utils/validator_test.js?rev=1469636&r1=1469635&r2=1469636&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-web/test/utils/validator_test.js (original)
+++ incubator/ambari/trunk/ambari-web/test/utils/validator_test.js Thu Apr 18
23:39:55 2013
@@ -197,7 +197,7 @@ describe('validator', function () {
it('"55454" - invalid Domain Name', function () {
expect(validator.isDomainName('55454')).to.equal(false);
})
- }),
+ })
describe('#isValidUserName(value)', function() {
var tests = [
{m:'"" - invalid',i:'',e:false},
@@ -216,5 +216,42 @@ describe('validator', function () {
})
});
})
+ describe('#isValidUNIXUser(value)', function() {
+ var tests = [
+ {m:'"" - invalid',i:'',e:false},
+ {m:'"abc123" - valid',i:'abc123',e:true},
+ {m:'"1abc123" - invalid',i:'1abc123',e:false},
+ {m:'"abc123$" - invalid',i:'abc123$',e:false},
+ {m:'"~1abc123" - invalid',i: '~1abc123',e:false},
+ {m:'"abc12345679abc1234567890abc1234567890$" -
invalid',i:'abc12345679abc1234567890abc1234567890$',e:false},
+ {m:'"1abc123$$" - invalid',i:'1abc123$$',e:false},
+ {m:'"a" - valid',i:'a',e:true},
+ {m:'"!" - invalid',i:'!',e:false},
+ {m:'"abc_" - valid',i:'abc_',e:true},
+ {m:'"_abc" - valid',i:'_abc',e:true},
+ {m:'"abc_abc" - valid',i:'_abc',e:true}
+ ];
+ tests.forEach(function(test) {
+ it(test.m + ' ', function () {
+ expect(validator.isValidUNIXUser(test.i)).to.equal(test.e);
+ })
+ });
+ })
+ describe('#isValidDir(value)', function() {
+ var tests = [
+ {m:'"dir" - invalid',i:'dir',e:false},
+ {m:'"/dir" - valid',i:'/dir',e:true},
+ {m:'"/dir1,dir2" - invalid',i:'/dir1,dir2',e:false},
+ {m:'"/dir1,/dir2" - valid',i:'/dir1,/dir2',e:true},
+ {m:'"/123" - valid',i:'/111',e:true},
+ {m:'"/abc" - valid',i:'/abc',e:true},
+ {m:'"/1a2b3c" - valid',i:'/1a2b3c',e:true}
+ ];
+ tests.forEach(function(test) {
+ it(test.m + ' ', function () {
+ expect(validator.isValidDir(test.i)).to.equal(test.e);
+ })
+ });
+ })
})
\ No newline at end of file