jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cla...@apache.org
Subject [1/4] jena git commit: Fixes for JENA-1143
Date Sun, 14 Feb 2016 20:18:28 GMT
Repository: jena
Updated Branches:
  refs/heads/master 0279a0dad -> a9762976e


Fixes for JENA-1143


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

Branch: refs/heads/master
Commit: bac245114ce6ab7f8f1691a70ac5cec32f41686a
Parents: 0279a0d
Author: Claude Warren <claude@apache.org>
Authored: Sun Feb 14 17:19:21 2016 +0000
Committer: Claude Warren <claude@apache.org>
Committed: Sun Feb 14 17:19:21 2016 +0000

----------------------------------------------------------------------
 .../arq/querybuilder/AbstractQueryBuilder.java  |  14 +
 .../arq/querybuilder/handlers/WhereHandler.java | 281 ++++++++-------
 .../jena/arq/AbstractRegexpBasedTest.java       |   2 +
 .../jena/arq/querybuilder/AskBuilderTest.java   | 141 ++++++++
 .../arq/querybuilder/ConstructBuilderTest.java  | 162 +++++++++
 .../arq/querybuilder/SelectBuilderTest.java     |  17 +
 .../querybuilder/clauses/WhereClauseTest.java   |  22 +-
 .../querybuilder/handlers/WhereHandlerTest.java | 342 +++++++++----------
 8 files changed, 664 insertions(+), 317 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/bac24511/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/AbstractQueryBuilder.java
