airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lah...@apache.org
Subject svn commit: r1422068 - in /airavata/trunk/modules: commons/utils/ commons/utils/src/main/java/org/apache/airavata/common/utils/ integration-tests/ registry/airavata-registry-test/src/test/java/org/apache/airavata/registry/api/test/util/ rest/service/ r...
Date Fri, 14 Dec 2012 20:33:17 GMT
Author: lahiru
Date: Fri Dec 14 20:33:05 2012
New Revision: 1422068

URL: http://svn.apache.org/viewvc?rev=1422068&view=rev
Log:
Fixing AIRAVATA-673. Also cleaned up integration tests bit. Thanks Amila

Added:
    airavata/trunk/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/DatabaseTestCases.java
    airavata/trunk/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/DerbyUtil.java
    airavata/trunk/modules/rest/service/src/test/java/org/apache/airavata/security/userstore/JDBCAuthenticatorTests.java
      - copied, changed from r1421802, airavata/trunk/modules/rest/service/src/test/java/org/apache/airavata/security/userstore/JDBCUserStoreTest.java
    airavata/trunk/modules/rest/service/src/test/java/org/apache/airavata/security/userstore/LDAPAuthenticatorTest.java
      - copied, changed from r1421802, airavata/trunk/modules/rest/service/src/test/java/org/apache/airavata/security/userstore/LDAPUserStoreTest.java
    airavata/trunk/modules/rest/service/src/test/java/org/apache/airavata/security/userstore/SessionDBAuthenticatorTest.java
      - copied, changed from r1421802, airavata/trunk/modules/rest/service/src/test/java/org/apache/airavata/security/userstore/SessionDBUserStoreTest.java
Removed:
    airavata/trunk/modules/integration-tests/derby-start.txt
    airavata/trunk/modules/rest/service/src/test/java/org/apache/airavata/security/userstore/JDBCUserStoreTest.java
    airavata/trunk/modules/rest/service/src/test/java/org/apache/airavata/security/userstore/LDAPUserStoreTest.java
    airavata/trunk/modules/rest/service/src/test/java/org/apache/airavata/security/userstore/SessionDBUserStoreTest.java
    airavata/trunk/modules/rest/service/src/test/resources/testdb/
    airavata/trunk/modules/security/src/test/resources/testdb/
Modified:
    airavata/trunk/modules/commons/utils/pom.xml
    airavata/trunk/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/DBUtil.java
    airavata/trunk/modules/integration-tests/pom.xml
    airavata/trunk/modules/registry/airavata-registry-test/src/test/java/org/apache/airavata/registry/api/test/util/Initialize.java
    airavata/trunk/modules/rest/service/pom.xml
    airavata/trunk/modules/rest/service/src/test/java/org/apache/airavata/services/registry/rest/security/local/LocalUserStoreTest.java
    airavata/trunk/modules/rest/service/src/test/resources/jdbc-authenticator.xml
    airavata/trunk/modules/rest/service/src/test/resources/session-authenticator.xml
    airavata/trunk/modules/security/pom.xml
    airavata/trunk/modules/security/src/main/java/org/apache/airavata/security/userstore/JDBCUserStore.java
    airavata/trunk/modules/security/src/test/java/org/apache/airavata/security/userstore/JDBCUserStoreTest.java
    airavata/trunk/modules/security/src/test/java/org/apache/airavata/security/userstore/SessionDBUserStoreTest.java
    airavata/trunk/modules/security/src/test/resources/jdbc-authenticator.xml
    airavata/trunk/modules/security/src/test/resources/session-authenticator.xml

Modified: airavata/trunk/modules/commons/utils/pom.xml
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/commons/utils/pom.xml?rev=1422068&r1=1422067&r2=1422068&view=diff
==============================================================================
--- airavata/trunk/modules/commons/utils/pom.xml (original)
+++ airavata/trunk/modules/commons/utils/pom.xml Fri Dec 14 20:33:05 2012
@@ -71,6 +71,27 @@
 			<artifactId>slf4j-api</artifactId>
 		</dependency>
 
