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