KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > rdf > model > test > TestModelFactory


1 /*
2   (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3   [See end of file]
4   $Id: TestModelFactory.java,v 1.26 2005/04/10 12:45:50 chris-dollin Exp $
5 */

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 /**
21     Tests the ModelFactory code. Very skeletal at the moment. It's really
22     testing that the methods actually exists, but it doesn't check much in
23     the way of behaviour.
24     
25     @author kers
26 */

27
28 public class TestModelFactory extends ModelTestBase
29     {
30     protected static final Resource DAMLLangResource = resource( ProfileRegistry.DAML_LANG );
31     
32     public TestModelFactory(String JavaDoc name)
33         { super(name); }
34         
35     public static TestSuite suite()
36         { return new TestSuite( TestModelFactory.class ); }
37         
38     /**
39         Test that ModelFactory.createDefaultModel() exists. [Should check that the Model
40         is truly a "default" model.]
41      */

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     /**
125         Test that ModelFactory.createModel exists and returns models.
126     */

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     /**
149          test that a union model is a model over the union of the two underlying
150          graphs. (We don't check that Union works - that's done in the Union
151          tests, we hope.)
152     */

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 /*
165     (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
166     All rights reserved.
167
168     Redistribution and use in source and binary forms, with or without
169     modification, are permitted provided that the following conditions
170     are met:
171
172     1. Redistributions of source code must retain the above copyright
173        notice, this list of conditions and the following disclaimer.
174
175     2. Redistributions in binary form must reproduce the above copyright
176        notice, this list of conditions and the following disclaimer in the
177        documentation and/or other materials provided with the distribution.
178
179     3. The name of the author may not be used to endorse or promote products
180        derived from this software without specific prior written permission.
181
182     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
183     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
184     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
185     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
186     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
187     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
188     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
189     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
190     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
191     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
192 */

193
Popular Tags