1 6 7 package com.hp.hpl.jena.util.test; 8 9 import com.hp.hpl.jena.util.FileUtils; 10 11 import junit.framework.*; 12 13 18 public class TestFileUtils extends TestCase 19 { 20 public TestFileUtils(String name) 21 { super( name ); } 22 23 public static TestSuite suite() 24 { return new TestSuite( TestFileUtils.class ); } 25 26 public void testLangXML() 27 { assertEquals( "RDF/XML", FileUtils.langXML ); } 28 29 public void testLangXMLAbbrev() 30 { assertEquals( "RDF/XML-ABBREV", FileUtils.langXMLAbbrev ); } 31 32 public void testLangNTriple() 33 { assertEquals( "N-TRIPLE", FileUtils.langNTriple ); } 34 35 public void testLangN3() 36 { assertEquals( "N3", FileUtils.langN3 ); } 37 38 public void testLangTurtle() 39 { assertEquals( "TURTLE", FileUtils.langTurtle ); } 40 41 public void testGuessLangLowerCase() 42 { 43 assertEquals( FileUtils.langN3, FileUtils.guessLang( "simple.n3") ); 44 assertEquals( FileUtils.langN3, FileUtils.guessLang( "hello.there.n3") ); 45 assertEquals( FileUtils.langTurtle, FileUtils.guessLang( "simple.ttl") ); 46 assertEquals( FileUtils.langTurtle, FileUtils.guessLang( "hello.there.ttl") ); 47 assertEquals( FileUtils.langNTriple, FileUtils.guessLang( "simple.nt" ) ); 48 assertEquals( FileUtils.langNTriple, FileUtils.guessLang( "whats.up.nt" ) ); 49 assertEquals( FileUtils.langXML, FileUtils.guessLang( "poggle.rdf") ); 50 assertEquals( FileUtils.langXML, FileUtils.guessLang( "wise.owl" ) ); 51 assertEquals( FileUtils.langXML, FileUtils.guessLang( "dotless" ) ); 52 } 53 54 public void testGuessLangMixedCase() 55 { 56 assertEquals( FileUtils.langN3, FileUtils.guessLang( "simple.N3") ); 57 assertEquals( FileUtils.langN3, FileUtils.guessLang( "hello.there.N3") ); 58 assertEquals( FileUtils.langTurtle, FileUtils.guessLang( "simple.TTL") ); 59 assertEquals( FileUtils.langTurtle, FileUtils.guessLang( "hello.there.TTL") ); 60 assertEquals( FileUtils.langNTriple, FileUtils.guessLang( "simple.NT" ) ); 61 assertEquals( FileUtils.langNTriple, FileUtils.guessLang( "whats.up.Nt" ) ); 62 assertEquals( FileUtils.langXML, FileUtils.guessLang( "poggle.rDf") ); 63 assertEquals( FileUtils.langXML, FileUtils.guessLang( "wise.OwL" ) ); 64 assertEquals( FileUtils.langXML, FileUtils.guessLang( "dotless" ) ); 65 } 66 67 public void testGuessLangFallback() 68 { 69 assertEquals( "spoo", FileUtils.guessLang( "noSuffix", "spoo" ) ); 70 assertEquals( "pots", FileUtils.guessLang( "suffix.unknown", "pots" ) ); 71 assertEquals( FileUtils.langXML, FileUtils.guessLang( "rdf.rdf", "spoo" ) ); 72 assertEquals( FileUtils.langXML, FileUtils.guessLang( "rdf.owl", "spoo" ) ); 73 } 74 75 public void testMisplacedDots() 76 { 77 assertEquals( "spoo", FileUtils.guessLang( "stuff.left/right", "spoo" ) ); 78 assertEquals( "spoo", FileUtils.guessLang( "stuff.left\\right", "spoo" ) ); 79 } 80 81 public void testFilename1() { isFilename("foo") ; } 82 public void testFilename2() { isFilename("foo/bar") ; } 83 public void testFilename3() { isFilename("foo\\bar") ; } 84 public void testFilename4() { isFilename("\\bar") ; } 85 public void testFilename5() { isFilename("foo/bar") ; } 86 public void testFilename6() { isFilename("c:foo") ; } 87 public void testFilename7() { isFilename("c:\\foo") ; } 88 public void testFilename8() { isFilename("c:\\foo\\bar") ; } 89 public void testFilename9() { isFilename("file::foo") ; } 90 public void testFilename10() { isNotFilename("http://www.hp.com/") ; } 91 public void testFilename11() { isNotFilename("urn:tag:stuff") ; } 92 93 void isFilename(String fn) 94 { assertTrue("Should be a file name : "+fn, FileUtils.isFile(fn)) ; } 95 void isNotFilename(String fn) 96 { assertFalse("Shouldn't be a file name: "+fn, FileUtils.isFile(fn)) ; } 97 98 } 99 100 101 | Popular Tags |