@Test public void testWrongUnicodeEncodedCharFail() throws RDFHandlerException, IOException, RDFParseException { final ByteArrayInputStream bais = new ByteArrayInputStream( "<http://s> <http://p> \"\\u123X\" <http://g> .".getBytes()); try { parser.parse(bais, "http://test.base.uri"); Assert.fail("Expected exception when an incorrect unicode character is included"); } catch (RDFParseException rdfpe) { Assert.assertEquals(1, rdfpe.getLineNumber()); // FIXME: Enable column numbers when parser supports them // Assert.assertEquals(30, rdfpe.getColumnNumber()); } }
/** * Tests the behaviour with non-whitespace characters after a period * character without a context. * * @throws RDFHandlerException * @throws IOException * @throws RDFParseException */ @Test public void testNonWhitespaceAfterPeriodNoContext() throws RDFHandlerException, IOException, RDFParseException { final ByteArrayInputStream bais = new ByteArrayInputStream( "<http://www.wrong.com> <http://wrong.com/1.1/tt> \"x\"^^<http://xxx.net/int> . <http://path.to.graph> ".getBytes()); try { parser.parse(bais, "http://base-uri"); Assert.fail("Expected exception when there is non-whitespace characters after a period."); } catch (RDFParseException rdfpe) { Assert.assertEquals(1, rdfpe.getLineNumber()); // FIXME: Enable column numbers when parser supports them // Assert.assertEquals(44, rdfpe.getColumnNumber()); } }
/** * Tests the behaviour with non-whitespace characters after a period * character without a context. * * @throws RDFHandlerException * @throws IOException * @throws RDFParseException */ @Test public void testNonWhitespaceAfterPeriodWithContext() throws RDFHandlerException, IOException, RDFParseException { final ByteArrayInputStream bais = new ByteArrayInputStream( "<http://www.wrong.com> <http://wrong.com/1.1/tt> \"x\"^^<http://xxx.net/int> <http://path.to.graph> . <thisisnotlegal> ".getBytes()); try { parser.parse(bais, "http://base-uri"); Assert.fail("Expected exception when there is non-whitespace characters after a period."); } catch (RDFParseException rdfpe) { Assert.assertEquals(1, rdfpe.getLineNumber()); // FIXME: Enable column numbers when parser supports them // Assert.assertEquals(44, rdfpe.getColumnNumber()); } }
@Test public void testStopAtFirstErrorStrictParsing() throws RDFHandlerException, IOException, RDFParseException { final ByteArrayInputStream bais = new ByteArrayInputStream( ("<http://s0> <http://p0> <http://o0> <http://g0> .\n" + "<http://sX> .\n" + // Line // with // error. "<http://s1> <http://p1> <http://o1> <http://g1> .\n").getBytes()); parser.getParserConfig().set(NTriplesParserSettings.FAIL_ON_NTRIPLES_INVALID_LINES, false); try { parser.parse(bais, "http://test.base.uri"); Assert.fail("Expected exception when encountering an invalid line"); } catch (RDFParseException rdfpe) { Assert.assertEquals(2, rdfpe.getLineNumber()); // Assert.assertEquals(50, rdfpe.getColumnNumber()); } }
/** * Tests N-Quads parsing with literal and datatype using a prefix, which is * illegal in NQuads, but legal in N3/Turtle that may otherwise look like * NQuads */ @Test public void testParseBasicLiteralDatatypePrefix() throws RDFHandlerException, IOException { final ByteArrayInputStream bais = new ByteArrayInputStream( ("<http://www.v/dat/4b2-21> " + "<http://www.w3.org/20/ica#dtend> " + "\"2010\"^^xsd:integer " + "<http://sin.siteserv.org/def/>.").getBytes()); final TestRDFHandler rdfHandler = new TestRDFHandler(); parser.setRDFHandler(rdfHandler); try { parser.parse(bais, "http://test.base.uri"); Assert.fail("Expected exception when passing in a datatype using an N3 style prefix"); } catch (RDFParseException rdfpe) { Assert.assertEquals(1, rdfpe.getLineNumber()); // FIXME: Enable column numbers when parser supports them // Assert.assertEquals(69, rdfpe.getColumnNumber()); } }
logger.warn("Could not load {} {}", url, e.getMessage()); String msg = e.getMessage() + " in " + url; throw new RDFParseException(msg, e.getLineNumber(), e.getColumnNumber()); } catch (IOException e) { logger.warn("Could not load {} {}", url, e.getMessage());
logger.warn("Could not load {} {}", url, e.getMessage()); String msg = e.getMessage() + " in " + url; throw new RDFParseException(msg, e.getLineNumber(), e.getColumnNumber()); } catch (IOException e) { logger.warn("Could not load {} {}", url, e.getMessage());
@Test public void testExceptionHandlingWithDefaultSettings() throws Exception { String data = "invalid nt"; RDFParser ntriplesParser = createRDFParser(); ntriplesParser.setDatatypeHandling(RDFParser.DatatypeHandling.IGNORE); Model model = new LinkedHashModel(); ntriplesParser.setRDFHandler(new StatementCollector(model)); try { ntriplesParser.parse(new StringReader(data), NTRIPLES_TEST_URL); fail("expected RDFParseException due to invalid data"); } catch (RDFParseException expected) { assertEquals(expected.getLineNumber(), 1); } }
@Test public void testExceptionHandlingWithStopAtFirstError() throws Exception { String data = "invalid nt"; RDFParser ntriplesParser = createRDFParser(); ntriplesParser.getParserConfig().set(NTriplesParserSettings.FAIL_ON_NTRIPLES_INVALID_LINES, Boolean.FALSE); Model model = new LinkedHashModel(); ntriplesParser.setRDFHandler(new StatementCollector(model)); try { ntriplesParser.parse(new StringReader(data), NTRIPLES_TEST_URL); fail("expected RDFParseException due to invalid data"); } catch (RDFParseException expected) { assertEquals(expected.getLineNumber(), 1); } }