Skip to content

Commit b611f2d

Browse files
authored
Merge pull request #13 from viniciusam/feature/test_failure_indicator
Feature/test failure indicator
2 parents c0757c4 + f3f1ca5 commit b611f2d

File tree

7 files changed

+111
-14
lines changed

7 files changed

+111
-14
lines changed

.travis.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ env:
1515
- CACHE_DIR=$HOME/.cache
1616
- MAVEN_HOME=/usr/local/maven
1717
- MAVEN_CFG=$HOME/.m2
18-
- API_DB_URL="127.0.0.1:1521:XE"
19-
- API_DB_USER=api
20-
- API_DB_PASS=api
18+
- DB_URL="127.0.0.1:1521:XE"
19+
- DB_USER=app
20+
- DB_PASS=app
2121
matrix:
2222
- ORACLE_VERSION="11g-xe-r2" DOCKER_OPTIONS="--shm-size=1g"
2323

@@ -31,6 +31,7 @@ install:
3131
- bash .travis/maven_cfg.sh
3232
- bash .travis/start_db.sh
3333
- bash .travis/install_utplsql.sh
34+
- bash .travis/install_demo_project.sh
3435

3536
script:
3637
- mvn test -B

.travis/install_demo_project.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
set -ev
3+
cd $(dirname $(readlink -f $0))
4+
5+
PROJECT_FILE="utPLSQL-demo-project"
6+
git clone -b develop --single-branch https://github.com/utPLSQL/utPLSQL-demo-project.git
7+
8+
cat > demo_project.sh.tmp <<EOF
9+
sqlplus -S -L sys/oracle@//127.0.0.1:1521/xe AS SYSDBA <<SQL
10+
create user ${DB_USER} identified by ${DB_PASS} quota unlimited on USERS default tablespace USERS;
11+
grant create session, create procedure, create type, create table, create sequence, create view to ${DB_USER};
12+
grant select any dictionary to ${DB_USER};
13+
exit
14+
SQL
15+
16+
cd ${PROJECT_FILE}
17+
sqlplus -S -L ${DB_USER}/${DB_PASS}@//127.0.0.1:1521/xe <<SQL
18+
whenever sqlerror exit failure rollback
19+
whenever oserror exit failure rollback
20+
21+
@source/award_bonus/employees_test.sql
22+
@source/award_bonus/award_bonus.prc
23+
24+
@source/between_string/betwnstr.fnc
25+
26+
@source/remove_rooms_by_name/rooms.sql
27+
@source/remove_rooms_by_name/remove_rooms_by_name.prc
28+
29+
@test/award_bonus/test_award_bonus.pks
30+
@test/award_bonus/test_award_bonus.pkb
31+
32+
@test/between_string/test_betwnstr.pks
33+
@test/between_string/test_betwnstr.pkb
34+
35+
@test/remove_rooms_by_name/test_remove_rooms_by_name.pks
36+
@test/remove_rooms_by_name/test_remove_rooms_by_name.pkb
37+
38+
exit
39+
SQL
40+
EOF
41+
42+
docker cp ./$PROJECT_FILE $ORACLE_VERSION:/$PROJECT_FILE
43+
docker cp ./demo_project.sh.tmp $ORACLE_VERSION:/demo_project.sh
44+
docker exec $ORACLE_VERSION bash demo_project.sh

.travis/install_utplsql.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ git clone -b develop --single-branch https://github.com/utPLSQL/utPLSQL.git
1515

1616
# Create a temporary install script.
1717
cat > install.sh.tmp <<EOF
18-
# tar -xzf $UTPLSQL_FILE.tar.gz && rm $UTPLSQL_FILE.tar.gz
19-
cd /$UTPLSQL_FILE/source
20-
sqlplus -S -L sys/oracle@//127.0.0.1:1521/xe AS SYSDBA @install_headless.sql
18+
# tar -xzf ${UTPLSQL_FILE}.tar.gz && rm ${UTPLSQL_FILE}.tar.gz
19+
cd ${UTPLSQL_FILE}/source
20+
sqlplus -S -L sys/oracle@//127.0.0.1:1521/xe AS SYSDBA @install_headless.sql ut3 ut3 users
2121
EOF
2222

2323
# Copy utPLSQL files to the container and install it.
@@ -28,6 +28,7 @@ docker cp ./create_api_user.sh $ORACLE_VERSION:/create_api_user.sh
2828

2929
# Remove temporary files.
3030
# rm $UTPLSQL_FILE.tar.gz
31+
rm -rf $UTPLSQL_FILE
3132
rm install.sh.tmp
3233

3334
# Execute the utPLSQL installation inside the container.

src/main/java/io/github/utplsql/api/TestRunner.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.utplsql.api;
22

