001: /*
002: (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: All rights reserved - see end of file.
004: $Id: TestDriverMap.java,v 1.4 2008/01/02 12:08:14 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.db.test;
008:
009: import java.io.InputStream;
010:
011: import junit.framework.TestSuite;
012:
013: import com.hp.hpl.jena.db.impl.DriverMap;
014: import com.hp.hpl.jena.rdf.model.*;
015: import com.hp.hpl.jena.test.JenaTestBase;
016: import com.hp.hpl.jena.util.FileManager;
017:
018: public class TestDriverMap extends JenaTestBase {
019: public TestDriverMap(String name) {
020: super (name);
021: }
022:
023: public static TestSuite suite() {
024: return new TestSuite(TestDriverMap.class);
025: }
026:
027: public void testAddDrivers() {
028: String className = "some.class.name";
029: String otherClassName = "other.class.name";
030: assertEquals(null, DriverMap.get("test-absent-A"));
031: assertEquals(null, DriverMap.get("test-Absent-A"));
032: assertEquals(null, DriverMap.get("Test-absent-A"));
033: assertEquals(null, DriverMap.get("tEST-absent-A"));
034: assertEquals(null, DriverMap.get("test-absent-B"));
035: assertEquals(null, DriverMap.get("test-absent-B"));
036: DriverMap.add("test-absent-A", className);
037: assertEquals(className, DriverMap.get("test-absent-A"));
038: assertEquals(className, DriverMap.get("test-absent-A"));
039: assertEquals(className, DriverMap.get("test-Absent-A"));
040: assertEquals(className, DriverMap.get("Test-absent-A"));
041: assertEquals(className, DriverMap.get("tEST-absent-A"));
042: assertEquals(null, DriverMap.get("test-absent-B"));
043: assertEquals(null, DriverMap.get("test-absent-B"));
044: DriverMap.add("test-absent-B", otherClassName);
045: assertEquals(otherClassName, DriverMap.get("test-absent-B"));
046: assertEquals(otherClassName, DriverMap.get("test-absent-B"));
047: assertEquals(className, DriverMap.get("test-absent-A"));
048: assertEquals(className, DriverMap.get("test-absent-A"));
049: }
050:
051: public void testBuiltinDrivers() {
052: assertEquals("com.mysql.jdbc.Driver", DriverMap.get("mysql"));
053: assertEquals("org.postgresql.Driver", DriverMap.get("postgres"));
054: assertEquals("org.postgresql.Driver", DriverMap
055: .get("postgresql"));
056: }
057:
058: public void testNormalDrivers() {
059: assertEquals("test.fake.Driver", DriverMap
060: .get("test-fake-driver"));
061: testDrivers(FileManager.get().open("etc/db-default-drivers.n3"));
062: }
063:
064: public void testExtraDrivers() {
065: testDrivers(FileManager.get().open("etc/db-extra-drivers.n3"));
066: }
067:
068: protected void testDrivers(InputStream in) {
069: if (in != null) {
070: Property ANY = null;
071: Model m = ModelFactory.createDefaultModel();
072: m.read(in, "", "N3");
073: StmtIterator A = m.listStatements(ANY,
074: DriverMap.driverClass, ANY);
075: while (A.hasNext()) {
076: Statement st = A.nextStatement();
077: Resource S = st.getSubject();
078: String className = st.getString();
079: StmtIterator B = m.listStatements(S,
080: DriverMap.driverName, ANY);
081: while (B.hasNext()) {
082: String name = B.nextStatement().getString();
083: assertEquals(className, DriverMap.get(name));
084: }
085: }
086: }
087: }
088:
089: }
090:
091: /*
092: * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
093: * All rights reserved.
094: *
095: * Redistribution and use in source and binary forms, with or without
096: * modification, are permitted provided that the following conditions
097: * are met:
098: * 1. Redistributions of source code must retain the above copyright
099: * notice, this list of conditions and the following disclaimer.
100: * 2. Redistributions in binary form must reproduce the above copyright
101: * notice, this list of conditions and the following disclaimer in the
102: * documentation and/or other materials provided with the distribution.
103: * 3. The name of the author may not be used to endorse or promote products
104: * derived from this software without specific prior written permission.
105: *
106: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
107: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
108: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
109: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
110: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
111: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
112: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
113: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
114: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
115: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
116: */
|