jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cla...@apache.org
Subject [1/2] jena git commit: fix for JENA-1351 : initial implementation of DescribeBilder
Date Sun, 28 May 2017 09:54:12 GMT
Repository: jena
Updated Branches:
  refs/heads/master 4b1f56083 -> a2fb93c2c


fix for JENA-1351 : initial implementation of DescribeBilder

added AF license header

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

Branch: refs/heads/master
Commit: c5786f8114bc322ab32de8ed934b53ccc34c53c7
Parents: f5818d4
Author: Claude Warren <claude@apache.org>
Authored: Sun May 28 10:49:34 2017 +0100
Committer: Claude Warren <claude@apache.org>
Committed: Sun May 28 10:51:39 2017 +0100

----------------------------------------------------------------------
 .../jena/arq/querybuilder/DescribeBuilder.java  | 316 +++++++++++++++++++
 .../jena/arq/querybuilder/SelectBuilder.java    |  20 +-
 .../arq/querybuilder/clauses/SelectClause.java  |  22 +-
 .../arq/querybuilder/handlers/HandlerBlock.java |   2 +-
 .../jena/arq/AbstractRegexpBasedTest.java       |   1 +
 .../DescribeBuilderContractTest.java            |  53 ++++
 .../arq/querybuilder/SelectBuilderTest.java     |  59 ++++
 .../querybuilder/clauses/SelectClauseTest.java  |  70 +---
 8 files changed, 460 insertions(+), 83 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/c5786f81/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/DescribeBuilder.java
