KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > util > test > TestFileUtils


1 /*
2   (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP, all rights reserved.
3   [See end of file]
4   $Id: TestFileUtils.java,v 1.4 2005/04/12 09:38:08 andy_seaborne Exp $
5 */

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 /**
14  TestFileUtils
15
16  @author kers
17 */

18 public class TestFileUtils extends TestCase
19     {
20     public TestFileUtils(String JavaDoc 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 JavaDoc fn)
94     { assertTrue("Should be a file name : "+fn, FileUtils.isFile(fn)) ; }
95     void isNotFilename(String JavaDoc fn)
96     { assertFalse("Shouldn't be a file name: "+fn, FileUtils.isFile(fn)) ; }
97     
98     }
99
100
101 /*
102     (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
103     All rights reserved.
104
105     Redistribution and use in source and binary forms, with or without
106     modification, are permitted provided that the following conditions
107     are met:
108
109     1. Redistributions of source code must retain the above copyright
110        notice, this list of conditions and the following disclaimer.
111
112     2. Redistributions in binary form must reproduce the above copyright
113        notice, this list of conditions and the following disclaimer in the
114        documentation and/or other materials provided with the distribution.
115
116     3. The name of the author may not be used to endorse or promote products
117        derived from this software without specific prior written permission.
118
119     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
120     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
121     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
122     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
123     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
124     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
125     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
126     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
127     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
128     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
129 */
Popular Tags