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

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Added system-test for code coverage creation
Also separated unit- and system-tests for RunCommand and refactored RunCommand a bit to use the fluent api provided
  • Loading branch information
pesse authored and Samuel Nitsche committed Dec 31, 2017
commit b7f99e2a0df25ee4543d6c0920ddfddd4cf09ba9
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<dependency>
<groupId>org.utplsql</groupId>
<artifactId>java-api</artifactId>
<version>3.0.4</version>
<version>3.0.4-SNAPSHOT</version>
<scope>compile</scope>
<exclusions>
<exclusion>
Expand Down
11 changes: 3 additions & 8 deletions src/main/java/org/utplsql/cli/RunCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,9 @@ public int run() throws Exception {
.testMappingOptions(testMappingOptions[0])
.colorConsole(this.colorConsole)
.failOnErrors(true)
.skipCompatibilityCheck(skipCompatibilityCheck);

for (String includeObject: finalIncludeObjectsList){
testRunner.includeObject(includeObject);
}
for (String excludeObject: finalExcludeObjectsList){
testRunner.excludeObject(excludeObject);
}
.skipCompatibilityCheck(skipCompatibilityCheck)
.includeObjects(finalIncludeObjectsList)
.excludeObjects(finalExcludeObjectsList);

testRunner.run(conn);
} catch (SomeTestsFailedException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package org.utplsql.cli;

import com.sun.org.apache.xerces.internal.impl.xpath.regex.Match;
import org.junit.Assert;
import org.junit.Test;
import org.utplsql.api.compatibility.OptionalFeatures;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* System tests for Code Coverage Reporter
*
* @author pesse
*/
public class RunCommandCoverageReporterSystemTest {

private static final Pattern REGEX_COVERAGE_TITLE = Pattern.compile("<a href=\"[a-zA-Z0-9#]+\" class=\"src_link\" title=\"[a-zA-Z\\._]+\">([a-zA-Z0-9\\._]+)<\\/a>");

private String getTempCoverageFileName(int counter) {

return "tmpCoverage_" + String.valueOf(System.currentTimeMillis()) + "_" + String.valueOf(counter) + ".html";
}

/**
* Returns a random filename which does not yet exist on the local path
*
* @return
*/
private Path getTempCoverageFilePath() {
int i = 1;
Path p = Paths.get(getTempCoverageFileName(i));

while (Files.exists(p) && i < 100)
p = Paths.get(getTempCoverageFileName(i++));

if (i >= 100)
throw new IllegalStateException("Could not get temporary file for coverage output");

return p;
}

/** Checks Coverage HTML Output if a given packageName is listed
*
* @param content
* @param packageName
* @return
*/
private boolean hasCoverageListed( String content, String packageName) {
Matcher m = REGEX_COVERAGE_TITLE.matcher(content);

while ( m.find() ) {
if ( packageName.equals(m.group(1)) )
return true;
}

return false;
}

@Test
public void run_CodeCoverageWithIncludeAndExclude() {

try {
Path coveragePath = getTempCoverageFilePath();

RunCommand runCmd = RunCommandTestHelper.createRunCommand(RunCommandTestHelper.getConnectionString(),
"-f=ut_coverage_html_reporter", "-o=" + coveragePath, "-s", "-exclude=app.award_bonus,app.betwnstr");

try {
int result = runCmd.run();

String content = new Scanner(coveragePath).useDelimiter("\\Z").next();

Assert.assertEquals(true, hasCoverageListed(content, "app.remove_rooms_by_name"));
Assert.assertEquals(false, hasCoverageListed(content, "app.award_bonus"));
Assert.assertEquals(false, hasCoverageListed(content, "app.betwnstr"));

} finally {
Files.delete(coveragePath);
}
} catch (Exception e) {
Assert.fail(e.getMessage());
}

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

import com.beust.jcommander.JCommander;
import org.junit.Assert;
import org.junit.Test;
import org.utplsql.api.CustomTypes;
import org.utplsql.api.compatibility.OptionalFeatures;

import java.util.List;

/**
* System tests for run command.
*/
public class RunCommandSystemTest {


@Test
public void run_Default() {
RunCommand runCmd = RunCommandTestHelper.createRunCommand(RunCommandTestHelper.getConnectionString(),
"-f=ut_documentation_reporter",
"-c",
"--failure-exit-code=2");

try {
int result = runCmd.run();

// Only expect failure-exit-code to work on several framework versions
if (OptionalFeatures.FAIL_ON_ERROR.isAvailableFor(runCmd.getDatabaseVersion()) )
Assert.assertEquals(2, result);
else
Assert.assertEquals(0, result);
}
catch ( Exception e ) {
Assert.fail(e.getMessage());
}
}



}
56 changes: 5 additions & 51 deletions src/test/java/org/utplsql/cli/RunCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,9 @@
*/
public class RunCommandTest {

private static String sUrl;
private static String sUser;
private static String sPass;

static {
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 RunCommand createRunCommand(String... args) {
RunCommand runCmd = new RunCommand();

JCommander.newBuilder()
.addObject(runCmd)
.args(args)
.build();

return runCmd;
}

private String getConnectionString() {
return sUser + "/" + sPass + "@" + sUrl;
}

@Test
public void reporterOptions_Default() {
RunCommand runCmd = createRunCommand(getConnectionString());
RunCommand runCmd = RunCommandTestHelper.createRunCommand(RunCommandTestHelper.getConnectionString());

List<ReporterOptions> reporterOptionsList = runCmd.getReporterOptionsList();

Expand All @@ -53,7 +28,7 @@ public void reporterOptions_Default() {

@Test
public void reporterOptions_OneReporter() {
RunCommand runCmd = createRunCommand(getConnectionString(), "-f=ut_documentation_reporter", "-o=output.txt");
RunCommand runCmd = RunCommandTestHelper.createRunCommand(RunCommandTestHelper.getConnectionString(), "-f=ut_documentation_reporter", "-o=output.txt");

List<ReporterOptions> reporterOptionsList = runCmd.getReporterOptionsList();

Expand All @@ -66,7 +41,7 @@ public void reporterOptions_OneReporter() {

@Test
public void reporterOptions_OneReporterForceScreen() {
RunCommand runCmd = createRunCommand(getConnectionString(), "-f=ut_documentation_reporter", "-o=output.txt", "-s");
RunCommand runCmd = RunCommandTestHelper.createRunCommand(RunCommandTestHelper.getConnectionString(), "-f=ut_documentation_reporter", "-o=output.txt", "-s");

List<ReporterOptions> reporterOptionsList = runCmd.getReporterOptionsList();

Expand All @@ -79,7 +54,7 @@ public void reporterOptions_OneReporterForceScreen() {

@Test
public void reporterOptions_OneReporterForceScreenInverse() {
RunCommand runCmd = createRunCommand(getConnectionString(), "-f=ut_documentation_reporter", "-s", "-o=output.txt");
RunCommand runCmd = RunCommandTestHelper.createRunCommand(RunCommandTestHelper.getConnectionString(), "-f=ut_documentation_reporter", "-s", "-o=output.txt");

List<ReporterOptions> reporterOptionsList = runCmd.getReporterOptionsList();

Expand All @@ -92,7 +67,7 @@ public void reporterOptions_OneReporterForceScreenInverse() {

@Test
public void reporterOptions_TwoReporters() {
RunCommand runCmd = createRunCommand(getConnectionString(),
RunCommand runCmd = RunCommandTestHelper.createRunCommand(RunCommandTestHelper.getConnectionString(),
"-f=ut_documentation_reporter",
"-f=ut_coverage_html_reporter", "-o=coverage.html", "-s");

Expand All @@ -111,25 +86,4 @@ public void reporterOptions_TwoReporters() {
Assert.assertTrue(reporterOptions2.outputToScreen());
}

@Test
public void run_Default() {
RunCommand runCmd = createRunCommand(getConnectionString(),
"-f=ut_documentation_reporter",
"-c",
"--failure-exit-code=2");

try {
int result = runCmd.run();

// Only expect failure-exit-code to work on several framework versions
if (OptionalFeatures.FAIL_ON_ERROR.isAvailableFor(runCmd.getDatabaseVersion()) )
Assert.assertEquals(2, result);
else
Assert.assertEquals(0, result);
}
catch ( Exception e ) {
Assert.fail(e.getMessage());
}
}

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

import com.beust.jcommander.JCommander;

class RunCommandTestHelper {
private static String sUrl;
private static String sUser;
private static String sPass;

static {
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";
}

static RunCommand createRunCommand(String... args) {
RunCommand runCmd = new RunCommand();

JCommander.newBuilder()
.addObject(runCmd)
.args(args)
.build();

return runCmd;
}

static String getConnectionString() {
return sUser + "/" + sPass + "@" + sUrl;
}
}