----------------------------------------------------------------------
diff --git a/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/DescribeBuilder.java
b/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/DescribeBuilder.java
new file mode 100644
index 0000000..cb20925
--- /dev/null
+++ b/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/DescribeBuilder.java
@@ -0,0 +1,316 @@
+/*
+ * 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.jena.arq.querybuilder;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.jena.arq.querybuilder.clauses.DatasetClause;
+import org.apache.jena.arq.querybuilder.clauses.SelectClause;
+import org.apache.jena.arq.querybuilder.clauses.SolutionModifierClause;
+import org.apache.jena.arq.querybuilder.clauses.WhereClause;
+import org.apache.jena.arq.querybuilder.handlers.DatasetHandler;
+import org.apache.jena.arq.querybuilder.handlers.HandlerBlock;
+import org.apache.jena.arq.querybuilder.handlers.SelectHandler;
+import org.apache.jena.arq.querybuilder.handlers.SolutionModifierHandler;
+import org.apache.jena.graph.FrontsTriple;
+import org.apache.jena.graph.Node;
+import org.apache.jena.graph.Triple;
+import org.apache.jena.query.SortCondition;
+import org.apache.jena.sparql.core.TriplePath;
+import org.apache.jena.sparql.core.Var;
+import org.apache.jena.sparql.expr.Expr;
+import org.apache.jena.sparql.lang.sparql_11.ParseException;
+
+public class DescribeBuilder extends AbstractQueryBuilder<DescribeBuilder> implements

+DatasetClause<DescribeBuilder>,
+	WhereClause<DescribeBuilder>, SolutionModifierClause<DescribeBuilder>, SelectClause<DescribeBuilder>{
+
+	private final HandlerBlock handlerBlock;
+
+	/**
+	 * Constructor.
+	 */
+	public DescribeBuilder() {
+		super();
+		query.setQueryDescribeType();
+		handlerBlock = new HandlerBlock(query);
+	}
+	
+	@Override
+	public SelectHandler getSelectHandler() {
+		return handlerBlock.getSelectHandler();
+	}
+
+	@Override
+	public DescribeBuilder addVar(Object var) {
+		getSelectHandler().addVar(makeVar(var));
+		return this;
+	}
+
+	@Override
+	public DescribeBuilder addVar(Expr expr, Object var) {
+		getSelectHandler().addVar(expr, makeVar(var));
+		return this;
+	}
+
+	@Override
+	public DescribeBuilder addVar(String expr, Object var) throws ParseException {
+		getSelectHandler().addVar(expr, makeVar(var));
+		return this;
+	}
+
+	@Override
+	public List<Var> getVars() {
+		return getSelectHandler().getVars();
+	}
+
+	@Override
+	public DescribeBuilder addOrderBy(Expr orderBy) {
+		getSolutionModifierHandler().addOrderBy(orderBy);
+		return this;
+	}
+
+	@Override
+	public DescribeBuilder addOrderBy(Object orderBy) {
+		getSolutionModifierHandler().addOrderBy(makeVar(orderBy));
+		return this;
+	}
+
+	@Override
+	public DescribeBuilder addOrderBy(SortCondition orderBy) {
+		getSolutionModifierHandler().addOrderBy(orderBy);
+		return this;
+	}
+
+	@Override
+	public DescribeBuilder addOrderBy(Expr orderBy, Order order) {
+		getSolutionModifierHandler().addOrderBy(orderBy, order);
+		return this;
+	}
+
+	@Override
+	public DescribeBuilder addOrderBy(Object orderBy, Order order) {
+		getSolutionModifierHandler().addOrderBy(makeVar(orderBy), order);
+		return this;
+	}
+
+	@Override
+	public DescribeBuilder addGroupBy(Object groupBy) {
+		getSolutionModifierHandler().addGroupBy(makeVar(groupBy));
+		return this;
+	}
+
+	@Override
+	public DescribeBuilder addGroupBy(Expr groupBy) {
+		getSolutionModifierHandler().addGroupBy(groupBy);
+		return this;
+	}
+
+	@Override
+	public DescribeBuilder addGroupBy(Object var, Expr expr) {
+		getSolutionModifierHandler().addGroupBy(makeVar(var), expr);
+		return this;
+	}
+
+	@Override
+	public DescribeBuilder addGroupBy(Object var, String expr) {
+		getSolutionModifierHandler().addGroupBy(makeVar(var), makeExpr(expr));
+		return this;
+	}
+
+	@Override
+	public DescribeBuilder addHaving(String expression) throws ParseException {
+		getSolutionModifierHandler().addHaving(expression);
+		return this;
+	}
+
+	@Override
+	public DescribeBuilder addHaving(Expr expression) throws ParseException {
+		getSolutionModifierHandler().addHaving(expression);
+		return this;
+	}
+
+	@Override
+	public DescribeBuilder addHaving(Object var) throws ParseException {
+		getSolutionModifierHandler().addHaving(makeVar(var));
+		return this;
+	}
+
+	@Override
+	public DescribeBuilder setLimit(int limit) {
+		getSolutionModifierHandler().setLimit(limit);
+		return this;
+	}
+
+	@Override
+	public DescribeBuilder setOffset(int offset) {
+		getSolutionModifierHandler().setOffset(offset);
+		return this;
+	}
+
+	@Override
+	public SolutionModifierHandler getSolutionModifierHandler() {
+		return handlerBlock.getModifierHandler();
+	}
+
+	@Override
+	public DescribeBuilder addWhere(Triple t) {
+		getWhereHandler().addWhere(new TriplePath(t));
+		return this;
+	}
+
+	@Override
+	public DescribeBuilder addWhere(TriplePath t) {
+		getWhereHandler().addWhere(t);
+		return this;
+	}
+
+	@Override
+	public DescribeBuilder addWhere(FrontsTriple t) {
+		getWhereHandler().addWhere(new TriplePath(t.asTriple()));
+		return this;
+	}
+
+	@Override
+	public DescribeBuilder addWhere(Object s, Object p, Object o) {
+		getWhereHandler().addWhere( makeTriplePath(s,p,o));
+		return this;
+	}
+
+	@Override
+	public DescribeBuilder addOptional(Triple t) {
+		getWhereHandler().addOptional( new TriplePath( t ) );
+		return this;
+	}
+
+	@Override
+	public DescribeBuilder addOptional(TriplePath t) {
+		getWhereHandler().addOptional( t );
+		return this;
+	}
+
+	@Override
+	public DescribeBuilder addOptional(FrontsTriple t) {
+		getWhereHandler().addOptional( new TriplePath( t.asTriple() ) );
+		return this;
+	}
+
+	@Override
+	public DescribeBuilder addOptional(Object s, Object p, Object o) {
+		getWhereHandler().addOptional( makeTriplePath( s, p, o ) );
+		return this;
+	}
+
+	@Override
+	public DescribeBuilder addOptional(AbstractQueryBuilder<?> t) {
+		getWhereHandler().addOptional(t.getWhereHandler());
+		return this;
+	}
+
+	@Override
+	public DescribeBuilder addFilter(String expression) throws ParseException {
+		getWhereHandler().addFilter(expression);
+		return this;
+	}
+
+	@Override
+	public DescribeBuilder addFilter(Expr expression) {
+		getWhereHandler().addFilter(expression);
+		return this;
+	}
+
+	@Override
+	public DescribeBuilder addSubQuery(AbstractQueryBuilder<?> subQuery) {
+		getWhereHandler().addSubQuery(subQuery);
+		return this;
+	}
+
+	@Override
+	public DescribeBuilder addUnion(AbstractQueryBuilder<?> union) {
+		getWhereHandler().addUnion(union);
+		return this;
+	}
+
+	@Override
+	public DescribeBuilder addGraph(Object graph, AbstractQueryBuilder<?> subQuery) {
+		getPrologHandler().addAll(subQuery.getPrologHandler());
+		getWhereHandler().addGraph(makeNode(graph), subQuery.getWhereHandler());
+		return this;
+	}
+
+	@Override
+	public DescribeBuilder addBind(Expr expression, Object var) {
+		getWhereHandler().addBind(expression, makeVar(var));
+		return this;
+	}
+
+	@Override
+	public DescribeBuilder addBind(String expression, Object var) throws ParseException {
+		getWhereHandler().addBind(expression, makeVar(var));
+		return this;
+	}
+
+	@Override
+	public Node list(Object... objs) {
+		return getWhereHandler().list(objs);
+	}
+
+	@Override
+	public DescribeBuilder addMinus(AbstractQueryBuilder<?> t) {
+		getWhereHandler().addMinus( t );
+		return this;
+	}
+
+	@Override
+	public DescribeBuilder fromNamed(String graphName) {
+		getDatasetHandler().fromNamed(graphName);
+		return this;
+	}
+
+	@Override
+	public DescribeBuilder fromNamed(Collection<String> graphNames) {
+		getDatasetHandler().fromNamed(graphNames);
+		return this;
+	}
+
+	@Override
+	public DescribeBuilder from(String graphName) {
+		getDatasetHandler().from(graphName);
+		return this;
+	}
+
+	@Override
+	public DescribeBuilder from(Collection<String> graphName) {
+		getDatasetHandler().from(graphName);
+		return this;
+	}
+
+	@Override
+	public DatasetHandler getDatasetHandler() {
+		return handlerBlock.getDatasetHandler();
+	}
+
+	@Override
+	public HandlerBlock getHandlerBlock() {
+		return handlerBlock;
+	}
+	
+	
+
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/c5786f81/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/SelectBuilder.java
----------------------------------------------------------------------
diff --git a/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/SelectBuilder.java
b/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/SelectBuilder.java
index 0978c8e..a0ecd90 100644
--- a/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/SelectBuilder.java
+++ b/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/SelectBuilder.java
@@ -73,13 +73,29 @@ public class SelectBuilder extends AbstractQueryBuilder<SelectBuilder>
implement
 		return qb;
 	}
 
