@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()); assertTrue(con.hasStatement(alice, FOAF.NAME, null, false, graph2)); 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)); }
loadDataset("/testdata-update/dataset-update-example9.trig"); assertFalse(msg, con.hasStatement(book1, null, null, true, bookStore)); assertTrue(msg, con.hasStatement(book1, RDF.TYPE, null, true, bookStore2)); assertTrue(msg, con.hasStatement(book1, DC.DATE, null, true, bookStore2)); assertTrue(msg, con.hasStatement(book1, DC.TITLE, null, true, bookStore2));
update.append(getNamespaceDeclarations()); update.append("INSERT DATA { _:foo dc:title \"book 1\" ; dc:creator \"Ringo\" . } "); assertFalse(con.hasStatement(null, DC.TITLE, f.createLiteral("book 1"), true)); assertFalse(con.hasStatement(null, DC.CREATOR, f.createLiteral("Ringo"), true)); assertNotNull(titleStatements); assertNotNull(creatorStatements); assertFalse(titleStatements.hasNext()); assertTrue(subject instanceof BNode); bookNode = (BNode)subject; assertNotNull(bookNode); assertFalse("_:foo".equals(bookNode.getID())); assertFalse(creatorStatements.hasNext()); assertTrue(subject instanceof BNode); assertEquals(bookNode, subject); fail("at least one creator statement expected");
@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 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)); }
update.append(getNamespaceDeclarations()); update.append(" INSERT { ?s ex:complexAge [ rdf:value ?age; rdfs:label \"old\" ] . } "); update.append(" WHERE { ?s ex:age ?age . "); URI complexAge = f.createURI(EX_NS, "complexAge"); assertTrue(con.hasStatement(bob, age, null, true)); assertTrue(sts.hasNext()); assertTrue(sts.hasNext()); assertEquals(v1, v2); String query = getNamespaceDeclarations() + " SELECT ?bn ?age ?l WHERE { ex:bob ex:complexAge ?bn. ?bn rdf:value ?age. ?bn rdfs:label ?l .} "; assertTrue(result.hasNext()); assertFalse(result.hasNext());
@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)); }
/** * @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."); }
@Test public void testClearNamed() throws Exception { logger.debug("executing testClearNamed"); String update = "CLEAR NAMED"; Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update); operation.execute(); assertFalse(con.hasStatement(null, null, null, false, graph1)); assertFalse(con.hasStatement(null, null, null, false, graph2)); 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(); } }
/** * Creates, initializes and clears a repository. * * @return an initialized empty repository. * @throws Exception */ protected Repository createRepository() throws Exception { Repository repository = newRepository(); repository.initialize(); RepositoryConnection con = repository.getConnection(); con.clear(); con.clearNamespaces(); con.close(); return repository; }
loadDataset("/testdata-update/dataset-update-example9.trig");
@Test public void testDropAll() throws Exception { logger.debug("executing testDropAll"); String update = "DROP ALL"; Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update); operation.execute(); assertFalse(con.hasStatement(null, null, null, false)); }
/** * Overridden to destroy the backend database and its files on the disk. */ @Override public void tearDown() throws Exception { super.tearDown(); if (backend != null) tearDownBackend(backend); /* * Note: this field MUST be cleared to null or the backing database * instance will be held by a hard reference throughout the execution of * all unit tests in this test suite! */ backend = null; }
@Test public void testMoveFromDefaultToDefault() throws Exception { logger.debug("executing testMoveFromDefaultToDefault"); StringBuilder update = new StringBuilder(); update.append(getNamespaceDeclarations()); update.append("MOVE 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)); }
update.append(getNamespaceDeclarations()); update.append(" INSERT { ?s ex:complexAge [ rdf:value ?age; rdfs:label \"old\" ] . } "); update.append(" WHERE { ?s ex:age ?age . "); URI complexAge = f.createURI(EX_NS, "complexAge"); assertTrue(con.hasStatement(bob, age, null, true)); assertTrue(sts.hasNext()); assertTrue(sts.hasNext()); assertEquals(v1, v2); String query = getNamespaceDeclarations() + " SELECT ?bn ?age ?l WHERE { ex:bob ex:complexAge ?bn. ?bn rdf:value ?age. ?bn rdfs:label ?l .} "; assertTrue(result.hasNext()); assertFalse(result.hasNext());
@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)); }
/** * @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.createIRI(EX_NS, "bob"); alice = f.createIRI(EX_NS, "alice"); graph1 = f.createIRI(EX_NS, "graph1"); graph2 = f.createIRI(EX_NS, "graph2"); logger.debug("setup complete."); }
@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 testDropNamed() throws Exception { logger.debug("executing testDropNamed"); String update = "DROP NAMED"; Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update); operation.execute(); assertFalse(con.hasStatement(null, null, null, false, graph1)); assertFalse(con.hasStatement(null, null, null, false, graph2)); assertTrue(con.hasStatement(null, null, null, false)); }