    1   /***
    2    * JFoxSOAF, Service-Oriented Application Framework
    3    *
    4    * Copyright (C) www.huihoo.org
    5    *
    6    * Distributable under GNU LGPL For more information, please visit:
    7    * http://www.huihoo.org/jfox/jfoxsoaf
    8    */
    9
    10  package org.huihoo.jfox.soaf.services.jdbc;
    11
    12  import junit.framework.TestCase;
    13
    14  import org.huihoo.jfox.soaf.exception.DataSourceConfigurationException;
    15  import org.huihoo.jfox.soaf.exception.ServiceLocatorException;
    16  import org.huihoo.jfox.soaf.services.ejb.ServiceLocator;
    17  import org.huihoo.jfox.soaf.services.ejb.ServiceLocatorImpl;
    18
    19  /***
    20   * JUnit test case for the
    21   * {@link org.huihoo.jfox.soaf.services.jdbc.DataSourceServiceImpl).
    22   *
    23   * @author <a href="mailto:founder_chen@yahoo.com">Peter Cheng </a>
    24   * @version $Revision: 1.1 $ $Date: 2004/10/28 15:44:25 $
    25   * @version Revision: 1.0
    26   */
    27
    28  public class DataSourceServiceImplTest extends TestCase {
    29
    30      private ServiceLocator serviceLocator;
    31
    32      /***
    33       * @see TestCase#setUp()
    34       */
    35      protected void setUp() throws Exception {
    36          super.setUp();
    37          serviceLocator = new ServiceLocatorImpl();
    38      }
    39
    40      /***
    41       * @see TestCase#tearDown()
    42       */
    43      protected void tearDown() throws Exception {
    44          super.tearDown();
    45      }
    46
    47      /***
    48       * Test for constructor.
    49       *
    50       * @see C3P0DataSourceFactory#removeAttribute()
    51       */
    52      public void testDataSourceServiceImpl() {
    53          DataSourceServiceImpl dsService = new DataSourceServiceImpl(serviceLocator);
    54          assertNotNull(dsService);
    55      }
    56
    57      /***
    58       * Test for method: getDataSource(String dataSourceName)
    59       * Condition: null
    60       *
    61       * @see C3P0DataSourceFactory#removeAttribute()
    62       */
    63      public void testGetDataSource() {
    64          DataSourceServiceImpl dsService = new DataSourceServiceImpl(serviceLocator);
    65          try {
    66              assertNotNull(dsService.getDataSource(null));
    67          } catch (DataSourceConfigurationException e) {
    68              e.printStackTrace();
    69          } catch (ServiceLocatorException e) {
    70              e.printStackTrace();
    71          }
    72      }
    73
    74      /***
    75       * Test for method: getDataSource(String dataSourceName)
    76       * Condition: JNDI-based
    77       *
    78       * @see C3P0DataSourceFactory#removeAttribute()
    79       */
    80      public void testGetDataSource1() {
    81          DataSourceServiceImpl dsService = new DataSourceServiceImpl(serviceLocator);
    82          try {
    83              assertNull(dsService.getDataSource("java:comp:DataBase"));
    84          } catch (DataSourceConfigurationException e) {
    85          } catch (ServiceLocatorException e) {
    86          }
    87      }
    88
    89  }