View Javadoc

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.util;
18  
19  import junit.framework.TestCase;
20  
21  import org.apache.commons.pool.impl.GenericObjectPool;
22  import org.apache.jetspeed.components.datasource.BoundDBCPDatasourceComponent;
23  import org.apache.jetspeed.components.jndi.JNDIComponent;
24  import org.apache.jetspeed.components.jndi.TyrexJNDIComponent;
25  
26  /***
27   * @author <a href="mailto:sweaver@einnovation.com">Scott T. Weaver </a>
28   *  
29   */
30  public class DatasourceTestCase extends TestCase
31  {
32  
33      protected BoundDBCPDatasourceComponent datasourceComponent;
34  
35      protected JNDIComponent jndi;
36  
37      /***
38       *  
39       */
40      public DatasourceTestCase()
41      {
42          super();
43          // TODO Auto-generated constructor stub
44      }
45  
46      /***
47       * @param arg0
48       */
49      public DatasourceTestCase(String arg0)
50      {
51          super(arg0);
52          // TODO Auto-generated constructor stub
53      }
54  
55      /***
56       * @see junit.framework.TestCase#setUp()
57       */
58      protected void setUp() throws Exception
59      {
60          super.setUp();
61          jndi = new TyrexJNDIComponent();
62          String url = System.getProperty("org.apache.jetspeed.database.url");
63          String driver = System.getProperty("org.apache.jetspeed.database.driver");
64          String user = System.getProperty("org.apache.jetspeed.database.user");
65          String password = System.getProperty("org.apache.jetspeed.database.password");
66          datasourceComponent = new BoundDBCPDatasourceComponent(user, password, driver, url, 20, 5000,
67                  GenericObjectPool.WHEN_EXHAUSTED_GROW, true, "jetspeed", jndi);
68          datasourceComponent.start();
69  
70      }
71  
72      /***
73       * @see junit.framework.TestCase#tearDown()
74       */
75      protected void tearDown() throws Exception
76      {
77          datasourceComponent.stop();
78          jndi.unbindFromCurrentThread();
79          super.tearDown();
80      }
81  
82  }