Skip to content

Feature/pass client charset to xml and html #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/main/java/org/utplsql/api/TestRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,15 @@ private void validateReporter(Connection conn, Reporter reporter) throws SQLExce
reporter.init(conn, compatibilityProxy, reporterFactory);
}

/** Returns the databaseVersion the TestRunner was run against
*
* @return Version of the database the TestRunner was run against
*/
public Version getUsedDatabaseVersion() {
if ( compatibilityProxy != null )
return compatibilityProxy.getDatabaseVersion();
else
return null;
}

}
3 changes: 3 additions & 0 deletions src/main/java/org/utplsql/api/TestRunnerOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import org.utplsql.api.reporter.Reporter;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -22,4 +24,5 @@ public class TestRunnerOptions {
public FileMapperOptions testMappingOptions;
public boolean failOnErrors = false;
public boolean skipCompatibilityCheck = false;
public String clientCharacterSet = Charset.defaultCharset().toString();
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public AbstractTestRunnerStatement(TestRunnerOptions options, Connection conn) t

protected abstract String getSql();

protected void createStatement() throws SQLException {
protected int createStatement() throws SQLException {

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

Expand Down Expand Up @@ -82,6 +82,8 @@ protected void createStatement() throws SQLException {
callableStatement.setArray(
++paramIdx, oraConn.createOracleArray(CustomTypes.UT_VARCHAR2_LIST, options.excludeObjects.toArray()));
}

return paramIdx;
}

public void execute() throws SQLException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,17 @@ protected String getSql() {
"a_test_file_mappings => ?, " +
"a_include_objects => ?, " +
"a_exclude_objects => ?, " +
"a_fail_on_errors => " + failOnErrors + "); " +
"a_fail_on_errors => " + failOnErrors + ", " +
"a_client_character_set => ?); " +
"END;";
}

@Override
protected int createStatement() throws SQLException {
int curParamIdx = super.createStatement();

callableStatement.setString(++curParamIdx, options.clientCharacterSet);

return curParamIdx;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.utplsql.api.testRunner;

import org.utplsql.api.TestRunnerOptions;

import java.sql.Connection;
import java.sql.SQLException;

/** TestRunner-Statement for Framework version before 3.0.3
* Does not know about client character set
*
* @author pesse
*/
class Pre312TestRunnerStatement extends AbstractTestRunnerStatement {

public Pre312TestRunnerStatement(TestRunnerOptions options, Connection connection ) throws SQLException {
super( options, connection);
}

@Override
protected String getSql() {
// Workaround because Oracle JDBC doesn't support passing boolean to stored procedures.
String colorConsoleStr = Boolean.toString(options.colorConsole);
String failOnErrors = Boolean.toString(options.failOnErrors);

return
"BEGIN " +
"ut_runner.run(" +
"a_paths => ?, " +
"a_reporters => ?, " +
"a_color_console => " + colorConsoleStr + ", " +
"a_coverage_schemes => ?, " +
"a_source_file_mappings => ?, " +
"a_test_file_mappings => ?, " +
"a_include_objects => ?, " +
"a_exclude_objects => ?, " +
"a_fail_on_errors => " + failOnErrors + "); " +
"END;";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public static TestRunnerStatement getCompatibleTestRunnerStatement(Version datab
try {
if (databaseVersion.isLessThan(new Version("3.0.3")))
stmt = new Pre303TestRunnerStatement(options, conn);
else if (databaseVersion.isLessThan(new Version("3.1.2")))
stmt = new Pre312TestRunnerStatement(options, conn);

} catch ( InvalidVersionException e ) {}

Expand Down
24 changes: 23 additions & 1 deletion src/test/java/org/utplsql/api/OutputBufferIT.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.utplsql.api;

import org.junit.jupiter.api.Test;
import org.utplsql.api.compatibility.CompatibilityProxy;
import org.utplsql.api.exception.InvalidVersionException;
import org.utplsql.api.reporter.CoreReporters;
import org.utplsql.api.reporter.DefaultReporter;
import org.utplsql.api.reporter.DocumentationReporter;
Expand All @@ -9,6 +11,7 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.nio.charset.Charset;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -106,7 +109,7 @@ public void fetchAllLines() throws SQLException {
}

@Test
public void getOutputFromSonarReporter() throws SQLException {
public void getOutputFromSonarReporter() throws SQLException, InvalidVersionException {
Reporter reporter = new DefaultReporter(CoreReporters.UT_SONAR_TEST_REPORTER.name(), null).init(newConnection());

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

@Test
public void sonarReporterHasEncodingSet() throws SQLException, InvalidVersionException {
CompatibilityProxy proxy = new CompatibilityProxy(newConnection());

if ( proxy.getDatabaseVersion().isGreaterOrEqualThan(new Version("3.1.2"))) {
Reporter reporter = new DefaultReporter(CoreReporters.UT_SONAR_TEST_REPORTER.name(), null).init(getConnection());

TestRunner tr = new TestRunner()
.addPath(getUser())
.addReporter(reporter);

tr.run(getConnection());

List<String> outputLines = reporter.getOutputBuffer().fetchAll(getConnection());

assertTrue(outputLines.get(0).contains("encoding=\"" + Charset.defaultCharset().toString() + "\""));
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,20 @@ public void testGettingPre303Version() throws SQLException {


@Test
public void testGettingActualVersion() throws SQLException {
public void testGettingPre312Version_from_303() throws SQLException {
TestRunnerStatement stmt = TestRunnerStatementProvider.getCompatibleTestRunnerStatement(new Version("3.0.3"), new TestRunnerOptions(), getConnection());
assertEquals(Pre312TestRunnerStatement.class, stmt.getClass());
}

@Test
public void testGettingPre312Version_from_311() throws SQLException {
TestRunnerStatement stmt = TestRunnerStatementProvider.getCompatibleTestRunnerStatement(new Version("3.1.1"), new TestRunnerOptions(), getConnection());
assertEquals(Pre312TestRunnerStatement.class, stmt.getClass());
}

@Test
public void testGettingActualVersion() throws SQLException {
TestRunnerStatement stmt = TestRunnerStatementProvider.getCompatibleTestRunnerStatement(new Version("3.1.2"), new TestRunnerOptions(), getConnection());
assertEquals(ActualTestRunnerStatement.class, stmt.getClass());
}
}