@Test public void testAddMalformedLiteralsDefaultConfig() throws Exception { try { testCon.add( RepositoryConnectionTest.class.getResourceAsStream(TEST_DIR_PREFIX + "malformed-literals.ttl"), "", RDFFormat.TURTLE); fail("upload of malformed literals should fail with error in default configuration"); } catch (RDFParseException e) { // ignore, as expected } }
public void testRecoverFromParseError() throws RepositoryException, IOException { String invalidData = "bad"; String validData = "@prefix foo: <http://example.org/foo#>.\nfoo:a foo:b foo:c."; try { testCon.add(new StringReader(invalidData), "", RDFFormat.TURTLE); fail("Invalid data should result in an exception"); } catch (RDFParseException e) { // Expected behaviour } try { testCon.add(new StringReader(validData), "", RDFFormat.TURTLE); } catch (RDFParseException e) { fail("Valid data should not result in an exception"); } assertEquals("Repository contains incorrect number of statements", 1, testCon.size()); }
@Test public void testRecoverFromParseError() throws RepositoryException, IOException { String invalidData = "bad"; String validData = "@prefix foo: <http://example.org/foo#>.\nfoo:a foo:b foo:c."; try { testCon.add(new StringReader(invalidData), "", RDFFormat.TURTLE); fail("Invalid data should result in an exception"); } catch (RDFParseException e) { // Expected behaviour } try { testCon.add(new StringReader(validData), "", RDFFormat.TURTLE); } catch (RDFParseException e) { fail("Valid data should not result in an exception"); } assertEquals("Repository contains incorrect number of statements", 1, testCon.size()); }
@Test public void testAddMalformedLiteralsStrictConfig() throws Exception { Set<RioSetting<?>> empty = Collections.emptySet(); testCon.getParserConfig().setNonFatalErrors(empty); try { testCon.add( RepositoryConnectionTest.class.getResourceAsStream(TEST_DIR_PREFIX + "malformed-literals.ttl"), "", RDFFormat.TURTLE); fail("upload of malformed literals should fail with error in strict configuration"); } catch (RDFParseException e) { // ingnore, as expected. } }
@Test public void testAddMalformedLiteralsDefaultConfig() throws Exception { try { testCon.add( RepositoryConnectionTest.class.getResourceAsStream(TEST_DIR_PREFIX + "malformed-literals.ttl"), "", RDFFormat.TURTLE); fail("upload of malformed literals should fail with error in default configuration"); } catch (RDFParseException e) { // ignore, as expected } }
@Test public void testRecoverFromParseError() throws RepositoryException, IOException { String invalidData = "bad"; String validData = "@prefix foo: <http://example.org/foo#>.\nfoo:a foo:b foo:c."; try { testCon.add(new StringReader(invalidData), "", RDFFormat.TURTLE); fail("Invalid data should result in an exception"); } catch (RDFParseException e) { // Expected behaviour } try { testCon.add(new StringReader(validData), "", RDFFormat.TURTLE); } catch (RDFParseException e) { fail("Valid data should not result in an exception"); } assertEquals("Repository contains incorrect number of statements", 1, testCon.size()); }
@Test public void testAddMalformedLiteralsStrictConfig() throws Exception { Set<RioSetting<?>> empty = Collections.emptySet(); testCon.getParserConfig().setNonFatalErrors(empty); try { testCon.add( RepositoryConnectionTest.class.getResourceAsStream(TEST_DIR_PREFIX + "malformed-literals.ttl"), "", RDFFormat.TURTLE); fail("upload of malformed literals should fail with error in strict configuration"); } catch (RDFParseException e) { // ingnore, as expected. } }
@Test public void testOrderByQueriesAreInterruptable() throws Exception { testCon.begin(); for (int index = 0; index < 512; index++) { testCon.add(RDFS.CLASS, RDFS.COMMENT, testCon.getValueFactory().createBNode()); } testCon.commit(); final TupleQuery query = testCon.prepareTupleQuery(QueryLanguage.SPARQL, "SELECT * WHERE { ?s ?p ?o . ?s1 ?p1 ?o1 . ?s2 ?p2 ?o2 . ?s3 ?p3 ?o3 } ORDER BY ?s1 ?p1 ?o1 LIMIT 1000"); query.setMaxQueryTime(2); final TupleQueryResult result = query.evaluate(); final long startTime = System.currentTimeMillis(); try { result.hasNext(); fail("Query should have been interrupted"); } catch (QueryInterruptedException e) { // Expected final long duration = System.currentTimeMillis() - startTime; assertTrue("Query not interrupted quickly enough, should have been ~2s, but was " + (duration / 1000) + "s", duration < 5000); } }
@Test public void testGetStatementsMalformedTypedLiteral() throws Exception { Literal invalidIntegerLiteral = vf.createLiteral("the number four", XMLSchema.INTEGER); try { URI pred = vf.createURI(URN_PRED); testCon.add(bob, pred, invalidIntegerLiteral); RepositoryResult<Statement> statements = testCon.getStatements(bob, pred, null, true); assertNotNull(statements); assertTrue(statements.hasNext()); Statement st = statements.next(); assertTrue(st.getObject() instanceof Literal); assertTrue(st.getObject().equals(invalidIntegerLiteral)); } catch (RepositoryException e) { // shouldn't happen fail(e.getMessage()); } }
@Test public void testGetStatementsMalformedLanguageLiteral() throws Exception { Literal invalidLanguageLiteral = vf.createLiteral("the number four", "en_us"); try { URI pred = vf.createURI(URN_PRED); testCon.add(bob, pred, invalidLanguageLiteral); RepositoryResult<Statement> statements = testCon.getStatements(bob, pred, null, true); assertNotNull(statements); assertTrue(statements.hasNext()); Statement st = statements.next(); assertTrue(st.getObject() instanceof Literal); assertTrue(st.getObject().equals(invalidLanguageLiteral)); } catch (RepositoryException e) { e.printStackTrace(); // shouldn't happen fail(e.getMessage()); } }
@Test public void testOrderByQueriesAreInterruptable() throws Exception { testCon.begin(); for (int index = 0; index < 512; index++) { testCon.add(RDFS.CLASS, RDFS.COMMENT, testCon.getValueFactory().createBNode()); } testCon.commit(); final TupleQuery query = testCon.prepareTupleQuery(QueryLanguage.SPARQL, "SELECT * WHERE { ?s ?p ?o . ?s1 ?p1 ?o1 . ?s2 ?p2 ?o2 . ?s3 ?p3 ?o3 } ORDER BY ?s1 ?p1 ?o1 LIMIT 1000"); query.setMaxQueryTime(2); final TupleQueryResult result = query.evaluate(); final long startTime = System.currentTimeMillis(); try { result.hasNext(); fail("Query should have been interrupted"); } catch (QueryInterruptedException e) { // Expected final long duration = System.currentTimeMillis() - startTime; assertTrue("Query not interrupted quickly enough, should have been ~2s, but was " + (duration / 1000) + "s", duration < 5000); } }
@Test public void testGetStatementsMalformedTypedLiteral() throws Exception { Literal invalidIntegerLiteral = vf.createLiteral("the number four", XMLSchema.INTEGER); try { URI pred = vf.createURI(URN_PRED); testCon.add(bob, pred, invalidIntegerLiteral); RepositoryResult<Statement> statements = testCon.getStatements(bob, pred, null, true); assertNotNull(statements); assertTrue(statements.hasNext()); Statement st = statements.next(); assertTrue(st.getObject() instanceof Literal); assertTrue(st.getObject().equals(invalidIntegerLiteral)); } catch (RepositoryException e) { // shouldn't happen fail(e.getMessage()); } }
@Test public void testGetStatementsMalformedLanguageLiteral() throws Exception { Literal invalidLanguageLiteral = vf.createLiteral("the number four", "en_us"); try { URI pred = vf.createURI(URN_PRED); testCon.add(bob, pred, invalidLanguageLiteral); RepositoryResult<Statement> statements = testCon.getStatements(bob, pred, null, true); assertNotNull(statements); assertTrue(statements.hasNext()); Statement st = statements.next(); assertTrue(st.getObject() instanceof Literal); assertTrue(st.getObject().equals(invalidLanguageLiteral)); } catch (RepositoryException e) { e.printStackTrace(); // shouldn't happen fail(e.getMessage()); } }