MARMOTTA-484: some more javadoc
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/2ed1887b Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/2ed1887b Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/2ed1887b Branch: refs/heads/ldp Commit: 2ed1887b65bb1cbd8fb3e539cd9a41f16cae2b52 Parents: 1a4c303 Author: Jakob Frank <[email protected]> Authored: Tue Jun 10 10:55:18 2014 +0200 Committer: Jakob Frank <[email protected]> Committed: Tue Jun 10 11:31:53 2014 +0200 ---------------------------------------------------------------------- .../commons/sesame/test/SesameMatchers.java | 288 ++++++++++++++++++- .../sesame/test/base/RdfStringMatcher.java | 11 +- .../sesame/test/base/RepositoryMatcher.java | 5 + .../sesame/test/sparql/SparqlAskMatcher.java | 18 ++ .../test/sparql/SparqlGraphQueryMatcher.java | 49 +++- 5 files changed, 347 insertions(+), 24 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/marmotta/blob/2ed1887b/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/SesameMatchers.java ---------------------------------------------------------------------- diff --git a/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/SesameMatchers.java b/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/SesameMatchers.java index 5baabe0..0466ff6 100644 --- a/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/SesameMatchers.java +++ b/commons/marmotta-sesame-tools/marmotta-sesame-matchers/src/main/java/org/apache/marmotta/commons/sesame/test/SesameMatchers.java @@ -45,11 +45,10 @@ public class SesameMatchers { /** * 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 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 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...) */ @@ -60,144 +59,403 @@ public class SesameMatchers { /** * Create a Repository Matcher checking if the provided Statement is contained in the Repository. * - * @param subject the subject of the statement, use {@code null} as wildcard. + * @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 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.base.RepositoryMatcher * @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...) */ public static <T extends Repository> Matcher<T> repositoryHasStatement(Resource subject, URI predicate, Value object, Resource... contexts) { - return RepositoryMatcher.wrap(hasStatement(subject, predicate, object,contexts)); + return RepositoryMatcher.wrap(hasStatement(subject, predicate, object, contexts)); } + /** + * Create a String Matcher that checks for the given RDF Statement in the serialized RDF dump + * + * @param format the RDFFormat used for de-serializing the RDF + * @param baseUri the baseUri used for de-serializing the RDF + * @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.base.RdfStringMatcher + * @see org.apache.marmotta.commons.sesame.test.connection.HasStatementMatcher + */ public static <T extends String> Matcher<T> rdfHasStatement(RDFFormat format, String baseUri, Resource subject, URI predicate, Value object, Resource... contexts) { return RdfStringMatcher.wrap(format, baseUri, hasStatement(subject, predicate, object, contexts)); } + /** + * Create a RepositoryConnection Matcher that evaluates a SPARQL ASK query. + * + * @param askQuery the SPARQL ASK query to check, test will fail if the result is {@code false} + * @see org.apache.marmotta.commons.sesame.test.sparql.SparqlAskMatcher + * @see org.openrdf.query.BooleanQuery#evaluate() + */ public static <T extends RepositoryConnection> Matcher<T> sparqlAsk(String askQuery) { return SparqlAskMatcher.sparqlAsk(askQuery); } + /** + * Create a RepositoryConnection Matcher that evaluates a SPARQL ASK 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 askQuery the SPARQL ASK query to check, test will fail if the result is {@code false} + * @see org.apache.marmotta.commons.sesame.test.sparql.SparqlAskMatcher + * @see org.openrdf.query.BooleanQuery#evaluate() + */ public static <T extends RepositoryConnection> Matcher<T> sparqlAsk(String baseUri, String askQuery) { return SparqlAskMatcher.sparqlAsk(baseUri, askQuery); } + /** + * Create a Repository Matcher that evaluates a SPARQL ASK query. + * + * @param askQuery the SPARQL ASK query to check, test will fail if the result is {@code false} + * @see org.apache.marmotta.commons.sesame.test.sparql.SparqlAskMatcher + * @see org.openrdf.query.BooleanQuery#evaluate() + * @see org.apache.marmotta.commons.sesame.test.base.RepositoryMatcher#wrap(org.hamcrest.Matcher) + */ public static <T extends Repository> Matcher<T> sparqlAskRepository(String askQuery) { return RepositoryMatcher.wrap(sparqlAsk(askQuery)); } + /** + * Create a RepositoryConnection Matcher that evaluates a SPARQL ASK 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 askQuery the SPARQL ASK query to check, test will fail if the result is {@code false} + * @see org.apache.marmotta.commons.sesame.test.sparql.SparqlAskMatcher + * @see org.openrdf.query.BooleanQuery#evaluate() + * @see org.apache.marmotta.commons.sesame.test.base.RepositoryMatcher#wrap(org.hamcrest.Matcher) + */ public static <T extends Repository> Matcher<T> sparqlAskRepository(String baseUri, String askQuery) { return RepositoryMatcher.wrap(sparqlAsk(baseUri, askQuery)); } + /** + * Create a RdfString Matcher that evaluates a SPARQL ASK query. + * + * @param format the RDFFormat used for de-serializing the RDF + * @param baseUri the baseUri used for de-serializing the RDF + * @param askQuery the SPARQL ASK query to check, test will fail if the result is {@code false} + * @see org.apache.marmotta.commons.sesame.test.sparql.SparqlAskMatcher + * @see org.openrdf.query.BooleanQuery#evaluate() + */ public static <T extends String> Matcher<T> sparqlAskRdf(RDFFormat format, String baseUri, String askQuery) { return RdfStringMatcher.wrap(format, baseUri, sparqlAsk(askQuery)); } + /** + * Create a RepositoryConnection Matcher that evaluates a SPARQL ASK query. + * + * @param format the RDFFormat used for de-serializing the RDF + * @param baseUri the baseUri used for de-serializing the RDF + * @param queryBaseUri 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 to check, test will fail if the result is {@code false} + * @see org.apache.marmotta.commons.sesame.test.sparql.SparqlAskMatcher + * @see org.openrdf.query.BooleanQuery#evaluate() + */ public static <T extends String> Matcher<T> sparqlAskRdf(RDFFormat format, String baseUri, String queryBaseUri, String askQuery) { return RdfStringMatcher.wrap(format, baseUri, sparqlAsk(queryBaseUri, askQuery)); } + /** + * Create a RepositoryConnection Matcher that checks for the presence of the provided binding in the ResultSet. + * + * @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 sparqlQuery A SPARQL SELECT query to match the provided matcher against. + * @param matcher The Matcher to match + * @see org.apache.marmotta.commons.sesame.test.sparql.SparqlTupleQueryMatcher + * @see org.openrdf.repository.sparql.query.SPARQLTupleQuery + */ public static <T extends RepositoryConnection> Matcher<T> sparqlTupleQuery(String baseUri, String sparqlQuery, Matcher<Iterable<BindingSet>> matcher) { return SparqlTupleQueryMatcher.sparqlQuery(baseUri, sparqlQuery, matcher); } + /** + * Create a RepositoryConnection Matcher that checks for the presence of the provided bindings in the ResultSet. + * + * @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 sparqlQuery A SPARQL SELECT query to match the provided matcher against. + * @param matchers The Matchers to match + * @see org.apache.marmotta.commons.sesame.test.sparql.SparqlTupleQueryMatcher + * @see org.openrdf.repository.sparql.query.SPARQLTupleQuery + */ @SafeVarargs public static <T extends RepositoryConnection> Matcher<T> sparqlTupleQuery(String baseUri, String sparqlQuery, Matcher<Iterable<BindingSet>>... matchers) { return SparqlTupleQueryMatcher.sparqlQuery(baseUri, sparqlQuery, matchers); } + /** + * Create a Repository Matcher that checks for the presence of the provided binding in the ResultSet. + * + * @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 sparqlQuery A SPARQL SELECT query to match the provided matcher against. + * @param matcher The Matcher to match + * @see org.apache.marmotta.commons.sesame.test.sparql.SparqlTupleQueryMatcher + * @see org.openrdf.repository.sparql.query.SPARQLTupleQuery + */ public static <T extends Repository> Matcher<T> sparqlTupleQueryRepository(String baseUri, String sparqlQuery, Matcher<Iterable<BindingSet>> matcher) { return RepositoryMatcher.wrap(SparqlTupleQueryMatcher.sparqlQuery(baseUri, sparqlQuery, matcher)); } + /** + * Create a Repository Matcher that checks for the presence of the provided bindings in the ResultSet. + * + * @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 sparqlQuery A SPARQL SELECT query to match the provided matcher against. + * @param matchers The Matchers to match + * @see org.apache.marmotta.commons.sesame.test.sparql.SparqlTupleQueryMatcher + * @see org.openrdf.repository.sparql.query.SPARQLTupleQuery + */ @SafeVarargs public static <T extends Repository> Matcher<T> sparqlTupleQueryRepository(String baseUri, String sparqlQuery, Matcher<Iterable<BindingSet>>... matchers) { return RepositoryMatcher.wrap(SparqlTupleQueryMatcher.sparqlQuery(baseUri, sparqlQuery, matchers)); } + /** + * Create a RDF-String Matcher that checks for the presence of the provided binding in the ResultSet. + * + * @param format the RDFFormat used for de-serializing the RDF + * @param baseUri the baseUri used for de-serializing the RDF + * @param queryBaseUri 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 sparqlQuery A SPARQL SELECT query to match the provided matcher against. + * @param matcher The Matcher to match + * @see org.apache.marmotta.commons.sesame.test.sparql.SparqlTupleQueryMatcher + * @see org.openrdf.repository.sparql.query.SPARQLTupleQuery + */ public static <T extends String> Matcher<T> sparqlTupleQueryRdf(RDFFormat format, String baseUri, String queryBaseUri, String sparqlQuery, Matcher<Iterable<BindingSet>> matcher) { return RdfStringMatcher.wrap(format, baseUri, SparqlTupleQueryMatcher.sparqlQuery(queryBaseUri, sparqlQuery, matcher)); } + /** + * Create a RDF-String Matcher that checks for the presence of the provided bindings in the ResultSet. + * + * @param format the RDFFormat used for de-serializing the RDF + * @param baseUri the baseUri used for de-serializing the RDF + * @param queryBaseUri 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 sparqlQuery A SPARQL SELECT query to match the provided matcher against. + * @param matchers The Matchers to match + * @see org.apache.marmotta.commons.sesame.test.sparql.SparqlTupleQueryMatcher + * @see org.openrdf.repository.sparql.query.SPARQLTupleQuery + */ @SafeVarargs public static <T extends String> Matcher<T> sparqlTupleQueryRdf(RDFFormat format, String baseUri, String queryBaseUri, String sparqlQuery, Matcher<Iterable<BindingSet>>... matchers) { + return RdfStringMatcher.wrap(format, baseUri, SparqlTupleQueryMatcher.sparqlQuery(queryBaseUri, sparqlQuery, matchers)); } + /** + * 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 sparqlQuery A SPARQL CONSTRUCT query + * @param matcher the AbstractRepositoryConnectionMatcher to match + * @see org.apache.marmotta.commons.sesame.test.sparql.SparqlGraphQueryMatcher + */ public static <T extends RepositoryConnection> Matcher<T> sparqlGraphQuery(String baseUri, String sparqlQuery, Matcher<? extends RepositoryConnection> matcher) { return SparqlGraphQueryMatcher.<T>sparqlGraphQuery(baseUri, sparqlQuery, matcher); } + /** + * 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 sparqlQuery A SPARQL CONSTRUCT query + * @param matchers the {@link org.apache.marmotta.commons.sesame.test.base.AbstractRepositoryConnectionMatcher}s to match + * @see org.apache.marmotta.commons.sesame.test.sparql.SparqlGraphQueryMatcher + */ @SafeVarargs public static <T extends RepositoryConnection, V extends RepositoryConnection> Matcher<T> sparqlGraphQuery(String baseUri, String sparqlQuery, Matcher<V>... matchers) { return SparqlGraphQueryMatcher.<T>sparqlGraphQuery(baseUri, sparqlQuery, CoreMatchers.allOf(matchers)); } + /** + * Create a {@link org.apache.marmotta.commons.sesame.test.base.RepositoryMatcher} that matches the given + * {@link org.apache.marmotta.commons.sesame.test.base.AbstractRepositoryConnectionMatcher} against the result of + * the given SPARQL CONSTRUCT query on a Repository. + * + * @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 sparqlQuery A SPARQL CONSTRUCT query + * @param matcher the RepositoryMatcher to match + * @see org.apache.marmotta.commons.sesame.test.sparql.SparqlGraphQueryMatcher + */ public static <T extends Repository, V extends RepositoryConnection> Matcher<T> sparqlGraphQueryRepository(String baseUri, String sparqlQuery, Matcher<V> matcher) { return RepositoryMatcher.wrap(sparqlGraphQuery(baseUri, sparqlQuery, matcher)); } + /** + * Create a {@link org.apache.marmotta.commons.sesame.test.base.RepositoryMatcher} that matches the given + * {@link org.apache.marmotta.commons.sesame.test.base.AbstractRepositoryConnectionMatcher}s against the result of + * the given SPARQL CONSTRUCT query on a Repository. + * + * @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 sparqlQuery A SPARQL CONSTRUCT query + * @param matchers the RepositoryMatchers to match + * @see org.apache.marmotta.commons.sesame.test.sparql.SparqlGraphQueryMatcher + */ @SafeVarargs public static <T extends Repository, V extends RepositoryConnection> Matcher<T> sparqlGraphQueryRepository(String baseUri, String sparqlQuery, Matcher<V>... matchers) { return RepositoryMatcher.wrap(sparqlGraphQuery(baseUri, sparqlQuery, matchers)); } + /** + * Create a {@link org.apache.marmotta.commons.sesame.test.base.RdfStringMatcher} that matches the given + * {@link org.apache.marmotta.commons.sesame.test.base.AbstractRepositoryConnectionMatcher}s against the result of + * the given SPARQL CONSTRUCT query on a Repository. + * + * @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 sparqlQuery A SPARQL CONSTRUCT query + * @param matcher the RepositoryMatcher to match + * @see org.apache.marmotta.commons.sesame.test.sparql.SparqlGraphQueryMatcher + */ public static <T extends String, V extends RepositoryConnection> Matcher<T> sparqlGraphQueryRdf(RDFFormat format, String baseUri, String queryBaseUri, String sparqlQuery, Matcher<V> matcher) { return RdfStringMatcher.wrap(format, baseUri, sparqlGraphQuery(queryBaseUri, sparqlQuery, matcher)); } + /** + * Create a {@link org.apache.marmotta.commons.sesame.test.base.RdfStringMatcher} that matches the given + * {@link org.apache.marmotta.commons.sesame.test.base.AbstractRepositoryConnectionMatcher}s against the result of + * the given SPARQL CONSTRUCT query on a Repository. + * + * @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 sparqlQuery A SPARQL CONSTRUCT query + * @param matchers the RepositoryMatchers to match + * @see org.apache.marmotta.commons.sesame.test.sparql.SparqlGraphQueryMatcher + */ @SafeVarargs public static <T extends String, V extends RepositoryConnection> Matcher<T> sparqlGraphQueryRdf(RDFFormat format, String baseUri, String queryBaseUri, String sparqlQuery, Matcher<V>... matchers) { return RdfStringMatcher.wrap(format, baseUri, sparqlGraphQuery(queryBaseUri, sparqlQuery, matchers)); } + /** + * Wrap a {@link org.apache.marmotta.commons.sesame.test.base.AbstractRepositoryConnectionMatcher} with a {@link org.apache.marmotta.commons.sesame.test.base.RepositoryMatcher}. + * + * @param matcher the Matcher to wrap + * @see org.apache.marmotta.commons.sesame.test.base.RepositoryMatcher#wrap(org.hamcrest.Matcher) + */ public static <T extends Repository, V extends RepositoryConnection> Matcher<T> repositoryMatches(Matcher<V> matcher) { return RepositoryMatcher.wrap(matcher); } + /** + * Wrap the {@link org.apache.marmotta.commons.sesame.test.base.AbstractRepositoryConnectionMatcher} with a {@link org.apache.marmotta.commons.sesame.test.base.RepositoryMatcher}. + * + * @param matcher1 the Matcher to wrap + * @param matcher2 the Matcher to wrap + * @see org.apache.marmotta.commons.sesame.test.base.RepositoryMatcher#wrap(org.hamcrest.Matcher) + */ public static <T extends Repository, V extends RepositoryConnection> Matcher<T> repositoryMatches(Matcher<V> matcher1, Matcher<V> matcher2) { return RepositoryMatcher.wrap(CoreMatchers.allOf(matcher1, matcher2)); } + /** + * Wrap the {@link org.apache.marmotta.commons.sesame.test.base.AbstractRepositoryConnectionMatcher} with a {@link org.apache.marmotta.commons.sesame.test.base.RepositoryMatcher}. + * + * @param matchers the Matchers to wrap + * @see org.apache.marmotta.commons.sesame.test.base.RepositoryMatcher#wrap(org.hamcrest.Matcher) + */ @SafeVarargs public static <T extends Repository, V extends RepositoryConnection> Matcher<T> repositoryMatches(Matcher<V>... matchers) { return RepositoryMatcher.wrap(CoreMatchers.allOf(matchers)); } + /** + * Wrap a {@link org.apache.marmotta.commons.sesame.test.base.AbstractRepositoryConnectionMatcher} with a {@link org.apache.marmotta.commons.sesame.test.base.RdfStringMatcher}, + * to match the provided matcher against an serialized RDF-String. + * + * @param format the RDFFormat used for de-serializing the RDF + * @param baseUri the baseUri used for de-serializing the RDF + * @param matcher the Matcher to wrap + * @see org.apache.marmotta.commons.sesame.test.base.RdfStringMatcher#wrap(org.openrdf.rio.RDFFormat, String, org.hamcrest.Matcher) + */ public static <T extends String, V extends RepositoryConnection> Matcher<T> rdfStringMatches(RDFFormat format, String baseUri, Matcher<V> matcher) { - return RdfStringMatcher.wrap(format, baseUri, matcher); + return RdfStringMatcher.wrap(format, baseUri, matcher); } + /** + * Wrap a {@link org.apache.marmotta.commons.sesame.test.base.AbstractRepositoryConnectionMatcher} with a {@link org.apache.marmotta.commons.sesame.test.base.RdfStringMatcher}, + * to match the provided matcher against an serialized RDF-String. + * + * @param format the RDFFormat used for de-serializing the RDF + * @param baseUri the baseUri used for de-serializing the RDF + * @param matcher1 the Matcher to wrap + * @param matcher2 the Matcher to wrap + * @see org.apache.marmotta.commons.sesame.test.base.RdfStringMatcher#wrap(org.openrdf.rio.RDFFormat, String, org.hamcrest.Matcher) + */ public static <T extends String, V extends RepositoryConnection> Matcher<T> rdfStringMatches(RDFFormat format, String baseUri, Matcher<V> matcher1, Matcher<V> matcher2) { - return RdfStringMatcher.wrap(format, baseUri, CoreMatchers.allOf(matcher1, matcher2)); + return RdfStringMatcher.wrap(format, baseUri, CoreMatchers.allOf(matcher1, matcher2)); } + /** + * Wrap a {@link org.apache.marmotta.commons.sesame.test.base.AbstractRepositoryConnectionMatcher} with a {@link org.apache.marmotta.commons.sesame.test.base.RdfStringMatcher}, + * to match the provided matcher against an serialized RDF-String. + * + * @param format the RDFFormat used for de-serializing the RDF + * @param baseUri the baseUri used for de-serializing the RDF + * @param matchers the Matchers to wrap + * @see org.apache.marmotta.commons.sesame.test.base.RdfStringMatcher#wrap(org.openrdf.rio.RDFFormat, String, org.hamcrest.Matcher) + */ @SafeVarargs public static <T extends String, V extends RepositoryConnection> Matcher<T> rdfStringMatches(RDFFormat format, String baseUri, Matcher<V>... matchers) { - return RdfStringMatcher.wrap(format, baseUri, CoreMatchers.allOf(matchers)); + return RdfStringMatcher.wrap(format, baseUri, CoreMatchers.allOf(matchers)); } + /** + * Wrap a {@link org.apache.marmotta.commons.sesame.test.base.AbstractRepositoryConnectionMatcher} with a {@link org.apache.marmotta.commons.sesame.test.base.RdfStringMatcher}, + * to match the provided matcher against an serialized RDF-String. + * + * @param mimeType the MimeType used to guess the RDFFormat for de-serializing the RDF + * @param baseUri the baseUri used for de-serializing the RDF + * @param matcher the Matcher to wrap + * @see Rio#getParserFormatForMIMEType(String) + * @see org.apache.marmotta.commons.sesame.test.base.RdfStringMatcher#wrap(org.openrdf.rio.RDFFormat, String, org.hamcrest.Matcher) + */ public static <T extends String, V extends RepositoryConnection> Matcher<T> rdfStringMatches(String mimeType, String baseUri, Matcher<V> matcher) { final RDFFormat format = Rio.getParserFormatForMIMEType(mimeType); if (format == null) throw new UnsupportedRDFormatException(mimeType); - return RdfStringMatcher.wrap(format, baseUri, matcher); + return RdfStringMatcher.wrap(format, baseUri, matcher); } + /** + * Wrap a {@link org.apache.marmotta.commons.sesame.test.base.AbstractRepositoryConnectionMatcher} with a {@link org.apache.marmotta.commons.sesame.test.base.RdfStringMatcher}, + * to match the provided matcher against an serialized RDF-String. + * + * @param mimeType the MimeType used to guess the RDFFormat for de-serializing the RDF + * @param baseUri the baseUri used for de-serializing the RDF + * @param matcher1 the Matcher to wrap + * @param matcher2 the Matcher to wrap + * @see Rio#getParserFormatForMIMEType(String) + * @see org.apache.marmotta.commons.sesame.test.base.RdfStringMatcher#wrap(org.openrdf.rio.RDFFormat, String, org.hamcrest.Matcher) + */ public static <T extends String, V extends RepositoryConnection> Matcher<T> rdfStringMatches(String mimeType, String baseUri, Matcher<V> matcher1, Matcher<V> matcher2) { final RDFFormat format = Rio.getParserFormatForMIMEType(mimeType); if (format == null) throw new UnsupportedRDFormatException(mimeType); - return RdfStringMatcher.wrap(format, baseUri, CoreMatchers.allOf(matcher1, matcher2)); + return RdfStringMatcher.wrap(format, baseUri, CoreMatchers.allOf(matcher1, matcher2)); } + /** + * Wrap a {@link org.apache.marmotta.commons.sesame.test.base.AbstractRepositoryConnectionMatcher} with a {@link org.apache.marmotta.commons.sesame.test.base.RdfStringMatcher}, + * to match the provided matcher against an serialized RDF-String. + * + * @param mimeType the MimeType used to guess the RDFFormat for de-serializing the RDF + * @param baseUri the baseUri used for de-serializing the RDF + * @param matchers the Matchers to wrap + * @see Rio#getParserFormatForMIMEType(String) + * @see org.apache.marmotta.commons.sesame.test.base.RdfStringMatcher#wrap(org.openrdf.rio.RDFFormat, String, org.hamcrest.Matcher) + */ @SafeVarargs public static <T extends String, V extends RepositoryConnection> Matcher<T> rdfStringMatches(String mimeType, String baseUri, Matcher<V>... matchers) { final RDFFormat format = Rio.getParserFormatForMIMEType(mimeType); if (format == null) throw new UnsupportedRDFormatException(mimeType); - return RdfStringMatcher.wrap(format, baseUri, CoreMatchers.allOf(matchers)); + return RdfStringMatcher.wrap(format, baseUri, CoreMatchers.allOf(matchers)); } private SesameMatchers() { http://git-wip-us.apache.org/repos/asf/marmotta/blob/2ed1887b/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 93dde30..2608ff9 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 @@ -28,7 +28,7 @@ import org.openrdf.sail.memory.MemoryStore; import java.io.StringReader; /** - * Match an RDF String (various Formats) + * Match against an RDF String (in various Formats) */ public class RdfStringMatcher<T extends String> extends SesameMatcher<T> implements Matcher<T> { @@ -82,6 +82,15 @@ public class RdfStringMatcher<T extends String> extends SesameMatcher<T> impleme description.appendText(format.getName()).appendText(" String ").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 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); } http://git-wip-us.apache.org/repos/asf/marmotta/blob/2ed1887b/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 306b58b..1da1cd3 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 @@ -68,6 +68,11 @@ public class RepositoryMatcher<T extends Repository> extends SesameMatcher<T> im delegate.describeMismatch(item, mismatchDescription); } + /** + * Wrap an instance of an {@link AbstractRepositoryConnectionMatcher} to match against an Sesame {@link Repository}. + * + * @param connectionMatcher the {@link AbstractRepositoryConnectionMatcher} to wrap + */ public static <T extends Repository> Matcher<T> wrap(Matcher<? extends RepositoryConnection> connectionMatcher) { return new RepositoryMatcher<T>(connectionMatcher); } http://git-wip-us.apache.org/repos/asf/marmotta/blob/2ed1887b/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 0da7f4f..e99f338 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 @@ -46,10 +46,28 @@ public class SparqlAskMatcher<T extends RepositoryConnection> extends SparqlMatc description.appendText("Query ").appendValue(query).appendText(" to match"); } + /** + * 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 askQuery the SPARQL ASK query. + * + * @see org.openrdf.query.BooleanQuery#evaluate() + */ public static <T extends RepositoryConnection> Matcher<T> sparqlAsk(String baseUri, String askQuery) { return new SparqlAskMatcher<T>(baseUri, askQuery); } + /** + * Create a SparqlAskMatcher that evaluates a SPARQL ASK query against the {@link org.openrdf.repository.RepositoryConnection} + * 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() + */ public static <T extends RepositoryConnection> Matcher<T> sparqlAsk(String askQuery) { return sparqlAsk(null, askQuery); } http://git-wip-us.apache.org/repos/asf/marmotta/blob/2ed1887b/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 cc356e5..e92309d 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 @@ -27,14 +27,16 @@ import org.openrdf.repository.sail.SailRepository; import org.openrdf.sail.memory.MemoryStore; /** - * + * Match an {@link org.apache.marmotta.commons.sesame.test.base.AbstractRepositoryConnectionMatcher} against the result + * of an SPARQL CONSTRUCT query. */ public class SparqlGraphQueryMatcher<T extends RepositoryConnection> extends SparqlMatcher<T> { - private final Matcher<? extends RepositoryConnection> matcher; + private final Matcher<? extends RepositoryConnection>[] matchers; - protected SparqlGraphQueryMatcher(String baseUri, String query, Matcher<? extends RepositoryConnection> matcher) { + @SafeVarargs + protected SparqlGraphQueryMatcher(String baseUri, String query, Matcher<? extends RepositoryConnection>... matchers) { super(baseUri, query); - this.matcher = matcher; + this.matchers = matchers; } @Override @@ -55,9 +57,12 @@ public class SparqlGraphQueryMatcher<T extends RepositoryConnection> extends Spa } connection2.commit(); - connection2.begin(); - final boolean result = matcher.matches(connection2); - connection2.commit(); + boolean result = true; + for (Matcher<? extends RepositoryConnection> matcher: matchers) { + connection2.begin(); + result &= matcher.matches(connection2); + connection2.commit(); + } return result; } finally { connection2.close(); @@ -69,10 +74,38 @@ public class SparqlGraphQueryMatcher<T extends RepositoryConnection> extends Spa @Override public void describeTo(Description description) { - description.appendText(" Graph ").appendValue(query).appendText(" ").appendDescriptionOf(matcher); + description.appendText(" Graph ").appendValue(query).appendText(" "); + if (matchers.length == 1) { + description.appendDescriptionOf(matchers[0]); + } else { + for (Matcher<? extends RepositoryConnection> matcher : matchers) { + description.appendText("\n ").appendDescriptionOf(matcher); + } + } } + /** + * 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 matcher the AbstractRepositoryConnectionMatcher to match + */ public static <T extends RepositoryConnection> Matcher<T> sparqlGraphQuery(String baseUri, String query, Matcher<? extends RepositoryConnection> matcher) { return new SparqlGraphQueryMatcher<T>(baseUri, query, matcher); } + + /** + * 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 matchers the AbstractRepositoryConnectionMatcher to match + */ + @SafeVarargs + public static <T extends RepositoryConnection> Matcher<T> sparqlGraphQuery(String baseUri, String query, Matcher<? extends RepositoryConnection>... matchers) { + return new SparqlGraphQueryMatcher<T>(baseUri, query, matchers); + } }
