Skip to content

Commit 91d2f43

Browse files
author
Samuel Nitsche
committed
Refactored tests to use Surefire, Failsafe and JUnit 5
1 parent 5ba83f4 commit 91d2f43

10 files changed

+239
-184
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ install:
3434

3535
script:
3636
- mvn package -DskipTests
37-
- mvn package jar:jar appassembler:assemble
37+
- mvn package verify jar:jar appassembler:assemble
3838

3939
before_deploy:
4040
- bash .travis/create_release.sh

pom.xml

Lines changed: 77 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,19 @@
1010
<name>cli</name>
1111
<url>http://maven.apache.org</url>
1212

13-
<properties>
14-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15-
<maven.compiler.source>1.8</maven.compiler.source>
16-
<maven.compiler.target>1.8</maven.compiler.target>
17-
</properties>
13+
<properties>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
<maven.compiler.source>1.8</maven.compiler.source>
16+
<maven.compiler.target>1.8</maven.compiler.target>
17+
<junit.platform.version>1.0.3</junit.platform.version>
18+
<junit.jupiter.version>5.0.3</junit.jupiter.version>
19+
</properties>
1820

1921
<dependencies>
2022
<dependency>
2123
<groupId>org.utplsql</groupId>
2224
<artifactId>java-api</artifactId>
23-
<version>3.0.4-SNAPSHOT</version>
25+
<version>3.0.5-SNAPSHOT</version>
2426
<scope>compile</scope>
2527
<exclusions>
2628
<exclusion>
@@ -48,11 +50,17 @@
4850
<scope>compile</scope>
4951
</dependency>
5052
<dependency>
51-
<groupId>junit</groupId>
52-
<artifactId>junit</artifactId>
53-
<version>4.12</version>
53+
<groupId>org.junit.jupiter</groupId>
54+
<artifactId>junit-jupiter-api</artifactId>
55+
<version>${junit.jupiter.version}</version>
5456
<scope>test</scope>
55-
</dependency>
57+
</dependency>
58+
<dependency>
59+
<groupId>org.junit.jupiter</groupId>
60+
<artifactId>junit-jupiter-engine</artifactId>
61+
<version>${junit.jupiter.version}</version>
62+
<scope>test</scope>
63+
</dependency>
5664
</dependencies>
5765

