KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2     (c) Copyright 2005, Hewlett-Packard Development Company, LP
3     All rights reserved.
4     [See end of file]
5 */

6 package com.hp.hpl.jena.rdf.model.test;
7
8
9 import java.util.*;
10
11 import junit.framework.TestSuite;
12
13 import com.hp.hpl.jena.rdf.model.*;
14 import com.hp.hpl.jena.rdf.model.impl.ModelSpecFactory;
15 import com.hp.hpl.jena.util.iterator.Filter;
16 import com.hp.hpl.jena.vocabulary.*;
17
18
19 /**
20     @author hedgehog
21 */

22 public class TestModelSpecWithSchema extends ModelTestBase
23     {
24     public TestModelSpecWithSchema( String JavaDoc name )
25         { super( name ); }
26
27     public static TestSuite suite()
28         { return new TestSuite( TestModelSpecWithSchema.class ); }
29
30     public void testReificationMode()
31         { testDomain( "jms:reificationMode rdfs:domain jms:MakerSpec" ); }
32
33     public void testMaker()
34         { testDomain( "jms:maker rdfs:domain jms:PlainModelSpec" ); }
35
36     public void testImportMaker()
37         { testDomain( "jms:importMaker rdfs:domain jms:OntModelSpec" ); }
38
39     public void testOntLanguage()
40         { testDomain( "jms:ontLanguage rdfs:domain jms:OntModelSpec" ); }
41
42     public void testReasonsWith()
43         { testDomain( "jms:reasonsWith rdfs:domain jms:InfModelSpec" ); }
44
45     public void testModelName()
46         { testDomain( "jms:modelName rdfs:domain jms:ModelSpec" ); }
47
48     public void testFileBase()
49         { testDomain( "jms:fileBase rdfs:domain jms:FileMakerSpec" ); }
50     
51     public void testSubclasses()
52         {
53         Model m = JenaModelSpec.getSchema();
54         Model m2 = ModelSpecFactory.withSpecSchema( ((InfModel) JenaModelSpec.getSchema()).getRawModel() );
55         Set wanted = iteratorToSet( m.listStatements( null, RDFS.subClassOf, (RDFNode) null ).filterKeep( inJMS ) );
56         Set got = iteratorToSet( m2.listStatements( null, RDFS.subClassOf, (RDFNode) null ) );
57         if (!wanted.equals( got ))
58             {
59             Set extra = new HashSet( got ); extra.removeAll( wanted );
60             Set missing = new HashSet( wanted ); missing.remove( got );
61             System.err.println( ">> " + extra );
62             System.err.println( ">> " + missing );
63             fail( "not equal" );
64             }
65         }
66
67     protected void testDomain( String JavaDoc triple )
68         { Statement s = statement( triple );
69         Property P = (Property) s.getSubject().as( Property.class );
70         Resource C = s.getResource();
71         Resource X = ResourceFactory.createResource(), Y = ResourceFactory.createResource();
72         Model m = ModelFactory.createDefaultModel().add( X, P, Y );
73         Model ws = ModelSpecFactory.withSpecSchema( m );
74         for (StmtIterator it = ws.listStatements( C, RDFS.subClassOf, (RDFNode) null ); it.hasNext();)
75             assertTrue( ws.contains( X, RDF.type, it.nextStatement().getObject() ) );
76         }
77     
78     protected void testOK( String JavaDoc wanted, String JavaDoc toTest )
79         { assertIsoModels( m( wanted ), ModelSpecFactory.withSpecSchema( m( toTest ) ) ); }
80
81     public Model m( String JavaDoc s )
82         { return modelWithStatements( s ); }
83     
84     protected static final Filter inJMS = new Filter()
85         {
86         public boolean accept( Object JavaDoc o )
87             {
88             Statement s = (Statement) o;
89             return s.getSubject().getNameSpace().equals( JenaModelSpec.baseURI ) && s.getResource().getNameSpace().equals( JenaModelSpec.baseURI );
90             }
91         };
92     }
93
94 /*
95  * (c) Copyright 2005 Hewlett-Packard Development Company, LP
96  * All rights reserved.
97  *
98  * Redistribution and use in source and binary forms, with or without
99  * modification, are permitted provided that the following conditions
100  * are met:
101  * 1. Redistributions of source code must retain the above copyright
102  * notice, this list of conditions and the following disclaimer.
103  * 2. Redistributions in binary form must reproduce the above copyright
104  * notice, this list of conditions and the following disclaimer in the
105  * documentation and/or other materials provided with the distribution.
106  * 3. The name of the author may not be used to endorse or promote products
107  * derived from this software without specific prior written permission.
108  *
109  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
110  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
111  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
112  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
113  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
114  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
115  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
116  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
117  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
118  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
119 */
Popular Tags