1 5 6 package com.hp.hpl.jena.rdql.test; 7 8 import junit.framework.* ; 9 10 import java.util.* ; 11 12 import com.hp.hpl.jena.rdf.model.* ; 13 import com.hp.hpl.jena.rdql.*; 14 15 21 22 public class QueryTestsMisc extends TestSuite 23 { 24 static final String testSetName = "RDQL - Query - Other" ; 25 public static String baseURI = "http://rdql/" ; 26 27 public static TestSuite suite() 28 { 29 return new QueryTestsMisc(testSetName) ; 30 } 31 32 33 private QueryTestsMisc(String name) 34 { 35 super(name) ; 36 37 try { 38 addTest(new TestQueryTriplesMerge()) ; 40 addTest(new TestQueryGetTriples()) ; 41 addTest(new TestQueryGetTriples2()) ; 42 } catch (Exception ex) 43 { 44 System.err.println("Problems making RDQL test") ; 45 ex.printStackTrace(System.err) ; 46 return ; 47 } 48 } 50 51 static abstract class TestQueryTriples extends TestCase 52 { 53 Model model ; 54 Resource r ; 55 56 TestQueryTriples(String testName) 57 { 58 super(testName) ; 59 model = ModelFactory.createDefaultModel() ; 60 r = model.createResource(baseURI+"r") ; 61 r.addProperty(model.createProperty(baseURI+"p1"), "v1") ; 62 r.addProperty(model.createProperty(baseURI+"p2"), "v2") ; 63 } 64 } 65 66 static class TestQueryTriplesMerge extends TestQueryTriples 67 { 68 69 TestQueryTriplesMerge() { super("TestQueryTriplesMerge" ) ; } 70 71 protected void runTest() throws Throwable 72 { 73 Model model2 = ModelFactory.createDefaultModel() ; 74 75 String queryString = "SELECT * WHERE (<"+r.getURI()+"> ?p ?v)" ; 76 77 Query query = new Query(queryString) ; 78 query.setSource(model); 79 QueryExecution qe = new QueryEngine(query) ; 80 QueryResults results = qe.exec() ; 81 82 for ( ; results.hasNext() ; ) 83 { 84 ResultBindingImpl rb = (ResultBindingImpl)results.next() ; 85 rb.mergeTriples(model2) ; 86 } 87 results.close() ; 88 89 assertTrue(getName()+": merged rsults not the same as target model", 90 model.isIsomorphicWith(model2)) ; 91 } 92 } 93 94 static class TestQueryGetTriples extends TestQueryTriples 95 { 96 97 TestQueryGetTriples() { super("TestQueryGetTriples" ) ; } 98 99 protected void runTest() throws Throwable 100 { 101 Model model2 = ModelFactory.createDefaultModel() ; 102 103 String queryString = "SELECT * WHERE (<"+r.getURI()+"> ?p ?v)" ; 104 105 Query query = new Query(queryString) ; 106 query.setSource(model); 107 QueryExecution qe = new QueryEngine(query) ; 108 QueryResults results = qe.exec() ; 109 110 int i = 0 ; 111 for ( ; results.hasNext() ; ) 112 { 113 i++ ; 114 ResultBindingImpl rb = (ResultBindingImpl)results.next() ; 115 assertTrue(getName()+": getTriples(loop "+i+")", rb.getTriples().size() == 1) ; 116 } 117 results.close() ; 118 } 119 } 120 121 static class TestQueryGetTriples2 extends TestQueryTriples 122 { 123 124 TestQueryGetTriples2() { super("TestQueryGetTriples2" ) ; } 125 126 protected void runTest() throws Throwable 127 { 128 Model model2 = ModelFactory.createDefaultModel() ; 129 130 String queryString = "SELECT * WHERE (<"+r.getURI()+"> ?p ?v)" ; 131 132 Query query = new Query(queryString) ; 133 query.setSource(model); 134 QueryExecution qe = new QueryEngine(query) ; 135 QueryResults results = qe.exec() ; 136 137 int i = 0 ; 138 for ( ; results.hasNext() ; ) 139 { 140 i++ ; 141 ResultBindingImpl rb = (ResultBindingImpl)results.next() ; 142 Set s = rb.getTriples() ; 143 assertTrue(getName()+": getTriples2(loop "+i+")", 145 rb.getTriples().size() == 1) ; 146 } 147 results.close() ; 148 } 149 } 150 151 } 152 153 179 180 | Popular Tags |