+        <dependency>
+            <groupId>org.apache.derby</groupId>
+            <artifactId>derby</artifactId>
+            <version>${derby.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.derby</groupId>
+            <artifactId>derbyclient</artifactId>
+            <version>${derby.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.derby</groupId>
+            <artifactId>derbynet</artifactId>
+            <version>${derby.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.derby</groupId>
+            <artifactId>derbytools</artifactId>
+            <version>${derby.version}</version>
+        </dependency>
+
 		<!-- Testing -->
 		<dependency>
 			<groupId>junit</groupId>

Modified: airavata/trunk/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/DBUtil.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/DBUtil.java?rev=1422068&r1=1422067&r2=1422068&view=diff
==============================================================================
--- airavata/trunk/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/DBUtil.java
(original)
+++ airavata/trunk/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/DBUtil.java
Fri Dec 14 20:33:05 2012
@@ -110,6 +110,35 @@ public class DBUtil {
         return null;
     }
 
+    /**
+     * Create table utility method.
+     * @param sql SQL to be executed.
+     * @throws SQLException If an error occurred while creating the table.
+     */
+    public void executeSQL(String sql) throws SQLException {
+
+        Connection connection = getConnection();
+
+        PreparedStatement ps = connection.prepareStatement(sql);
+
+        try {
+            ps.executeUpdate();
+            connection.commit();
+        } finally {
+            try {
+                if (ps != null) {
+                    ps.close();
+                }
+
+                connection.close();
+
+            } catch (Exception ignore) {
+                log.error("An error occurred while closing database connections ", ignore);
+            }
+        }
+
+    }
+
     private void loadDriver() throws ClassNotFoundException, IllegalAccessException, InstantiationException
{
         Class.forName(driverName).newInstance();
     }

Added: airavata/trunk/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/DatabaseTestCases.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/DatabaseTestCases.java?rev=1422068&view=auto
==============================================================================
--- airavata/trunk/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/DatabaseTestCases.java
(added)
+++ airavata/trunk/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/DatabaseTestCases.java
Fri Dec 14 20:33:05 2012
@@ -0,0 +1,84 @@
+package org.apache.airavata.common.utils;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+/**
+ * An abstraction for database specific test classes. This will create a database and provides
+ * methods to execute SQLs.
+ */
+public class DatabaseTestCases {
+
+    private static final Logger logger = LoggerFactory.getLogger(DatabaseTestCases.class);
+
+
+    protected static String hostAddress = "localhost";
+    protected static int port = 20000;
+    protected static String userName = "admin";
+    protected static String password = "admin";
+    protected static String driver = "org.apache.derby.jdbc.ClientDriver";
+
+
+    public static String getHostAddress() {
+        return hostAddress;
+    }
+
+    public static int getPort() {
+        return port;
+    }
+
+    public static String getUserName() {
+        return userName;
+    }
+
+    public static String getPassword() {
+        return password;
+    }
+
+    public static String getDriver() {
+        return driver;
+    }
+
+    public static String getJDBCUrl() {
+        return new StringBuilder().append("jdbc:derby://").append(getHostAddress()).append(":").append(getPort()).
+                append("/persistent_data;create=true;user=").append(getUserName()).
+                append(";password=").append(getPassword()).toString();
+    }
+
+    public static void waitTillServerStarts() {
+        DBUtil dbUtil = new DBUtil(getJDBCUrl(), getUserName(), getPassword(), getDriver());
+
+        Connection connection = null;
+        try {
+           connection = dbUtil.getConnection();
+        } catch (SQLException e) {
+            // ignore
+        }
+
+        while (connection == null) {
+            try {
+                Thread.sleep(1000);
+                try {
+                    connection = dbUtil.getConnection();
+                } catch (SQLException e) {
+                    // ignore
+                }
+            } catch (InterruptedException e) {
+                //ignore
+            }
+        }
+
+
+    }
+
+
+
+    public static void executeSQL(String sql) throws Exception {
+        DBUtil dbUtil = new DBUtil(getJDBCUrl(), getUserName(), getPassword(), getDriver());
+        dbUtil.executeSQL(sql);
+    }
+
+}

Added: airavata/trunk/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/DerbyUtil.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/DerbyUtil.java?rev=1422068&view=auto
==============================================================================
--- airavata/trunk/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/DerbyUtil.java
(added)
+++ airavata/trunk/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/DerbyUtil.java
Fri Dec 14 20:33:05 2012
@@ -0,0 +1,84 @@
+package org.apache.airavata.common.utils;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.InetAddress;
+import java.sql.DriverManager;
+import org.apache.derby.drda.NetworkServerControl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.sql.SQLException;
+
+/**
+ * This class includes methods to start stop Derby database. Mainly user for tests.
+ */
+public class DerbyUtil {
+
+    private static NetworkServerControl server;
+
+    private static final Logger logger = LoggerFactory.getLogger(DerbyUtil.class);
+
+    public static final String DERBY_SERVER_MODE_SYS_PROPERTY = "derby.drda.startNetworkServer";
+
+    /**
+     * Starts new derby server instance with given configurations.
+     * @param hostAddress The host address start the server.
+     * @param port The port number which server is starting.
+     * @param user JDBC user name.
+     * @param password JDBC password.
+     * @throws Exception If an error occurred while starting the server.
+     */
+    public static void startDerbyInServerMode(String hostAddress, int port, String user,
String password)
+            throws Exception {
+        PrintWriter consoleWriter = null;
+
+        try {
+            System.setProperty(DERBY_SERVER_MODE_SYS_PROPERTY, "true");
+            server = new NetworkServerControl(InetAddress.getByName(hostAddress),
+                    port,
+                    user, password);
+            consoleWriter = new PrintWriter(System.out, true);
+            server.start(consoleWriter);
+
+        } catch (IOException e) {
+            logger.error("Unable to start Apache derby in the server mode! Check whether
" +
+                    "specified port is available", e);
+            throw e;
+        } catch (Exception e) {
+            logger.error("Unable to start Apache derby in the server mode! Check whether
" +
+                    "specified port is available", e);
+            throw e;
+        } finally {
+
+            if (consoleWriter != null) {
+                consoleWriter.close();
+            }
+
+        }
+
+    }
+
+    /**
+     * Starts derby server in embedded mode.
+     * @throws ClassNotFoundException If specified driver not found in the class path.
+     * @throws SQLException  If an error occurred while creat
+     */
+    public static void startDerbyInEmbeddedMode() throws ClassNotFoundException, SQLException
{
+        Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
+        DriverManager.getConnection("jdbc:derby:memory:unit-testing-jpa;create=true").close();
+    }
+
+    /**
+     * Shuts down the server.
+     * @throws Exception If an error occurred while shutting down.
+     */
+    public static void stopDerbyServer() throws Exception {
+        try {
+            server.shutdown();
+        } catch (Exception e) {
+            logger.error("Error shutting down derby server.", e);
+            throw e;
+        }
+    }
+}

Modified: airavata/trunk/modules/integration-tests/pom.xml
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/integration-tests/pom.xml?rev=1422068&r1=1422067&r2=1422068&view=diff
==============================================================================
--- airavata/trunk/modules/integration-tests/pom.xml (original)
+++ airavata/trunk/modules/integration-tests/pom.xml Fri Dec 14 20:33:05 2012
@@ -24,33 +24,6 @@
     
     <build>
         <plugins>
-            <!--plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-dependency-plugin</artifactId>
-                <version>2.4</version>
-                <inherited>false</inherited>
-                <executions>
-                    <execution>
-                        <id>unpack-tomcat</id>
-                        <phase>compile</phase>
-                        <goals>
-                            <goal>unpack</goal>
-                        </goals>
-                        <configuration>
-                            <artifactItems>
-                                <artifactItem>
-                                    <groupId>org.apache.tomcat</groupId>
-                                    <artifactId>binary-distribution</artifactId>
-                                    <version>7.0.33</version>
-                                    <type>zip</type>
-                                    <overWrite>true</overWrite>
-                                    <outputDirectory>target/tests</outputDirectory>
-                                </artifactItem>
-                            </artifactItems>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin-->
             <plugin>
                 <artifactId>maven-antrun-plugin</artifactId>
                 <executions>

Modified: airavata/trunk/modules/registry/airavata-registry-test/src/test/java/org/apache/airavata/registry/api/test/util/Initialize.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/registry/airavata-registry-test/src/test/java/org/apache/airavata/registry/api/test/util/Initialize.java?rev=1422068&r1=1422067&r2=1422068&view=diff
==============================================================================
--- airavata/trunk/modules/registry/airavata-registry-test/src/test/java/org/apache/airavata/registry/api/test/util/Initialize.java
(original)
+++ airavata/trunk/modules/registry/airavata-registry-test/src/test/java/org/apache/airavata/registry/api/test/util/Initialize.java
Fri Dec 14 20:33:05 2012
@@ -21,6 +21,7 @@
 
 package org.apache.airavata.registry.api.test.util;
 
+import org.apache.airavata.common.utils.DerbyUtil;
 import org.apache.airavata.persistance.registry.jpa.ResourceType;
 import org.apache.airavata.persistance.registry.jpa.resources.GatewayResource;
 import org.apache.airavata.persistance.registry.jpa.resources.UserResource;
@@ -28,7 +29,6 @@ import org.apache.airavata.persistance.r
 import org.apache.airavata.persistance.registry.jpa.resources.WorkerResource;
 import org.apache.airavata.registry.api.exception.RegistrySettingsException;
 import org.apache.airavata.registry.api.util.RegistrySettings;
-import org.apache.derby.drda.NetworkServerControl;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -36,16 +36,11 @@ import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
-import java.net.InetAddress;
-import java.net.URL;
 import java.sql.*;
-import java.util.Properties;
 import java.util.StringTokenizer;
 
 public class Initialize {
     private static final Logger logger = LoggerFactory.getLogger(Initialize.class);
-    public static final String DERBY_SERVER_MODE_SYS_PROPERTY = "derby.drda.startNetworkServer";
-    private NetworkServerControl server;
     private static final String delimiter = ";";
     public static final String PERSISTANT_DATA = "Configuration";
 
@@ -271,39 +266,29 @@ public class Initialize {
     }
 
     private void startDerbyInServerMode() {
+
         try {
-            System.setProperty(DERBY_SERVER_MODE_SYS_PROPERTY, "true");
-            server = new NetworkServerControl(InetAddress.getByName(Utils.getHost()),
-                    20000,
-                    Utils.getJDBCUser(), Utils.getJDBCUser());
-            java.io.PrintWriter consoleWriter = new java.io.PrintWriter(System.out, true);
-            server.start(consoleWriter);
-        } catch (IOException e) {
-            logger.error("Unable to start Apache derby in the server mode! Check whether
" +
-                    "specified port is available");
+            DerbyUtil.startDerbyInServerMode(Utils.getHost(), 20000, Utils.getJDBCUser(),
Utils.getJDBCUser());
         } catch (Exception e) {
             logger.error("Unable to start Apache derby in the server mode! Check whether
" +
-                    "specified port is available");
+                    "specified port is available", e);
         }
 
     }
 
     private void startDerbyInEmbeddedMode(){
         try {
-            Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
-            DriverManager.getConnection("jdbc:derby:memory:unit-testing-jpa;create=true").close();
-        } catch (ClassNotFoundException e) {
-            e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
-        } catch (SQLException e) {
-            e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
+            DerbyUtil.startDerbyInEmbeddedMode();
+        } catch (Exception e) {
+            logger.error("Error occurred while starting Derby in embedded mode", e);
         }
     }
 
     public void stopDerbyServer() {
         try {
-            server.shutdown();
+            DerbyUtil.stopDerbyServer();
         } catch (Exception e) {
-            e.printStackTrace();
+            logger.error("Error occurred while stopping Derby", e);
         }
     }
 }

Modified: airavata/trunk/modules/rest/service/pom.xml
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/rest/service/pom.xml?rev=1422068&r1=1422067&r2=1422068&view=diff
==============================================================================
--- airavata/trunk/modules/rest/service/pom.xml (original)
+++ airavata/trunk/modules/rest/service/pom.xml Fri Dec 14 20:33:05 2012
@@ -43,12 +43,6 @@
 			<artifactId>shiro-core</artifactId>
 			<version>1.2.1</version>
 		</dependency>
-		<dependency>
-			<groupId>com.h2database</groupId>
-			<artifactId>h2</artifactId>
-			<version>1.3.168</version>
-			<scope>test</scope>
-		</dependency>
 
 		<!-- Airavata -->
 		<dependency>

Copied: airavata/trunk/modules/rest/service/src/test/java/org/apache/airavata/security/userstore/JDBCAuthenticatorTests.java
(from r1421802, airavata/trunk/modules/rest/service/src/test/java/org/apache/airavata/security/userstore/JDBCUserStoreTest.java)
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/rest/service/src/test/java/org/apache/airavata/security/userstore/JDBCAuthenticatorTests.java?p2=airavata/trunk/modules/rest/service/src/test/java/org/apache/airavata/security/userstore/JDBCAuthenticatorTests.java&p1=airavata/trunk/modules/rest/service/src/test/java/org/apache/airavata/security/userstore/JDBCUserStoreTest.java&r1=1421802&r2=1422068&rev=1422068&view=diff
==============================================================================
--- airavata/trunk/modules/rest/service/src/test/java/org/apache/airavata/security/userstore/JDBCUserStoreTest.java
(original)
+++ airavata/trunk/modules/rest/service/src/test/java/org/apache/airavata/security/userstore/JDBCAuthenticatorTests.java
Fri Dec 14 20:33:05 2012
@@ -20,22 +20,23 @@
 
 package org.apache.airavata.security.userstore;
 
-import junit.framework.TestCase;
-import org.apache.airavata.security.Authenticator;
+import org.apache.airavata.common.utils.DatabaseTestCases;
+import org.apache.airavata.common.utils.DerbyUtil;
 import org.apache.airavata.security.UserStore;
-import org.apache.airavata.security.configurations.AuthenticatorConfigurationReader;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
 import org.w3c.dom.Document;
 import org.w3c.dom.NodeList;
 
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
-import java.io.File;
-import java.util.List;
 
 /**
  * Test class for JDBC user store.
  */
-public class JDBCUserStoreTest extends TestCase {
+public class JDBCAuthenticatorTests extends DatabaseTestCases {
 
     /**
      * <specificConfigurations>
@@ -53,8 +54,25 @@ public class JDBCUserStoreTest extends T
      * @throws Exception
      */
 
+    @BeforeClass
+    public static void setUpDatabase() throws Exception{
+        DerbyUtil.startDerbyInServerMode(getHostAddress(), getPort(), getUserName(), getPassword());
 
+        waitTillServerStarts();
 
+        String createTable = "create table AIRAVATA_USER ( USERID varchar(255), PASSWORD
varchar(255) )";
+        executeSQL(createTable);
+
+        String insertSQL = "INSERT INTO AIRAVATA_USER VALUES('amilaj', 'secret')";
+        executeSQL(insertSQL);
+    }
+
+    @AfterClass
+    public static void shutDownDatabase() throws Exception {
+        DerbyUtil.stopDerbyServer();
+    }
+
+    @Test
     public void testAuthenticate() throws Exception {
 
         DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
@@ -66,9 +84,9 @@ public class JDBCUserStoreTest extends T
         UserStore userStore = new JDBCUserStore();
         userStore.configure(configurations.item(0));
 
-        assertTrue(userStore.authenticate("amilaj", "secret"));
-        assertFalse(userStore.authenticate("amilaj", "1secret"));
-        assertFalse(userStore.authenticate("lahiru", "1234"));
+        Assert.assertTrue(userStore.authenticate("amilaj", "secret"));
+        Assert.assertFalse(userStore.authenticate("amilaj", "1secret"));
+        Assert.assertFalse(userStore.authenticate("lahiru", "1234"));
 
     }
 }

Copied: airavata/trunk/modules/rest/service/src/test/java/org/apache/airavata/security/userstore/LDAPAuthenticatorTest.java
(from r1421802, airavata/trunk/modules/rest/service/src/test/java/org/apache/airavata/security/userstore/LDAPUserStoreTest.java)
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/rest/service/src/test/java/org/apache/airavata/security/userstore/LDAPAuthenticatorTest.java?p2=airavata/trunk/modules/rest/service/src/test/java/org/apache/airavata/security/userstore/LDAPAuthenticatorTest.java&p1=airavata/trunk/modules/rest/service/src/test/java/org/apache/airavata/security/userstore/LDAPUserStoreTest.java&r1=1421802&r2=1422068&rev=1422068&view=diff
==============================================================================
--- airavata/trunk/modules/rest/service/src/test/java/org/apache/airavata/security/userstore/LDAPUserStoreTest.java
(original)
+++ airavata/trunk/modules/rest/service/src/test/java/org/apache/airavata/security/userstore/LDAPAuthenticatorTest.java
Fri Dec 14 20:33:05 2012
@@ -33,7 +33,7 @@ import javax.xml.parsers.DocumentBuilder
  * User store test 2
  */
 @Ignore("Need LDAP server to run these tests")
-public class LDAPUserStoreTest extends TestCase{
+public class LDAPAuthenticatorTest extends TestCase{
 
     private LDAPUserStore ldapUserStore;
 

Copied: airavata/trunk/modules/rest/service/src/test/java/org/apache/airavata/security/userstore/SessionDBAuthenticatorTest.java
(from r1421802, airavata/trunk/modules/rest/service/src/test/java/org/apache/airavata/security/userstore/SessionDBUserStoreTest.java)
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/rest/service/src/test/java/org/apache/airavata/security/userstore/SessionDBAuthenticatorTest.java?p2=airavata/trunk/modules/rest/service/src/test/java/org/apache/airavata/security/userstore/SessionDBAuthenticatorTest.java&p1=airavata/trunk/modules/rest/service/src/test/java/org/apache/airavata/security/userstore/SessionDBUserStoreTest.java&r1=1421802&r2=1422068&rev=1422068&view=diff
==============================================================================
--- airavata/trunk/modules/rest/service/src/test/java/org/apache/airavata/security/userstore/SessionDBUserStoreTest.java
(original)
+++ airavata/trunk/modules/rest/service/src/test/java/org/apache/airavata/security/userstore/SessionDBAuthenticatorTest.java
Fri Dec 14 20:33:05 2012
@@ -21,6 +21,9 @@
 package org.apache.airavata.security.userstore;
 
 import junit.framework.TestCase;
+import org.apache.airavata.common.utils.DatabaseTestCases;
+import org.apache.airavata.common.utils.DerbyUtil;
+import org.junit.*;
 import org.w3c.dom.Document;
 import org.w3c.dom.NodeList;
 
@@ -32,14 +35,39 @@ import java.io.InputStream;
 /**
  * Test class for session DB authenticator.
  */
-public class SessionDBUserStoreTest extends TestCase {
+public class SessionDBAuthenticatorTest extends DatabaseTestCases {
+
+    @BeforeClass
+    public static void setUpDatabase() throws Exception{
+        DerbyUtil.startDerbyInServerMode(getHostAddress(), getPort(), getUserName(), getPassword());
+
+        waitTillServerStarts();
+
+        String createTable = "create table Persons ( sessionId varchar(255) )";
+        executeSQL(createTable);
+
+        String insertSQL = "INSERT INTO Persons VALUES('1234')";
+        executeSQL(insertSQL);
+    }
+
+    @AfterClass
+    public static void shutDownDatabase() throws Exception {
+        DerbyUtil.stopDerbyServer();
+    }
+
+    @Before
+    public void setUp() throws Exception{
+
+        loadConfigurations();
+
+    }
 
     private SessionDBUserStore sessionDBUserStore = new SessionDBUserStore();
 
     private InputStream configurationFileStream
             = this.getClass().getClassLoader().getResourceAsStream("session-authenticator.xml");
 
-    public void setUp() throws Exception {
+    public void loadConfigurations() throws Exception {
         DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
         DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
         Document doc = dBuilder.parse(configurationFileStream);
@@ -49,12 +77,13 @@ public class SessionDBUserStoreTest exte
         sessionDBUserStore.configure(specificConfigurations.item(0));
     }
 
+    @Test
     public void testAuthenticate() throws Exception {
-        assertTrue(sessionDBUserStore.authenticate("1234"));
-
+        Assert.assertTrue(sessionDBUserStore.authenticate("1234"));
     }
 
+    @Test
     public void testAuthenticateFailure() throws Exception  {
-        assertFalse(sessionDBUserStore.authenticate("12345"));
+        Assert.assertFalse(sessionDBUserStore.authenticate("12345"));
     }
 }

Modified: airavata/trunk/modules/rest/service/src/test/java/org/apache/airavata/services/registry/rest/security/local/LocalUserStoreTest.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/rest/service/src/test/java/org/apache/airavata/services/registry/rest/security/local/LocalUserStoreTest.java?rev=1422068&r1=1422067&r2=1422068&view=diff
==============================================================================
--- airavata/trunk/modules/rest/service/src/test/java/org/apache/airavata/services/registry/rest/security/local/LocalUserStoreTest.java
(original)
+++ airavata/trunk/modules/rest/service/src/test/java/org/apache/airavata/services/registry/rest/security/local/LocalUserStoreTest.java
Fri Dec 14 20:33:05 2012
@@ -1,21 +1,16 @@
 package org.apache.airavata.services.registry.rest.security.local;
 
-import junit.framework.TestCase;
 import org.apache.airavata.common.utils.DBUtil;
+import org.apache.airavata.common.utils.DatabaseTestCases;
+import org.apache.airavata.common.utils.DerbyUtil;
+import org.junit.*;
 
-import java.io.File;
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.sql.Statement;
 import java.util.List;
 
 /**
  * A test class for local user store.
  */
-public class LocalUserStoreTest extends TestCase {
-
-    private DBUtil dbUtil = new DBUtil("jdbc:h2:modules/airavata-rest-services/src/test/resources/testdb/test",
-            "sa", "sa", "org.h2.Driver");
+public class LocalUserStoreTest extends DatabaseTestCases {
 
     private LocalUserStore localUserStore;
 
@@ -25,88 +20,79 @@ public class LocalUserStoreTest extends 
                     "        user_name varchar(255),\n" +
                     "        password varchar(255),\n" +
                     "        PRIMARY KEY(user_name)\n" +
-                    ");";
+                    ")";
+
 
-    private static final String dropTableScript =
-            "drop table Users";
+    @BeforeClass
+    public static void setUpDatabase() throws Exception{
+        DerbyUtil.startDerbyInServerMode(getHostAddress(), getPort(), getUserName(), getPassword());
 
-    private void createTable(Connection connection, String query) {
+        waitTillServerStarts();
 
+        executeSQL(createTableScript);
+
+    }
 
-        Statement stmt = null;
-
-        try {
-            stmt = connection.createStatement();
-            stmt.executeUpdate(query);
-        }
-        catch (Exception e) {
-            e.printStackTrace();
-        } finally {
-            if (stmt != null) {
-                try {
-                    stmt.close();
-                } catch (SQLException e) {
-                    e.printStackTrace();
-                }
-            }
-        }
+    @AfterClass
+    public static void shutDownDatabase() throws Exception {
+        DerbyUtil.stopDerbyServer();
     }
 
+    @Before
     public void setUp() throws Exception{
 
+        DBUtil dbUtil = new DBUtil(getJDBCUrl(), getUserName(), getPassword(), getDriver());
         dbUtil.init();
 
-        File f = new File(".");
-        System.out.println(f.getAbsolutePath());
-
-        Connection connection = dbUtil.getConnection();
-        createTable(connection, dropTableScript);
-        createTable(connection, createTableScript);
-
-        try {
-            connection.close();
-        } catch (SQLException e) {
-            e.printStackTrace();
-        }
-
         localUserStore = new LocalUserStore(dbUtil);
     }
 
+    @Test
     public void testAddUser() throws Exception {
 
         localUserStore.addUser("thejaka", "qwqwqw");
 
         List<String> users = localUserStore.getUsers();
-        assertEquals(1, users.size());
-        assertEquals("thejaka", users.get(0));
+        Assert.assertEquals(1, users.size());
+        Assert.assertEquals("thejaka", users.get(0));
+
+        localUserStore.deleteUser("thejaka");
+
     }
 
+    @Test
     public void testChangePassword() throws Exception {
 
         localUserStore.addUser("thejaka", "qwqwqw");
 
         localUserStore.changePassword("thejaka", "qwqwqw", "sadsad");
+
+        localUserStore.deleteUser("thejaka");
     }
 
+    @Test
     public void testChangePasswordByAdmin() throws Exception {
 
         localUserStore.addUser("thejaka", "qwqwqw");
 
         localUserStore.changePasswordByAdmin("thejaka", "sadsad");
+
+        localUserStore.deleteUser("thejaka");
     }
 
+    @Test
     public void testDeleteUser() throws Exception {
 
         localUserStore.addUser("thejaka", "qwqwqw");
 
         List<String> users = localUserStore.getUsers();
-        assertEquals(1, users.size());
-        assertEquals("thejaka", users.get(0));
+        Assert.assertEquals(1, users.size());
+        Assert.assertEquals("thejaka", users.get(0));
 
         localUserStore.deleteUser("thejaka");
 
         users = localUserStore.getUsers();
-        assertEquals(0, users.size());
+        Assert.assertEquals(0, users.size());
 
     }
 }

Modified: airavata/trunk/modules/rest/service/src/test/resources/jdbc-authenticator.xml
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/rest/service/src/test/resources/jdbc-authenticator.xml?rev=1422068&r1=1422067&r2=1422068&view=diff
==============================================================================
--- airavata/trunk/modules/rest/service/src/test/resources/jdbc-authenticator.xml (original)
+++ airavata/trunk/modules/rest/service/src/test/resources/jdbc-authenticator.xml Fri Dec
14 20:33:05 2012
@@ -26,10 +26,10 @@
         <specificConfigurations>
             <database>
                 <!--jdbcUrl>jdbc:h2:modules/commons/airavata-registry-rest/src/test/resources/testdb/test</jdbcUrl-->
-                <jdbcUrl>jdbc:h2:../../src/test/resources/testdb/test</jdbcUrl>
-                <userName>sa</userName>
-                <password>sa</password>
-                <databaseDriver>org.h2.Driver</databaseDriver>
+                <jdbcUrl>jdbc:derby://localhost:20000/persistent_data;create=true</jdbcUrl>
+                <userName>admin</userName>
+                <password>admin</password>
+                <databaseDriver>org.apache.derby.jdbc.ClientDriver</databaseDriver>
                 <userTableName>AIRAVATA_USER</userTableName>
                 <userNameColumnName>USERID</userNameColumnName>
                 <passwordColumnName>PASSWORD</passwordColumnName>

Modified: airavata/trunk/modules/rest/service/src/test/resources/session-authenticator.xml
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/rest/service/src/test/resources/session-authenticator.xml?rev=1422068&r1=1422067&r2=1422068&view=diff
==============================================================================
--- airavata/trunk/modules/rest/service/src/test/resources/session-authenticator.xml (original)
+++ airavata/trunk/modules/rest/service/src/test/resources/session-authenticator.xml Fri Dec
14 20:33:05 2012
@@ -28,12 +28,12 @@
             <database>
                 <!--jdbcUrl>jdbc:h2:modules/commons/airavata-registry-rest/src/test/resources/testdb/test</jdbcUrl-->
                 <!-- Points to /Users/thejaka/development/apache/airavata/trunk/modules/commons/airavata-registry-rest/target/tomcat6x/.
-->
-                <jdbcUrl>jdbc:h2:../../src/test/resources/testdb/test</jdbcUrl>
+                <jdbcUrl>jdbc:derby://localhost:20000/persistent_data;create=true</jdbcUrl>
                 <!--jdbcUrl>jdbc:h2:modules/security/src/test/resources/testdb/test</jdbcUrl-->
 
-                <userName>sa</userName>
-                <password>sa</password>
-                <databaseDriver>org.h2.Driver</databaseDriver>
+                <userName>admin</userName>
+                <password>admin</password>
+                <databaseDriver>org.apache.derby.jdbc.ClientDriver</databaseDriver>
                 <sessionTable>Persons</sessionTable>
                 <sessionColumn>sessionId</sessionColumn>
                 <comparingColumn>sessionId</comparingColumn>

Modified: airavata/trunk/modules/security/pom.xml
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/security/pom.xml?rev=1422068&r1=1422067&r2=1422068&view=diff
==============================================================================
--- airavata/trunk/modules/security/pom.xml (original)
+++ airavata/trunk/modules/security/pom.xml Fri Dec 14 20:33:05 2012
@@ -52,12 +52,6 @@
             <version>4.7</version>
             <scope>test</scope>
         </dependency>
-        <dependency>
-            <groupId>com.h2database</groupId>
-            <artifactId>h2</artifactId>
-            <version>1.3.168</version>
-            <scope>test</scope>
-        </dependency>
     </dependencies>
     <build>
         <plugins>

Modified: airavata/trunk/modules/security/src/main/java/org/apache/airavata/security/userstore/JDBCUserStore.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/security/src/main/java/org/apache/airavata/security/userstore/JDBCUserStore.java?rev=1422068&r1=1422067&r2=1422068&view=diff
==============================================================================
--- airavata/trunk/modules/security/src/main/java/org/apache/airavata/security/userstore/JDBCUserStore.java
(original)
+++ airavata/trunk/modules/security/src/main/java/org/apache/airavata/security/userstore/JDBCUserStore.java
Fri Dec 14 20:33:05 2012
@@ -60,7 +60,8 @@ public class JDBCUserStore extends Abstr
         try {
             authenticationInfo = jdbcRealm.getAuthenticationInfo(authenticationToken);
         } catch (AuthenticationException e) {
-            log.warn(e.getLocalizedMessage(), e);
+            log.warn(e.getLocalizedMessage());
+            log.debug(e.getLocalizedMessage(), e);
             return false;
         }
 

Modified: airavata/trunk/modules/security/src/test/java/org/apache/airavata/security/userstore/JDBCUserStoreTest.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/security/src/test/java/org/apache/airavata/security/userstore/JDBCUserStoreTest.java?rev=1422068&r1=1422067&r2=1422068&view=diff
==============================================================================
--- airavata/trunk/modules/security/src/test/java/org/apache/airavata/security/userstore/JDBCUserStoreTest.java
(original)
+++ airavata/trunk/modules/security/src/test/java/org/apache/airavata/security/userstore/JDBCUserStoreTest.java
Fri Dec 14 20:33:05 2012
@@ -23,22 +23,20 @@
 
 package org.apache.airavata.security.userstore;
 
-import junit.framework.TestCase;
-import org.apache.airavata.security.Authenticator;
+import org.apache.airavata.common.utils.DatabaseTestCases;
+import org.apache.airavata.common.utils.DerbyUtil;
 import org.apache.airavata.security.UserStore;
-import org.apache.airavata.security.configurations.AuthenticatorConfigurationReader;
+import org.junit.*;
 import org.w3c.dom.Document;
 import org.w3c.dom.NodeList;
 
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
-import java.io.File;
-import java.util.List;
 
 /**
  * Test class for JDBC user store.
  */
-public class JDBCUserStoreTest extends TestCase {
+public class JDBCUserStoreTest extends DatabaseTestCases {
 
     /**
      * <specificConfigurations>
@@ -57,7 +55,29 @@ public class JDBCUserStoreTest extends T
      */
 
 
+    @BeforeClass
+    public static void setUpDatabase() throws Exception{
+        DerbyUtil.startDerbyInServerMode(getHostAddress(), getPort(), getUserName(), getPassword());
 
+        waitTillServerStarts();
+
+        String createTable = "create table AIRAVATA_USER ( USERID varchar(255), PASSWORD
varchar(255) )";
+        executeSQL(createTable);
+
+        String insertSQL = "INSERT INTO AIRAVATA_USER VALUES('amilaj', 'secret')";
+        executeSQL(insertSQL);
+    }
+
+    @AfterClass
+    public static void shutDownDatabase() throws Exception {
+        DerbyUtil.stopDerbyServer();
+    }
+
+    @Before
+    public void setUp() throws Exception{
+    }
+
+    @Test
     public void testAuthenticate() throws Exception {
 
         DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
@@ -69,9 +89,9 @@ public class JDBCUserStoreTest extends T
         UserStore userStore = new JDBCUserStore();
         userStore.configure(configurations.item(0));
 
-        assertTrue(userStore.authenticate("amilaj", "secret"));
-        assertFalse(userStore.authenticate("amilaj", "1secret"));
-        assertFalse(userStore.authenticate("lahiru", "1234"));
+        Assert.assertTrue(userStore.authenticate("amilaj", "secret"));
+        Assert.assertFalse(userStore.authenticate("amilaj", "1secret"));
+        Assert.assertFalse(userStore.authenticate("lahiru", "1234"));
 
     }
 }

Modified: airavata/trunk/modules/security/src/test/java/org/apache/airavata/security/userstore/SessionDBUserStoreTest.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/security/src/test/java/org/apache/airavata/security/userstore/SessionDBUserStoreTest.java?rev=1422068&r1=1422067&r2=1422068&view=diff
==============================================================================
--- airavata/trunk/modules/security/src/test/java/org/apache/airavata/security/userstore/SessionDBUserStoreTest.java
(original)
+++ airavata/trunk/modules/security/src/test/java/org/apache/airavata/security/userstore/SessionDBUserStoreTest.java
Fri Dec 14 20:33:05 2012
@@ -24,6 +24,9 @@
 package org.apache.airavata.security.userstore;
 
 import junit.framework.TestCase;
+import org.apache.airavata.common.utils.DatabaseTestCases;
+import org.apache.airavata.common.utils.DerbyUtil;
+import org.junit.*;
 import org.w3c.dom.Document;
 import org.w3c.dom.NodeList;
 
@@ -35,14 +38,40 @@ import java.io.InputStream;
 /**
  * Test class for session DB authenticator.
  */
-public class SessionDBUserStoreTest extends TestCase {
+
+public class SessionDBUserStoreTest extends DatabaseTestCases {
+
+    @BeforeClass
+    public static void setUpDatabase() throws Exception{
+        DerbyUtil.startDerbyInServerMode(getHostAddress(), getPort(), getUserName(), getPassword());
+
+        waitTillServerStarts();
+
+        String createTable = "create table Persons ( sessionId varchar(255) )";
+        executeSQL(createTable);
+
+        String insertSQL = "INSERT INTO Persons VALUES('1234')";
+        executeSQL(insertSQL);
+    }
+
+    @AfterClass
+    public static void shutDownDatabase() throws Exception {
+        DerbyUtil.stopDerbyServer();
+    }
+
+    @Before
+    public void setUp() throws Exception{
+
+        loadConfigurations();
+
+    }
 
     private SessionDBUserStore sessionDBUserStore = new SessionDBUserStore();
 
     private InputStream configurationFileStream
             = this.getClass().getClassLoader().getResourceAsStream("session-authenticator.xml");
 
-    public void setUp() throws Exception {
+    private void loadConfigurations () throws Exception {
         DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
         DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
         Document doc = dBuilder.parse(configurationFileStream);
@@ -52,12 +81,14 @@ public class SessionDBUserStoreTest exte
         sessionDBUserStore.configure(specificConfigurations.item(0));
     }
 
+    @Test
     public void testAuthenticate() throws Exception {
-        assertTrue(sessionDBUserStore.authenticate("1234"));
+        Assert.assertTrue(sessionDBUserStore.authenticate("1234"));
 
     }
 
+    @Test
     public void testAuthenticateFailure() throws Exception  {
-        assertFalse(sessionDBUserStore.authenticate("12345"));
+        Assert.assertFalse(sessionDBUserStore.authenticate("12345"));
     }
 }

Modified: airavata/trunk/modules/security/src/test/resources/jdbc-authenticator.xml
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/security/src/test/resources/jdbc-authenticator.xml?rev=1422068&r1=1422067&r2=1422068&view=diff
==============================================================================
--- airavata/trunk/modules/security/src/test/resources/jdbc-authenticator.xml (original)
+++ airavata/trunk/modules/security/src/test/resources/jdbc-authenticator.xml Fri Dec 14 20:33:05
2012
@@ -26,10 +26,10 @@
         <specificConfigurations>
             <database>
                 <!--jdbcUrl>jdbc:h2:modules/commons/airavata-registry-rest/src/test/resources/testdb/test</jdbcUrl-->
-                <jdbcUrl>jdbc:h2:../../src/test/resources/testdb/test</jdbcUrl>
-                <userName>sa</userName>
-                <password>sa</password>
-                <databaseDriver>org.h2.Driver</databaseDriver>
+                <jdbcUrl>jdbc:derby://localhost:20000/persistent_data;create=true</jdbcUrl>
+                <userName>admin</userName>
+                <password>admin</password>
+                <databaseDriver>org.apache.derby.jdbc.ClientDriver</databaseDriver>
                 <userTableName>AIRAVATA_USER</userTableName>
                 <userNameColumnName>USERID</userNameColumnName>
                 <passwordColumnName>PASSWORD</passwordColumnName>

Modified: airavata/trunk/modules/security/src/test/resources/session-authenticator.xml
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/security/src/test/resources/session-authenticator.xml?rev=1422068&r1=1422067&r2=1422068&view=diff
==============================================================================
--- airavata/trunk/modules/security/src/test/resources/session-authenticator.xml (original)
+++ airavata/trunk/modules/security/src/test/resources/session-authenticator.xml Fri Dec 14
20:33:05 2012
@@ -28,12 +28,13 @@
             <database>
                 <!--jdbcUrl>jdbc:h2:modules/commons/airavata-registry-rest/src/test/resources/testdb/test</jdbcUrl-->
                 <!-- Points to /Users/thejaka/development/apache/airavata/trunk/modules/commons/airavata-registry-rest/target/tomcat6x/.
-->
-                <jdbcUrl>jdbc:h2:../../src/test/resources/testdb/test</jdbcUrl>
+                <jdbcUrl>jdbc:derby://localhost:20000/persistent_data;create=true</jdbcUrl>
+
                 <!--jdbcUrl>jdbc:h2:modules/security/src/test/resources/testdb/test</jdbcUrl-->
 
-                <userName>sa</userName>
-                <password>sa</password>
-                <databaseDriver>org.h2.Driver</databaseDriver>
+                <userName>admin</userName>
+                <password>admin</password>
+                <databaseDriver>org.apache.derby.jdbc.ClientDriver</databaseDriver>
                 <sessionTable>Persons</sessionTable>
                 <sessionColumn>sessionId</sessionColumn>
                 <comparingColumn>sessionId</comparingColumn>



Mime
View raw message