Skip to content

Bugfix/dbms output enable #141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
29 changes: 20 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ utplsql run "my/Username"/"myP@ssword"@connectstring
#### Options
```
-p=suite_path(s) - A suite path or a comma separated list of suite paths for unit test to be executed.
The path(s) can be in one of the following formats:
(--path) The path(s) can be in one of the following formats:
schema[.package[.procedure]]
schema:suite[.suite[.suite][...]][.procedure]
Both formats can be mixed in the list.
If only schema is provided, then all suites owner by that schema are executed.
If -p is omitted, the current schema is used.

-f=format - A reporter to be used for reporting.
If no -f option is provided, the default ut_documentation_reporter is used.
(--format) If no -f option is provided, the default ut_documentation_reporter is used.
See reporters command for possible values
-o=output - Defines file name to save the output from the specified reporter.
If defined, the output is not displayed on screen by default. This can be changed with the -s parameter.
Expand All @@ -119,12 +119,14 @@ utplsql run "my/Username"/"myP@ssword"@connectstring
-name_subexpression=subexpression_number

-c - If specified, enables printing of test results in colors as defined by ANSICONSOLE standards.
Works only on reporeters that support colors (ut_documentation_reporter).
(--color) Works only on reporeters that support colors (ut_documentation_reporter).

--failure-exit-code - Override the exit code on failure, defaults to 1. You can set it to 0 to always exit with a success status.
-fcode=code - Override the exit code on failure, defaults to 1. You can set it to 0 to always exit with a success status.
(--failure-exit-code)

-scc - If specified, skips the compatibility-check with the version of the database framework.
If you skip compatibility-check, CLI will expect the most actual framework version
(--skip- If you skip compatibility-check, CLI will expect the most actual framework version
compatibility-check)

-include=pckg_list - Comma-separated object list to include in the coverage report.
Format: [schema.]package[,[schema.]package ...].
Expand All @@ -135,13 +137,16 @@ utplsql run "my/Username"/"myP@ssword"@connectstring
See coverage reporting options in framework documentation.

-q - Does not output the informational messages normally printed to console.
Default: false
(--quiet) Default: false

-d - Outputs a load of debug information to console
Default: false
(--debug) Default: false

-t - Sets the timeout in minutes after which the cli will abort.
Default 60
-t=timeInMinutes - Sets the timeout in minutes after which the cli will abort.
(--timeout) Default 60

-dbout - Enables DBMS_OUTPUT in the TestRunner-Session
(--dbms_output) Default: false
```

Parameters -f, -o, -s are correlated. That is parameters -o and -s are controlling outputs for reporter specified by the preceding -f parameter.
Expand Down Expand Up @@ -214,13 +219,19 @@ UT_COVERALLS_REPORTER:
Designed for [Coveralls](https://coveralls.io/).
JSON format conforms with specification: https://docs.coveralls.io/api-introduction

UT_DEBUG_REPORTER:
No description available

UT_DOCUMENTATION_REPORTER:
A textual pretty-print of unit test results (usually use for console output)
Provides additional properties lvl and failed

UT_JUNIT_REPORTER:
Provides outcomes in a format conforming with JUnit 4 and above as defined in: https://gist.github.com/kuzuha/232902acab1344d6b578

UT_REALTIME_REPORTER:
Provides test results in a XML format, for clients such as SQL Developer interested in showing progressing details.

UT_SONAR_TEST_REPORTER:
Generates a JSON report providing detailed information on test execution.
Designed for [SonarQube](https://about.sonarqube.com/) to report test execution.
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>org.utplsql</groupId>
<artifactId>cli</artifactId>
<version>3.1.6</version>
<version>3.1.7-SNAPSHOT</version>
<packaging>jar</packaging>

<name>cli</name>
Expand All @@ -22,7 +22,7 @@
<dependency>
<groupId>org.utplsql</groupId>
<artifactId>java-api</artifactId>
<version>3.1.6</version>
<version>3.1.7-SNAPSHOT</version>
<scope>compile</scope>
<exclusions>
<exclusion>
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/org/utplsql/cli/RunCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ public class RunCommand implements ICommand {
description = "Sets the timeout in minutes after which the cli will abort. Default 60")
private int timeoutInMinutes = 60;

@Parameter(
names = {"-dbout", "--dbms_output"},
description = "Enables DBMS_OUTPUT for the TestRunner (default: DISABLED)"
)
private boolean enableDbmsOutput = false;

private CompatibilityProxy compatibilityProxy;
private ReporterFactory reporterFactory;
private ReporterManager reporterManager;
Expand Down Expand Up @@ -157,15 +163,15 @@ public int doRun() throws OracleCreateStatmenetStuckException {
reporterList = initReporters(dataSource);

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

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

// Run tests.
Future<Boolean> future = executorService.submit(new RunTestRunnerTask(dataSource, newTestRunner(reporterList)));
Future<Boolean> future = executorService.submit(new RunTestRunnerTask(dataSource, newTestRunner(reporterList), enableDbmsOutput));

// Gather each reporter results on a separate thread.
getReporterManager().startReporterGatherers(executorService, dataSource);
Expand Down Expand Up @@ -278,7 +284,7 @@ private void initDatabase(DataSource dataSource) throws SQLException {
// First of all do a compatibility check and fail-fast
compatibilityProxy = checkFrameworkCompatibility(conn);

logger.info("Successfully connected to database. UtPLSQL core: {}", compatibilityProxy.getDatabaseVersion());
logger.info("Successfully connected to database. UtPLSQL core: {}", compatibilityProxy.getVersionDescription());
logger.info("Oracle-Version: {}", new DefaultDatabaseInformation().getOracleVersion(conn));
}
catch (SQLException e) {
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/org/utplsql/cli/RunTestRunnerTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.utplsql.api.DBHelper;
import org.utplsql.api.TestRunner;
import org.utplsql.api.exception.OracleCreateStatmenetStuckException;
import org.utplsql.api.exception.SomeTestsFailedException;
Expand All @@ -24,17 +25,20 @@ public class RunTestRunnerTask implements Callable<Boolean> {
private static final Logger logger = LoggerFactory.getLogger(RunTestRunnerTask.class);
private DataSource dataSource;
private TestRunner testRunner;
private boolean enableDmbsOutput;

RunTestRunnerTask(DataSource dataSource, TestRunner testRunner) {
RunTestRunnerTask(DataSource dataSource, TestRunner testRunner, boolean enableDmbsOutput) {
this.dataSource = dataSource;
this.testRunner = testRunner;
this.enableDmbsOutput = enableDmbsOutput;
}

@Override
public Boolean call() throws Exception {
Connection conn = null;
try {
conn = dataSource.getConnection();
if ( enableDmbsOutput ) DBHelper.enableDBMSOutput(conn);
logger.info("Running tests now.");
logger.info("--------------------------------------");
testRunner.run(conn);
Expand All @@ -54,6 +58,7 @@ public Boolean call() throws Exception {
} finally {
if ( conn != null ) {
try {
if ( enableDmbsOutput ) DBHelper.disableDBMSOutput(conn);
conn.close();
} catch (SQLException e) {
logger.error(e.getMessage(), e);
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/org/utplsql/cli/RunCommandIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,14 @@ void run_MultipleReporters() throws Exception {
}


@Test
void run_withDbmsOutputEnabled() throws Exception {

int result = TestHelper.runApp("run",
TestHelper.getConnectionString(),
"-dbout",
"--failure-exit-code=2");

assertValidReturnCode(result);
}
}