Source code: com/hp/hpl/jena/graph/compose/test/TestPolyadicPrefixMapping.java
1 /*
2 (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
3 [See end of file]
4 $Id: TestPolyadicPrefixMapping.java,v 1.4 2005/02/21 11:52:08 andy_seaborne Exp $
5 */
6
7 package com.hp.hpl.jena.graph.compose.test;
8
9 import junit.framework.TestSuite;
10
11 import com.hp.hpl.jena.graph.*;
12 import com.hp.hpl.jena.graph.compose.*;
13 import com.hp.hpl.jena.shared.PrefixMapping;
14 import com.hp.hpl.jena.shared.test.AbstractTestPrefixMapping;
15
16
17 public class TestPolyadicPrefixMapping extends AbstractTestPrefixMapping
18 {
19 public TestPolyadicPrefixMapping( String name )
20 { super( name ); }
21
22 public static TestSuite suite()
23 { return new TestSuite( TestPolyadicPrefixMapping.class ); }
24
25 Graph gBase;
26 Graph g1, g2;
27 Polyadic poly;
28
29 protected static final String alpha = "something:alpha#";
30 protected static final String beta = "something:beta#";
31
32 public void setUp()
33 {
34 gBase = Factory.createDefaultGraph();
35 g1 = Factory.createDefaultGraph();
36 g2 = Factory.createDefaultGraph();
37 poly = new MultiUnion( new Graph[] {gBase, g1, g2} );
38 poly.setBaseGraph( gBase );
39 }
40
41 protected PrefixMapping getMapping()
42 {
43 Graph gBase = Factory.createDefaultGraph();
44 Graph g1 = Factory.createDefaultGraph();
45 Graph g2 = Factory.createDefaultGraph();
46 Polyadic poly = new MultiUnion( new Graph[] {gBase, g1, g2} );
47 return new PolyadicPrefixMappingImpl( poly );
48 }
49
50 /*
51 tests for polyadic prefix mappings
52 (a) base mapping is the mutable one
53 (b) base mapping over-rides all others
54 (c) non-overridden mappings in other maps are visible
55 */
56
57 public void testOnlyBaseMutated()
58 {
59 poly.getPrefixMapping().setNsPrefix( "a", alpha );
60 assertEquals( null, g1.getPrefixMapping().getNsPrefixURI( "a" ) );
61 assertEquals( null, g2.getPrefixMapping().getNsPrefixURI( "a" ) );
62 assertEquals( alpha, gBase.getPrefixMapping().getNsPrefixURI( "a" ) );
63 }
64
65 public void testUpdatesVisible()
66 {
67 g1.getPrefixMapping().setNsPrefix( "a", alpha );
68 g2.getPrefixMapping().setNsPrefix( "b", beta );
69 assertEquals( alpha, poly.getPrefixMapping().getNsPrefixURI( "a" ) );
70 assertEquals( beta, poly.getPrefixMapping().getNsPrefixURI( "b" ) );
71 }
72
73 public void testUpdatesOverridden()
74 {
75 g1.getPrefixMapping().setNsPrefix( "x", alpha );
76 poly.getPrefixMapping().setNsPrefix( "x", beta );
77 assertEquals( beta, poly.getPrefixMapping().getNsPrefixURI( "x" ) );
78 }
79
80 public void testQNameComponents()
81 {
82 g1.getPrefixMapping().setNsPrefix( "x", alpha );
83 g2.getPrefixMapping().setNsPrefix( "y", beta );
84 assertEquals( "x:hoop", poly.getPrefixMapping().qnameFor( alpha + "hoop" ) );
85 assertEquals( "y:lens", poly.getPrefixMapping().qnameFor( beta + "lens" ) );
86 }
87
88 }
89
90 /*
91 (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
92 All rights reserved.
93
94 Redistribution and use in source and binary forms, with or without
95 modification, are permitted provided that the following conditions
96 are met:
97
98 1. Redistributions of source code must retain the above copyright
99 notice, this list of conditions and the following disclaimer.
100
101 2. Redistributions in binary form must reproduce the above copyright
102 notice, this list of conditions and the following disclaimer in the
103 documentation and/or other materials provided with the distribution.
104
105 3. The name of the author may not be used to endorse or promote products
106 derived from this software without specific prior written permission.
107
108 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
109 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
110 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
111 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
112 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
113 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
114 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
115 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
116 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
117 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
118 */