Search in sources :

Example 11 with QueryResultCollector

use of org.eclipse.rdf4j.query.resultio.helpers.QueryResultCollector in project rdf4j by eclipse.

the class SPARQLJSONTupleTest method testNonStandardDistinct.

@Test
public void testNonStandardDistinct() throws Exception {
    SPARQLResultsJSONParser parser = new SPARQLResultsJSONParser(SimpleValueFactory.getInstance());
    QueryResultCollector handler = new QueryResultCollector();
    parser.setQueryResultHandler(handler);
    InputStream stream = this.getClass().getResourceAsStream("/sparqljson/non-standard-distinct.srj");
    assertNotNull("Could not find test resource", stream);
    parser.parseQueryResult(stream);
    // there must be 1 variable
    assertEquals(1, handler.getBindingNames().size());
    // first must be called "Concept", etc.,
    assertEquals("Concept", handler.getBindingNames().get(0));
    // -1 results
    assertEquals(100, handler.getBindingSets().size());
}
Also used : SPARQLResultsJSONParser(org.eclipse.rdf4j.query.resultio.sparqljson.SPARQLResultsJSONParser) InputStream(java.io.InputStream) QueryResultCollector(org.eclipse.rdf4j.query.resultio.helpers.QueryResultCollector) AbstractQueryResultIOTupleTest(org.eclipse.rdf4j.query.resultio.AbstractQueryResultIOTupleTest) Test(org.junit.Test)

Example 12 with QueryResultCollector

use of org.eclipse.rdf4j.query.resultio.helpers.QueryResultCollector in project rdf4j by eclipse.

the class SPARQLJSONTupleTest method testBindings1.

@Test
public void testBindings1() throws Exception {
    SPARQLResultsJSONParser parser = new SPARQLResultsJSONParser(SimpleValueFactory.getInstance());
    QueryResultCollector handler = new QueryResultCollector();
    parser.setQueryResultHandler(handler);
    InputStream stream = this.getClass().getResourceAsStream("/sparqljson/bindings1.srj");
    assertNotNull("Could not find test resource", stream);
    parser.parseQueryResult(stream);
    // there must be two variables
    assertEquals(2, handler.getBindingNames().size());
    // first must be called "book", the second "title"
    assertEquals("book", handler.getBindingNames().get(0));
    assertEquals("title", handler.getBindingNames().get(1));
    // should be 7 solutions alltogether
    assertEquals(7, handler.getBindingSets().size());
    // Results are ordered, so first should be book6
    assertEquals("http://example.org/book/book6", handler.getBindingSets().get(0).getValue("book").stringValue());
    for (BindingSet b : handler.getBindingSets()) {
        assertNotNull(b.getValue("book"));
        assertNotNull(b.getValue("title"));
        assertTrue(b.getValue("book") instanceof IRI);
        assertTrue(b.getValue("title") instanceof Literal);
        IRI book = (IRI) b.getValue("book");
        if (book.stringValue().equals("http://example.org/book/book6")) {
            assertEquals("Harry Potter and the Half-Blood Prince", b.getValue("title").stringValue());
        } else if (book.stringValue().equals("http://example.org/book/book7")) {
            assertEquals("Harry Potter and the Deathly Hallows", b.getValue("title").stringValue());
        } else if (book.stringValue().equals("http://example.org/book/book5")) {
            assertEquals("Harry Potter and the Order of the Phoenix", b.getValue("title").stringValue());
        } else if (book.stringValue().equals("http://example.org/book/book4")) {
            assertEquals("Harry Potter and the Goblet of Fire", b.getValue("title").stringValue());
        } else if (book.stringValue().equals("http://example.org/book/book2")) {
            assertEquals("Harry Potter and the Chamber of Secrets", b.getValue("title").stringValue());
        } else if (book.stringValue().equals("http://example.org/book/book3")) {
            assertEquals("Harry Potter and the Prisoner Of Azkaban", b.getValue("title").stringValue());
        } else if (book.stringValue().equals("http://example.org/book/book1")) {
            assertEquals("Harry Potter and the Philosopher's Stone", b.getValue("title").stringValue());
        } else {
            fail("Found unexpected binding set in result: " + b.toString());
        }
    }
}
Also used : BindingSet(org.eclipse.rdf4j.query.BindingSet) IRI(org.eclipse.rdf4j.model.IRI) SPARQLResultsJSONParser(org.eclipse.rdf4j.query.resultio.sparqljson.SPARQLResultsJSONParser) InputStream(java.io.InputStream) Literal(org.eclipse.rdf4j.model.Literal) QueryResultCollector(org.eclipse.rdf4j.query.resultio.helpers.QueryResultCollector) AbstractQueryResultIOTupleTest(org.eclipse.rdf4j.query.resultio.AbstractQueryResultIOTupleTest) Test(org.junit.Test)

Example 13 with QueryResultCollector

use of org.eclipse.rdf4j.query.resultio.helpers.QueryResultCollector 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 14 with QueryResultCollector

use of org.eclipse.rdf4j.query.resultio.helpers.QueryResultCollector 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 15 with QueryResultCollector

use of org.eclipse.rdf4j.query.resultio.helpers.QueryResultCollector 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

QueryResultCollector (org.eclipse.rdf4j.query.resultio.helpers.QueryResultCollector)20 Test (org.junit.Test)18 InputStream (java.io.InputStream)10 AbstractQueryResultIOTupleTest (org.eclipse.rdf4j.query.resultio.AbstractQueryResultIOTupleTest)10 SPARQLResultsJSONParser (org.eclipse.rdf4j.query.resultio.sparqljson.SPARQLResultsJSONParser)10 QueryResultParseException (org.eclipse.rdf4j.query.resultio.QueryResultParseException)5 IRI (org.eclipse.rdf4j.model.IRI)4 Literal (org.eclipse.rdf4j.model.Literal)4 BindingSet (org.eclipse.rdf4j.query.BindingSet)4 AbstractQueryResultIOBooleanTest (org.eclipse.rdf4j.query.resultio.AbstractQueryResultIOBooleanTest)4 QueryResultParser (org.eclipse.rdf4j.query.resultio.QueryResultParser)4 SPARQLBooleanJSONParser (org.eclipse.rdf4j.query.resultio.sparqljson.SPARQLBooleanJSONParser)4 ParseErrorCollector (org.eclipse.rdf4j.rio.helpers.ParseErrorCollector)4 BNode (org.eclipse.rdf4j.model.BNode)2 HttpResponse (org.apache.http.HttpResponse)1 QueryResultHandlerException (org.eclipse.rdf4j.query.QueryResultHandlerException)1 TupleQueryResultHandlerException (org.eclipse.rdf4j.query.TupleQueryResultHandlerException)1 BooleanQueryResultFormat (org.eclipse.rdf4j.query.resultio.BooleanQueryResultFormat)1 BooleanQueryResultParser (org.eclipse.rdf4j.query.resultio.BooleanQueryResultParser)1 QueryResultFormat (org.eclipse.rdf4j.query.resultio.QueryResultFormat)1