You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by wi...@apache.org on 2014/06/13 11:02:47 UTC

[18/20] git commit: MARMOTTA-484: more doku and some convenience methods

MARMOTTA-484: more doku and some convenience methods


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

Branch: refs/heads/ldp
Commit: e25131fee9304d358cd4a326e7d43c36c187be47
Parents: 2ed1887
Author: Jakob Frank <ja...@apache.org>
Authored: Tue Jun 10 11:34:48 2014 +0200
Committer: Jakob Frank <ja...@apache.org>
Committed: Tue Jun 10 11:34:48 2014 +0200

----------------------------------------------------------------------
 .../AbstractRepositoryConnectionMatcher.java    |  1 -
 .../sesame/test/base/RdfStringMatcher.java      | 45 +++++++++++++++-----
 .../sesame/test/base/RepositoryMatcher.java     | 45 ++++++++++++++++----
 .../commons/sesame/test/base/SesameMatcher.java |  1 -
 .../test/connection/HasStatementMatcher.java    | 26 +++++------
 .../sesame/test/sparql/SparqlAskMatcher.java    |  4 +-
 .../test/sparql/SparqlGraphQueryMatcher.java    | 10 +++--
 .../test/sparql/SparqlTupleQueryMatcher.java    |  1 -
 8 files changed, 91 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/marmotta/blob/e25131fe/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/base/AbstractRepositoryConnectionMatcher.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/base/AbstractRepositoryConnectionMatcher.java b/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/base/AbstractRepositoryConnectionMatcher.java
index 77df042..6a0ffb0 100644
--- a/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/base/AbstractRepositoryConnectionMatcher.java
+++ b/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/base/AbstractRepositoryConnectionMatcher.java
@@ -17,7 +17,6 @@
  */
 package org.apache.marmotta.commons.sesame.test.base;
 
-import org.hamcrest.Description;
 import org.hamcrest.Matcher;
 import org.openrdf.repository.RepositoryConnection;
 import org.openrdf.repository.RepositoryException;

