1 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.rdf.model.impl.*; 11 import com.hp.hpl.jena.vocabulary.*; 12 import com.hp.hpl.jena.ontology.*; 13 import com.hp.hpl.jena.reasoner.rulesys.*; 14 import com.hp.hpl.jena.shared.*; 15 import com.hp.hpl.jena.graph.compose.Union; 16 import com.hp.hpl.jena.mem.*; 17 18 import junit.framework.*; 19 20 27 28 public class TestModelFactory extends ModelTestBase 29 { 30 protected static final Resource DAMLLangResource = resource( ProfileRegistry.DAML_LANG ); 31 32 public TestModelFactory(String name) 33 { super(name); } 34 35 public static TestSuite suite() 36 { return new TestSuite( TestModelFactory.class ); } 37 38 42 public void testCreateDefaultModel() 43 { ModelFactory.createDefaultModel().close(); } 44 45 public void testGetDefaultPrefixMapping() 46 { 47 assertSame( ModelCom.getDefaultModelPrefixes(), ModelFactory.getDefaultModelPrefixes() ); 48 } 49 50 public void testSetDefaultPrefixMapping() 51 { 52 PrefixMapping original = ModelCom.getDefaultModelPrefixes(); 53 PrefixMapping pm = PrefixMapping.Factory.create(); 54 ModelFactory.setDefaultModelPrefixes( pm ); 55 assertSame( pm, ModelCom.getDefaultModelPrefixes() ); 56 assertSame( pm, ModelFactory.getDefaultModelPrefixes() ); 57 ModelCom.setDefaultModelPrefixes( original ); 58 } 59 60 public void testCreateSpecFails() 61 { 62 try 63 { 64 ModelFactory.createSpec( ModelFactory.createDefaultModel() ); 65 fail( "empty descriptions should throw the appropriate exception" ); 66 } 67 catch (BadDescriptionException e) { pass(); } 68 } 69 70 public void testCreatePlainSpec() 71 { 72 Model desc = TestModelSpec.createPlainModelDesc(); 73 ModelSpec spec = ModelFactory.createSpec( desc ); 74 assertIsoModels( desc, spec.getDescription() ); 75 assertTrue( spec instanceof PlainModelSpec ); 76 assertTrue( spec.createModel().getGraph() instanceof GraphMem ); 77 } 78 79 public void testCreateOntSpec() 80 { 81 Resource root = ResourceFactory.createResource(); 82 Resource importsMaker = ResourceFactory.createResource(); 83 Resource baseMaker = ResourceFactory.createResource(); 84 Resource reasoner = ResourceFactory.createResource(); 85 OntDocumentManager docManager = new OntDocumentManager(); 86 Resource reasonerURI = ResourceFactory.createResource( DAMLMicroReasonerFactory.URI ); 87 Model desc = ModelFactory.createDefaultModel() 88 .add( root, JenaModelSpec.maker, baseMaker ) 89 .add( root, JenaModelSpec.importMaker, importsMaker ) 90 .add( baseMaker, RDF.type, JenaModelSpec.FileMakerSpec ) 91 .add( baseMaker, JenaModelSpec.fileBase, "/tmp/example" ) 92 .add( baseMaker, JenaModelSpec.reificationMode, JenaModelSpec.rsMinimal ) 93 .add( importsMaker, RDF.type, JenaModelSpec.MemMakerSpec ) 94 .add( importsMaker, JenaModelSpec.reificationMode, JenaModelSpec.rsMinimal ) 95 .add( root, JenaModelSpec.ontLanguage, DAMLLangResource ) 96 .add( root, JenaModelSpec.docManager, ModelSpecImpl.createValue( docManager ) ) 97 .add( root, JenaModelSpec.reasonsWith, reasoner ) 98 .add( reasoner, JenaModelSpec.reasoner, reasonerURI ); 99 ModelSpec spec = ModelFactory.createSpec( desc ); 100 assertTrue( spec instanceof OntModelSpec ); 101 assertIsoModels( desc, spec.getDescription() ); 102 assertTrue( spec.createModel() instanceof OntModel ); 103 } 104 105 public void testCreateOntologyModelFromSpecOnly() 106 { 107 Resource root = ResourceFactory.createResource(); 108 Model desc = ModelFactory.createDefaultModel() 109 .add( root, JenaModelSpec.ontLanguage, DAMLLangResource ) 110 ; 111 OntModelSpec spec = (OntModelSpec) ModelFactory.createSpec( desc ); 112 OntModel m = ModelFactory.createOntologyModel( spec ); 113 } 114 115 public void testCreateInfSpec() 116 { 117 Model desc = TestModelSpec.createInfModelDesc( DAMLMicroReasonerFactory.URI ); 118 ModelSpec spec = ModelFactory.createSpec( desc ); 119 assertTrue( spec instanceof InfModelSpec ); 120 assertIsoModels( desc, spec.getDescription() ); 121 assertTrue( spec.createModel() instanceof InfModel ); 122 } 123 124 127 public void testMFCreate() 128 { 129 Model desc = TestModelSpec.createPlainModelDesc(); 130 ModelSpec spec = ModelFactory.createSpec( desc ); 131 Model m = ModelFactory.createModel( spec ); 132 } 133 134 public void testMFCreateNamed() 135 { 136 Model desc = TestModelSpec.createPlainModelDesc(); 137 ModelSpec spec = ModelFactory.createSpec( desc ); 138 Model m = ModelFactory.createModelOver( spec, "aName" ); 139 } 140 141 public void testCreateNamed() 142 { 143 Resource root = ResourceFactory.createResource(); 144 Model desc = TestModelSpec.createPlainModelDesc( root ); 145 ModelSpec spec = ModelFactory.createSpec( root, desc ); 146 } 147 148 153 public void testCreateUnion() 154 { 155 Model m1 = ModelFactory.createDefaultModel(); 156 Model m2 = ModelFactory.createDefaultModel(); 157 Model m = ModelFactory.createUnion( m1, m2 ); 158 assertTrue( m.getGraph() instanceof Union ); 159 assertSame( m1.getGraph(), ((Union) m.getGraph()).getL() ); 160 assertSame( m2.getGraph(), ((Union) m.getGraph()).getR() ); 161 } 162 } 163 164 193 | Popular Tags |