Search in sources :

Example 21 with LinkedHashModel

use of org.eclipse.rdf4j.model.impl.LinkedHashModel in project rdf4j by eclipse.

the class RDFXMLParserCustomTest method testEntityExpansionDefaultSettings.

/**
 * Test with the default ParserConfig settings. Ie, setParserConfig is not called.
 *
 * @throws Exception
 */
@Test
public void testEntityExpansionDefaultSettings() throws Exception {
    final Model aGraph = new LinkedHashModel();
    ParseErrorCollector errorCollector = new ParseErrorCollector();
    RDFParser aParser = Rio.createParser(RDFFormat.RDFXML).setRDFHandler(new StatementCollector(aGraph)).setParseErrorListener(errorCollector);
    try {
        // this should trigger a SAX parse exception that will blow up at the
        // 64k entity limit rather than OOMing
        aParser.parse(this.getClass().getResourceAsStream("/testcases/rdfxml/openrdf/bad-entity-expansion-limit.rdf"), "http://example.org");
        fail("Parser did not throw an exception");
    } catch (RDFParseException 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 : StatementCollector(org.eclipse.rdf4j.rio.helpers.StatementCollector) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) Model(org.eclipse.rdf4j.model.Model) ParseErrorCollector(org.eclipse.rdf4j.rio.helpers.ParseErrorCollector) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) RDFParser(org.eclipse.rdf4j.rio.RDFParser) RDFParseException(org.eclipse.rdf4j.rio.RDFParseException) Test(org.junit.Test)

Example 22 with LinkedHashModel

use of org.eclipse.rdf4j.model.impl.LinkedHashModel in project rdf4j by eclipse.

the class RDFXMLParserCustomTest method testEntityExpansionUnrelatedSettings.

/**
 * Test with unrelated ParserConfig settings
 *
 * @throws Exception
 */
@Test
public void testEntityExpansionUnrelatedSettings() throws Exception {
    final Model aGraph = new LinkedHashModel();
    ParseErrorCollector errorCollector = new ParseErrorCollector();
    ParserConfig config = new ParserConfig();
    RDFParser aParser = Rio.createParser(RDFFormat.RDFXML).setRDFHandler(new StatementCollector(aGraph)).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.parse(this.getClass().getResourceAsStream("/testcases/rdfxml/openrdf/bad-entity-expansion-limit.rdf"), "http://example.org");
        fail("Parser did not throw an exception");
    } catch (RDFParseException 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 : StatementCollector(org.eclipse.rdf4j.rio.helpers.StatementCollector) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) Model(org.eclipse.rdf4j.model.Model) ParseErrorCollector(org.eclipse.rdf4j.rio.helpers.ParseErrorCollector) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) RDFParser(org.eclipse.rdf4j.rio.RDFParser) ParserConfig(org.eclipse.rdf4j.rio.ParserConfig) RDFParseException(org.eclipse.rdf4j.rio.RDFParseException) Test(org.junit.Test)

Example 23 with LinkedHashModel

use of org.eclipse.rdf4j.model.impl.LinkedHashModel in project rdf4j by eclipse.

the class RDFXMLParserCustomTest method testEntityExpansionSecureProcessing.

/**
 * Test with Secure processing setting on.
 *
 * @throws Exception
 */
@Test
public void testEntityExpansionSecureProcessing() throws Exception {
    final Model aGraph = new LinkedHashModel();
    ParseErrorCollector errorCollector = new ParseErrorCollector();
    RDFParser aParser = Rio.createParser(RDFFormat.RDFXML).setRDFHandler(new StatementCollector(aGraph)).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.parse(this.getClass().getResourceAsStream("/testcases/rdfxml/openrdf/bad-entity-expansion-limit.rdf"), "http://example.org");
        fail("Parser did not throw an exception");
    } catch (RDFParseException 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 : StatementCollector(org.eclipse.rdf4j.rio.helpers.StatementCollector) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) Model(org.eclipse.rdf4j.model.Model) ParseErrorCollector(org.eclipse.rdf4j.rio.helpers.ParseErrorCollector) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) RDFParser(org.eclipse.rdf4j.rio.RDFParser) RDFParseException(org.eclipse.rdf4j.rio.RDFParseException) Test(org.junit.Test)

Example 24 with LinkedHashModel

