KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > rdf > model > test > TestModelPrefixMapping


1 /*
2   (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3   [See end of file]
4   $Id: TestModelPrefixMapping.java,v 1.7 2005/02/21 12:15:13 andy_seaborne Exp $
5 */

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 /**
18     Test that a model is a prefix mapping.
19     @author kers
20 */

21 public class TestModelPrefixMapping extends AbstractTestPrefixMapping
22     {
23     public TestModelPrefixMapping( String JavaDoc 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 JavaDoc alphaPrefix = "alpha";
33     protected static final String JavaDoc betaPrefix = "beta";
34     protected static final String JavaDoc alphaURI = "http://testing.jena.hpl.hp.com/alpha#";
35     protected static final String JavaDoc 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     /**
54         Test that a freshly-created Model has the prefixes established by the
55         default in ModelCom.
56     */

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     /**
72        Test that existing prefixes are not over-ridden by the default ones.
73     */

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