use of org.apache.jena.rdf.model.Literal in project jena by apache.
the class TestLiterals method testLong.
protected void testLong(final Model model, final long tv) {
final Literal l = model.createTypedLiteral(tv);
try {
Assert.assertEquals(tv, l.getByte());
assertInRange(Byte.MIN_VALUE, tv, Byte.MAX_VALUE);
} catch (final IllegalArgumentException e) {
assertOutsideRange(Byte.MIN_VALUE, tv, Byte.MAX_VALUE);
}
try {
Assert.assertEquals(tv, l.getShort());
assertInRange(Short.MIN_VALUE, tv, Short.MAX_VALUE);
} catch (final IllegalArgumentException e) {
assertOutsideRange(Short.MIN_VALUE, tv, Short.MAX_VALUE);
}
try {
Assert.assertEquals(tv, l.getInt());
assertInRange(Integer.MIN_VALUE, tv, Integer.MAX_VALUE);
} catch (final IllegalArgumentException e) {
assertOutsideRange(Integer.MIN_VALUE, tv, Integer.MAX_VALUE);
}
Assert.assertEquals(tv, l.getLong());
}
use of org.apache.jena.rdf.model.Literal in project jena by apache.
the class TestLiteralsInModel method testAddWithLiteralObject.
public void testAddWithLiteralObject() {
final Literal lit = model.createLiteral("spoo");
model.addLiteral(X, P, lit);
Assert.assertTrue(model.contains(X, P, lit));
Assert.assertTrue(model.containsLiteral(X, P, lit));
}
use of org.apache.jena.rdf.model.Literal in project jena by apache.
the class SecuredResourceTest method testAddProperty.
@Test
public void testAddProperty() {
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] { Action.Update, Action.Create });
final RDFNode rdfNode = ResourceFactory.createResource("http://example.com/newResource");
try {
getSecuredResource().addLiteral(SecuredRDFNodeTest.p, rdfNode);
if (!securityEvaluator.evaluate(perms)) {
Assert.fail("Should have thrown AccessDeniedException Exception");
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(perms)) {
Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e, e.getTriple()));
}
}
try {
getSecuredResource().addLiteral(SecuredRDFNodeTest.p, "string");
if (!securityEvaluator.evaluate(perms)) {
Assert.fail("Should have thrown AccessDeniedException Exception");
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(perms)) {
Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e, e.getTriple()));
}
}
final Literal l = ResourceFactory.createTypedLiteral(3.14F);
try {
getSecuredResource().addProperty(SecuredRDFNodeTest.p, l.getLexicalForm(), l.getDatatype());
if (!securityEvaluator.evaluate(perms)) {
Assert.fail("Should have thrown AccessDeniedException Exception");
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(perms)) {
Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e, e.getTriple()));
}
}
try {
getSecuredResource().addProperty(SecuredRDFNodeTest.p, "dos", "sp");
if (!securityEvaluator.evaluate(perms)) {
Assert.fail("Should have thrown AccessDeniedException Exception");
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(perms)) {
Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e, e.getTriple()));
}
}
}
use of org.apache.jena.rdf.model.Literal in project jena by apache.
the class SecuredLiteralTest method setup.
@Override
@Before
public void setup() {
super.setup();
Literal l = ResourceFactory.createTypedLiteral("literal");
setSecuredRDFNode(SecuredLiteralImpl.getInstance(securedModel, l), l);
}
use of org.apache.jena.rdf.model.Literal in project jena by apache.
the class rdflangtest method insertMetaOld.
//OLD meta.
static void insertMetaOld(EarlReport report) {
Model model = report.getModel();
/*
<> foaf:primaryTopic <http://jena.apache.org/#riot> ;
dc:issued "..."^^xsd:dateTime;
foaf:maker who.
*/
// Update the EARL report.
Resource jena = model.createResource().addProperty(FOAF.homepage, model.createResource("http://jena.apache.org/"));
// ARQ is part of Jena.
Resource arq = report.getSystem().addProperty(DCTerms.isPartOf, jena);
// Andy wrote the test software (updates the thing being tested as well as they are the same).
Resource who = model.createResource(FOAF.Person).addProperty(FOAF.name, "Andy Seaborne").addProperty(FOAF.homepage, model.createResource("http://people.apache.org/~andy"));
Resource reporter = report.getReporter();
reporter.addProperty(DC.creator, who);
Resource system = report.getSystem();
system.addProperty(RDF.type, DOAP.Project);
system.addProperty(DOAP.name, name);
system.addProperty(DOAP.homepage, homepage);
system.addProperty(DOAP.maintainer, who);
Resource release = model.createResource(DOAP.Version);
system.addProperty(DOAP.release, release);
Node today_node = NodeFactoryExtra.todayAsDate();
Literal today = model.createTypedLiteral(today_node.getLiteralLexicalForm(), today_node.getLiteralDatatype());
release.addProperty(DOAP.created, today);
// Again
release.addProperty(DOAP.name, releaseName);
}
Aggregations