01: /*
02: (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP, all rights reserved.
03: [See end of file]
04: $Id: TestListSubjectsEtc.java,v 1.7 2008/01/02 12:04:44 andy_seaborne Exp $
05: */
06: package com.hp.hpl.jena.rdf.model.test;
07:
08: import com.hp.hpl.jena.rdf.model.*;
09:
10: import junit.framework.TestSuite;
11:
12: /**
13: TestListSubjectsEtc - tests for listSubjects, listObjects [and listPredicates, if
14: it were to exist]
15: TODO make preperly generic, add missing test cases [we're relying, at root,
16: on SimpleQueryHandler]
17:
18: @author kers
19: */
20: public class TestListSubjectsEtc extends ModelTestBase {
21: public TestListSubjectsEtc(String name) {
22: super (name);
23: }
24:
25: public static TestSuite suite() {
26: return new TestSuite(TestListSubjectsEtc.class);
27: }
28:
29: public void testListSubjectsNoRemove() {
30: Model m = modelWithStatements("a P b; b Q c; c R a");
31: ResIterator it = m.listSubjects();
32: it.next();
33: try {
34: it.remove();
35: fail("listSubjects should not support .remove()");
36: } catch (UnsupportedOperationException e) {
37: pass();
38: }
39: }
40:
41: public void testListObjectsNoRemove() {
42: Model m = modelWithStatements("a P b; b Q c; c R a");
43: NodeIterator it = m.listObjects();
44: it.next();
45: try {
46: it.remove();
47: fail("listObjects should not support .remove()");
48: } catch (UnsupportedOperationException e) {
49: pass();
50: }
51: }
52:
53: public void testListSubjectsWorksAfterRemoveProperties() {
54: Model m = modelWithStatements("p1 before terminal; p2 before terminal");
55: m.createResource("eh:/p1").removeProperties();
56: assertIsoModels(modelWithStatements("p2 before terminal"), m);
57: assertEquals(resourceSet("p2"), m.listSubjects().toSet());
58: }
59:
60: public void testListSubjectsWorksAfterRemovePropertiesWIthLots() {
61: Model m = modelWithStatements("p2 before terminal");
62: for (int i = 0; i < 100; i += 1)
63: modelAdd(m, "p1 hasValue " + i);
64: m.createResource("eh:/p1").removeProperties();
65: assertIsoModels(modelWithStatements("p2 before terminal"), m);
66: assertEquals(resourceSet("p2"), m.listSubjects().toSet());
67: }
68: }
69:
70: /*
71: (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
72: All rights reserved.
73:
74: Redistribution and use in source and binary forms, with or without
75: modification, are permitted provided that the following conditions
76: are met:
77:
78: 1. Redistributions of source code must retain the above copyright
79: notice, this list of conditions and the following disclaimer.
80:
81: 2. Redistributions in binary form must reproduce the above copyright
82: notice, this list of conditions and the following disclaimer in the
83: documentation and/or other materials provided with the distribution.
84:
85: 3. The name of the author may not be used to endorse or promote products
86: derived from this software without specific prior written permission.
87:
88: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
89: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
90: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
91: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
92: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
93: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
94: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
95: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
96: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
97: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
98: */
|