KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > db > test > TestDBSpec


1 /*
2   (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3   [See end of file]
4   $Id: TestDBSpec.java,v 1.8 2005/04/11 15:19:14 chris-dollin Exp $
5 */

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 /**
19     @author kers
20 */

21 public class TestDBSpec extends ModelTestBase
22     {
23     public TestDBSpec( String JavaDoc 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 JavaDoc e)
40             { pass(); }
41         }
42             
43     public void testCreateSuccessUser() throws ClassNotFoundException JavaDoc
44         {
45         Resource me = ResourceFactory.createResource();
46         Resource con = ResourceFactory.createResource();
47         Resource mak = ResourceFactory.createResource();
48         String JavaDoc dbType = TestPackage.M_DB;
49         String JavaDoc 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 JavaDoc dbType = TestPackage.M_DB;
73         String JavaDoc 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 /*
91     (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
92     All rights reserved.
93
94     Redistribution and use in source and binary forms, with or without
95     modification, are permitted provided that the following conditions
96     are met:
97
98     1. Redistributions of source code must retain the above copyright
99        notice, this list of conditions and the following disclaimer.
100
101     2. Redistributions in binary form must reproduce the above copyright
102        notice, this list of conditions and the following disclaimer in the
103        documentation and/or other materials provided with the distribution.
104
105     3. The name of the author may not be used to endorse or promote products
106        derived from this software without specific prior written permission.
107
108     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
109     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
110     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
111     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
112     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
113     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
114     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
115     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
116     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
117     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
118 */
Popular Tags