001: /*
002: (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP, all rights reserved.
003: [See end of file]
004: $Id: AbstractTestReifierTripleMap.java,v 1.7 2008/01/02 12:05:31 andy_seaborne Exp $
005: */
006: package com.hp.hpl.jena.graph.test;
007:
008: import com.hp.hpl.jena.graph.*;
009: import com.hp.hpl.jena.graph.impl.ReifierTripleMap;
010:
011: /**
012: TestReifierTripleMap
013: @author kers
014: */
015: public abstract class AbstractTestReifierTripleMap extends
016: GraphTestBase {
017:
018: public AbstractTestReifierTripleMap(String name) {
019: super (name);
020: }
021:
022: protected abstract ReifierTripleMap getTripleMap();
023:
024: protected ReifierTripleMap tripleMap = getTripleMap();
025:
026: protected static final Triple triple_xRy = triple("x R y");
027: protected static final Triple triple_aRb = triple("a R b");
028:
029: protected static final Node nodeA = node("a");
030: protected static final Node nodeB = node("b");
031: protected static final Node nodeC = node("c");
032:
033: public void testEmptyMap() {
034: assertEquals(null, tripleMap.getTriple(nodeA));
035: assertEquals(null, tripleMap.getTriple(nodeB));
036: assertEquals(false, tripleMap.hasTriple(triple_xRy));
037: assertEquals(false, tripleMap.tagIterator().hasNext());
038: assertEquals(false, tripleMap.tagIterator(triple_aRb).hasNext());
039: assertFalse(tripleMap.find(Triple.ANY).hasNext());
040: }
041:
042: public void testPutTriple_hasTriple() {
043: tripleMap.putTriple(nodeA, triple_xRy);
044: assertEquals(true, tripleMap.hasTriple(triple_xRy));
045: assertEquals(false, tripleMap.hasTriple(triple("x R z")));
046: }
047:
048: public void testPutTriple_getTriple() {
049: tripleMap.putTriple(nodeA, triple_xRy);
050: assertEquals(triple_xRy, tripleMap.getTriple(nodeA));
051: assertEquals(null, tripleMap.getTriple(nodeB));
052: }
053:
054: public void testPutTriple_tagIterator() {
055: tripleMap.putTriple(nodeA, triple_xRy);
056: assertEquals(nodeSet("a"), iteratorToSet(tripleMap
057: .tagIterator()));
058: }
059:
060: public void testPutTriple_tagIteratorT() {
061: tripleMap.putTriple(nodeA, triple_xRy);
062: assertEquals(nodeSet("a"), iteratorToSet(tripleMap
063: .tagIterator(triple_xRy)));
064: assertEquals(nodeSet(""), iteratorToSet(tripleMap
065: .tagIterator(triple("x S y"))));
066: }
067:
068: public void testPutTriples_hasTriple() {
069: put_xRy_and_aRb();
070: assertEquals(true, tripleMap.hasTriple(triple_xRy));
071: assertEquals(true, tripleMap.hasTriple(triple_aRb));
072: }
073:
074: public void testPutTriples_getTriple() {
075: put_xRy_and_aRb();
076: assertEquals(triple_xRy, tripleMap.getTriple(nodeA));
077: assertEquals(triple_aRb, tripleMap.getTriple(nodeB));
078: }
079:
080: public void testPutTriples_tagIterator() {
081: put_xRy_and_aRb();
082: assertEquals(nodeSet("a b"), iteratorToSet(tripleMap
083: .tagIterator()));
084: }
085:
086: public void testPutTriples_tagIteratorT() {
087: put_xRy_and_aRb();
088: assertEquals(nodeSet("a"), iteratorToSet(tripleMap
089: .tagIterator(triple_xRy)));
090: assertEquals(nodeSet("b"), iteratorToSet(tripleMap
091: .tagIterator(triple_aRb)));
092: }
093:
094: public void testMultipleTagging() {
095: tripleMap.putTriple(nodeA, triple_xRy);
096: tripleMap.putTriple(nodeB, triple_xRy);
097: assertEquals(nodeSet("a b"), iteratorToSet(tripleMap
098: .tagIterator(triple_xRy)));
099: }
100:
101: public void testRemoveTriplesByTag() {
102: put_xRy_and_aRb();
103: tripleMap.removeTriple(nodeA);
104: assertEquals(nodeSet("b"), iteratorToSet(tripleMap
105: .tagIterator()));
106: assertEquals(nodeSet("b"), iteratorToSet(tripleMap
107: .tagIterator(triple_aRb)));
108: assertEquals(nodeSet(""), iteratorToSet(tripleMap
109: .tagIterator(triple_xRy)));
110: }
111:
112: public void testRemoveTaggedTriple() {
113: put_xRy_and_aRb();
114: tripleMap.removeTriple(nodeA, triple_xRy);
115: assertEquals(null, tripleMap.getTriple(nodeA));
116: assertEquals(triple_aRb, tripleMap.getTriple(nodeB));
117: assertEquals(nodeSet("b"), iteratorToSet(tripleMap
118: .tagIterator(triple_aRb)));
119: assertEquals(nodeSet(""), iteratorToSet(tripleMap
120: .tagIterator(triple_xRy)));
121: }
122:
123: public void testRemoveTripleDirectly() {
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
131: .tagIterator(triple_aRb)));
132: assertEquals(nodeSet(""), iteratorToSet(tripleMap
133: .tagIterator(triple_xRy)));
134: }
135:
136: protected void put_xRy_and_aRb() {
137: tripleMap.putTriple(nodeA, triple_xRy);
138: tripleMap.putTriple(nodeB, triple_aRb);
139: }
140:
141: }
142:
143: /*
144: (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
145: All rights reserved.
146:
147: Redistribution and use in source and binary forms, with or without
148: modification, are permitted provided that the following conditions
149: are met:
150:
151: 1. Redistributions of source code must retain the above copyright
152: notice, this list of conditions and the following disclaimer.
153:
154: 2. Redistributions in binary form must reproduce the above copyright
155: notice, this list of conditions and the following disclaimer in the
156: documentation and/or other materials provided with the distribution.
157:
158: 3. The name of the author may not be used to endorse or promote products
159: derived from this software without specific prior written permission.
160:
161: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
162: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
163: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
164: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
165: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
166: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
167: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
168: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
169: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
170: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
171: */
|