5866
<build>
@@ -75,6 +83,43 @@
7583
</programs>
7684
</configuration>
7785
</plugin>
86+
<plugin>
87+
<groupId>org.apache.maven.plugins</groupId>
88+
<artifactId>maven-surefire-plugin</artifactId>
89+
<version>2.19.1</version>
90+
<configuration>
91+
<excludes>
92+
<exclude>**/*IT.java</exclude>
93+
</excludes>
94+
</configuration>
95+
<dependencies>
96+
<dependency>
97+
<groupId>org.junit.platform</groupId>
98+
<artifactId>junit-platform-surefire-provider</artifactId>
99+
<version>${junit.platform.version}</version>
100+
</dependency>
101+
</dependencies>
102+
</plugin>
103+
<plugin>
104+
<groupId>org.apache.maven.plugins</groupId>
105+
<artifactId>maven-failsafe-plugin</artifactId>
106+
<version>2.19.1</version>
107+
<executions>
108+
<execution>
109+
<goals>
110+
<goal>integration-test</goal>
111+
<goal>verify</goal>
112+
</goals>
113+
</execution>
114+
</executions>
115+
<dependencies>
116+
<dependency>
117+
<groupId>org.junit.platform</groupId>
118+
<artifactId>junit-platform-surefire-provider</artifactId>
119+
<version>${junit.platform.version}</version>
120+
</dependency>
121+
</dependencies>
122+
</plugin>
78123
</plugins>
79124
</build>
80125

@@ -93,4 +138,26 @@
93138
</repository>
94139
</repositories>
95140

141+
<profiles>
142+
<profile>
143+
<id>utPLSQL-local</id>
144+
<build>
145+
<pluginManagement>
146+
<plugins>
147+
<plugin>
148+
<groupId>org.apache.maven.plugins</groupId>
149+
<artifactId>maven-failsafe-plugin</artifactId>
150+
<configuration>
151+
<environmentVariables>
152+
<DB_URL>${dbUrl}</DB_URL>
153+
<DB_USER>${dbUser}</DB_USER>
154+
<DB_PASS>${dbPass}</DB_PASS>
155+
</environmentVariables>
156+
</configuration>
157+
</plugin>
158+
</plugins>
159+
</pluginManagement>
160+
</build>
161+
</profile>
162+
</profiles>
96163
</project>

src/test/java/org/utplsql/cli/FileWalkerTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package org.utplsql.cli;
22

3-
import org.junit.Assert;
4-
import org.junit.Test;
3+
import org.junit.jupiter.api.Test;
54

65
import java.io.File;
76
import java.util.Collections;
87
import java.util.List;
98

9+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
10+
1011
/**
1112
* Created by Vinicius on 18/06/2017.
1213
*/
@@ -18,7 +19,7 @@ public class FileWalkerTest {
1819
public void fileWalker_Relative() {
1920
List<String> fileList = new FileWalker().getFileList(BASE_DIR, "source");
2021
Collections.sort(fileList);
21-
Assert.assertArrayEquals(new Object[] {
22+
assertArrayEquals(new Object[] {
2223
"source/packages/package.pkb".replace('/', File.separatorChar),
2324
"source/packages/package.pks".replace('/', File.separatorChar),
2425
"source/script.sql".replace('/', File.separatorChar),
@@ -30,7 +31,7 @@ public void fileWalker_Relative() {
3031
public void fileWalker_Absolute() {
3132
List<String> fileList = new FileWalker().getFileList(BASE_DIR, "source", false);
3233
Collections.sort(fileList);
33-
Assert.assertArrayEquals(new Object[] {
34+
assertArrayEquals(new Object[] {
3435
BASE_DIR.getAbsolutePath() + "/source/packages/package.pkb".replace('/', File.separatorChar),
3536
BASE_DIR.getAbsolutePath() + "/source/packages/package.pks".replace('/', File.separatorChar),
3637
BASE_DIR.getAbsolutePath() + "/source/script.sql".replace('/', File.separatorChar),
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package org.utplsql.cli;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import java.nio.file.Files;
6+
import java.nio.file.Path;
7+
import java.nio.file.Paths;
8+
import java.util.Scanner;
9+
import java.util.regex.Matcher;
10+
import java.util.regex.Pattern;
11+
12+
import static org.junit.jupiter.api.Assertions.assertEquals;
13+
14+
/**
15+
* System tests for Code Coverage Reporter
16+
*
17+
* @author pesse
18+
*/
19+
public class RunCommandCoverageReporterIT {
20+
21+
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>");
22+
23+
private String getTempCoverageFileName(int counter) {
24+
25+
return "tmpCoverage_" + String.valueOf(System.currentTimeMillis()) + "_" + String.valueOf(counter) + ".html";
26+
}
27+
28+
/**
29+
* Returns a random filename which does not yet exist on the local path
30+
*
31+
* @return
32+
*/
33+
private Path getTempCoverageFilePath() {
34+
int i = 1;
35+
Path p = Paths.get(getTempCoverageFileName(i));
36+
37+
while (Files.exists(p) && i < 100)
38+
p = Paths.get(getTempCoverageFileName(i++));
39+
40+
if (i >= 100)
41+
throw new IllegalStateException("Could not get temporary file for coverage output");
42+
43+
return p;
44+
}
45+
46+
/**
47+
* Checks Coverage HTML Output if a given packageName is listed
48+
*
49+
* @param content
50+
* @param packageName
51+
* @return
52+
*/
53+
private boolean hasCoverageListed(String content, String packageName) {
54+
Matcher m = REGEX_COVERAGE_TITLE.matcher(content);
55+
56+
while (m.find()) {
57+
if (packageName.equals(m.group(1)))
58+
return true;
59+
}
60+
61+
return false;
62+
}
63+
64+
@Test
65+
public void run_CodeCoverageWithIncludeAndExclude() throws Exception {
66+
67+
Path coveragePath = getTempCoverageFilePath();
68+
69+
RunCommand runCmd = RunCommandTestHelper.createRunCommand(RunCommandTestHelper.getConnectionString(),
70+
"-f=ut_coverage_html_reporter", "-o=" + coveragePath, "-s", "-exclude=app.award_bonus,app.betwnstr");
71+
72+
try {
73+
int result = runCmd.run();
74+
75+
String content = new Scanner(coveragePath).useDelimiter("\\Z").next();
76+
77+
assertEquals(true, hasCoverageListed(content, "app.remove_rooms_by_name"));
78+
assertEquals(false, hasCoverageListed(content, "app.award_bonus"));
79+
assertEquals(false, hasCoverageListed(content, "app.betwnstr"));
80+
81+
} finally {
82+
Files.delete(coveragePath);
83+
}
84+
85+
}
86+
}

src/test/java/org/utplsql/cli/RunCommandCoverageReporterSystemTest.java

Lines changed: 0 additions & 91 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.utplsql.cli;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.utplsql.api.compatibility.OptionalFeatures;
5+
6+
import static org.junit.jupiter.api.Assertions.assertEquals;
7+
8+
/**
9+
* System tests for run command.
10+
*/
11+
public class RunCommandIT {
12+
13+
@Test
14+
public void run_Default() throws Exception {
15+
RunCommand runCmd = RunCommandTestHelper.createRunCommand(RunCommandTestHelper.getConnectionString(),
16+
"-f=ut_documentation_reporter",
17+
"-c",
18+
"--failure-exit-code=2");
19+
20+
int result = runCmd.run();
21+
22+
// Only expect failure-exit-code to work on several framework versions
23+
if (OptionalFeatures.FAIL_ON_ERROR.isAvailableFor(runCmd.getDatabaseVersion()))
24+
assertEquals(2, result);
25+
else
26+
assertEquals(0, result);
27+
}
28+
29+
30+
}

0 commit comments

Comments
 (0)