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"));
}
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());
}
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));
}
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
}
}
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));
}
Aggregations