ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jai...@apache.org
Subject git commit: AMBARI-7526. Unable to logout from Admin View, when ambari-server is stopped. (jaimin)
Date Tue, 30 Sep 2014 21:41:45 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 73c169e32 -> 3843209c1


AMBARI-7526. Unable to logout from Admin View, when ambari-server is stopped. (jaimin)


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

Branch: refs/heads/trunk
Commit: 3843209c127aeab29c63799c5c38df2b54b2b9f1
Parents: 73c169e
Author: Jaimin Jetly <jaimin@hortonworks.com>
Authored: Tue Sep 30 14:41:36 2014 -0700
Committer: Jaimin Jetly <jaimin@hortonworks.com>
Committed: Tue Sep 30 14:41:42 2014 -0700

----------------------------------------------------------------------
 ambari-admin/pom.xml                            | 17 +++++-
 .../main/resources/ui/admin-web/app/index.html  |  2 +-
 .../app/scripts/controllers/mainCtrl.js         | 15 +++--
 .../ui/admin-web/app/scripts/services/Auth.js   |  9 ++-
 .../src/main/resources/ui/admin-web/bower.json  | 15 +++--
 .../main/resources/ui/admin-web/package.json    | 19 +++++++
 .../resources/ui/admin-web/test/e2e/signout.js  | 43 +++++++++++++++
 .../resources/ui/admin-web/test/karma.conf.js   | 58 ++++++++++++++++++++
 .../ui/admin-web/test/protractor-conf.js        | 51 +++++++++++++++++
 .../resources/ui/admin-web/test/spec/test.js    | 30 ----------
 .../test/unit/controllers/mainCtrl_test.js      | 54 ++++++++++++++++++
 11 files changed, 270 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/3843209c/ambari-admin/pom.xml
----------------------------------------------------------------------
diff --git a/ambari-admin/pom.xml b/ambari-admin/pom.xml
index 6f70b43..3b78238 100644
--- a/ambari-admin/pom.xml
+++ b/ambari-admin/pom.xml
@@ -15,7 +15,7 @@
    limitations under the License.
 -->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
   <parent>
     <groupId>org.apache.ambari</groupId>
     <artifactId>ambari-project</artifactId>
@@ -122,6 +122,21 @@
               </arguments>
             </configuration>
           </execution>
+          <execution>
+            <id>unit test</id>
+            <phase>test</phase>
+            <goals>
+              <goal>exec</goal>
+            </goals>
+            <configuration>
+              <workingDirectory>${basedir}/src/main/resources/ui/admin-web</workingDirectory>
+              <executable>npm</executable>
+              <arguments>
+                <argument>run</argument>
+                <argument>test-single-run</argument>
+              </arguments>
+            </configuration>
+          </execution>
         </executions>
       </plugin>
       <plugin>

http://git-wip-us.apache.org/repos/asf/ambari/blob/3843209c/ambari-admin/src/main/resources/ui/admin-web/app/index.html
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/index.html b/ambari-admin/src/main/resources/ui/admin-web/app/index.html
index 2fb9fce..b197302 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/index.html
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/index.html
@@ -52,7 +52,7 @@
             <ul class="nav navbar-nav navbar-right">
               <li>
                 <div class="btn-group" dropdown is-open="status.isopen">
-                <button type="button" class="btn btn-default dropdown-toggle navbar-btn"
ng-disabled="disabled">
+                  <button type="button" class="btn btn-default dropdown-toggle navbar-btn"
ng-disabled="disabled">
                     <i class="fa fa-user"></i> {{currentUser}} <span class="caret"></span>
                   </button>
                   <ul class="dropdown-menu" role="menu">

http://git-wip-us.apache.org/repos/asf/ambari/blob/3843209c/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/mainCtrl.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/mainCtrl.js
b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/mainCtrl.js
index 797ecb2..64b9e27 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/mainCtrl.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/mainCtrl.js
@@ -18,13 +18,16 @@
 'use strict';
 
 angular.module('ambariAdminConsole')
