Exemplo n.º 1
0
 public void testCreateNullPropertyFails() {
   try {
     model.createProperty(null);
     Assert.fail("should not create null property");
   } catch (final InvalidPropertyURIException e) {
     JenaTestBase.pass();
   }
 }
Exemplo n.º 2
0
 public void testRemoveSPOCallsGraphDeleteTriple() {
   final List<Triple> deleted = new ArrayList<Triple>();
   final Graph base =
       new WrappedGraph(model.getGraph()) {
         @Override
         public void delete(final Triple t) {
           deleted.add(t);
         }
       };
   model = createModel(base);
   model.remove(
       ModelHelper.resource("R"), ModelHelper.property("P"), ModelHelper.rdfNode(model, "17"));
   Assert.assertEquals(JenaTestBase.listOfOne(NodeCreateUtils.createTriple("R P 17")), deleted);
 }
Exemplo n.º 3
0
 private void testResource(final Model model, final Resource r, final int numProps) {
   final Literal tvLiteral = model.createLiteral("test 12 string 2");
   final Resource tvResource = model.createResource();
   final String lang = "fr";
   //
   Assert.assertTrue(
       r.addLiteral(RDF.value, AbstractModelTestBase.tvBoolean)
           .hasLiteral(RDF.value, AbstractModelTestBase.tvBoolean));
   Assert.assertTrue(
       r.addLiteral(RDF.value, AbstractModelTestBase.tvByte)
           .hasLiteral(RDF.value, AbstractModelTestBase.tvByte));
   Assert.assertTrue(
       r.addLiteral(RDF.value, AbstractModelTestBase.tvShort)
           .hasLiteral(RDF.value, AbstractModelTestBase.tvShort));
   Assert.assertTrue(
       r.addLiteral(RDF.value, AbstractModelTestBase.tvInt)
           .hasLiteral(RDF.value, AbstractModelTestBase.tvInt));
   Assert.assertTrue(
       r.addLiteral(RDF.value, AbstractModelTestBase.tvLong)
           .hasLiteral(RDF.value, AbstractModelTestBase.tvLong));
   Assert.assertTrue(
       r.addLiteral(RDF.value, AbstractModelTestBase.tvChar)
           .hasLiteral(RDF.value, AbstractModelTestBase.tvChar));
   Assert.assertTrue(
       r.addLiteral(RDF.value, AbstractModelTestBase.tvFloat)
           .hasLiteral(RDF.value, AbstractModelTestBase.tvFloat));
   Assert.assertTrue(
       r.addLiteral(RDF.value, AbstractModelTestBase.tvDouble)
           .hasLiteral(RDF.value, AbstractModelTestBase.tvDouble));
   Assert.assertTrue(
       r.addProperty(RDF.value, AbstractModelTestBase.tvString)
           .hasProperty(RDF.value, AbstractModelTestBase.tvString));
   Assert.assertTrue(
       r.addProperty(RDF.value, AbstractModelTestBase.tvString, lang)
           .hasProperty(RDF.value, AbstractModelTestBase.tvString, lang));
   Assert.assertTrue(
       r.addLiteral(RDF.value, AbstractModelTestBase.tvObject)
           .hasLiteral(RDF.value, AbstractModelTestBase.tvObject));
   Assert.assertTrue(r.addProperty(RDF.value, tvLiteral).hasProperty(RDF.value, tvLiteral));
   Assert.assertTrue(r.addProperty(RDF.value, tvResource).hasProperty(RDF.value, tvResource));
   Assert.assertTrue(r.getRequiredProperty(RDF.value).getSubject().equals(r));
   //
   final Property p = model.createProperty("foo/", "bar");
   try {
     r.getRequiredProperty(p);
     Assert.fail("should detect missing property");
   } catch (final PropertyNotFoundException e) {
     JenaTestBase.pass();
   }
   //
   Assert.assertEquals(13, GraphTestBase.iteratorToSet(r.listProperties(RDF.value)).size());
   Assert.assertEquals(
       setOf(r),
       GraphTestBase.iteratorToSet(
           r.listProperties(RDF.value).mapWith(Statement.Util.getSubject)));
   //
   Assert.assertEquals(0, GraphTestBase.iteratorToSet(r.listProperties(p)).size());
   Assert.assertEquals(
       new HashSet<Resource>(),
       GraphTestBase.iteratorToSet(r.listProperties(p).mapWith(Statement.Util.getSubject)));
   //
   Assert.assertEquals(13 + numProps, GraphTestBase.iteratorToSet(r.listProperties()).size());
   Assert.assertEquals(
       setOf(r),
       GraphTestBase.iteratorToSet(r.listProperties().mapWith(Statement.Util.getSubject)));
   //
   r.removeProperties();
   Assert.assertEquals(0, model.query(new SimpleSelector(r, null, (RDFNode) null)).size());
 }