Search in sources :

Example 6 with TreeModel

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

the class LocalRepositoryManagerTest method testAddToSystemRepository.

@Test
public void testAddToSystemRepository() {
    RepositoryConfig config = manager.getRepositoryConfig(TEST_REPO);
    manager.addRepositoryConfig(new RepositoryConfig(SystemRepository.ID, new SystemRepositoryConfig()));
    manager.shutDown();
    manager = new LocalRepositoryManager(datadir);
    manager.initialize();
    try (RepositoryConnection con = manager.getSystemRepository().getConnection()) {
        Model model = new TreeModel();
        config.setID("changed");
        config.export(model, con.getValueFactory().createBNode());
        con.begin();
        con.add(model, con.getValueFactory().createBNode());
        con.commit();
    }
    assertTrue(manager.hasRepositoryConfig("changed"));
}
Also used : SailRepositoryConfig(org.eclipse.rdf4j.repository.sail.config.SailRepositoryConfig) ProxyRepositoryConfig(org.eclipse.rdf4j.repository.sail.config.ProxyRepositoryConfig) RepositoryConfig(org.eclipse.rdf4j.repository.config.RepositoryConfig) RepositoryConnection(org.eclipse.rdf4j.repository.RepositoryConnection) TreeModel(org.eclipse.rdf4j.model.impl.TreeModel) Model(org.eclipse.rdf4j.model.Model) TreeModel(org.eclipse.rdf4j.model.impl.TreeModel) Test(org.junit.Test)

Example 7 with TreeModel

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

the class LocalRepositoryManagerTest method testModifySystemRepository.

@Test
public void testModifySystemRepository() {
    RepositoryConfig config = manager.getRepositoryConfig(TEST_REPO);
    manager.addRepositoryConfig(new RepositoryConfig(SystemRepository.ID, new SystemRepositoryConfig()));
    manager.shutDown();
    manager = new LocalRepositoryManager(datadir);
    manager.initialize();
    try (RepositoryConnection con = manager.getSystemRepository().getConnection()) {
        Model model = new TreeModel();
        config.setTitle("Changed");
        config.export(model, con.getValueFactory().createBNode());
        Resource ctx = RepositoryConfigUtil.getContext(con, config.getID());
        con.begin();
        con.clear(ctx);
        con.add(model, ctx == null ? con.getValueFactory().createBNode() : ctx);
        con.commit();
    }
    assertEquals("Changed", manager.getRepositoryConfig(TEST_REPO).getTitle());
}
Also used : SailRepositoryConfig(org.eclipse.rdf4j.repository.sail.config.SailRepositoryConfig) ProxyRepositoryConfig(org.eclipse.rdf4j.repository.sail.config.ProxyRepositoryConfig) RepositoryConfig(org.eclipse.rdf4j.repository.config.RepositoryConfig) RepositoryConnection(org.eclipse.rdf4j.repository.RepositoryConnection) TreeModel(org.eclipse.rdf4j.model.impl.TreeModel) Model(org.eclipse.rdf4j.model.Model) TreeModel(org.eclipse.rdf4j.model.impl.TreeModel) Resource(org.eclipse.rdf4j.model.Resource) Test(org.junit.Test)

Example 8 with TreeModel

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

the class RDFCollectionsTest method testConversionRoundtrip.

@Test
public void testConversionRoundtrip() {
    IRI head = vf.createIRI("urn:head");
    Model m = RDFCollections.asRDF(values, head, new TreeModel());
    assertNotNull(m);
    assertTrue(m.contains(head, RDF.FIRST, a));
    assertFalse(m.contains(null, RDF.REST, head));
    List<Value> newList = RDFCollections.asValues(m, head, new ArrayList<Value>());
    assertNotNull(newList);
    assertTrue(newList.contains(a));
    assertTrue(newList.contains(b));
    assertTrue(newList.contains(c));
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) TreeModel(org.eclipse.rdf4j.model.impl.TreeModel) Model(org.eclipse.rdf4j.model.Model) TreeModel(org.eclipse.rdf4j.model.impl.TreeModel) Value(org.eclipse.rdf4j.model.Value) Test(org.junit.Test)

