KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > rdf > model > test > TestModelExtract


1 /*
2   (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
3   All rights reserved.
4   [See end of file]
5   $Id: TestModelExtract.java,v 1.4 2005/02/21 12:15:02 andy_seaborne Exp $
6 */

7
8 package com.hp.hpl.jena.rdf.model.test;
9
10 import com.hp.hpl.jena.graph.*;
11 import com.hp.hpl.jena.rdf.model.*;
12
13 import junit.framework.TestSuite;
14
15 /**
16  @author hedgehog
17 */

18 public class TestModelExtract extends ModelTestBase
19     {
20     protected static final StatementBoundary sbTrue = new StatementBoundaryBase()
21         {
22         public boolean stopAt( Statement s ) { return true; }
23         };
24         
25     protected static final StatementBoundary sbFalse = new StatementBoundaryBase()
26         {
27         public boolean stopAt( Statement s ) { return false; }
28         };
29
30     public TestModelExtract( String JavaDoc name )
31         { super( name ); }
32     
33     public static TestSuite suite()
34         { return new TestSuite( TestModelExtract.class ); }
35
36     static class MockModelExtract extends ModelExtract
37         {
38         Node root;
39         Graph result;
40         Graph subject;
41        
42         public MockModelExtract( StatementBoundary b )
43             { super( b ); }
44             
45         public StatementBoundary getStatementBoundary()
46             { return boundary; }
47         
48         protected GraphExtract getGraphExtract( TripleBoundary b )
49             {
50             return new GraphExtract( b )
51                 {
52                 public Graph extractInto( Graph toUpdate, Node n, Graph source )
53                     {
54                     root = n;
55                     return result = super.extractInto( toUpdate, n, subject = source );
56                     }
57                 };
58             }
59         }
60     
61     public void testAsTripleBoundary()
62         {
63         Model m = ModelFactory.createDefaultModel();
64         assertTrue( sbTrue.asTripleBoundary( m ).stopAt( triple( "x R y" ) ) );
65         assertFalse( sbFalse.asTripleBoundary( m ).stopAt( triple( "x R y" ) ) );
66         }
67     
68     public void testStatementTripleBoundaryAnon()
69         {
70         TripleBoundary anon = TripleBoundary.stopAtAnonObject;
71         assertSame( anon, new StatementTripleBoundary( anon ).asTripleBoundary( null ) );
72         assertFalse( new StatementTripleBoundary( anon ).stopAt( statement( "s P o" ) ) );
73         assertTrue( new StatementTripleBoundary( anon ).stopAt( statement( "s P _o" ) ) );
74         }
75     
76     public void testStatementContinueWith()
77         {
78         StatementBoundary sb = new StatementBoundaryBase()
79              { public boolean continueWith( Statement s ) { return false; } };
80         assertTrue( sb.stopAt( statement( "x pings y" ) ) );
81         }
82     
83     public void testStatementTripleBoundaryNowhere()
84         {
85         TripleBoundary nowhere = TripleBoundary.stopNowhere;
86         assertSame( nowhere, new StatementTripleBoundary( nowhere ).asTripleBoundary( null ) );
87         assertFalse( new StatementTripleBoundary( nowhere ).stopAt( statement( "s P _o" ) ) );
88         assertFalse( new StatementTripleBoundary( nowhere ).stopAt( statement( "s P o" ) ) );
89         }
90     public void testRemembersBoundary()
91         {
92         assertSame( sbTrue, new MockModelExtract( sbTrue ).getStatementBoundary() );
93         assertSame( sbFalse, new MockModelExtract( sbFalse ).getStatementBoundary() );
94         }
95     
96     public void testInvokesExtract()
97         {
98         MockModelExtract mock = new MockModelExtract( sbTrue );
99         Model source = modelWithStatements( "a R b" );
100         Model m = mock.extract( resource( "a" ), source );
101         assertEquals( node( "a" ), mock.root );
102         assertSame( mock.result, m.getGraph() );
103         assertSame( mock.subject, source.getGraph() );
104         }
105
106     /* (non-Javadoc)
107      * @see com.hp.hpl.jena.rdf.model.StatementBoundary#stopAt(com.hp.hpl.jena.rdf.model.Statement)
108      */

109     public boolean stopAt( Statement s )
110         {
111         // TODO Auto-generated method stub
112
return false;
113         }
114
115     /* (non-Javadoc)
116      * @see com.hp.hpl.jena.rdf.model.StatementBoundary#asTripleBoundary(com.hp.hpl.jena.rdf.model.Model)
117      */

118     public TripleBoundary asTripleBoundary( Model m )
119         {
120         // TODO Auto-generated method stub
121
return null;
122         }
123     }
124
125 /*
126  * (c) Copyright 2000, 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
127  * All rights reserved.
128  *
129  * Redistribution and use in source and binary forms, with or without
130  * modification, are permitted provided that the following conditions
131  * are met:
132  * 1. Redistributions of source code must retain the above copyright
133  * notice, this list of conditions and the following disclaimer.
134  * 2. Redistributions in binary form must reproduce the above copyright
135  * notice, this list of conditions and the following disclaimer in the
136  * documentation and/or other materials provided with the distribution.
137  * 3. The name of the author may not be used to endorse or promote products
138  * derived from this software without specific prior written permission.
139  *
140  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
141  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
142  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
143  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
144  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
145  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
146  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
147  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
148  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
149  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
150  */

151
Popular Tags