incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From srima...@apache.org
Subject svn commit: r1466260 - in /incubator/ambari/trunk: ./ ambari-web/ ambari-web/app/ ambari-web/app/assets/test/ ambari-web/app/controllers/global/ ambari-web/test/ ambari-web/test/controllers/global/ ambari-web/test/utils/
Date Tue, 09 Apr 2013 21:59:21 GMT
Author: srimanth
Date: Tue Apr  9 21:59:21 2013
New Revision: 1466260

URL: http://svn.apache.org/r1466260
Log:
AMBARI-1850. Update unit tests. (srimanth)

Added:
    incubator/ambari/trunk/ambari-web/app/assets/test/
    incubator/ambari/trunk/ambari-web/app/assets/test/test.html
    incubator/ambari/trunk/ambari-web/app/assets/test/tests.js
Removed:
    incubator/ambari/trunk/ambari-web/test/test-helpers.coffee
Modified:
    incubator/ambari/trunk/CHANGES.txt
    incubator/ambari/trunk/ambari-web/app/config.js
    incubator/ambari/trunk/ambari-web/app/controllers/global/background_operations_controller.js
    incubator/ambari/trunk/ambari-web/config.coffee
    incubator/ambari/trunk/ambari-web/package.json
    incubator/ambari/trunk/ambari-web/test/controllers/global/background_operations_test.js
    incubator/ambari/trunk/ambari-web/test/utils/ajax_test.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=1466260&r1=1466259&r2=1466260&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Tue Apr  9 21:59:21 2013
@@ -11,6 +11,8 @@ Trunk (unreleased changes):
  INCOMPATIBLE CHANGES 
 
  NEW FEATURES
+ 
+ AMBARI-1850. Update unit tests. (srimanth)
 
  AMBARI-1829. HDFS Mirroring: Display Status and handle maintenance operations 
  like Stop, Suspend, Activate etc. (Arun Kandregula via srimanth)

Added: incubator/ambari/trunk/ambari-web/app/assets/test/test.html
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/app/assets/test/test.html?rev=1466260&view=auto
==============================================================================
--- incubator/ambari/trunk/ambari-web/app/assets/test/test.html (added)
+++ incubator/ambari/trunk/ambari-web/app/assets/test/test.html Tue Apr  9 21:59:21 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.
+-->
+
+<html>
+<head>
+    <meta charset="utf-8">
+    <script src="../javascripts/vendor.js"></script>
+    <script src="../javascripts/app.js"></script>
+    <link rel="stylesheet" href="../../node_modules/mocha/mocha.css" />
+</head>
+<body>
+<div id="mocha"></div>
+<div id="wrapper">
+    <!-- ApplicationView -->
+</div>
+<script src="../../node_modules/mocha/mocha.js"></script>
+<script src="../../node_modules/chai/chai.js"></script>
+<script src="../../node_modules/sinon/lib/sinon.js"></script>
+<script src="../../node_modules/sinon/lib/sinon/spy.js"></script>
+<script src="../../node_modules/sinon/lib/sinon/stub.js"></script>
+<script>
+    $.mocho = true;
+    $.hostName = 'localhost:3333';
+    mocha.ui('bdd');
+    mocha.reporter('html');
+    expect = chai.expect;
+</script>
+<script src="./javascripts/test.js"></script>
+<script src="./tests.js"></script>
+<script>
+    if (window.mochaPhantomJS) { mochaPhantomJS.run(); }
+    else { mocha.run(); }
+</script>
+</body>
+</html>
\ No newline at end of file

Added: 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=1466260&view=auto
==============================================================================
--- incubator/ambari/trunk/ambari-web/app/assets/test/tests.js (added)
+++ incubator/ambari/trunk/ambari-web/app/assets/test/tests.js Tue Apr  9 21:59:21 2013
@@ -0,0 +1,40 @@
+/**
+ * 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.
+ */
+
+require('test/utils/ajax_test');
+require('test/controllers/global/background_operations_test');
+require('test/controllers/main/app_contoller_test');
+require('test/controllers/main/charts/heatmap_metrics/heatmap_metric_test');
+require('test/installer/step1_test');
+require('test/installer/step2_test');
+require('test/installer/step3_test');
+require('test/installer/step4_test');
+require('test/installer/step5_test');
+require('test/installer/step6_test');
+require('test/installer/step7_test');
+require('test/installer/step9_test');
+require('test/login_test');
+require('test/main/app/app_contoller_test');
+require('test/main/dashboard_test');
+require('test/main/host/details_test');
+require('test/main/host_test');
+require('test/main/item_test');
+require('test/utils/form_field_test');
+require('test/utils/misc_test');
+require('test/utils/validator_test');
+require('test/views/common/chart/linear_time_test');
\ No newline at end of file

