1 6 7 package com.hp.hpl.jena.db.test; 8 9 import java.util.*; 10 11 import com.hp.hpl.jena.db.*; 12 import com.hp.hpl.jena.rdf.model.Model; 13 import com.hp.hpl.jena.shared.*; 14 import com.hp.hpl.jena.shared.test.AbstractTestPrefixMapping; 15 import junit.framework.*; 16 17 25 public class TestPrefixMapping extends AbstractTestPrefixMapping { 26 27 private List models = null; 28 private IDBConnection theConnection = null; 29 private static int count = 0; 30 31 public TestPrefixMapping(String name) { 32 super(name); 33 } 34 35 public static TestSuite suite() { 36 return new TestSuite(TestPrefixMapping.class); 37 } 38 39 public void setUp() { 40 theConnection = TestConnection.makeAndCleanTestConnection(); 41 models = new ArrayList(); 42 } 43 44 public void tearDown() { 45 46 Iterator it = models.iterator(); 48 while(it.hasNext()) { 49 Model m = (Model)it.next(); 50 m.close(); 51 } 52 53 try { 54 theConnection.close(); 55 } catch (Exception e) { 56 throw new JenaException(e); 57 } 58 } 59 60 private String getModelName() 61 { return "test" + count++; } 62 63 private Model getModel() 64 { 65 Model model = ModelRDB.createModel( theConnection, getModelName() ); 66 models.add( model ); 67 return model; 68 } 69 70 public PrefixMapping getMapping() { 71 Model model = getModel(); 72 return model.getGraph().getPrefixMapping(); 73 } 74 75 public void testPrefixesPersist() 76 { 77 String name = "prefix-testing-model-persist"; 78 Model m = ModelRDB.createModel( theConnection, name ); 79 m.setNsPrefix( "hello", "eh:/someURI#" ); 80 m.setNsPrefix( "bingo", "eh:/otherURI#" ); 81 m.setNsPrefix( "yendi", "eh:/otherURI#" ); 82 m.close(); 83 Model m1 = ModelRDB.open( theConnection, name ); 84 assertEquals( "eh:/someURI#", m1.getNsPrefixURI( "hello" ) ); 85 assertEquals( "eh:/otherURI#", m1.getNsPrefixURI( "yendi" ) ); 86 assertEquals( null, m1.getNsPrefixURI( "bingo" ) ); 87 m1.close(); 88 } 89 90 public void testPrefixesRemoved() 91 { 92 String name = "prefix-testing-model-remove"; 93 Model m = ModelRDB.createModel( theConnection, name ); 94 m.setNsPrefix( "hello", "eh:/someURI#" ); 95 m.setNsPrefix( "there", "eg:/otherURI#" ); 96 m.removeNsPrefix( "hello" ); 97 assertEquals( null, m.getNsPrefixURI( "hello" ) ); 98 m.close(); 99 Model m1 = ModelRDB.open( theConnection, name ); 100 assertEquals( null, m1.getNsPrefixURI( "hello" ) ); 101 assertEquals( "eg:/otherURI#", m1.getNsPrefixURI( "there" ) ); 102 m1.close(); 103 } 104 105 } 106 107 | Popular Tags |