Author: [email protected]
Date: Wed Sep 28 14:13:27 2011
New Revision: 1419

Log:
[AMDATUCASSANDRA-97] Added integration test to verify if the login procedure 
also succeeds using the Cassandra implementation of the token storage provider

Added:
   
trunk/amdatu-cassandra/test-integration/tests/src/test/java/org/amdatu/cassandra/test/integration/tests/LoginTest.java
   
trunk/amdatu-cassandra/test-integration/tests/src/test/java/org/amdatu/cassandra/test/integration/tests/util/HttpUtil.java
Modified:
   
trunk/amdatu-cassandra/test-integration/base/src/main/java/org/amdatu/cassandra/test/integration/base/CassandraFixture.java
   trunk/amdatu-cassandra/test-integration/pom.xml
   trunk/amdatu-cassandra/test-integration/tests/pom.xml
   
trunk/amdatu-cassandra/test-integration/tests/src/test/java/org/amdatu/cassandra/test/integration/tests/framework/CassandraTest.java
   
trunk/amdatu-cassandra/test-integration/tests/src/test/java/org/amdatu/cassandra/test/integration/tests/framework/CassandraTestBase.java
   
trunk/amdatu-cassandra/test-integration/tests/src/test/java/org/amdatu/cassandra/test/integration/tests/util/ServiceUtil.java

Modified: 
trunk/amdatu-cassandra/test-integration/base/src/main/java/org/amdatu/cassandra/test/integration/base/CassandraFixture.java
==============================================================================
--- 
trunk/amdatu-cassandra/test-integration/base/src/main/java/org/amdatu/cassandra/test/integration/base/CassandraFixture.java
 (original)
+++ 
trunk/amdatu-cassandra/test-integration/base/src/main/java/org/amdatu/cassandra/test/integration/base/CassandraFixture.java
 Wed Sep 28 14:13:27 2011
@@ -53,6 +53,7 @@
             
mavenBundle().groupId("org.amdatu.auth").artifactId("org.amdatu.auth.oauth.server").versionAsInProject(),
             
mavenBundle().groupId("org.amdatu.auth").artifactId("org.amdatu.auth.oauth.consumerregistry").versionAsInProject(),
             
mavenBundle().groupId("org.amdatu.auth").artifactId("org.amdatu.auth.tokenprovider").versionAsInProject(),
+            
mavenBundle().groupId("org.amdatu.auth").artifactId("org.amdatu.auth.login.service").versionAsInProject(),
             
             // Wrap libraries we depend on as OSGi bundles and provision those
             
wrappedBundle(mavenBundle().groupId("commons-httpclient").artifactId("commons-httpclient").versionAsInProject()),

Modified: trunk/amdatu-cassandra/test-integration/pom.xml
==============================================================================
--- trunk/amdatu-cassandra/test-integration/pom.xml     (original)
+++ trunk/amdatu-cassandra/test-integration/pom.xml     Wed Sep 28 14:13:27 2011
@@ -145,6 +145,13 @@
         <scope>compile</scope>
         <type>bundle</type>
       </dependency>
+      <dependency>
+        <groupId>org.amdatu.auth</groupId>
+        <artifactId>org.amdatu.auth.login.service</artifactId>
+        <version>${org.amdatu.auth.version}</version>
+        <scope>compile</scope>
+        <type>bundle</type>
+      </dependency>
 
       <dependency>
         <groupId>org.amdatu.web</groupId>

Modified: trunk/amdatu-cassandra/test-integration/tests/pom.xml
==============================================================================
--- trunk/amdatu-cassandra/test-integration/tests/pom.xml       (original)
+++ trunk/amdatu-cassandra/test-integration/tests/pom.xml       Wed Sep 28 
14:13:27 2011
@@ -190,6 +190,11 @@
       <artifactId>org.amdatu.auth.tokenprovider</artifactId>
       <type>bundle</type>
     </dependency>
