01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.jetspeed.components;
18:
19: import java.sql.Connection;
20:
21: import javax.naming.InitialContext;
22: import javax.naming.NamingException;
23: import javax.sql.DataSource;
24:
25: import junit.framework.Test;
26: import junit.framework.TestSuite;
27:
28: import org.apache.jetspeed.components.datasource.DBCPDatasourceComponent;
29: import org.apache.jetspeed.components.datasource.DatasourceComponent;
30: import org.apache.jetspeed.components.util.DatasourceTestCase;
31:
32: /**
33: * <p>
34: * TestJNDIComponent
35: * </p>@
36: *
37: * @author <a href="mailto:weaver@apache.org">Scott T. Weaver </a>
38: * @version $ $
39: *
40: */
41: public class TestRDBMS extends DatasourceTestCase {
42: public static Test suite() {
43: // All methods starting with "test" will be executed in the test suite.
44: return new TestSuite(TestRDBMS.class);
45: }
46:
47: /**
48: * Defines the testcase name for JUnit.
49: *
50: * @param name
51: * the testcase's name.
52: */
53: public TestRDBMS(String name) {
54: super (name);
55: }
56:
57: public void testDBCP_1() throws Exception {
58: assertTrue(DatasourceComponent.class
59: .isAssignableFrom(DBCPDatasourceComponent.class));
60:
61: InitialContext context = new InitialContext();
62: //look up from jndi
63: assertNotNull(context.lookup("java:/jdbc/jetspeed"));
64: assertNotNull(datasourceComponent);
65: DataSource ds = datasourceComponent.getDatasource();
66: assertNotNull(ds);
67: Connection conn = ds.getConnection();
68: assertNotNull(conn);
69: assertFalse(conn.isClosed());
70: conn.close();
71: (datasourceComponent).stop();
72:
73: try {
74: context.lookup("java:/jdbc/jetspeed");
75: assertNotNull("java:/jdbc/jetspeed was not unbound", null);
76: } catch (NamingException e) {
77:
78: }
79:
80: }
81:
82: }
|