Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 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
177 changes: 122 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,87 +39,89 @@ export LC_ALL=en_US.utf-8
The charset-part of LC_ALL is ignored.

## Usage
Currently, utPLSQL-cli supports the following commands:
- run
- info
- reporters

`utplsql run <ConnectionURL> [-p=(ut_path|ut_paths)] [-f=format [-o=output_file] [-s] ...]`
#### \<ConnectionURL>

```
<ConnectionURL> - accepted formats:
<user>/<password>@//<host>[:<port>]/<service>
<user>/<password>@<host>:<port>:<SID>
<user>/<password>@<TNSName>
To connect using TNS, you need to have the ORACLE_HOME environment variable set.
The file tnsnames.ora must exist in path %ORACLE_HOME%/network/admin
The file tnsnames.ora must contain valid TNS entries.
This is used in all commands as first parameter (though it's optional for `info`).

Accepted formats:

- `<user>/<password>@//<host>[:<port>]/<service>`
- `<user>/<password>@<host>:<port>:<SID>`
- `<user>/<password>@<TNSName>`

To connect using TNS, you need to have the ORACLE_HOME environment variable set.
The file tnsnames.ora must exist in path %ORACLE_HOME%/network/admin
The file tnsnames.ora must contain valid TNS entries.

### run
`utplsql run <ConnectionURL> [<options>]`


