You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by ja...@apache.org on 2013/08/26 17:26:54 UTC

[5/8] git commit: Converted test in kiwi-transactions to use the KiWiDatabaseRunner

Converted test in kiwi-transactions to use the KiWiDatabaseRunner

Project: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/commit/bd477fed
Tree: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/tree/bd477fed
Diff: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/diff/bd477fed

Branch: refs/heads/develop
Commit: bd477fedf60ea6dee9853618a23c242ebb9f7a9c
Parents: d0f0c69
Author: Jakob Frank <ja...@apache.org>
Authored: Mon Aug 26 16:29:16 2013 +0200
Committer: Jakob Frank <ja...@apache.org>
Committed: Mon Aug 26 16:29:16 2013 +0200

----------------------------------------------------------------------
 .../marmotta/kiwi/test/TransactionTest.java     | 128 ++++---------------
 1 file changed, 23 insertions(+), 105 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/bd477fed/libraries/kiwi/kiwi-transactions/src/test/java/org/apache/marmotta/kiwi/test/TransactionTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-transactions/src/test/java/org/apache/marmotta/kiwi/test/TransactionTest.java b/libraries/kiwi/kiwi-transactions/src/test/java/org/apache/marmotta/kiwi/test/TransactionTest.java
index af79558..e5aaa78 100644
--- a/libraries/kiwi/kiwi-transactions/src/test/java/org/apache/marmotta/kiwi/test/TransactionTest.java
+++ b/libraries/kiwi/kiwi-transactions/src/test/java/org/apache/marmotta/kiwi/test/TransactionTest.java
@@ -17,16 +17,19 @@
  */
 package org.apache.marmotta.kiwi.test;
 
+import static org.hamcrest.CoreMatchers.hasItems;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.junit.Assume.assumeThat;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.sql.SQLException;
+import java.util.List;
+
 import org.apache.marmotta.commons.sesame.repository.ResourceUtils;
-import com.google.common.base.Function;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
-import org.apache.marmotta.kiwi.persistence.KiWiDialect;
-import org.apache.marmotta.kiwi.persistence.h2.H2Dialect;
-import org.apache.marmotta.kiwi.persistence.mysql.MySQLDialect;
-import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect;
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
 import org.apache.marmotta.kiwi.sail.KiWiStore;
-import org.apache.marmotta.kiwi.test.helper.DBConnectionChecker;
+import org.apache.marmotta.kiwi.test.junit.KiWiDatabaseRunner;
 import org.apache.marmotta.kiwi.transactions.api.TransactionListener;
 import org.apache.marmotta.kiwi.transactions.model.TransactionData;
 import org.apache.marmotta.kiwi.transactions.sail.KiWiTransactionalSail;
@@ -38,7 +41,6 @@ import org.junit.Test;
 import org.junit.rules.TestWatcher;
 import org.junit.runner.Description;
 import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
 import org.openrdf.model.Resource;
 import org.openrdf.repository.Repository;
 import org.openrdf.repository.RepositoryConnection;
@@ -49,82 +51,19 @@ import org.openrdf.rio.RDFParseException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.hasItems;
-import static org.hamcrest.CoreMatchers.notNullValue;
-import static org.junit.Assume.assumeThat;
+import com.google.common.base.Function;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
 
 /**
- * Test the Sesame repository functionality backed by the KiWi triple store. It will try running over all
- * available databases. Except for in-memory databases like H2 or Derby, database URLs must be passed as
- * system property, or otherwise the test is skipped for this database. Available system properties:
- * <ul>
- *     <li>PostgreSQL:
- *     <ul>
- *         <li>postgresql.url, e.g. jdbc:postgresql://localhost:5433/kiwitest?prepareThreshold=3</li>
- *         <li>postgresql.user (default: lmf)</li>
- *         <li>postgresql.pass (default: lmf)</li>
- *     </ul>
- *     </li>
- *     <li>MySQL:
- *     <ul>
- *         <li>mysql.url, e.g. jdbc:mysql://localhost:3306/kiwitest?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull</li>
- *         <li>mysql.user (default: lmf)</li>
- *         <li>mysql.pass (default: lmf)</li>
- *     </ul>
- *     </li>
- *     <li>H2:
- *     <ul>
- *         <li>h2.url, e.g. jdbc:h2:mem;MVCC=true;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=10</li>
- *         <li>h2.user (default: lmf)</li>
- *         <li>h2.pass (default: lmf)</li>
- *     </ul>
- *     </li>
- * </ul>
- * <p/>
- * Author: Sebastian Schaffert
+ * Test the Sesame repository functionality backed by the KiWi triple store. 
+ * 
+ * @author Sebastian Schaffert (sebastian.schaffert@apache.org)
  */
