001: /**
002: * Speedo: an implementation of JDO compliant personality on top of JORM generic
003: * I/O sub-system.
004: * Copyright (C) 2001-2004 France Telecom R&D
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: *
021: *
022: * Contact: speedo@objectweb.org
023: *
024: * Authors: S.Chassande-Barrioz.
025: *
026: */package org.objectweb.speedo.runtime.basic;
027:
028: import org.objectweb.speedo.api.SpeedoProperties;
029: import org.objectweb.util.monolog.api.BasicLevel;
030: import org.objectweb.jorm.mapper.rdb.lib.ConnectionSpecJDBC;
031:
032: import javax.naming.InitialContext;
033: import javax.sql.DataSource;
034: import java.sql.Driver;
035: import java.sql.DriverManager;
036: import java.sql.SQLException;
037: import java.util.Properties;
038:
039: import junit.framework.Assert;
040:
041: /**
042: * @author S.Chassande-Barrioz
043: */
044: public class TestJavaxSqlDatasource extends TestBasicA {
045:
046: static {
047: System
048: .setProperty("java.naming.factory.initial",
049: "org.objectweb.speedo.runtime.basic.SpeedoInitialNamingFactory");
050: }
051:
052: public final static String CF_NAME = "ds";
053:
054: public TestJavaxSqlDatasource(String s) {
055: super (s);
056: }
057:
058: public Properties getPMFProperties() {
059: Properties p = super .getPMFProperties();
060: p
061: .setProperty("javax.jdo.option.ConnectionFactoryName",
062: CF_NAME);
063: if (pmf == null) {
064: String dcn = getConnectionDriverNameProperty(p);
065: String user = p
066: .getProperty(SpeedoProperties.JDO_OPTION_CONNECTION_USER_NAME);
067: String pass = p
068: .getProperty(
069: SpeedoProperties.JDO_OPTION_CONNECTION_PASSWORD,
070: "");
071: String url = p
072: .getProperty(SpeedoProperties.JDO_OPTION_CONNECTION_URL);
073: if (user == null) {
074: System.out.println(p);
075: fail("No user name specified");
076: }
077: if (url == null) {
078: System.out.println(p);
079: fail("No database url specified");
080: }
081: try {
082: DriverManager.registerDriver((Driver) Class
083: .forName(dcn).newInstance());
084: Object cf = new ConnectionSpecJDBC(url, dcn, user, pass);
085: InitialContext ic = new InitialContext();
086: ic.rebind(CF_NAME, cf);
087: } catch (Exception e) {
088: e.printStackTrace();
089: fail(e.getMessage());
090: }
091: }
092: return p;
093: }
094:
095: public void testGetSqlConnection() {
096: logger.log(BasicLevel.DEBUG, "testGetSqlConnection");
097: Object cf = pmf.getConnectionFactory();
098: Assert.assertTrue("The connection factory is not a DataSource",
099: cf instanceof DataSource);
100: try {
101: ((DataSource) cf).getConnection().close();
102: } catch (SQLException e) {
103: fail("Impossible to get a connection on the factory " + cf);
104: }
105: }
106: }
|