2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.database
;
12 import static org
.junit
.Assert
.assertEquals
;
14 import java
.util
.List
;
16 import org
.apache
.log4j
.Logger
;
17 import org
.junit
.Before
;
18 import org
.junit
.BeforeClass
;
19 import org
.junit
.Test
;
26 public class DatabaseTypeEnumTest
{
27 @SuppressWarnings("unused")
28 private static final Logger logger
= Logger
.getLogger(DatabaseTypeEnumTest
.class);
29 private static DatabaseTypeEnum dbEnum
;
30 private static DatabaseTypeEnum dbEnumSql2005
;
33 * @throws java.lang.Exception
36 public static void setUpBeforeClass() throws Exception
{
37 dbEnum
= DatabaseTypeEnum
.MySQL
;
38 dbEnumSql2005
= DatabaseTypeEnum
.SqlServer2005
;
43 * @throws java.lang.Exception
46 public void setUp() throws Exception
{
50 * Test method for {@link eu.etaxonomy.cdm.database.DatabaseTypeEnum#getName()}.
53 public void testGetName() {
54 assertEquals("MySQL", DatabaseTypeEnumTest
.dbEnum
.getName());
58 * Test method for {@link eu.etaxonomy.cdm.database.DatabaseTypeEnum#getDriverClassName()}.
61 public void testGetDriverClassName() {
62 assertEquals("com.mysql.jdbc.Driver", DatabaseTypeEnumTest
.dbEnum
.getDriverClassName());
66 * Test method for {@link eu.etaxonomy.cdm.database.DatabaseTypeEnum#getUrl()}.
69 public void testGetUrl() {
70 assertEquals("jdbc:mysql://", DatabaseTypeEnumTest
.dbEnum
.getUrl());
74 * Test method for {@link eu.etaxonomy.cdm.database.DatabaseTypeEnum#getDefaultPort()}.
77 public void testGetDefaultPort() {
78 assertEquals(9001, DatabaseTypeEnum
.HSqlDb
.getDefaultPort());
82 * Test method for {@link eu.etaxonomy.cdm.database.DatabaseTypeEnum#getConnectionString(java.lang.String, java.lang.String, int)}.
85 public void testGetConnectionStringStringStringInt() {
86 ICdmDataSource cdmDataSource
= CdmDataSource
.NewMySqlInstance("192.168.2.10", "cdm_test", 1234, null, null);
87 assertEquals("jdbc:mysql://192.168.2.10:1234/cdm_test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull", DatabaseTypeEnumTest
.dbEnum
.getConnectionString(cdmDataSource
));
91 * Test method for {@link eu.etaxonomy.cdm.database.DatabaseTypeEnum#getConnectionString(java.lang.String, java.lang.String)}.
94 public void testGetConnectionStringStringString() {
95 ICdmDataSource cdmDataSource
= CdmDataSource
.NewMySqlInstance("192.168.2.10", "cdm_test", null, null);
96 assertEquals("jdbc:mysql://192.168.2.10:3306/cdm_test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull", DatabaseTypeEnumTest
.dbEnum
.getConnectionString(cdmDataSource
));
97 ICdmDataSource sqlServerDataSource
= CdmDataSource
.NewSqlServer2005Instance("192.168.2.10", "cdm_test", -1, null, null);
98 assertEquals("jdbc:sqlserver://192.168.2.10:1433;databaseName=cdm_test;SelectMethod=cursor", DatabaseTypeEnumTest
.dbEnumSql2005
.getConnectionString(sqlServerDataSource
));
102 * Test method for {@link eu.etaxonomy.cdm.database.DatabaseTypeEnum#getAllTypes()}.
105 public void testGetAllTypes() {
106 List
<DatabaseTypeEnum
> typeList
= DatabaseTypeEnum
.getAllTypes();
107 assertEquals(8, typeList
.size());
108 assertEquals(DatabaseTypeEnum
.HSqlDb
, typeList
.get(0));
109 assertEquals(DatabaseTypeEnum
.MySQL
, typeList
.get(1));
110 assertEquals(DatabaseTypeEnum
.ODBC
, typeList
.get(2));
111 assertEquals(DatabaseTypeEnum
.PostgreSQL
, typeList
.get(3));
112 assertEquals(DatabaseTypeEnum
.Oracle
, typeList
.get(4));
113 // assertEquals(DatabaseTypeEnum.SqlServer2000, typeList.get(5));
114 assertEquals(DatabaseTypeEnum
.SqlServer2005
, typeList
.get(5));
115 assertEquals(DatabaseTypeEnum
.Sybase
, typeList
.get(6));
116 assertEquals(DatabaseTypeEnum
.H2
, typeList
.get(7));
121 * Test method for {@link eu.etaxonomy.cdm.database.DatabaseTypeEnum#byDriverClass(java.lang.String)}.
124 public void testGetDatabaseTypeEnumByDriverClass() {
125 //assertEquals(DatabaseTypeEnum.SqlServer2000, DatabaseTypeEnum.getDatabaseEnumByDriverClass("com.microsoft.jdbc.sqlserver.SQLServerDriver"));
126 //does not work anymore as SQLServer driver is ambigous
127 //assertEquals(DatabaseTypeEnum.SqlServer2000, DatabaseTypeEnum.getDatabaseEnumByDriverClass("com.microsoft.sqlserver.jdbc.SQLServerDriver"));
128 //assertEquals(DatabaseTypeEnum.SqlServer2005, DatabaseTypeEnum.getDatabaseEnumByDriverClass("com.microsoft.sqlserver.jdbc.SQLServerDriver"));
129 assertEquals(DatabaseTypeEnum
.MySQL
, DatabaseTypeEnum
.byDriverClass("com.mysql.jdbc.Driver"));
130 assertEquals(null, DatabaseTypeEnum
.byDriverClass("com.microsoft.xxx"));
134 public void testGetDatabaseTypeEnumByConnectionString() {
135 String connectionString
= "jdbc:mysql://192.168.2.10:3306/cdm_test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull";
136 DatabaseTypeEnum type
= DatabaseTypeEnum
.byConnectionString(connectionString
);
137 assertEquals(DatabaseTypeEnum
.MySQL
, type
);
138 String dbName
= type
.getDatabaseType().getDatabaseNameByConnectionString(connectionString
);
139 assertEquals("cdm_test", dbName
);