-@RunWith(Parameterized.class)
+@RunWith(KiWiDatabaseRunner.class)
 public class TransactionTest {
     private static Logger log = LoggerFactory.getLogger(TransactionTest.class);
 
-    /**
-     * Return database configurations if the appropriate parameters have been set.
-     *
-     * @return an array (database name, url, user, password)
-     */
-    @Parameterized.Parameters(name="Database Test {index}: {0} at {1}")
-    public static Iterable<Object[]> databases() {
-        String[] databases = {"H2", "PostgreSQL", "MySQL"};
-
-        List<Object[]> result = new ArrayList<Object[]>(databases.length);
-        for(String database : databases) {
-            if(System.getProperty(database.toLowerCase()+".url") != null) {
-                result.add(new Object[] {
-                        database,
-                        System.getProperty(database.toLowerCase()+".url"),
-                        System.getProperty(database.toLowerCase()+".user","lmf"),
-                        System.getProperty(database.toLowerCase()+".pass","lmf")
-                });
-            }
-        }
-        return result;
-    }
-
-
-    private KiWiDialect dialect;
-
-    private String jdbcUrl;
-
-    private String jdbcUser;
-
-    private String jdbcPass;
-
     private Repository repository;
 
     private KiWiStore store;
@@ -133,25 +72,15 @@ public class TransactionTest {
 
     private MockListener listener;
 
-    public TransactionTest(String database, String jdbcUrl, String jdbcUser, String jdbcPass) {
-        this.jdbcPass = jdbcPass;
-        this.jdbcUrl = jdbcUrl;
-        this.jdbcUser = jdbcUser;
-
-        if("H2".equals(database)) {
-            this.dialect = new H2Dialect();
-        } else if("MySQL".equals(database)) {
-            this.dialect = new MySQLDialect();
-        } else if("PostgreSQL".equals(database)) {
-            this.dialect = new PostgreSQLDialect();
-        }
-        
-        DBConnectionChecker.checkDatabaseAvailability(jdbcUrl, jdbcUser, jdbcPass, dialect);
+    private final KiWiConfiguration kiwiConfiguration;
+
+    public TransactionTest(KiWiConfiguration configuration) {
+        this.kiwiConfiguration = configuration;
     }
 
     @Before
     public void initDatabase() throws RepositoryException {
-        store = new KiWiStore("test",jdbcUrl,jdbcUser,jdbcPass,dialect, "http://localhost/context/default", "http://localhost/context/inferred");
+        store = new KiWiStore(kiwiConfiguration);
         tstore = new KiWiTransactionalSail(store);
         listener = new MockListener();
         tstore.addTransactionListener(listener);
@@ -165,17 +94,6 @@ public class TransactionTest {
         repository.shutDown();
     }
 
-    @Rule
-    public TestWatcher watchman = new TestWatcher() {
-        /**
-         * Invoked when a test is about to start
-         */
-        @Override
-        protected void starting(Description description) {
-            log.info("{} being run...", description.getMethodName());
-        }
-    };
-
 
     /**
      * Test importing data; the test will load a small sample RDF file and check whether the expected resources are