forked from utPLSQL/utPLSQL-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataSourceProviderIT.java
More file actions
84 lines (66 loc) · 2.8 KB
/
DataSourceProviderIT.java
File metadata and controls
84 lines (66 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package org.utplsql.cli;
import org.junit.jupiter.api.Test;
import org.utplsql.cli.datasource.TestedDataSourceProvider;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import static org.junit.jupiter.api.Assertions.*;
class DataSourceProviderIT {
@Test
void connectToDatabase() throws SQLException {
DataSource dataSource = getDataSource();
assertNotNull(dataSource);
}
//@Test
void connectAsSysdba() throws SQLException {
ConnectionConfig config = new ConnectionConfig("sys as sysdba/oracle@localhost:1522/ORCLPDB1");
DataSource dataSource = new TestedDataSourceProvider(config, 2).getDataSource();
assertNotNull(dataSource);
}
@Test
void initNlsLang() throws SQLException {
System.setProperty("NLS_LANG", "BRAZILIAN PORTUGUESE_BRAZIL.WE8ISO8859P1");
DataSource dataSource = getDataSource();
assertNotNull(dataSource);
checkNlsSessionParameter(dataSource, "NLS_LANGUAGE", "BRAZILIAN PORTUGUESE");
checkNlsSessionParameter(dataSource, "NLS_TERRITORY", "BRAZIL");
}
@Test
void initPartialNlsLangTerritory() throws SQLException {
System.setProperty("NLS_LANG", "_SOMALIA");
DataSource dataSource = getDataSource();
assertNotNull(dataSource);
checkNlsSessionParameter(dataSource, "NLS_TERRITORY", "SOMALIA");
}
@Test
void initPartialNlsLangLanguage() throws SQLException {
System.setProperty("NLS_LANG", "HINDI");
DataSource dataSource = getDataSource();
assertNotNull(dataSource);
checkNlsSessionParameter(dataSource, "NLS_LANGUAGE", "HINDI");
}
@Test
void initNlsLangEmpty() throws SQLException {
System.setProperty("NLS_LANG", "");
DataSource dataSource = getDataSource();
assertNotNull(dataSource);
}
private DataSource getDataSource() throws SQLException {
ConnectionConfig config = new ConnectionConfig(TestHelper.getConnectionString());
return new TestedDataSourceProvider(config, 2).getDataSource();
}
private void checkNlsSessionParameter( DataSource dataSource, String parameterName, String expectedValue ) throws SQLException {
try ( Connection con = dataSource.getConnection() ) {
try (PreparedStatement stmt = con.prepareStatement("select value from nls_session_parameters where parameter = ?")) {
stmt.setString(1, parameterName);
ResultSet rs = stmt.executeQuery();
if ( rs.next() )
assertEquals(expectedValue, rs.getString(1));
else
fail("Could not get NLS Session parameter value for '" + parameterName + "'");
}
}
}
}