Search in sources :

Example 1 with QueryResultParser

use of org.eclipse.rdf4j.query.resultio.QueryResultParser in project rdf4j by eclipse.

the class SPARQLXMLParserCustomTest method testEntityExpansionNoSecureProcessing.

/**
 * Test with Secure processing setting off.
 * <p>
 * IMPORTANT: Only turn this on to verify it is still working, as there is
 * no way to safely perform this test.
 * <p>
 * WARNING: This test will cause an OutOfMemoryException when it eventually
 * fails, as it will eventually fail.
 *
 * @throws Exception
 */
@Ignore
@Test(timeout = 10000)
public void testEntityExpansionNoSecureProcessing() throws Exception {
    QueryResultCollector handler = new QueryResultCollector();
    ParseErrorCollector errorCollector = new ParseErrorCollector();
    QueryResultParser aParser = QueryResultIO.createTupleParser(TupleQueryResultFormat.SPARQL).setQueryResultHandler(handler).set(XMLParserSettings.SECURE_PROCESSING, false).setParseErrorListener(errorCollector);
    try {
        // IMPORTANT: This will not use the entity limit
        aParser.parseQueryResult(this.getClass().getResourceAsStream("/sparqlxml/bad-entity-expansion-limit.srx"));
        fail("Parser did not throw an exception");
    } catch (QueryResultParseException e) {
    // assertTrue(e.getMessage().contains(
    // "The parser has encountered more than \"64,000\" entity
    // expansions in this document; this is the limit imposed by the"));
    }
    assertEquals(0, errorCollector.getWarnings().size());
    assertEquals(0, errorCollector.getErrors().size());
    assertEquals(1, errorCollector.getFatalErrors().size());
}
Also used : QueryResultParser(org.eclipse.rdf4j.query.resultio.QueryResultParser) QueryResultParseException(org.eclipse.rdf4j.query.resultio.QueryResultParseException) ParseErrorCollector(org.eclipse.rdf4j.rio.helpers.ParseErrorCollector) QueryResultCollector(org.eclipse.rdf4j.query.resultio.helpers.QueryResultCollector) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with QueryResultParser

use of org.eclipse.rdf4j.query.resultio.QueryResultParser in project rdf4j by eclipse.

the class SPARQLXMLParserCustomTest method testEntityExpansionUnrelatedSettings.

/**
 * Test with unrelated ParserConfig settings
 *
 * @throws Exception
 */
@Test
public void testEntityExpansionUnrelatedSettings() throws Exception {
    ParserConfig config = new ParserConfig();
    QueryResultCollector handler = new QueryResultCollector();
    ParseErrorCollector errorCollector = new ParseErrorCollector();
    QueryResultParser aParser = QueryResultIO.createTupleParser(TupleQueryResultFormat.SPARQL).setQueryResultHandler(handler).setParserConfig(config).setParseErrorListener(errorCollector);
    try {
        // this should trigger a SAX parse exception that will blow up at
        // the 64k entity limit rather than OOMing
        aParser.parseQueryResult(this.getClass().getResourceAsStream("/sparqlxml/bad-entity-expansion-limit.srx"));
        fail("Parser did not throw an exception");
    } catch (QueryResultParseException e) {
    // assertTrue(e.getMessage().contains(
    // "The parser has encountered more than \"64,000\" entity
    // expansions in this document; this is the limit imposed by the
    // "));
    }
    assertEquals(0, errorCollector.getWarnings().size());
    assertEquals(0, errorCollector.getErrors().size());
    assertEquals(1, errorCollector.getFatalErrors().size());
}
Also used : QueryResultParser(org.eclipse.rdf4j.query.resultio.QueryResultParser) QueryResultParseException(org.eclipse.rdf4j.query.resultio.QueryResultParseException) ParseErrorCollector(org.eclipse.rdf4j.rio.helpers.ParseErrorCollector) ParserConfig(org.eclipse.rdf4j.rio.ParserConfig) QueryResultCollector(org.eclipse.rdf4j.query.resultio.helpers.QueryResultCollector) Test(org.junit.Test)

Example 3 with QueryResultParser

use of org.eclipse.rdf4j.query.resultio.QueryResultParser in project rdf4j by eclipse.

