cleanup
[cdmlib.git] / cdmlib-persistence / src / test / java / eu / etaxonomy / cdm / database / types / ODBCDatabaseTypeTest.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9
10 package eu.etaxonomy.cdm.database.types;
11
12 import static org.junit.Assert.assertEquals;
13
14 import org.apache.logging.log4j.LogManager;
15 import org.apache.logging.log4j.Logger;
16 import org.junit.After;
17 import org.junit.AfterClass;
18 import org.junit.Before;
19 import org.junit.BeforeClass;
20 import org.junit.Test;
21
22 import eu.etaxonomy.cdm.database.CdmDataSource;
23 import eu.etaxonomy.cdm.database.CdmPersistentDataSource;
24 import eu.etaxonomy.cdm.database.DatabaseTypeEnum;
25
26 /**
27 * @author a.mueller
28 * @since 18.12.2008
29 */
30 public class ODBCDatabaseTypeTest {
31
32 @SuppressWarnings("unused")
33 private static final Logger logger = LogManager.getLogger();
34
35 private static DatabaseTypeEnum enumType;
36
37 CdmPersistentDataSource dataSource;
38 String server;
39 String dbName;
40 int port;
41 String username;
42 String password;
43
44 /**
45 * @throws java.lang.Exception
46 */
47 @BeforeClass
48 public static void setUpBeforeClass() throws Exception {
49 enumType = DatabaseTypeEnum.ODBC;
50 }
51
52 /**
53 * @throws java.lang.Exception
54 */
55 @AfterClass
56 public static void tearDownAfterClass() throws Exception {
57 }
58
59 /**
60 * @throws java.lang.Exception
61 */
62 @Before
63 public void setUp() throws Exception {
64 server = "server";
65 dbName = "db";
66 port = 80;
67 username = "user";
68 password = "wd";
69 dataSource = CdmPersistentDataSource.save(
70 "sybaseTest", CdmDataSource.NewInstance(enumType, server, dbName, port, username, password));
71 }
72
73 /**
74 * @throws java.lang.Exception
75 */
76 @After
77 public void tearDown() throws Exception {
78 }
79
80 /**
81 * Test method for {@link eu.etaxonomy.cdm.database.types.PostgreSQLDatabaseType#getConnectionString(eu.etaxonomy.cdm.database.ICdmDataSource)}.
82 */
83 @Test
84 public void testGetConnectionStringICdmDataSource() {
85 String expected = "jdbc:odbc:" + server ;
86 assertEquals(expected, enumType.getConnectionString(dataSource));
87 }
88
89 /**
90 * Test method for {@link eu.etaxonomy.cdm.database.types.PostgreSQLDatabaseType#getConnectionString(eu.etaxonomy.cdm.database.ICdmDataSource, int)}.
91 */
92 @Test
93 public void testGetConnectionStringICdmDataSourceInt() {
94 port = 357;
95 String expected = "jdbc:odbc:" + server ;
96 assertEquals(expected, ((OdbcDatabaseType)enumType.getDatabaseType()).getConnectionString(dataSource, port));
97 }
98
99 /**
100 * Test method for {@link eu.etaxonomy.cdm.database.types.PostgreSQLDatabaseType#getDatabaseNameByConnectionString(java.lang.String)}.
101 */
102 @Test
103 public void testGetDatabaseNameByConnectionString() {
104 dbName = null;
105 assertEquals(dbName, dataSource.getDatabase());
106 }
107
108 /**
109 * Test method for {@link eu.etaxonomy.cdm.database.types.DatabaseTypeBase#getServerNameByConnectionString(java.lang.String)}.
110 */
111 @Test
112 public void testGetServerNameByConnectionStringString() {
113 assertEquals(server, dataSource.getServer());
114 }
115
116 /**
117 * Test method for {@link eu.etaxonomy.cdm.database.types.DatabaseTypeBase#getPortByConnectionString(java.lang.String)}.
118 */
119 @Test
120 public void testGetPortByConnectionStringString() {
121 port = -1;
122 assertEquals(port, dataSource.getPort());
123 }
124 }