001: /*
002: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: [See end of file]
004: $Id: TestModelBulkUpdate.java,v 1.13 2008/01/02 12:04:40 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.rdf.model.test;
008:
009: import com.hp.hpl.jena.rdf.model.*;
010: import com.hp.hpl.jena.shared.*;
011:
012: import java.util.*;
013: import junit.framework.*;
014:
015: /**
016: Tests of the Model-level bulk update API.
017:
018: @author kers
019: */
020:
021: public class TestModelBulkUpdate extends ModelTestBase {
022: public TestModelBulkUpdate(String name) {
023: super (name);
024: }
025:
026: public static TestSuite suite() {
027: return new TestSuite(TestModelBulkUpdate.class);
028: }
029:
030: public void testMBU() {
031: testMBU(ModelFactory.createDefaultModel());
032: }
033:
034: public void testContains(Model m, Statement[] statements) {
035: for (int i = 0; i < statements.length; i += 1)
036: assertTrue("it should be here", m.contains(statements[i]));
037: }
038:
039: public void testContains(Model m, List statements) {
040: for (int i = 0; i < statements.size(); i += 1)
041: assertTrue("it should be here", m
042: .contains((Statement) statements.get(i)));
043: }
044:
045: public void testOmits(Model m, Statement[] statements) {
046: for (int i = 0; i < statements.length; i += 1)
047: assertFalse("it should not be here", m
048: .contains(statements[i]));
049: }
050:
051: public void testOmits(Model m, List statements) {
052: for (int i = 0; i < statements.size(); i += 1)
053: assertFalse("it should not be here", m
054: .contains((Statement) statements.get(i)));
055: }
056:
057: public void testMBU(Model m) {
058: Statement[] sArray = statements(m,
059: "moon orbits earth; earth orbits sun");
060: List sList = Arrays.asList(statements(m,
061: "I drink tea; you drink coffee"));
062: m.add(sArray);
063: testContains(m, sArray);
064: m.add(sList);
065: testContains(m, sList);
066: testContains(m, sArray);
067: /* */
068: m.remove(sArray);
069: testOmits(m, sArray);
070: testContains(m, sList);
071: m.remove(sList);
072: testOmits(m, sArray);
073: testOmits(m, sList);
074: }
075:
076: public void testBulkByModel() {
077: testBulkByModel(ModelFactory.createDefaultModel());
078: }
079:
080: public void testBulkByModel(Model m) {
081: assertEquals("precondition: model must be empty", 0, m.size());
082: Model A = modelWithStatements("clouds offer rain; trees offer shelter");
083: Model B = modelWithStatements("x R y; y Q z; z P x");
084: m.add(A);
085: assertIsoModels(A, m);
086: m.add(B);
087: m.remove(A);
088: assertIsoModels(B, m);
089: m.remove(B);
090: assertEquals("", 0, m.size());
091: }
092:
093: public void testBulkRemoveSelf() {
094: Model m = modelWithStatements("they sing together; he sings alone");
095: m.remove(m);
096: assertEquals("", 0, m.size());
097: }
098:
099: public void testBulkByModelReifying() {
100: testBulkByModelReifying(false);
101: testBulkByModelReifying(true);
102: }
103:
104: public void testBulkByModelReifying(boolean suppress) {
105: Model m = modelWithStatements(ReificationStyle.Minimal, "a P b");
106: addReification(m, "x", "S P O");
107: addReification(m, "a", "x R y");
108: Model target = modelWithStatements(ReificationStyle.Minimal, "");
109: target.add(m, suppress);
110: target.setNsPrefixes(PrefixMapping.Standard);
111: assertIsoModels((suppress ? modelWithStatements("a P b") : m),
112: target);
113: }
114:
115: public void testBulkDeleteByModelReifying() {
116: testBulkDeleteByModelReifying(false);
117: testBulkDeleteByModelReifying(true);
118: }
119:
120: public void testBulkDeleteByModelReifying(boolean suppress) {
121: Model target = modelWithStatements(ReificationStyle.Minimal, "");
122: addReification(target, "x", "S P O");
123: addReification(target, "y", "A P B");
124: Model remove = modelWithStatements("");
125: addReification(remove, "y", "A P B");
126: Model answer = modelWithStatements("");
127: addReification(answer, "x", "S P O");
128: if (suppress)
129: addReification(answer, "y", "A P B");
130: target.remove(remove, suppress);
131: assertIsoModels(answer, target);
132: }
133:
134: public void addReification(Model m, String tag, String statement) {
135: m.createReifiedStatement(tag, statement(m, statement));
136: }
137: }
138:
139: /*
140: (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
141: All rights reserved.
142:
143: Redistribution and use in source and binary forms, with or without
144: modification, are permitted provided that the following conditions
145: are met:
146:
147: 1. Redistributions of source code must retain the above copyright
148: notice, this list of conditions and the following disclaimer.
149:
150: 2. Redistributions in binary form must reproduce the above copyright
151: notice, this list of conditions and the following disclaimer in the
152: documentation and/or other materials provided with the distribution.
153:
154: 3. The name of the author may not be used to endorse or promote products
155: derived from this software without specific prior written permission.
156:
157: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
158: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
159: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
160: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
161: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
162: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
163: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
164: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
165: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
166: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
167: */
|