Skip to content

Commit dd0dcdf

Browse files
pesseSamuel Nitsche
authored andcommitted
Output warning when --failureExitCode is set and framework is not compatible with that option
also refactored some things and made run_Default-test work with framework versions < 3.0.3, too
1 parent c140c5e commit dd0dcdf

File tree

4 files changed

+101
-30
lines changed

4 files changed

+101
-30
lines changed

src/main/java/org/utplsql/cli/RunCommand.java

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.beust.jcommander.Parameters;
55
import org.utplsql.api.*;
66
import org.utplsql.api.compatibility.CompatibilityProxy;
7+
import org.utplsql.api.compatibility.OptionalFeatures;
78
import org.utplsql.api.exception.DatabaseNotCompatibleException;
89
import org.utplsql.api.exception.SomeTestsFailedException;
910
import org.utplsql.api.reporter.Reporter;
@@ -82,6 +83,8 @@ public class RunCommand {
8283
"most actual. Use this if you use CLI with a development version of utPLSQL-framework")
8384
private boolean skipCompatibilityCheck = false;
8485

86+
private CompatibilityProxy compatibilityProxy;
87+
8588
public ConnectionInfo getConnectionInfo() {
8689
return connectionInfoList.get(0);
8790
}
@@ -92,7 +95,7 @@ public List<String> getTestPaths() {
9295

9396
public int run() throws Exception {
9497

95-
checkOracleJDBCExists();
98+
RunCommandChecker.checkOracleJDBCExists();
9699

97100
final ConnectionInfo ci = getConnectionInfo();
98101

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

115118
// Check if orai18n exists if database version is 11g
116-
checkOracleI18nExists(ci.getOracleDatabaseVersion(conn));
119+
RunCommandChecker.checkOracleI18nExists(ci.getOracleDatabaseVersion(conn));
117120

118121
// First of all do a compatibility check and fail-fast
119-
checkFrameworkCompatibility(conn);
122+
compatibilityProxy = checkFrameworkCompatibility(conn);
120123

121124
reporterList = initReporters(conn, reporterOptionsList);
122125

@@ -129,6 +132,12 @@ public int run() throws Exception {
129132
}
130133
}
131134

135+
// Output a message if --failureExitCode is set but database framework is not capable of
136+
String msg = RunCommandChecker.getCheckFailOnErrorMessage(failureExitCode, compatibilityProxy.getDatabaseVersion());
137+
if ( msg != null ) {
138+
System.out.println(msg);
139+
}
140+
132141
ExecutorService executorService = Executors.newFixedThreadPool(1 + reporterList.size());
133142

134143
// Run tests.
@@ -268,7 +277,7 @@ public List<ReporterOptions> getReporterOptionsList() {
268277
* @param conn Active Connection
269278
* @throws SQLException
270279
*/
271-
private void checkFrameworkCompatibility(Connection conn) throws SQLException {
280+
private CompatibilityProxy checkFrameworkCompatibility(Connection conn) throws SQLException {
272281

273282
CompatibilityProxy proxy = new CompatibilityProxy(conn, skipCompatibilityCheck);
274283

@@ -279,6 +288,8 @@ private void checkFrameworkCompatibility(Connection conn) throws SQLException {
279288
System.out.println("Skipping Compatibility check with framework version, expecting the latest version " +
280289
"to be installed in database");
281290
}
291+
292+
return proxy;
282293
}
283294

284295
public FileMapperOptions getMapperOptions(List<String> mappingParams, List<String> filePaths) {
@@ -328,33 +339,14 @@ public FileMapperOptions getMapperOptions(List<String> mappingParams, List<Strin
328339
return mapperOptions;
329340
}
330341

331-
332-
/** Checks that ojdbc library exists
342+
/** Returns the version of the database framework if available
333343
*
344+
* @return
334345
*/
335-
private void checkOracleJDBCExists()
336-
{
337-
if ( !OracleLibraryChecker.checkOjdbcExists() )
338-
{
339-
System.out.println("Could not find Oracle JDBC driver in classpath. Please download the jar from Oracle website" +
340-
" and copy it to the 'lib' folder of your utPLSQL-cli installation.");
341-
System.out.println("Download from http://www.oracle.com/technetwork/database/features/jdbc/jdbc-ucp-122-3110062.html");
342-
343-
throw new RuntimeException("Can't run utPLSQL-cli without Oracle JDBC driver");
344-
}
345-
}
346+
public Version getDatabaseVersion() {
347+
if ( compatibilityProxy != null )
348+
return compatibilityProxy.getDatabaseVersion();
346349

347-
/** Checks that orai18n library exists if database is an oracle 11
348-
*
349-
*/
350-
private void checkOracleI18nExists(String oracleDatabaseVersion )
351-
{
352-
if ( oracleDatabaseVersion.startsWith("11.") && !OracleLibraryChecker.checkOrai18nExists() )
353-
{
354-
System.out.println("Warning: Could not find Oracle i18n driver in classpath. Depending on the database charset " +
355-
"utPLSQL-cli might not run properly. It is recommended you download " +
356-
"the i18n driver from the Oracle website and copy it to the 'lib' folder of your utPLSQL-cli installation.");
357-
System.out.println("Download from http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html");
358-
}
350+
return null;
359351
}
360352
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package org.utplsql.cli;
2+
3+
import org.utplsql.api.Version;
4+
import org.utplsql.api.compatibility.OptionalFeatures;
5+
6+
/** Helper class to check several circumstances with RunCommand. Might need refactoring.
7+
*
8+
* @author pesse
9+
*/
10+
class RunCommandChecker {
11+
12+
/** Checks that ojdbc library exists
13+
*
14+
*/
15+
static void checkOracleJDBCExists()
16+
{
17+
if ( !OracleLibraryChecker.checkOjdbcExists() )
18+
{
19+
System.out.println("Could not find Oracle JDBC driver in classpath. Please download the jar from Oracle website" +
20+
" and copy it to the 'lib' folder of your utPLSQL-cli installation.");
21+
System.out.println("Download from http://www.oracle.com/technetwork/database/features/jdbc/jdbc-ucp-122-3110062.html");
22+
23+
throw new RuntimeException("Can't run utPLSQL-cli without Oracle JDBC driver");
24+
}
25+
}
26+
27+
/** Checks that orai18n library exists if database is an oracle 11
28+
*
29+
*/
30+
static void checkOracleI18nExists(String oracleDatabaseVersion )
31+
{
32+
if ( oracleDatabaseVersion.startsWith("11.") && !OracleLibraryChecker.checkOrai18nExists() )
33+
{
34+
System.out.println("Warning: Could not find Oracle i18n driver in classpath. Depending on the database charset " +
35+
"utPLSQL-cli might not run properly. It is recommended you download " +
36+
"the i18n driver from the Oracle website and copy it to the 'lib' folder of your utPLSQL-cli installation.");
37+
System.out.println("Download from http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html");
38+
}
39+
}
40+
41+
/** Returns a warning message if failureExitCode is specified but database version is too low
42+
*
43+
* @param failureExitCode
44+
* @param databaseVersion
45+
*/
46+
static String getCheckFailOnErrorMessage(int failureExitCode, Version databaseVersion) {
47+
if ( failureExitCode != 1 && !OptionalFeatures.FAIL_ON_ERROR.isAvailableFor(databaseVersion)) {
48+
return "Your database framework version (" + databaseVersion.getNormalizedString() + ") is not able to " +
49+
"redirect failureCodes. Please upgrade to a newer version if you want to use that feature.";
50+
}
51+
52+
return null;
53+
}
54+
}

src/test/java/org/utplsql/cli/RunCommandTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.junit.Assert;
55
import org.junit.Test;
66
import org.utplsql.api.CustomTypes;
7+
import org.utplsql.api.compatibility.OptionalFeatures;
78

89
import java.util.List;
910

@@ -119,7 +120,12 @@ public void run_Default() {
119120

120121
try {
121122
int result = runCmd.run();
122-
Assert.assertEquals(2, result);
123+
124+
// Only expect failure-exit-code to work on several framework versions
125+
if (OptionalFeatures.FAIL_ON_ERROR.isAvailableFor(runCmd.getDatabaseVersion()) )
126+
Assert.assertEquals(2, result);
127+
else
128+
Assert.assertEquals(0, result);
123129
}
124130
catch ( Exception e ) {
125131
Assert.fail(e.getMessage());
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.utplsql.cli;
2+
3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
import org.utplsql.api.Version;
6+
7+
public class TestRunCommandChecker {
8+
9+
@Test
10+
public void getCheckFailOnErrorMessage()
11+
{
12+
// FailOnError option should work since 3.0.3+ framework
13+
Assert.assertNotNull(RunCommandChecker.getCheckFailOnErrorMessage(2, new Version("3.0.0")));
14+
Assert.assertNotNull(RunCommandChecker.getCheckFailOnErrorMessage(2, new Version("3.0.1")));
15+
Assert.assertNotNull(RunCommandChecker.getCheckFailOnErrorMessage(2, new Version("3.0.2")));
16+
Assert.assertNull(RunCommandChecker.getCheckFailOnErrorMessage(2, new Version("3.0.3")));
17+
Assert.assertNull(RunCommandChecker.getCheckFailOnErrorMessage(2, new Version("3.0.4")));
18+
}
19+
}

0 commit comments

Comments
 (0)