1 6 7 package com.hp.hpl.jena.util.test; 8 9 import java.util.Iterator ; 10 import junit.framework.*; 11 import org.apache.commons.logging.*; 12 13 import com.hp.hpl.jena.util.LocationMapper; 14 import com.hp.hpl.jena.util.FileManager; 15 import com.hp.hpl.jena.rdf.model.Model ; 16 17 22 23 public class TestLocationMapper extends TestCase 24 { 25 static Log log = LogFactory.getLog(TestLocationMapper.class) ; 26 static final String testingDir = TestFileManager.testingDir ; 27 static final String filename1 = "file:test" ; 28 static final String notFilename = "zzzz" ; 29 static final String filename2 = "file:"+testingDir+"/location-mapping-test-file" ; 30 static final String mapping = "location-mapping-test.n3;"+ 31 testingDir+"/location-mapping-test.n3" ; 32 33 34 public TestLocationMapper( String name ) 35 { 36 super(name); 37 } 38 39 public static TestSuite suite() 40 { 41 return new TestSuite( TestLocationMapper.class ); 42 } 43 44 public void testLocationMapping() 45 { 46 LocationMapper locMap = new LocationMapper(mapping) ; 47 String alt = locMap.altMapping(filename1) ; 48 assertNotNull(alt) ; 49 assertEquals(alt, filename2) ; 50 } 51 52 public void testLocationMappingMiss() 53 { 54 LocationMapper locMap = new LocationMapper(mapping) ; 55 String alt = locMap.altMapping(notFilename) ; 56 assertNotNull(alt) ; 57 assertEquals(alt, notFilename) ; 58 } 59 60 public void testLocationMappingURLtoFile() 61 { 62 LocationMapper locMap = new LocationMapper(mapping) ; 63 String alt = locMap.altMapping("http://example.org/file") ; 64 assertNotNull(alt) ; 65 assertEquals(alt, "file:"+testingDir+"/location-mapping-test-file") ; 66 } 67 68 public void testLocationMappingFromModel() 69 { 70 Model model = FileManager.get().loadModel(testingDir+"/location-mapping-test.n3") ; 71 LocationMapper loc = new LocationMapper(model) ; 72 73 LocationMapper locMap = new LocationMapper(mapping) ; 75 for ( Iterator iter = loc.listAltEntries() ; iter.hasNext() ; ) 76 { 77 String e = (String )iter.next() ; 78 String v1 = locMap.getAltEntry(e) ; 79 String v2 = loc.getAltEntry(e) ; 80 assertEquals("Different entries", v1, v2) ; 81 } 82 for ( Iterator iter = loc.listAltPrefixes() ; iter.hasNext() ; ) 83 { 84 String e = (String )iter.next() ; 85 String v1 = locMap.getAltPrefix(e) ; 86 String v2 = loc.getAltPrefix(e) ; 87 assertEquals("Different entries", v1, v2) ; 88 } 89 } 90 91 92 93 } 94 95 | Popular Tags |