http://git-wip-us.apache.org/repos/asf/marmotta/blob/e25131fe/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/base/RdfStringMatcher.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/base/RdfStringMatcher.java b/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/base/RdfStringMatcher.java
index 2608ff9..7f5adc3 100644
--- a/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/base/RdfStringMatcher.java
+++ b/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/base/RdfStringMatcher.java
@@ -32,12 +32,13 @@ import java.io.StringReader;
  */
 public class RdfStringMatcher<T extends String> extends SesameMatcher<T> implements Matcher<T> {
 
-    private final Matcher<? extends RepositoryConnection> delegate;
+    private final Matcher<? extends RepositoryConnection>[] delegates;
     private final String baseUri;
     private final RDFFormat format;
 
-    public RdfStringMatcher(RDFFormat format, String baseUri, Matcher<? extends RepositoryConnection> delegate) {
-        this.delegate = delegate;
+    @SafeVarargs
+    public RdfStringMatcher(RDFFormat format, String baseUri, Matcher<? extends RepositoryConnection>... delegates) {
+        this.delegates = delegates;
         this.baseUri = baseUri;
         this.format = format;
     }
@@ -57,9 +58,12 @@ public class RdfStringMatcher<T extends String> extends SesameMatcher<T> impleme
                     con.add(r, baseUri, format);
                     con.commit();
 
-                    con.begin();
-                    final boolean result = delegate.matches(con);
-                    con.commit();
+                    boolean result = true;
+                    for (Matcher<? extends RepositoryConnection> delegate : delegates) {
+                        con.begin();
+                        result &= delegate.matches(con);
+                        con.commit();
+                    }
                     return result;
                 } catch (final Throwable t) {
                     con.rollback();
@@ -79,19 +83,40 @@ public class RdfStringMatcher<T extends String> extends SesameMatcher<T> impleme
 
     @Override
     public void describeTo(Description description) {
-        description.appendText(format.getName()).appendText(" String ").appendDescriptionOf(delegate);
+        description.appendText(format.getName()).appendText(" String ");
+        if (delegates.length == 1) {
+            description.appendDescriptionOf(delegates[0]);
+        } else {
+            for (Matcher<? extends RepositoryConnection> delegate : delegates) {
+                description.appendText("\n  ").appendDescriptionOf(delegate);
+            }
+        }
     }
 
     /**
      * Wrap an instance of an AbstractRepositoryConnectionMatcher to match it against an RDF-String.
      *
-     * @param format the RDFFormat of the String
-     * @param baseUri the baseUri for de-serializing the String
+     * @param format   the RDFFormat of the String
+     * @param baseUri  the baseUri for de-serializing the String
      * @param delegate the AbstractRepositoryConnectionMatcher to wrap.
-     *
      * @see org.apache.marmotta.commons.sesame.test.base.AbstractRepositoryConnectionMatcher
      */
     public static <T extends String> Matcher<T> wrap(RDFFormat format, String baseUri, Matcher<? extends RepositoryConnection> delegate) {
         return new RdfStringMatcher<T>(format, baseUri, delegate);
     }
+
+    /**
+     * Wrap an instance of an AbstractRepositoryConnectionMatcher to match it against an RDF-String.
+     *
+     * @param format    the RDFFormat of the String
+     * @param baseUri   the baseUri for de-serializing the String
+     * @param delegates the AbstractRepositoryConnectionMatcher to wrap.
+     * @see org.apache.marmotta.commons.sesame.test.base.AbstractRepositoryConnectionMatcher
+     */
+    @SafeVarargs
+    public static <T extends String> Matcher<T> wrap(RDFFormat format, String baseUri, Matcher<? extends RepositoryConnection>... delegates) {
+        return new RdfStringMatcher<T>(format, baseUri, delegates);
+    }
+
+
 }

http://git-wip-us.apache.org/repos/asf/marmotta/blob/e25131fe/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/base/RepositoryMatcher.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/base/RepositoryMatcher.java b/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/base/RepositoryMatcher.java
index 1da1cd3..187b3f9 100644
--- a/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/base/RepositoryMatcher.java
+++ b/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/base/RepositoryMatcher.java
@@ -27,13 +27,13 @@ import org.openrdf.repository.RepositoryConnection;
  */
 public class RepositoryMatcher<T extends Repository> extends SesameMatcher<T> implements Matcher<T> {
 
-    private final Matcher<? extends RepositoryConnection> delegate;
+    private final Matcher<? extends RepositoryConnection>[] delegates;
 
     /**
-     * @param delegate the Matcher to wrap.
+     * @param delegates the Matcher to wrap.
      */
-    public RepositoryMatcher(Matcher<? extends RepositoryConnection> delegate) {
-        this.delegate = delegate;
+    public RepositoryMatcher(Matcher<? extends RepositoryConnection>... delegates) {
+        this.delegates = delegates;
     }
 
     @Override
@@ -41,9 +41,13 @@ public class RepositoryMatcher<T extends Repository> extends SesameMatcher<T> im
         try {
             final RepositoryConnection con = repository.getConnection();
             try {
-                con.begin();
-                boolean matches = delegate.matches(con);
-                con.commit();
+
+                boolean matches = true;
+                for (Matcher<? extends RepositoryConnection> delegate : delegates) {
+                    con.begin();
+                    matches &= delegate.matches(con);
+                    con.commit();
+                }
                 return matches;
             } catch (final Throwable t) {
                 con.rollback();
@@ -60,12 +64,26 @@ public class RepositoryMatcher<T extends Repository> extends SesameMatcher<T> im
 
     @Override
     public void describeTo(Description description) {
-        delegate.describeTo(description);
+        description.appendText(" a SesameRepositoy ");
+        for (int i = 0; i < delegates.length; i++) {
+            Matcher<? extends RepositoryConnection> delegate = delegates[i];
+            if (i > 0) {
+                description.appendText(",\n and ");
+            }
+            description.appendDescriptionOf(delegate);
+        }
     }
 
     @Override
     protected void describeMismatchSafely(T item, Description mismatchDescription) {
-        delegate.describeMismatch(item, mismatchDescription);
+        mismatchDescription.appendText(" a SesameRepositoy ");
+        for (int i = 0; i < delegates.length; i++) {
+            Matcher<? extends RepositoryConnection> delegate = delegates[i];
+            if (i > 0) {
+                mismatchDescription.appendText(",\n and ");
+            }
+            delegate.describeMismatch(item, mismatchDescription);
+        }
     }
 
     /**
@@ -76,4 +94,13 @@ public class RepositoryMatcher<T extends Repository> extends SesameMatcher<T> im
     public static <T extends Repository> Matcher<T> wrap(Matcher<? extends RepositoryConnection> connectionMatcher) {
         return new RepositoryMatcher<T>(connectionMatcher);
     }
+
+    /**
+     * Wrap an instance of an {@link AbstractRepositoryConnectionMatcher} to match against an Sesame {@link Repository}.
+     *
+     * @param connectionMatchers the {@link AbstractRepositoryConnectionMatcher}s to wrap
+     */
+    public static <T extends Repository> Matcher<T> wrap(Matcher<? extends RepositoryConnection>... connectionMatchers) {
+        return new RepositoryMatcher<T>(connectionMatchers);
+    }
 }

http://git-wip-us.apache.org/repos/asf/marmotta/blob/e25131fe/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/base/SesameMatcher.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/base/SesameMatcher.java b/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/base/SesameMatcher.java
index fb9fdcc..a9b3f8c 100644
--- a/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/base/SesameMatcher.java
+++ b/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/base/SesameMatcher.java
@@ -18,7 +18,6 @@
 package org.apache.marmotta.commons.sesame.test.base;
 
 import org.hamcrest.TypeSafeMatcher;
-import org.openrdf.repository.RepositoryConnection;
 
 /**
  * Shared Superclass for all SesameMatchers.

http://git-wip-us.apache.org/repos/asf/marmotta/blob/e25131fe/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/connection/HasStatementMatcher.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/connection/HasStatementMatcher.java b/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/connection/HasStatementMatcher.java
index e2dbbc1..d4803a0 100644
--- a/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/connection/HasStatementMatcher.java
+++ b/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/connection/HasStatementMatcher.java
@@ -39,11 +39,11 @@ public class HasStatementMatcher<T extends RepositoryConnection> extends Abstrac
 
     /**
      * Create a RepositoryConnection Matcher checking if the provided Statement is contained in the Connection.
-     * @param subject the subject of the statement, use {@code null} as wildcard.
-     * @param predicate the predicate of the statement, use {@code null} as wildcard.
-     * @param object the object of the statement, use {@code null} as wildcard.
-     * @param contexts the contexts in which to look for the statement, use an empty varargs array to look in all contexts available.
      *
+     * @param subject   the subject of the statement, use {@code null} as wildcard.
+     * @param predicate the predicate of the statement, use {@code null} as wildcard.
+     * @param object    the object of the statement, use {@code null} as wildcard.
+     * @param contexts  the contexts in which to look for the statement, use an empty varargs array to look in all contexts available.
      * @see org.apache.marmotta.commons.sesame.test.connection.HasStatementMatcher
      * @see org.openrdf.repository.RepositoryConnection#hasStatement(org.openrdf.model.Resource, org.openrdf.model.URI, org.openrdf.model.Value, boolean, org.openrdf.model.Resource...)
      */
@@ -53,12 +53,12 @@ public class HasStatementMatcher<T extends RepositoryConnection> extends Abstrac
 
     /**
      * Create a RepositoryConnection Matcher checking if the provided Statement is contained in the Connection.
-     * @param subject the subject of the statement, use {@code null} as wildcard.
-     * @param predicate the predicate of the statement, use {@code null} as wildcard.
-     * @param object the object of the statement, use {@code null} as wildcard.
-     * @param includeInferrred if false, no inferred statements are considered; if true, inferred statements are considered if available
-     * @param contexts the contexts in which to look for the statement, use an empty varargs array to look in all contexts available.
      *
+     * @param subject          the subject of the statement, use {@code null} as wildcard.
+     * @param predicate        the predicate of the statement, use {@code null} as wildcard.
+     * @param object           the object of the statement, use {@code null} as wildcard.
+     * @param includeInferrred if false, no inferred statements are considered; if true, inferred statements are considered if available
+     * @param contexts         the contexts in which to look for the statement, use an empty varargs array to look in all contexts available.
      * @see org.apache.marmotta.commons.sesame.test.connection.HasStatementMatcher
      * @see org.openrdf.repository.RepositoryConnection#hasStatement(org.openrdf.model.Resource, org.openrdf.model.URI, org.openrdf.model.Value, boolean, org.openrdf.model.Resource...)
      */
@@ -86,11 +86,11 @@ public class HasStatementMatcher<T extends RepositoryConnection> extends Abstrac
 
     /**
      * Create a RepositoryConnection Matcher checking if the provided Statement is contained in the Connection.
-     * @param subject the subject of the statement, use {@code null} as wildcard.
-     * @param predicate the predicate of the statement, use {@code null} as wildcard.
-     * @param object the object of the statement, use {@code null} as wildcard.
-     * @param contexts the contexts in which to look for the statement, use an empty varargs array to look in all contexts available.
      *
+     * @param subject   the subject of the statement, use {@code null} as wildcard.
+     * @param predicate the predicate of the statement, use {@code null} as wildcard.
+     * @param object    the object of the statement, use {@code null} as wildcard.
+     * @param contexts  the contexts in which to look for the statement, use an empty varargs array to look in all contexts available.
      * @see org.apache.marmotta.commons.sesame.test.connection.HasStatementMatcher
      * @see org.openrdf.repository.RepositoryConnection#hasStatement(org.openrdf.model.Resource, org.openrdf.model.URI, org.openrdf.model.Value, boolean, org.openrdf.model.Resource...)
      */

http://git-wip-us.apache.org/repos/asf/marmotta/blob/e25131fe/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/sparql/SparqlAskMatcher.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/sparql/SparqlAskMatcher.java b/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/sparql/SparqlAskMatcher.java
index e99f338..f9bd2d0 100644
--- a/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/sparql/SparqlAskMatcher.java
+++ b/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/sparql/SparqlAskMatcher.java
@@ -50,9 +50,8 @@ public class SparqlAskMatcher<T extends RepositoryConnection> extends SparqlMatc
      * Create a SparqlAskMatcher that evaluates a SPARQL ASK query against the {@link org.openrdf.repository.RepositoryConnection}
      * to test.
      *
-     * @param baseUri The base URI to resolve any relative URIs that are in the query against, can be null if the query does not contain any relative URIs.
+     * @param baseUri  The base URI to resolve any relative URIs that are in the query against, can be null if the query does not contain any relative URIs.
      * @param askQuery the SPARQL ASK query.
-     *
      * @see org.openrdf.query.BooleanQuery#evaluate()
      */
     public static <T extends RepositoryConnection> Matcher<T> sparqlAsk(String baseUri, String askQuery) {
@@ -64,7 +63,6 @@ public class SparqlAskMatcher<T extends RepositoryConnection> extends SparqlMatc
      * to test. The baseUri of the SPARQL Query is assumed {@code null}.
      *
      * @param askQuery the SPARQL ASK query.
-     *
      * @see #sparqlAsk(String, String)
      * @see org.openrdf.query.BooleanQuery#evaluate()
      */

http://git-wip-us.apache.org/repos/asf/marmotta/blob/e25131fe/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/sparql/SparqlGraphQueryMatcher.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/sparql/SparqlGraphQueryMatcher.java b/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/sparql/SparqlGraphQueryMatcher.java
index e92309d..fca9ed9 100644
--- a/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/sparql/SparqlGraphQueryMatcher.java
+++ b/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/sparql/SparqlGraphQueryMatcher.java
@@ -58,7 +58,7 @@ public class SparqlGraphQueryMatcher<T extends RepositoryConnection> extends Spa
                 connection2.commit();
 
                 boolean result = true;
-                for (Matcher<? extends RepositoryConnection> matcher: matchers) {
+                for (Matcher<? extends RepositoryConnection> matcher : matchers) {
                     connection2.begin();
                     result &= matcher.matches(connection2);
                     connection2.commit();
@@ -88,8 +88,9 @@ public class SparqlGraphQueryMatcher<T extends RepositoryConnection> extends Spa
      * Create a {@link org.apache.marmotta.commons.sesame.test.sparql.SparqlGraphQueryMatcher} that matches the given
      * {@link org.apache.marmotta.commons.sesame.test.base.AbstractRepositoryConnectionMatcher} against the result of
      * the given SPARQL CONSTRUCT query.
+     *
      * @param baseUri The base URI to resolve any relative URIs that are in the query against, can be null if the query does not contain any relative URIs.
-     * @param query A SPARQL CONSTRUCT query
+     * @param query   A SPARQL CONSTRUCT query
      * @param matcher the AbstractRepositoryConnectionMatcher to match
      */
     public static <T extends RepositoryConnection> Matcher<T> sparqlGraphQuery(String baseUri, String query, Matcher<? extends RepositoryConnection> matcher) {
@@ -100,8 +101,9 @@ public class SparqlGraphQueryMatcher<T extends RepositoryConnection> extends Spa
      * Create a {@link org.apache.marmotta.commons.sesame.test.sparql.SparqlGraphQueryMatcher} that matches the given
      * {@link org.apache.marmotta.commons.sesame.test.base.AbstractRepositoryConnectionMatcher} against the result of
      * the given SPARQL CONSTRUCT query.
-     * @param baseUri The base URI to resolve any relative URIs that are in the query against, can be null if the query does not contain any relative URIs.
-     * @param query A SPARQL CONSTRUCT query
+     *
+     * @param baseUri  The base URI to resolve any relative URIs that are in the query against, can be null if the query does not contain any relative URIs.
+     * @param query    A SPARQL CONSTRUCT query
      * @param matchers the AbstractRepositoryConnectionMatcher to match
      */
     @SafeVarargs

http://git-wip-us.apache.org/repos/asf/marmotta/blob/e25131fe/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/sparql/SparqlTupleQueryMatcher.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/sparql/SparqlTupleQueryMatcher.java b/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/sparql/SparqlTupleQueryMatcher.java
index 1af5540..8df97eb 100644
--- a/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/sparql/SparqlTupleQueryMatcher.java
+++ b/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/sparql/SparqlTupleQueryMatcher.java
@@ -24,7 +24,6 @@ import org.openrdf.query.*;
 import org.openrdf.repository.RepositoryConnection;
 import org.openrdf.repository.RepositoryException;
 
-import java.util.Collection;
 import java.util.List;
 
 /**