-	@Override
+	/**
+	 * Set set the distinct flag.
+	 * 
+	 * Setting the select distinct will unset reduced if it was set.
+	 * 
+	 * @param state
+	 *            if true results will be distinct.
+	 * @return The builder for chaining.
+	 */
 	public SelectBuilder setDistinct(boolean state) {
 		getSelectHandler().setDistinct(state);
 		return this;
 	}
 
-	@Override
+	/**
+	 * Set set the reduced flag.
+	 * 
+	 * Setting the select reduced will unset distinct if it was set.
+	 * 
+	 * @param state
+	 *            if true results will be reduced.
+	 * @return The builder for chaining.
+	 */
 	public SelectBuilder setReduced(boolean state) {
 		getSelectHandler().setReduced(state);
 		return this;

http://git-wip-us.apache.org/repos/asf/jena/blob/c5786f81/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/clauses/SelectClause.java
----------------------------------------------------------------------
diff --git a/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/clauses/SelectClause.java
b/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/clauses/SelectClause.java
index dc83218..756d36c 100644
--- a/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/clauses/SelectClause.java
+++ b/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/clauses/SelectClause.java
@@ -40,27 +40,7 @@ public interface SelectClause<T extends AbstractQueryBuilder<T>>
{
 	 */
 	public SelectHandler getSelectHandler();
 
-	/**
-	 * Set set the distinct flag.
-	 * 
-	 * Setting the select distinct will unset reduced if it was set.
-	 * 
-	 * @param state
-	 *            if true results will be distinct.
-	 * @return The builder for chaining.
-	 */
-	public T setDistinct(boolean state);
-
-	/**
-	 * Set set the reduced flag.
-	 * 
-	 * Setting the select reduced will unset distinct if it was set.
-	 * 
-	 * @param state
-	 *            if true results will be reduced.
-	 * @return The builder for chaining.
-	 */
-	public T setReduced(boolean state);
+	
 
 	/**
 	 * Add a variable to the select statement.

http://git-wip-us.apache.org/repos/asf/jena/blob/c5786f81/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/handlers/HandlerBlock.java
----------------------------------------------------------------------
diff --git a/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/handlers/HandlerBlock.java
b/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/handlers/HandlerBlock.java
index 5e84e15..41bd925 100644
--- a/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/handlers/HandlerBlock.java
+++ b/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/handlers/HandlerBlock.java
@@ -61,7 +61,7 @@ public class HandlerBlock {
 		} else if (query.isAskType()) {
 			// nochange
 		} else if (query.isDescribeType()) {
-			// no change
+			sTemp = new SelectHandler(aggHandler);
 		} else if (query.isConstructType()) {
 			cTemp = new ConstructHandler(query);
 		}

http://git-wip-us.apache.org/repos/asf/jena/blob/c5786f81/jena-extras/jena-querybuilder/src/test/java/org/apache/jena/arq/AbstractRegexpBasedTest.java
----------------------------------------------------------------------
diff --git a/jena-extras/jena-querybuilder/src/test/java/org/apache/jena/arq/AbstractRegexpBasedTest.java
b/jena-extras/jena-querybuilder/src/test/java/org/apache/jena/arq/AbstractRegexpBasedTest.java
index 47e907b..0021b8b 100644
--- a/jena-extras/jena-querybuilder/src/test/java/org/apache/jena/arq/AbstractRegexpBasedTest.java
+++ b/jena-extras/jena-querybuilder/src/test/java/org/apache/jena/arq/AbstractRegexpBasedTest.java
@@ -44,6 +44,7 @@ public abstract class AbstractRegexpBasedTest {
 	protected static final String CONSTRUCT = "CONSTRUCT" + SPACE;
 	protected static final String ASK = "ASK" + SPACE;
 	protected static final String SELECT = "SELECT" + SPACE;
+	protected static final String DESCRIBE = "DESCRIBE" + SPACE;
 	protected static final String UNION = "UNION" + SPACE;
 	protected static final String LIMIT = "LIMIT" + SPACE;
 	protected static final String OFFSET = "OFFSET" + SPACE;

http://git-wip-us.apache.org/repos/asf/jena/blob/c5786f81/jena-extras/jena-querybuilder/src/test/java/org/apache/jena/arq/querybuilder/DescribeBuilderContractTest.java
----------------------------------------------------------------------
diff --git a/jena-extras/jena-querybuilder/src/test/java/org/apache/jena/arq/querybuilder/DescribeBuilderContractTest.java
b/jena-extras/jena-querybuilder/src/test/java/org/apache/jena/arq/querybuilder/DescribeBuilderContractTest.java
new file mode 100644
index 0000000..a4ed110
--- /dev/null
+++ b/jena-extras/jena-querybuilder/src/test/java/org/apache/jena/arq/querybuilder/DescribeBuilderContractTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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.jena.arq.querybuilder;
+
+import org.junit.runner.RunWith;
+import org.xenei.junit.contract.Contract;
+import org.xenei.junit.contract.ContractImpl;
+import org.xenei.junit.contract.ContractSuite;
+import org.xenei.junit.contract.IProducer;
+
+@RunWith(ContractSuite.class)
+@ContractImpl(DescribeBuilder.class)
+public class DescribeBuilderContractTest {
+
+	// create the producer to inject
+	private IProducer<DescribeBuilder> producer = new IProducer<DescribeBuilder>()
{
+
+		@Override
+		public DescribeBuilder newInstance() {
+			return new DescribeBuilder();
+		}
+
+		@Override
+		public void cleanUp() {
+			// no cleanup required
+		}
+
+	};
+
+	public DescribeBuilderContractTest() {
+	}
+
+	@Contract.Inject
+	public IProducer<DescribeBuilder> getProducer() {
+		return producer;
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/c5786f81/jena-extras/jena-querybuilder/src/test/java/org/apache/jena/arq/querybuilder/SelectBuilderTest.java
----------------------------------------------------------------------
diff --git a/jena-extras/jena-querybuilder/src/test/java/org/apache/jena/arq/querybuilder/SelectBuilderTest.java
b/jena-extras/jena-querybuilder/src/test/java/org/apache/jena/arq/querybuilder/SelectBuilderTest.java
index c20283b..ebe238e 100644
--- a/jena-extras/jena-querybuilder/src/test/java/org/apache/jena/arq/querybuilder/SelectBuilderTest.java
+++ b/jena-extras/jena-querybuilder/src/test/java/org/apache/jena/arq/querybuilder/SelectBuilderTest.java
@@ -23,6 +23,8 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
 import org.apache.jena.arq.AbstractRegexpBasedTest;
+import org.apache.jena.arq.querybuilder.clauses.SelectClause;
+import org.apache.jena.query.Query;
 import org.apache.jena.query.QueryExecution;
 import org.apache.jena.query.QueryExecutionFactory;
 import org.apache.jena.query.QuerySolution;
@@ -36,6 +38,7 @@ import org.apache.jena.vocabulary.RDF;
 import org.apache.jena.vocabulary.XSD;
 import org.junit.Before;
 import org.junit.Test;
+import org.xenei.junit.contract.ContractTest;
 
 public class SelectBuilderTest extends AbstractRegexpBasedTest {
 
@@ -269,4 +272,60 @@ public class SelectBuilderTest extends AbstractRegexpBasedTest {
 			}
 		}
 	}
+	
+	
+	@Test
+	public void setDistinctTest() throws Exception {
+		Query query = builder.query;
+		assertFalse(query.isDistinct());
+		assertFalse(query.isReduced());
+
+		query = builder.setDistinct(true).query;
+		assertTrue(query.isDistinct());
+		assertFalse(query.isReduced());
+
+		query = builder.setReduced(false).query;
+		assertTrue(query.isDistinct());
+		assertFalse(query.isReduced());
+
+		query = builder.setReduced(true).query;
+		assertFalse(query.isDistinct());
+		assertTrue(query.isReduced());
+
+		query = builder.setDistinct(true).query;
+		assertTrue(query.isDistinct());
+		assertFalse(query.isReduced());
+
+		query = builder.setDistinct(false).query;
+		assertFalse(query.isDistinct());
+		assertFalse(query.isReduced());
+	}
+
+	@Test
+	public void setReducedTest() throws Exception {
+		Query query = builder.query;
+		assertFalse(query.isDistinct());
+		assertFalse(query.isReduced());
+
+		query = builder.setReduced(true).query;
+		assertFalse(query.isDistinct());
+		assertTrue(query.isReduced());
+
+		query = builder.setDistinct(false).query;
+		assertFalse(query.isDistinct());
+		assertTrue(query.isReduced());
+
+		query = builder.setDistinct(true).query;
+		assertTrue(query.isDistinct());
+		assertFalse(query.isReduced());
+
+		query = builder.setReduced(true).query;
+		assertFalse(query.isDistinct());
+		assertTrue(query.isReduced());
+
+		query = builder.setReduced(false).query;
+		assertFalse(query.isDistinct());
+		assertFalse(query.isReduced());
+	}
+
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/c5786f81/jena-extras/jena-querybuilder/src/test/java/org/apache/jena/arq/querybuilder/clauses/SelectClauseTest.java
----------------------------------------------------------------------
diff --git a/jena-extras/jena-querybuilder/src/test/java/org/apache/jena/arq/querybuilder/clauses/SelectClauseTest.java
b/jena-extras/jena-querybuilder/src/test/java/org/apache/jena/arq/querybuilder/clauses/SelectClauseTest.java
index c3ab7f3..4d6cd51 100644
--- a/jena-extras/jena-querybuilder/src/test/java/org/apache/jena/arq/querybuilder/clauses/SelectClauseTest.java
+++ b/jena-extras/jena-querybuilder/src/test/java/org/apache/jena/arq/querybuilder/clauses/SelectClauseTest.java
@@ -19,6 +19,8 @@ package org.apache.jena.arq.querybuilder.clauses;
 
 import static org.junit.Assert.*;
 
+import java.util.List;
+
 import org.apache.jena.arq.querybuilder.AbstractQueryBuilder;
 import org.apache.jena.arq.querybuilder.handlers.SelectHandler;
 import org.apache.jena.graph.NodeFactory ;
@@ -61,62 +63,7 @@ public class SelectClauseTest<T extends SelectClause<?>> extends
 		assertNotNull(handler);
 	}
 
-	@ContractTest
-	public void setDistinctTest() throws Exception {
-		SelectClause<?> selectClause = getProducer().newInstance();
-		Query query = getQuery((AbstractQueryBuilder<?>) selectClause);
-		assertFalse(query.isDistinct());
-		assertFalse(query.isReduced());
-
-		query = getQuery(selectClause.setDistinct(true));
-		assertTrue(query.isDistinct());
-		assertFalse(query.isReduced());
-
-		query = getQuery(selectClause.setReduced(false));
-		assertTrue(query.isDistinct());
-		assertFalse(query.isReduced());
-
-		query = getQuery(selectClause.setReduced(true));
-		assertFalse(query.isDistinct());
-		assertTrue(query.isReduced());
-
-		query = getQuery(selectClause.setDistinct(true));
-		assertTrue(query.isDistinct());
-		assertFalse(query.isReduced());
-
-		query = getQuery(selectClause.setDistinct(false));
-		assertFalse(query.isDistinct());
-		assertFalse(query.isReduced());
-	}
-
-	@ContractTest
-	public void setReducedTest() throws Exception {
-		SelectClause<?> selectClause = getProducer().newInstance();
-		Query query = getQuery((AbstractQueryBuilder<?>) selectClause);
-		assertFalse(query.isDistinct());
-		assertFalse(query.isReduced());
-
-		query = getQuery(selectClause.setReduced(true));
-		assertFalse(query.isDistinct());
-		assertTrue(query.isReduced());
-
-		query = getQuery(selectClause.setDistinct(false));
-		assertFalse(query.isDistinct());
-		assertTrue(query.isReduced());
-
-		query = getQuery(selectClause.setDistinct(true));
-		assertTrue(query.isDistinct());
-		assertFalse(query.isReduced());
-
-		query = getQuery(selectClause.setReduced(true));
-		assertFalse(query.isDistinct());
-		assertTrue(query.isReduced());
-
-		query = getQuery(selectClause.setReduced(false));
-		assertFalse(query.isDistinct());
-		assertFalse(query.isReduced());
-	}
-
+	
 	@ContractTest
 	public void testAddVarString() throws Exception {
 		Var v = Var.alloc("one");
@@ -151,12 +98,17 @@ public class SelectClauseTest<T extends SelectClause<?>>
extends
 	}
 
 	@ContractTest
-	public void getVarsTest() {
+	public void getVarsTest()  {
 		SelectClause<?> selectClause = getProducer().newInstance();
 		AbstractQueryBuilder<?> builder = selectClause.addVar(NodeFactory
 				.createVariable("foo"));
-		String[] s = byLine(builder);
-		assertContainsRegex( SELECT+var("foo"), s );
+		try {
+			List<Var> vars = getQuery(builder).getProjectVars();
+			assertEquals( 1, vars.size());
+			assertEquals( "?foo", vars.get(0).toString());
+		} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException
e) {
+			fail( "Unable to access query from queryBuilder: "+e.getMessage() );
+		}
 	}
 
 	@ContractTest


Mime
View raw message