diff --git a/.travis.yml b/.travis.yml index 3deef5c..b47a39d 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" @@ -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 < 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."); + } + } + } 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;