KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > db > test > TestPrefixMapping


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

6
7 package com.hp.hpl.jena.db.test;
8
9 import java.util.*;
10
11 import com.hp.hpl.jena.db.*;
12 import com.hp.hpl.jena.rdf.model.Model;
13 import com.hp.hpl.jena.shared.*;
14 import com.hp.hpl.jena.shared.test.AbstractTestPrefixMapping;
15 import junit.framework.*;
16
17 /**
18  *
19  * This shares the same test as the in-memory prefix mapping.
20  * (Tests for the persistence of prefix maps are in TestNSPrefix).
21  *
22  * @author csayers based on testGraphRDB by kers
23  * @version $Revision: 1.6 $
24  */

25 public class TestPrefixMapping extends AbstractTestPrefixMapping {
26
27     private List models = null;
28     private IDBConnection theConnection = null;
29     private static int count = 0;
30     
31     public TestPrefixMapping(String JavaDoc name) {
32         super(name);
33     }
34
35     public static TestSuite suite() {
36         return new TestSuite(TestPrefixMapping.class);
37     }
38
39     public void setUp() {
40         theConnection = TestConnection.makeAndCleanTestConnection();
41         models = new ArrayList();
42     }
43
44     public void tearDown() {
45         
46         // close all the models we opened
47
Iterator it = models.iterator();
48         while(it.hasNext()) {
49             Model m = (Model)it.next();
50             m.close();
51         }
52             
53         try {
54             theConnection.close();
55         } catch (Exception JavaDoc e) {
56             throw new JenaException(e);
57         }
58     }
59
60     private String JavaDoc getModelName()
61         { return "test" + count++; }
62         
63     private Model getModel()
64         {
65         Model model = ModelRDB.createModel( theConnection, getModelName() );
66         models.add( model );
67         return model;
68         }
69         
70     public PrefixMapping getMapping() {
71         Model model = getModel();
72         return model.getGraph().getPrefixMapping();
73     }
74     
75     public void testPrefixesPersist()
76         {
77         String JavaDoc name = "prefix-testing-model-persist";
78         Model m = ModelRDB.createModel( theConnection, name );
79         m.setNsPrefix( "hello", "eh:/someURI#" );
80         m.setNsPrefix( "bingo", "eh:/otherURI#" );
81         m.setNsPrefix( "yendi", "eh:/otherURI#" );
82         m.close();
83         Model m1 = ModelRDB.open( theConnection, name );
84         assertEquals( "eh:/someURI#", m1.getNsPrefixURI( "hello" ) );
85         assertEquals( "eh:/otherURI#", m1.getNsPrefixURI( "yendi" ) );
86         assertEquals( null, m1.getNsPrefixURI( "bingo" ) );
87         m1.close();
88         }
89     
90     public void testPrefixesRemoved()
91         {
92         String JavaDoc name = "prefix-testing-model-remove";
93         Model m = ModelRDB.createModel( theConnection, name );
94         m.setNsPrefix( "hello", "eh:/someURI#" );
95         m.setNsPrefix( "there", "eg:/otherURI#" );
96         m.removeNsPrefix( "hello" );
97         assertEquals( null, m.getNsPrefixURI( "hello" ) );
98         m.close();
99         Model m1 = ModelRDB.open( theConnection, name );
100         assertEquals( null, m1.getNsPrefixURI( "hello" ) );
101         assertEquals( "eg:/otherURI#", m1.getNsPrefixURI( "there" ) );
102         m1.close();
103         }
104
105 }
106
107 /*
108     (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
109     All rights reserved.
110
111     Redistribution and use in source and binary forms, with or without
112     modification, are permitted provided that the following conditions
113     are met:
114
115     1. Redistributions of source code must retain the above copyright
116        notice, this list of conditions and the following disclaimer.
117
118     2. Redistributions in binary form must reproduce the above copyright
119        notice, this list of conditions and the following disclaimer in the
120        documentation and/or other materials provided with the distribution.
121
122     3. The name of the author may not be used to endorse or promote products
123        derived from this software without specific prior written permission.
124
125     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
126     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
127     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
128     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
129     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
130     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
131     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
132     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
133     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
134     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
135 */
Popular Tags