001: /*
002: * HA-JDBC: High-Availability JDBC
003: * Copyright (c) 2004-2007 Paul Ferraro
004: *
005: * This library is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU Lesser General Public License as published by the
007: * Free Software Foundation; either version 2.1 of the License, or (at your
008: * option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful, but WITHOUT
011: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
012: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
013: * for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public License
016: * along with this library; if not, write to the Free Software Foundation,
017: * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: *
019: * Contact: ferraro@users.sourceforge.net
020: */
021: package net.sf.hajdbc.dialect;
022:
023: import net.sf.hajdbc.Dialect;
024:
025: import org.easymock.EasyMock;
026: import org.testng.annotations.Test;
027:
028: /**
029: * @author Paul Ferraro
030: *
031: */
032: @SuppressWarnings("nls")
033: public class TestDialectClass {
034: /**
035: * Test method for {@link DialectClass#serialize(Dialect)}.
036: */
037: @Test
038: public void serialize() {
039: Dialect dialect = EasyMock.createStrictMock(Dialect.class);
040:
041: this .assertDialect(dialect, dialect.getClass().getName());
042: this .assertDialect(new DB2Dialect(), "db2");
043: this .assertDialect(new DerbyDialect(), "derby");
044: this .assertDialect(new FirebirdDialect(), "firebird");
045: this .assertDialect(new H2Dialect(), "h2");
046: this .assertDialect(new HSQLDBDialect(), "hsqldb");
047: this .assertDialect(new IngresDialect(), "ingres");
048: this .assertDialect(new MaxDBDialect(), "maxdb");
049: this .assertDialect(new MySQLDialect(), "mysql");
050: this .assertDialect(new OracleDialect(), "oracle");
051: this .assertDialect(new PostgreSQLDialect(), "postgresql");
052: this .assertDialect(new StandardDialect(), "standard");
053: }
054:
055: private void assertDialect(Dialect dialect, String id) {
056: String result = DialectClass.serialize(dialect);
057:
058: assert result.equals(id) : result;
059: }
060:
061: /**
062: * Test method for {@link DialectClass#deserialize(String)}.
063: */
064: @Test
065: public void deserialize() {
066: this .assertDialect(null, StandardDialect.class);
067: this .assertDialect("net.sf.hajdbc.dialect.StandardDialect",
068: StandardDialect.class);
069:
070: this .assertDialect("standard", StandardDialect.class);
071: this .assertDialect("db2", DB2Dialect.class);
072: this .assertDialect("derby", DerbyDialect.class);
073: this .assertDialect("firebird", StandardDialect.class);
074: this .assertDialect("h2", H2Dialect.class);
075: this .assertDialect("hsqldb", HSQLDBDialect.class);
076: this .assertDialect("ingres", IngresDialect.class);
077: this .assertDialect("maxdb", MaxDBDialect.class);
078: this .assertDialect("mckoi", MckoiDialect.class);
079: this .assertDialect("mysql", MySQLDialect.class);
080: this .assertDialect("oracle", OracleDialect.class);
081: this .assertDialect("postgresql", PostgreSQLDialect.class);
082:
083: this .assertDialect("PostgreSQL", PostgreSQLDialect.class);
084: this .assertDialect("POSTGRESQL", PostgreSQLDialect.class);
085:
086: try {
087: Dialect dialect = DialectClass.deserialize("invalid");
088:
089: assert false : dialect.getClass().getName();
090: } catch (Exception e) {
091: assert true;
092: }
093: }
094:
095: private void assertDialect(String id,
096: Class<? extends Dialect> dialectClass) {
097: try {
098: Dialect dialect = DialectClass.deserialize(id);
099:
100: assert dialectClass.isInstance(dialect) : dialect
101: .getClass().getName();
102: } catch (Exception e) {
103: assert false : e;
104: }
105: }
106: }
|