use of org.apache.jena.assembler.JA.MemoryModel in project jena by apache.
the class TestInMemDatasetAssembler method directDataLinkForDefaultAndNamedGraphs.
@Test
public void directDataLinkForDefaultAndNamedGraphs() throws IOException {
// first make a file of triples to load later
final Model model = createDefaultModel();
final Path triples = createTempFile("simpleExample", ".nt");
final Resource triplesURI = model.createResource(triples.toFile().toURI().toString());
final Resource simpleExample = model.createResource("test:simpleExample");
simpleExample.addProperty(type, DatasetAssemblerVocab.tDatasetTxnMem);
// add a default graph
simpleExample.addProperty(data, triplesURI);
// add a named graph
final Resource namedGraphDef = model.createResource("test:namedGraphDef");
simpleExample.addProperty(pNamedGraph, namedGraphDef);
final Resource namedGraphName = model.createResource("test:namedGraphExample");
namedGraphDef.addProperty(type, MemoryModel);
namedGraphDef.addProperty(pGraphName, namedGraphName);
namedGraphDef.addProperty(data, triplesURI);
try (OutputStream out = new FileOutputStream(triples.toFile())) {
write(out, model, NTRIPLES);
}
final Dataset dataset = assemble(simpleExample);
final Model assembledDefaultModel = dataset.getDefaultModel();
final Model assembledNamedModel = dataset.getNamedModel(namedGraphName.getURI());
// we put the same triples in each model, so we check for the same triples in each model
for (final Model m : new Model[] { assembledDefaultModel, assembledNamedModel }) {
assertTrue(m.contains(simpleExample, pNamedGraph, namedGraphDef));
assertTrue(m.contains(namedGraphDef, pGraphName, namedGraphName));
assertTrue(m.contains(simpleExample, data, triplesURI));
}
final Iterator<Node> graphNodes = dataset.asDatasetGraph().listGraphNodes();
assertTrue(graphNodes.hasNext());
assertEquals(namedGraphName.asNode(), graphNodes.next());
assertFalse(graphNodes.hasNext());
}
Aggregations