Skip to content

Commit a3db7da

Browse files
committed
Pass Default charset from locale to new ut_runner.run method
Requires utPLSQL/utPLSQL#697 Fixes utPLSQL/utPLSQL-cli#78
1 parent ebd4cdb commit a3db7da

File tree

6 files changed

+71
-3
lines changed

6 files changed

+71
-3
lines changed

Diff for: src/main/java/org/utplsql/api/TestRunnerOptions.java

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import org.utplsql.api.reporter.Reporter;
44

5+
import java.nio.charset.Charset;
6+
import java.nio.charset.StandardCharsets;
57
import java.util.ArrayList;
68
import java.util.List;
79

@@ -22,4 +24,5 @@ public class TestRunnerOptions {
2224
public FileMapperOptions testMappingOptions;
2325
public boolean failOnErrors = false;
2426
public boolean skipCompatibilityCheck = false;
27+
public String clientCharacterSet = Charset.defaultCharset().toString();
2528
}

Diff for: src/main/java/org/utplsql/api/testRunner/AbstractTestRunnerStatement.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public AbstractTestRunnerStatement(TestRunnerOptions options, Connection conn) t
3030

3131
protected abstract String getSql();
3232

33-
protected void createStatement() throws SQLException {
33+
protected int createStatement() throws SQLException {
3434

3535
OracleConnection oraConn = conn.unwrap(OracleConnection.class);
3636

@@ -82,6 +82,8 @@ protected void createStatement() throws SQLException {
8282
callableStatement.setArray(
8383
++paramIdx, oraConn.createOracleArray(CustomTypes.UT_VARCHAR2_LIST, options.excludeObjects.toArray()));
8484
}
85+
86+
return paramIdx;
8587
}
8688

8789
public void execute() throws SQLException {

Diff for: src/main/java/org/utplsql/api/testRunner/ActualTestRunnerStatement.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,17 @@ protected String getSql() {
3333
"a_test_file_mappings => ?, " +
3434
"a_include_objects => ?, " +
3535
"a_exclude_objects => ?, " +
36-
"a_fail_on_errors => " + failOnErrors + "); " +
36+
"a_fail_on_errors => " + failOnErrors + ", " +
37+
"a_client_character_set => ?); " +
3738
"END;";
3839
}
40+
41+
@Override
42+
protected int createStatement() throws SQLException {
43+
int curParamIdx = super.createStatement();
44+
45+
callableStatement.setString(++curParamIdx, options.clientCharacterSet);
46+
47+
return curParamIdx;
48+
}
3949
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package org.utplsql.api.testRunner;
2+
3+
import org.utplsql.api.TestRunnerOptions;
4+
5+
import java.sql.Connection;
6+
import java.sql.SQLException;
7+
8+
/** TestRunner-Statement for Framework version before 3.0.3
9+
* Does not know about client character set
10+
*
11+
* @author pesse
12+
*/
13+
class Pre312TestRunnerStatement extends AbstractTestRunnerStatement {
14+
15+
public Pre312TestRunnerStatement(TestRunnerOptions options, Connection connection ) throws SQLException {
16+
super( options, connection);
17+
}
18+
19+
@Override
20+
protected String getSql() {
21+
// Workaround because Oracle JDBC doesn't support passing boolean to stored procedures.
22+
String colorConsoleStr = Boolean.toString(options.colorConsole);
23+
String failOnErrors = Boolean.toString(options.failOnErrors);
24+
25+
return
26+
"BEGIN " +
27+
"ut_runner.run(" +
28+
"a_paths => ?, " +
29+
"a_reporters => ?, " +
30+
"a_color_console => " + colorConsoleStr + ", " +
31+
"a_coverage_schemes => ?, " +
32+
"a_source_file_mappings => ?, " +
33+
"a_test_file_mappings => ?, " +
34+
"a_include_objects => ?, " +
35+
"a_exclude_objects => ?, " +
36+
"a_fail_on_errors => " + failOnErrors + "); " +
37+
"END;";
38+
}
39+
}

Diff for: src/main/java/org/utplsql/api/testRunner/TestRunnerStatementProvider.java

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public static TestRunnerStatement getCompatibleTestRunnerStatement(Version datab
2929
try {
3030
if (databaseVersion.isLessThan(new Version("3.0.3")))
3131
stmt = new Pre303TestRunnerStatement(options, conn);
32+
else if (databaseVersion.isLessThan(new Version("3.1.2")))
33+
stmt = new Pre312TestRunnerStatement(options, conn);
3234

3335
} catch ( InvalidVersionException e ) {}
3436

Diff for: src/test/java/org/utplsql/api/testRunner/TestRunnerStatementProviderIT.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,20 @@ public void testGettingPre303Version() throws SQLException {
2020

2121

2222
@Test
23-
public void testGettingActualVersion() throws SQLException {
23+
public void testGettingPre312Version_from_303() throws SQLException {
2424
TestRunnerStatement stmt = TestRunnerStatementProvider.getCompatibleTestRunnerStatement(new Version("3.0.3"), new TestRunnerOptions(), getConnection());
25+
assertEquals(Pre312TestRunnerStatement.class, stmt.getClass());
26+
}
27+
28+
@Test
29+
public void testGettingPre312Version_from_311() throws SQLException {
30+
TestRunnerStatement stmt = TestRunnerStatementProvider.getCompatibleTestRunnerStatement(new Version("3.1.1"), new TestRunnerOptions(), getConnection());
31+
assertEquals(Pre312TestRunnerStatement.class, stmt.getClass());
32+
}
33+
34+
@Test
35+
public void testGettingActualVersion() throws SQLException {
36+
TestRunnerStatement stmt = TestRunnerStatementProvider.getCompatibleTestRunnerStatement(new Version("3.1.2"), new TestRunnerOptions(), getConnection());
2537
assertEquals(ActualTestRunnerStatement.class, stmt.getClass());
2638
}
2739
}

0 commit comments

Comments
 (0)