-.controller('MainCtrl',['$scope', 'Auth', 'uiAlert', '$modal', 'Cluster', function($scope,
Auth, uiAlert, $modal, Cluster) {
+.controller('MainCtrl',['$scope', '$window','Auth', 'uiAlert', '$modal', 'Cluster', function($scope,
$window, Auth, uiAlert, $modal, Cluster) {
   $scope.signOut = function() {
-    Auth.signout().then(function() {
-     window.location.pathname = ''; // Change location hard, because Angular works only with
relative urls
-    }).catch(function(data) {
-      uiAlert.danger(data.data.status, data.data.message);
-    });
+    var data = JSON.parse(localStorage.ambari);
+    delete data.app.authenticated;
+    delete data.app.loginName;
+    delete data.app.user;
+    localStorage.ambari = JSON.stringify(data);
+    $window.location.pathname = '';
+    $scope.hello = "hello";
+    Auth.signout();
   };
 
   $scope.about = function() {

http://git-wip-us.apache.org/repos/asf/ambari/blob/3843209c/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/Auth.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/Auth.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/Auth.js
index 93377b9..bc25e1e 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/Auth.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/Auth.js
@@ -19,7 +19,14 @@
 
 angular.module('ambariAdminConsole')
 .factory('Auth',['$http', 'Settings', function($http, Settings) {
-	var currentUserName = JSON.parse(localStorage.ambari).app.loginName;
+  var ambari;
+  var currentUserName;
+  if (localStorage.ambari) {
+    ambari = JSON.parse(localStorage.ambari);
+    if (ambari && ambari.app && ambari.app.loginName) {
+      currentUserName = ambari.app.loginName;
+    }
+  }
   return {
     signout: function() {
       return $http({

http://git-wip-us.apache.org/repos/asf/ambari/blob/3843209c/ambari-admin/src/main/resources/ui/admin-web/bower.json
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/bower.json b/ambari-admin/src/main/resources/ui/admin-web/bower.json
index 896e5bd..dbc6ae3 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/bower.json
+++ b/ambari-admin/src/main/resources/ui/admin-web/bower.json
@@ -3,14 +3,21 @@
   "private": true,
   "dependencies": {
     "bootstrap": "~3.1.1",
-    "angular": "~1.2.18",
-    "angular-route": "~1.2.18",
+    "angular": "~1.2.25",
+    "angular-route": "~1.2.25",
     "angular-bootstrap": "~0.11.0",
+    "underscore": "~1.7.0",
     "restangular": "~1.4.0",
     "angular-bootstrap-toggle-switch": "~0.5.1",
-    "angular-animate": "~1.2.23",
+    "angular-animate": "~1.2.25",
     "angular-translate": "~2.2.0",
     "font-awesome": "~4.2.0"
   },
-  "devDependencies": {}
+  "devDependencies": {
+    "angular-mocks": "~1.2.25",
+    "commonjs": "~0.2.0",
+    "chai": "~1.8.0",
+    "mocha": "~1.14.0",
+    "sinon": "~1.10.3"
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/3843209c/ambari-admin/src/main/resources/ui/admin-web/package.json
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/package.json b/ambari-admin/src/main/resources/ui/admin-web/package.json
index 0dc99e8..06af9ae 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/package.json
+++ b/ambari-admin/src/main/resources/ui/admin-web/package.json
@@ -4,6 +4,12 @@
   "dependencies": {
   },
   "devDependencies": {
+    "karma": "^0.12.16",
+    "karma-phantomjs-launcher": "~0.1",
+    "karma-chrome-launcher": "^0.1.4",
+    "karma-jasmine": "^0.1.5",
+    "protractor": "~1.0.0",
+    "http-server": "^0.6.1",
     "bower": "1.3.8",
     "gulp": "^3.6.0",
     "gulp-autoprefixer": "^0.0.7",
@@ -18,6 +24,19 @@
     "gulp-useref": "^0.4.2",
     "gulp-plumber": "*"
   },
+  "scripts": {
+    "postinstall": "bower install",
+    "prestart": "npm install",
+    "start": "http-server -a 0.0.0.0 -p 8000",
+    "pretest": "npm install",
+    "test": "node node_modules/karma/bin/karma start test/karma.conf.js",
+    "test-single-run": "node node_modules/karma/bin/karma start test/karma.conf.js  --single-run",
+    "preupdate-webdriver": "npm install",
+    "update-webdriver": "webdriver-manager update",
+    "preprotractor": "npm run update-webdriver",
+    "protractor": "protractor test/protractor-conf.js",
+    "update-index-async": "node -e \"require('shelljs/global'); sed('-i', /\\/\\/@@NG_LOADER_START@@[\\s\\S]*\\/\\/@@NG_LOADER_END@@/,
'//@@NG_LOADER_START@@\\n' + cat('bower_components/angular-loader/angular-loader.min.js')
+ '\\n//@@NG_LOADER_END@@', 'app/index-async.html');\""
+  },
   "engines": {
     "node": ">=0.10.0"
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/3843209c/ambari-admin/src/main/resources/ui/admin-web/test/e2e/signout.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/test/e2e/signout.js b/ambari-admin/src/main/resources/ui/admin-web/test/e2e/signout.js
new file mode 100644
index 0000000..cb670ec
--- /dev/null
+++ b/ambari-admin/src/main/resources/ui/admin-web/test/e2e/signout.js
@@ -0,0 +1,43 @@
+/**
+ * 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.
+ */
+'use strict';
+describe('Ambari sign out from Admin view', function () {
+  describe('Admin view', function () {
+    var ptor = protractor.getInstance();
+    beforeEach(function () {
+      ptor.get('app/index.html');
+      ptor.waitForAngular();
+    });
+    it('should navigate to login page on clicking "Sign out" action', function () {
+      var userDropdownBtn = element(by.binding('currentUser'));
+      var signOutAction = element(by.css('[ng-click="signOut()"]'));
+      //Action-1: Click on user dropdown menu and
+      //Action-2: Click on SignOut action link
+      userDropdownBtn.click().then(function () {
+        signOutAction.click().then(function () {
+          //Validation
+          setTimeout(function () {
+            expect(ptor.getCurrentUrl()).toContain('#/login');
+          }, 3000);
+        });
+      });
+    });
+  });
+});
+
+

http://git-wip-us.apache.org/repos/asf/ambari/blob/3843209c/ambari-admin/src/main/resources/ui/admin-web/test/karma.conf.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/test/karma.conf.js b/ambari-admin/src/main/resources/ui/admin-web/test/karma.conf.js
new file mode 100644
index 0000000..1b815e5
--- /dev/null
+++ b/ambari-admin/src/main/resources/ui/admin-web/test/karma.conf.js
@@ -0,0 +1,58 @@
+/**
+ * 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.
+ */
+
+module.exports = function(config){
+  config.set({
+
+    basePath : '../',
+
+    files : [
+      'app/bower_components/angular/angular.js',
+      'app/bower_components/angular-animate/angular-animate.js',
+      'app/bower_components/angular-bootstrap/ui-bootstrap.js',
+      'app/bower_components/angular-bootstrap-toggle-switch/angular-toggle-switch.js',
+      'app/bower_components/angular-route/angular-route.js',
+      'app/bower_components/angular-translate/angular-translate.js',
+      'app/bower_components/underscore/underscore.js',
+      'app/bower_components/restangular/dist/restangular.js',
+      'app/bower_components/mocha/mocha.js',
+      'app/bower_components/chai/chai.js',
+      'app/bower_components/sinon/lib/sinon.js',
+      'app/bower_components/angular-mocks/angular-mocks.js',
+      'app/scripts/**/*.js',
+      'test/unit/**/*.js'
+    ],
+
+    autoWatch : true,
+
+    frameworks: ['jasmine'],
+
+    browsers: ['PhantomJS'],
+
+    plugins : [
+            'karma-jasmine',
+            'karma-phantomjs-launcher'
+            ],
+
+    junitReporter : {
+      outputFile: 'test_out/unit.xml',
+      suite: 'unit'
+    }
+
+  });
+};
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/3843209c/ambari-admin/src/main/resources/ui/admin-web/test/protractor-conf.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/test/protractor-conf.js b/ambari-admin/src/main/resources/ui/admin-web/test/protractor-conf.js
new file mode 100644
index 0000000..18a32cb
--- /dev/null
+++ b/ambari-admin/src/main/resources/ui/admin-web/test/protractor-conf.js
@@ -0,0 +1,51 @@
+/**
+ * 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.
+ */
+
+exports.config = {
+  allScriptsTimeout: 11000,
+
+  specs: [
+    'e2e/*.js'
+  ],
+
+  capabilities: {
+    'browserName': 'chrome'
+  },
+
+  chromeOnly: true,
+
+  baseUrl: 'http://localhost:8000',
+
+  rootElement: 'body',
+
+  onPrepare: function() {
+
+  },
+
+
+  framework: 'jasmine',
+
+  jasmineNodeOpts: {
+    onComplete: null,
+    isVerbose: true,
+    showColors: true,
+    includeStackTrace: true,
+    defaultTimeoutInterval: 30000
+  }
+};
+

http://git-wip-us.apache.org/repos/asf/ambari/blob/3843209c/ambari-admin/src/main/resources/ui/admin-web/test/spec/test.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/test/spec/test.js b/ambari-admin/src/main/resources/ui/admin-web/test/spec/test.js
deleted file mode 100644
index a43f4e1..0000000
--- a/ambari-admin/src/main/resources/ui/admin-web/test/spec/test.js
+++ /dev/null
@@ -1,30 +0,0 @@
-/**
- * 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.
- */
-/* global describe, it */
-
-(function () {
-    'use strict';
-
-    describe('Give it some context', function () {
-        describe('maybe a bit more context here', function () {
-            it('should run here few assertions', function () {
-
-            });
-        });
-    });
-})();

http://git-wip-us.apache.org/repos/asf/ambari/blob/3843209c/ambari-admin/src/main/resources/ui/admin-web/test/unit/controllers/mainCtrl_test.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/test/unit/controllers/mainCtrl_test.js
b/ambari-admin/src/main/resources/ui/admin-web/test/unit/controllers/mainCtrl_test.js
new file mode 100644
index 0000000..c66d96e
--- /dev/null
+++ b/ambari-admin/src/main/resources/ui/admin-web/test/unit/controllers/mainCtrl_test.js
@@ -0,0 +1,54 @@
+/**
+ * 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.
+ */
+
+describe('#Auth', function () {
+
+  describe('signout', function () {
+    var scope, ctrl, $httpBackend, $window, clusterService,deferred;
+    beforeEach(module('ambariAdminConsole', function($provide){
+      $provide.value('$window', {location: {pathname: 'http://c6401.ambari.apache.org:8080/views/ADMIN_VIEW/1.0.0/INSTANCE/#/'}});
+      localStorage.ambari = JSON.stringify({app: {authenticated: true, loginName: 'admin',
user: 'user'}});
+    }));
+    afterEach(function() {
+      $httpBackend.verifyNoOutstandingExpectation();
+      $httpBackend.verifyNoOutstandingRequest();
+    });
+    beforeEach(inject(function (_$httpBackend_, $rootScope, $controller, _$window_, _Cluster_,_$q_)
{
+      clusterService =  _Cluster_;
+      deferred = _$q_.defer();
+      spyOn(clusterService, 'getStatus').andReturn(deferred.promise);
+      deferred.resolve('c1');
+      $window = _$window_;
+      $httpBackend = _$httpBackend_;
+      $httpBackend.whenGET('/api/v1/logout').respond(200,{message: "successfully logged out"});
+      scope = $rootScope.$new();
+      scope.$apply();
+      ctrl = $controller('MainCtrl', {$scope: scope});
+    }));
+
+    it('should reset window.location and ambari localstorage', function () {
+      scope.signOut();
+      $httpBackend.flush();
+      chai.expect($window.location.pathname).to.be.empty;
+      var data = JSON.parse(localStorage.ambari);
+      chai.expect(data.app.authenticated).to.equal(undefined);
+      chai.expect(data.app.loginName).to.equal(undefined);
+      chai.expect(data.app.user).to.equal(undefined);
+    });
+  });
+});
\ No newline at end of file


Mime
View raw message