001: /*
002: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: [See end of file]
004: $Id: TestModelPrefixMapping.java,v 1.10 2008/01/02 12:04:42 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.rdf.model.test;
008:
009: import com.hp.hpl.jena.shared.*;
010: import com.hp.hpl.jena.shared.test.*;
011: import com.hp.hpl.jena.graph.*;
012: import com.hp.hpl.jena.rdf.model.*;
013: import com.hp.hpl.jena.rdf.model.impl.ModelCom;
014:
015: import junit.framework.*;
016:
017: /**
018: Test that a model is a prefix mapping.
019: @author kers
020: */
021: public class TestModelPrefixMapping extends AbstractTestPrefixMapping {
022: public TestModelPrefixMapping(String name) {
023: super (name);
024: }
025:
026: public static TestSuite suite() {
027: return new TestSuite(TestModelPrefixMapping.class);
028: }
029:
030: protected PrefixMapping getMapping() {
031: return ModelFactory.createDefaultModel();
032: }
033:
034: protected static final String alphaPrefix = "alpha";
035: protected static final String betaPrefix = "beta";
036: protected static final String alphaURI = "http://testing.jena.hpl.hp.com/alpha#";
037: protected static final String betaURI = "http://testing.jena.hpl.hp.com/beta#";
038:
039: protected PrefixMapping baseMap = PrefixMapping.Factory.create()
040: .setNsPrefix(alphaPrefix, alphaURI).setNsPrefix(betaPrefix,
041: betaURI);
042:
043: private PrefixMapping prevMap;
044:
045: public void setPrefixes() {
046: prevMap = ModelCom.setDefaultModelPrefixes(baseMap);
047: }
048:
049: public void restorePrefixes() {
050: ModelCom.setDefaultModelPrefixes(prevMap);
051: }
052:
053: /**
054: Test that a freshly-created Model has the prefixes established by the
055: default in ModelCom.
056: */
057: public void testDefaultPrefixes() {
058: setPrefixes();
059: Model m = ModelFactory.createDefaultModel();
060: assertEquals(baseMap.getNsPrefixMap(), m.getNsPrefixMap());
061: restorePrefixes();
062: }
063:
064: public void testOnlyFreshPrefixes() {
065: setPrefixes();
066: try {
067: doOnlyFreshPrefixes();
068: } finally {
069: restorePrefixes();
070: }
071: }
072:
073: /**
074: Test that existing prefixes are not over-ridden by the default ones.
075: */
076: private void doOnlyFreshPrefixes() {
077: String newURI = "abc:def/";
078: Graph g = Factory.createDefaultGraph();
079: PrefixMapping pm = g.getPrefixMapping();
080: pm.setNsPrefix(alphaPrefix, newURI);
081: Model m = ModelFactory.createModelForGraph(g);
082: assertEquals(newURI, m.getNsPrefixURI(alphaPrefix));
083: assertEquals(betaURI, m.getNsPrefixURI(betaPrefix));
084: }
085:
086: public void testGetDefault() {
087: setPrefixes();
088: try {
089: assertSame(baseMap, ModelCom.getDefaultModelPrefixes());
090: } finally {
091: restorePrefixes();
092: }
093: }
094: }
095:
096: /*
097: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
098: All rights reserved.
099:
100: Redistribution and use in source and binary forms, with or without
101: modification, are permitted provided that the following conditions
102: are met:
103:
104: 1. Redistributions of source code must retain the above copyright
105: notice, this list of conditions and the following disclaimer.
106:
107: 2. Redistributions in binary form must reproduce the above copyright
108: notice, this list of conditions and the following disclaimer in the
109: documentation and/or other materials provided with the distribution.
110:
111: 3. The name of the author may not be used to endorse or promote products
112: derived from this software without specific prior written permission.
113:
114: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
115: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
116: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
117: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
118: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
119: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
120: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
121: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
122: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
123: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
124: */
|