1 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 22 public class TestModelSpecWithSchema extends ModelTestBase 23 { 24 public TestModelSpecWithSchema( String 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 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 wanted, String toTest ) 79 { assertIsoModels( m( wanted ), ModelSpecFactory.withSpecSchema( m( toTest ) ) ); } 80 81 public Model m( String s ) 82 { return modelWithStatements( s ); } 83 84 protected static final Filter inJMS = new Filter() 85 { 86 public boolean accept( Object 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 | Popular Tags |