Modified: incubator/ambari/trunk/ambari-web/app/config.js
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/app/config.js?rev=1466260&r1=1466259&r2=1466260&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-web/app/config.js (original)
+++ incubator/ambari/trunk/ambari-web/app/config.js Tue Apr  9 21:59:21 2013
@@ -19,6 +19,9 @@
 var App = require('app');
 
 App.testMode = false;
+if(location.port == '3333'){
+  App.testMode = true;
+}
 App.testModeDelayForActions = 10000;
 App.skipBootstrap = false;
 App.alwaysGoToInstaller = false;

Modified: incubator/ambari/trunk/ambari-web/app/controllers/global/background_operations_controller.js
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/app/controllers/global/background_operations_controller.js?rev=1466260&r1=1466259&r2=1466260&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-web/app/controllers/global/background_operations_controller.js
(original)
+++ incubator/ambari/trunk/ambari-web/app/controllers/global/background_operations_controller.js
Tue Apr  9 21:59:21 2013
@@ -109,12 +109,10 @@ App.BackgroundOperationsController = Em.
    * @return PopupObject For testing purposes
    */
   showPopup: function(){
-    if(App.testMode){
-      App.HostPopup.initPopup("", this, true);
-    }else{
+    if(!App.testMode){
       App.updater.immediateRun('requestMostRecent');
-      App.HostPopup.initPopup("", this, true);
     }
+    return App.HostPopup.initPopup("", this, true);
   }
 
 });

Modified: incubator/ambari/trunk/ambari-web/config.coffee
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/config.coffee?rev=1466260&r1=1466259&r2=1466260&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-web/config.coffee (original)
+++ incubator/ambari/trunk/ambari-web/config.coffee Tue Apr  9 21:59:21 2013
@@ -55,8 +55,7 @@ exports.config =
           'vendor/scripts/workflow_visualization.js',
           'vendor/scripts/rickshaw.js',
           'vendor/scripts/spin.js',
-          'vendor/scripts/jquery.flexibleArea.js',
-          'test/utils/ajax_test.js'
+          'vendor/scripts/jquery.flexibleArea.js'
           ]
 
     stylesheets:

Modified: incubator/ambari/trunk/ambari-web/package.json
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/package.json?rev=1466260&r1=1466259&r2=1466260&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-web/package.json (original)
+++ incubator/ambari/trunk/ambari-web/package.json Tue Apr  9 21:59:21 2013
@@ -22,11 +22,11 @@
     "less-brunch":">= 1.0 < 1.5"
   },
   "devDependencies":{
-    "mocha":"0.14.0",
-    "chai":"1.2.0",
-    "sinon":"1.4.2",
-    "sinon-chai":"2.1.2",
+    "mocha":"*",
+    "chai":"*",
+    "sinon":"*",
+    "sinon-chai":"*",
     "express":"2.5.8",
-    "xmlhttprequest":"1.5.0"
+    "mocha-phantomjs": "*"
   }
 }

Modified: incubator/ambari/trunk/ambari-web/test/controllers/global/background_operations_test.js
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/test/controllers/global/background_operations_test.js?rev=1466260&r1=1466259&r2=1466260&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-web/test/controllers/global/background_operations_test.js
(original)
+++ incubator/ambari/trunk/ambari-web/test/controllers/global/background_operations_test.js
Tue Apr  9 21:59:21 2013
@@ -25,6 +25,7 @@ require('utils/ajax');
 
 require('controllers/global/background_operations_controller');
 require('views/common/modal_popup');
+require('utils/host_progress_popup');
 
 /*window.console.log = function(text){
   console.log(text);
@@ -45,43 +46,6 @@ describe('App.BackgroundOperationsContro
    */
   var controller = App.BackgroundOperationsController.create();
 