3+
import io.github.utplsql.api.exception.SomeTestsFailedException;
34
import io.github.utplsql.api.reporter.DocumentationReporter;
45
import io.github.utplsql.api.reporter.Reporter;
56
import oracle.jdbc.OracleConnection;
@@ -21,6 +22,7 @@ public class TestRunner {
2122
private List<String> testFiles = new ArrayList<>();
2223
private List<String> includeObjects = new ArrayList<>();
2324
private List<String> excludeObjects = new ArrayList<>();
25+
private boolean failOnErrors = false;
2426

2527
public TestRunner addPath(String path) {
2628
this.pathList.add(path);
@@ -72,7 +74,12 @@ public TestRunner excludeObject(String obj) {
7274
return this;
7375
}
7476

75-
public void run(Connection conn) throws SQLException {
77+
public TestRunner failOnErrors(boolean failOnErrors) {
78+
this.failOnErrors = failOnErrors;
79+
return this;
80+
}
81+
82+
public void run(Connection conn) throws SomeTestsFailedException, SQLException {
7683
for (Reporter r : this.reporterList)
7784
validateReporter(conn, r);
7885

@@ -86,16 +93,23 @@ public void run(Connection conn) throws SQLException {
8693

8794
// Workaround because Oracle JDBC doesn't support passing boolean to stored procedures.
8895
String colorConsoleStr = Boolean.toString(this.colorConsole);
96+
String failOnErrors = Boolean.toString(this.failOnErrors);
8997

9098
OracleConnection oraConn = conn.unwrap(OracleConnection.class);
9199
CallableStatement callableStatement = null;
92100
try {
93101
callableStatement = conn.prepareCall(
94102
"BEGIN " +
95103
"ut_runner.run(" +
96-
"a_paths => ?, a_reporters => ?, a_color_console => " + colorConsoleStr + ", " +
97-
"a_coverage_schemes => ?, a_source_files => ?, a_test_files => ?, " +
98-
"a_include_objects => ?, a_exclude_objects => ?); " +
104+
"a_paths => ?, " +
105+
"a_reporters => ?, " +
106+
"a_color_console => " + colorConsoleStr + ", " +
107+
"a_coverage_schemes => ?, " +
108+
"a_source_files => ?, " +
109+
"a_test_files => ?, " +
110+
"a_include_objects => ?, " +
111+
"a_exclude_objects => ?, " +
112+
"a_fail_on_errors => " + failOnErrors + "); " +
99113
"END;");
100114

101115
int paramIdx = 0;
@@ -142,6 +156,12 @@ public void run(Connection conn) throws SQLException {
142156
}
143157

144158
callableStatement.execute();
159+
} catch (SQLException e) {
160+
if (e.getErrorCode() == SomeTestsFailedException.ERROR_CODE) {
161+
throw new SomeTestsFailedException(e.getMessage(), e);
162+
} else {
163+
throw e;
164+
}
145165
} finally {
146166
if (callableStatement != null)
147167
callableStatement.close();
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package io.github.utplsql.api.exception;
2+
3+
import java.sql.SQLException;
4+
5+
/**
6+
* Custom exception class to indicate if some tests failed.
7+
*/
8+
public class SomeTestsFailedException extends SQLException {
9+
10+
public static final int ERROR_CODE = 20213;
11+
12+
public SomeTestsFailedException(String reason, Throwable cause) {
13+
super(reason, cause);
14+
}
15+
16+
}

src/test/java/io/github/utplsql/api/TestRunnerTest.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.utplsql.api;
22

3+
import io.github.utplsql.api.exception.SomeTestsFailedException;
34
import io.github.utplsql.api.reporter.*;
45
import io.github.utplsql.api.rules.DatabaseRule;
56
import org.junit.Assert;
@@ -32,7 +33,6 @@ public void runWithManyReporters() {
3233
try {
3334
Connection conn = db.newConnection();
3435
new TestRunner()
35-
.addPath("ut3")
3636
.addPath(db.getUser())
3737
.addReporter(new DocumentationReporter().init(conn))
3838
.addReporter(new CoverageHTMLReporter().init(conn))
@@ -47,4 +47,19 @@ public void runWithManyReporters() {
4747
}
4848
}
4949

50+
@Test
51+
public void failOnErrors() {
52+
try {
53+
Connection conn = db.newConnection();
54+
new TestRunner()
55+
.failOnErrors(true)
56+
.run(conn);
57+
Assert.fail();
58+
} catch (SomeTestsFailedException ignored) {
59+
System.out.println("Expected exception object thrown.");
60+
} catch (SQLException e) {
61+
Assert.fail("Wrong exception object thrown.");
62+
}
63+
}
64+
5065
}

src/test/java/io/github/utplsql/api/rules/DatabaseRule.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ public class DatabaseRule extends ExternalResource {
1818
private static String sPass;
1919

2020
static {
21-
sUrl = System.getenv("API_DB_URL") != null ? System.getenv("API_DB_URL") : "127.0.0.1:1521:XE";
22-
sUser = System.getenv("API_DB_USER") != null ? System.getenv("API_DB_USER") : "app";
23-
sPass = System.getenv("API_DB_PASS") != null ? System.getenv("API_DB_PASS") : "app";
21+
sUrl = System.getenv("DB_URL") != null ? System.getenv("DB_URL") : "192.168.99.100:1521:XE";
22+
sUser = System.getenv("DB_USER") != null ? System.getenv("DB_USER") : "app";
23+
sPass = System.getenv("DB_PASS") != null ? System.getenv("DB_PASS") : "app";
2424
}
2525

2626
private List<Connection> connectionList;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy