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