KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > graph > test > AbstractTestReifierTripleMap


1 /*
2   (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP, all rights reserved.
3   [See end of file]
4   $Id: AbstractTestReifierTripleMap.java,v 1.4 2005/02/21 11:52:37 andy_seaborne Exp $
5 */

6 package com.hp.hpl.jena.graph.test;
7
8 import com.hp.hpl.jena.graph.*;
9 import com.hp.hpl.jena.graph.impl.ReifierTripleMap;
10
11 /**
12      TestReifierTripleMap
13      @author kers
14 */

15 public abstract class AbstractTestReifierTripleMap extends GraphTestBase
16     {
17     
18     public AbstractTestReifierTripleMap( String JavaDoc name )
19         { super( name ); }
20
21     protected abstract ReifierTripleMap getTripleMap();
22         
23     protected ReifierTripleMap tripleMap = getTripleMap();
24
25     protected static final Triple triple_xRy = triple( "x R y" );
26     protected static final Triple triple_aRb = triple( "a R b" );
27     
28     protected static final Node nodeA = node( "a" );
29     protected static final Node nodeB = node( "b" );
30     protected static final Node nodeC = node( "c" );
31     
32     public void testEmptyMap()
33         {
34         assertEquals( null, tripleMap.getTriple( nodeA ) );
35         assertEquals( null, tripleMap.getTriple( nodeB ) );
36         assertEquals( false, tripleMap.hasTriple( triple_xRy ) );
37         assertEquals( false, tripleMap.tagIterator().hasNext() );
38         assertEquals( false, tripleMap.tagIterator( triple_aRb ).hasNext() );
39         assertFalse( tripleMap.find( Triple.ANY ).hasNext() );
40         }
41     
42     public void testPutTriple_hasTriple()
43         {
44         tripleMap.putTriple( nodeA, triple_xRy );
45         assertEquals( true, tripleMap.hasTriple( triple_xRy ) );
46         assertEquals( false, tripleMap.hasTriple( triple( "x R z" ) ) );
47         }
48     
49     public void testPutTriple_getTriple()
50         {
51         tripleMap.putTriple( nodeA, triple_xRy );
52         assertEquals( triple_xRy, tripleMap.getTriple( nodeA ) );
53         assertEquals( null, tripleMap.getTriple( nodeB ) );
54         }
55     
56     public void testPutTriple_tagIterator()
57         {
58         tripleMap.putTriple( nodeA, triple_xRy );
59         assertEquals( nodeSet( "a" ), iteratorToSet( tripleMap.tagIterator() ) );
60         }
61     
62     public void testPutTriple_tagIteratorT()
63         {
64         tripleMap.putTriple( nodeA, triple_xRy );
65         assertEquals( nodeSet( "a" ), iteratorToSet( tripleMap.tagIterator( triple_xRy ) ) );
66         assertEquals( nodeSet( "" ), iteratorToSet( tripleMap.tagIterator( triple( "x S y" ) ) ) );
67         }
68     
69     public void testPutTriples_hasTriple()
70         {
71         put_xRy_and_aRb();
72         assertEquals( true, tripleMap.hasTriple( triple_xRy ) );
73         assertEquals( true, tripleMap.hasTriple( triple_aRb ) );
74         }
75     
76     public void testPutTriples_getTriple()
77         {
78         put_xRy_and_aRb();
79         assertEquals( triple_xRy, tripleMap.getTriple( nodeA ) );
80         assertEquals( triple_aRb, tripleMap.getTriple( nodeB ) );
81         }
82     
83     public void testPutTriples_tagIterator()
84         {
85         put_xRy_and_aRb();
86         assertEquals( nodeSet( "a b" ), iteratorToSet( tripleMap.tagIterator() ) );
87         }
88     
89     public void testPutTriples_tagIteratorT()
90         {
91         put_xRy_and_aRb();
92         assertEquals( nodeSet( "a" ), iteratorToSet( tripleMap.tagIterator( triple_xRy ) ) );
93         assertEquals( nodeSet( "b" ), iteratorToSet( tripleMap.tagIterator( triple_aRb ) ) );
94         }
95     
96     public void testMultipleTagging()
97         {
98         tripleMap.putTriple( nodeA, triple_xRy );
99         tripleMap.putTriple( nodeB, triple_xRy );
100         assertEquals( nodeSet( "a b" ), iteratorToSet( tripleMap.tagIterator( triple_xRy ) ) );
101         }
102     
103     public void testRemoveTriplesByTag()
104         {
105         put_xRy_and_aRb();
106         tripleMap.removeTriple( nodeA );
107         assertEquals( nodeSet( "b" ), iteratorToSet( tripleMap.tagIterator() ) );
108         assertEquals( nodeSet( "b" ), iteratorToSet( tripleMap.tagIterator( triple_aRb ) ) );
109         assertEquals( nodeSet( "" ), iteratorToSet( tripleMap.tagIterator( triple_xRy ) ) );
110         }
111     
112     public void testRemoveTaggedTriple()
113         {
114         put_xRy_and_aRb();
115         tripleMap.removeTriple( nodeA, triple_xRy );
116         assertEquals( null, tripleMap.getTriple( nodeA ) );
117         assertEquals( triple_aRb, tripleMap.getTriple( nodeB ) );
118         assertEquals( nodeSet( "b" ), iteratorToSet( tripleMap.tagIterator( triple_aRb ) ) );
119         assertEquals( nodeSet( "" ), iteratorToSet( tripleMap.tagIterator( triple_xRy ) ) );
120         }
121     
122     public void testRemoveTripleDirectly()
123         {
124         put_xRy_and_aRb();
125         tripleMap.putTriple( nodeC, triple_xRy );
126         tripleMap.removeTriple( triple_xRy );
127         assertEquals( null, tripleMap.getTriple( nodeA ) );
128         assertEquals( null, tripleMap.getTriple( nodeC ) );
129         assertEquals( triple_aRb, tripleMap.getTriple( nodeB ) );
130         assertEquals( nodeSet( "b" ), iteratorToSet( tripleMap.tagIterator( triple_aRb ) ) );
131         assertEquals( nodeSet( "" ), iteratorToSet( tripleMap.tagIterator( triple_xRy ) ) );
132         }
133     
134     protected void put_xRy_and_aRb()
135         {
136         tripleMap.putTriple( nodeA, triple_xRy );
137         tripleMap.putTriple( nodeB, triple_aRb );
138         }
139
140     }
141
142 /*
143     (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
144     All rights reserved.
145     
146     Redistribution and use in source and binary forms, with or without
147     modification, are permitted provided that the following conditions
148     are met:
149     
150     1. Redistributions of source code must retain the above copyright
151        notice, this list of conditions and the following disclaimer.
152     
153     2. Redistributions in binary form must reproduce the above copyright
154        notice, this list of conditions and the following disclaimer in the
155        documentation and/or other materials provided with the distribution.
156     
157     3. The name of the author may not be used to endorse or promote products
158        derived from this software without specific prior written permission.
159     
160     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
161     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
162     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
163     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
164     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
165     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
166     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
167     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
168     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
169     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
170 */
Popular Tags