+    <dependency>
+      <groupId>org.amdatu.auth</groupId>
+      <artifactId>org.amdatu.auth.login.service</artifactId>
+      <type>bundle</type>
+    </dependency>
 
     <dependency>
       <groupId>commons-httpclient</groupId>

Added: 
trunk/amdatu-cassandra/test-integration/tests/src/test/java/org/amdatu/cassandra/test/integration/tests/LoginTest.java
==============================================================================
--- (empty file)
+++ 
trunk/amdatu-cassandra/test-integration/tests/src/test/java/org/amdatu/cassandra/test/integration/tests/LoginTest.java
      Wed Sep 28 14:13:27 2011
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2010, 2011 The Amdatu Foundation
+ * 
+ * Licensed 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.
+ */
+package org.amdatu.cassandra.test.integration.tests;
+
+import org.amdatu.cassandra.test.integration.base.CassandraFixture;
+import org.amdatu.cassandra.test.integration.tests.framework.CassandraTestBase;
+import org.amdatu.cassandra.test.integration.tests.util.HttpUtil;
+import org.osgi.service.useradmin.Role;
+import org.osgi.service.useradmin.User;
+
+/**
+ * This test verifies if we can simply login, using the Cassandra 
implementation of the token provider.
+ * 
+ * @author ivol
+ */
+public class LoginTest extends CassandraTestBase {
+    private final static String USERNAME = "testadmin";
+    private final static String PASSWORD = "testpassword";
+    
+    @SuppressWarnings("unchecked")
+    public void execute() throws Exception {
+        // First create a test user
+        User testUser = (User) m_userAdmin.createRole(USERNAME, Role.USER);
+        assertTrue(testUser != null);
+        testUser.getCredentials().put("password", PASSWORD);
+        
+        // Check if we can login using the login service
+        assertNotNull(HttpUtil.login(CassandraFixture.HOSTNAME, USERNAME, 
PASSWORD));
+        
+        m_userAdmin.removeRole(USERNAME);
+    }
+}

Modified: 
trunk/amdatu-cassandra/test-integration/tests/src/test/java/org/amdatu/cassandra/test/integration/tests/framework/CassandraTest.java
==============================================================================
--- 
trunk/amdatu-cassandra/test-integration/tests/src/test/java/org/amdatu/cassandra/test/integration/tests/framework/CassandraTest.java
        (original)
+++ 
trunk/amdatu-cassandra/test-integration/tests/src/test/java/org/amdatu/cassandra/test/integration/tests/framework/CassandraTest.java
        Wed Sep 28 14:13:27 2011
@@ -30,6 +30,7 @@
 import org.amdatu.cassandra.test.integration.base.CassandraFixture;
 import org.amdatu.cassandra.test.integration.tests.CassandraDaemonTest;
 import 
org.amdatu.cassandra.test.integration.tests.CassandraPersistenceManagerTest;
+import org.amdatu.cassandra.test.integration.tests.LoginTest;
 import org.amdatu.cassandra.test.integration.tests.NonceStoreTest;
 import 
org.amdatu.cassandra.test.integration.tests.OAuthServiceConsumerRESTTest;
 import org.amdatu.cassandra.test.integration.tests.OAuthServiceConsumerTest;
@@ -118,13 +119,14 @@
         // Create the dependency manager
         m_dependencyManager = new 
DependencyManager(m_testContext.getBundleContext());
         
-        // Execute the tests
+        // Execute the tests        
         test(CassandraDaemonTest.class);
         test(CassandraPersistenceManagerTest.class);
         test(UserAdminStoreTest.class);
         test(OAuthServiceConsumerTest.class);
         test(OAuthServiceConsumerRESTTest.class);
         test(NonceStoreTest.class);
+        test(LoginTest.class);
         
         // And we are done
         m_testContext.tearDown();

Modified: 
trunk/amdatu-cassandra/test-integration/tests/src/test/java/org/amdatu/cassandra/test/integration/tests/framework/CassandraTestBase.java
==============================================================================
--- 
trunk/amdatu-cassandra/test-integration/tests/src/test/java/org/amdatu/cassandra/test/integration/tests/framework/CassandraTestBase.java
    (original)
