void runTestAsk(Query query, QueryExecution qe) throws Exception { boolean result = qe.execAsk(); if (results != null) { if (results.isBoolean()) { boolean b = results.getBooleanResult(); assertEquals("ASK test results do not match", b, result); } else { Model resultsAsModel = results.getModel(); StmtIterator sIter = results.getModel().listStatements(null, RDF.type, ResultSetGraphVocab.ResultSet); if (!sIter.hasNext()) throw new QueryTestException("Can't find the ASK result"); Statement s = sIter.nextStatement(); if (sIter.hasNext()) throw new QueryTestException("Too many result sets in ASK result"); Resource r = s.getSubject(); Property p = resultsAsModel.createProperty(ResultSetGraphVocab.getURI() + "boolean"); boolean x = r.getRequiredProperty(p).getBoolean(); if (x != result) assertEquals("ASK test results do not match", x, result); } } return; }
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()); }
/** * @see com.hp.hpl.jena.rdf.model.Resource#getRequiredProperty(com.hp.hpl.jena.rdf.model.Property) */ public Statement getRequiredProperty(Property p) { synchronized (model) { return new ThreadSafeStatement(model, wrapped.getRequiredProperty(p)); } }