Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Output warning when --failureExitCode is set and framework is not com…
…patible with that option

also refactored some things and made run_Default-test work with framework versions < 3.0.3, too
  • Loading branch information
pesse authored and Samuel Nitsche committed Nov 17, 2017
commit dd0dcdf2d67d6e61d920ab3e21d9e58632ba609b
50 changes: 21 additions & 29 deletions src/main/java/org/utplsql/cli/RunCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.beust.jcommander.Parameters;
import org.utplsql.api.*;
import org.utplsql.api.compatibility.CompatibilityProxy;
import org.utplsql.api.compatibility.OptionalFeatures;
import org.utplsql.api.exception.DatabaseNotCompatibleException;
import org.utplsql.api.exception.SomeTestsFailedException;
import org.utplsql.api.reporter.Reporter;
Expand Down Expand Up @@ -82,6 +83,8 @@ public class RunCommand {
"most actual. Use this if you use CLI with a development version of utPLSQL-framework")
private boolean skipCompatibilityCheck = false;

private CompatibilityProxy compatibilityProxy;

public ConnectionInfo getConnectionInfo() {
return connectionInfoList.get(0);
}
Expand All @@ -92,7 +95,7 @@ public List<String> getTestPaths() {

public int run() throws Exception {

checkOracleJDBCExists();
RunCommandChecker.checkOracleJDBCExists();

final ConnectionInfo ci = getConnectionInfo();

Expand All @@ -113,10 +116,10 @@ public int run() throws Exception {
try (Connection conn = ci.getConnection()) {

// Check if orai18n exists if database version is 11g
checkOracleI18nExists(ci.getOracleDatabaseVersion(conn));
RunCommandChecker.checkOracleI18nExists(ci.getOracleDatabaseVersion(conn));

// First of all do a compatibility check and fail-fast
checkFrameworkCompatibility(conn);
compatibilityProxy = checkFrameworkCompatibility(conn);

reporterList = initReporters(conn, reporterOptionsList);

Expand All @@ -129,6 +132,12 @@ public int run() throws Exception {
}
}

// Output a message if --failureExitCode is set but database framework is not capable of
String msg = RunCommandChecker.getCheckFailOnErrorMessage(failureExitCode, compatibilityProxy.getDatabaseVersion());
if ( msg != null ) {
System.out.println(msg);
}

ExecutorService executorService = Executors.newFixedThreadPool(1 + reporterList.size());

// Run tests.
Expand Down Expand Up @@ -268,7 +277,7 @@ public List<ReporterOptions> getReporterOptionsList() {
* @param conn Active Connection
* @throws SQLException
*/
private void checkFrameworkCompatibility(Connection conn) throws SQLException {
private CompatibilityProxy checkFrameworkCompatibility(Connection conn) throws SQLException {

CompatibilityProxy proxy = new CompatibilityProxy(conn, skipCompatibilityCheck);

Expand All @@ -279,6 +288,8 @@ private void checkFrameworkCompatibility(Connection conn) throws SQLException {
System.out.println("Skipping Compatibility check with framework version, expecting the latest version " +
"to be installed in database");
}

return proxy;
}

public FileMapperOptions getMapperOptions(List<String> mappingParams, List<String> filePaths) {
Expand Down Expand Up @@ -328,33 +339,14 @@ public FileMapperOptions getMapperOptions(List<String> mappingParams, List<Strin
return mapperOptions;
}


/** Checks that ojdbc library exists
/** Returns the version of the database framework if available
*
* @return
*/
private void checkOracleJDBCExists()
{
if ( !OracleLibraryChecker.checkOjdbcExists() )
{
System.out.println("Could not find Oracle JDBC driver in classpath. Please download the jar from Oracle website" +
" and copy it to the 'lib' folder of your utPLSQL-cli installation.");
System.out.println("Download from http://www.oracle.com/technetwork/database/features/jdbc/jdbc-ucp-122-3110062.html");

throw new RuntimeException("Can't run utPLSQL-cli without Oracle JDBC driver");
}
}
public Version getDatabaseVersion() {
if ( compatibilityProxy != null )
return compatibilityProxy.getDatabaseVersion();

/** Checks that orai18n library exists if database is an oracle 11
*
*/
private void checkOracleI18nExists(String oracleDatabaseVersion )
{
if ( oracleDatabaseVersion.startsWith("11.") && !OracleLibraryChecker.checkOrai18nExists() )
{
System.out.println("Warning: Could not find Oracle i18n driver in classpath. Depending on the database charset " +
"utPLSQL-cli might not run properly. It is recommended you download " +
"the i18n driver from the Oracle website and copy it to the 'lib' folder of your utPLSQL-cli installation.");
System.out.println("Download from http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html");
}
return null;
}
}
54 changes: 54 additions & 0 deletions src/main/java/org/utplsql/cli/RunCommandChecker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.utplsql.cli;

import org.utplsql.api.Version;
import org.utplsql.api.compatibility.OptionalFeatures;

/** Helper class to check several circumstances with RunCommand. Might need refactoring.
*
* @author pesse
*/
class RunCommandChecker {

/** Checks that ojdbc library exists
*
*/
static void checkOracleJDBCExists()
{
if ( !OracleLibraryChecker.checkOjdbcExists() )
{
System.out.println("Could not find Oracle JDBC driver in classpath. Please download the jar from Oracle website" +
" and copy it to the 'lib' folder of your utPLSQL-cli installation.");
System.out.println("Download from http://www.oracle.com/technetwork/database/features/jdbc/jdbc-ucp-122-3110062.html");

throw new RuntimeException("Can't run utPLSQL-cli without Oracle JDBC driver");
}
}

/** Checks that orai18n library exists if database is an oracle 11
*
*/
static void checkOracleI18nExists(String oracleDatabaseVersion )
{
if ( oracleDatabaseVersion.startsWith("11.") && !OracleLibraryChecker.checkOrai18nExists() )
{
System.out.println("Warning: Could not find Oracle i18n driver in classpath. Depending on the database charset " +
"utPLSQL-cli might not run properly. It is recommended you download " +
"the i18n driver from the Oracle website and copy it to the 'lib' folder of your utPLSQL-cli installation.");
System.out.println("Download from http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html");
}
}

/** Returns a warning message if failureExitCode is specified but database version is too low
*
* @param failureExitCode
* @param databaseVersion
*/
static String getCheckFailOnErrorMessage(int failureExitCode, Version databaseVersion) {
if ( failureExitCode != 1 && !OptionalFeatures.FAIL_ON_ERROR.isAvailableFor(databaseVersion)) {
return "Your database framework version (" + databaseVersion.getNormalizedString() + ") is not able to " +
"redirect failureCodes. Please upgrade to a newer version if you want to use that feature.";
}

return null;
}
}
8 changes: 7 additions & 1 deletion src/test/java/org/utplsql/cli/RunCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.junit.Assert;
import org.junit.Test;
import org.utplsql.api.CustomTypes;
import org.utplsql.api.compatibility.OptionalFeatures;

import java.util.List;

Expand Down Expand Up @@ -119,7 +120,12 @@ public void run_Default() {

try {
int result = runCmd.run();
Assert.assertEquals(2, result);

// Only expect failure-exit-code to work on several framework versions
if (OptionalFeatures.FAIL_ON_ERROR.isAvailableFor(runCmd.getDatabaseVersion()) )
Assert.assertEquals(2, result);
else
Assert.assertEquals(0, result);
}
catch ( Exception e ) {
Assert.fail(e.getMessage());
Expand Down
19 changes: 19 additions & 0 deletions src/test/java/org/utplsql/cli/TestRunCommandChecker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.utplsql.cli;

import org.junit.Assert;
import org.junit.Test;
import org.utplsql.api.Version;

public class TestRunCommandChecker {

@Test
public void getCheckFailOnErrorMessage()
{
// FailOnError option should work since 3.0.3+ framework
Assert.assertNotNull(RunCommandChecker.getCheckFailOnErrorMessage(2, new Version("3.0.0")));
Assert.assertNotNull(RunCommandChecker.getCheckFailOnErrorMessage(2, new Version("3.0.1")));
Assert.assertNotNull(RunCommandChecker.getCheckFailOnErrorMessage(2, new Version("3.0.2")));
Assert.assertNull(RunCommandChecker.getCheckFailOnErrorMessage(2, new Version("3.0.3")));
Assert.assertNull(RunCommandChecker.getCheckFailOnErrorMessage(2, new Version("3.0.4")));
}
}