1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      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  import java.sql.Connection;
19  
20  import javax.naming.InitialContext;
21  import javax.naming.NamingException;
22  import javax.sql.DataSource;
23  
24  import junit.framework.Test;
25  import junit.framework.TestSuite;
26  
27  import org.apache.jetspeed.components.datasource.DBCPDatasourceComponent;
28  import org.apache.jetspeed.components.datasource.DatasourceComponent;
29  import org.apache.jetspeed.components.util.DatasourceTestCase;
30  /***
31   * <p>
32   * TestJNDIComponent
33   * </p>@
34   * 
35   * @author <a href="mailto:weaver@apache.org">Scott T. Weaver </a>
36   * @version $ $
37   *  
38   */
39  public class TestRDBMS extends DatasourceTestCase
40  {
41      public static Test suite()
42      {
43          // All methods starting with "test" will be executed in the test suite.
44          return new TestSuite(TestRDBMS.class);
45      }
46      /***
47       * Defines the testcase name for JUnit.
48       * 
49       * @param name
50       *            the testcase's name.
51       */
52      public TestRDBMS(String name)
53      {
54          super(name);
55      }
56      
57      public void testDBCP_1() throws Exception
58      {
59          assertTrue(DatasourceComponent.class.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          
74          try
75          {
76              context.lookup("java:/jdbc/jetspeed");
77              assertNotNull("java:/jdbc/jetspeed was not unbound", null);
78          }
79          catch (NamingException e)
80          {
81         
82          }
83          
84   
85       
86      }
87      
88     
89  
90  }