001: /*
002: (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: All rights reserved.
004: [See end of file]
005: $Id: TestModelExtract.java,v 1.7 2008/01/02 12:04:44 andy_seaborne Exp $
006: */
007:
008: package com.hp.hpl.jena.rdf.model.test;
009:
010: import com.hp.hpl.jena.graph.*;
011: import com.hp.hpl.jena.rdf.model.*;
012:
013: import junit.framework.TestSuite;
014:
015: /**
016: @author hedgehog
017: */
018: public class TestModelExtract extends ModelTestBase {
019: protected static final StatementBoundary sbTrue = new StatementBoundaryBase() {
020: public boolean stopAt(Statement s) {
021: return true;
022: }
023: };
024:
025: protected static final StatementBoundary sbFalse = new StatementBoundaryBase() {
026: public boolean stopAt(Statement s) {
027: return false;
028: }
029: };
030:
031: public TestModelExtract(String name) {
032: super (name);
033: }
034:
035: public static TestSuite suite() {
036: return new TestSuite(TestModelExtract.class);
037: }
038:
039: static class MockModelExtract extends ModelExtract {
040: Node root;
041: Graph result;
042: Graph subject;
043:
044: public MockModelExtract(StatementBoundary b) {
045: super (b);
046: }
047:
048: public StatementBoundary getStatementBoundary() {
049: return boundary;
050: }
051:
052: protected GraphExtract getGraphExtract(TripleBoundary b) {
053: return new GraphExtract(b) {
054: public Graph extractInto(Graph toUpdate, Node n,
055: Graph source) {
056: root = n;
057: return result = super .extractInto(toUpdate, n,
058: subject = source);
059: }
060: };
061: }
062: }
063:
064: public void testAsTripleBoundary() {
065: Model m = ModelFactory.createDefaultModel();
066: assertTrue(sbTrue.asTripleBoundary(m).stopAt(triple("x R y")));
067: assertFalse(sbFalse.asTripleBoundary(m).stopAt(triple("x R y")));
068: }
069:
070: public void testStatementTripleBoundaryAnon() {
071: TripleBoundary anon = TripleBoundary.stopAtAnonObject;
072: assertSame(anon, new StatementTripleBoundary(anon)
073: .asTripleBoundary(null));
074: assertFalse(new StatementTripleBoundary(anon)
075: .stopAt(statement("s P o")));
076: assertTrue(new StatementTripleBoundary(anon)
077: .stopAt(statement("s P _o")));
078: }
079:
080: public void testStatementContinueWith() {
081: StatementBoundary sb = new StatementBoundaryBase() {
082: public boolean continueWith(Statement s) {
083: return false;
084: }
085: };
086: assertTrue(sb.stopAt(statement("x pings y")));
087: }
088:
089: public void testStatementTripleBoundaryNowhere() {
090: TripleBoundary nowhere = TripleBoundary.stopNowhere;
091: assertSame(nowhere, new StatementTripleBoundary(nowhere)
092: .asTripleBoundary(null));
093: assertFalse(new StatementTripleBoundary(nowhere)
094: .stopAt(statement("s P _o")));
095: assertFalse(new StatementTripleBoundary(nowhere)
096: .stopAt(statement("s P o")));
097: }
098:
099: public void testRemembersBoundary() {
100: assertSame(sbTrue, new MockModelExtract(sbTrue)
101: .getStatementBoundary());
102: assertSame(sbFalse, new MockModelExtract(sbFalse)
103: .getStatementBoundary());
104: }
105:
106: public void testInvokesExtract() {
107: MockModelExtract mock = new MockModelExtract(sbTrue);
108: Model source = modelWithStatements("a R b");
109: Model m = mock.extract(resource("a"), source);
110: assertEquals(node("a"), mock.root);
111: assertSame(mock.result, m.getGraph());
112: assertSame(mock.subject, source.getGraph());
113: }
114:
115: /* (non-Javadoc)
116: * @see com.hp.hpl.jena.rdf.model.StatementBoundary#stopAt(com.hp.hpl.jena.rdf.model.Statement)
117: */
118: public boolean stopAt(Statement s) {
119: // TODO Auto-generated method stub
120: return false;
121: }
122:
123: /* (non-Javadoc)
124: * @see com.hp.hpl.jena.rdf.model.StatementBoundary#asTripleBoundary(com.hp.hpl.jena.rdf.model.Model)
125: */
126: public TripleBoundary asTripleBoundary(Model m) {
127: // TODO Auto-generated method stub
128: return null;
129: }
130: }
131:
132: /*
133: * (c) Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
134: * All rights reserved.
135: *
136: * Redistribution and use in source and binary forms, with or without
137: * modification, are permitted provided that the following conditions
138: * are met:
139: * 1. Redistributions of source code must retain the above copyright
140: * notice, this list of conditions and the following disclaimer.
141: * 2. Redistributions in binary form must reproduce the above copyright
142: * notice, this list of conditions and the following disclaimer in the
143: * documentation and/or other materials provided with the distribution.
144: * 3. The name of the author may not be used to endorse or promote products
145: * derived from this software without specific prior written permission.
146: *
147: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
148: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
149: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
150: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
151: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
152: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
153: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
154: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
155: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
156: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
157: */
|