public void testGraphSerialization() throws Exception { testCon.add(bob, name, nameBob); testCon.add(alice, name, nameAlice); Graph graph; RepositoryResult<Statement> statements = testCon.getStatements(null, null, null, true); try { graph = new GraphImpl(vf, statements.asList()); } finally { statements.close(); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(baos); out.writeObject(graph); out.close(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); ObjectInputStream in = new ObjectInputStream(bais); Graph deserializedGraph = (Graph)in.readObject(); in.close(); assertFalse(deserializedGraph.isEmpty()); for (Statement st : deserializedGraph) { assertTrue(graph.contains(st)); assertTrue(testCon.hasStatement(st, true)); } }
public void testClear() throws Exception { testCon.add(bob, name, nameBob); assertTrue(testCon.hasStatement(null, name, nameBob, false)); testCon.clear(); assertFalse(testCon.hasStatement(null, name, nameBob, false)); }
public void testEmptyCommit() throws Exception { assertTrue(testCon.isEmpty()); assertTrue(testCon2.isEmpty()); testCon.setAutoCommit(false); testCon.add(vf.createBNode(), vf.createURI("urn:pred"), vf.createBNode()); assertFalse(testCon.isEmpty()); assertTrue(testCon2.isEmpty()); testCon.commit(); assertFalse(testCon.isEmpty()); assertFalse(testCon2.isEmpty()); }
@Test public void testSES713() throws Exception { String queryString = "SELECT * { ?sub ?pred ?obj . FILTER ( 'not a number' + 1 = ?obj )}"; TupleQuery query = testCon.prepareTupleQuery(QueryLanguage.SPARQL, queryString); TupleQueryResult tqr = query.evaluate(); try { assertFalse("Query should not return any results", tqr.hasNext()); } finally { tqr.close(); } }
public void testRemoveStatementCollection() throws Exception { testCon.setAutoCommit(false); testCon.add(alice, name, nameAlice); testCon.add(bob, name, nameBob); testCon.setAutoCommit(true); assertTrue(testCon.hasStatement(bob, name, nameBob, false)); assertTrue(testCon.hasStatement(alice, name, nameAlice, false)); Collection<Statement> c = Iterations.addAll(testCon.getStatements(null, null, null, false), new ArrayList<Statement>()); testCon.remove(c); assertFalse(testCon.hasStatement(bob, name, nameBob, false)); assertFalse(testCon.hasStatement(alice, name, nameAlice, false)); }
@Test public void testAddInputStream() throws Exception { // add file default-graph.ttl to repository, no context InputStream defaultGraph = RepositoryConnectionTest.class.getResourceAsStream(TEST_DIR_PREFIX + "default-graph.ttl"); testCon.add(defaultGraph, "", RDFFormat.TURTLE); defaultGraph.close(); assertTrue(NEWLY_ADDED, testCon.hasStatement(null, publisher, nameBob, false)); assertTrue(NEWLY_ADDED, testCon.hasStatement(null, publisher, nameAlice, false)); // add file graph1.ttl to context1 InputStream graph1 = RepositoryConnectionTest.class.getResourceAsStream(TEST_DIR_PREFIX + "graph1.ttl"); testCon.add(graph1, "", RDFFormat.TURTLE, context1); graph1.close(); // add file graph2.ttl to context2 InputStream graph2 = RepositoryConnectionTest.class.getResourceAsStream(TEST_DIR_PREFIX + "graph2.ttl"); testCon.add(graph2, "", RDFFormat.TURTLE, context2); graph2.close(); assertTrue("alice should be known in the store", testCon.hasStatement(null, name, nameAlice, false)); assertFalse("alice should not be known in context1", testCon.hasStatement(null, name, nameAlice, false, context1)); assertTrue("alice should be known in context2", testCon.hasStatement(null, name, nameAlice, false, context2)); assertTrue("bob should be known in the store", testCon.hasStatement(null, name, nameBob, false)); assertFalse("bob should not be known in context2", testCon.hasStatement(null, name, nameBob, false, context2)); assertTrue("bib should be known in context1", testCon.hasStatement(null, name, nameBob, false, context1)); }
public void testRollback() throws Exception { testCon.setAutoCommit(false); testCon.add(alice, name, nameAlice); assertTrue("Uncommitted updates should be visible to own connection", testCon.hasStatement(alice, name, nameAlice, false)); testCon.rollback(); assertFalse("Repository should not contain statement after rollback", testCon.hasStatement(alice, name, nameAlice, false)); testCon.setAutoCommit(true); }
@Test public void testRollback() throws Exception { testCon.begin(); testCon.add(alice, name, nameAlice); assertTrue("Uncommitted updates should be visible to own connection", testCon.hasStatement(alice, name, nameAlice, false)); testCon.rollback(); assertFalse("Repository should not contain statement after rollback", testCon.hasStatement(alice, name, nameAlice, false)); }
@Test public void testTransactionIsolationForRead() throws Exception { testCon.begin(); try { // Add but do not commit testCon.add(OWL.CLASS, RDFS.COMMENT, RDF.STATEMENT); assertTrue("Should be able to see uncommitted statement on same connection", testCon.hasStatement(OWL.CLASS, RDFS.COMMENT, RDF.STATEMENT, true)); assertFalse( "Should not be able to see uncommitted statement on separate connection outside transaction", testCon2.hasStatement(OWL.CLASS, RDFS.COMMENT, RDF.STATEMENT, true)); testCon2.begin(); try { assertFalse( "Should not be able to see uncommitted statement on separate connection inside transaction", testCon2.hasStatement(OWL.CLASS, RDFS.COMMENT, RDF.STATEMENT, true)); } finally { testCon2.rollback(); } } finally { testCon.rollback(); } }
public void testOpen() throws Exception { assertTrue(testCon.isOpen()); assertTrue(testCon2.isOpen()); testCon.close(); assertFalse(testCon.isOpen()); assertTrue(testCon2.isOpen()); }
public void testRemoveStatementIteration() throws Exception { testCon.setAutoCommit(false); testCon.add(alice, name, nameAlice); testCon.add(bob, name, nameBob); testCon.setAutoCommit(true); assertTrue(testCon.hasStatement(bob, name, nameBob, false)); assertTrue(testCon.hasStatement(alice, name, nameAlice, false)); CloseableIteration<? extends Statement, RepositoryException> iter = testCon.getStatements(null, null, null, false); try { testCon.remove(iter); } finally { iter.close(); } assertFalse(testCon.hasStatement(bob, name, nameBob, false)); assertFalse(testCon.hasStatement(alice, name, nameAlice, false)); }
public void testRemoveStatements() throws Exception { testCon.setAutoCommit(false); testCon.add(bob, name, nameBob); testCon.add(alice, name, nameAlice); testCon.setAutoCommit(true); assertTrue(testCon.hasStatement(bob, name, nameBob, false)); assertTrue(testCon.hasStatement(alice, name, nameAlice, false)); testCon.remove(bob, name, nameBob); assertFalse(testCon.hasStatement(bob, name, nameBob, false)); assertTrue(testCon.hasStatement(alice, name, nameAlice, false)); testCon.remove(alice, null, null); assertFalse(testCon.hasStatement(alice, name, nameAlice, false)); assertTrue(testCon.isEmpty()); }
public void testTransactionIsolation() throws Exception { testCon.setAutoCommit(false); testCon.add(bob, name, nameBob); assertTrue(testCon.hasStatement(bob, name, nameBob, false)); assertFalse(testCon2.hasStatement(bob, name, nameBob, false)); testCon.commit(); assertTrue(testCon.hasStatement(bob, name, nameBob, false)); assertTrue(testCon2.hasStatement(bob, name, nameBob, false)); }
public void testGetStatements() throws Exception { testCon.add(bob, name, nameBob); assertTrue("Repository should contain statement", testCon.hasStatement(bob, name, nameBob, false)); RepositoryResult<Statement> result = testCon.getStatements(null, name, null, false); try { assertTrue("Iterator should not be null", result != null); assertTrue("Iterator should not be empty", result.hasNext()); while (result.hasNext()) { Statement st = result.next(); assertTrue("Statement should not be in a context ", st.getContext() == null); assertTrue("Statement predicate should be equal to name ", st.getPredicate().equals(name)); } } finally { result.close(); } List<Statement> list = Iterations.addAll(testCon.getStatements(null, name, null, false), new ArrayList<Statement>()); assertTrue("List should not be null", list != null); assertFalse("List should not be empty", list.isEmpty()); }
@Test public void testSES713() throws Exception { String queryString = "SELECT * { ?sub ?pred ?obj . FILTER ( 'not a number' + 1 = ?obj )}"; TupleQuery query = testCon.prepareTupleQuery(QueryLanguage.SPARQL, queryString); TupleQueryResult tqr = query.evaluate(); try { assertFalse("Query should not return any results", tqr.hasNext()); } finally { tqr.close(); } }
@Test public void testGetStatements() throws Exception { testCon.add(bob, name, nameBob); assertTrue("Repository should contain statement", testCon.hasStatement(bob, name, nameBob, false)); RepositoryResult<Statement> result = testCon.getStatements(null, name, null, false); try { assertNotNull("Iterator should not be null", result); assertTrue("Iterator should not be empty", result.hasNext()); while (result.hasNext()) { Statement st = result.next(); assertNull("Statement should not be in a context ", st.getContext()); assertTrue("Statement predicate should be equal to name ", st.getPredicate().equals(name)); } } finally { result.close(); } List<Statement> list = Iterations.addAll(testCon.getStatements(null, name, null, false), new ArrayList<Statement>()); assertNotNull("List should not be null", list); assertFalse("List should not be empty", list.isEmpty()); }
@Test public void testRollback() throws Exception { testCon.begin(); testCon.add(alice, name, nameAlice); assertTrue("Uncommitted updates should be visible to own connection", testCon.hasStatement(alice, name, nameAlice, false)); testCon.rollback(); assertFalse("Repository should not contain statement after rollback", testCon.hasStatement(alice, name, nameAlice, false)); }
@Test public void testTransactionIsolationForRead() throws Exception { testCon.begin(); try { // Add but do not commit testCon.add(OWL.CLASS, RDFS.COMMENT, RDF.STATEMENT); assertTrue("Should be able to see uncommitted statement on same connection", testCon.hasStatement(OWL.CLASS, RDFS.COMMENT, RDF.STATEMENT, true)); assertFalse( "Should not be able to see uncommitted statement on separate connection outside transaction", testCon2.hasStatement(OWL.CLASS, RDFS.COMMENT, RDF.STATEMENT, true)); testCon2.begin(); try { assertFalse( "Should not be able to see uncommitted statement on separate connection inside transaction", testCon2.hasStatement(OWL.CLASS, RDFS.COMMENT, RDF.STATEMENT, true)); } finally { testCon2.rollback(); } } finally { testCon.rollback(); } }
public void testEmptyRollback() throws Exception { assertTrue(testCon.isEmpty()); assertTrue(testCon2.isEmpty()); testCon.setAutoCommit(false); testCon.add(vf.createBNode(), vf.createURI("urn:pred"), vf.createBNode()); assertFalse(testCon.isEmpty()); assertTrue(testCon2.isEmpty()); testCon.rollback(); assertTrue(testCon.isEmpty()); assertTrue(testCon2.isEmpty()); }
@Test public void testGetStatements() throws Exception { testCon.add(bob, name, nameBob); assertTrue("Repository should contain statement", testCon.hasStatement(bob, name, nameBob, false)); RepositoryResult<Statement> result = testCon.getStatements(null, name, null, false); try { assertNotNull("Iterator should not be null", result); assertTrue("Iterator should not be empty", result.hasNext()); while (result.hasNext()) { Statement st = result.next(); assertNull("Statement should not be in a context ", st.getContext()); assertTrue("Statement predicate should be equal to name ", st.getPredicate().equals(name)); } } finally { result.close(); } List<Statement> list = Iterations.addAll(testCon.getStatements(null, name, null, false), new ArrayList<Statement>()); assertNotNull("List should not be null", list); assertFalse("List should not be empty", list.isEmpty()); }