the class SPARQLXMLParserCustomTest method testEntityExpansionDefaultSettings.

/**
 * Test with the default ParserConfig settings. Ie, setParserConfig is not
 * called.
 *
 * @throws Exception
 */
@Test
public void testEntityExpansionDefaultSettings() throws Exception {
    QueryResultCollector handler = new QueryResultCollector();
    ParseErrorCollector errorCollector = new ParseErrorCollector();
    QueryResultParser aParser = QueryResultIO.createTupleParser(TupleQueryResultFormat.SPARQL).setQueryResultHandler(handler).setParseErrorListener(errorCollector);
    try {
        // this should trigger a SAX parse exception that will blow up at
        // the 64k entity limit rather than OOMing
        aParser.parseQueryResult(this.getClass().getResourceAsStream("/sparqlxml/bad-entity-expansion-limit.srx"));
        fail("Parser did not throw an exception");
    } catch (QueryResultParseException e) {
    // assertTrue(e.getMessage().contains(
    // "The parser has encountered more than \"64,000\" entity
    // expansions in this document; this is the limit imposed by the
    // "));
    }
    assertEquals(0, errorCollector.getWarnings().size());
    assertEquals(0, errorCollector.getErrors().size());
    assertEquals(1, errorCollector.getFatalErrors().size());
}
Also used : QueryResultParser(org.eclipse.rdf4j.query.resultio.QueryResultParser) QueryResultParseException(org.eclipse.rdf4j.query.resultio.QueryResultParseException) ParseErrorCollector(org.eclipse.rdf4j.rio.helpers.ParseErrorCollector) QueryResultCollector(org.eclipse.rdf4j.query.resultio.helpers.QueryResultCollector) Test(org.junit.Test)

Example 4 with QueryResultParser

use of org.eclipse.rdf4j.query.resultio.QueryResultParser in project rdf4j by eclipse.

the class SPARQLXMLParserCustomTest method testEntityExpansionSecureProcessing.

/**
 * Test with Secure processing setting on.
 *
 * @throws Exception
 */
@Test
public void testEntityExpansionSecureProcessing() throws Exception {
    QueryResultCollector handler = new QueryResultCollector();
    ParseErrorCollector errorCollector = new ParseErrorCollector();
    QueryResultParser aParser = QueryResultIO.createTupleParser(TupleQueryResultFormat.SPARQL).setQueryResultHandler(handler).set(XMLParserSettings.SECURE_PROCESSING, true).setParseErrorListener(errorCollector);
    try {
        // this should trigger a SAX parse exception that will blow up at
        // the 64k entity limit rather than OOMing
        aParser.parseQueryResult(this.getClass().getResourceAsStream("/sparqlxml/bad-entity-expansion-limit.srx"));
        fail("Parser did not throw an exception");
    } catch (QueryResultParseException e) {
    // assertTrue(e.getMessage().contains(
    // "The parser has encountered more than \"64,000\" entity
    // expansions in this document; this is the limit imposed by the
    // "));
    }
    assertEquals(0, errorCollector.getWarnings().size());
    assertEquals(0, errorCollector.getErrors().size());
    assertEquals(1, errorCollector.getFatalErrors().size());
}
Also used : QueryResultParser(org.eclipse.rdf4j.query.resultio.QueryResultParser) QueryResultParseException(org.eclipse.rdf4j.query.resultio.QueryResultParseException) ParseErrorCollector(org.eclipse.rdf4j.rio.helpers.ParseErrorCollector) QueryResultCollector(org.eclipse.rdf4j.query.resultio.helpers.QueryResultCollector) Test(org.junit.Test)

Aggregations

QueryResultParseException (org.eclipse.rdf4j.query.resultio.QueryResultParseException)4 QueryResultParser (org.eclipse.rdf4j.query.resultio.QueryResultParser)4 QueryResultCollector (org.eclipse.rdf4j.query.resultio.helpers.QueryResultCollector)4 ParseErrorCollector (org.eclipse.rdf4j.rio.helpers.ParseErrorCollector)4 Test (org.junit.Test)4 ParserConfig (org.eclipse.rdf4j.rio.ParserConfig)1 Ignore (org.junit.Ignore)1