1 6 7 package com.hp.hpl.jena.db.test; 8 9 21 22 import com.hp.hpl.jena.db.IDBConnection; 23 import com.hp.hpl.jena.db.ModelRDB; 24 import com.hp.hpl.jena.rdf.model.*; 25 import com.hp.hpl.jena.vocabulary.*; 26 27 import junit.framework.TestCase; 28 import junit.framework.TestSuite; 29 30 31 public class TestSimpleSelector extends TestCase 32 { 33 34 public TestSimpleSelector( String name ) 35 { super( name ); } 36 37 public static TestSuite suite() 38 { return new TestSuite( TestSimpleSelector.class ); } 39 42 43 44 Model model = null; 45 IDBConnection conn = null; 46 47 protected void setUp() throws java.lang.Exception { 48 49 conn = TestConnection.makeAndCleanTestConnection(); 50 model = ModelRDB.createModel(conn, TestPackage.M_DB); 51 52 model.createResource() 53 .addProperty(RDF.type, RDFS.Resource) 54 .addProperty(RDFS.label, "foo") 55 .addProperty(RDF.value, "123"); 56 model.createResource() 57 .addProperty(RDF.type, RDFS.Resource) 58 .addProperty(RDFS.label, "bar") 59 .addProperty(RDF.value, "123"); 60 61 } 62 63 protected void tearDown() throws java.lang.Exception { 64 model.close(); 65 model = null; 66 conn.cleanDB(); 67 conn.close(); 68 } 69 70 public void testAll() { 71 StmtIterator iter = model.listStatements( 72 new SimpleSelector(null, null, (RDFNode) null)); 73 int i =0; 74 while (iter.hasNext()) { 75 i++; 76 iter.next(); 77 } 78 assertEquals(6, i); 79 } 80 81 public void testFindProperty() { 82 StmtIterator iter = model.listStatements( 83 new SimpleSelector(null, RDFS.label, (RDFNode) null)); 84 int i =0; 85 while (iter.hasNext()) { 86 i++; 87 Statement stmt = iter.nextStatement(); 88 assertEquals(RDFS.label, stmt.getPredicate()); 89 } 90 assertEquals(2, i); 91 } 92 93 public void testFindObject() { 94 StmtIterator iter = model.listStatements( 95 new SimpleSelector(null, null, RDFS.Resource)); 96 int i =0; 97 while (iter.hasNext()) { 98 i++; 99 Statement stmt = iter.nextStatement(); 100 assertEquals(RDFS.Resource, stmt.getObject()); 101 } 102 assertEquals(2, i); 103 } 104 105 public void testFindSubject() { 106 StmtIterator iter = model.listStatements( new SimpleSelector(null, null, RDFS.Resource)); 107 assertTrue( iter.hasNext() ); 108 Resource subject = iter.nextStatement().getSubject(); 109 iter.close(); 110 iter = model.listStatements( new SimpleSelector(subject, null, (RDFNode) null)); 111 int i =0; 112 while (iter.hasNext()) { 113 i++; 114 Statement stmt = iter.nextStatement(); 115 assertEquals(subject, stmt.getSubject()); 116 } 117 assertEquals(3, i); 118 } 119 120 public void testFindPropertyAndObject() { 121 StmtIterator iter = model.listStatements( 122 new SimpleSelector(null, RDF.value, 123)); 123 int i =0; 124 while (iter.hasNext()) { 125 i++; 126 Statement stmt = iter.nextStatement(); 127 assertEquals(RDF.value, stmt.getPredicate()); 128 assertEquals(123, stmt.getInt()); 129 } 130 assertEquals(2, i); 131 } 132 133 } 134 135 136 165 | Popular Tags |