1 6 7 package com.hp.hpl.jena.db.test; 8 9 import com.hp.hpl.jena.rdf.model.test.*; 10 import com.hp.hpl.jena.rdf.model.*; 11 import com.hp.hpl.jena.rdf.model.impl.*; 12 import com.hp.hpl.jena.db.ModelRDB; 13 import com.hp.hpl.jena.db.impl.*; 14 import com.hp.hpl.jena.vocabulary.*; 15 16 import junit.framework.*; 17 18 21 public class TestDBSpec extends ModelTestBase 22 { 23 public TestDBSpec( String name ) 24 { super( name ); } 25 26 public static TestSuite suite() 27 { return new TestSuite( TestDBSpec.class ); } 28 29 public void testCreateFailsUser() 30 { 31 try 32 {Resource me = ResourceFactory.createResource(); 33 Model spec = ModelFactory.createDefaultModel() 34 .add( me, RDF.type, JenaModelSpec.RDBMakerSpec ); 35 ModelMaker maker = ModelSpecImpl.createMaker( spec ); 36 assertTrue( maker.getGraphMaker() instanceof GraphRDBMaker ); 37 fail( "should not be able to make RDB model from empty specification" ); 38 } 39 catch (Exception e) 40 { pass(); } 41 } 42 43 public void testCreateSuccessUser() throws ClassNotFoundException 44 { 45 Resource me = ResourceFactory.createResource(); 46 Resource con = ResourceFactory.createResource(); 47 Resource mak = ResourceFactory.createResource(); 48 String dbType = TestPackage.M_DB; 49 String className = TestPackage.M_DBDRIVER_CLASS; 50 Model spec = ModelFactory.createDefaultModel() 51 .add( me, JenaModelSpec.maker, mak ) 52 .add( mak, RDF.type, JenaModelSpec.RDBMakerSpec ) 53 .add( mak, JenaModelSpec.hasConnection, con ) 54 .add( con, JenaModelSpec.dbUser, TestPackage.M_DB_USER ) 55 .add( con, JenaModelSpec.dbPassword, TestPackage.M_DB_PASSWD ) 56 .add( con, JenaModelSpec.dbURL, resource( TestPackage.M_DB_URL ) ) 57 .add( con, JenaModelSpec.dbType, dbType ) 58 .add( con, JenaModelSpec.dbClass, className ) 59 ; 60 ModelMaker maker = ModelSpecImpl.createMaker( spec ); 61 assertTrue( maker.getGraphMaker() instanceof GraphRDBMaker ); 62 maker.openModel( "something" ).close(); 63 maker.removeModel( "something" ); 64 maker.close(); 65 } 66 67 public void testCreateDBModelSpec() 68 { 69 Resource me = ResourceFactory.createResource(); 70 Resource dbMaker = ResourceFactory.createResource(); 71 Resource con = ResourceFactory.createResource(); 72 String dbType = TestPackage.M_DB; 73 String className = TestPackage.M_DBDRIVER_CLASS; 74 Model spec = ModelFactory.createDefaultModel() 75 .add( me, JenaModelSpec.maker, dbMaker ) 76 .add( dbMaker, RDF.type, JenaModelSpec.RDBMakerSpec ) 77 .add( dbMaker, JenaModelSpec.hasConnection, con ) 78 .add( con, JenaModelSpec.dbUser, TestPackage.M_DB_USER ) 79 .add( con, JenaModelSpec.dbPassword, TestPackage.M_DB_PASSWD ) 80 .add( con, JenaModelSpec.dbURL, resource( TestPackage.M_DB_URL ) ) 81 .add( con, JenaModelSpec.dbType, dbType ) 82 .add( con, JenaModelSpec.dbClass, className ) 83 ; 84 ModelSpec s = ModelFactory.createSpec( spec ); 85 Model d = s.createModel(); 86 assertTrue( d instanceof ModelRDB ); 87 } 88 } 89 90 | Popular Tags |