KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > hajdbc > dialect > TestDialectFactory


1 /*
2  * HA-JDBC: High-Availability JDBC
3  * Copyright (c) 2004-2006 Paul Ferraro
4  *
5  * This library is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU Lesser General Public License as published by the
7  * Free Software Foundation; either version 2.1 of the License, or (at your
8  * option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13  * for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this library; if not, write to the Free Software Foundation,
17  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Contact: ferraro@users.sourceforge.net
20  */

21 package net.sf.hajdbc.dialect;
22
23 import net.sf.hajdbc.Dialect;
24
25 import org.easymock.EasyMock;
26 import org.testng.annotations.Test;
27
28 /**
29  * @author Paul Ferraro
30  *
31  */

32 @Test
33 public class TestDialectFactory
34 {
35     public void testSerialize()
36     {
37         Dialect dialect = EasyMock.createMock(Dialect.class);
38         
39         String JavaDoc id = DialectFactory.serialize(dialect);
40         
41         assert id.equals(dialect.getClass().getName()) : id;
42     }
43     
44     public void testDeserialize()
45     {
46         this.assertDialect("net.sf.hajdbc.dialect.DefaultDialect", DefaultDialect.class);
47         this.assertDialect("db2", DB2Dialect.class);
48         this.assertDialect("derby", DerbyDialect.class);
49         this.assertDialect("firebird", DefaultDialect.class);
50         this.assertDialect("hsqldb", HSQLDBDialect.class);
51         this.assertDialect("ingres", DefaultDialect.class);
52         this.assertDialect("maxdb", MaxDBDialect.class);
53         this.assertDialect("mckoi", DefaultDialect.class);
54         this.assertDialect("mysql", DefaultDialect.class);
55         this.assertDialect("oracle", MaxDBDialect.class);
56         this.assertDialect("postgresql", PostgreSQLDialect.class);
57
58         this.assertDialect("PostgreSQL", PostgreSQLDialect.class);
59         this.assertDialect("POSTGRESQL", PostgreSQLDialect.class);
60
61         try
62         {
63             Dialect dialect = DialectFactory.deserialize("invalid");
64             
65             assert false : dialect.getClass().getName();
66         }
67         catch (Exception JavaDoc e)
68         {
69             assert true;
70         }
71     }
72     
73     private void assertDialect(String JavaDoc id, Class JavaDoc<? extends Dialect> dialectClass)
74     {
75         try
76         {
77             Dialect dialect = DialectFactory.deserialize(id);
78             
79             assert dialectClass.isInstance(dialect) : dialect.getClass().getName();
80         }
81         catch (Exception JavaDoc e)
82         {
83             assert false : e;
84         }
85     }
86 }
87
Popular Tags