#### 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:
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.
Available options:
-f=ut_documentation_reporter
A textual pretty-print of unit test results (usually use for console output)
-f=ut_teamcity_reporter
For reporting live progress of test execution with Teamcity CI.
-f=ut_xunit_reporter
Used for reporting test results with CI servers like Jenkins/Hudson/Teamcity.
-f=ut_coverage_html_reporter
Generates a HTML coverage report with summary and line by line information on code coverage.
Based on open-source simplecov-html coverage reporter for Ruby.
Includes source code in the report.
-f=ut_coveralls_reporter
Generates a JSON coverage report providing information on code coverage with line numbers.
Designed for [Coveralls](https://coveralls.io/).
-f=ut_coverage_sonar_reporter
Generates a JSON coverage report providing information on code coverage with line numbers.
Designed for [SonarQube](https://about.sonarqube.com/) to report coverage.
-f=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.

-o=output - Defines file name to save the output from the specified reporter.
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.
If not defined, then output will be displayed on screen, even if the parameter -s is not specified.
If more than one -o parameter is specified for one -f parameter, the last one is taken into consideration.
-s - Forces putting output to to screen for a given -f parameter.
-s - Forces putting output to to screen for a given -f parameter.

-source_path=source - path to project source files, use the following options to enable custom type mappings:
-owner="app"
-regex_expression="pattern"
-type_mapping="matched_string=TYPE[/matched_string=TYPE]*"
-owner_subexpression=subexpression_number
-type_subexpression=subexpression_number
-name_subexpression=subexpression_number
-owner="app"
-regex_expression="pattern"
-type_mapping="matched_string=TYPE[/matched_string=TYPE]*"
-owner_subexpression=subexpression_number
-type_subexpression=subexpression_number
-name_subexpression=subexpression_number

-test_path=test - path to project test files, use the following options to enable custom type mappings:
-owner="app"
-regex_expression="pattern"
-type_mapping="matched_string=TYPE[/matched_string=TYPE]*"
-owner_subexpression=subexpression_number
-type_subexpression=subexpression_number
-name_subexpression=subexpression_number
-owner="app"
-regex_expression="pattern"
-type_mapping="matched_string=TYPE[/matched_string=TYPE]*"
-owner_subexpression=subexpression_number
-type_subexpression=subexpression_number
-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).

--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.

-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
-include=package_list - Comma-separated object list to include in the coverage report.
Format: [schema.]package[,[schema.]package ...].
See coverage reporting options in framework documentation.
-exclude=package_list - Comma-separated object list to exclude from the coverage report.
Format: [schema.]package[,[schema.]package ...].
See coverage reporting options in framework documentation.

-include=pckg_list - Comma-separated object list to include in the coverage report.
Format: [schema.]package[,[schema.]package ...].
See coverage reporting options in framework documentation.

-exclude=pckg_list - Comma-separated object list to exclude from the coverage report.
Format: [schema.]package[,[schema.]package ...].
See coverage reporting options in framework documentation.
```

Parameters -f, -o, -s are correlated. That is parameters -o and -s are controlling outputs for reporter specified by the preceding -f parameter.

Sonar and Coveralls reporter will only provide valid reports, when source_path and/or test_path are provided, and ut_run is executed from your project's root path.

Examples:
#### Examples

```
utplsql run hr/hr@xe -p=hr_test -f=ut_documentation_reporter -o=run.log -s -f=ut_coverage_html_reporter -o=coverage.html -source_path=source
> utplsql run hr/hr@xe -p=hr_test -f=ut_documentation_reporter -o=run.log -s -f=ut_coverage_html_reporter -o=coverage.html -source_path=source
```

Invokes all Unit tests from schema/package "hr_test" with two reporters:
Expand All @@ -128,12 +130,77 @@ Invokes all Unit tests from schema/package "hr_test" with two reporters:
* ut_coverage_html_reporter - will report only on database objects that are mapping to file structure from "source" folder and save output to file "coverage.html"

```
utplsql run hr/hr@xe
> utplsql run hr/hr@xe
```

Invokes all unit test suites from schema "hr". Results are displayed to screen using default ut_documentation_reporter.

#### Enabling Color Outputs on Windows
### info
`utplsql info [<ConnectionURL>]`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe make a separate section for the connection URL and link to it in each command. That way it is defined only once.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, came to my mind but wasn't able to come up with a good way and therefore decided to refactor later ;)



#### Examples

```
> utplsql info

cli 3.1.1-SNAPSHOT.local
utPLSQL-java-api 3.1.1-SNAPSHOT.123
```
```
> utplsql info app/app@localhost:1521/ORCLPDB1

cli 3.1.1-SNAPSHOT.local
utPLSQL-java-api 3.1.1-SNAPSHOT.123
utPLSQL 3.1.2.1913
```

### reporters
`utplsql reporters <ConnectionURL>`

#### Examples
```
> utplsql reporters app/app@localhost:1521/ORCLPDB1

UT_COVERAGE_COBERTURA_REPORTER Generates a Cobertura coverage report providing information on code coverage with line numbers.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With my pedantic hat on - wouldn't it be better to have it formatted with indentation of 4 spaces?

UT_COVERAGE_COBERTURA_REPORTER:
    Generates a Cobertura coverage report providing information on code coverage with line numbers.
    Designed for Jenkins and TFS to report coverage.

Indenting by up to 31 chars seems excessive

Designed for Jenkins and TFS to report coverage.
Cobertura Document Type Definition can be found: http://cobertura.sourceforge.net/xml/coverage-04.dtd.
Sample file: https://github.com/leobalter/testing-examples/blob/master/solutions/3/report/cobertura-coverage.xml.

UT_COVERAGE_HTML_REPORTER Generates a HTML coverage report with summary and line by line information on code coverage.
Based on open-source simplecov-html coverage reporter for Ruby.
Includes source code in the report.
Will copy all necessary assets to a folder named after the Output-File

UT_COVERAGE_SONAR_REPORTER Generates a JSON coverage report providing information on code coverage with line numbers.
Designed for [SonarQube](https://about.sonarqube.com/) to report coverage.
JSON format returned conforms with the Sonar specification: https://docs.sonarqube.org/display/SONAR/Generic+Test+Data

UT_COVERALLS_REPORTER Generates a JSON coverage report providing information on code coverage with line numbers.
Designed for [Coveralls](https://coveralls.io/).
JSON format conforms with specification: https://docs.coveralls.io/api-introduction

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_SONAR_TEST_REPORTER Generates a JSON report providing detailed information on test execution.
Designed for [SonarQube](https://about.sonarqube.com/) to report test execution.
JSON format returned conforms with the Sonar specification: https://docs.sonarqube.org/display/SONAR/Generic+Test+Data

UT_TEAMCITY_REPORTER Provides the TeamCity (a CI server by jetbrains) reporting-format that allows tracking of progress of a CI step/task as it executes.
https://confluence.jetbrains.com/display/TCD9/Build+Script+Interaction+with+TeamCity

UT_TFS_JUNIT_REPORTER Provides outcomes in a format conforming with JUnit version for TFS / VSTS.
As defined by specs :https://docs.microsoft.com/en-us/vsts/build-release/tasks/test/publish-test-results?view=vsts
Version is based on windy road junit https://github.com/windyroad/JUnit-Schema/blob/master/JUnit.xsd.

UT_XUNIT_REPORTER Depracated reporter. Please use Junit.
Provides outcomes in a format conforming with JUnit 4 and above as defined in: https://gist.github.com/kuzuha/232902acab1344d6b578
```

## Enabling Color Outputs on Windows

To enable color outputs on Windows cmd you need to install an open-source utility called [ANSICON](http://adoxa.altervista.org/ansicon/).

Expand All @@ -143,4 +210,4 @@ Since v3.1.0 you can call custom reporters (PL/SQL) via cli, too. Just call the

```
utplsql run hr/hr@xe -p=hr_test -f=my_custom_reporter -o=run.log -s
```
```
36 changes: 36 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<maven.compiler.target>1.8</maven.compiler.target>
<junit.platform.version>1.0.3</junit.platform.version>
<junit.jupiter.version>5.0.3</junit.jupiter.version>
<travisBuildNumber>local</travisBuildNumber>
</properties>

<dependencies>
Expand Down Expand Up @@ -88,6 +89,41 @@
</programs>
</configuration>
</plugin>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<id>replace-version-number</id>
<phase>generate-sources</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<basedir>${project.basedir}/src/main/java</basedir>
<includes>
<include>**/CliVersionInfo.java</include>
</includes>
<preserveDir>true</preserveDir>
<replacements>
<replacement>
<token>MAVEN_PROJECT_NAME = ".*"</token>
<value>MAVEN_PROJECT_NAME = "${project.name}"</value>
</replacement>
<replacement>
<token>MAVEN_PROJECT_VERSION = ".*"</token>
<value>MAVEN_PROJECT_VERSION = "${project.version}"</value>
</replacement>
<replacement>
<token>BUILD_NO = ".*"</token>
<value>BUILD_NO = "${travisBuildNumber}"</value>
</replacement>
</replacements>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
Expand Down
27 changes: 14 additions & 13 deletions src/main/java/org/utplsql/cli/Cli.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,43 @@ public class Cli {
static final int DEFAULT_ERROR_CODE = 1;

static final String HELP_CMD = "-h";
private static final String RUN_CMD = "run";

public static void main(String[] args) {

int exitCode = runWithExitCode(args);

System.exit(exitCode);
}

static int runWithExitCode( String[] args ) {
LocaleInitializer.initLocale();

JCommander jc = new JCommander();
jc.setProgramName("utplsql");
// jc.addCommand(HELP_CMD, new HelpCommand());
RunCommand runCmd = new RunCommand();
jc.addCommand(RUN_CMD, runCmd);

CommandProvider cmdProvider = new CommandProvider();

cmdProvider.commands().forEach(cmd -> jc.addCommand(cmd.getCommand(), cmd));

int exitCode = DEFAULT_ERROR_CODE;

try {
jc.parse(args);

if (RUN_CMD.equals(jc.getParsedCommand())) {
exitCode = runCmd.run();
} else {
throw new ParameterException("Command not specified.");
}
exitCode = cmdProvider.getCommand(jc.getParsedCommand()).run();

} catch (ParameterException e) {
if (jc.getParsedCommand() != null) {
System.err.println(e.getMessage());
jc.usage(jc.getParsedCommand());
} else {
jc.usage();
}
} catch ( DatabaseNotCompatibleException | UtPLSQLNotInstalledException | DatabaseConnectionFailed e ) {
System.out.println(e.getMessage());
} catch (Exception e) {
} catch (Exception e) {
e.printStackTrace();
}

System.exit(exitCode);
return exitCode;
}

private static class HelpCommand {
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/org/utplsql/cli/CliVersionInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.utplsql.cli;

/** This class is getting updated automatically by the build process.
* Please do not update its constants manually cause they will be overwritten.
*
* @author pesse
*/
public class CliVersionInfo {

private static final String BUILD_NO = "local";
private static final String MAVEN_PROJECT_NAME = "cli";
private static final String MAVEN_PROJECT_VERSION = "3.1.1-SNAPSHOT";

public static String getVersion() {
return MAVEN_PROJECT_VERSION + "." + BUILD_NO;
}

public static String getInfo() { return MAVEN_PROJECT_NAME + " " + getVersion(); }

}
37 changes: 37 additions & 0 deletions src/main/java/org/utplsql/cli/CommandProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.utplsql.cli;

import java.util.HashMap;
import java.util.Map;
import java.util.stream.Stream;

public class CommandProvider {

private Map<String, ICommand> commands;

public CommandProvider() {
init();
}

private void init() {
commands = new HashMap<>();

addCommand(new RunCommand());
addCommand(new VersionInfoCommand());
addCommand(new ReportersCommand());
}

private void addCommand( ICommand command ) {
commands.put(command.getCommand().toLowerCase(), command);
}

public ICommand getCommand( String key ) {
if ( commands.containsKey(key))
return commands.get(key.toLowerCase());
else
return new HelpCommand("Unknown command: '" + key + "'");
}

public Stream<ICommand> commands() {
return commands.values().stream();
}
}
Loading