Skip to content

Commit 9c7f855

Browse files
authored
Merge pull request #57 from utPLSQL/feature/pass_client_charset_to_xml_and_html
Feature/pass client charset to xml and html
2 parents ebd4cdb + ff0b270 commit 9c7f855

File tree

8 files changed

+105
-4
lines changed

8 files changed

+105
-4
lines changed

src/main/java/org/utplsql/api/TestRunner.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,15 @@ private void validateReporter(Connection conn, Reporter reporter) throws SQLExce
180180
reporter.init(conn, compatibilityProxy, reporterFactory);
181181
}
182182

183+
/** Returns the databaseVersion the TestRunner was run against
184+
*
185+
* @return Version of the database the TestRunner was run against
186+
*/
187+
public Version getUsedDatabaseVersion() {
188+
if ( compatibilityProxy != null )
189+
return compatibilityProxy.getDatabaseVersion();
190+
else
191+
return null;
192+
}
193+
183194
}

src/main/java/org/utplsql/api/TestRunnerOptions.java

Lines changed: 3 additions & 0 deletions
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
}

src/main/java/org/utplsql/api/testRunner/AbstractTestRunnerStatement.java

Lines changed: 3 additions & 1 deletion
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 {

src/main/java/org/utplsql/api/testRunner/ActualTestRunnerStatement.java

Lines changed: 11 additions & 1 deletion
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
}
Lines changed: 39 additions & 0 deletions
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+
}

src/main/java/org/utplsql/api/testRunner/TestRunnerStatementProvider.java

Lines changed: 2 additions & 0 deletions
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

src/test/java/org/utplsql/api/OutputBufferIT.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.utplsql.api;
22

33
import org.junit.jupiter.api.Test;
4+
import org.utplsql.api.compatibility.CompatibilityProxy;
5+
import org.utplsql.api.exception.InvalidVersionException;
46
import org.utplsql.api.reporter.CoreReporters;
57
import org.utplsql.api.reporter.DefaultReporter;
68
import org.utplsql.api.reporter.DocumentationReporter;
@@ -9,6 +11,7 @@
911
import java.io.File;
1012
import java.io.FileOutputStream;
1113
import java.io.PrintStream;
14+
import java.nio.charset.Charset;
1215
import java.sql.SQLException;
1316
import java.util.ArrayList;
1417
import java.util.List;
@@ -106,7 +109,7 @@ public void fetchAllLines() throws SQLException {
106109
}
107110

108111
@Test
109-
public void getOutputFromSonarReporter() throws SQLException {
112+
public void getOutputFromSonarReporter() throws SQLException, InvalidVersionException {
110113
Reporter reporter = new DefaultReporter(CoreReporters.UT_SONAR_TEST_REPORTER.name(), null).init(newConnection());
111114

112115
new TestRunner()
@@ -119,4 +122,23 @@ public void getOutputFromSonarReporter() throws SQLException {
119122
assertTrue(outputLines.size() > 0);
120123
}
121124

125+
@Test
126+
public void sonarReporterHasEncodingSet() throws SQLException, InvalidVersionException {
127+
CompatibilityProxy proxy = new CompatibilityProxy(newConnection());
128+
129+
if ( proxy.getDatabaseVersion().isGreaterOrEqualThan(new Version("3.1.2"))) {
130+
Reporter reporter = new DefaultReporter(CoreReporters.UT_SONAR_TEST_REPORTER.name(), null).init(getConnection());
131+
132+
TestRunner tr = new TestRunner()
133+
.addPath(getUser())
134+
.addReporter(reporter);
135+
136+
tr.run(getConnection());
137+
138+
List<String> outputLines = reporter.getOutputBuffer().fetchAll(getConnection());
139+
140+
assertTrue(outputLines.get(0).contains("encoding=\"" + Charset.defaultCharset().toString() + "\""));
141+
}
142+
143+
}
122144
}

src/test/java/org/utplsql/api/testRunner/TestRunnerStatementProviderIT.java

Lines changed: 13 additions & 1 deletion
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy