001: /*
002: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: [See end of file]
004: $Id: TestPrefixMapping.java,v 1.10 2008/01/02 12:08:14 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.db.test;
008:
009: import java.util.*;
010:
011: import com.hp.hpl.jena.db.*;
012: import com.hp.hpl.jena.rdf.model.Model;
013: import com.hp.hpl.jena.shared.*;
014: import com.hp.hpl.jena.shared.test.AbstractTestPrefixMapping;
015: import junit.framework.*;
016:
017: /**
018: *
019: * This shares the same test as the in-memory prefix mapping.
020: * (Tests for the persistence of prefix maps are in TestNSPrefix).
021: *
022: * @author csayers based on testGraphRDB by kers
023: * @version $Revision: 1.10 $
024: */
025: public class TestPrefixMapping extends AbstractTestPrefixMapping {
026:
027: private List models = null;
028: private IDBConnection theConnection = null;
029: private static int count = 0;
030:
031: public TestPrefixMapping(String name) {
032: super (name);
033: }
034:
035: public static TestSuite suite() {
036: return new TestSuite(TestPrefixMapping.class);
037: }
038:
039: public void setUp() {
040: theConnection = TestConnection.makeAndCleanTestConnection();
041: models = new ArrayList();
042: }
043:
044: public void tearDown() {
045:
046: // close all the models we opened
047: Iterator it = models.iterator();
048: while (it.hasNext()) {
049: Model m = (Model) it.next();
050: m.close();
051: }
052:
053: try {
054: theConnection.close();
055: } catch (Exception e) {
056: throw new JenaException(e);
057: }
058: }
059:
060: private String getModelName() {
061: return "test" + count++;
062: }
063:
064: private Model getModel() {
065: Model model = ModelRDB.createModel(theConnection,
066: getModelName());
067: models.add(model);
068: return model;
069: }
070:
071: public PrefixMapping getMapping() {
072: Model model = getModel();
073: return model.getGraph().getPrefixMapping();
074: }
075:
076: public void testPrefixesPersist() {
077: String name = "prefix-testing-model-persist";
078: Model m = ModelRDB.createModel(theConnection, name);
079: m.setNsPrefix("hello", "eh:/someURI#");
080: m.setNsPrefix("bingo", "eh:/otherURI#");
081: m.setNsPrefix("yendi", "eh:/otherURI#");
082: m.close();
083: Model m1 = ModelRDB.open(theConnection, name);
084: assertEquals("eh:/someURI#", m1.getNsPrefixURI("hello"));
085: assertEquals("eh:/otherURI#", m1.getNsPrefixURI("yendi"));
086: assertEquals("eh:/otherURI#", m1.getNsPrefixURI("bingo"));
087: m1.close();
088: }
089:
090: public void testPrefixesRemoved() {
091: String name = "prefix-testing-model-remove";
092: Model m = ModelRDB.createModel(theConnection, name);
093: m.setNsPrefix("hello", "eh:/someURI#");
094: m.setNsPrefix("there", "eg:/otherURI#");
095: m.removeNsPrefix("hello");
096: assertEquals(null, m.getNsPrefixURI("hello"));
097: m.close();
098: Model m1 = ModelRDB.open(theConnection, name);
099: assertEquals(null, m1.getNsPrefixURI("hello"));
100: assertEquals("eg:/otherURI#", m1.getNsPrefixURI("there"));
101: m1.close();
102: }
103:
104: }
105:
106: /*
107: (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
108: All rights reserved.
109:
110: Redistribution and use in source and binary forms, with or without
111: modification, are permitted provided that the following conditions
112: are met:
113:
114: 1. Redistributions of source code must retain the above copyright
115: notice, this list of conditions and the following disclaimer.
116:
117: 2. Redistributions in binary form must reproduce the above copyright
118: notice, this list of conditions and the following disclaimer in the
119: documentation and/or other materials provided with the distribution.
120:
121: 3. The name of the author may not be used to endorse or promote products
122: derived from this software without specific prior written permission.
123:
124: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
125: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
126: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
127: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
128: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
129: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
130: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
131: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
132: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
133: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
134: */
|