KickJava   Java API By Example, From Geeks To Geeks.

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


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

6
7 package com.hp.hpl.jena.rdf.model.test;
8
9 import com.hp.hpl.jena.rdf.model.*;
10 import com.hp.hpl.jena.shared.*;
11
12 import java.util.*;
13 import junit.framework.*;
14
15 /**
16     Tests of the Model-level bulk update API.
17     
18     @author kers
19 */

20
21 public class TestModelBulkUpdate extends ModelTestBase
22     {
23     public TestModelBulkUpdate( String JavaDoc name )
24         { super( name ); }
25         
26     public static TestSuite suite()
27         { return new TestSuite( TestModelBulkUpdate.class ); }
28
29     public void testMBU()
30         { testMBU( ModelFactory.createDefaultModel() ); }
31         
32     public void testContains( Model m, Statement [] statements )
33         {
34         for (int i = 0; i < statements.length; i += 1)
35             assertTrue( "it should be here", m.contains( statements[i] ) );
36         }
37     
38     public void testContains( Model m, List statements )
39         {
40         for (int i = 0; i < statements.size(); i += 1)
41             assertTrue( "it should be here", m.contains( (Statement) statements.get(i) ) );
42         }
43         
44     public void testOmits( Model m, Statement [] statements )
45         {
46         for (int i = 0; i < statements.length; i += 1)
47             assertFalse( "it should not be here", m.contains( statements[i] ) );
48         }
49
50     public void testOmits( Model m, List statements )
51         {
52         for (int i = 0; i < statements.size(); i += 1)
53             assertFalse( "it should not be here", m.contains( (Statement) statements.get(i) ) );
54         }
55                 
56     public void testMBU( Model m )
57         {
58         Statement [] sArray = statements( m, "moon orbits earth; earth orbits sun" );
59         List sList = Arrays.asList( statements( m, "I drink tea; you drink coffee" ) );
60         m.add( sArray );
61         testContains( m, sArray );
62         m.add( sList );
63         testContains( m, sList );
64         testContains( m, sArray );
65     /* */
66         m.remove( sArray );
67         testOmits( m, sArray );
68         testContains( m, sList );
69         m.remove( sList );
70         testOmits( m, sArray );
71         testOmits( m, sList );
72         }
73         
74     public void testBulkByModel()
75         { testBulkByModel( ModelFactory.createDefaultModel() ); }
76         
77     public void testBulkByModel( Model m )
78         {
79         assertEquals( "precondition: model must be empty", 0, m.size() );
80         Model A = modelWithStatements( "clouds offer rain; trees offer shelter" );
81         Model B = modelWithStatements( "x R y; y Q z; z P x" );
82         m.add( A );
83         assertIsoModels( A, m );
84         m.add( B );
85         m.remove( A );
86         assertIsoModels( B, m );
87         m.remove( B );
88         assertEquals( "", 0, m.size() );
89         }
90         
91     public void testBulkRemoveSelf()
92         {
93         Model m = modelWithStatements( "they sing together; he sings alone" );
94         m.remove( m );
95         assertEquals( "", 0, m.size() );
96         }
97         
98     public void testBulkByModelReifying()
99         {
100         testBulkByModelReifying( false );
101         testBulkByModelReifying( true );
102         }
103         
104     public void testBulkByModelReifying( boolean suppress )
105         {
106         Model m = modelWithStatements( ReificationStyle.Minimal, "a P b" );
107         addReification( m, "x", "S P O" );
108         addReification( m, "a", "x R y" );
109         Model target = modelWithStatements( ReificationStyle.Minimal, "" );
110         target.add( m, suppress );
111         target.setNsPrefixes( PrefixMapping.Standard );
112         assertIsoModels( (suppress ? modelWithStatements("a P b") : m), target );
113         }
114         
115     public void testBulkDeleteByModelReifying()
116         {
117         testBulkDeleteByModelReifying( false );
118         testBulkDeleteByModelReifying( true );
119         }
120         
121     public void testBulkDeleteByModelReifying( boolean suppress )
122         {
123         Model target = modelWithStatements( ReificationStyle.Minimal, "" );
124         addReification( target, "x", "S P O" );
125         addReification( target, "y", "A P B" );
126         Model remove = modelWithStatements( "" );
127         addReification( remove, "y", "A P B" );
128         Model answer = modelWithStatements( "" );
129         addReification( answer, "x", "S P O" );
130         if (suppress) addReification( answer, "y", "A P B" );
131         target.remove( remove, suppress );
132         assertIsoModels( answer, target );
133         }
134         
135     public void addReification( Model m, String JavaDoc tag, String JavaDoc statement )
136         {
137         m.createReifiedStatement( tag, statement( m, statement ) );
138         }
139     }
140
141
142 /*
143     (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
144     All rights reserved.
145
146     Redistribution and use in source and binary forms, with or without
147     modification, are permitted provided that the following conditions
148     are met:
149
150     1. Redistributions of source code must retain the above copyright
151        notice, this list of conditions and the following disclaimer.
152
153     2. Redistributions in binary form must reproduce the above copyright
154        notice, this list of conditions and the following disclaimer in the
155        documentation and/or other materials provided with the distribution.
156
157     3. The name of the author may not be used to endorse or promote products
158        derived from this software without specific prior written permission.
159
160     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
161     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
162     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
163     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
164     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
165     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
166     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
167     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
168     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
169     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
170 */
Popular Tags