KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
3  * All rights reserved.
4  * [See end of file]
5  */

6
7 package com.hp.hpl.jena.util.test;
8
9 import java.util.Iterator JavaDoc ;
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 /** TestLocationMapper
18  *
19  * @author Andy Seaborne
20  * @version $Id: TestLocationMapper.java,v 1.4 2005/03/18 21:47:06 andy_seaborne Exp $
21  */

22
23 public class TestLocationMapper extends TestCase
24 {
25     static Log log = LogFactory.getLog(TestLocationMapper.class) ;
26     static final String JavaDoc testingDir = TestFileManager.testingDir ;
27     static final String JavaDoc filename1 = "file:test" ;
28     static final String JavaDoc notFilename = "zzzz" ;
29     static final String JavaDoc filename2 = "file:"+testingDir+"/location-mapping-test-file" ;
30     static final String JavaDoc mapping = "location-mapping-test.n3;"+
31                                   testingDir+"/location-mapping-test.n3" ;
32
33     
34     public TestLocationMapper( String JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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         // Light test that the two location mappers are "the same"
74
LocationMapper locMap = new LocationMapper(mapping) ;
75         for ( Iterator JavaDoc iter = loc.listAltEntries() ; iter.hasNext() ; )
76         {
77             String JavaDoc e = (String JavaDoc)iter.next() ;
78             String JavaDoc v1 = locMap.getAltEntry(e) ;
79             String JavaDoc v2 = loc.getAltEntry(e) ;
80             assertEquals("Different entries", v1, v2) ;
81         }
82         for ( Iterator JavaDoc iter = loc.listAltPrefixes() ; iter.hasNext() ; )
83         {
84             String JavaDoc e = (String JavaDoc)iter.next() ;
85             String JavaDoc v1 = locMap.getAltPrefix(e) ;
86             String JavaDoc v2 = loc.getAltPrefix(e) ;
87             assertEquals("Different entries", v1, v2) ;
88         }
89     }
90
91
92     
93 }
94
95 /*
96  * (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
97  * All rights reserved.
98  *
99  * Redistribution and use in source and binary forms, with or without
100  * modification, are permitted provided that the following conditions
101  * are met:
102  * 1. Redistributions of source code must retain the above copyright
103  * notice, this list of conditions and the following disclaimer.
104  * 2. Redistributions in binary form must reproduce the above copyright
105  * notice, this list of conditions and the following disclaimer in the
106  * documentation and/or other materials provided with the distribution.
107  * 3. The name of the author may not be used to endorse or promote products
108  * derived from this software without specific prior written permission.
109  *
110  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
111  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
112  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
113  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
114  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
115  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
116  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
117  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
118  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
119  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
120  */
Popular Tags