001: /*
002: (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: All rights reserved - see end of file.
004: $Id: TestTripleField.java,v 1.6 2008/01/02 12:05:34 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.graph.test;
008:
009: import junit.framework.TestSuite;
010:
011: import com.hp.hpl.jena.graph.*;
012: import com.hp.hpl.jena.graph.Triple.*;
013: import com.hp.hpl.jena.util.iterator.Filter;
014:
015: /**
016: @author kers
017: */
018: public class TestTripleField extends GraphTestBase {
019: public TestTripleField(String name) {
020: super (name);
021: }
022:
023: public static TestSuite suite() {
024: return new TestSuite(TestTripleField.class);
025: }
026:
027: public void testFieldsExistAndAreTyped() {
028: assertInstanceOf(Triple.Field.class, Triple.Field.getSubject);
029: assertInstanceOf(Triple.Field.class, Triple.Field.getObject);
030: assertInstanceOf(Triple.Field.class, Triple.Field.getPredicate);
031: }
032:
033: public void testGetSubject() {
034: assertEquals(node("s"), Field.getSubject
035: .getField(triple("s p o")));
036: }
037:
038: public void testGetObject() {
039: assertEquals(node("o"), Field.getObject
040: .getField(triple("s p o")));
041: }
042:
043: public void testGetPredicate() {
044: assertEquals(node("p"), Field.getPredicate
045: .getField(triple("s p o")));
046: }
047:
048: public void testFilterSubject() {
049: assertTrue(Field.getSubject.filterOn(node("a")).accept(
050: triple("a P b")));
051: assertFalse(Field.getSubject.filterOn(node("x")).accept(
052: triple("a P b")));
053: }
054:
055: public void testFilterObject() {
056: assertTrue(Field.getObject.filterOn(node("b")).accept(
057: triple("a P b")));
058: assertFalse(Field.getObject.filterOn(node("c")).accept(
059: triple("a P b")));
060: }
061:
062: public void testFilterPredicate() {
063: assertTrue(Field.getPredicate.filterOn(node("P")).accept(
064: triple("a P b")));
065: assertFalse(Field.getPredicate.filterOn(node("Q")).accept(
066: triple("a P b")));
067: }
068:
069: public void testFilterByTriple() {
070: assertTrue(Field.getSubject.filterOn(triple("s P o")).accept(
071: triple("s Q p")));
072: assertFalse(Field.getSubject.filterOn(triple("s P o")).accept(
073: triple("x Q p")));
074: }
075:
076: public void testWildcardFilterIsAny() {
077: assertSame(Filter.any, Field.getSubject
078: .filterOn(triple("?x R s")));
079: assertSame(Filter.any, Field.getObject
080: .filterOn(triple("x R ?s")));
081: assertSame(Filter.any, Field.getPredicate
082: .filterOn(triple("x ?R s")));
083: }
084: }
085:
086: /*
087: * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
088: * All rights reserved.
089: *
090: * Redistribution and use in source and binary forms, with or without
091: * modification, are permitted provided that the following conditions
092: * are met:
093: * 1. Redistributions of source code must retain the above copyright
094: * notice, this list of conditions and the following disclaimer.
095: * 2. Redistributions in binary form must reproduce the above copyright
096: * notice, this list of conditions and the following disclaimer in the
097: * documentation and/or other materials provided with the distribution.
098: * 3. The name of the author may not be used to endorse or promote products
099: * derived from this software without specific prior written permission.
100: *
101: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
102: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
103: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
104: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
105: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
106: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
107: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
108: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
109: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
110: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
111: */
|