use of org.eclipse.rdf4j.model.impl.LinkedHashModel in project rdf4j by eclipse.

the class JSONLDWriterTest method testRoundTripNamespaces.

@Test
public void testRoundTripNamespaces() throws Exception {
    String exNs = "http://example.org/";
    IRI uri1 = vf.createIRI(exNs, "uri1");
    IRI uri2 = vf.createIRI(exNs, "uri2");
    Literal plainLit = vf.createLiteral("plain", XMLSchema.STRING);
    Statement st1 = vf.createStatement(uri1, uri2, plainLit);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    RDFWriter rdfWriter = rdfWriterFactory.getWriter(out);
    rdfWriter.getWriterConfig().set(JSONLDSettings.JSONLD_MODE, JSONLDMode.COMPACT);
    rdfWriter.handleNamespace("ex", exNs);
    rdfWriter.startRDF();
    rdfWriter.handleStatement(st1);
    rdfWriter.endRDF();
    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    RDFParser rdfParser = rdfParserFactory.getParser();
    ParserConfig config = new ParserConfig();
    config.set(BasicParserSettings.FAIL_ON_UNKNOWN_DATATYPES, true);
    config.set(BasicParserSettings.FAIL_ON_UNKNOWN_LANGUAGES, true);
    rdfParser.setParserConfig(config);
    rdfParser.setValueFactory(vf);
    Model model = new LinkedHashModel();
    rdfParser.setRDFHandler(new StatementCollector(model));
    rdfParser.parse(in, "foo:bar");
    assertEquals("Unexpected number of statements, found " + model.size(), 1, model.size());
    assertTrue("missing namespaced statement", model.contains(st1));
    if (rdfParser.getRDFFormat().supportsNamespaces()) {
        assertTrue("Expected at least one namespace, found " + model.getNamespaces().size(), model.getNamespaces().size() >= 1);
        assertEquals(exNs, model.getNamespace("ex").get().getName());
    }
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) ByteArrayInputStream(java.io.ByteArrayInputStream) Statement(org.eclipse.rdf4j.model.Statement) StatementCollector(org.eclipse.rdf4j.rio.helpers.StatementCollector) Literal(org.eclipse.rdf4j.model.Literal) Model(org.eclipse.rdf4j.model.Model) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) RDFWriter(org.eclipse.rdf4j.rio.RDFWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) RDFParser(org.eclipse.rdf4j.rio.RDFParser) ParserConfig(org.eclipse.rdf4j.rio.ParserConfig) RDFWriterTest(org.eclipse.rdf4j.rio.RDFWriterTest) Test(org.junit.Test)

Example 25 with LinkedHashModel

use of org.eclipse.rdf4j.model.impl.LinkedHashModel in project rdf4j by eclipse.

the class LinkedHashModelWithValueFactoryTest method makeEmptyModel.

public Model makeEmptyModel() {
    LinkedHashModel model = new LinkedHashModel();
    model.getValueFactory();
    return model;
}
Also used : LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel)

Aggregations

LinkedHashModel (org.eclipse.rdf4j.model.impl.LinkedHashModel)30 Model (org.eclipse.rdf4j.model.Model)23 StatementCollector (org.eclipse.rdf4j.rio.helpers.StatementCollector)11 Test (org.junit.Test)11 RDFParser (org.eclipse.rdf4j.rio.RDFParser)7 ParseErrorCollector (org.eclipse.rdf4j.rio.helpers.ParseErrorCollector)7 ParserConfig (org.eclipse.rdf4j.rio.ParserConfig)6 Statement (org.eclipse.rdf4j.model.Statement)5 RDFParseException (org.eclipse.rdf4j.rio.RDFParseException)5 Literal (org.eclipse.rdf4j.model.Literal)4 Before (org.junit.Before)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 IOException (java.io.IOException)3 IRI (org.eclipse.rdf4j.model.IRI)3 Resource (org.eclipse.rdf4j.model.Resource)3 RDF4JProtocolSession (org.eclipse.rdf4j.http.client.RDF4JProtocolSession)2 UnauthorizedException (org.eclipse.rdf4j.http.protocol.UnauthorizedException)2 SimpleValueFactory (org.eclipse.rdf4j.model.impl.SimpleValueFactory)2 QueryEvaluationException (org.eclipse.rdf4j.query.QueryEvaluationException)2