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/23 18:08:21 UTC
git commit: Implemented a special JUnit Runner to replace the
Parameterized Runner which is used for the database-related tests.
Updated Branches:
refs/heads/develop 068ffc5fa -> a20d93573
Implemented a special JUnit Runner to replace the Parameterized Runner
which is used for the database-related tests.
The KiWiDatabaseRunner works similar to a "normal" Parameterized Runner
but:
* expects a field of type KiWiConfiguration, annotated with @KiWiConfig,
or:
* a constructor accepting exactly one parameter of type
KiWiConfiguration
Availability is checked directly by the runner, H2 is always tested.
(will be gradually used in the KiWi-Tests, such as MARMOTTA-285 and
MARMOTTA-287)
Project: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/commit/a20d9357
Tree: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/tree/a20d9357
Diff: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/diff/a20d9357
Branch: refs/heads/develop
Commit: a20d9357313ed9818551507bbc60b302262d6c03
Parents: 068ffc5
Author: Jakob Frank <ja...@apache.org>
Authored: Fri Aug 23 18:04:31 2013 +0200
Committer: Jakob Frank <ja...@apache.org>
Committed: Fri Aug 23 18:07:58 2013 +0200
----------------------------------------------------------------------
.../apache/marmotta/kiwi/test/DialectTest.java | 68 +----
.../marmotta/kiwi/test/H2ConcurrencyTest.java | 34 +--
.../kiwi/test/MySQLConcurrencyTest.java | 22 +-
.../marmotta/kiwi/test/PersistenceTest.java | 150 +++-------
.../kiwi/test/PostgreSQLConcurrencyTest.java | 3 +-
.../marmotta/kiwi/test/RepositoryTest.java | 113 ++-----
.../kiwi/test/helper/DBConnectionChecker.java | 95 ++++--
.../kiwi/test/junit/DatabaseRunnerTest1.java | 39 +++
.../kiwi/test/junit/DatabaseRunnerTest2.java | 37 +++
.../kiwi/test/junit/KiWiDatabaseRunner.java | 296 +++++++++++++++++++
.../test/sesame/KiWiSailConcurrencyTest.java | 90 +-----
.../kiwi/test/sesame/KiWiSailInterruptTest.java | 64 +---
.../kiwi/test/sesame/KiWiStoreTest.java | 88 +-----
13 files changed, 553 insertions(+), 546 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/a20d9357/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/DialectTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/DialectTest.java b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/DialectTest.java
index a7ad54d..286d1aa 100644
--- a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/DialectTest.java
+++ b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/DialectTest.java
@@ -17,66 +17,32 @@
*/
package org.apache.marmotta.kiwi.test;
+import static org.hamcrest.Matchers.hasItem;
+
+import java.util.Set;
+
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
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.test.junit.KiWiDatabaseRunner;
import org.junit.Assert;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.MethodRule;
-import org.junit.rules.TestWatcher;
-import org.junit.rules.TestWatchman;
-import org.junit.runner.Description;
import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.model.FrameworkMethod;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-
-import static org.hamcrest.Matchers.hasItem;
-
/**
* Test if the dialects returns correct values
* <p/>
- * Author: Sebastian Schaffert
+ * @author Sebastian Schaffert
*/
-@RunWith(Parameterized.class)
+@RunWith(KiWiDatabaseRunner.class)
public class DialectTest {
- public KiWiDialect dialect;
-
-
- /**
- * Return database configurations if the appropriate parameters have been set.
- *
- * @return an array (database name)
- */
- @Parameterized.Parameters(name="Database Test {index}: {0}")
- public static Iterable<Object[]> databases() {
- String[] databases = {"H2", "PostgreSQL", "MySQL"};
-
- List<Object[]> result = new ArrayList<Object[]>(databases.length);
- for(String database : databases) {
- result.add(new Object[] {
- database
- });
- }
- return result;
- }
+ public final KiWiDialect dialect;
+
- public DialectTest(String database) {
- 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();
- }
+ public DialectTest(KiWiConfiguration configuration) {
+ this.dialect = configuration.getDialect();
}
@Test
@@ -122,15 +88,5 @@ public class DialectTest {
final Logger logger =
LoggerFactory.getLogger(DialectTest.class);
- @Rule
- public TestWatcher watchman = new TestWatcher() {
- /**
- * Invoked when a test is about to start
- */
- @Override
- protected void starting(Description description) {
- logger.info("{} being run...", description.getMethodName());
- }
- };
}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/a20d9357/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/H2ConcurrencyTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/H2ConcurrencyTest.java b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/H2ConcurrencyTest.java
index 8d8de9c..3d02b1c 100644
--- a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/H2ConcurrencyTest.java
+++ b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/H2ConcurrencyTest.java
@@ -1,38 +1,22 @@
package org.apache.marmotta.kiwi.test;
-import com.google.code.tempusfugit.concurrency.ConcurrentRule;
-import com.google.code.tempusfugit.concurrency.RepeatingRule;
-import com.google.code.tempusfugit.concurrency.annotations.Concurrent;
-import com.google.code.tempusfugit.concurrency.annotations.Repeating;
-import org.apache.commons.lang3.RandomStringUtils;
+import static org.junit.Assert.assertTrue;
+
+import java.sql.SQLException;
+import java.util.Random;
+
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
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.sail.KiWiStore;
import org.apache.marmotta.kiwi.test.helper.DBConnectionChecker;
-import org.junit.*;
-import org.junit.rules.TestWatcher;
-import org.junit.runner.Description;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.openrdf.model.URI;
-import org.openrdf.model.Value;
-import org.openrdf.repository.Repository;
-import org.openrdf.repository.RepositoryConnection;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
import org.openrdf.repository.RepositoryException;
import org.openrdf.repository.sail.SailRepository;
import org.openrdf.sail.SailException;
-import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Random;
-
-import static org.junit.Assert.assertTrue;
-
/**
* This test starts many triplestore operations in parallel to check if concurrent operations will break things,
*
@@ -92,7 +76,7 @@ public class H2ConcurrencyTest extends ConcurrencyTestBase {
DBConnectionChecker.checkDatabaseAvailability(jdbcUrl, jdbcUser, jdbcPass, dialect);
- store = new KiWiStore("test",jdbcUrl,jdbcUser,jdbcPass,dialect, "http://localhost/context/default", "http://localhost/context/inferred" );
+ store = new KiWiStore(new KiWiConfiguration("test",jdbcUrl,jdbcUser,jdbcPass,dialect, "http://localhost/context/default", "http://localhost/context/inferred" ));
repository = new SailRepository(store);
repository.initialize();
}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/a20d9357/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/MySQLConcurrencyTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/MySQLConcurrencyTest.java b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/MySQLConcurrencyTest.java
index d38123a..98f69d6 100644
--- a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/MySQLConcurrencyTest.java
+++ b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/MySQLConcurrencyTest.java
@@ -1,36 +1,22 @@
package org.apache.marmotta.kiwi.test;
+import static org.junit.Assert.assertTrue;
+
import java.sql.SQLException;
import java.util.Random;
-import org.apache.commons.lang3.RandomStringUtils;
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
import org.apache.marmotta.kiwi.persistence.KiWiDialect;
import org.apache.marmotta.kiwi.persistence.mysql.MySQLDialect;
import org.apache.marmotta.kiwi.sail.KiWiStore;
import org.apache.marmotta.kiwi.test.helper.DBConnectionChecker;
import org.junit.AfterClass;
import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TestWatcher;
-import org.junit.runner.Description;
-import org.openrdf.model.URI;
-import org.openrdf.model.Value;
-import org.openrdf.repository.Repository;
-import org.openrdf.repository.RepositoryConnection;
import org.openrdf.repository.RepositoryException;
import org.openrdf.repository.sail.SailRepository;
import org.openrdf.sail.SailException;
-import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.code.tempusfugit.concurrency.ConcurrentRule;
-import com.google.code.tempusfugit.concurrency.RepeatingRule;
-import com.google.code.tempusfugit.concurrency.annotations.Concurrent;
-import com.google.code.tempusfugit.concurrency.annotations.Repeating;
-
-import static org.junit.Assert.assertTrue;
-
/**
* This test starts many triplestore operations in parallel to check if concurrent operations will break things,
*
@@ -90,7 +76,7 @@ public class MySQLConcurrencyTest extends ConcurrencyTestBase {
DBConnectionChecker.checkDatabaseAvailability(jdbcUrl, jdbcUser, jdbcPass, dialect);
- store = new KiWiStore("test",jdbcUrl,jdbcUser,jdbcPass,dialect, "http://localhost/context/default", "http://localhost/context/inferred" );
+ store = new KiWiStore(new KiWiConfiguration("test",jdbcUrl,jdbcUser,jdbcPass,dialect, "http://localhost/context/default", "http://localhost/context/inferred" ));
repository = new SailRepository(store);
repository.initialize();
}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/a20d9357/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/PersistenceTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/PersistenceTest.java b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/PersistenceTest.java
index a51b701..e390feb 100644
--- a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/PersistenceTest.java
+++ b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/PersistenceTest.java
@@ -18,134 +18,67 @@
package org.apache.marmotta.kiwi.test;
import static org.apache.marmotta.commons.sesame.model.LiteralCommons.getRDFLangStringType;
+import static org.hamcrest.Matchers.hasItem;
+import static org.hamcrest.Matchers.hasItems;
+import info.aduna.iteration.Iterations;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Date;
+import java.util.List;
+import java.util.Locale;
+import java.util.Random;
+import org.apache.commons.lang3.RandomStringUtils;
import org.apache.marmotta.commons.sesame.model.Namespaces;
import org.apache.marmotta.commons.util.DateUtils;
-import info.aduna.iteration.Iterations;
-import org.apache.commons.lang3.RandomStringUtils;
-import org.apache.marmotta.kiwi.model.rdf.*;
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+import org.apache.marmotta.kiwi.model.rdf.KiWiAnonResource;
+import org.apache.marmotta.kiwi.model.rdf.KiWiBooleanLiteral;
+import org.apache.marmotta.kiwi.model.rdf.KiWiDateLiteral;
+import org.apache.marmotta.kiwi.model.rdf.KiWiDoubleLiteral;
+import org.apache.marmotta.kiwi.model.rdf.KiWiIntLiteral;
+import org.apache.marmotta.kiwi.model.rdf.KiWiLiteral;
+import org.apache.marmotta.kiwi.model.rdf.KiWiNamespace;
+import org.apache.marmotta.kiwi.model.rdf.KiWiNode;
+import org.apache.marmotta.kiwi.model.rdf.KiWiResource;
+import org.apache.marmotta.kiwi.model.rdf.KiWiStringLiteral;
+import org.apache.marmotta.kiwi.model.rdf.KiWiTriple;
+import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
import org.apache.marmotta.kiwi.persistence.KiWiConnection;
-import org.apache.marmotta.kiwi.persistence.KiWiDialect;
import org.apache.marmotta.kiwi.persistence.KiWiPersistence;
-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.test.helper.DBConnectionChecker;
+import org.apache.marmotta.kiwi.test.junit.KiWiDatabaseRunner;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
-import org.junit.Rule;
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.Statement;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Locale;
-import java.util.Random;
-
-import static org.hamcrest.Matchers.hasItem;
-import static org.hamcrest.Matchers.hasItems;
/**
- * This test verifies the persistence functionality of 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>
+ * This test verifies the persistence functionality of the KiWi triple store.
*
* @see org.apache.marmotta.kiwi.persistence.KiWiConnection
* @see org.apache.marmotta.kiwi.persistence.KiWiPersistence
- * <p/>
- * Author: Sebastian Schaffert
+ * @author Sebastian Schaffert
*/
-@RunWith(Parameterized.class)
+@RunWith(KiWiDatabaseRunner.class)
public class PersistenceTest {
- /**
- * 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 KiWiPersistence persistence;
- public PersistenceTest(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 kiwiConfig;
+
+ public PersistenceTest(KiWiConfiguration kiwiConfig) {
+ this.kiwiConfig = kiwiConfig;
}
@Before
public void initDatabase() throws SQLException {
- persistence = new KiWiPersistence("test",jdbcUrl,jdbcUser,jdbcPass,dialect);
+ persistence = new KiWiPersistence(kiwiConfig);
persistence.initDatabase();
}
@@ -156,21 +89,6 @@ public class PersistenceTest {
}
- final Logger logger =
- LoggerFactory.getLogger(PersistenceTest.class);
-
- @Rule
- public TestWatcher watchman = new TestWatcher() {
- /**
- * Invoked when a test is about to start
- */
- @Override
- protected void starting(Description description) {
- logger.info("{} being run...", description.getMethodName());
- }
- };
-
-
@Test
public void testCreateDropDatabase() throws SQLException {
// test if database exists and has a version
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/a20d9357/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/PostgreSQLConcurrencyTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/PostgreSQLConcurrencyTest.java b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/PostgreSQLConcurrencyTest.java
index 9e1b8c9..ddd9b2d 100644
--- a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/PostgreSQLConcurrencyTest.java
+++ b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/PostgreSQLConcurrencyTest.java
@@ -3,6 +3,7 @@ package org.apache.marmotta.kiwi.test;
import java.sql.SQLException;
import java.util.Random;
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
import org.apache.marmotta.kiwi.persistence.KiWiDialect;
import org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect;
import org.apache.marmotta.kiwi.sail.KiWiStore;
@@ -75,7 +76,7 @@ public class PostgreSQLConcurrencyTest extends ConcurrencyTestBase {
DBConnectionChecker.checkDatabaseAvailability(jdbcUrl, jdbcUser, jdbcPass, dialect);
- store = new KiWiStore("test",jdbcUrl,jdbcUser,jdbcPass,dialect, "http://localhost/context/default", "http://localhost/context/inferred" );
+ store = new KiWiStore(new KiWiConfiguration("test",jdbcUrl,jdbcUser,jdbcPass,dialect, "http://localhost/context/default", "http://localhost/context/inferred" ));
repository = new SailRepository(store);
repository.initialize();
}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/a20d9357/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/RepositoryTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/RepositoryTest.java b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/RepositoryTest.java
index 59507c2..4d2e291 100644
--- a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/RepositoryTest.java
+++ b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/RepositoryTest.java
@@ -17,27 +17,31 @@
*/
package org.apache.marmotta.kiwi.test;
-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 static org.hamcrest.CoreMatchers.hasItems;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.Matchers.hasItem;
+import static org.hamcrest.Matchers.hasProperty;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.lessThan;
+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.commons.lang3.RandomStringUtils;
-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.commons.sesame.repository.ResourceUtils;
+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.hamcrest.CoreMatchers;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
-import org.junit.Rule;
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.Literal;
import org.openrdf.model.Namespace;
import org.openrdf.model.Resource;
@@ -56,18 +60,9 @@ 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.not;
-import static org.hamcrest.CoreMatchers.notNullValue;
-import static org.hamcrest.Matchers.hasItem;
-import static org.hamcrest.Matchers.*;
-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
@@ -99,66 +94,25 @@ import static org.junit.Assume.assumeThat;
* <p/>
* Author: Sebastian Schaffert
*/
-@RunWith(Parameterized.class)
+@RunWith(KiWiDatabaseRunner.class)
public class RepositoryTest {
private static Logger log = LoggerFactory.getLogger(RepositoryTest.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;
- public RepositoryTest(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, this.dialect);
+ private final KiWiConfiguration kiwiConfiguration;
+
+ public RepositoryTest(KiWiConfiguration kiwiConfiguration) {
+ this.kiwiConfiguration = kiwiConfiguration;
+
}
@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);
repository = new SailRepository(store);
repository.initialize();
}
@@ -170,19 +124,6 @@ public class RepositoryTest {
repository.shutDown();
}
- final Logger logger =
- LoggerFactory.getLogger(RepositoryTest.class);
-
- @Rule
- public TestWatcher watchman = new TestWatcher() {
- /**
- * Invoked when a test is about to start
- */
- @Override
- protected void starting(Description description) {
- logger.info("{} being run...", description.getMethodName());
- }
- };
/**
* Test importing data; the test will load a small sample RDF file and check whether the expected resources are
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/a20d9357/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/helper/DBConnectionChecker.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/helper/DBConnectionChecker.java b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/helper/DBConnectionChecker.java
index 6b429f4..49eae30 100644
--- a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/helper/DBConnectionChecker.java
+++ b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/helper/DBConnectionChecker.java
@@ -1,4 +1,4 @@
-/**
+/*
* 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
@@ -17,33 +17,84 @@
*/
package org.apache.marmotta.kiwi.test.helper;
-import org.apache.marmotta.kiwi.persistence.KiWiDialect;
-import org.junit.Assume;
-
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+import org.apache.marmotta.kiwi.persistence.KiWiDialect;
+import org.junit.Assume;
+import org.junit.internal.AssumptionViolatedException;
+
public class DBConnectionChecker {
- private DBConnectionChecker() {
- // static only
- }
-
- public static void checkDatabaseAvailability(String jdbcUrl, String jdbcUser,
- String jdbcPass, KiWiDialect dialect) {
- try {
- Class.forName(dialect.getDriverClass());
- Connection conn = DriverManager.getConnection(jdbcUrl, jdbcUser, jdbcPass);
+ private DBConnectionChecker() {
+ // static only
+ }
+
+ /**
+ * Check availability of the Database.
+ * @param jdbcUrl - the jdbcURL
+ * @param jdbcUser - the user
+ * @param jdbcPass - the password
+ * @param dialect - the {@link KiWiDialect}
+ * @throws AssumptionViolatedException if the database is not available.
+ */
+ public static void checkDatabaseAvailability(String jdbcUrl, String jdbcUser,
+ String jdbcPass, KiWiDialect dialect) throws AssumptionViolatedException {
+ try {
+ Class.forName(dialect.getDriverClass());
+ Connection conn = DriverManager.getConnection(jdbcUrl, jdbcUser, jdbcPass);
conn.setAutoCommit(false);
- Assume.assumeTrue("Database not available", conn.isValid(1000));
- conn.commit();
- conn.close();
- } catch (SQLException e) {
- Assume.assumeNoException("Database not available", e);
- } catch (ClassNotFoundException e) {
- Assume.assumeNoException("Missing DB driver", e);
- }
- }
+ Assume.assumeTrue("Database not available", conn.isValid(1000));
+ conn.commit();
+ conn.close();
+ } catch (SQLException e) {
+ Assume.assumeNoException("Database not available", e);
+ } catch (ClassNotFoundException e) {
+ Assume.assumeNoException("Missing DB driver", e);
+ }
+ }
+
+ /**
+ * Check availability of the Database.
+ * @param config the {@link KiWiConfiguration} to test
+ * @throws AssumptionViolatedException if the database is not available.
+ */
+ public static void checkDatabaseAvailability(KiWiConfiguration config) throws AssumptionViolatedException {
+ checkDatabaseAvailability(config.getJdbcUrl(), config.getDbUser(), config.getDbPassword(), config.getDialect());
+ }
+
+ /**
+ * Check the availability of the Database.
+ * @param jdbcUrl - the jdbcURL
+ * @param jdbcUser - the user
+ * @param jdbcPass - the password
+ * @param dialect - the {@link KiWiDialect}
+ * @return {@code true} if the database is available, {@code false} if not
+ */
+ public static boolean isDatabaseAvailable(String jdbcUrl, String jdbcUser,
+ String jdbcPass, KiWiDialect dialect) {
+ try {
+ checkDatabaseAvailability(jdbcUrl, jdbcUser, jdbcPass, dialect);
+ return true;
+ } catch (AssumptionViolatedException ave) {
+ return false;
+ }
+ }
+
+ /**
+ * Check availability of the Database.
+ * @param config the {@link KiWiConfiguration} to test
+ * @return {@code true} if the database is available, {@code false} if not
+ */
+ public static boolean isDatabaseAvailable(KiWiConfiguration config) {
+ try {
+ checkDatabaseAvailability(config);
+ return true;
+ } catch (AssumptionViolatedException ave) {
+ return false;
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/a20d9357/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/junit/DatabaseRunnerTest1.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/junit/DatabaseRunnerTest1.java b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/junit/DatabaseRunnerTest1.java
new file mode 100644
index 0000000..7c6a9d3
--- /dev/null
+++ b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/junit/DatabaseRunnerTest1.java
@@ -0,0 +1,39 @@
+/*
+ * 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.
+ */
+package org.apache.marmotta.kiwi.test.junit;
+
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(KiWiDatabaseRunner.class)
+public class DatabaseRunnerTest1 {
+
+ private final KiWiConfiguration dbConfig;
+
+ public DatabaseRunnerTest1(KiWiConfiguration dbConfig) {
+ this.dbConfig = dbConfig;
+ }
+
+ @Test
+ public void testDatabase() {
+ Assert.assertNotNull(dbConfig);
+ System.out.println("Running test with " + dbConfig.getName());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/a20d9357/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/junit/DatabaseRunnerTest2.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/junit/DatabaseRunnerTest2.java b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/junit/DatabaseRunnerTest2.java
new file mode 100644
index 0000000..8757672
--- /dev/null
+++ b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/junit/DatabaseRunnerTest2.java
@@ -0,0 +1,37 @@
+/*
+ * 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.
+ */
+package org.apache.marmotta.kiwi.test.junit;
+
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(KiWiDatabaseRunner.class)
+public class DatabaseRunnerTest2 {
+
+ @KiWiDatabaseRunner.KiWiConfig
+ public KiWiConfiguration dbConfig;
+
+ @Test
+ public void testDatabase() {
+ Assert.assertNotNull(dbConfig);
+ System.out.println("Running test with " + dbConfig.getName());
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/a20d9357/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/junit/KiWiDatabaseRunner.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/junit/KiWiDatabaseRunner.java b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/junit/KiWiDatabaseRunner.java
new file mode 100644
index 0000000..4f15c38
--- /dev/null
+++ b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/junit/KiWiDatabaseRunner.java
@@ -0,0 +1,296 @@
+/*
+ * 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.
+ */
+package org.apache.marmotta.kiwi.test.junit;
+
+import java.lang.annotation.Annotation;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+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.test.helper.DBConnectionChecker;
+import org.junit.internal.AssumptionViolatedException;
+import org.junit.rules.MethodRule;
+import org.junit.rules.TestWatcher;
+import org.junit.runner.Runner;
+import org.junit.runner.notification.RunNotifier;
+import org.junit.runners.BlockJUnit4ClassRunner;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Suite;
+import org.junit.runners.model.FrameworkField;
+import org.junit.runners.model.FrameworkMethod;
+import org.junit.runners.model.InitializationError;
+import org.junit.runners.model.Statement;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Specialized {@link Parameterized} runner for UnitTests that injects the database config for KiWi.
+ * <p>
+ * 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: kiwi)</li>
+ * <li>postgresql.pass (default: kiwi)</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: kiwi)</li>
+ * <li>mysql.pass (default: kiwi)</li>
+ * </ul>
+ * </li>
+ * <li>H2:
+ * <ul>
+ * <li>h2.url, e.g. jdbc:h2:mem:kiwitest;MVCC=true;DB_CLOSE_ON_EXIT=TRUE</li>
+ * <li>h2.user (default: kiwi)</li>
+ * <li>h2.pass (default: kiwi)</li>
+ * </ul>
+ * </li>
+ * </ul>
+ * @author Jakob Frank <ja...@apache.org>
+ *
+ */
+public class KiWiDatabaseRunner extends Suite {
+
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target(ElementType.FIELD)
+ public static @interface KiWiConfig {
+ }
+
+ private final ArrayList<Runner> runners = new ArrayList<Runner>();
+
+ public KiWiDatabaseRunner(Class<?> klass) throws Throwable {
+ super(klass, Collections.<Runner>emptyList());
+
+ createRunners();
+ }
+
+ private void createRunners() throws InitializationError {
+ List<KiWiConfiguration> configs = new ArrayList<>();
+ createKiWiConfig("H2", new H2Dialect(), configs);
+ createKiWiConfig("PostgreSQL", new PostgreSQLDialect(), configs);
+ createKiWiConfig("MySQL", new MySQLDialect(), configs);
+
+ for (KiWiConfiguration config : configs) {
+ final DatabaseTestClassRunner runner = new DatabaseTestClassRunner(getTestClass().getJavaClass(), config);
+ runners.add(runner);
+ }
+ }
+
+ private void createKiWiConfig(String database, KiWiDialect dialect, List<KiWiConfiguration> configs) {
+ KiWiConfiguration c = createKiWiConfig(database, dialect);
+ if (c!=null) configs.add(c);
+ }
+
+ private KiWiConfiguration createKiWiConfig(String database, KiWiDialect dialect) {
+ final KiWiConfiguration config;
+ if(System.getProperty(database.toLowerCase()+".url") != null) {
+ config = new KiWiConfiguration(
+ database,
+ System.getProperty(database.toLowerCase()+".url"),
+ System.getProperty(database.toLowerCase()+".user","kiwi"),
+ System.getProperty(database.toLowerCase()+".pass","kiwi"),
+ dialect);
+ } else if (dialect instanceof H2Dialect) {
+ config = new KiWiConfiguration(
+ "default-H2",
+ "jdbc:h2:mem:kiwitest;MVCC=true;DB_CLOSE_ON_EXIT=TRUE",
+ "kiwi", "kiwi",
+ dialect);
+ } else {
+ return null;
+ }
+ config.setDefaultContext("http://localhost/context/default");
+ config.setInferredContext("http://localhost/context/inferred");
+ return config;
+ }
+
+ @Override
+ protected List<Runner> getChildren() {
+ return runners;
+ }
+
+ private class DatabaseTestClassRunner extends BlockJUnit4ClassRunner {
+
+ private final KiWiConfiguration config;
+
+ private final Logger logger;
+
+ private final CheckDBRule checkDB;
+ private final ExecutionLogger loggerRule;
+
+ public DatabaseTestClassRunner(Class<?> klass, KiWiConfiguration config)
+ throws InitializationError {
+ super(klass);
+ logger = LoggerFactory.getLogger(klass);
+ this.config = config;
+
+ checkDB = new CheckDBRule(config);
+ loggerRule = new ExecutionLogger();
+ }
+
+ @Override
+ protected Object createTest() throws Exception {
+ if (fieldAnnotated()) {
+ Object testInstance = getTestClass().getOnlyConstructor().newInstance();
+ List<FrameworkField> configFields = getFieldsAnnotatedByKiWiConfig();
+ for (FrameworkField field : configFields) {
+ try {
+ field.getField().set(testInstance, config);
+ } catch (IllegalArgumentException iae) {
+ throw new Exception(getTestClass().getName() + ": Trying to set " + field.getName() + " that has a wrong type.");
+ }
+ }
+ return testInstance;
+ }
+ return getTestClass().getOnlyConstructor().newInstance(config);
+ }
+
+ @Override
+ protected List<MethodRule> rules(Object target) {
+ LinkedList<MethodRule> rules = new LinkedList<>();
+ rules.add(loggerRule);
+ rules.addAll(super.rules(target));
+ rules.add(checkDB);
+ return rules;
+ }
+
+ @Override
+ protected String getName() {
+ return "KiWi-Triplestore - " + config.getName();
+ }
+
+ @Override
+ protected String testName(FrameworkMethod method) {
+ return method.getName() + "(" + config.getName() + ")";
+ }
+
+ @Override
+ protected void validateConstructor(List<Throwable> errors) {
+ validateOnlyOneConstructor(errors);
+ if (fieldAnnotated()) {
+ validateZeroArgConstructor(errors);
+ }
+ }
+
+ @Override
+ protected void validateFields(List<Throwable> errors) {
+ super.validateFields(errors);
+ if (fieldAnnotated()) {
+ List<FrameworkField> configFields = getFieldsAnnotatedByKiWiConfig();
+ for (FrameworkField field : configFields) {
+ if (!field.getType().isAssignableFrom(KiWiConfiguration.class)) {
+ errors.add(new Exception(String.format("Invalid type %s for field %s, must be %s", field.getType().getName(), field.getName(), KiWiConfiguration.class.getSimpleName())));
+ }
+ }
+ }
+ }
+
+ @Override
+ protected Statement classBlock(RunNotifier notifier) {
+ return childrenInvoker(notifier);
+ }
+
+ @Override
+ protected Annotation[] getRunnerAnnotations() {
+ return new Annotation[0];
+ }
+
+ private class CheckDBRule implements MethodRule {
+
+ private final AssumptionViolatedException assume;
+
+ public CheckDBRule(KiWiConfiguration dbConfig) {
+ AssumptionViolatedException ex = null;
+ try {
+ DBConnectionChecker.checkDatabaseAvailability(dbConfig);
+ } catch (AssumptionViolatedException ave) {
+ ex = ave;
+ }
+ this.assume = ex;
+ }
+
+ @Override
+ public Statement apply(final Statement base, final FrameworkMethod method,
+ Object target) {
+ return new Statement() {
+ @Override
+ public void evaluate() throws Throwable {
+ if (assume != null) {
+ logger.info("{} skipped because database is not available", testName(method));
+ throw assume;
+ }
+ base.evaluate();
+ }
+ };
+ }
+
+ }
+
+ private class ExecutionLogger extends TestWatcher implements MethodRule {
+
+
+ @Override
+ public Statement apply(final Statement base, final FrameworkMethod method,
+ Object target) {
+ return new Statement() {
+ @Override
+ public void evaluate() throws Throwable {
+ logger.info("{} starting...", testName(method));
+ try {
+ base.evaluate();
+ logger.debug("{} SUCCESS", testName(method));
+ } catch (AssumptionViolatedException e) {
+ logger.info("{} Ignored: {}", testName(method), e.getMessage());
+ throw e;
+ } catch (Throwable t) {
+ logger.warn("{} FAILED: {}", testName(method), t.getMessage());
+ throw t;
+ }
+ }
+ };
+ }
+
+ }
+
+ }
+
+ private boolean fieldAnnotated() {
+ return !getFieldsAnnotatedByKiWiConfig().isEmpty();
+ }
+
+ private List<FrameworkField> getFieldsAnnotatedByKiWiConfig() {
+ return getTestClass().getAnnotatedFields(KiWiConfig.class);
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/a20d9357/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/sesame/KiWiSailConcurrencyTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/sesame/KiWiSailConcurrencyTest.java b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/sesame/KiWiSailConcurrencyTest.java
index 646407d..f4d1fec 100644
--- a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/sesame/KiWiSailConcurrencyTest.java
+++ b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/sesame/KiWiSailConcurrencyTest.java
@@ -17,110 +17,34 @@
*/
package org.apache.marmotta.kiwi.test.sesame;
-import java.util.ArrayList;
-import java.util.List;
-
import org.apache.marmotta.kiwi.config.KiWiConfiguration;
-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.sail.KiWiStore;
-import org.apache.marmotta.kiwi.test.helper.DBConnectionChecker;
+import org.apache.marmotta.kiwi.test.junit.KiWiDatabaseRunner;
import org.junit.After;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
import org.openrdf.sail.Sail;
import org.openrdf.sail.SailConcurrencyTest;
import org.openrdf.sail.SailException;
/**
* Run the Sesame {@link SailConcurrencyTest} suite.
- * <p/>
- * 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>
* @author Jakob Frank <ja...@apache.org>
*/
-@RunWith(Parameterized.class)
+@RunWith(KiWiDatabaseRunner.class)
public class KiWiSailConcurrencyTest extends SailConcurrencyTest {
- /**
- * 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 final String jdbcPass;
- private final String jdbcUrl;
- private final String jdbcUser;
- private final KiWiDialect dialect;
-
- public KiWiSailConcurrencyTest(String database, String jdbcUrl, String jdbcUser, String jdbcPass) {
- super(String.format("%s (%S)", KiWiSailConcurrencyTest.class.getSimpleName(), database));
- this.jdbcPass = jdbcPass;
- this.jdbcUrl = jdbcUrl;
- this.jdbcUser = jdbcUser;
+ private final KiWiConfiguration kiwiConfig;
- 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();
- } else {
- Assert.fail("unknown database dialect: " + database);
- throw new AssertionError();
- }
-
- DBConnectionChecker.checkDatabaseAvailability(jdbcUrl, jdbcUser, jdbcPass, this.dialect);
+ public KiWiSailConcurrencyTest(KiWiConfiguration kiwiConfig) {
+ super(String.format("%s (%S)", KiWiSailConcurrencyTest.class.getSimpleName(), kiwiConfig.getName()));
+ this.kiwiConfig = kiwiConfig;
}
@Override
protected Sail createSail() throws SailException {
- KiWiStore store = new KiWiStore(new KiWiConfiguration("test",jdbcUrl,jdbcUser,jdbcPass,dialect, "http://localhost/context/default", "http://localhost/context/inferred"));
+ KiWiStore store = new KiWiStore(kiwiConfig);
return store;
}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/a20d9357/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/sesame/KiWiSailInterruptTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/sesame/KiWiSailInterruptTest.java b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/sesame/KiWiSailInterruptTest.java
index af9dc47..176d375 100644
--- a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/sesame/KiWiSailInterruptTest.java
+++ b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/sesame/KiWiSailInterruptTest.java
@@ -17,22 +17,13 @@
*/
package org.apache.marmotta.kiwi.test.sesame;
-import java.util.ArrayList;
-import java.util.List;
-
import org.apache.marmotta.kiwi.config.KiWiConfiguration;
-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.sail.KiWiStore;
-import org.apache.marmotta.kiwi.test.helper.DBConnectionChecker;
+import org.apache.marmotta.kiwi.test.junit.KiWiDatabaseRunner;
import org.junit.After;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
import org.openrdf.sail.Sail;
import org.openrdf.sail.SailException;
import org.openrdf.sail.SailInterruptTest;
@@ -42,63 +33,22 @@ import org.openrdf.sail.SailInterruptTest;
* @author Jakob Frank <ja...@apache.org>
*
*/
-@RunWith(Parameterized.class)
+@RunWith(KiWiDatabaseRunner.class)
public class KiWiSailInterruptTest extends SailInterruptTest {
- /**
- * 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 final String jdbcPass;
- private final String jdbcUrl;
- private final String jdbcUser;
- private final KiWiDialect dialect;
-
- public KiWiSailInterruptTest(String database, String jdbcUrl, String jdbcUser, String jdbcPass) {
- super(String.format("%s (%S)", KiWiSailInterruptTest.class.getSimpleName(), database));
-
- this.jdbcPass = jdbcPass;
- this.jdbcUrl = jdbcUrl;
- this.jdbcUser = jdbcUser;
+ private final KiWiConfiguration kiwiConfig;
- 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();
- } else {
- Assert.fail("unknown database dialect: " + database);
- throw new AssertionError();
- }
+ public KiWiSailInterruptTest(KiWiConfiguration kiwiConfig) {
+ super(String.format("%s (%S)", KiWiSailInterruptTest.class.getSimpleName(), kiwiConfig.getName()));
+ this.kiwiConfig = kiwiConfig;
- DBConnectionChecker.checkDatabaseAvailability(jdbcUrl, jdbcUser, jdbcPass, this.dialect);
}
@Override
protected Sail createSail() throws SailException {
- KiWiStore store = new KiWiStore(new KiWiConfiguration("test",jdbcUrl,jdbcUser,jdbcPass,dialect, "http://localhost/context/default", "http://localhost/context/inferred"));
+ KiWiStore store = new KiWiStore(kiwiConfig);
return store;
}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/a20d9357/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/sesame/KiWiStoreTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/sesame/KiWiStoreTest.java b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/sesame/KiWiStoreTest.java
index 11c9f75..93ebf66 100644
--- a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/sesame/KiWiStoreTest.java
+++ b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/sesame/KiWiStoreTest.java
@@ -17,106 +17,30 @@
*/
package org.apache.marmotta.kiwi.test.sesame;
-import java.util.ArrayList;
-import java.util.List;
-
import org.apache.marmotta.kiwi.config.KiWiConfiguration;
-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.sail.KiWiStore;
-import org.apache.marmotta.kiwi.test.helper.DBConnectionChecker;
-import org.junit.Assert;
+import org.apache.marmotta.kiwi.test.junit.KiWiDatabaseRunner;
import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
import org.openrdf.sail.RDFStoreTest;
import org.openrdf.sail.Sail;
import org.openrdf.sail.SailException;
/**
* Run the Sesame {@link RDFStoreTest} suite.
- * <p/>
- * 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>
* @author Jakob Frank <ja...@apache.org>
*/
-@RunWith(Parameterized.class)
+@RunWith(KiWiDatabaseRunner.class)
public class KiWiStoreTest extends RDFStoreTest {
- /**
- * 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 final String jdbcPass;
- private final String jdbcUrl;
- private final String jdbcUser;
- private final KiWiDialect dialect;
+ private final KiWiConfiguration kiwiConfig;
- public KiWiStoreTest(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();
- } else {
- Assert.fail("unknown database dialect: " + database);
- throw new AssertionError();
- }
-
- DBConnectionChecker.checkDatabaseAvailability(jdbcUrl, jdbcUser, jdbcPass, this.dialect);
+ public KiWiStoreTest(KiWiConfiguration kiwiConfig) {
+ this.kiwiConfig = kiwiConfig;
}
@Override
protected Sail createSail() throws SailException {
- KiWiStore store = new KiWiStore(new KiWiConfiguration("test",jdbcUrl,jdbcUser,jdbcPass,dialect, "http://localhost/context/default", "http://localhost/context/inferred"));
+ KiWiStore store = new KiWiStore(kiwiConfig);
store.initialize();
return store;
}