01: /**
02: *
03: * Licensed to the Apache Software Foundation (ASF) under one or more
04: * contributor license agreements. See the NOTICE file distributed with
05: * this work for additional information regarding copyright ownership.
06: * The ASF licenses this file to You under the Apache License, Version 2.0
07: * (the "License"); you may not use this file except in compliance with
08: * the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */package org.apache.openejb.resource.jdbc;
18:
19: import junit.framework.TestCase;
20:
21: import java.sql.SQLException;
22:
23: public class BasicDataSourceUtilTest extends TestCase {
24: public void testGetJdbcName() {
25: assertEquals("hsqldb", BasicDataSourceUtil
26: .getJdbcName("jdbc:hsqldb:file:foo"));
27: assertEquals("idb", BasicDataSourceUtil
28: .getJdbcName("jdbc:idb:foo"));
29:
30: // not a proper jdbc url
31: assertNull(BasicDataSourceUtil
32: .getJdbcName("notjdbc:hsqldb:file:foo"));
33:
34: // no trailing :
35: assertEquals("specialDB", BasicDataSourceUtil
36: .getJdbcName("jdbc:specialDB"));
37:
38: // null
39: assertNull(BasicDataSourceUtil.getJdbcName(null));
40:
41: // empty string
42: assertNull(BasicDataSourceUtil.getJdbcName(""));
43: }
44:
45: public void testGetDataSourcePlugin() throws Exception {
46: // all current known plugins
47: assertPluginClass("jdbc:hsqldb:file:foo",
48: HsqldbDataSourcePlugin.class);
49: assertPluginClass("jdbc:idb:foo",
50: InstantdbDataSourcePlugin.class);
51: assertPluginClass("jdbc:derby:foo", DerbyDataSourcePlugin.class);
52:
53: // not a proper jdbc url
54: assertNull(BasicDataSourceUtil
55: .getDataSourcePlugin("notjdbc:hsqldb:file:foo"));
56:
57: // no trailing :
58: assertPluginClass("jdbc:hsqldb", HsqldbDataSourcePlugin.class);
59:
60: // null
61: assertNull(BasicDataSourceUtil.getDataSourcePlugin(null));
62:
63: // empty string
64: assertNull(BasicDataSourceUtil.getDataSourcePlugin(""));
65: }
66:
67: private void assertPluginClass(String jdbcUrl,
68: Class<? extends DataSourcePlugin> pluginClass)
69: throws SQLException {
70: DataSourcePlugin plugin = BasicDataSourceUtil
71: .getDataSourcePlugin(jdbcUrl);
72: assertNotNull(plugin);
73: assertSame(pluginClass, plugin.getClass());
74: }
75:
76: }
|