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