|
5 | 5 |
|
6 | 6 | import javax.sql.DataSource;
|
7 | 7 | import java.io.IOException;
|
| 8 | +import java.sql.Connection; |
| 9 | +import java.sql.PreparedStatement; |
| 10 | +import java.sql.ResultSet; |
8 | 11 | import java.sql.SQLException;
|
9 | 12 |
|
| 13 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
10 | 14 | import static org.junit.jupiter.api.Assertions.assertNotNull;
|
| 15 | +import static org.junit.jupiter.api.Assertions.fail; |
11 | 16 |
|
12 |
| -public class DataSourceProviderIT { |
| 17 | +class DataSourceProviderIT { |
13 | 18 |
|
14 | 19 | @Test
|
15 |
| - public void connectToDatabase() throws IOException, SQLException { |
| 20 | + void connectToDatabase() throws SQLException { |
| 21 | + DataSource dataSource = getDataSource(); |
16 | 22 |
|
17 |
| - ConnectionConfig config = new ConnectionConfig(TestHelper.getConnectionString()); |
| 23 | + assertNotNull(dataSource); |
| 24 | + } |
| 25 | + |
| 26 | + @Test |
| 27 | + void initNlsLang() throws SQLException { |
| 28 | + System.setProperty("NLS_LANG", "BRAZILIAN PORTUGUESE_BRAZIL.WE8ISO8859P1"); |
| 29 | + DataSource dataSource = getDataSource(); |
| 30 | + |
| 31 | + assertNotNull(dataSource); |
| 32 | + checkNlsSessionParameter(dataSource, "NLS_LANGUAGE", "BRAZILIAN PORTUGUESE"); |
| 33 | + checkNlsSessionParameter(dataSource, "NLS_TERRITORY", "BRAZIL"); |
| 34 | + } |
| 35 | + |
| 36 | + @Test |
| 37 | + void initPartialNlsLangTerritory() throws SQLException { |
| 38 | + System.setProperty("NLS_LANG", "_SOMALIA"); |
| 39 | + DataSource dataSource = getDataSource(); |
| 40 | + |
| 41 | + assertNotNull(dataSource); |
| 42 | + checkNlsSessionParameter(dataSource, "NLS_TERRITORY", "SOMALIA"); |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + void initPartialNlsLangLanguage() throws SQLException { |
| 47 | + System.setProperty("NLS_LANG", "HINDI"); |
| 48 | + DataSource dataSource = getDataSource(); |
| 49 | + |
| 50 | + assertNotNull(dataSource); |
| 51 | + checkNlsSessionParameter(dataSource, "NLS_LANGUAGE", "HINDI"); |
| 52 | + } |
18 | 53 |
|
19 |
| - DataSource dataSource = new TestedDataSourceProvider(config).getDataSource(); |
| 54 | + @Test |
| 55 | + void initNlsLangEmpty() throws SQLException { |
| 56 | + System.setProperty("NLS_LANG", ""); |
| 57 | + DataSource dataSource = getDataSource(); |
20 | 58 |
|
21 | 59 | assertNotNull(dataSource);
|
22 | 60 | }
|
| 61 | + |
| 62 | + private DataSource getDataSource() throws SQLException { |
| 63 | + ConnectionConfig config = new ConnectionConfig(TestHelper.getConnectionString()); |
| 64 | + return new TestedDataSourceProvider(config).getDataSource(); |
| 65 | + } |
| 66 | + |
| 67 | + private void checkNlsSessionParameter( DataSource dataSource, String parameterName, String expectedValue ) throws SQLException { |
| 68 | + try ( Connection con = dataSource.getConnection() ) { |
| 69 | + try (PreparedStatement stmt = con.prepareStatement("select value from nls_session_parameters where parameter = ?")) { |
| 70 | + stmt.setString(1, parameterName); |
| 71 | + ResultSet rs = stmt.executeQuery(); |
| 72 | + if ( rs.next() ) |
| 73 | + assertEquals(expectedValue, rs.getString(1)); |
| 74 | + else |
| 75 | + fail("Could not get NLS Session parameter value for '" + parameterName + "'"); |
| 76 | + } |
| 77 | + } |
| 78 | + } |
23 | 79 | }
|
0 commit comments