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

Skip to content
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ install:

script:
- mvn package -DskipTests
- mvn package jar:jar appassembler:assemble
- mvn package verify jar:jar appassembler:assemble

before_deploy:
- bash .travis/create_release.sh
Expand Down
87 changes: 77 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@
<name>cli</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<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>
</properties>

<dependencies>
<dependency>
<groupId>org.utplsql</groupId>
<artifactId>java-api</artifactId>
<version>3.0.4-SNAPSHOT</version>
<version>3.0.5-SNAPSHOT</version>
<scope>compile</scope>
<exclusions>
<exclusion>
Expand Down Expand Up @@ -48,11 +50,17 @@
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -75,6 +83,43 @@
</programs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<excludes>
<exclude>**/*IT.java</exclude>
</excludes>
</configuration>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>${junit.platform.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>${junit.platform.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>

Expand All @@ -93,4 +138,26 @@
</repository>
</repositories>

<profiles>
<profile>
<id>utPLSQL-local</id>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<environmentVariables>
<DB_URL>${dbUrl}</DB_URL>
<DB_USER>${dbUser}</DB_USER>
<DB_PASS>${dbPass}</DB_PASS>
</environmentVariables>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
</project>
11 changes: 9 additions & 2 deletions src/main/java/org/utplsql/cli/RunCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
import com.beust.jcommander.Parameters;
import org.utplsql.api.*;
import org.utplsql.api.compatibility.CompatibilityProxy;
import org.utplsql.api.compatibility.OptionalFeatures;
import org.utplsql.api.exception.DatabaseNotCompatibleException;
import org.utplsql.api.exception.SomeTestsFailedException;
import org.utplsql.api.reporter.CoverageHTMLReporter;
import org.utplsql.api.reporter.Reporter;
import org.utplsql.api.reporter.ReporterFactory;
import org.utplsql.cli.exception.DatabaseConnectionFailed;
Expand All @@ -15,6 +14,7 @@
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.nio.file.Paths;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
Expand Down Expand Up @@ -219,6 +219,13 @@ private List<Reporter> initReporters( Connection conn, List<ReporterOptions> rep

for (ReporterOptions ro : reporterOptionsList) {
Reporter reporter = ReporterFactory.createReporter(ro.getReporterName());

// Quick-hack for CoverageHTML Reporter
if ( reporter instanceof CoverageHTMLReporter && ro.outputToFile() ) {
((CoverageHTMLReporter)reporter).setAssetsPath(ro.getOutputFileName()+"_assets/");
CoverageHTMLReporter.writeReportAssetsTo(Paths.get(ro.getOutputFileName()+"_assets/"));
}

reporter.init(conn);
ro.setReporterObj(reporter);
reporterList.add(reporter);
Expand Down
9 changes: 5 additions & 4 deletions src/test/java/org/utplsql/cli/FileWalkerTest.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package org.utplsql.cli;

import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.util.Collections;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;

/**
* Created by Vinicius on 18/06/2017.
*/
Expand All @@ -18,7 +19,7 @@ public class FileWalkerTest {
public void fileWalker_Relative() {
List<String> fileList = new FileWalker().getFileList(BASE_DIR, "source");
Collections.sort(fileList);
Assert.assertArrayEquals(new Object[] {
assertArrayEquals(new Object[] {
"source/packages/package.pkb".replace('/', File.separatorChar),
"source/packages/package.pks".replace('/', File.separatorChar),
"source/script.sql".replace('/', File.separatorChar),
Expand All @@ -30,7 +31,7 @@ public void fileWalker_Relative() {
public void fileWalker_Absolute() {
List<String> fileList = new FileWalker().getFileList(BASE_DIR, "source", false);
Collections.sort(fileList);
Assert.assertArrayEquals(new Object[] {
assertArrayEquals(new Object[] {
BASE_DIR.getAbsolutePath() + "/source/packages/package.pkb".replace('/', File.separatorChar),
BASE_DIR.getAbsolutePath() + "/source/packages/package.pks".replace('/', File.separatorChar),
BASE_DIR.getAbsolutePath() + "/source/script.sql".replace('/', File.separatorChar),
Expand Down
139 changes: 139 additions & 0 deletions src/test/java/org/utplsql/cli/RunCommandCoverageReporterIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
package org.utplsql.cli;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

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

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

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

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 Set<Path> tempPaths;

private void addTempPath(Path path) {
tempPaths.add(path);
}

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) || tempPaths.contains(p)) && i < 100)
p = Paths.get(getTempCoverageFileName(i++));

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

addTempPath(p);
addTempPath(Paths.get(p.toString()+"_assets"));

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;
}

@BeforeEach
public void setupTest() {
tempPaths = new HashSet<>();
}

@Test
public void run_CodeCoverageWithIncludeAndExclude() throws Exception {

Path coveragePath = getTempCoverageFilePath();

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


int result = runCmd.run();

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

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

}

@Test
public void coverageReporterWriteAssetsToOutput() throws Exception {
Path coveragePath = getTempCoverageFilePath();
Path coverageAssetsPath = Paths.get(coveragePath.toString() + "_assets");

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

runCmd.run();

// Check application file exists
File applicationJs = coverageAssetsPath.resolve(Paths.get("application.js")).toFile();
assertTrue(applicationJs.exists());

// Check correct script-part in HTML source exists
String content = new Scanner(coveragePath).useDelimiter("\\Z").next();
assertTrue(content.contains("<script src='" + coverageAssetsPath.toString() + "/application.js' type='text/javascript'>"));
}

@AfterEach
public void deleteTempFiles() {
tempPaths.forEach(p -> deleteDir(p.toFile()));
}

void deleteDir(File file) {
if (file.exists()) {
File[] contents = file.listFiles();
if (contents != null) {
for (File f : contents) {
deleteDir(f);
}
}
file.delete();
}
}
}
Loading