-  describe('#getOperationsForRequestId', function(){
-
-    var obj = new window.Array({"exit_code":0,"stdout":"Output","status":"COMPLETED","stderr":"none","host_name":"dev.hortonworks.com","id":10,"cluster_name":"mycluster","attempt_cnt":1,"request_id":2,"command":"EXECUTE","role":"HDFS_SERVICE_CHECK","start_time":1352119106480,"stage_id":2,"display_exit_code":true},{"exit_code":0,"stdout":"Output","status":"COMPLETED","stderr":"none","host_name":"dev.hortonworks.com","id":14,"cluster_name":"mycluster","attempt_cnt":1,"request_id":2,"command":"EXECUTE","role":"MAPREDUCE_SERVICE_CHECK","start_time":1352119157294,"stage_id":3,"display_exit_code":true},{"exit_code":0,"stdout":"Output","status":"QUEUED","stderr":"none","host_name":"dev.hortonworks.com","id":16,"cluster_name":"mycluster","attempt_cnt":1,"request_id":3,"command":"STOP","role":"NAMENODE","start_time":1352125378300,"stage_id":1,"display_exit_code":true});
-    var controller = App.BackgroundOperationsController.create();
-
-
-    it('test 1 with 3 items  ', function(){
-
-      controller.set('allOperations', obj);
-      expect(controller.getOperationsForRequestId(1).length).to.be.equal(0);
-      expect(controller.getOperationsForRequestId(2).length).to.be.equal(2);
-      expect(controller.getOperationsForRequestId(3).length).to.be.equal(1);
-
-    });
-
-
-
-    it('test 2 with 0 items  ', function(){
-
-      controller.set('allOperations', new window.Array());
-      expect(controller.getOperationsForRequestId(1).length).to.be.equal(0);
-      expect(controller.getOperationsForRequestId(2).length).to.be.equal(0);
-      expect(controller.getOperationsForRequestId(3).length).to.be.equal(0);
-
-    });
-
-    it('test 3 with 9 items  ', function(){
-
-      controller.set('allOperations', obj.concat(obj, obj));
-      expect(controller.getOperationsForRequestId(1).length).to.be.equal(0);
-      expect(controller.getOperationsForRequestId(2).length).to.be.equal(6);
-      expect(controller.getOperationsForRequestId(3).length).to.be.equal(3);
-
-    });
-
-  });
-
   describe('when set isWorking to true  ', function () {
 
     it('startPolling executes App.updater.run  ', function(done){
@@ -94,31 +58,31 @@ describe('App.BackgroundOperationsContro
       controller.set('isWorking', true);
     });
 
-    it('loadOperations should be called  ', function(done){
+    it('requestMostRecent should be called  ', function(done){
       this.timeout(App.bgOperationsUpdateInterval + 500);
 
-      sinon.stub(controller, 'loadOperations', function(){
+      sinon.stub(controller, 'requestMostRecent', function(){
         controller.set('isWorking', false);
-        controller.loadOperations.restore();
+        controller.requestMostRecent.restore();
         done();
       });
 
       controller.set('isWorking', true);
     });
 
-    it('updateBackgroundOperations should be called  ', function(done){
-      this.timeout(App.bgOperationsUpdateInterval + 500);
+    it('callBackForMostRecent should be called  ', function(done){
+      this.timeout(App.bgOperationsUpdateInterval + 1500);
 
-      sinon.stub(controller, 'updateBackgroundOperations', function(){
+      sinon.stub(controller, 'callBackForMostRecent', function(){
         controller.set('isWorking', false);
-        controller.updateBackgroundOperations.restore();
+        controller.callBackForMostRecent.restore();
         done();
       });
 
       controller.set('isWorking', true);
     });
 
-    it('allOperations should be set  ', function(done){
+    /*it('allOperations should be set  ', function(done){
       this.timeout(App.bgOperationsUpdateInterval + 500);
 
       sinon.stub(controller, 'updateBackgroundOperations', function(data){
@@ -139,209 +103,15 @@ describe('App.BackgroundOperationsContro
       });
 
       controller.set('isWorking', true);
-    });
+    });*/
 
   })
 
-  describe('#showPopup', function () {
+  /*describe('#showPopup', function () {
     it('works without exceptions  ', function(){
       var popup = controller.showPopup();
       popup.onPrimary();
     });
-  });
-
-  function generateTask(time, role, status, id, command){
-    command = command || 'STOP';
-    return {
-      "Tasks" : {
-        "exit_code" : 0,
-        "stdout" : "Output",
-        "status" : status,
-        "stderr" : "none",
-        "host_name" : "dev.hortonworks.com",
-        "id" : id,
-        "cluster_name" : "mycluster",
-        "attempt_cnt" : 1,
-        "request_id" : 1,
-        "command" : command,
-        "role" : role,
-        "start_time" : time,
-        "stage_id" : 1
-      }
-    };
-  }
-
-  function generate_test_json(){
-
-    var time = new Date().getTime();
-
-    return {
-      items:[
-        {
-          "Requests" : {
-            "id" : 3,
-            "cluster_name" : "mycluster"
-          },
-          "tasks":[
-            generateTask(time, 'NAMENODE', 'QUEUED', 16),
-            generateTask(time, 'DATANODE', 'QUEUED', 15),
-            generateTask(time, 'SECONDARY_NAMENODE', 'QUEUED', 14),
-            generateTask(time, 'MAPREDUCE_SERVICE_CHECK', 'QUEUED', 13, 'EXECUTE')
-          ]
-        }
-      ]
-    };
-  }
-
-  function update_test_json(json, index, state){
-    var item = json.items[0].tasks[index].Tasks;
-    item.status = state;
-    item.finishedTime = new Date().getTime();
-  }
-
-  function add_to_test_json(json){
-    var tasks = json.items[0].tasks;
-    var item = tasks[0].Tasks;
-    tasks.push(generateTask(item.start_time, 'HBASE_MASTER', 'QUEUED', 12));
-    tasks.push(generateTask(item.start_time, 'ZOOKEEPER_SERVER', 'QUEUED', 11));
-  }
-
-  describe('#updateBackgroundOperations', function () {
-    describe('finished items are removed with delay  ', function(){
-      controller.set('allOperations', new window.Array());
-      controller.set('executeTasks', new window.Array());
-      controller.set('allOperationsCount', 0);
-
-      var json = generate_test_json();
-
-      it('on start we have 4 tasks  ', function(){
-        controller.updateBackgroundOperations(json);
-        expect(controller.get('allOperationsCount')).to.be.equal(4);
-        expect(controller.get('allOperations').length).to.be.equal(4);
-        expect(controller.get('executeTasks').length).to.be.equal(1);
-      })
-
-      it('first task is in progress  ', function(){
-        update_test_json(json, 2, 'IN_PROGRESS');
-        controller.updateBackgroundOperations(json);
-        expect(controller.get('allOperationsCount')).to.be.equal(4);
-        expect(controller.get('allOperations').length).to.be.equal(4);
-        expect(controller.get('executeTasks').length).to.be.equal(1);
-      });
-
-      it('first task finished  ', function(){
-        update_test_json(json, 2, 'COMPLETED');
-        controller.updateBackgroundOperations(json);
-        expect(controller.get('allOperationsCount')).to.be.equal(3);
-        expect(controller.get('allOperations').length).to.be.equal(3);
-        expect(controller.get('executeTasks').length).to.be.equal(1);
-      });
-
-      it('second task is in progress  ', function(){
-        update_test_json(json, 3, 'IN_PROGRESS');
-        controller.updateBackgroundOperations(json);
-        expect(controller.get('allOperationsCount')).to.be.equal(3);
-        expect(controller.get('allOperations').length).to.be.equal(3);
-        expect(controller.get('executeTasks').length).to.be.equal(1);
-      });
-
-      it('second task finished  ', function(){
-        update_test_json(json, 3, 'COMPLETED');
-        controller.updateBackgroundOperations(json);
-        expect(controller.get('allOperationsCount')).to.be.equal(2);
-        expect(controller.get('allOperations').length).to.be.equal(3);
-        expect(controller.get('executeTasks').length).to.be.equal(1);
-      });
-
-      var oldLifeTime = controller.get('taskLifeTime');
-      controller.set('taskLifeTime', 10);
-
-      it('second task removed from list  ', function(done){
-        setTimeout(function(){
-          controller.updateBackgroundOperations(json);
-          expect(controller.get('allOperationsCount')).to.be.equal(2);
-          expect(controller.get('allOperations').length).to.be.equal(2);
-          expect(controller.get('executeTasks').length).to.be.equal(0);
-
-          done();
-        }, controller.get('taskLifeTime'));
-      });
-
-      it('add new items  ', function(){
-        add_to_test_json(json);
-        controller.updateBackgroundOperations(json);
-        expect(controller.get('allOperationsCount')).to.be.equal(4);
-        expect(controller.get('allOperations').length).to.be.equal(4);
-        expect(controller.get('executeTasks').length).to.be.equal(0);
-        controller.set('taskLifeTime', oldLifeTime);
-      });
-    });
-  });
-
-  describe('#updateFinishedTask  ', function(){
-
-    var json = null;
-
-    beforeEach(function(){
-      controller.set('allOperations', new window.Array());
-      controller.set('executeTasks', new window.Array());
-      controller.set('allOperationsCount', 0);
-
-      json = generate_test_json();
-      controller.updateBackgroundOperations(json);
-    });
-
-    it('update task  ', function(){
-      update_test_json(json, 3, 'COMPLETED');
-      controller.updateFinishedTask(json.items[0].tasks[3]);
-
-      var item = controller.get('allOperations').findProperty('id', 13);
-      expect(item).to.be.an('object');
-      expect(item).to.have.property('status', 'COMPLETED');
-      expect(item.finishedTime).to.be.above(0);
-    })
-
-    it("don't update task  ", function(){
-      controller.updateFinishedTask({ Tasks: { id : 1 } });
-
-      var item = controller.get('allOperations').findProperty('id', 13);
-      expect(item).to.be.an('object');
-      expect(item).to.have.property('status', 'QUEUED');
-      expect(item.finishedTime).to.be.equal(undefined);
-    })
-
-  });
-
-  describe('#eventsArray  ', function(){
-
-    var json = null;
-
-    beforeEach(function(){
-      controller.set('allOperations', new window.Array());
-      controller.set('executeTasks', new window.Array());
-      controller.set('allOperationsCount', 0);
-
-      json = generate_test_json();
-      controller.updateBackgroundOperations(json);
-    });
-
-    it("it's working  ", function(done){
-      controller.get('eventsArray').push({
-        "when" : function(controller){
-          return controller.get('allOperationsCount') == 3;
-        },
-        "do" : done
-      });
-
-      controller.updateBackgroundOperations(json);
-      controller.updateBackgroundOperations(json);
-      controller.updateBackgroundOperations(json);
-      controller.updateBackgroundOperations(json);
-
-      update_test_json(json, 1, 'COMPLETED');
-      controller.updateBackgroundOperations(json);
-    })
-  });
-
+  });*/
 
 })

Modified: incubator/ambari/trunk/ambari-web/test/utils/ajax_test.js
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/test/utils/ajax_test.js?rev=1466260&r1=1466259&r2=1466260&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-web/test/utils/ajax_test.js (original)
+++ incubator/ambari/trunk/ambari-web/test/utils/ajax_test.js Tue Apr  9 21:59:21 2013
@@ -20,23 +20,3 @@
  * Here is fix for ajax support
  * @type {*}
  */
-var XMLHttpRequest = xmlhttprequest.XMLHttpRequest;
-var $ = window.$;
-
-$.support.cors = true;
-$.ajaxSettings.xhr = function () {
-  return new XMLHttpRequest();
-}
-
-$.mocho = true;
-$.hostName = testHost;
-
-/*sinon.stub2 = function(object, property, value){
-  var origin = object[property];
-  var count = 0;
-  var newValue = function(){
-    count++;
-    return value.call(this, arguments, origin, count);
-  }
-  sinon.stub(object, property, newValue);
-}*/

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=1466260&r1=1466259&r2=1466260&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-web/test/utils/validator_test.js (original)
+++ incubator/ambari/trunk/ambari-web/test/utils/validator_test.js Tue Apr  9 21:59:21 2013
@@ -203,7 +203,7 @@ describe('validator', function () {
       {m:'"" - invalid',i:'',e:false},
       {m:'"abc123" - valid',i:'abc123',e:true},
       {m:'"1abc123" - invalid',i:'1abc123',e:false},
-      {m:'"abc123$" - valid',i:'abc123$',e:true},
+      {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},



Mime
View raw message