Clover coverage report -
Coverage timestamp: Fri Nov 19 2004 13:41:51 PST
file stats: LOC: 167   Methods: 5
NCLOC: 102   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
JenaTest.java 91.7% 98.1% 100% 97.2%
coverage coverage
 1    package photospace.meta.rdf;
 2   
 3    import java.io.*;
 4    import org.apache.commons.logging.*;
 5    import com.hp.hpl.jena.rdf.model.*;
 6    import com.hp.hpl.jena.vocabulary.*;
 7    import junit.framework.*;
 8   
 9    public class JenaTest
 10    extends TestCase
 11    {
 12    private static final Log log = LogFactory.getLog(JenaTest.class);
 13   
 14  1 public void testTutorials() throws Exception
 15    {
 16    // some definitions
 17  1 String personURI = "http://somewhere/JohnSmith";
 18  1 String givenName = "John";
 19  1 String familyName = "Smith";
 20  1 String fullName = givenName + " " + familyName;
 21   
 22    // Tutorial 01, 02 //
 23   
 24    // create an empty Model
 25  1 Model model = ModelFactory.createDefaultModel();
 26   
 27    // create the resource
 28    // and add the properties cascading style
 29  1 Resource johnSmith
 30    = model.createResource(personURI)
 31    .addProperty(VCARD.FN, fullName)
 32    .addProperty(VCARD.N,
 33    model.createResource()
 34    .addProperty(VCARD.Given, givenName)
 35    .addProperty(VCARD.Family, familyName));
 36   
 37   
 38    // Tutorial 03 //
 39   
 40    // list the statements in the graph
 41  1 StmtIterator iter = model.listStatements();
 42   
 43    // print out the predicate, subject and object of each statement
 44  1 while (iter.hasNext()) {
 45  4 Statement stmt = iter.nextStatement(); // get next statement
 46  4 Resource subject = stmt.getSubject(); // get the subject
 47  4 Property predicate = stmt.getPredicate(); // get the predicate
 48  4 RDFNode object = stmt.getObject(); // get the object
 49   
 50  4 String stmtStr = subject.toString() + " " + predicate.toString() + " ";
 51  4 if (object instanceof Resource) {
 52  1 stmtStr += object.toString();
 53    } else {
 54    // object is a literal
 55  3 stmtStr += " \"" + object.toString() + "\"";
 56    }
 57  4 log.info(stmtStr + " .");
 58    }
 59   
 60    // Tutorial 04 //
 61   
 62    // now write the model in XML form to a file
 63  1 model.write(System.out);
 64  1 model.write(System.out, "RDF/XML-ABBREV");
 65  1 model.write(System.out, "N-TRIPLE");
 66    }
 67   
 68  1 public void testTutorial05() throws Exception
 69    {
 70    // create an empty model
 71  1 Model model = ModelFactory.createDefaultModel();
 72   
 73  1 File rdf = new File(System.getProperty("project.root"), "build/test/jena-test.rdf");
 74  1 InputStream in = new FileInputStream(rdf);
 75   
 76    // read the RDF/XML file
 77  1 model.read(new InputStreamReader(in), "");
 78   
 79    // write it to standard out
 80  1 model.write(System.out);
 81  1 model.write(System.out, "RDF/XML-ABBREV");
 82  1 model.write(System.out, "N-TRIPLE");
 83    }
 84   
 85  1 public void testTutorial06070810() throws Exception
 86    {
 87  1 String personURI = "http://somewhere/JohnSmith/";
 88   
 89    // create an empty model
 90  1 Model model = ModelFactory.createDefaultModel();
 91   
 92  1 File rdf = new File(System.getProperty("project.root"), "build/test/jena-test.rdf");
 93  1 InputStream in = new FileInputStream(rdf);
 94   
 95    // read the RDF/XML file
 96  1 model.read(new InputStreamReader(in), "");
 97  1 model.write(System.out);
 98   
 99    // retrieve the John Smith vcard resource from the model
 100  1 Resource vcard = model.getResource(personURI);
 101   
 102    // retrieve the value of the N property
 103  1 Resource name = (Resource) vcard.getRequiredProperty(VCARD.N).getObject();
 104   
 105    // retrieve the given name property
 106  1 String fullName = vcard.getRequiredProperty(VCARD.FN).getString();
 107   
 108    // add two nick name properties to vcard
 109  1 vcard.addProperty(VCARD.NICKNAME, "Smithy")
 110    .addProperty(VCARD.NICKNAME, "Adman");
 111   
 112    // set up the output
 113  1 log.info("The nicknames of \"" + fullName + "\" are:");
 114   
 115    // list the nicknames
 116  1 StmtIterator iter = vcard.listProperties(VCARD.NICKNAME);
 117  1 while (iter.hasNext())
 118    {
 119  2 log.info(" " + iter.nextStatement().getObject().toString());
 120    }
 121   
 122    // Tutorial 08 //
 123   
 124    // select all the resources with a VCARD.FN property
 125    // whose value ends with "Smith"
 126  1 StmtIterator stmts = model.listStatements(
 127    new SimpleSelector(null, VCARD.FN, (RDFNode) null)
 128    {
 129  4 public boolean selects(Statement s) {
 130  4 return s.getString().endsWith("Smith");
 131    }
 132    });
 133  1 if (stmts.hasNext())
 134    {
 135  1 log.info("The database contains vcards for:");
 136  2 while (stmts.hasNext()) log.info(" " + stmts.nextStatement().getString());
 137    }
 138    else
 139    {
 140  0 log.info("No Smith's were found in the database");
 141    }
 142   
 143    // Tutorial 10 //
 144   
 145    // create a bag
 146  1 Bag smiths = model.createBag();
 147   
 148    // select all the resources with a VCARD.FN property
 149    // whose value ends with "Smith"
 150  1 StmtIterator stmts2 = model.listStatements (
 151    new SimpleSelector(null, VCARD.FN, (RDFNode) null)
 152    {
 153  4 public boolean selects(Statement s) {
 154  4 return s.getString().endsWith("Smith");
 155    }
 156    });
 157   
 158    // add the Smith's to the bag
 159  1 while (stmts2.hasNext())
 160    {
 161  2 smiths.add(stmts2.nextStatement().getSubject());
 162    }
 163   
 164  1 model.write(System.out);
 165    }
 166   
 167    }