use of org.apache.jena.rdf.model.Statement in project jena by apache.
the class TestAddAndContains method testAddDuplicateLeavesSizeSame.
public void testAddDuplicateLeavesSizeSame() {
final Statement s = model.createStatement(S, RDF.value, "something");
model.add(s);
final long size = model.size();
model.add(s);
Assert.assertEquals(size, model.size());
}
use of org.apache.jena.rdf.model.Statement in project jena by apache.
the class TestAddAndContains method testAddContainLiteralByStatement.
public void testAddContainLiteralByStatement() {
final Literal L = model.createTypedLiteral(210);
final Statement s = model.createStatement(S, RDF.value, L);
Assert.assertTrue(model.add(s).contains(s));
Assert.assertTrue(model.contains(S, RDF.value));
}
use of org.apache.jena.rdf.model.Statement in project jena by apache.
the class TestOntTools method testPath.
// Internal implementation methods
//////////////////////////////////
private void testPath(OntTools.Path path, Property[] expected) {
assertEquals(expected.length, path.size());
int i = 0;
for (Statement aPath : path) {
assertEquals("path position: " + i, expected[i], aPath.getPredicate());
i++;
}
}
use of org.apache.jena.rdf.model.Statement in project jena by apache.
the class SecurityExample method main.
/**
* @param args
*/
public static void main(String[] args) {
String[] names = { "alice", "bob", "chuck", "darla" };
RDFNode msgType = ResourceFactory.createResource("http://example.com/msg");
Property pTo = ResourceFactory.createProperty("http://example.com/to");
Property pFrom = ResourceFactory.createProperty("http://example.com/from");
Property pSubj = ResourceFactory.createProperty("http://example.com/subj");
Model model = ModelFactory.createDefaultModel();
URL url = SecurityExample.class.getClassLoader().getResource("org/apache/jena/security/example/example.ttl");
model.read(url.toExternalForm());
ResIterator ri = model.listSubjectsWithProperty(RDF.type, msgType);
System.out.println("All the messages");
while (ri.hasNext()) {
Resource msg = ri.next();
Statement to = msg.getProperty(pTo);
Statement from = msg.getProperty(pFrom);
Statement subj = msg.getProperty(pSubj);
System.out.println(String.format("%s to: %s from: %s subj: %s", msg, to.getObject(), from.getObject(), subj.getObject()));
}
System.out.println();
ExampleEvaluator evaluator = new ExampleEvaluator(model);
model = Factory.getInstance(evaluator, "http://example.com/SecuredModel", model);
for (String userName : names) {
evaluator.setPrincipal(userName);
System.out.println("Messages " + userName + " can manipulate");
ri = model.listSubjectsWithProperty(RDF.type, msgType);
while (ri.hasNext()) {
Resource msg = ri.next();
Statement to = msg.getProperty(pTo);
Statement from = msg.getProperty(pFrom);
Statement subj = msg.getProperty(pSubj);
System.out.println(String.format("%s to: %s from: %s subj: %s", msg, to.getObject(), from.getObject(), subj.getObject()));
}
ri.close();
for (String name : names) {
System.out.println(String.format("%s messages to %s", model.listSubjectsWithProperty(pTo, name).toList().size(), name));
}
System.out.println();
}
}
use of org.apache.jena.rdf.model.Statement in project jena by apache.
the class TestConcurrentAccess method mrswGraph6.
@Test(expected = ConcurrentModificationException.class)
public void mrswGraph6() {
Dataset d = TDBFactory.createDataset();
Model m = d.getNamedModel("http://example");
GraphUtil.addInto(m.getGraph(), buildGraph());
Resource r = m.createResource("x");
ExtendedIterator<Statement> iter1 = m.listStatements(r, null, (RDFNode) null);
assertNotNull(iter1.next());
Triple t = SSE.parseTriple("(<y> <p> 99)");
m.getGraph().delete(t);
iter1.next();
}
Aggregations