From d59b88d6ec776ffa61e14edde0fbdd7758f8d586 Mon Sep 17 00:00:00 2001 From: Vinicius Avellar Date: Wed, 19 Jul 2017 23:32:34 -0300 Subject: [PATCH 1/4] Add option to fail on errors --- .../io/github/utplsql/api/TestRunner.java | 28 ++++++++++++++++--- .../exception/SomeTestsFailedException.java | 16 +++++++++++ .../io/github/utplsql/api/TestRunnerTest.java | 17 ++++++++++- 3 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 src/main/java/io/github/utplsql/api/exception/SomeTestsFailedException.java diff --git a/src/main/java/io/github/utplsql/api/TestRunner.java b/src/main/java/io/github/utplsql/api/TestRunner.java index c904093..d980cf1 100644 --- a/src/main/java/io/github/utplsql/api/TestRunner.java +++ b/src/main/java/io/github/utplsql/api/TestRunner.java @@ -1,5 +1,6 @@ package io.github.utplsql.api; +import io.github.utplsql.api.exception.SomeTestsFailedException; import io.github.utplsql.api.reporter.DocumentationReporter; import io.github.utplsql.api.reporter.Reporter; import oracle.jdbc.OracleConnection; @@ -21,6 +22,7 @@ public class TestRunner { private List testFiles = new ArrayList<>(); private List includeObjects = new ArrayList<>(); private List excludeObjects = new ArrayList<>(); + private boolean failOnErrors = false; public TestRunner addPath(String path) { this.pathList.add(path); @@ -72,7 +74,12 @@ public TestRunner excludeObject(String obj) { return this; } - public void run(Connection conn) throws SQLException { + public TestRunner failOnErrors(boolean failOnErrors) { + this.failOnErrors = failOnErrors; + return this; + } + + public void run(Connection conn) throws SomeTestsFailedException, SQLException { for (Reporter r : this.reporterList) validateReporter(conn, r); @@ -86,6 +93,7 @@ public void run(Connection conn) throws SQLException { // Workaround because Oracle JDBC doesn't support passing boolean to stored procedures. String colorConsoleStr = Boolean.toString(this.colorConsole); + String failOnErrors = Boolean.toString(this.failOnErrors); OracleConnection oraConn = conn.unwrap(OracleConnection.class); CallableStatement callableStatement = null; @@ -93,9 +101,15 @@ public void run(Connection conn) throws SQLException { callableStatement = conn.prepareCall( "BEGIN " + "ut_runner.run(" + - "a_paths => ?, a_reporters => ?, a_color_console => " + colorConsoleStr + ", " + - "a_coverage_schemes => ?, a_source_files => ?, a_test_files => ?, " + - "a_include_objects => ?, a_exclude_objects => ?); " + + "a_paths => ?, " + + "a_reporters => ?, " + + "a_color_console => " + colorConsoleStr + ", " + + "a_coverage_schemes => ?, " + + "a_source_files => ?, " + + "a_test_files => ?, " + + "a_include_objects => ?, " + + "a_exclude_objects => ?, " + + "a_fail_on_errors => " + failOnErrors + "); " + "END;"); int paramIdx = 0; @@ -142,6 +156,12 @@ public void run(Connection conn) throws SQLException { } callableStatement.execute(); + } catch (SQLException e) { + if (e.getErrorCode() == SomeTestsFailedException.ERROR_CODE) { + throw new SomeTestsFailedException(e.getMessage(), e); + } else { + throw e; + } } finally { if (callableStatement != null) callableStatement.close(); diff --git a/src/main/java/io/github/utplsql/api/exception/SomeTestsFailedException.java b/src/main/java/io/github/utplsql/api/exception/SomeTestsFailedException.java new file mode 100644 index 0000000..48e7452 --- /dev/null +++ b/src/main/java/io/github/utplsql/api/exception/SomeTestsFailedException.java @@ -0,0 +1,16 @@ +package io.github.utplsql.api.exception; + +import java.sql.SQLException; + +/** + * Custom exception class to indicate if some tests failed. + */ +public class SomeTestsFailedException extends SQLException { + + public static final int ERROR_CODE = 20213; + + public SomeTestsFailedException(String reason, Throwable cause) { + super(reason, cause); + } + +} diff --git a/src/test/java/io/github/utplsql/api/TestRunnerTest.java b/src/test/java/io/github/utplsql/api/TestRunnerTest.java index f7f0600..dd198a3 100644 --- a/src/test/java/io/github/utplsql/api/TestRunnerTest.java +++ b/src/test/java/io/github/utplsql/api/TestRunnerTest.java @@ -1,5 +1,6 @@ package io.github.utplsql.api; +import io.github.utplsql.api.exception.SomeTestsFailedException; import io.github.utplsql.api.reporter.*; import io.github.utplsql.api.rules.DatabaseRule; import org.junit.Assert; @@ -32,7 +33,6 @@ public void runWithManyReporters() { try { Connection conn = db.newConnection(); new TestRunner() - .addPath("ut3") .addPath(db.getUser()) .addReporter(new DocumentationReporter().init(conn)) .addReporter(new CoverageHTMLReporter().init(conn)) @@ -47,4 +47,19 @@ public void runWithManyReporters() { } } + @Test + public void failOnErrors() { + try { + Connection conn = db.newConnection(); + new TestRunner() + .failOnErrors(true) + .run(conn); + Assert.fail(); + } catch (SomeTestsFailedException ignored) { + System.out.println("Expected exception object thrown."); + } catch (SQLException e) { + Assert.fail("Wrong exception object thrown."); + } + } + } From f5e73d5cda5ab12505ff4b307ba7700dc94b75e7 Mon Sep 17 00:00:00 2001 From: Vinicius Avellar Date: Fri, 21 Jul 2017 20:28:33 -0300 Subject: [PATCH 2/4] Change utplsql install user --- .travis/install_utplsql.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis/install_utplsql.sh b/.travis/install_utplsql.sh index 5032f08..b17ff8f 100644 --- a/.travis/install_utplsql.sh +++ b/.travis/install_utplsql.sh @@ -17,7 +17,7 @@ git clone -b develop --single-branch https://github.com/utPLSQL/utPLSQL.git cat > install.sh.tmp < Date: Fri, 21 Jul 2017 22:01:04 -0300 Subject: [PATCH 3/4] Change db env names --- .travis.yml | 6 +++--- .travis/install_utplsql.sh | 1 + src/test/java/io/github/utplsql/api/rules/DatabaseRule.java | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3deef5c..a0bc18b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,9 +15,9 @@ env: - CACHE_DIR=$HOME/.cache - MAVEN_HOME=/usr/local/maven - MAVEN_CFG=$HOME/.m2 - - API_DB_URL="127.0.0.1:1521:XE" - - API_DB_USER=api - - API_DB_PASS=api + - DB_URL="127.0.0.1:1521:XE" + - DB_USER=app + - DB_PASS=app matrix: - ORACLE_VERSION="11g-xe-r2" DOCKER_OPTIONS="--shm-size=1g" diff --git a/.travis/install_utplsql.sh b/.travis/install_utplsql.sh index b17ff8f..e1ffcd3 100644 --- a/.travis/install_utplsql.sh +++ b/.travis/install_utplsql.sh @@ -28,6 +28,7 @@ docker cp ./create_api_user.sh $ORACLE_VERSION:/create_api_user.sh # Remove temporary files. # rm $UTPLSQL_FILE.tar.gz +rm -rf $UTPLSQL_FILE rm install.sh.tmp # Execute the utPLSQL installation inside the container. diff --git a/src/test/java/io/github/utplsql/api/rules/DatabaseRule.java b/src/test/java/io/github/utplsql/api/rules/DatabaseRule.java index da0c35a..2cb5805 100644 --- a/src/test/java/io/github/utplsql/api/rules/DatabaseRule.java +++ b/src/test/java/io/github/utplsql/api/rules/DatabaseRule.java @@ -18,9 +18,9 @@ public class DatabaseRule extends ExternalResource { private static String sPass; static { - sUrl = System.getenv("API_DB_URL") != null ? System.getenv("API_DB_URL") : "127.0.0.1:1521:XE"; - sUser = System.getenv("API_DB_USER") != null ? System.getenv("API_DB_USER") : "app"; - sPass = System.getenv("API_DB_PASS") != null ? System.getenv("API_DB_PASS") : "app"; + sUrl = System.getenv("DB_URL") != null ? System.getenv("DB_URL") : "192.168.99.100:1521:XE"; + sUser = System.getenv("DB_USER") != null ? System.getenv("DB_USER") : "app"; + sPass = System.getenv("DB_PASS") != null ? System.getenv("DB_PASS") : "app"; } private List connectionList; From f3f1ca56993087ba3f340016387f0ce4f28e3a46 Mon Sep 17 00:00:00 2001 From: Vinicius Avellar Date: Fri, 21 Jul 2017 22:01:22 -0300 Subject: [PATCH 4/4] Add demo project with failing tests example --- .travis.yml | 1 + .travis/install_demo_project.sh | 44 +++++++++++++++++++++++++++++++++ .travis/install_utplsql.sh | 4 +-- 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 .travis/install_demo_project.sh diff --git a/.travis.yml b/.travis.yml index a0bc18b..b47a39d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,6 +31,7 @@ install: - bash .travis/maven_cfg.sh - bash .travis/start_db.sh - bash .travis/install_utplsql.sh + - bash .travis/install_demo_project.sh script: - mvn test -B diff --git a/.travis/install_demo_project.sh b/.travis/install_demo_project.sh new file mode 100644 index 0000000..adb9566 --- /dev/null +++ b/.travis/install_demo_project.sh @@ -0,0 +1,44 @@ +#!/bin/bash +set -ev +cd $(dirname $(readlink -f $0)) + +PROJECT_FILE="utPLSQL-demo-project" +git clone -b develop --single-branch https://github.com/utPLSQL/utPLSQL-demo-project.git + +cat > demo_project.sh.tmp < install.sh.tmp <