+++ 
trunk/amdatu-cassandra/test-integration/tests/src/test/java/org/amdatu/cassandra/test/integration/tests/framework/CassandraTestBase.java
    Wed Sep 28 14:13:27 2011
@@ -79,10 +79,15 @@
     protected void assertFalse(boolean check) {
         Assert.assertFalse(getStackTrace(), check);
     }
+    
     protected void assertTrue(boolean check) {
         Assert.assertTrue(getStackTrace(), check);
     }
     
+    protected void assertNotNull(Object object) {
+        Assert.assertNotNull(getStackTrace(), object);
+    }
+    
     protected String getStackTrace() {
         String eol = System.getProperty("line.separator");
         String stackTrace = "Assertion failed." + eol + "Stacktrace:" + eol;

Added: 
trunk/amdatu-cassandra/test-integration/tests/src/test/java/org/amdatu/cassandra/test/integration/tests/util/HttpUtil.java
==============================================================================
--- (empty file)
+++ 
trunk/amdatu-cassandra/test-integration/tests/src/test/java/org/amdatu/cassandra/test/integration/tests/util/HttpUtil.java
  Wed Sep 28 14:13:27 2011
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2010, 2011 The Amdatu Foundation
+ * 
+ * Licensed 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.
+ */
+package org.amdatu.cassandra.test.integration.tests.util;
+
+import java.io.IOException;
+
+import junit.framework.Assert;
+
+import org.amdatu.auth.tokenprovider.TokenProvider;
+import org.amdatu.cassandra.test.integration.base.CassandraFixture;
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HeaderElement;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.methods.PostMethod;
+
+public class HttpUtil {
+    public static HeaderElement login(String host, String username, String 
password) throws HttpException, IOException {
+        String loginUrl = "http://"; + host + ":" + CassandraFixture.PORTNR + 
"/rest/authorization/login";
+        HttpClient httpClient = new HttpClient();
+        PostMethod postMethod = null;
+        try {
+            postMethod = new PostMethod(loginUrl);
+            postMethod.addParameter("username", username);
+            postMethod.addParameter("password", password);
+            postMethod.addRequestHeader("Content-Type", 
"application/x-www-form-urlencoded;charset=UTF-8");
+            int status = httpClient.executeMethod(postMethod);
+            Assert.assertTrue("Login failed using Amdatu account '" + username 
+ "', response code=" + status,
+                status == HttpStatus.SC_OK);
+            Header cookieHeader = postMethod.getResponseHeader("Set-Cookie");
+            if (cookieHeader != null) {
+                HeaderElement[] headerElements = cookieHeader.getElements();
+                for (HeaderElement headerElement : headerElements) {
+                    if 
(TokenProvider.TOKEN_COOKIE_NAME.equalsIgnoreCase(headerElement.getName())) {
+                        return headerElement;
+                    }
+                }
+            }
+        }
+        finally {
+            postMethod.releaseConnection();
+        }
+        return null;
+    }
+}

Modified: 
trunk/amdatu-cassandra/test-integration/tests/src/test/java/org/amdatu/cassandra/test/integration/tests/util/ServiceUtil.java
==============================================================================
--- 
trunk/amdatu-cassandra/test-integration/tests/src/test/java/org/amdatu/cassandra/test/integration/tests/util/ServiceUtil.java
       (original)
+++ 
trunk/amdatu-cassandra/test-integration/tests/src/test/java/org/amdatu/cassandra/test/integration/tests/util/ServiceUtil.java
       Wed Sep 28 14:13:27 2011
@@ -1,3 +1,18 @@
+/*
+ * Copyright (c) 2010, 2011 The Amdatu Foundation
+ * 
+ * Licensed 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.
+ */
 package org.amdatu.cassandra.test.integration.tests.util;
 
 import static org.hamcrest.core.Is.is;
_______________________________________________
Amdatu-commits mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-commits

Reply via email to