001: /*
002: (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: All rights reserved - see end of file.
004: $Id: TestDomain.java,v 1.4 2008/01/02 12:08:56 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.graph.query.test;
008:
009: import java.util.*;
010:
011: import com.hp.hpl.jena.graph.query.Domain;
012:
013: import junit.framework.*;
014:
015: /**
016: Post-hoc tests for Domain, added because Domain::equals was broken: it
017: didn't work for comparing against a non-Domain List.
018: @author kers
019: */
020: public class TestDomain extends QueryTestBase {
021: public TestDomain(String name) {
022: super (name);
023: }
024:
025: public static TestSuite suite() {
026: return new TestSuite(TestDomain.class);
027: }
028:
029: public void testDomainGet() {
030: Domain d = domain("a 'b' 17 _x");
031: assertEquals(node("a"), d.get(0));
032: assertEquals(node("'b'"), d.get(1));
033: assertEquals(node("17"), d.get(2));
034: assertEquals(node("_x"), d.get(3));
035: }
036:
037: public void testDomainGetElement() {
038: Domain d = domain("X 'why' 42 _z9m9z");
039: assertEquals(node("X"), d.getElement(0));
040: assertEquals(node("'why'"), d.getElement(1));
041: assertEquals(node("42"), d.getElement(2));
042: assertEquals(node("_z9m9z"), d.getElement(3));
043: }
044:
045: public void testSetElement() {
046: Domain d = domain("A B C D");
047: d.setElement(0, node("X"));
048: assertEquals(node("X"), d.getElement(0));
049: d.setElement(2, node("Z"));
050: assertEquals(node("Z"), d.getElement(2));
051: assertEquals(node("X"), d.getElement(0));
052: }
053:
054: public void testEqualsList() {
055: Domain d = new Domain(2);
056: List L = new ArrayList();
057: d.setElement(0, node("a"));
058: L.add(node("a"));
059: d.setElement(1, node("b"));
060: L.add(node("b"));
061: assertEquals(L, d);
062: assertEquals(d, L);
063: }
064:
065: public void testSize() {
066: assertEquals(0, domain("").size());
067: assertEquals(1, domain("X").size());
068: assertEquals(5, domain("a song in the wind").size());
069: }
070:
071: public void testCopiesDistinctButEqual() {
072: Domain d = domain("a lot of bottle");
073: assertNotSame(d, d.copy());
074: assertEquals(d, d.copy());
075: }
076:
077: private Domain domain(String string) {
078: return new Domain(nodeArray(string));
079: }
080: }
081:
082: /*
083: * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
084: * All rights reserved.
085: *
086: * Redistribution and use in source and binary forms, with or without
087: * modification, are permitted provided that the following conditions
088: * are met:
089: * 1. Redistributions of source code must retain the above copyright
090: * notice, this list of conditions and the following disclaimer.
091: * 2. Redistributions in binary form must reproduce the above copyright
092: * notice, this list of conditions and the following disclaimer in the
093: * documentation and/or other materials provided with the distribution.
094: * 3. The name of the author may not be used to endorse or promote products
095: * derived from this software without specific prior written permission.
096: *
097: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
098: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
099: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
100: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
101: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
102: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
103: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
104: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
105: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
106: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
107: */
|