1 6 7 package com.hp.hpl.jena.rdf.model.test; 8 9 import com.hp.hpl.jena.shared.*; 10 import com.hp.hpl.jena.shared.test.*; 11 import com.hp.hpl.jena.graph.*; 12 import com.hp.hpl.jena.rdf.model.*; 13 import com.hp.hpl.jena.rdf.model.impl.ModelCom; 14 15 import junit.framework.*; 16 17 21 public class TestModelPrefixMapping extends AbstractTestPrefixMapping 22 { 23 public TestModelPrefixMapping( String name ) 24 { super( name ); } 25 26 public static TestSuite suite() 27 { return new TestSuite( TestModelPrefixMapping.class ); } 28 29 protected PrefixMapping getMapping() 30 { return ModelFactory.createDefaultModel(); } 31 32 protected static final String alphaPrefix = "alpha"; 33 protected static final String betaPrefix = "beta"; 34 protected static final String alphaURI = "http://testing.jena.hpl.hp.com/alpha#"; 35 protected static final String betaURI = "http://testing.jena.hpl.hp.com/beta#"; 36 37 protected PrefixMapping baseMap = PrefixMapping.Factory.create() 38 .setNsPrefix( alphaPrefix, alphaURI ) 39 .setNsPrefix( betaPrefix, betaURI ); 40 41 private PrefixMapping prevMap; 42 43 public void setPrefixes() 44 { 45 prevMap = ModelCom.setDefaultModelPrefixes( baseMap ); 46 } 47 48 public void restorePrefixes() 49 { 50 ModelCom.setDefaultModelPrefixes( prevMap ); 51 } 52 53 57 public void testDefaultPrefixes() 58 { 59 setPrefixes(); 60 Model m = ModelFactory.createDefaultModel(); 61 assertEquals( baseMap.getNsPrefixMap(), m.getNsPrefixMap() ); 62 restorePrefixes(); 63 } 64 65 public void testOnlyFreshPrefixes() 66 { 67 setPrefixes(); 68 try { doOnlyFreshPrefixes(); } finally { restorePrefixes(); } 69 } 70 71 74 private void doOnlyFreshPrefixes() 75 { 76 String newURI = "abc:def/"; 77 Graph g = Factory.createDefaultGraph(); 78 PrefixMapping pm = g.getPrefixMapping(); 79 pm.setNsPrefix( alphaPrefix, newURI ); 80 Model m = ModelFactory.createModelForGraph( g ); 81 assertEquals( newURI, m.getNsPrefixURI( alphaPrefix ) ); 82 assertEquals( betaURI, m.getNsPrefixURI( betaPrefix ) ); } 83 84 public void testGetDefault() 85 { setPrefixes(); 86 try { assertSame( baseMap, ModelCom.getDefaultModelPrefixes() ); } 87 finally { restorePrefixes(); } } 88 } 89 90 91 | Popular Tags |