gt: 			StringBuilder update = new StringBuilder();
context: /******************************************************************************
  ** Copyright (c) 2008-2014 Franz Inc.
  ** All rights reserved. This program and the accompanying materials
  ** are made available under the terms of the Eclipse Public License v1.0
  ** which accompanies this distribution, and is available at
  ** http://www.eclipse.org/legal/epl-v10.html
  ******************************************************************************/
  
  package test.openrdf;
  
  import static org.junit.Assert.assertEquals;
  import static org.junit.Assert.assertFalse;
  import static org.junit.Assert.assertNotNull;
  import static org.junit.Assert.assertTrue;
  import static org.junit.Assert.fail;
  
  import java.io.IOException;
  import java.io.InputStream;
  
  import org.junit.After;
  import org.junit.Before;
  import org.junit.Test;
  import org.openrdf.model.BNode;
  import org.openrdf.model.Literal;
  import org.openrdf.model.Resource;
  import org.openrdf.model.Statement;
  import org.openrdf.model.URI;
  import org.openrdf.model.Value;
  import org.openrdf.model.ValueFactory;
  import org.openrdf.model.vocabulary.RDF;
  import org.openrdf.model.vocabulary.RDFS;
  import org.openrdf.model.vocabulary.XMLSchema;
  import org.openrdf.query.BindingSet;
  import org.openrdf.query.QueryLanguage;
  import org.openrdf.query.TupleQueryResult;
  import org.openrdf.query.Update;
  import org.openrdf.query.UpdateExecutionException;
  import org.openrdf.model.vocabulary.DC;
  import org.openrdf.model.vocabulary.FOAF;
  import org.openrdf.repository.Repository;
  import org.openrdf.repository.RepositoryConnection;
  import org.openrdf.repository.RepositoryException;
  import org.openrdf.repository.RepositoryResult;
  import org.openrdf.rio.RDFFormat;
  import org.openrdf.rio.RDFParseException;
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  
  /**
   * Tests for SPARQL 1.1 Update functionality.
   * 
   * This class is a variant of
   * 
   * org.openrdf.query.parser.sparql.SPARQLUpdateTest
   * 
   * that allows access to con, f in subclasses.
   * 
   */
  public abstract class SPARQLUpdateTest {
  		static final Logger logger = LoggerFactory.getLogger(SPARQLUpdateTest.class);
  
  		private Repository rep;
  
  		protected RepositoryConnection con;
  
  		protected ValueFactory f;
  
  		private URI bob;
  
  		private URI alice;
  
  		private URI graph1;
  
  		private URI graph2;
  
  		protected static final String EX_NS = "http://example.org/";
  
  		/**
  		 * @throws java.lang.Exception
  		 */
  		@Before
  		public void setUp()
  			throws Exception
  		{
  			logger.debug("setting up test");
  
  			rep = createRepository();
  			con = rep.getConnection();
  			f = rep.getValueFactory();
  
  			loadDataset("/testdata-update/dataset-update.trig");
  
  			bob = f.createURI(EX_NS, "bob");
  			alice = f.createURI(EX_NS, "alice");
  
  			graph1 = f.createURI(EX_NS, "graph1");
  			graph2 = f.createURI(EX_NS, "graph2");
  
  			logger.debug("setup complete.");
  		}
  
  		/**
  		 * @throws java.lang.Exception
  		 */
  		@After
  		public void tearDown()
  			throws Exception
  		{
  			logger.debug("tearing down...");
  			con.close();
  			con = null;
  
  			rep.shutDown();
  			rep = null;
  
  			logger.debug("tearDown complete.");
  		}
  
  		/* test methods */
  
  		@Test
  		public void testInsertWhere()
  			throws Exception
  		{
  			logger.debug("executing test InsertWhere");
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append("INSERT {?x rdfs:label ?y . } WHERE {?x foaf:name ?y }");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  
  			assertFalse(con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bob"), true));
  			assertFalse(con.hasStatement(alice, RDFS.LABEL, f.createLiteral("Alice"), true));
  
  			operation.execute();
  
  			assertTrue(con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bob"), true));
  			assertTrue(con.hasStatement(alice, RDFS.LABEL, f.createLiteral("Alice"), true));
  		}
  
  		@Test
  		public void testInsertWhereWithBinding()
  			throws Exception
  		{
  			logger.debug("executing test testInsertWhereWithBinding");
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append("INSERT {?x rdfs:label ?y . } WHERE {?x foaf:name ?y }");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  			operation.setBinding("x", bob);
  
  			assertFalse(con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bob"), true));
  			assertFalse(con.hasStatement(alice, RDFS.LABEL, f.createLiteral("Alice"), true));
  
  			operation.execute();
  
  			assertTrue(con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bob"), true));
  			assertFalse(con.hasStatement(alice, RDFS.LABEL, f.createLiteral("Alice"), true));
  		}
  		
  
  		@Test
  		public void testInsertWhereWithBindings2()
  			throws Exception
  		{
  			logger.debug("executing test testInsertWhereWithBindings2");
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append("INSERT {?x rdfs:label ?z . } WHERE {?x foaf:name ?y }");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  			operation.setBinding("z", f.createLiteral("Bobbie"));
  			operation.setBinding("x", bob);
  
  			assertFalse(con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bobbie"), true));
  			assertFalse(con.hasStatement(alice, RDFS.LABEL, null, true));
  
  			operation.execute();
  
  			assertTrue(con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bobbie"), true));
  			assertFalse(con.hasStatement(alice, RDFS.LABEL, f.createLiteral("Alice"), true));
  		}
  
  		@Test
  		public void testInsertEmptyWhere()
  			throws Exception
  		{
  			logger.debug("executing test testInsertEmptyWhere");
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append("INSERT { <" + bob + "> rdfs:label \"Bob\" . } WHERE { }");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  
  			assertFalse(con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bob"), true));
  
  			operation.execute();
  
  			assertTrue(con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bob"), true));
  		}
  
  		@Test
  		public void testInsertEmptyWhereWithBinding()
  			throws Exception
  		{
  			logger.debug("executing test testInsertEmptyWhereWithBinding");
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append("INSERT {?x rdfs:label ?y . } WHERE { }");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  			operation.setBinding("x", bob);
  			operation.setBinding("y", f.createLiteral("Bob"));
  
  			assertFalse(con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bob"), true));
  
  			operation.execute();
  
  			assertTrue(con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bob"), true));
  		}
  
  		@Test
  		public void testInsertNonMatchingWhere()
  			throws Exception
  		{
  			logger.debug("executing test testInsertNonMatchingWhere");
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append("INSERT { ?x rdfs:label ?y . } WHERE { ?x rdfs:comment ?y }");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  
  			assertFalse(con.hasStatement(bob, RDFS.LABEL, null, true));
  
  			operation.execute();
  
  			assertFalse(con.hasStatement(bob, RDFS.LABEL, null, true));
  		}
  
  		@Test
  		public void testInsertNonMatchingWhereWithBindings()
  			throws Exception
  		{
  			logger.debug("executing test testInsertNonMatchingWhereWithBindings");
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append("INSERT { ?x rdfs:label ?y . } WHERE { ?x rdfs:comment ?y }");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  			operation.setBinding("x", bob);
  			operation.setBinding("y", f.createLiteral("Bob"));
  
  			assertFalse(con.hasStatement(bob, RDFS.LABEL, null, true));
  
  			operation.execute();
  
  			assertFalse(con.hasStatement(bob, RDFS.LABEL, null, true));
  		}
  
  		@Test
  		public void testInsertWhereWithBindings()
  			throws Exception
  		{
  			logger.debug("executing test testInsertWhereWithBindings");
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append("INSERT { ?x rdfs:comment ?z . } WHERE { ?x foaf:name ?y }");
  
  			Literal comment = f.createLiteral("Bob has a comment");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  			operation.setBinding("x", bob);
  			operation.setBinding("z", comment);
  
  			assertFalse(con.hasStatement(null, RDFS.COMMENT, comment, true));
  
  			operation.execute();
  
  			assertTrue(con.hasStatement(bob, RDFS.COMMENT, comment, true));
  			assertFalse(con.hasStatement(alice, RDFS.COMMENT, comment, true));
  
  		}
  
  		@Test
  		public void testInsertWhereWithOptional()
  			throws Exception
  		{
  			logger.debug("executing testInsertWhereWithOptional");
  
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append(" INSERT { ?s ex:age ?incAge } ");
  			// update.append(" DELETE { ?s ex:age ?age } ");
  			update.append(" WHERE { ?s foaf:name ?name . ");
  			update.append(" OPTIONAL {?s ex:age ?age . BIND ((?age + 1) as ?incAge)  } ");
  			update.append(" } ");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  
  			URI age = f.createURI(EX_NS, "age");
  
  			assertFalse(con.hasStatement(alice, age, null, true));
  			assertTrue(con.hasStatement(bob, age, null, true));
  
  			operation.execute();
  
  			//RepositoryResult<Statement> result = con.getStatements(bob, age, null, true);
  
  			//while (result.hasNext()) {
  				//System.out.println(result.next().toString());
  			//}
  
  			assertTrue(con.hasStatement(bob, age, f.createLiteral("43", XMLSchema.INTEGER), true));
  
  			//result = con.getStatements(alice, age, null, true);
  
  			//while (result.hasNext()) {
  				//System.out.println(result.next());
  			//}
  			assertFalse(con.hasStatement(alice, age, null, true));
  		}
  
  		@Test
  		public void testInsertWhereWithBlankNode()
  			throws Exception
  		{
  			logger.debug("executing testInsertWhereWithBlankNode");
  
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append(" INSERT { ?s ex:complexAge [ rdf:value ?age; rdfs:label \"old\" ] . } ");
  			update.append(" WHERE { ?s ex:age ?age . ");
  			update.append(" } ");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  
  			URI age = f.createURI(EX_NS, "age");
  			URI complexAge = f.createURI(EX_NS, "complexAge");
  
  			assertTrue(con.hasStatement(bob, age, null, true));
  
  			operation.execute();
  
  			RepositoryResult<Statement> sts = con.getStatements(bob, complexAge, null, true);
  
  			assertTrue(sts.hasNext());
  
  			Value v1 = sts.next().getObject();
  
  			sts.close();
  
  			sts = con.getStatements(null, RDF.VALUE, null, true);
  
  			assertTrue(sts.hasNext());
  
  			Value v2 = sts.next().getSubject();
  
  			assertEquals(v1, v2);
  
  			sts.close();
  
  			String query = getNamespaceDeclarations()
  					+ " SELECT ?bn ?age ?l WHERE { ex:bob ex:complexAge ?bn. ?bn rdf:value ?age. ?bn rdfs:label ?l .} ";
  
  			TupleQueryResult result = con.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();
  
  			assertTrue(result.hasNext());
  
  			BindingSet bs = result.next();
  
  			assertFalse(result.hasNext());
  
  		}
  
  		@Test
  		public void testDeleteInsertWhere()
  			throws Exception
  		{
  			logger.debug("executing test DeleteInsertWhere");
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append("DELETE { ?x foaf:name ?y } INSERT {?x rdfs:label ?y . } WHERE {?x foaf:name ?y }");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  
  			assertFalse(con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bob"), true));
  			assertFalse(con.hasStatement(alice, RDFS.LABEL, f.createLiteral("Alice"), true));
  
  			operation.execute();
  
  			assertTrue(con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bob"), true));
  			assertTrue(con.hasStatement(alice, RDFS.LABEL, f.createLiteral("Alice"), true));
  
  			assertFalse(con.hasStatement(bob, FOAF.NAME, f.createLiteral("Bob"), true));
  			assertFalse(con.hasStatement(alice, FOAF.NAME, f.createLiteral("Alice"), true));
  
  		}
  		
  		@Test
  		public void testDeleteWhereOptional()
  			throws Exception
  		{
  			logger.debug("executing test testDeleteWhereOptional");
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append(" DELETE { ?x foaf:name ?y; foaf:mbox ?mbox. } ");
  			update.append(" WHERE {?x foaf:name ?y. ");
  			update.append(" OPTIONAL { ?x foaf:mbox ?mbox. FILTER (str(?mbox) = \"bob@example.org\") } }");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  
  			Literal mboxBob = f.createLiteral("bob@example.org");
  			Literal mboxAlice = f.createLiteral("alice@example.org");
  			assertTrue(con.hasStatement(bob, FOAF.MBOX, mboxBob , true));
  			assertTrue(con.hasStatement(alice, FOAF.MBOX, mboxAlice, true));
  
  
  			assertTrue(con.hasStatement(bob, FOAF.NAME, f.createLiteral("Bob"), true));
  			assertTrue(con.hasStatement(alice, FOAF.NAME, f.createLiteral("Alice"), true));
  			
  			operation.execute();
  
  			assertFalse(con.hasStatement(bob, FOAF.MBOX, mboxBob , true));
  			assertTrue(con.hasStatement(alice, FOAF.MBOX, mboxAlice, true));
  			
  			assertFalse(con.hasStatement(bob, FOAF.NAME, f.createLiteral("Bob"), true));
  			assertFalse(con.hasStatement(alice, FOAF.NAME, f.createLiteral("Alice"), true));
  
  		}
  
  		@Test
  		public void testDeleteInsertWhereWithBindings()
  			throws Exception
  		{
  			logger.debug("executing test testDeleteInsertWhereWithBindings");
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append("DELETE { ?x foaf:name ?y } INSERT {?x rdfs:label ?y . } WHERE {?x foaf:name ?y }");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  
  			operation.setBinding("x", bob);
  			
  			assertFalse(con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bob"), true));
  			assertFalse(con.hasStatement(alice, RDFS.LABEL, f.createLiteral("Alice"), true));
  
  			operation.execute();
  
  			assertTrue(con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bob"), true));
  			assertFalse(con.hasStatement(alice, RDFS.LABEL, f.createLiteral("Alice"), true));
  
  			assertFalse(con.hasStatement(bob, FOAF.NAME, f.createLiteral("Bob"), true));
  			assertTrue(con.hasStatement(alice, FOAF.NAME, f.createLiteral("Alice"), true));
  		}
  		
  		@Test
  		public void testDeleteInsertWhereWithBindings2()
  			throws Exception
  		{
  			logger.debug("executing test testDeleteInsertWhereWithBindings2");
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append("DELETE { ?x foaf:name ?y } INSERT {?x rdfs:label ?z . } WHERE {?x foaf:name ?y }");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  
  			operation.setBinding("z", f.createLiteral("person"));
  			
  			assertFalse(con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bob"), true));
  			assertFalse(con.hasStatement(alice, RDFS.LABEL, f.createLiteral("Alice"), true));
  
  			operation.execute();
  
  			assertTrue(con.hasStatement(bob, RDFS.LABEL, f.createLiteral("person"), true));
  			assertTrue(con.hasStatement(alice, RDFS.LABEL, f.createLiteral("person"), true));
  
  			assertFalse(con.hasStatement(bob, FOAF.NAME, f.createLiteral("Bob"), true));
  			assertFalse(con.hasStatement(alice, FOAF.NAME, f.createLiteral("Alice"), true));
  		}
  		
  		@Test
  		public void testDeleteInsertWhereLoopingBehavior()
  			throws Exception
  		{
  			logger.debug("executing test testDeleteInsertWhereLoopingBehavior");
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append(" DELETE { ?x ex:age ?y } INSERT {?x ex:age ?z }");
  			update.append(" WHERE { ");
  			update.append("   ?x ex:age ?y .");
  			update.append("   BIND((?y + 1) as ?z) ");
  			update.append("   FILTER( ?y < 46 ) ");
  			update.append(" } ");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  
  			URI age = f.createURI(EX_NS, "age");
  			Literal originalAgeValue = f.createLiteral("42", XMLSchema.INTEGER);
  			Literal correctAgeValue = f.createLiteral("43", XMLSchema.INTEGER);
  			Literal inCorrectAgeValue = f.createLiteral("46", XMLSchema.INTEGER);
  
  			assertTrue(con.hasStatement(bob, age, originalAgeValue, true));
  
  			operation.execute();
  
  			assertFalse(con.hasStatement(bob, age, originalAgeValue, true));
  			assertTrue(con.hasStatement(bob, age, correctAgeValue, true));
  			assertFalse(con.hasStatement(bob, age, inCorrectAgeValue, true));
  		}
  
  		@Test
  		public void testAutoCommitHandling()
  			throws Exception
  		{
  			logger.debug("executing test testAutoCommitHandling");
  
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append("DELETE { ?x foaf:name ?y } INSERT {?x rdfs:label ?y . } WHERE {?x foaf:name ?y }");
  
  			boolean autoCommit = !con.isActive();
  
  			con.begin();
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  
  			assertFalse(con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bob"), true));
  			assertFalse(con.hasStatement(alice, RDFS.LABEL, f.createLiteral("Alice"), true));
  
  			operation.execute();
  
  			// update should be visible to own connection.
  			assertTrue(con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bob"), true));
  			assertTrue(con.hasStatement(alice, RDFS.LABEL, f.createLiteral("Alice"), true));
  
  			assertFalse(con.hasStatement(bob, FOAF.NAME, f.createLiteral("Bob"), true));
  			assertFalse(con.hasStatement(alice, FOAF.NAME, f.createLiteral("Alice"), true));
  
  			RepositoryConnection con2 = rep.getConnection();
  			try {
  				// update should not yet be visible to separate connection
  				assertFalse(con2.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bob"), true));
  				assertFalse(con2.hasStatement(alice, RDFS.LABEL, f.createLiteral("Alice"), true));
  
  				assertTrue(con2.hasStatement(bob, FOAF.NAME, f.createLiteral("Bob"), true));
  				assertTrue(con2.hasStatement(alice, FOAF.NAME, f.createLiteral("Alice"), true));
  
  				con.commit();
  
  				// after commit, update should be visible to separate connection.
  				assertTrue(con2.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bob"), true));
  				assertTrue(con2.hasStatement(alice, RDFS.LABEL, f.createLiteral("Alice"), true));
  
  				assertFalse(con2.hasStatement(bob, FOAF.NAME, f.createLiteral("Bob"), true));
  				assertFalse(con2.hasStatement(alice, FOAF.NAME, f.createLiteral("Alice"), true));
  
  			}
  			finally {
  				con2.close();
  				if (con.isActive()) {
  					con.rollback();
  				}
  			}
  		}
  
  		@Test
  		public void testConsecutiveUpdatesInSameTransaction()
  			throws Exception
  		{
  			// this tests if consecutive updates in the same transaction behave
  			// correctly. See issue SES-930
  			logger.debug("executing test testConsecutiveUpdatesInSameTransaction");
  
  			StringBuilder update1 = new StringBuilder();
  			update1.append(getNamespaceDeclarations());
  			update1.append("DELETE { ?x foaf:name ?y } WHERE {?x foaf:name ?y }");
  
  			boolean autoCommit = !con.isActive();
  
  			con.begin();
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update1.toString());
  
  			assertFalse(con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bob"), true));
  			assertFalse(con.hasStatement(alice, RDFS.LABEL, f.createLiteral("Alice"), true));
  
  			operation.execute();
  
  			// update should be visible to own connection.
  			assertFalse(con.hasStatement(bob, FOAF.NAME, f.createLiteral("Bob"), true));
  			assertFalse(con.hasStatement(alice, FOAF.NAME, f.createLiteral("Alice"), true));
  
  			StringBuilder update2 = new StringBuilder();
  			update2.append(getNamespaceDeclarations());
  			update2.append("INSERT { ?x rdfs:label ?y } WHERE {?x foaf:name ?y }");
  
  			operation = con.prepareUpdate(QueryLanguage.SPARQL, update2.toString());
  
  			operation.execute();
  
  			// update should not have resulted in any inserts: where clause is empty.
  			assertFalse(con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bob"), true));
  			assertFalse(con.hasStatement(alice, RDFS.LABEL, f.createLiteral("Alice"), true));
  
  			con.setAutoCommit(autoCommit);
  
  		}
  
  		@Test
  		public void testInsertTransformedWhere()
  			throws Exception
  		{
  			logger.debug("executing test InsertTransformedWhere");
  
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append("INSERT {?x rdfs:label [] . } WHERE {?y ex:containsPerson ?x.  }");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  
  			assertFalse(con.hasStatement(bob, RDFS.LABEL, null, true));
  			assertFalse(con.hasStatement(alice, RDFS.LABEL, null, true));
  
  			operation.execute();
  
  			assertTrue(con.hasStatement(bob, RDFS.LABEL, null, true));
  			assertTrue(con.hasStatement(alice, RDFS.LABEL, null, true));
  		}
  
  		@Test
  		public void testInsertWhereGraph()
  			throws Exception
  		{
  			logger.debug("executing testInsertWhereGraph");
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append("INSERT {GRAPH ?g {?x rdfs:label ?y . }} WHERE {GRAPH ?g {?x foaf:name ?y }}");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  
  			operation.execute();
  
  			String message = "labels should have been inserted in corresponding named graphs only.";
  			assertTrue(message, con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bob"), true, graph1));
  			assertFalse(message, con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bob"), true, graph2));
  			assertTrue(message, con.hasStatement(alice, RDFS.LABEL, f.createLiteral("Alice"), true, graph2));
  			assertFalse(message, con.hasStatement(alice, RDFS.LABEL, f.createLiteral("Alice"), true, graph1));
  		}
  
  		@Test
  		public void testInsertWhereUsing()
  			throws Exception
  		{
  
  			logger.debug("executing testInsertWhereUsing");
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append("INSERT {?x rdfs:label ?y . } USING ex:graph1 WHERE {?x foaf:name ?y }");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  
  			operation.execute();
  
  			String message = "label should have been inserted in default graph, for ex:bob only";
  			assertTrue(message, con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bob"), true));
  			assertFalse(message, con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bob"), true, graph1));
  			assertFalse(message, con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bob"), true, graph2));
  			assertFalse(message, con.hasStatement(alice, RDFS.LABEL, f.createLiteral("Alice"), true));
  		}
  
  		@Test
  		public void testInsertWhereWith()
  			throws Exception
  		{
  			logger.debug("executing testInsertWhereWith");
  
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append("WITH ex:graph1 INSERT {?x rdfs:label ?y . } WHERE {?x foaf:name ?y }");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  
  			operation.execute();
  
  			String message = "label should have been inserted in graph1 only, for ex:bob only";
  			assertTrue(message, con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bob"), true, graph1));
  			assertFalse(message, con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bob"), true, graph2));
  			assertFalse(message, con.hasStatement(alice, RDFS.LABEL, f.createLiteral("Alice"), true, graph2));
  			assertFalse(message, con.hasStatement(alice, RDFS.LABEL, f.createLiteral("Alice"), true, graph1));
  		}
  
  		@Test
  		public void testDeleteWhereShortcut()
  			throws Exception
  		{
  			logger.debug("executing testDeleteWhereShortcut");
  
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append("DELETE WHERE {?x foaf:name ?y }");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  
  			assertTrue(con.hasStatement(bob, FOAF.NAME, f.createLiteral("Bob"), true));
  			assertTrue(con.hasStatement(alice, FOAF.NAME, f.createLiteral("Alice"), true));
  
  			operation.execute();
  
  			String msg = "foaf:name properties should have been deleted";
  			assertFalse(msg, con.hasStatement(bob, FOAF.NAME, f.createLiteral("Bob"), true));
  			assertFalse(msg, con.hasStatement(alice, FOAF.NAME, f.createLiteral("Alice"), true));
  
  			msg = "foaf:knows properties should not have been deleted";
  			assertTrue(msg, con.hasStatement(bob, FOAF.KNOWS, null, true));
  			assertTrue(msg, con.hasStatement(alice, FOAF.KNOWS, null, true));
  		}
  
  		@Test
  		public void testDeleteWhere()
  			throws Exception
  		{
  			logger.debug("executing testDeleteWhere");
  
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append("DELETE {?x foaf:name ?y } WHERE {?x foaf:name ?y }");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  
  			assertTrue(con.hasStatement(bob, FOAF.NAME, f.createLiteral("Bob"), true));
  			assertTrue(con.hasStatement(alice, FOAF.NAME, f.createLiteral("Alice"), true));
  
  			operation.execute();
  
  			String msg = "foaf:name properties should have been deleted";
  			assertFalse(msg, con.hasStatement(bob, FOAF.NAME, f.createLiteral("Bob"), true));
  			assertFalse(msg, con.hasStatement(alice, FOAF.NAME, f.createLiteral("Alice"), true));
  
  		}
  
  		@Test
  		public void testDeleteTransformedWhere()
  			throws Exception
  		{
  			logger.debug("executing testDeleteTransformedWhere");
  
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append("DELETE {?y foaf:name ?n } WHERE {?x ex:containsPerson ?y . ?y foaf:name ?n . }");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  
  			assertTrue(con.hasStatement(bob, FOAF.NAME, f.createLiteral("Bob"), true));
  			assertTrue(con.hasStatement(alice, FOAF.NAME, f.createLiteral("Alice"), true));
  
  			operation.execute();
  
  			String msg = "foaf:name properties should have been deleted";
  			assertFalse(msg, con.hasStatement(bob, FOAF.NAME, f.createLiteral("Bob"), true));
  			assertFalse(msg, con.hasStatement(alice, FOAF.NAME, f.createLiteral("Alice"), true));
  
  			msg = "ex:containsPerson properties should not have been deleted";
  			assertTrue(msg, con.hasStatement(graph1, f.createURI(EX_NS, "containsPerson"), bob, true));
  			assertTrue(msg, con.hasStatement(graph2, f.createURI(EX_NS, "containsPerson"), alice, true));
  
  		}
  
  
  		@Test
  		public void testInsertData()
  			throws Exception
  		{
  			logger.debug("executing testInsertData");
  
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append("INSERT DATA { ex:book1 dc:title \"book 1\" ; dc:creator \"Ringo\" . } ");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  
  			URI book1 = f.createURI(EX_NS, "book1");
  
  			assertFalse(con.hasStatement(book1, DC.TITLE, f.createLiteral("book 1"), true));
  			assertFalse(con.hasStatement(book1, DC.CREATOR, f.createLiteral("Ringo"), true));
  
  			operation.execute();
  
  			String msg = "two new statements about ex:book1 should have been inserted";
  			assertTrue(msg, con.hasStatement(book1, DC.TITLE, f.createLiteral("book 1"), true));
  			assertTrue(msg, con.hasStatement(book1, DC.CREATOR, f.createLiteral("Ringo"), true));
  		}
  		
  		@Test
  		public void testInsertDataBlankNode()
  			throws Exception
  		{
  			logger.debug("executing testInsertDataBlankNode");
  
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append("INSERT DATA { _:foo dc:title \"book 1\" ; dc:creator \"Ringo\" . } ");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  
  			assertFalse(con.hasStatement(null, DC.TITLE, f.createLiteral("book 1"), true));
  			assertFalse(con.hasStatement(null, DC.CREATOR, f.createLiteral("Ringo"), true));
  
  			operation.execute();
  
  			RepositoryResult<Statement> titleStatements = con.getStatements(null, DC.TITLE, f.createLiteral("book 1"), true);
  			assertNotNull(titleStatements);
  			
  			RepositoryResult<Statement> creatorStatements = con.getStatements(null, DC.CREATOR, f.createLiteral("Ringo"), true);
  			assertNotNull(creatorStatements);
  			
  			BNode bookNode = null;
  			if (titleStatements.hasNext()) {
  				Statement ts = titleStatements.next();
  				assertFalse(titleStatements.hasNext());
  				
  				Resource subject = ts.getSubject();
  				assertTrue(subject instanceof BNode);
  				bookNode = (BNode)subject;
  			}
  			titleStatements.close();
  			assertNotNull(bookNode);
  			assertFalse("_:foo".equals(bookNode.getID()));
  			
  			if (creatorStatements.hasNext()) {
  				Statement cs = creatorStatements.next();
  				assertFalse (creatorStatements.hasNext());
  				
  				Resource subject = cs.getSubject();
  				assertTrue(subject instanceof BNode);
  				assertEquals(bookNode, subject);
  			}
  			else {
  				fail("at least one creator statement expected");
  			}
  			creatorStatements.close();
  		}
  
  		@Test
  		public void testInsertDataMultiplePatterns()
  			throws Exception
  		{
  			logger.debug("executing testInsertData");
  
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append("INSERT DATA { ex:book1 dc:title \"book 1\". ex:book1 dc:creator \"Ringo\" . ex:book2 dc:creator \"George\". } ");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  
  			URI book1 = f.createURI(EX_NS, "book1");
  			URI book2 = f.createURI(EX_NS, "book2");
  
  			assertFalse(con.hasStatement(book1, DC.TITLE, f.createLiteral("book 1"), true));
  			assertFalse(con.hasStatement(book1, DC.CREATOR, f.createLiteral("Ringo"), true));
  			assertFalse(con.hasStatement(book2, DC.CREATOR, f.createLiteral("George"), true));
  
  			operation.execute();
  
  			String msg = "newly inserted statement missing";
  			assertTrue(msg, con.hasStatement(book1, DC.TITLE, f.createLiteral("book 1"), true));
  			assertTrue(msg, con.hasStatement(book1, DC.CREATOR, f.createLiteral("Ringo"), true));
  			assertTrue(msg, con.hasStatement(book2, DC.CREATOR, f.createLiteral("George"), true));
  		}
  
  		@Test
  		public void testInsertDataInGraph()
  			throws Exception
  		{
  			logger.debug("executing testInsertDataInGraph");
  
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append("INSERT DATA { GRAPH ex:graph1 { ex:book1 dc:title \"book 1\" ; dc:creator \"Ringo\" . } } ");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  
  			URI book1 = f.createURI(EX_NS, "book1");
  
  			assertFalse(con.hasStatement(book1, DC.TITLE, f.createLiteral("book 1"), true, graph1));
  			assertFalse(con.hasStatement(book1, DC.CREATOR, f.createLiteral("Ringo"), true, graph1));
  
  			operation.execute();
  
  			String msg = "two new statements about ex:book1 should have been inserted in graph1";
  			assertTrue(msg, con.hasStatement(book1, DC.TITLE, f.createLiteral("book 1"), true, graph1));
  			assertTrue(msg, con.hasStatement(book1, DC.CREATOR, f.createLiteral("Ringo"), true, graph1));
  		}
  
  		@Test
  		public void testInsertDataInGraph2()
  			throws Exception
  		{
  			logger.debug("executing testInsertDataInGraph2");
  
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append("INSERT DATA { GRAPH ex:graph1 { ex:Human rdfs:subClassOf ex:Mammal. ex:Mammal rdfs:subClassOf ex:Animal. ex:george a ex:Human. ex:ringo a ex:Human. } } ");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  
  			URI human = f.createURI(EX_NS, "Human");
  			URI mammal = f.createURI(EX_NS, "Mammal");
  			URI george = f.createURI(EX_NS, "george");
  
  			operation.execute();
  
  			assertTrue(con.hasStatement(human, RDFS.SUBCLASSOF, mammal, true, graph1));
  			assertTrue(con.hasStatement(mammal, RDFS.SUBCLASSOF, null, true, graph1));
  			assertTrue(con.hasStatement(george, RDF.TYPE, human, true, graph1));
  		}
  
  		@Test
  		public void testDeleteData()
  			throws Exception
  		{
  			logger.debug("executing testDeleteData");
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append("DELETE DATA { ex:alice foaf:knows ex:bob. } ");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  
  			assertTrue(con.hasStatement(alice, FOAF.KNOWS, bob, true));
  			operation.execute();
  
  			String msg = "statement should have been deleted.";
  			assertFalse(msg, con.hasStatement(alice, FOAF.KNOWS, bob, true));
  		}
  
  		@Test
  		public void testDeleteDataMultiplePatterns()
  			throws Exception
  		{
  			logger.debug("executing testDeleteData");
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append("DELETE DATA { ex:alice foaf:knows ex:bob. ex:alice foaf:mbox \"alice@example.org\" .} ");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  
  			assertTrue(con.hasStatement(alice, FOAF.KNOWS, bob, true));
  			assertTrue(con.hasStatement(alice, FOAF.MBOX, f.createLiteral("alice@example.org"), true));
  			operation.execute();
  
  			String msg = "statement should have been deleted.";
  			assertFalse(msg, con.hasStatement(alice, FOAF.KNOWS, bob, true));
  			assertFalse(msg, con.hasStatement(alice, FOAF.MBOX, f.createLiteral("alice@example.org"), true));
  		}
  
  		@Test
  		public void testDeleteDataFromGraph()
  			throws Exception
  		{
  			logger.debug("executing testDeleteDataFromGraph");
  
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append("DELETE DATA { GRAPH ex:graph1 {ex:alice foaf:knows ex:bob. } } ");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  
  			assertTrue(con.hasStatement(alice, FOAF.KNOWS, bob, true, graph1));
  			operation.execute();
  
  			String msg = "statement should have been deleted from graph1";
  			assertFalse(msg, con.hasStatement(alice, FOAF.KNOWS, bob, true, graph1));
  		}
  
  		@Test
  		public void testDeleteDataFromWrongGraph()
  			throws Exception
  		{
  			logger.debug("executing testDeleteDataFromWrongGraph");
  
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  
  			// statement does not exist in graph2.
  			update.append("DELETE DATA { GRAPH ex:graph2 {ex:alice foaf:knows ex:bob. } } ");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  
  			assertTrue(con.hasStatement(alice, FOAF.KNOWS, bob, true, graph1));
  			assertFalse(con.hasStatement(alice, FOAF.KNOWS, bob, true, graph2));
  			operation.execute();
  
  			String msg = "statement should have not have been deleted from graph1";
  			assertTrue(msg, con.hasStatement(alice, FOAF.KNOWS, bob, true, graph1));
  		}
  
  		@Test
  		public void testCreateNewGraph()
  			throws Exception
  		{
  			logger.debug("executing testCreateNewGraph");
  
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  
  			URI newGraph = f.createURI(EX_NS, "new-graph");
  
  			update.append("CREATE GRAPH <" + newGraph + "> ");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  
  			operation.execute();
  			assertTrue(con.hasStatement(null, null, null, false, graph1));
  			assertTrue(con.hasStatement(null, null, null, false, graph2));
  			assertFalse(con.hasStatement(null, null, null, false, newGraph));
  			assertTrue(con.hasStatement(null, null, null, false));
  		}
  
  		@Test
  		public void testCreateExistingGraph()
  			throws Exception
  		{
  			logger.debug("executing testCreateExistingGraph");
  
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append("CREATE GRAPH <" + graph1 + "> ");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  
  			try {
  				operation.execute();
  
  				fail("creation of existing graph should have resulted in error.");
  			}
  			catch (UpdateExecutionException e) {
  				// expected behavior
  				con.rollback();
  			}
  		}
  
  		@Test
  		public void testCopyToDefault()
  			throws Exception
  		{
  			logger.debug("executing testCopyToDefault");
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append("COPY GRAPH <" + graph1.stringValue() + "> TO DEFAULT");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  
  			assertTrue(con.hasStatement(graph1, DC.PUBLISHER, null, false, (Resource)null));
  			assertTrue(con.hasStatement(graph2, DC.PUBLISHER, null, false, (Resource)null));
  			operation.execute();
  			assertFalse(con.hasStatement(graph1, DC.PUBLISHER, null, false, (Resource)null));
  			assertFalse(con.hasStatement(graph2, DC.PUBLISHER, null, false, (Resource)null));
  			assertTrue(con.hasStatement(bob, FOAF.NAME, null, false, (Resource)null));
  			assertTrue(con.hasStatement(bob, FOAF.NAME, null, false, graph1));
  		}
  
  		@Test
  		public void testCopyToExistingNamed()
  			throws Exception
  		{
  			logger.debug("executing testCopyToExistingNamed");
  
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append("COPY GRAPH ex:graph1 TO ex:graph2");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  
  			operation.execute();
  			assertTrue(con.hasStatement(bob, FOAF.NAME, null, false, graph2));
  			assertFalse(con.hasStatement(alice, FOAF.NAME, null, false, graph2));
  			assertTrue(con.hasStatement(bob, FOAF.NAME, null, false, graph1));
  		}
  
  		@Test
  		public void testCopyToNewNamed()
  			throws Exception
  		{
  			logger.debug("executing testCopyToNewNamed");
  
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append("COPY GRAPH ex:graph1 TO ex:graph3");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  
  			operation.execute();
  			assertTrue(con.hasStatement(bob, FOAF.NAME, null, false, f.createURI(EX_NS, "graph3")));
  			assertTrue(con.hasStatement(bob, FOAF.NAME, null, false, graph1));
  		}
  
  		@Test
  		public void testCopyFromDefault()
  			throws Exception
  		{
  			logger.debug("executing testCopyFromDefault");
  
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append("COPY DEFAULT TO ex:graph3");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  
  			assertTrue(con.hasStatement(graph1, DC.PUBLISHER, null, false, (Resource)null));
  			assertTrue(con.hasStatement(graph2, DC.PUBLISHER, null, false, (Resource)null));
  			operation.execute();
  			assertTrue(con.hasStatement(graph1, DC.PUBLISHER, null, false, (Resource)null));
  			assertTrue(con.hasStatement(graph2, DC.PUBLISHER, null, false, (Resource)null));
  			assertTrue(con.hasStatement(graph1, DC.PUBLISHER, null, false, f.createURI(EX_NS, "graph3")));
  			assertTrue(con.hasStatement(graph2, DC.PUBLISHER, null, false, f.createURI(EX_NS, "graph3")));
  
  		}
  
  		@Test
  		public void testCopyFromDefaultToDefault()
  			throws Exception
  		{
  			logger.debug("executing testCopyFromDefaultToDefault");
  
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append("COPY DEFAULT TO DEFAULT");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  
  			assertTrue(con.hasStatement(graph1, DC.PUBLISHER, null, false, (Resource)null));
  			assertTrue(con.hasStatement(graph2, DC.PUBLISHER, null, false, (Resource)null));
  			operation.execute();
  			assertTrue(con.hasStatement(graph1, DC.PUBLISHER, null, false, (Resource)null));
  			assertTrue(con.hasStatement(graph2, DC.PUBLISHER, null, false, (Resource)null));
  		}
  
  		@Test
  		public void testAddToDefault()
  			throws Exception
  		{
  			logger.debug("executing testAddToDefault");
  
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append("ADD GRAPH <" + graph1.stringValue() + "> TO DEFAULT");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  
  			assertTrue(con.hasStatement(graph1, DC.PUBLISHER, null, false, (Resource)null));
  			assertTrue(con.hasStatement(graph2, DC.PUBLISHER, null, false, (Resource)null));
  			operation.execute();
  			assertTrue(con.hasStatement(graph1, DC.PUBLISHER, null, false, (Resource)null));
  			assertTrue(con.hasStatement(graph2, DC.PUBLISHER, null, false, (Resource)null));
  			assertTrue(con.hasStatement(bob, FOAF.NAME, null, false, (Resource)null));
  			assertTrue(con.hasStatement(bob, FOAF.NAME, null, false, graph1));
  		}
  
  		@Test
  		public void testAddToExistingNamed()
  			throws Exception
  		{
  			logger.debug("executing testAddToExistingNamed");
  
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append("ADD GRAPH ex:graph1 TO ex:graph2");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  
  			operation.execute();
  			assertTrue(con.hasStatement(bob, FOAF.NAME, null, false, graph2));
  			assertTrue(con.hasStatement(alice, FOAF.NAME, null, false, graph2));
  			assertTrue(con.hasStatement(bob, FOAF.NAME, null, false, graph1));
  		}
  
  		@Test
  		public void testAddToNewNamed()
  			throws Exception
  		{
  			logger.debug("executing testAddToNewNamed");
  
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append("ADD GRAPH ex:graph1 TO ex:graph3");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  
  			operation.execute();
  			assertTrue(con.hasStatement(bob, FOAF.NAME, null, false, f.createURI(EX_NS, "graph3")));
  			assertTrue(con.hasStatement(bob, FOAF.NAME, null, false, graph1));
  		}
  
  		@Test
  		public void testAddFromDefault()
  			throws Exception
  		{
  			logger.debug("executing testAddFromDefault");
  
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append("ADD DEFAULT TO ex:graph3");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  
  			assertTrue(con.hasStatement(graph1, DC.PUBLISHER, null, false, (Resource)null));
  			assertTrue(con.hasStatement(graph2, DC.PUBLISHER, null, false, (Resource)null));
  			operation.execute();
  			assertTrue(con.hasStatement(graph1, DC.PUBLISHER, null, false, (Resource)null));
  			assertTrue(con.hasStatement(graph2, DC.PUBLISHER, null, false, (Resource)null));
  			assertTrue(con.hasStatement(graph1, DC.PUBLISHER, null, false, f.createURI(EX_NS, "graph3")));
  			assertTrue(con.hasStatement(graph2, DC.PUBLISHER, null, false, f.createURI(EX_NS, "graph3")));
  
  		}
  
  		@Test
  		public void testAddFromDefaultToDefault()
  			throws Exception
  		{
  			logger.debug("executing testAddFromDefaultToDefault");
  
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append("ADD DEFAULT TO DEFAULT");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  
  			assertTrue(con.hasStatement(graph1, DC.PUBLISHER, null, false, (Resource)null));
  			assertTrue(con.hasStatement(graph2, DC.PUBLISHER, null, false, (Resource)null));
  			operation.execute();
  			assertTrue(con.hasStatement(graph1, DC.PUBLISHER, null, false, (Resource)null));
  			assertTrue(con.hasStatement(graph2, DC.PUBLISHER, null, false, (Resource)null));
  		}
  
  		@Test
  		public void testMoveToDefault()
  			throws Exception
  		{
  			logger.debug("executing testMoveToDefault");
  
  			StringBuilder update = new StringBuilder();
  			update.append(getNamespaceDeclarations());
  			update.append("MOVE GRAPH <" + graph1.stringValue() + "> TO DEFAULT");
  
  			Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  
  			assertTrue(con.hasStatement(graph1, DC.PUBLISHER, null, false, (Resource)null));
  			assertTrue(con.hasStatement(graph2, DC.PUBLISHER, null, false, (Resource)null));
  			operation.execute();
  			assertFalse(con.hasStatement(graph1, DC.PUBLISHER, null, false, (Resource)null));
  			assertFalse(con.hasStatement(graph2, DC.PUBLISHER, null, false, (Resource)null));
  			assertTrue(con.hasStatement(bob, FOAF.NAME, null, false, (Resource)null));
  			assertFalse(con.hasStatement(null, null, null, false, graph1));
  		}
  
  		@Test
  		public void testMoveToNewNamed()
  			throws Exception
  		{
  			logger.debug("executing testMoveToNewNamed");
  