001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: TestXml2Datasources.java 3634 2007-01-08 21:42:24Z gbevin $
007: */
008: package com.uwyn.rife.database;
009:
010: import com.uwyn.rife.database.exceptions.DatasourcesException;
011: import com.uwyn.rife.resources.ResourceFinderClasspath;
012: import com.uwyn.rife.tools.ExceptionUtils;
013: import junit.framework.TestCase;
014:
015: public class TestXml2Datasources extends TestCase {
016: public TestXml2Datasources(String name) {
017: super (name);
018: }
019:
020: public void testParser() {
021: Datasources datasources = null;
022: try {
023: datasources = new Datasources(
024: "xml/test_xml2datasources.xml",
025: ResourceFinderClasspath.getInstance());
026:
027: assertEquals(4, datasources.getDatasourceNames().size());
028:
029: assertTrue(datasources.getDatasourceNames().contains(
030: "datasource1"));
031: assertTrue(datasources.getDatasourceNames().contains(
032: "datasource2"));
033: assertTrue(datasources.getDatasourceNames().contains(
034: "datasource3"));
035:
036: Datasource datasource1 = datasources
037: .getDatasource("datasource1");
038: assertEquals("org.postgresql.Driver", datasource1
039: .getDriver());
040: assertEquals("org.postgresql.Driver", datasource1
041: .getAliasedDriver());
042: assertEquals("jdbc:postgresql://localhost:5432/thedb",
043: datasource1.getUrl());
044: assertEquals("unittests1", datasource1.getUser());
045: assertEquals("password1", datasource1.getPassword());
046: assertEquals(5, datasource1.getPoolsize());
047: assertTrue(datasource1.isPooled());
048:
049: Datasource datasource2 = datasources
050: .getDatasource("datasource2");
051: assertEquals("com.mysql.jdbc.Driver", datasource2
052: .getDriver());
053: assertEquals("com.mysql.jdbc.Driver", datasource2
054: .getAliasedDriver());
055: assertEquals("jdbc:mysql://localhost:3306/thedb",
056: datasource2.getUrl());
057: assertEquals("user2", datasource2.getUser());
058: assertEquals("pw2", datasource2.getPassword());
059: assertEquals(15, datasource2.getPoolsize());
060: assertTrue(datasource2.isPooled());
061:
062: Datasource datasource3 = datasources
063: .getDatasource("datasource3");
064: assertEquals("oracle.jdbc.driver.OracleDriver", datasource3
065: .getDriver());
066: assertEquals("oracle.jdbc.driver.OracleDriver", datasource3
067: .getAliasedDriver());
068: assertEquals("jdbc:oracle:thin:@10.1.1.2:1521:database",
069: datasource3.getUrl());
070: assertEquals("unittests", datasource3.getUser());
071: assertEquals("password", datasource3.getPassword());
072: assertEquals(0, datasource3.getPoolsize());
073: assertTrue(!datasource3.isPooled());
074:
075: Datasource datasource4 = datasources
076: .getDatasource("datasource4");
077: assertEquals("org.gjt.mm.mysql.Driver", datasource4
078: .getDriver());
079: assertEquals("com.mysql.jdbc.Driver", datasource4
080: .getAliasedDriver());
081: assertEquals("jdbc:mysql://localhost:3306/thedb",
082: datasource4.getUrl());
083: assertEquals("user2", datasource4.getUser());
084: assertEquals("pw2", datasource4.getPassword());
085: assertEquals(15, datasource4.getPoolsize());
086: assertTrue(datasource4.isPooled());
087: } catch (DatasourcesException e) {
088: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
089: }
090: }
091:
092: public void testSelectedShortClassname() {
093: Datasources datasources = null;
094:
095: try {
096: datasources = new Datasources("TestSelectorDatasources",
097: ResourceFinderClasspath.getInstance());
098: } catch (DatasourcesException e) {
099: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
100: }
101:
102: assertTrue(null != datasources.getDatasource("datasource1"));
103: }
104:
105: public void testSelectedFullClassname() {
106: Datasources datasources = null;
107:
108: try {
109: datasources = new Datasources(
110: "com.uwyn.rife.selector.TestSelectorDatasources",
111: ResourceFinderClasspath.getInstance());
112: } catch (DatasourcesException e) {
113: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
114: }
115:
116: assertTrue(null != datasources.getDatasource("datasource1"));
117: }
118:
119: public void testUnavailableXmlFile() {
120: Datasources datasources = null;
121:
122: try {
123: datasources = new Datasources(
124: "xml/this_file_is_not_there.xml",
125: ResourceFinderClasspath.getInstance());
126: fail();
127: assertNotNull(datasources);
128: } catch (IllegalArgumentException e) {
129: assertTrue(true);
130: } catch (DatasourcesException e) {
131: assertTrue(true);
132: }
133: }
134: }
|