001: /*
002: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: [See end of file]
004: $Id: TestModelMakerImpl.java,v 1.29 2008/01/15 08:19:27 chris-dollin Exp $
005: */
006:
007: package com.hp.hpl.jena.rdf.model.test;
008:
009: import com.hp.hpl.jena.rdf.model.impl.*;
010: import com.hp.hpl.jena.rdf.model.*;
011: import com.hp.hpl.jena.shared.*;
012: import com.hp.hpl.jena.util.iterator.*;
013: import com.hp.hpl.jena.graph.*;
014: import com.hp.hpl.jena.graph.test.*;
015:
016: import java.util.*;
017:
018: import junit.framework.*;
019:
020: /**
021: Test ModelMakerImpl using a mock GraphMaker. This is as much an
022: exercise in learning testing technique as it is in actually doing the test ....
023:
024: @author hedgehog
025: */
026: public class TestModelMakerImpl extends ModelTestBase {
027: public TestModelMakerImpl(String name) {
028: super (name);
029: }
030:
031: public static TestSuite suite() {
032: return new TestSuite(TestModelMakerImpl.class);
033: }
034:
035: private ModelMaker maker;
036: private Graph graph;
037: private GraphMaker graphMaker;
038:
039: public void setUp() {
040: graph = GraphTestBase.graphWith("");
041: graphMaker = new MockGraphMaker(graph);
042: maker = new ModelMakerImpl(graphMaker);
043: }
044:
045: public void testClose() {
046: maker.close();
047: checkHistory(listOfOne("close()"));
048: }
049:
050: public void testRemove() {
051: maker.removeModel("London");
052: checkHistory(listOfOne("remove(London)"));
053: }
054:
055: public void testCreateFreshModel() {
056: maker.createFreshModel();
057: checkHistory(listOfOne("create()"));
058: }
059:
060: public void testCreateDefaultModel() {
061: maker.createDefaultModel();
062: checkHistory(listOfOne("get()"));
063: }
064:
065: public void testCreateNamed() {
066: Model m = maker.createModel("petal");
067: checkHistory(listOfOne("create(petal,false)"));
068: assertTrue(m.getGraph() == graph);
069: }
070:
071: public void testCreateTrue() {
072: Model m = maker.createModel("stem", true);
073: checkHistory(listOfOne("create(stem,true)"));
074: assertTrue(m.getGraph() == graph);
075: }
076:
077: public void testCreateFalse() {
078: Model m = maker.createModel("leaf", false);
079: checkHistory(listOfOne("create(leaf,false)"));
080: assertTrue(m.getGraph() == graph);
081: }
082:
083: public void testOpen() {
084: Model m = maker.openModel("trunk");
085: checkHistory(listOfOne("open(trunk,false)"));
086: assertTrue(m.getGraph() == graph);
087: }
088:
089: public void testOpenFalse() {
090: Model m = maker.openModel("branch", false);
091: checkHistory(listOfOne("open(branch,false)"));
092: assertTrue(m.getGraph() == graph);
093: }
094:
095: public void testOpenTrue() {
096: Model m = maker.openModel("bark", true);
097: checkHistory(listOfOne("open(bark,true)"));
098: assertTrue(m.getGraph() == graph);
099: }
100:
101: public void testListGraphs() {
102: maker.listModels().close();
103: checkHistory(listOfOne("listModels()"));
104: }
105:
106: public void testGetGraphMaker() {
107: assertTrue(maker.getGraphMaker() == graphMaker);
108: }
109:
110: private void checkHistory(List expected) {
111: assertEquals(expected, history());
112: }
113:
114: private List history() {
115: return ((MockGraphMaker) maker.getGraphMaker()).history;
116: }
117:
118: static class MockGraphMaker implements GraphMaker {
119: List history = new ArrayList();
120: Graph graph;
121:
122: public MockGraphMaker(Graph graph) {
123: this .graph = graph;
124: }
125:
126: public ReificationStyle getReificationStyle() {
127: history.add("getReificationStyle()");
128: return null;
129: }
130:
131: public Graph getGraph() {
132: history.add("get()");
133: return graph;
134: }
135:
136: public Graph createGraph() {
137: history.add("create()");
138: return graph;
139: }
140:
141: public Graph createGraph(String name, boolean strict) {
142: history.add("create(" + name + "," + strict + ")");
143: return graph;
144: }
145:
146: public Graph createGraph(String name) {
147: history.add("create(" + name + ")");
148: return graph;
149: }
150:
151: public Graph openGraph(String name, boolean strict) {
152: history.add("open(" + name + "," + strict + ")");
153: return graph;
154: }
155:
156: public Graph openGraph(String name) {
157: history.add("open(" + name + ")");
158: return graph;
159: }
160:
161: public void removeGraph(String name) {
162: history.add("remove(" + name + ")");
163: }
164:
165: public boolean hasGraph(String name) {
166: history.add("has(" + name + ")");
167: return false;
168: }
169:
170: public Graph getDescription() {
171: history.add("getDescription()");
172: return graphWith("");
173: }
174:
175: public Graph getDescription(Node root) {
176: history.add("getDescription(Node)");
177: return graphWith("");
178: }
179:
180: public Graph addDescription(Graph desc, Node self) {
181: history.add("addDescription()");
182: return desc;
183: }
184:
185: public void close() {
186: history.add("close()");
187: }
188:
189: public ExtendedIterator listGraphs() {
190: history.add("listModels()");
191: return NullIterator.instance;
192: }
193:
194: public Graph openGraph() {
195:
196: return null;
197: }
198: }
199: }
200:
201: /*
202: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
203: All rights reserved.
204:
205: Redistribution and use in source and binary forms, with or without
206: modification, are permitted provided that the following conditions
207: are met:
208:
209: 1. Redistributions of source code must retain the above copyright
210: notice, this list of conditions and the following disclaimer.
211:
212: 2. Redistributions in binary form must reproduce the above copyright
213: notice, this list of conditions and the following disclaimer in the
214: documentation and/or other materials provided with the distribution.
215:
216: 3. The name of the author may not be used to endorse or promote products
217: derived from this software without specific prior written permission.
218:
219: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
220: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
221: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
222: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
223: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
224: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
225: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
226: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
227: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
228: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
229: */
|