1 6 7 package com.hp.hpl.jena.rdf.model.test; 8 9 import com.hp.hpl.jena.rdf.model.impl.*; 10 import com.hp.hpl.jena.rdf.model.*; 11 import com.hp.hpl.jena.shared.*; 12 import com.hp.hpl.jena.util.iterator.*; 13 import com.hp.hpl.jena.graph.*; 14 import com.hp.hpl.jena.graph.test.*; 15 16 import java.util.*; 17 18 import junit.framework.*; 19 20 26 public class TestModelMakerImpl extends ModelTestBase 27 { 28 public TestModelMakerImpl(String name) 29 { super(name); } 30 31 public static TestSuite suite() 32 { return new TestSuite( TestModelMakerImpl.class ); } 33 34 private ModelMaker maker; 35 private Graph graph; 36 private GraphMaker graphMaker; 37 38 public void setUp() 39 { 40 graph = GraphTestBase.graphWith( "" ); 41 graphMaker = new MockGraphMaker( graph ); 42 maker = new ModelMakerImpl( graphMaker ); 43 } 44 45 public void testClose() 46 { 47 maker.close(); 48 checkHistory( one( "close()") ); 49 } 50 51 public void testRemove() 52 { 53 maker.removeModel( "London" ); 54 checkHistory( one( "remove(London)" ) ); 55 } 56 57 public void testCreate() 58 { 59 maker.createModel(); 60 checkHistory( one( "create()" ) ); 61 } 62 63 public void testGet() 64 { 65 maker.getModel(); 66 checkHistory( one( "get()" ) ); 67 } 68 69 public void testCreateNamed() 70 { 71 Model m = maker.createModel( "petal" ); 72 checkHistory( one("create(petal,false)" ) ); 73 assertTrue( m.getGraph() == graph ); 74 } 75 76 public void testCreateTrue() 77 { 78 Model m = maker.createModel( "stem", true ); 79 checkHistory( one("create(stem,true)" ) ); 80 assertTrue( m.getGraph() == graph ); 81 } 82 83 public void testCreateFalse() 84 { 85 Model m = maker.createModel( "leaf", false ); 86 checkHistory( one("create(leaf,false)" ) ); 87 assertTrue( m.getGraph() == graph ); 88 } 89 90 public void testOpen() 91 { 92 Model m = maker.openModel( "trunk" ); 93 checkHistory( one("open(trunk,false)" ) ); 94 assertTrue( m.getGraph() == graph ); 95 } 96 97 public void testOpenFalse() 98 { 99 Model m = maker.openModel( "branch", false ); 100 checkHistory( one("open(branch,false)" ) ); 101 assertTrue( m.getGraph() == graph ); 102 } 103 104 public void testOpenTrue() 105 { 106 Model m = maker.openModel( "bark", true ); 107 checkHistory( one("open(bark,true)" ) ); 108 assertTrue( m.getGraph() == graph ); 109 } 110 111 public void testListGraphs() 112 { 113 maker.listModels().close(); 114 checkHistory( one("listModels()" ) ); 115 } 116 117 public void testGetGraphMaker() 118 { 119 assertTrue( maker.getGraphMaker() == graphMaker ); 120 } 121 122 public void testGetDescription() 123 { 124 maker.getDescription(); 125 checkHistory( one( "getDescription()" ) ); 126 } 127 128 private void checkHistory( List expected ) 129 { assertEquals( expected, history() ); } 130 131 private List history() 132 { return ((MockGraphMaker) maker.getGraphMaker()).history; } 133 134 private List one( String s ) 135 { 136 List result = new ArrayList(); 137 result.add( s ); 138 return result; 139 } 140 141 static class MockGraphMaker implements GraphMaker 142 { 143 List history = new ArrayList(); 144 Graph graph; 145 146 public MockGraphMaker( Graph graph ) 147 { this.graph = graph; } 148 149 public ReificationStyle getReificationStyle() 150 { 151 history.add( "getReificationStyle()" ); 152 return null; 153 } 154 155 public Graph getGraph() 156 { 157 history.add( "get()" ); 158 return graph; 159 } 160 161 public Graph createGraph() 162 { 163 history.add( "create()" ); 164 return graph; 165 } 166 167 public Graph createGraph( String name, boolean strict ) 168 { 169 history.add( "create(" + name + "," + strict + ")" ); 170 return graph; 171 } 172 173 public Graph createGraph( String name ) 174 { 175 history.add( "create(" + name + ")" ); 176 return graph; 177 } 178 179 public Graph openGraph( String name, boolean strict ) 180 { 181 history.add( "open(" + name + "," + strict + ")" ); 182 return graph; 183 } 184 185 public Graph openGraph( String name ) 186 { 187 history.add( "open(" + name + ")" ); 188 return graph; 189 } 190 191 public void removeGraph( String name ) 192 { 193 history.add( "remove(" + name + ")" ); 194 } 195 196 public boolean hasGraph( String name ) 197 { 198 history.add( "has(" + name + ")" ); 199 return false; 200 } 201 202 public Graph getDescription() 203 { 204 history.add( "getDescription()" ); 205 return graphWith( "" ); 206 } 207 208 public Graph getDescription( Node root ) 209 { 210 history.add( "getDescription(Node)" ); 211 return graphWith( "" ); 212 } 213 214 public Graph addDescription( Graph desc, Node self ) 215 { 216 history.add( "addDescription()" ); 217 return desc; 218 } 219 220 public void close() 221 { 222 history.add( "close()" ); 223 } 224 225 public ExtendedIterator listGraphs() 226 { 227 history.add( "listModels()" ); 228 return NullIterator.instance; 229 } 230 } 231 } 232 233 234 263 | Popular Tags |