Example 9 with TreeModel

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

the class RDFCollectionsTest method testNonWellformedCollection.

@Test
public void testNonWellformedCollection() {
    Resource head = vf.createBNode();
    Model m = RDFCollections.asRDF(values, head, new TreeModel());
    m.remove(null, RDF.REST, RDF.NIL);
    try {
        RDFCollections.asValues(m, head, new ArrayList<Value>());
        fail("collection missing terminator should result in error");
    } catch (ModelException e) {
    // fall through, expected
    }
    m = RDFCollections.asRDF(values, head, new TreeModel());
    m.add(head, RDF.REST, head);
    try {
        RDFCollections.asValues(m, head, new ArrayList<Value>());
        fail("collection with cycle should result in error");
    } catch (ModelException e) {
    // fall through, expected
    }
    // supply incorrect head node
    try {
        RDFCollections.asValues(m, vf.createBNode(), new ArrayList<Value>());
        fail("resource that is not a collection should result in error");
    } catch (ModelException e) {
    // fall through, expected
    }
}
Also used : TreeModel(org.eclipse.rdf4j.model.impl.TreeModel) Resource(org.eclipse.rdf4j.model.Resource) Model(org.eclipse.rdf4j.model.Model) TreeModel(org.eclipse.rdf4j.model.impl.TreeModel) Value(org.eclipse.rdf4j.model.Value) Test(org.junit.Test)

Example 10 with TreeModel

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

the class RDFCollectionsTest method testExtract.

@Test
public void testExtract() {
    Resource head = vf.createBNode();
    Model m = RDFCollections.asRDF(values, head, new TreeModel());
    // add something to the model that is not part of the RDF collection.
    m.add(RDF.TYPE, RDF.TYPE, RDF.PROPERTY);
    Model collection = RDFCollections.getCollection(m, head, new TreeModel());
    assertNotNull(collection);
    assertFalse(collection.contains(RDF.TYPE, RDF.TYPE, RDF.PROPERTY));
    assertTrue(collection.contains(null, RDF.FIRST, a));
    assertTrue(collection.contains(null, RDF.FIRST, b));
    assertTrue(collection.contains(null, RDF.FIRST, c));
}
Also used : TreeModel(org.eclipse.rdf4j.model.impl.TreeModel) Resource(org.eclipse.rdf4j.model.Resource) Model(org.eclipse.rdf4j.model.Model) TreeModel(org.eclipse.rdf4j.model.impl.TreeModel) Test(org.junit.Test)

Aggregations

Model (org.eclipse.rdf4j.model.Model)11 TreeModel (org.eclipse.rdf4j.model.impl.TreeModel)11 Test (org.junit.Test)9 Resource (org.eclipse.rdf4j.model.Resource)5 RepositoryConnection (org.eclipse.rdf4j.repository.RepositoryConnection)3 RepositoryConfig (org.eclipse.rdf4j.repository.config.RepositoryConfig)3 ProxyRepositoryConfig (org.eclipse.rdf4j.repository.sail.config.ProxyRepositoryConfig)3 SailRepositoryConfig (org.eclipse.rdf4j.repository.sail.config.SailRepositoryConfig)3 Value (org.eclipse.rdf4j.model.Value)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 URISyntaxException (java.net.URISyntaxException)1 IRI (org.eclipse.rdf4j.model.IRI)1 RepositoryConfigException (org.eclipse.rdf4j.repository.config.RepositoryConfigException)1 RDFHandlerException (org.eclipse.rdf4j.rio.RDFHandlerException)1 UnsupportedRDFormatException (org.eclipse.rdf4j.rio.UnsupportedRDFormatException)1