001: /*
002: (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: [See end of file]
004: $Id: TestPolyadicPrefixMapping.java,v 1.9 2008/01/02 12:07:21 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.graph.compose.test;
008:
009: import junit.framework.TestSuite;
010:
011: import com.hp.hpl.jena.graph.*;
012: import com.hp.hpl.jena.graph.compose.*;
013: import com.hp.hpl.jena.shared.PrefixMapping;
014: import com.hp.hpl.jena.shared.test.AbstractTestPrefixMapping;
015:
016: public class TestPolyadicPrefixMapping extends
017: AbstractTestPrefixMapping {
018: public TestPolyadicPrefixMapping(String name) {
019: super (name);
020: }
021:
022: public static TestSuite suite() {
023: return new TestSuite(TestPolyadicPrefixMapping.class);
024: }
025:
026: Graph gBase;
027: Graph g1, g2;
028:
029: /**
030: Will be a polyadic graph with base gBase and subs g1, g2.
031: */
032: Polyadic poly;
033:
034: protected static final String alpha = "something:alpha#";
035: protected static final String beta = "something:beta#";
036:
037: public void setUp() {
038: gBase = Factory.createDefaultGraph();
039: g1 = Factory.createDefaultGraph();
040: g2 = Factory.createDefaultGraph();
041: poly = new MultiUnion(new Graph[] { gBase, g1, g2 });
042: poly.setBaseGraph(gBase);
043: }
044:
045: protected PrefixMapping getMapping() {
046: Graph gBase = Factory.createDefaultGraph();
047: Graph g1 = Factory.createDefaultGraph();
048: Graph g2 = Factory.createDefaultGraph();
049: Polyadic poly = new MultiUnion(new Graph[] { gBase, g1, g2 });
050: return new PolyadicPrefixMappingImpl(poly);
051: }
052:
053: /*
054: tests for polyadic prefix mappings
055: (a) base mapping is the mutable one
056: (b) base mapping over-rides all others
057: (c) non-overridden mappings in other maps are visible
058: */
059:
060: public void testOnlyBaseMutated() {
061: poly.getPrefixMapping().setNsPrefix("a", alpha);
062: assertEquals(null, g1.getPrefixMapping().getNsPrefixURI("a"));
063: assertEquals(null, g2.getPrefixMapping().getNsPrefixURI("a"));
064: assertEquals(alpha, gBase.getPrefixMapping()
065: .getNsPrefixURI("a"));
066: }
067:
068: public void testUpdatesVisible() {
069: g1.getPrefixMapping().setNsPrefix("a", alpha);
070: g2.getPrefixMapping().setNsPrefix("b", beta);
071: assertEquals(alpha, poly.getPrefixMapping().getNsPrefixURI("a"));
072: assertEquals(beta, poly.getPrefixMapping().getNsPrefixURI("b"));
073: }
074:
075: public void testUpdatesOverridden() {
076: g1.getPrefixMapping().setNsPrefix("x", alpha);
077: poly.getPrefixMapping().setNsPrefix("x", beta);
078: assertEquals(beta, poly.getPrefixMapping().getNsPrefixURI("x"));
079: }
080:
081: public void testQNameComponents() {
082: g1.getPrefixMapping().setNsPrefix("x", alpha);
083: g2.getPrefixMapping().setNsPrefix("y", beta);
084: assertEquals("x:hoop", poly.getPrefixMapping().qnameFor(
085: alpha + "hoop"));
086: assertEquals("y:lens", poly.getPrefixMapping().qnameFor(
087: beta + "lens"));
088: }
089:
090: /**
091: Test that the default namespace of a sub-graph doesn't appear as a
092: default namespace of the polyadic graph.
093: */
094: public void testSubgraphsDontPolluteDefaultPrefix() {
095: String imported = "http://imported#", local = "http://local#";
096: g1.getPrefixMapping().setNsPrefix("", imported);
097: poly.getPrefixMapping().setNsPrefix("", local);
098: assertEquals(null, poly.getPrefixMapping().getNsURIPrefix(
099: imported));
100: }
101:
102: public void testPolyDoesntSeeImportedDefaultPrefix() {
103: String imported = "http://imported#";
104: g1.getPrefixMapping().setNsPrefix("", imported);
105: assertEquals(null, poly.getPrefixMapping().getNsPrefixURI(""));
106: }
107:
108: }
109:
110: /*
111: (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
112: All rights reserved.
113:
114: Redistribution and use in source and binary forms, with or without
115: modification, are permitted provided that the following conditions
116: are met:
117:
118: 1. Redistributions of source code must retain the above copyright
119: notice, this list of conditions and the following disclaimer.
120:
121: 2. Redistributions in binary form must reproduce the above copyright
122: notice, this list of conditions and the following disclaimer in the
123: documentation and/or other materials provided with the distribution.
124:
125: 3. The name of the author may not be used to endorse or promote products
126: derived from this software without specific prior written permission.
127:
128: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
129: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
130: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
131: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
132: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
133: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
134: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
135: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
136: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
137: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
138: */
|