----------------------------------------------------------------------
diff --git a/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/AbstractQueryBuilder.java b/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/AbstractQueryBuilder.java
index a4f0ddb..b05fc4e 100644
--- a/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/AbstractQueryBuilder.java
+++ b/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/AbstractQueryBuilder.java
@@ -364,6 +364,20 @@ public abstract class AbstractQueryBuilder<T extends AbstractQueryBuilder<T>>
 	 */
 	public static Query clone(Query q2) {
 		Query retval = new Query();
+		
+	    if (q2.isSelectType())
+	    {
+	    	retval.setQuerySelectType();
+	    } else if (q2.isAskType()) {
+	    	retval.setQueryAskType();
+	    } else if (q2.isDescribeType())
+	    {
+	    	retval.setQueryDescribeType();
+	    } else if (q2.isConstructType()) 
+	    {
+	    	retval.setQueryConstructType();
+	    }
+	    
 		new PrologHandler(retval).addAll(new PrologHandler(q2));
 		new ConstructHandler(retval).addAll(new ConstructHandler(q2));
 		new DatasetHandler(retval).addAll(new DatasetHandler(q2));

http://git-wip-us.apache.org/repos/asf/jena/blob/bac24511/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/handlers/WhereHandler.java
----------------------------------------------------------------------
diff --git a/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/handlers/WhereHandler.java b/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/handlers/WhereHandler.java
index d01c3bf..08b0412 100644
--- a/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/handlers/WhereHandler.java
+++ b/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/handlers/WhereHandler.java
@@ -17,28 +17,31 @@
  */
 package org.apache.jena.arq.querybuilder.handlers;
 
-import java.util.Iterator ;
-import java.util.List ;
-import java.util.Map ;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
 
 import org.apache.jena.arq.querybuilder.AbstractQueryBuilder;
 import org.apache.jena.arq.querybuilder.SelectBuilder;
 import org.apache.jena.arq.querybuilder.clauses.ConstructClause;
 import org.apache.jena.arq.querybuilder.rewriters.ElementRewriter;
-import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.Node;
 import org.apache.jena.graph.NodeFactory;
-import org.apache.jena.graph.Triple ;
-import org.apache.jena.query.Query ;
-import org.apache.jena.sparql.core.Var ;
-import org.apache.jena.sparql.expr.Expr ;
-import org.apache.jena.sparql.lang.sparql_11.ParseException ;
-import org.apache.jena.sparql.syntax.* ;
-import org.apache.jena.sparql.util.ExprUtils ;
+import org.apache.jena.graph.Triple;
+import org.apache.jena.query.Query;
+import org.apache.jena.sparql.core.Var;
+import org.apache.jena.sparql.expr.Expr;
+import org.apache.jena.sparql.lang.sparql_11.ParseException;
+import org.apache.jena.sparql.syntax.*;
+import org.apache.jena.sparql.util.ExprUtils;
 import org.apache.jena.vocabulary.RDF;
 
 /**
- * The where handler.  Generally handles GroupGraphPattern.
- * @see <a href="http://www.w3.org/TR/2013/REC-sparql11-query-20130321/#rGroupGraphPattern">SPARQL 11 Query Language - Group Graph Pattern</a>
+ * The where handler. Generally handles GroupGraphPattern.
+ * 
+ * @see <a href=
+ *      "http://www.w3.org/TR/2013/REC-sparql11-query-20130321/#rGroupGraphPattern">
+ *      SPARQL 11 Query Language - Group Graph Pattern</a>
  *
  */
 public class WhereHandler implements Handler {
@@ -48,7 +51,9 @@ public class WhereHandler implements Handler {
 
 	/**
 	 * Constructor.
-	 * @param query The query to manipulate.
+	 * 
+	 * @param query
+	 *            The query to manipulate.
 	 */
 	public WhereHandler(Query query) {
 		this.query = query;
@@ -56,90 +61,110 @@ public class WhereHandler implements Handler {
 
 	/**
 	 * Add all where attributes from the Where Handler argument.
-	 * @param whereHandler The Where Handler to copy from.
+	 * 
+	 * @param whereHandler
+	 *            The Where Handler to copy from.
 	 */
 	public void addAll(WhereHandler whereHandler) {
 		Element e = whereHandler.query.getQueryPattern();
-		Element locE = query.getQueryPattern();
 		if (e != null) {
-			if (locE == null) {
-				query.setQueryPattern(e);
+			// clone the Element
+			ElementRewriter rewriter = new ElementRewriter(Collections.emptyMap());
+			e.visit(rewriter);
+			Element clone = rewriter.getResult();
+			Element mine = query.getQueryPattern();
+			if (mine == null) {
+				query.setQueryPattern(clone);
 			} else {
-				ElementTriplesBlock locEtb = (ElementTriplesBlock) locE;
-				ElementTriplesBlock etp = (ElementTriplesBlock) e;
-				Iterator<Triple> iter = etp.patternElts();
-				while (iter.hasNext()) {
-					locEtb.addTriple(iter.next());
+				ElementGroup eg = null;
+				if (mine instanceof ElementGroup) {
+					eg = (ElementGroup) mine;
+				} else {
+					eg = new ElementGroup();
+					eg.addElement(mine);
 				}
+				if (clone instanceof ElementGroup) {
+					for (Element ele : ((ElementGroup) clone).getElements()) {
+						eg.addElement(ele);
+					}
+				} else {
+					eg.addElement(clone);
+				}
+				query.setQueryPattern(eg);
 			}
 		}
 	}
 
 	/**
-	 * Get the base element from the where clause.
-	 * If the clause does not contain an element return the element group, otherwise return the 
+	 * Get the base element from the where clause. If the clause does not
+	 * contain an element return the element group, otherwise return the
 	 * enclosed elelment.
+	 * 
 	 * @return the base element.
 	 */
 	private Element getElement() {
-		ElementGroup eg = getClause();
-		if (eg.getElements().size() == 1) {
-			return eg.getElements().get(0);
+		Element result = query.getQueryPattern();
+		if (result == null) {
+			result = getClause();
 		}
-		return eg;
+		return result;
 	}
 
 	/**
-	 * Get the element group for the clause.
-	 * if HTe element group is not set, create and set it.
+	 * Get the element group for the clause. if The element group is not set,
+	 * create and set it.
+	 * 
 	 * @return The element group.
 	 */
 	private ElementGroup getClause() {
-		ElementGroup e = (ElementGroup) query.getQueryPattern();
+		Element e = query.getQueryPattern();
 		if (e == null) {
 			e = new ElementGroup();
 			query.setQueryPattern(e);
 		}
-		return e;
+		if (e instanceof ElementGroup) {
+			return (ElementGroup) e;
+		}
+
+		ElementGroup eg = new ElementGroup();
+		eg.addElement(e);
+		;
+		query.setQueryPattern(eg);
+		return eg;
 	}
 
 	/**
-	 * Test that a triple is valid.
-	 * Throws an IllegalArgumentException if the triple is not valid.
-	 * @param t The trip to test.
+	 * Test that a triple is valid. Throws an IllegalArgumentException if the
+	 * triple is not valid.
+	 * 
+	 * @param t
+	 *            The trip to test.
 	 */
 	private void testTriple(Triple t) {
 		// verify Triple is valid
-		boolean validSubject = t.getSubject().isURI()
-				|| t.getSubject().isBlank() || t.getSubject().isVariable()
+		boolean validSubject = t.getSubject().isURI() || t.getSubject().isBlank() || t.getSubject().isVariable()
 				|| t.getSubject().equals(Node.ANY);
-		boolean validPredicate = t.getPredicate().isURI()
-				|| t.getPredicate().isVariable()
+		boolean validPredicate = t.getPredicate().isURI() || t.getPredicate().isVariable()
 				|| t.getPredicate().equals(Node.ANY);
-		boolean validObject = t.getObject().isURI()
-				|| t.getObject().isLiteral() || t.getObject().isBlank()
+		boolean validObject = t.getObject().isURI() || t.getObject().isLiteral() || t.getObject().isBlank()
 				|| t.getObject().isVariable() || t.getObject().equals(Node.ANY);
 
 		if (!validSubject || !validPredicate || !validObject) {
 			StringBuilder sb = new StringBuilder();
 			if (!validSubject) {
-				sb.append(String
-						.format("Subject (%s) must be a URI, blank, variable, or a wildcard. %n",
-								t.getSubject()));
+				sb.append(String.format("Subject (%s) must be a URI, blank, variable, or a wildcard. %n",
+						t.getSubject()));
 			}
 			if (!validPredicate) {
-				sb.append(String
-						.format("Predicate (%s) must be a URI , variable, or a wildcard. %n",
-								t.getPredicate()));
+				sb.append(
+						String.format("Predicate (%s) must be a URI , variable, or a wildcard. %n", t.getPredicate()));
 			}
 			if (!validObject) {
-				sb.append(String
-						.format("Object (%s) must be a URI, literal, blank, , variable, or a wildcard. %n",
-								t.getObject()));
+				sb.append(String.format("Object (%s) must be a URI, literal, blank, , variable, or a wildcard. %n",
+						t.getObject()));
 			}
 			if (!validSubject || !validPredicate) {
-				sb.append(String
-						.format("Is a prefix missing?  Prefix must be defined before use. %n"));
+				sb.append(String.format("Is a prefix missing?  Prefix must be defined before use. %n"));
 			}
 			throw new IllegalArgumentException(sb.toString());
 		}
@@ -147,8 +172,11 @@ public class WhereHandler implements Handler {
 
 	/**
 	 * Add the triple to the where clause
-	 * @param t The triple to add.
-	 * @throws IllegalArgumentException If the triple is not a valid triple for a where clause.
+	 * 
+	 * @param t
+	 *            The triple to add.
+	 * @throws IllegalArgumentException
+	 *             If the triple is not a valid triple for a where clause.
 	 */
 	public void addWhere(Triple t) throws IllegalArgumentException {
 		testTriple(t);
@@ -177,8 +205,11 @@ public class WhereHandler implements Handler {
 
 	/**
 	 * Add an optional triple to the where clause
-	 * @param t The triple to add.
-	 * @throws IllegalArgumentException If the triple is not a valid triple for a where clause.
+	 * 
+	 * @param t
+	 *            The triple to add.
+	 * @throws IllegalArgumentException
+	 *             If the triple is not a valid triple for a where clause.
 	 */
 	public void addOptional(Triple t) throws IllegalArgumentException {
 		testTriple(t);
@@ -187,23 +218,28 @@ public class WhereHandler implements Handler {
 		ElementOptional opt = new ElementOptional(epb);
 		getClause().addElement(opt);
 	}
-	
+
 	public void addOptional(WhereHandler whereHandler) {
-		getClause().addElement( new ElementOptional( whereHandler.getClause()));
+		getClause().addElement(new ElementOptional(whereHandler.getClause()));
 	}
 
 	/**
 	 * Add an expression string as a filter.
-	 * @param expression The expression string to add.
-	 * @throws ParseException If the expression can not be parsed.
+	 * 
+	 * @param expression
+	 *            The expression string to add.
+	 * @throws ParseException
+	 *             If the expression can not be parsed.
 	 */
 	public void addFilter(String expression) throws ParseException {
-		getClause().addElement( new ElementFilter( ExprUtils.parse( query, expression, true ) ) );
+		getClause().addElement(new ElementFilter(ExprUtils.parse(query, expression, true)));
 	}
 
 	/**
 	 * add an expression as a filter.
-	 * @param expr The expression to add.
+	 * 
+	 * @param expr
+	 *            The expression to add.
 	 */
 	public void addFilter(Expr expr) {
 		getClause().addElement(new ElementFilter(expr));
@@ -211,7 +247,9 @@ public class WhereHandler implements Handler {
 
 	/**
 	 * Add a subquery to the where clause.
-	 * @param subQuery The sub query to add.
+	 * 
+	 * @param subQuery
+	 *            The sub query to add.
 	 */
 	public void addSubQuery(SelectBuilder subQuery) {
 		getClause().addElement(makeSubQuery(subQuery));
@@ -219,7 +257,9 @@ public class WhereHandler implements Handler {
 
 	/**
 	 * Convert a subquery into a subquery element.
-	 * @param subQuery The sub query to convert
+	 * 
+	 * @param subQuery
+	 *            The sub query to convert
 	 * @return THe converted element.
 	 */
 	private ElementSubQuery makeSubQuery(SelectBuilder subQuery) {
@@ -238,42 +278,40 @@ public class WhereHandler implements Handler {
 
 		}
 		DatasetHandler dh = new DatasetHandler(q);
-		dh.addAll( subQuery.getDatasetHandler() );
+		dh.addAll(subQuery.getDatasetHandler());
 		SolutionModifierHandler smh = new SolutionModifierHandler(q);
-		smh.addAll( subQuery.getSolutionModifierHandler() );
+		smh.addAll(subQuery.getSolutionModifierHandler());
 		WhereHandler wh = new WhereHandler(q);
-		wh.addAll( subQuery.getWhereHandler() );
+		wh.addAll(subQuery.getWhereHandler());
 		return new ElementSubQuery(q);
 
 	}
 
 	/**
 	 * Add a union to the where clause.
-	 * @param subQuery The subquery to add as the union.
+	 * 
+	 * @param subQuery
+	 *            The subquery to add as the union.
 	 */
 	public void addUnion(SelectBuilder subQuery) {
-		ElementUnion union=null; 
+		ElementUnion union = null;
 		ElementGroup clause = getClause();
 		// if the last element is a union make sure we add to it.
-		if ( ! clause.isEmpty() ) {
-			Element lastElement =  clause.getElements().get(clause.getElements().size()-1);
-			if (lastElement instanceof ElementUnion)	
-			{
+		if (!clause.isEmpty()) {
+			Element lastElement = clause.getElements().get(clause.getElements().size() - 1);
+			if (lastElement instanceof ElementUnion) {
 				union = (ElementUnion) lastElement;
-			}
-			else 
-			{
-				// clauses is not empty and is not a union so it is the left side of the union.
+			} else {
+				// clauses is not empty and is not a union so it is the left
+				// side of the union.
 				union = new ElementUnion();
-				union.addElement( clause );
-				query.setQueryPattern( union );
+				union.addElement(clause);
+				query.setQueryPattern(union);
 			}
-		}
-		else
-		{
+		} else {
 			// add the union as the first element in the clause.
 			union = new ElementUnion();
-			clause.addElement( union );
+			clause.addElement(union);
 		}
 		// if there are projected vars then do a full blown subquery
 		// otherwise just add the clause.
@@ -282,46 +320,48 @@ public class WhereHandler implements Handler {
 		} else {
 			PrologHandler ph = new PrologHandler(query);
 			ph.addAll(subQuery.getPrologHandler());
-			union.addElement( subQuery.getWhereHandler().getClause() );
+			union.addElement(subQuery.getWhereHandler().getClause());
 		}
-		
+
 	}
 
 	/**
 	 * Add a graph to the where clause.
-	 * @param graph The name of the graph.
-	 * @param subQuery The where handler that defines the graph.
+	 * 
+	 * @param graph
+	 *            The name of the graph.
+	 * @param subQuery
+	 *            The where handler that defines the graph.
 	 */
 	public void addGraph(Node graph, WhereHandler subQuery) {
-		getClause().addElement(
-				new ElementNamedGraph(graph, subQuery.getElement()));
+		getClause().addElement(new ElementNamedGraph(graph, subQuery.getElement()));
 	}
-	
+
 	/**
 	 * Add a binding to the where clause.
-	 * @param expr The expression to bind.
-	 * @param var The variable to bind it to.
+	 * 
+	 * @param expr
+	 *            The expression to bind.
+	 * @param var
+	 *            The variable to bind it to.
 	 */
-	public void addBind( Expr expr, Var var )
-	{
-		getClause().addElement(
-				new ElementBind(var,expr)
-				);
+	public void addBind(Expr expr, Var var) {
+		getClause().addElement(new ElementBind(var, expr));
 	}
 
 	/**
 	 * Add a binding to the where clause.
-	 * @param expression The expression to bind.
-	 * @param var The variable to bind it to.
-	 * @throws ParseException 
+	 * 
+	 * @param expression
+	 *            The expression to bind.
+	 * @param var
+	 *            The variable to bind it to.
+	 * @throws ParseException
 	 */
-	public void addBind( String expression, Var var ) throws ParseException
-	{
-		getClause().addElement(
-				new ElementBind(var, ExprUtils.parse( query, expression, true ))
-				);
+	public void addBind(String expression, Var var) throws ParseException {
+		getClause().addElement(new ElementBind(var, ExprUtils.parse(query, expression, true)));
 	}
-	
+
 	@Override
 	public void setVars(Map<Var, Node> values) {
 		if (values.isEmpty()) {
@@ -340,33 +380,32 @@ public class WhereHandler implements Handler {
 	public void build() {
 		// no special operations required.
 	}
-	
+
 	/**
 	 * Create a list node from a list of objects as per RDF Collections.
 	 * 
-	 * http://www.w3.org/TR/2013/REC-sparql11-query-20130321/#collections 
+	 * http://www.w3.org/TR/2013/REC-sparql11-query-20130321/#collections
 	 * 
-	 * @param objs the list of objects for the list.
+	 * @param objs
+	 *            the list of objects for the list.
 	 * @return the first blank node in the list.
 	 */
-	public Node list( Object ... objs) {
+	public Node list(Object... objs) {
 		Node retval = NodeFactory.createBlankNode();
 		Node lastObject = retval;
-		for (int i=0;i<objs.length;i++ )
-		{
-			Node n = AbstractQueryBuilder.makeNode( objs[i], query.getPrefixMapping() );
-			addWhere( new Triple( lastObject, RDF.first.asNode(), n ));
-			if (i+1 < objs.length)
-			{
+		for (int i = 0; i < objs.length; i++) {
+			Node n = AbstractQueryBuilder.makeNode(objs[i], query.getPrefixMapping());
+			addWhere(new Triple(lastObject, RDF.first.asNode(), n));
+			if (i + 1 < objs.length) {
 				Node nextObject = NodeFactory.createBlankNode();
-				addWhere( new Triple( lastObject, RDF.rest.asNode(), nextObject ));
+				addWhere(new Triple(lastObject, RDF.rest.asNode(), nextObject));
 				lastObject = nextObject;
 			} else {
-				addWhere( new Triple( lastObject, RDF.rest.asNode(), RDF.nil.asNode() ));
+				addWhere(new Triple(lastObject, RDF.rest.asNode(), RDF.nil.asNode()));
 			}
-			
+
 		}
-		
+
 		return retval;
 	}
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/bac24511/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 5e3d552..6be2010 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
@@ -41,6 +41,8 @@ public abstract class AbstractRegexpBasedTest {
 	protected static final String GROUP_BY = "GROUP" + SPACE + "BY" + SPACE;
 	protected static final String HAVING = "HAVING" + SPACE;
 	protected static final String PREFIX = "PREFIX" + SPACE;
+	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 UNION = "UNION" + SPACE;
 	protected static final String LIMIT = "LIMIT" + SPACE;

http://git-wip-us.apache.org/repos/asf/jena/blob/bac24511/jena-extras/jena-querybuilder/src/test/java/org/apache/jena/arq/querybuilder/AskBuilderTest.java
----------------------------------------------------------------------
diff --git a/jena-extras/jena-querybuilder/src/test/java/org/apache/jena/arq/querybuilder/AskBuilderTest.java b/jena-extras/jena-querybuilder/src/test/java/org/apache/jena/arq/querybuilder/AskBuilderTest.java
new file mode 100644
index 0000000..3f0258e
--- /dev/null
+++ b/jena-extras/jena-querybuilder/src/test/java/org/apache/jena/arq/querybuilder/AskBuilderTest.java
@@ -0,0 +1,141 @@
+/*
+ * 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 static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.jena.arq.AbstractRegexpBasedTest;
+import org.apache.jena.sparql.core.Var ;
+import org.apache.jena.vocabulary.RDF ;
+import org.junit.Before;
+import org.junit.Test;
+
+public class AskBuilderTest extends AbstractRegexpBasedTest {
+
+	private AskBuilder builder;
+	
+    @Before
+	public void setup() {
+		builder = new AskBuilder();
+	}
+
+	@Test
+	public void testAll() {
+		builder.addPrefix("foaf", "http://xmlns.com/foaf/0.1/")
+				.addWhere("?s", RDF.type, "foaf:Person")
+				.addOptional("?s", "foaf:name", "?name").addOrderBy("?s");
+
+		String query = builder.buildString();
+		/*
+		 * PREFIX foaf: <http://xmlns.com/foaf/0.1/>
+		 * 
+		 * ASK WHERE { ?s
+		 * <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> foaf:Person .
+		 * OPTIONAL { ?s foaf:name ?name .} } ORDER BY ?s
+		 */
+		assertContainsRegex(PREFIX + "foaf:" + SPACE
+				+ uri("http://xmlns.com/foaf/0.1/"), query);
+		assertContainsRegex(ASK, query);
+		assertContainsRegex(WHERE + OPEN_CURLY + var("s") + SPACE
+				+ regexRDFtype
+				+ SPACE + "foaf:Person" + SPACE + OPTIONAL
+				+ OPEN_CURLY + var("s") + SPACE + "foaf:name" + SPACE
+				+ var("name") + OPT_SPACE + CLOSE_CURLY
+				+ CLOSE_CURLY, query);
+		assertContainsRegex(ORDER_BY + var("s"), query);
+
+		builder.setVar("name", "Smith");
+
+		query = builder.buildString();
+		assertContainsRegex(PREFIX + "foaf:" + SPACE
+				+ uri("http://xmlns.com/foaf/0.1/"), query);
+		assertContainsRegex(ASK + WHERE + OPEN_CURLY + var("s") + SPACE
+                + regexRDFtype
+				+ SPACE + "foaf:Person" + SPACE + OPTIONAL
+				+ OPEN_CURLY + var("s") + SPACE + "foaf:name" + SPACE
+				+ quote("Smith") + presentStringType()
+				+ OPT_SPACE + CLOSE_CURLY + CLOSE_CURLY, query);
+		assertContainsRegex(ORDER_BY + var("s"), query);
+	}
+
+	@Test
+	public void testPredicateVar() {
+		builder.addPrefix("", "http://example/")
+				.addWhere(":S", "?p", ":O");
+		String query = builder.buildString();
+
+		assertContainsRegex(WHERE + OPEN_CURLY + ":S" + SPACE + var("p")
+				+ SPACE + ":O" + OPT_SPACE + CLOSE_CURLY, query);
+	}
+
+	@Test
+	public void testSubjectVar() {
+		builder.addPrefix("", "http://example/")
+				.addWhere("?s", ":P", ":O");
+		String query = builder.buildString();
+
+		assertContainsRegex(WHERE + OPEN_CURLY + var("s") + SPACE + ":P"
+				+ SPACE + ":O" + OPT_SPACE + CLOSE_CURLY, query);
+	}
+
+	@Test
+	public void testObjectVar() {
+		builder.addPrefix("", "http://example/")
+				.addWhere(":S", ":P", "?o");
+		String query = builder.buildString();
+
+		assertContainsRegex(WHERE + OPEN_CURLY + ":S" + SPACE + ":P" + SPACE
+				+ var("o") + OPT_SPACE +  CLOSE_CURLY, query);
+	}
+
+	
+	@Test
+	public void testList() {
+		builder
+		 .addWhere( builder.list( "<one>", "?two", "'three'"), "<foo>", "<bar>");
+		String query = builder.buildString();
+		
+		assertContainsRegex(
+				"_:b0"+SPACE+ uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#first") + SPACE	+ uri("one") + SEMI 
+				+ SPACE + uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#rest") + SPACE+"_:b1"+ DOT
+				+ SPACE + "_:b1"+SPACE+ uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#first") + SPACE + var("two") + SEMI
+				+ SPACE + uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#rest") + SPACE+"_:b2"+ DOT
+				+ SPACE + "_:b2"+SPACE+ uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#first") + SPACE + quote("three") + SEMI
+				+ SPACE + uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#rest") + SPACE +uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#nil") 
+				, query);
+		
+		assertContainsRegex(
+				 "_:b0"+SPACE+ uri("foo") + SPACE	+ uri("bar"), query);
+	}
+	
+	@Test
+	public void testClone() {
+		builder
+		 .addWhere( "?two", "<foo>", "<bar>");
+		AskBuilder builder2 = builder.clone();
+		builder2.addOrderBy( "?two");
+		
+		String q1 = builder.buildString();
+		String q2 = builder2.buildString();
+		
+		assertTrue( q2.contains("ORDER BY"));
+		assertFalse( q1.contains("ORDER BY"));
+	}
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/bac24511/jena-extras/jena-querybuilder/src/test/java/org/apache/jena/arq/querybuilder/ConstructBuilderTest.java
----------------------------------------------------------------------
diff --git a/jena-extras/jena-querybuilder/src/test/java/org/apache/jena/arq/querybuilder/ConstructBuilderTest.java b/jena-extras/jena-querybuilder/src/test/java/org/apache/jena/arq/querybuilder/ConstructBuilderTest.java
new file mode 100644
index 0000000..3e35ccc
--- /dev/null
+++ b/jena-extras/jena-querybuilder/src/test/java/org/apache/jena/arq/querybuilder/ConstructBuilderTest.java
@@ -0,0 +1,162 @@
+/*
+ * 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 static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.jena.arq.AbstractRegexpBasedTest;
+import org.apache.jena.graph.Triple;
+import org.apache.jena.sparql.core.Var ;
+import org.apache.jena.vocabulary.RDF ;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ConstructBuilderTest extends AbstractRegexpBasedTest {
+
+	private ConstructBuilder builder;
+	
+    @Before
+	public void setup() {
+		builder = new ConstructBuilder();
+	}
+
+//	@Test
+//	public void testSelectAsterisk() {
+//		builder.addWhere("?s", "?p", "?o");
+//
+//		assertContainsRegex(SELECT + "\\*" + SPACE + WHERE + OPEN_CURLY
+//				+ var("s") + SPACE + var("p") + SPACE + var("o") + OPT_SPACE
+//				+ CLOSE_CURLY, builder.buildString());
+//
+//		builder.setVar(Var.alloc("p"), RDF.type);
+//
+//		assertContainsRegex(SELECT + "\\*" + SPACE + WHERE + OPEN_CURLY
+//				+ var("s") + SPACE
+//				+ regexRDFtype
+//				+ SPACE + var("o") + OPT_SPACE + CLOSE_CURLY,
+//				builder.buildString());
+//	}
+
+	@Test
+	public void testAll() {
+		builder.addPrefix("foaf", "http://xmlns.com/foaf/0.1/")
+		.addConstruct( Triple.ANY )
+				.addWhere("?s", RDF.type, "foaf:Person")
+				.addOptional("?s", "foaf:name", "?name").addOrderBy("?s");
+
+		String query = builder.buildString();
+		
+		assertContainsRegex(PREFIX + "foaf:" + SPACE
+				+ uri("http://xmlns.com/foaf/0.1/"), query);
+		assertContainsRegex(CONSTRUCT + OPEN_CURLY+ "ANY"+SPACE+"ANY"+SPACE+"ANY"+DOT+CLOSE_CURLY, query);
+		assertContainsRegex(WHERE + OPEN_CURLY + var("s") + SPACE
+				+ regexRDFtype
+				+ SPACE + "foaf:Person" + SPACE + OPTIONAL
+				+ OPEN_CURLY + var("s") + SPACE + "foaf:name" + SPACE
+				+ var("name") + OPT_SPACE + CLOSE_CURLY
+				+ CLOSE_CURLY, query);
+		assertContainsRegex(ORDER_BY + var("s"), query);
+
+		builder.setVar("name", "Smith");
+
+		query = builder.buildString();
+		assertContainsRegex(PREFIX + "foaf:" + SPACE
+				+ uri("http://xmlns.com/foaf/0.1/"), query);
+		assertContainsRegex(CONSTRUCT + OPEN_CURLY+ "ANY"+SPACE+"ANY"+SPACE+"ANY"+DOT+CLOSE_CURLY, query);
+		assertContainsRegex(WHERE + OPEN_CURLY + var("s") + SPACE
+                + regexRDFtype
+				+ SPACE + "foaf:Person" + SPACE + OPTIONAL
+				+ OPEN_CURLY + var("s") + SPACE + "foaf:name" + SPACE
+				+ quote("Smith") + presentStringType()
+				+ OPT_SPACE + CLOSE_CURLY + CLOSE_CURLY, query);
+		assertContainsRegex(ORDER_BY + var("s"), query);
+	}
+
+	@Test
+	public void testPredicateVar() {
+		builder.addPrefix("", "http://example/")
+				.addWhere(":S", "?p", ":O");
+		String query = builder.buildString();
+
+		assertContainsRegex(WHERE + OPEN_CURLY + ":S" + SPACE + var("p")
+				+ SPACE + ":O" + OPT_SPACE + CLOSE_CURLY, query);
+	}
+
+	@Test
+	public void testSubjectVar() {
+		builder.addPrefix("", "http://example/")
+				.addWhere("?s", ":P", ":O");
+		String query = builder.buildString();
+
+		assertContainsRegex(WHERE + OPEN_CURLY + var("s") + SPACE + ":P"
+				+ SPACE + ":O" + OPT_SPACE + CLOSE_CURLY, query);
+	}
+
+	@Test
+	public void testObjectVar() {
+		builder.addPrefix("", "http://example/")
+				.addWhere(":S", ":P", "?o");
+		String query = builder.buildString();
+
+		assertContainsRegex(WHERE + OPEN_CURLY + ":S" + SPACE + ":P" + SPACE
+				+ var("o") + OPT_SPACE +  CLOSE_CURLY, query);
+	}
+
+	@Test
+	public void testNoVars() {
+		builder.addConstruct("?s", "?p", "?o");
+		String query = builder.buildString();
+		assertContainsRegex(CONSTRUCT + OPEN_CURLY+ var("s")+SPACE+var("p")+SPACE+var("o")
+				+DOT+CLOSE_CURLY, query);
+	}
+	
+	@Test
+	public void testList() {
+		builder
+		 .addWhere( builder.list( "<one>", "?two", "'three'"), "<foo>", "<bar>");
+		String query = builder.buildString();
+		
+		assertContainsRegex(
+				"_:b0"+SPACE+ uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#first") + SPACE	+ uri("one") + SEMI 
+				+ SPACE + uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#rest") + SPACE+"_:b1"+ DOT
+				+ SPACE + "_:b1"+SPACE+ uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#first") + SPACE + var("two") + SEMI
+				+ SPACE + uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#rest") + SPACE+"_:b2"+ DOT
+				+ SPACE + "_:b2"+SPACE+ uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#first") + SPACE + quote("three") + SEMI
+				+ SPACE + uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#rest") + SPACE +uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#nil") 
+				, query);
+		
+		assertContainsRegex(
+				 "_:b0"+SPACE+ uri("foo") + SPACE	+ uri("bar"), query);
+	}
+	
+	@Test
+	public void testClone() {
+		builder
+		 .addWhere( "?two", "<foo>", "<bar>");
+		ConstructBuilder builder2 = builder.clone();
+		builder2.addOrderBy( "?two");
+		
+		String q1 = builder.buildString();
+		String q2 = builder2.buildString();
+		
+		assertTrue( q2.contains("ORDER BY"));
+		assertFalse( q1.contains("ORDER BY"));
+	}
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/bac24511/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 8cb36c0..535be17 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
@@ -18,6 +18,9 @@
 
 package org.apache.jena.arq.querybuilder;
 
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
 import org.apache.jena.arq.AbstractRegexpBasedTest;
 import org.apache.jena.sparql.core.Var ;
 import org.apache.jena.vocabulary.RDF ;
@@ -146,4 +149,18 @@ public class SelectBuilderTest extends AbstractRegexpBasedTest {
 		assertContainsRegex(
 				 "_:b0"+SPACE+ uri("foo") + SPACE	+ uri("bar"), query);
 	}
+	
+	@Test
+	public void testClone() {
+		builder.addVar( "*" )
+		 .addWhere( "?two", "<foo>", "<bar>");
+		SelectBuilder builder2 = builder.clone();
+		builder2.addOrderBy( "?two");
+		
+		String q1 = builder.buildString();
+		String q2 = builder2.buildString();
+		
+		assertTrue( q2.contains("ORDER BY"));
+		assertFalse( q1.contains("ORDER BY"));
+	}
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/bac24511/jena-extras/jena-querybuilder/src/test/java/org/apache/jena/arq/querybuilder/clauses/WhereClauseTest.java
----------------------------------------------------------------------
diff --git a/jena-extras/jena-querybuilder/src/test/java/org/apache/jena/arq/querybuilder/clauses/WhereClauseTest.java b/jena-extras/jena-querybuilder/src/test/java/org/apache/jena/arq/querybuilder/clauses/WhereClauseTest.java
index e366e1f..570a91e 100644
--- a/jena-extras/jena-querybuilder/src/test/java/org/apache/jena/arq/querybuilder/clauses/WhereClauseTest.java
+++ b/jena-extras/jena-querybuilder/src/test/java/org/apache/jena/arq/querybuilder/clauses/WhereClauseTest.java
@@ -168,11 +168,13 @@ public class WhereClauseTest<T extends WhereClause<?>> extends
 		whereClause.getWhereHandler().addWhere(Triple.ANY);
 		AbstractQueryBuilder<?> builder = whereClause.addUnion(sb);
 
-		assertContainsRegex(PREFIX + "pfx:" + SPACE + uri("uri") + ".+"
-				+ UNION + OPEN_CURLY + SELECT + var("x") + SPACE + WHERE
+		String str = builder.buildString();
+		assertContainsRegex(PREFIX + "pfx:" + SPACE + uri("uri") + SPACE, str );
+		assertContainsRegex( WHERE + OPEN_CURLY + OPEN_CURLY+"ANY"+SPACE+"ANY"+SPACE+"ANY"+CLOSE_CURLY
+				+ SPACE+UNION + OPEN_CURLY + SELECT + var("x") + SPACE + WHERE
 				+ OPEN_CURLY + uri("one") + SPACE + uri("two") + SPACE
 				+ quote("three") + presentStringType() + OPT_SPACE
-				+ CLOSE_CURLY + CLOSE_CURLY, builder.buildString());
+				+ CLOSE_CURLY + CLOSE_CURLY, str);
 
 	}
 
@@ -251,13 +253,13 @@ public class WhereClauseTest<T extends WhereClause<?>> extends
 		WhereClause<?> whereClause = getProducer().newInstance();
 		AbstractQueryBuilder<?> builder = whereClause.addSubQuery(sb);
 
-		assertContainsRegex(WHERE + OPEN_CURLY + uri("one") + ".+"
-				+ uri("two") + ".+" + var("v") + ".+" + CLOSE_CURLY,
+		assertContainsRegex(WHERE + OPEN_CURLY + uri("one") + SPACE
+				+ uri("two") + SPACE + var("v") + CLOSE_CURLY,
 				builder.buildString());
 
 		builder.setVar(v, NodeFactory.createURI("three"));
-		assertContainsRegex(WHERE + OPEN_CURLY + uri("one") + ".+"
-				+ uri("two") + ".+" + uri("three") + ".+" + CLOSE_CURLY,
+		assertContainsRegex(WHERE + OPEN_CURLY + uri("one") + SPACE
+				+ uri("two") + SPACE + uri("three") + CLOSE_CURLY,
 				builder.buildString());
 	}
 
@@ -269,13 +271,13 @@ public class WhereClauseTest<T extends WhereClause<?>> extends
 		WhereClause<?> whereClause = getProducer().newInstance();
 		AbstractQueryBuilder<?> builder = whereClause.addUnion(sb);
 		assertContainsRegex(WHERE + OPEN_CURLY + UNION + OPEN_CURLY
-				+ uri("one") + ".+" + uri("two") + ".+" + var("v") + ".+"
+				+ uri("one") + SPACE + uri("two") + SPACE + var("v") 
 				+ CLOSE_CURLY, builder.buildString());
 
 		builder.setVar(v, NodeFactory.createURI("three"));
 		assertContainsRegex(WHERE + OPEN_CURLY + UNION + OPEN_CURLY
-				+ uri("one") + ".+" + uri("two") + ".+" + uri("three")
-				+ ".+" + CLOSE_CURLY, builder.buildString());
+				+ uri("one") + SPACE + uri("two") + SPACE + uri("three")
+				+ SPACE + CLOSE_CURLY, builder.buildString());
 	}
 
 	@ContractTest

http://git-wip-us.apache.org/repos/asf/jena/blob/bac24511/jena-extras/jena-querybuilder/src/test/java/org/apache/jena/arq/querybuilder/handlers/WhereHandlerTest.java
----------------------------------------------------------------------
diff --git a/jena-extras/jena-querybuilder/src/test/java/org/apache/jena/arq/querybuilder/handlers/WhereHandlerTest.java b/jena-extras/jena-querybuilder/src/test/java/org/apache/jena/arq/querybuilder/handlers/WhereHandlerTest.java
index 053918f..b3f134f 100644
--- a/jena-extras/jena-querybuilder/src/test/java/org/apache/jena/arq/querybuilder/handlers/WhereHandlerTest.java
+++ b/jena-extras/jena-querybuilder/src/test/java/org/apache/jena/arq/querybuilder/handlers/WhereHandlerTest.java
@@ -34,6 +34,8 @@ import org.apache.jena.rdf.model.ResourceFactory;
 import org.apache.jena.sparql.core.Var;
 import org.apache.jena.sparql.expr.E_Random;
 import org.apache.jena.sparql.lang.sparql_11.ParseException;
+import org.apache.jena.sparql.sse.Item;
+import org.apache.jena.sparql.sse.SSE;
 import org.apache.jena.vocabulary.RDF;
 import org.junit.Assert;
 import org.junit.Before;
@@ -51,116 +53,118 @@ public class WhereHandlerTest extends AbstractHandlerTest {
 	}
 
 	@Test
-	public void testAddAll() {
+	public void testAddAllOnEmpty() {
 		Query query2 = new Query();
 		WhereHandler handler2 = new WhereHandler(query2);
-		handler2.addWhere(new Triple(NodeFactory.createURI("one"), NodeFactory
-				.createURI("two"), NodeFactory.createLiteral("three")));
+		handler2.addWhere(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"),
+				NodeFactory.createLiteral("three")));
 		handler.addAll(handler2);
 
-		assertContainsRegex(WHERE + OPEN_CURLY + uri("one") + SPACE
-				+ uri("two") + SPACE + quote("three") + OPT_SPACE
-				+ CLOSE_CURLY, query.toString());
+		assertContainsRegex(
+				WHERE + OPEN_CURLY + uri("one") + SPACE + uri("two") + SPACE + quote("three") + OPT_SPACE + CLOSE_CURLY,
+				query.toString());
+	}
+
+	@Test
+	public void testAddAllPopulatedEmpty() {
+		handler.addWhere(Triple.ANY);
+		Query query2 = new Query();
+		WhereHandler handler2 = new WhereHandler(query2);
+		handler2.addWhere(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"),
+				NodeFactory.createLiteral("three")));
+		handler.addAll(handler2);
+
+		assertContainsRegex(WHERE + OPEN_CURLY + "ANY" + SPACE + "ANY" + SPACE + "ANY" + DOT + SPACE + uri("one")
+				+ SPACE + uri("two") + SPACE + quote("three") + OPT_SPACE + CLOSE_CURLY, query.toString());
 	}
 
 	@Test
 	public void addWhereTriple() {
-		handler.addWhere(new Triple(NodeFactory.createURI("one"), NodeFactory
-				.createURI("two"), NodeFactory.createURI("three")));
-		assertContainsRegex(WHERE + OPEN_CURLY + uri("one") + SPACE
-				+ uri("two") + SPACE + uri("three") + OPT_SPACE
-				+ CLOSE_CURLY, query.toString());
+		handler.addWhere(
+				new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three")));
+		assertContainsRegex(
+				WHERE + OPEN_CURLY + uri("one") + SPACE + uri("two") + SPACE + uri("three") + OPT_SPACE + CLOSE_CURLY,
+				query.toString());
 	}
 
 	@Test
 	public void testAddWhereObjects() {
-		handler.addWhere(new Triple(NodeFactory.createURI("one"),
-				ResourceFactory.createResource("two").asNode(), ResourceFactory
-						.createLangLiteral("three", "en-US").asNode()));
-		assertContainsRegex(WHERE + OPEN_CURLY + uri("one") + SPACE
-				+ uri("two") + SPACE + quote("three") + "@en-US" + OPT_SPACE
-				+ CLOSE_CURLY, query.toString());
+		handler.addWhere(new Triple(NodeFactory.createURI("one"), ResourceFactory.createResource("two").asNode(),
+				ResourceFactory.createLangLiteral("three", "en-US").asNode()));
+		assertContainsRegex(WHERE + OPEN_CURLY + uri("one") + SPACE + uri("two") + SPACE + quote("three") + "@en-US"
+				+ OPT_SPACE + CLOSE_CURLY, query.toString());
 	}
 
 	@Test
 	public void testAddWhereAnonymous() {
 		handler.addWhere(new Triple(Node.ANY, RDF.first.asNode(), Node.ANY));
 		assertContainsRegex(WHERE + OPEN_CURLY + "ANY" + SPACE
-				+ uri("http://www\\.w3\\.org/1999/02/22-rdf-syntax-ns#first")
-				+ SPACE + "ANY" + OPT_SPACE + CLOSE_CURLY,
+				+ uri("http://www\\.w3\\.org/1999/02/22-rdf-syntax-ns#first") + SPACE + "ANY" + OPT_SPACE + CLOSE_CURLY,
 				query.toString());
 	}
 
 	@Test
 	public void testAddOptionalStrings() {
-		handler.addOptional(new Triple(NodeFactory.createURI("one"),
-				NodeFactory.createURI("two"), NodeFactory.createURI("three")));
-		assertContainsRegex(WHERE + OPEN_CURLY + "OPTIONAL" + SPACE
-				+ OPEN_CURLY + uri("one") + SPACE + uri("two") + SPACE
-				+ uri("three") + OPT_SPACE + CLOSE_CURLY + CLOSE_CURLY,
-				query.toString());
+		handler.addOptional(
+				new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three")));
+		assertContainsRegex(WHERE + OPEN_CURLY + "OPTIONAL" + SPACE + OPEN_CURLY + uri("one") + SPACE + uri("two")
+				+ SPACE + uri("three") + OPT_SPACE + CLOSE_CURLY + CLOSE_CURLY, query.toString());
 	}
 
 	@Test
 	public void testAddOptionalAnonymous() {
 		handler.addOptional(new Triple(Node.ANY, RDF.first.asNode(), Node.ANY));
-		assertContainsRegex(WHERE + OPEN_CURLY + "OPTIONAL" + SPACE
-				+ OPEN_CURLY + "ANY" + SPACE
-				+ uri("http://www\\.w3\\.org/1999/02/22-rdf-syntax-ns#first")
-				+ SPACE + "ANY" + OPT_SPACE + CLOSE_CURLY + CLOSE_CURLY,
-				query.toString());
+		assertContainsRegex(WHERE + OPEN_CURLY + "OPTIONAL" + SPACE + OPEN_CURLY + "ANY" + SPACE
+				+ uri("http://www\\.w3\\.org/1999/02/22-rdf-syntax-ns#first") + SPACE + "ANY" + OPT_SPACE + CLOSE_CURLY
+				+ CLOSE_CURLY, query.toString());
 	}
 
-	
 	@Test
 	public void testAddOptionalWhereHandler() throws ParseException {
-		
+
 		WhereHandler pattern = new WhereHandler(new Query());
-		Var s = Var.alloc("s" );
-		Node q = NodeFactory.createURI( "urn:q" );
-		Node v = NodeFactory.createURI( "urn:v" );
+		Var s = Var.alloc("s");
+		Node q = NodeFactory.createURI("urn:q");
+		Node v = NodeFactory.createURI("urn:v");
 		Var x = Var.alloc("x");
-		Node n123 = NodeFactory.createLiteral(LiteralLabelFactory.createTypedLiteral(123));	
-		
-		pattern.addWhere( new Triple( s, q,  n123 ) );
-		pattern.addWhere( new Triple( s, v, x));
-		pattern.addFilter( "?x>56");
-		
-		handler.addOptional( pattern );
-		
-		Query expected = QueryFactory.create( "SELECT * WHERE { OPTIONAL { ?s <urn:q> '123'^^<http://www.w3.org/2001/XMLSchema#int> . ?s <urn:v> ?x . FILTER(?x>56) }}");
-		
-		Assert.assertEquals( expected.getQueryPattern(), query.getQueryPattern());
+		Node n123 = NodeFactory.createLiteral(LiteralLabelFactory.createTypedLiteral(123));
+
+		pattern.addWhere(new Triple(s, q, n123));
+		pattern.addWhere(new Triple(s, v, x));
+		pattern.addFilter("?x>56");
+
+		handler.addOptional(pattern);
+
+		Query expected = QueryFactory.create(
+				"SELECT * WHERE { OPTIONAL { ?s <urn:q> '123'^^<http://www.w3.org/2001/XMLSchema#int> . ?s <urn:v> ?x . FILTER(?x>56) }}");
+
+		Assert.assertEquals(expected.getQueryPattern(), query.getQueryPattern());
 
 	}
-	
+
 	@Test
 	public void testAddOptionalObjects() {
-		handler.addOptional(new Triple(NodeFactory.createURI("one"),
-				ResourceFactory.createResource("two").asNode(), ResourceFactory
-						.createLangLiteral("three", "en-US").asNode()));
-		assertContainsRegex(WHERE + OPEN_CURLY + "OPTIONAL" + SPACE
-				+ OPEN_CURLY + uri("one") + SPACE + uri("two") + SPACE
-				+ quote("three") + "@en-US" + OPT_SPACE + CLOSE_CURLY
-				+ CLOSE_CURLY, query.toString());
+		handler.addOptional(new Triple(NodeFactory.createURI("one"), ResourceFactory.createResource("two").asNode(),
+				ResourceFactory.createLangLiteral("three", "en-US").asNode()));
+		assertContainsRegex(WHERE + OPEN_CURLY + "OPTIONAL" + SPACE + OPEN_CURLY + uri("one") + SPACE + uri("two")
+				+ SPACE + quote("three") + "@en-US" + OPT_SPACE + CLOSE_CURLY + CLOSE_CURLY, query.toString());
 	}
 
 	@Test
 	public void testAddWhereStrings() {
-		handler.addWhere(new Triple(NodeFactory.createURI("one"), NodeFactory
-				.createURI("two"), NodeFactory.createURI("three")));
-		assertContainsRegex(WHERE + OPEN_CURLY + uri("one") + SPACE
-				+ uri("two") + SPACE + uri("three") + OPT_SPACE
-				+ CLOSE_CURLY, query.toString());
+		handler.addWhere(
+				new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three")));
+		assertContainsRegex(
+				WHERE + OPEN_CURLY + uri("one") + SPACE + uri("two") + SPACE + uri("three") + OPT_SPACE + CLOSE_CURLY,
+				query.toString());
 	}
 
 	@Test
 	public void testAddFilter() throws ParseException {
 		handler.addFilter("?one < 10");
 
-		assertContainsRegex(WHERE + OPEN_CURLY + "FILTER" + OPT_SPACE
-				+ OPEN_PAREN + var("one") + OPT_SPACE + LT + OPT_SPACE + "10"
-				+ CLOSE_PAREN + CLOSE_CURLY, query.toString());
+		assertContainsRegex(WHERE + OPEN_CURLY + "FILTER" + OPT_SPACE + OPEN_PAREN + var("one") + OPT_SPACE + LT
+				+ OPT_SPACE + "10" + CLOSE_PAREN + CLOSE_CURLY, query.toString());
 	}
 
 	@Test
@@ -168,30 +172,28 @@ public class WhereHandlerTest extends AbstractHandlerTest {
 		query.setPrefix("afn", "http://jena.apache.org/ARQ/function#");
 		handler.addFilter("afn:namespace(?one) = 'foo'");
 
-		assertContainsRegex(WHERE + OPEN_CURLY + "FILTER" + OPT_SPACE
-				+ OPEN_PAREN + "afn:namespace" + OPEN_PAREN + var("one")
-				+ CLOSE_PAREN + OPT_SPACE + EQ + OPT_SPACE + QUOTE + "foo"
-				+ QUOTE + CLOSE_PAREN + CLOSE_CURLY, query.toString());
+		assertContainsRegex(
+				WHERE + OPEN_CURLY + "FILTER" + OPT_SPACE + OPEN_PAREN + "afn:namespace" + OPEN_PAREN + var("one")
+						+ CLOSE_PAREN + OPT_SPACE + EQ + OPT_SPACE + QUOTE + "foo" + QUOTE + CLOSE_PAREN + CLOSE_CURLY,
+				query.toString());
 	}
 
 	@Test
 	public void testAddFilterVarOnly() throws ParseException {
 		handler.addFilter("?one");
 
-		assertContainsRegex(WHERE + OPEN_CURLY + "FILTER" + OPT_SPACE
-				+ OPEN_PAREN + var("one") + CLOSE_PAREN + CLOSE_CURLY,
+		assertContainsRegex(
+				WHERE + OPEN_CURLY + "FILTER" + OPT_SPACE + OPEN_PAREN + var("one") + CLOSE_PAREN + CLOSE_CURLY,
 				query.toString());
 	}
 
 	@Test
 	public void testAddSubQueryWithVars() {
 		SelectBuilder sb = new SelectBuilder();
-		sb.addPrefix("pfx", "uri").addVar("?x")
-				.addWhere("<one>", "<two>", "three");
+		sb.addPrefix("pfx", "uri").addVar("?x").addWhere("<one>", "<two>", "three");
 		handler.addSubQuery(sb);
-		assertContainsRegex("SELECT" + SPACE + var("x") + SPACE + WHERE
-				+ OPEN_CURLY + uri("one") + ".+" + uri("two") + ".+"
-				+ quote("three") + ".+" + CLOSE_CURLY, query.toString());
+		assertContainsRegex("SELECT" + SPACE + var("x") + SPACE + WHERE + OPEN_CURLY + uri("one") + ".+" + uri("two")
+				+ ".+" + quote("three") + ".+" + CLOSE_CURLY, query.toString());
 	}
 
 	@Test
@@ -199,115 +201,98 @@ public class WhereHandlerTest extends AbstractHandlerTest {
 		SelectBuilder sb = new SelectBuilder();
 		sb.addPrefix("pfx", "uri").addWhere("<one>", "<two>", "three");
 		handler.addSubQuery(sb);
-		assertContainsRegex(WHERE + OPEN_CURLY + uri("one") + ".+"
-				+ uri("two") + ".+" + quote("three") + ".+" + CLOSE_CURLY,
+		assertContainsRegex(
+				WHERE + OPEN_CURLY + uri("one") + ".+" + uri("two") + ".+" + quote("three") + ".+" + CLOSE_CURLY,
 				query.toString());
 	}
 
 	@Test
 	public void testAddUnion() {
 		SelectBuilder sb = new SelectBuilder();
-		sb.addWhere(new Triple(NodeFactory.createURI("one"), NodeFactory
-				.createURI("two"), NodeFactory.createURI("three")));
+		sb.addWhere(
+				new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three")));
 
 		handler.addUnion(sb);
-		assertContainsRegex(WHERE + OPEN_CURLY + UNION + OPEN_CURLY
-				+ uri("one") + SPACE + uri("two") + SPACE + uri("three")
-				+ OPT_SPACE + CLOSE_CURLY, query.toString());
+		assertContainsRegex(WHERE + OPEN_CURLY + UNION + OPEN_CURLY + uri("one") + SPACE + uri("two") + SPACE
+				+ uri("three") + OPT_SPACE + CLOSE_CURLY, query.toString());
 	}
-	
+
 	@Test
 	public void testAddUnionToExisting() {
-		handler.addWhere( new Triple( NodeFactory.createURI( "s"), NodeFactory.createURI("p"),
-				NodeFactory.createURI("o")));
+		handler.addWhere(
+				new Triple(NodeFactory.createURI("s"), NodeFactory.createURI("p"), NodeFactory.createURI("o")));
 		SelectBuilder sb = new SelectBuilder();
-		sb.addWhere(new Triple(NodeFactory.createURI("one"), NodeFactory
-				.createURI("two"), NodeFactory.createURI("three")));
+		sb.addWhere(
+				new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three")));
 
 		handler.addUnion(sb);
-		assertContainsRegex(WHERE + OPEN_CURLY + OPEN_CURLY 
-				+ uri("s") + SPACE+ uri("p") + SPACE + uri("o")+CLOSE_CURLY
-				+OPT_SPACE + UNION + OPEN_CURLY
-				+ uri("one") + SPACE + uri("two") + SPACE + uri("three")
-				+ OPT_SPACE + CLOSE_CURLY+ CLOSE_CURLY, query.toString());
+		assertContainsRegex(WHERE + OPEN_CURLY + OPEN_CURLY + uri("s") + SPACE + uri("p") + SPACE + uri("o")
+				+ CLOSE_CURLY + OPT_SPACE + UNION + OPEN_CURLY + uri("one") + SPACE + uri("two") + SPACE + uri("three")
+				+ OPT_SPACE + CLOSE_CURLY + CLOSE_CURLY, query.toString());
 	}
 
 	@Test
 	public void testAddUnionWithVar() {
 		SelectBuilder sb = new SelectBuilder().addVar("x").addWhere(
-				new Triple(NodeFactory.createURI("one"), NodeFactory
-						.createURI("two"), NodeFactory.createURI("three")));
+				new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three")));
 
 		handler.addUnion(sb);
-		assertContainsRegex(WHERE + OPEN_CURLY + UNION + OPEN_CURLY + SELECT
-				+ var("x") + SPACE + WHERE + OPEN_CURLY + uri("one") + SPACE
-				+ uri("two") + SPACE + uri("three") + OPT_SPACE
-				+ CLOSE_CURLY, query.toString());
+		assertContainsRegex(WHERE + OPEN_CURLY + UNION + OPEN_CURLY + SELECT + var("x") + SPACE + WHERE + OPEN_CURLY
+				+ uri("one") + SPACE + uri("two") + SPACE + uri("three") + OPT_SPACE + CLOSE_CURLY, query.toString());
 	}
 
 	@Test
 	public void testAddUnionToExistingWithVar() {
-		handler.addWhere( new Triple( NodeFactory.createURI( "s"), NodeFactory.createURI("p"),
-				NodeFactory.createURI("o")));
+		handler.addWhere(
+				new Triple(NodeFactory.createURI("s"), NodeFactory.createURI("p"), NodeFactory.createURI("o")));
 		SelectBuilder sb = new SelectBuilder().addVar("x").addWhere(
-				new Triple(NodeFactory.createURI("one"), NodeFactory
-						.createURI("two"), NodeFactory.createURI("three")));
+				new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three")));
 
 		handler.addUnion(sb);
-		assertContainsRegex(WHERE + OPEN_CURLY + OPEN_CURLY 
-				+ uri("s") + SPACE+ uri("p") + SPACE + uri("o")+CLOSE_CURLY
-				+OPT_SPACE 				
-				+ UNION + OPEN_CURLY + SELECT
-				+ var("x") + SPACE + WHERE + OPEN_CURLY + uri("one") + SPACE
-				+ uri("two") + SPACE + uri("three") + OPT_SPACE
-				+ CLOSE_CURLY, query.toString());
+		assertContainsRegex(WHERE + OPEN_CURLY + OPEN_CURLY + uri("s") + SPACE + uri("p") + SPACE + uri("o")
+				+ CLOSE_CURLY + OPT_SPACE + UNION + OPEN_CURLY + SELECT + var("x") + SPACE + WHERE + OPEN_CURLY
+				+ uri("one") + SPACE + uri("two") + SPACE + uri("three") + OPT_SPACE + CLOSE_CURLY, query.toString());
 	}
+
 	@Test
 	public void addGraph() {
 
 		WhereHandler handler2 = new WhereHandler(new Query());
-		handler2.addWhere(new Triple(NodeFactory.createURI("one"), NodeFactory
-				.createURI("two"), NodeFactory.createURI("three")));
+		handler2.addWhere(
+				new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three")));
 
 		handler.addGraph(NodeFactory.createURI("graph"), handler2);
-		assertContainsRegex(WHERE + OPEN_CURLY + "GRAPH" + SPACE
-				+ uri("graph") + SPACE + OPEN_CURLY + uri("one") + SPACE
-				+ uri("two") + SPACE + uri("three") + OPT_SPACE
-				+ CLOSE_CURLY + CLOSE_CURLY, query.toString());
+		assertContainsRegex(WHERE + OPEN_CURLY + "GRAPH" + SPACE + uri("graph") + SPACE + OPEN_CURLY + uri("one")
+				+ SPACE + uri("two") + SPACE + uri("three") + OPT_SPACE + CLOSE_CURLY + CLOSE_CURLY, query.toString());
 
 	}
 
 	@Test
 	public void testSetVarsInTriple() {
 		Var v = Var.alloc("v");
-		handler.addWhere(new Triple(NodeFactory.createURI("one"), NodeFactory
-				.createURI("two"), v));
-		assertContainsRegex(WHERE + OPEN_CURLY + uri("one") + SPACE
-				+ uri("two") + SPACE + var("v") + OPT_SPACE
-				+ CLOSE_CURLY, query.toString());
+		handler.addWhere(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), v));
+		assertContainsRegex(
+				WHERE + OPEN_CURLY + uri("one") + SPACE + uri("two") + SPACE + var("v") + OPT_SPACE + CLOSE_CURLY,
+				query.toString());
 		Map<Var, Node> values = new HashMap<Var, Node>();
 		values.put(v, NodeFactory.createURI("three"));
 		handler.setVars(values);
-		assertContainsRegex(WHERE + OPEN_CURLY + uri("one") + SPACE
-				+ uri("two") + SPACE + uri("three") + OPT_SPACE
-				+ CLOSE_CURLY, query.toString());
+		assertContainsRegex(
+				WHERE + OPEN_CURLY + uri("one") + SPACE + uri("two") + SPACE + uri("three") + OPT_SPACE + CLOSE_CURLY,
+				query.toString());
 	}
 
 	@Test
 	public void testSetVarsInFilter() throws ParseException {
 		handler.addFilter("?one < ?v");
-		assertContainsRegex(WHERE + OPEN_CURLY + "FILTER" + OPT_SPACE
-				+ OPEN_PAREN + var("one") + OPT_SPACE + LT + OPT_SPACE
-				+ var("v") + CLOSE_PAREN + CLOSE_CURLY, query.toString());
+		assertContainsRegex(WHERE + OPEN_CURLY + "FILTER" + OPT_SPACE + OPEN_PAREN + var("one") + OPT_SPACE + LT
+				+ OPT_SPACE + var("v") + CLOSE_PAREN + CLOSE_CURLY, query.toString());
 		Map<Var, Node> values = new HashMap<Var, Node>();
 
-		values.put(Var.alloc("v"), NodeFactory
-				.createLiteral(LiteralLabelFactory.createTypedLiteral(10)));
+		values.put(Var.alloc("v"), NodeFactory.createLiteral(LiteralLabelFactory.createTypedLiteral(10)));
 		handler.setVars(values);
-		assertContainsRegex(WHERE + OPEN_CURLY + "FILTER" + OPT_SPACE
-				+ OPEN_PAREN + var("one") + OPT_SPACE + LT + OPT_SPACE
-				+ quote("10") + "\\^\\^"
-				+ uri("http://www.w3.org/2001/XMLSchema#int") + CLOSE_PAREN
+		assertContainsRegex(WHERE + OPEN_CURLY + "FILTER" + OPT_SPACE + OPEN_PAREN + var("one") + OPT_SPACE + LT
+				+ OPT_SPACE + quote("10") + "\\^\\^" + uri("http://www.w3.org/2001/XMLSchema#int") + CLOSE_PAREN
 				+ CLOSE_CURLY, query.toString());
 
 	}
@@ -315,19 +300,14 @@ public class WhereHandlerTest extends AbstractHandlerTest {
 	@Test
 	public void testSetVarsInOptional() {
 		Var v = Var.alloc("v");
-		handler.addOptional(new Triple(NodeFactory.createURI("one"),
-				NodeFactory.createURI("two"), v));
-		assertContainsRegex(WHERE + OPEN_CURLY + "OPTIONAL" + SPACE
-				+ OPEN_CURLY + uri("one") + SPACE + uri("two") + SPACE
-				+ var("v") + OPT_SPACE + CLOSE_CURLY + CLOSE_CURLY,
-				query.toString());
+		handler.addOptional(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), v));
+		assertContainsRegex(WHERE + OPEN_CURLY + "OPTIONAL" + SPACE + OPEN_CURLY + uri("one") + SPACE + uri("two")
+				+ SPACE + var("v") + OPT_SPACE + CLOSE_CURLY + CLOSE_CURLY, query.toString());
 		Map<Var, Node> values = new HashMap<Var, Node>();
 		values.put(v, NodeFactory.createURI("three"));
 		handler.setVars(values);
-		assertContainsRegex(WHERE + OPEN_CURLY + "OPTIONAL" + SPACE
-				+ OPEN_CURLY + uri("one") + SPACE + uri("two") + SPACE
-				+ uri("three") + OPT_SPACE + CLOSE_CURLY + CLOSE_CURLY,
-				query.toString());
+		assertContainsRegex(WHERE + OPEN_CURLY + "OPTIONAL" + SPACE + OPEN_CURLY + uri("one") + SPACE + uri("two")
+				+ SPACE + uri("three") + OPT_SPACE + CLOSE_CURLY + CLOSE_CURLY, query.toString());
 	}
 
 	@Test
@@ -336,14 +316,13 @@ public class WhereHandlerTest extends AbstractHandlerTest {
 		SelectBuilder sb = new SelectBuilder();
 		sb.addPrefix("pfx", "uri").addWhere("<one>", "<two>", v);
 		handler.addSubQuery(sb);
-		assertContainsRegex(WHERE + OPEN_CURLY + uri("one") + ".+"
-				+ uri("two") + ".+" + var("v") + ".+" + CLOSE_CURLY,
+		assertContainsRegex(WHERE + OPEN_CURLY + uri("one") + ".+" + uri("two") + ".+" + var("v") + ".+" + CLOSE_CURLY,
 				query.toString());
 		Map<Var, Node> values = new HashMap<Var, Node>();
 		values.put(v, NodeFactory.createURI("three"));
 		handler.setVars(values);
-		assertContainsRegex(WHERE + OPEN_CURLY + uri("one") + ".+"
-				+ uri("two") + ".+" + uri("three") + ".+" + CLOSE_CURLY,
+		assertContainsRegex(
+				WHERE + OPEN_CURLY + uri("one") + ".+" + uri("two") + ".+" + uri("three") + ".+" + CLOSE_CURLY,
 				query.toString());
 	}
 
@@ -353,15 +332,13 @@ public class WhereHandlerTest extends AbstractHandlerTest {
 		SelectBuilder sb = new SelectBuilder();
 		sb.addPrefix("pfx", "uri").addWhere("<one>", "<two>", v);
 		handler.addUnion(sb);
-		assertContainsRegex(WHERE + OPEN_CURLY + UNION + OPEN_CURLY
-				+ uri("one") + ".+" + uri("two") + ".+" + var("v") + ".+"
-				+ CLOSE_CURLY, query.toString());
+		assertContainsRegex(WHERE + OPEN_CURLY + UNION + OPEN_CURLY + uri("one") + ".+" + uri("two") + ".+" + var("v")
+				+ ".+" + CLOSE_CURLY, query.toString());
 		Map<Var, Node> values = new HashMap<Var, Node>();
 		values.put(v, NodeFactory.createURI("three"));
 		handler.setVars(values);
-		assertContainsRegex(WHERE + OPEN_CURLY + UNION + OPEN_CURLY
-				+ uri("one") + ".+" + uri("two") + ".+" + uri("three")
-				+ ".+" + CLOSE_CURLY, query.toString());
+		assertContainsRegex(WHERE + OPEN_CURLY + UNION + OPEN_CURLY + uri("one") + ".+" + uri("two") + ".+"
+				+ uri("three") + ".+" + CLOSE_CURLY, query.toString());
 	}
 
 	@Test
@@ -369,10 +346,8 @@ public class WhereHandlerTest extends AbstractHandlerTest {
 		Var v = Var.alloc("foo");
 		handler.addBind("rand()", v);
 
-		assertContainsRegex(
-				OPEN_CURLY + BIND + OPEN_PAREN + "rand\\(\\)" + SPACE + "AS"
-						+ SPACE + var("foo") + CLOSE_PAREN + CLOSE_CURLY,
-				query.toString());
+		assertContainsRegex(OPEN_CURLY + BIND + OPEN_PAREN + "rand\\(\\)" + SPACE + "AS" + SPACE + var("foo")
+				+ CLOSE_PAREN + CLOSE_CURLY, query.toString());
 	}
 
 	@Test
@@ -380,45 +355,40 @@ public class WhereHandlerTest extends AbstractHandlerTest {
 		Var v = Var.alloc("foo");
 		handler.addBind(new E_Random(), v);
 
-		assertContainsRegex(
-				OPEN_CURLY + BIND + OPEN_PAREN + "rand\\(\\)" + SPACE + "AS"
-						+ SPACE + var("foo") + CLOSE_PAREN + CLOSE_CURLY,
-				query.toString());
+		assertContainsRegex(OPEN_CURLY + BIND + OPEN_PAREN + "rand\\(\\)" + SPACE + "AS" + SPACE + var("foo")
+				+ CLOSE_PAREN + CLOSE_CURLY, query.toString());
 	}
-	
+
 	@Test
 	public void testList() {
-		Node n = handler.list( "<one>", "?var", "'three'" );
-
-		assertContainsRegex(WHERE + OPEN_CURLY 
-				+ "_:b0"+SPACE+ uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#first") + SPACE	+ uri("one") + SEMI 
-				+ SPACE + uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#rest") + SPACE+"_:b1"+ DOT
-				+ SPACE + "_:b1"+SPACE+ uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#first") + SPACE + var("var") + SEMI
-				+ SPACE + uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#rest") + SPACE+"_:b2"+ DOT
-				+ SPACE + "_:b2"+SPACE+ uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#first") + SPACE + quote("three") + SEMI
-				+ SPACE + uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#rest") + SPACE +uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#nil") 
-				+ CLOSE_CURLY, query.toString());
-		
-	 	assertTrue( n.isBlank() );
+		Node n = handler.list("<one>", "?var", "'three'");
+
+		assertContainsRegex(WHERE + OPEN_CURLY + "_:b0" + SPACE
+				+ uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#first") + SPACE + uri("one") + SEMI + SPACE
+				+ uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#rest") + SPACE + "_:b1" + DOT + SPACE + "_:b1" + SPACE
+				+ uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#first") + SPACE + var("var") + SEMI + SPACE
+				+ uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#rest") + SPACE + "_:b2" + DOT + SPACE + "_:b2" + SPACE
+				+ uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#first") + SPACE + quote("three") + SEMI + SPACE
+				+ uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#rest") + SPACE
+				+ uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#nil") + CLOSE_CURLY, query.toString());
+
+		assertTrue(n.isBlank());
 	}
-	
+
 	@Test
 	public void testListInTriple() {
-		handler.addWhere( new Triple(handler.list( "<one>", "?var", "'three'" ), ResourceFactory.createResource("foo").asNode(), 
-				ResourceFactory.createResource("bar").asNode()));
+		handler.addWhere(new Triple(handler.list("<one>", "?var", "'three'"),
+				ResourceFactory.createResource("foo").asNode(), ResourceFactory.createResource("bar").asNode()));
 
-		assertContainsRegex(
-				 "_:b0"+SPACE+ uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#first") + SPACE	+ uri("one") + SEMI 
-				+ SPACE + uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#rest") + SPACE+"_:b1"+ DOT
-				+ SPACE + "_:b1"+SPACE+ uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#first") + SPACE + var("var") + SEMI
-				+ SPACE + uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#rest") + SPACE+"_:b2"+ DOT
-				+ SPACE + "_:b2"+SPACE+ uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#first") + SPACE + quote("three") + SEMI
-				+ SPACE + uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#rest") + SPACE +uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#nil") 
-				, query.toString());
-		
-		assertContainsRegex(
-				 "_:b0"+SPACE+ uri("foo") + SPACE	+ uri("bar"), query.toString());
+		assertContainsRegex("_:b0" + SPACE + uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#first") + SPACE
+				+ uri("one") + SEMI + SPACE + uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#rest") + SPACE + "_:b1"
+				+ DOT + SPACE + "_:b1" + SPACE + uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#first") + SPACE
+				+ var("var") + SEMI + SPACE + uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#rest") + SPACE + "_:b2"
+				+ DOT + SPACE + "_:b2" + SPACE + uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#first") + SPACE
+				+ quote("three") + SEMI + SPACE + uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#rest") + SPACE
+				+ uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"), query.toString());
+
+		assertContainsRegex("_:b0" + SPACE + uri("foo") + SPACE + uri("bar"), query.toString());
 
-	 
 	}
 }


Mime
View raw message