1 6 7 package com.hp.hpl.jena.db.test; 8 9 22 23 import com.hp.hpl.jena.db.*; 24 import com.hp.hpl.jena.shared.PrefixMapping; 25 import com.hp.hpl.jena.shared.impl.PrefixMappingImpl; 26 import com.hp.hpl.jena.shared.test.AbstractTestPrefixMapping; 27 28 import junit.framework.*; 29 30 public class TestNsPrefix extends AbstractTestPrefixMapping { 31 32 public TestNsPrefix( String name ) 33 { super( name ); } 34 35 public static TestSuite suite() 36 { return new TestSuite( TestNsPrefix.class ); } 37 38 protected void setUp() throws java.lang.Exception { 39 } 40 41 protected void tearDown() throws java.lang.Exception { 42 } 43 44 protected PrefixMapping getMapping() 45 { 46 IDBConnection conn = TestConnection.makeAndCleanTestConnection(); 47 return ModelRDB.createModel( conn ); 48 } 49 50 public void testSinglePrefix() throws java.lang.Exception { 51 String testPrefix = "testPrefix"; 52 String testURI = "http://someTestURI#"; 53 IDBConnection conn = TestConnection.makeAndCleanTestConnection(); 54 ModelRDB m = ModelRDB.createModel(conn); 55 assertTrue( m.getNsPrefixMap().size() == 0 ); m.setNsPrefix(testPrefix,testURI); 57 assertTrue( m.getNsPrefixMap().size() == 1); 58 assertTrue( m.getNsPrefixURI(testPrefix).compareTo(testURI) ==0 ); 59 m.close(); 60 conn.close(); 61 } 62 63 public void testDuplicatePrefix() throws java.lang.Exception { 64 String testPrefix = "testPrefix"; 65 String testURI = "http://someTestURI#"; 66 IDBConnection conn = TestConnection.makeAndCleanTestConnection(); 67 ModelRDB m = ModelRDB.createModel(conn); 68 assertTrue( m.getNsPrefixMap().size() == 0 ); m.setNsPrefix(testPrefix,testURI); 70 m.setNsPrefix(testPrefix,testURI); 71 assertTrue( m.getNsPrefixMap().size() == 1); 72 assertTrue( m.getNsPrefixURI(testPrefix).compareTo(testURI) ==0 ); 73 m.close(); 74 conn.close(); 75 } 76 77 public void testChangingPrefixMapping() throws java.lang.Exception { 78 String testPrefix = "testPrefix"; 79 String testURI = "http://someTestURI#"; 80 String someOtherTestURI = "http://someOtherTestURI#"; 81 IDBConnection conn = TestConnection.makeAndCleanTestConnection(); 82 ModelRDB m = ModelRDB.createModel(conn); 83 assertTrue( m.getNsPrefixMap().size() == 0 ); m.setNsPrefix(testPrefix,testURI); 85 m.setNsPrefix(testPrefix,someOtherTestURI); 86 assertTrue( m.getNsPrefixMap().size() == 1); 87 assertTrue( m.getNsPrefixURI(testPrefix).compareTo(testURI) !=0 ); 88 assertTrue( m.getNsPrefixURI(testPrefix).compareTo(someOtherTestURI) ==0 ); 89 m.close(); 90 conn.close(); 91 } 92 93 public void testPersistenceOfPrefixes() throws java.lang.Exception { 94 String testPrefix = "testPrefix"; 95 String testURI = "http://someTestURI#"; 96 IDBConnection conn = TestConnection.makeAndCleanTestConnection(); 97 ModelRDB m = ModelRDB.createModel(conn); 98 assertTrue( m.getNsPrefixMap().size() == 0 ); m.setNsPrefix(testPrefix,testURI); 100 assertTrue( m.getNsPrefixMap().size() == 1); 101 assertTrue( m.getNsPrefixURI(testPrefix).compareTo(testURI) ==0 ); 102 m.close(); 103 104 ModelRDB m2 = ModelRDB.createModel(conn,"myName"); 107 assertTrue( m2.getNsPrefixMap().size() == 0); 108 m2.remove(); 109 m2.close(); 110 111 ModelRDB m3 = ModelRDB.open(conn); 113 assertTrue( m3.getNsPrefixMap().size() == 1); 114 assertTrue( m3.getNsPrefixURI(testPrefix).compareTo(testURI) ==0 ); 115 m3.close(); 116 117 conn.close(); 118 } 119 120 public void testIdependenceOfPrefixes() throws java.lang.Exception { 121 String testPrefix1 = "testPrefix1"; 122 String testURI1 = "http://someTestURI1#"; 123 String testPrefix2 = "testPrefix2"; 124 String testURI2 = "http://someTestURI2#"; 125 String testPrefix3 = "testPrefix3"; 126 String testURI3 = "http://someTestURI3#"; 127 IDBConnection conn = TestConnection.makeAndCleanTestConnection(); 128 129 ModelRDB m = ModelRDB.createModel(conn); 131 assertTrue( m.getNsPrefixMap().size() == 0 ); m.setNsPrefix(testPrefix1,testURI1); 133 m.setNsPrefix(testPrefix2,testURI2); 134 assertTrue( m.getNsPrefixMap().size() == 2); 135 assertTrue( m.getNsPrefixURI(testPrefix1).compareTo(testURI1) ==0 ); 136 assertTrue( m.getNsPrefixURI(testPrefix2).compareTo(testURI2) ==0 ); 137 138 ModelRDB m2 = ModelRDB.createModel(conn,"secondGraph"); 140 assertTrue( m2.getNsPrefixMap().size() == 0 ); m2.setNsPrefix(testPrefix2,testURI2); 142 m2.setNsPrefix(testPrefix3,testURI3); 143 144 assertTrue( m2.getNsPrefixMap().size() == 2); 146 assertTrue( m2.getNsPrefixURI(testPrefix2).compareTo(testURI2) ==0 ); 147 assertTrue( m2.getNsPrefixURI(testPrefix3).compareTo(testURI3) ==0 ); 148 149 assertTrue( m.getNsPrefixMap().size() == 2); 151 assertTrue( m.getNsPrefixURI(testPrefix1).compareTo(testURI1) ==0 ); 152 assertTrue( m.getNsPrefixURI(testPrefix2).compareTo(testURI2) ==0 ); 153 154 m2.remove(); 156 m2.close(); 157 m2 = null; 158 159 assertTrue( m.getNsPrefixMap().size() == 2); 161 assertTrue( m.getNsPrefixURI(testPrefix1).compareTo(testURI1) ==0 ); 162 assertTrue( m.getNsPrefixURI(testPrefix2).compareTo(testURI2) ==0 ); 163 164 m.close(); 166 m = null; 167 168 ModelRDB m3 = ModelRDB.open(conn); 169 assertTrue( m3.getNsPrefixMap().size() == 2); 170 assertTrue( m3.getNsPrefixURI(testPrefix1).compareTo(testURI1) ==0 ); 171 assertTrue( m3.getNsPrefixURI(testPrefix2).compareTo(testURI2) ==0 ); 172 m3.close(); 173 174 conn.close(); 175 } 176 177 public void testPersistedChangedPrefixes() throws java.lang.Exception { 178 String testPrefix1 = "testPrefix1"; 179 String testURI1 = "http://someTestURI/1#"; 180 String testURI1b = "http://someTestURI/1b#"; 181 String testPrefix2 = "testPrefix2"; 182 String testURI2 = "http://someTestURI/2#"; 183 String testPrefix3 = "testPrefix3"; 184 String testURI3 = "http://someTestURI/3#"; 185 IDBConnection conn = TestConnection.makeAndCleanTestConnection(); 186 187 ModelRDB m = ModelRDB.createModel(conn); 188 assertTrue( m.getNsPrefixMap().size() == 0 ); m.setNsPrefix(testPrefix1,testURI1); 190 m.setNsPrefix(testPrefix2,testURI2); 191 assertTrue( m.getNsPrefixMap().size() == 2); 192 assertTrue( m.getNsPrefixURI(testPrefix1).compareTo(testURI1) ==0 ); 193 assertTrue( m.getNsPrefixURI(testPrefix2).compareTo(testURI2) ==0 ); 194 m.close(); 195 m=null; 196 197 ModelRDB m2 = ModelRDB.open(conn); 199 assertTrue( m2.getNsPrefixMap().size() == 2); 200 assertTrue( m2.getNsPrefixURI(testPrefix1).compareTo(testURI1) ==0 ); 201 assertTrue( m2.getNsPrefixURI(testPrefix2).compareTo(testURI2) ==0 ); 202 203 m2.setNsPrefix(testPrefix1,testURI1b); 205 m2.setNsPrefix(testPrefix3, testURI3); 206 207 assertTrue( m2.getNsPrefixMap().size() == 3); 208 assertTrue( m2.getNsPrefixURI(testPrefix1).compareTo(testURI1b) ==0 ); 209 assertTrue( m2.getNsPrefixURI(testPrefix2).compareTo(testURI2) ==0 ); 210 assertTrue( m2.getNsPrefixURI(testPrefix3).compareTo(testURI3) ==0 ); 211 212 m2.close(); 213 m2 = null; 214 215 ModelRDB m3 = ModelRDB.open(conn); 217 assertTrue( m3.getNsPrefixMap().size() == 3); 218 assertTrue( m3.getNsPrefixURI(testPrefix1).compareTo(testURI1b) ==0 ); 219 assertTrue( m3.getNsPrefixURI(testPrefix2).compareTo(testURI2) ==0 ); 220 assertTrue( m3.getNsPrefixURI(testPrefix3).compareTo(testURI3) ==0 ); 221 222 m3.close(); 223 conn.close(); 224 } 225 226 public void testCopyPersistentPrefixMapping() throws java.lang.Exception { 227 String testPrefix1 = "testPrefix1"; 228 String testPrefix2 = "testPrefix2"; 229 String testURI1 = "http://someTestURI/1#"; 230 String testURI2 = "http://someTestURI/2#"; 231 IDBConnection conn = TestConnection.makeAndCleanTestConnection(); 232 ModelRDB m = ModelRDB.createModel(conn); 233 assertTrue( m.getNsPrefixMap().size() == 0 ); m.setNsPrefix(testPrefix1,testURI1); 235 m.setNsPrefix(testPrefix2,testURI2); 236 assertTrue( m.getNsPrefixMap().size() == 2); 237 assertTrue( m.getNsPrefixURI(testPrefix1).compareTo(testURI1) ==0 ); 238 assertTrue( m.getNsPrefixURI(testPrefix2).compareTo(testURI2) ==0 ); 239 240 ModelRDB m2 = ModelRDB.createModel(conn, "secondModel"); 242 assertTrue( m2.getNsPrefixMap().size() == 0); 243 m2.setNsPrefixes(m.getNsPrefixMap()); 244 assertTrue( m2.getNsPrefixMap().size() == 2); 245 assertTrue( m2.getNsPrefixURI(testPrefix1).compareTo(testURI1) ==0 ); 246 assertTrue( m2.getNsPrefixURI(testPrefix2).compareTo(testURI2) ==0 ); 247 248 m.close(); 249 m2.close(); 250 251 conn.close(); 252 } 253 254 255 public void testCopyMemoryPrefixMapping() throws java.lang.Exception { 256 String testPrefix1 = "testPrefix1"; 257 String testPrefix2 = "testPrefix2"; 258 String testURI1 = "http://someTestURI/1#"; 259 String testURI2 = "http://someTestURI/2#"; 260 261 PrefixMapping myMap = new PrefixMappingImpl(); 262 myMap.setNsPrefix(testPrefix1, testURI1); 263 myMap.setNsPrefix(testPrefix2, testURI2); 264 265 assertTrue( myMap.getNsPrefixMap().size() == 2); 266 assertTrue( myMap.getNsPrefixURI(testPrefix1).compareTo(testURI1) ==0 ); 267 assertTrue( myMap.getNsPrefixURI(testPrefix2).compareTo(testURI2) ==0 ); 268 269 IDBConnection conn = TestConnection.makeAndCleanTestConnection(); 270 ModelRDB m = ModelRDB.createModel(conn); 271 assertTrue( m.getNsPrefixMap().size() == 0 ); m.setNsPrefixes(myMap); 273 assertTrue( m.getNsPrefixMap().size() == 2); 274 assertTrue( m.getNsPrefixURI(testPrefix1).compareTo(testURI1) ==0 ); 275 assertTrue( m.getNsPrefixURI(testPrefix2).compareTo(testURI2) ==0 ); 276 277 m.close(); 278 conn.close(); 279 } 280 281 } 282 283 284 313 | Popular Tags |