Skip to content

Commit 204c4fa

Browse files
authored
Feature/refactor tests (#19)
* Refactor existing tests to integration tests Java : Add a new module "it" Move all existing tests into this new module Bind these tests to integration-test phase with failsafe plugin Each Integration test is run with maven-verifier-plugin Travis : Provides explicitly url parameter on maven command line Run tests and integration tests in 2 steps
1 parent 93abf66 commit 204c4fa

File tree

35 files changed

+826
-639
lines changed

35 files changed

+826
-639
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@
1818
log/
1919
target/
2020
.mvn
21+
log.txt
22+
**/pom.xml.versionsBackup

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ install:
3333
- bash .travis/install_demo_project.sh
3434

3535
script:
36-
- mvn package -DdbUser="${DB_USER}" -DdbPass="${DB_PASS}"
36+
- echo "Run Unit tests"
37+
- mvn test
38+
- echo "Run Integration tests"
39+
- mvn verify -Dmaven.skip.test -DdbUser="${DB_USER}" -DdbPass="${DB_PASS}" -DdbUrl="jdbc:oracle:thin:@${DB_URL}"
3740

3841
#before_deploy:
3942
# - bash .travis/create_release.sh

.travis/install_demo_project.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
set -ev
33

4-
PROJECT_FILES_SRC="utplsql-maven-plugin/src/test/resources/simple-project"
4+
PROJECT_FILES_SRC="utplsql-maven-plugin-it/src/it/resources/simple-project"
55
PROJECT_FILES="resources"
66

77
cat > demo_project.sh.tmp <<EOF

pom.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
<modelVersion>4.0.0</modelVersion>
44

55
<groupId>org.utplsql</groupId>
6-
<artifactId>utplsql-maven-plugin-build</artifactId>
6+
<artifactId>utplsql-maven-plugin-parent</artifactId>
77
<version>3.1.0-SNAPSHOT</version>
88
<packaging>pom</packaging>
99

10-
<name>utplsql-maven-plugin Maven Plugin Build</name>
10+
<name>utplsql-maven-plugin Parent</name>
1111

1212
<url>https://github.com/utPLSQL/utPLSQL-maven-plugin</url>
1313

@@ -18,6 +18,7 @@
1818

1919
<modules>
2020
<module>utplsql-maven-plugin</module>
21+
<module>utplsql-maven-plugin-it</module>
2122
</modules>
2223

2324
</project>

utplsql-maven-plugin-it/pom.xml

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>org.utplsql</groupId>
7+
<artifactId>utplsql-maven-plugin-parent</artifactId>
8+
<version>3.1.0-SNAPSHOT</version>
9+
</parent>
10+
<name>utplsql-maven-plugin Integration tests</name>
11+
<artifactId>utplsql-maven-plugin-it</artifactId>
12+
<packaging>jar</packaging>
13+
14+
<properties>
15+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16+
<java.version>1.8</java.version>
17+
</properties>
18+
19+
<dependencies>
20+
<dependency>
21+
<groupId>org.apache.maven</groupId>
22+
<artifactId>maven-model</artifactId>
23+
<version>3.0.2</version>
24+
</dependency>
25+
<dependency>
26+
<groupId>commons-io</groupId>
27+
<artifactId>commons-io</artifactId>
28+
<version>2.5</version>
29+
</dependency>
30+
<dependency>
31+
<groupId>org.apache.maven.shared</groupId>
32+
<artifactId>maven-verifier</artifactId>
33+
<version>1.6</version>
34+
</dependency>
35+
<dependency>
36+
<groupId>junit</groupId>
37+
<artifactId>junit</artifactId>
38+
<version>4.12</version>
39+
<scope>test</scope>
40+
</dependency>
41+
</dependencies>
42+
43+
<build>
44+
<plugins>
45+
<plugin>
46+
<groupId>org.apache.maven.plugins</groupId>
47+
<artifactId>maven-install-plugin</artifactId>
48+
<version>2.5.2</version>
49+
<configuration>
50+
<skip>true</skip>
51+
</configuration>
52+
</plugin>
53+
54+
<plugin>
55+
<groupId>org.apache.maven.plugins</groupId>
56+
<artifactId>maven-deploy-plugin</artifactId>
57+
<version>2.8.2</version>
58+
<configuration>
59+
<skip>true</skip>
60+
</configuration>
61+
</plugin>
62+
<plugin>
63+
<groupId>org.apache.maven.plugins</groupId>
64+
<artifactId>maven-compiler-plugin</artifactId>
65+
<version>3.7.0</version>
66+
<configuration>
67+
<source>${java.version}</source>
68+
<target>${java.version}</target>
69+
<encoding>${project.build.sourceEncoding}</encoding>
70+
</configuration>
71+
</plugin>
72+
<plugin>
73+
<groupId>org.codehaus.mojo</groupId>
74+
<artifactId>build-helper-maven-plugin</artifactId>
75+
<version>3.0.0</version>
76+
<executions>
77+
<execution>
78+
<id>add-it-resource</id>
79+
<phase>process-resources</phase>
80+
<goals>
81+
<goal>add-test-resource</goal>
82+
</goals>
83+
<configuration>
84+
<resources>
85+
<resource>
86+
<directory>src/it/resources</directory>
87+
</resource>
88+
</resources>
89+
</configuration>
90+
</execution>
91+
</executions>
92+
</plugin>
93+
<plugin>
94+
<groupId>org.codehaus.mojo</groupId>
95+
<artifactId>build-helper-maven-plugin</artifactId>
96+
<version>3.0.0</version>
97+
<executions>
98+
<execution>
99+
<id>add-it-source</id>
100+
<phase>process-resources</phase>
101+
<goals>
102+
<goal>add-test-source</goal>
103+
</goals>
104+
<configuration>
105+
<sources>
106+
<source>src/it/java</source>
107+
</sources>
108+
</configuration>
109+
</execution>
110+
</executions>
111+
</plugin>
112+
<plugin>
113+
<groupId>org.apache.maven.plugins</groupId>
114+
<artifactId>maven-failsafe-plugin</artifactId>
115+
<version>2.22.0</version>
116+
<executions>
117+
<execution>
118+
<id>integration-test</id>
119+
<goals>
120+
<goal>integration-test</goal>
121+
</goals>
122+
</execution>
123+
<execution>
124+
<id>verify</id>
125+
<goals>
126+
<goal>verify</goal>
127+
</goals>
128+
</execution>
129+
</executions>
130+
</plugin>
131+
132+
</plugins>
133+
</build>
134+
</project>
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
package org.utpsql.maven.plugin.test;
2+
3+
import java.io.File;
4+
import java.io.FileReader;
5+
import java.io.IOException;
6+
import java.nio.file.Files;
7+
import java.nio.file.Paths;
8+
import java.util.stream.Collectors;
9+
import java.util.stream.Stream;
10+
11+
import org.apache.commons.io.FileUtils;
12+
import org.apache.maven.it.VerificationException;
13+
import org.apache.maven.it.Verifier;
14+
import org.apache.maven.it.util.ResourceExtractor;
15+
import org.apache.maven.model.Model;
16+
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
17+
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
18+
import org.junit.Assert;
19+
import org.junit.BeforeClass;
20+
import org.junit.Test;
21+
22+
public class UtPLSQLMojoIT
23+
{
24+
25+
private static String pluginVersion = null;
26+
27+
@BeforeClass
28+
public static void setUp() throws VerificationException, IOException, XmlPullParserException {
29+
// Read plugin pom file
30+
MavenXpp3Reader reader = new MavenXpp3Reader();
31+
Model model = reader.read(new FileReader("../pom.xml"));
32+
33+
File pomFile = new File("../");
34+
Verifier verifier = new Verifier(pomFile.getAbsolutePath());
35+
36+
// delete plugin
37+
//verifier.deleteArtifact( model.getGroupId(), model.getArtifactId(), model.getVersion(), "pom" );
38+
39+
// install plugin
40+
verifier.setAutoclean(false);
41+
verifier.addCliOption("-Dmaven.skip.test=true");
42+
verifier.addCliOption("-DskipITs");
43+
verifier.executeGoal("install");
44+
45+
pluginVersion = model.getVersion();
46+
}
47+
48+
49+
@Test
50+
public void testSimpleDefinition() throws Exception
51+
{
52+
53+
try
54+
{
55+
final String PROJECT_NAME = "simple-project";
56+
File testProject = ResourceExtractor.simpleExtractResources(getClass(), "/"+ PROJECT_NAME);
57+
58+
Verifier verifier;
59+
verifier = new Verifier(testProject.getAbsolutePath());
60+
verifier.addCliOption("-N");
61+
verifier.addCliOption("-Dutplsql-maven-plugin-version="+pluginVersion);
62+
verifier.addCliOption("-DdbUrl="+System.getProperty("dbUrl"));
63+
verifier.addCliOption("-DdbUser="+System.getProperty("dbUser"));
64+
verifier.addCliOption("-DdbPass="+System.getProperty("dbPass"));
65+
66+
verifier.executeGoal("test");
67+
68+
checkReportsGenerated(PROJECT_NAME,"utplsql/sonar-test-reporter.xml","utplsql/coverage-sonar-reporter.xml");
69+
}
70+
catch (Exception e)
71+
{
72+
e.printStackTrace();
73+
Assert.fail("Unexpected Exception running the test of Definition "+e.getMessage());
74+
}
75+
}
76+
77+
@Test
78+
public void testRegexDefinition() throws Exception
79+
{
80+
try
81+
{
82+
final String PROJECT_NAME = "regex-project";
83+
File testProject = ResourceExtractor.simpleExtractResources(getClass(), "/"+ PROJECT_NAME);
84+
85+
Verifier verifier;
86+
verifier = new Verifier(testProject.getAbsolutePath());
87+
verifier.addCliOption("-N");
88+
verifier.addCliOption("-Dutplsql-maven-plugin-version="+pluginVersion);
89+
verifier.addCliOption("-DdbUrl="+System.getProperty("dbUrl"));
90+
verifier.addCliOption("-DdbUser="+System.getProperty("dbUser"));
91+
verifier.addCliOption("-DdbPass="+System.getProperty("dbPass"));
92+
93+
verifier.executeGoal("test");
94+
95+
checkReportsGenerated(PROJECT_NAME,"utplsql/sonar-test-reporter.xml","utplsql/coverage-sonar-reporter.xml");
96+
}
97+
catch (Exception e)
98+
{
99+
e.printStackTrace();
100+
Assert.fail("Unexpected Exception running the test of Definition");
101+
}
102+
}
103+
104+
@Test
105+
public void testTypeMappingDefinition() throws Exception
106+
{
107+
try
108+
{
109+
final String PROJECT_NAME = "type-mapping-project";
110+
File testProject = ResourceExtractor.simpleExtractResources(getClass(), "/"+ PROJECT_NAME);
111+
112+
Verifier verifier;
113+
verifier = new Verifier(testProject.getAbsolutePath());
114+
verifier.addCliOption("-N");
115+
verifier.addCliOption("-Dutplsql-maven-plugin-version="+pluginVersion);
116+
verifier.addCliOption("-DdbUrl="+System.getProperty("dbUrl"));
117+
verifier.addCliOption("-DdbUser="+System.getProperty("dbUser"));
118+
verifier.addCliOption("-DdbPass="+System.getProperty("dbPass"));
119+
120+
verifier.executeGoal("test");
121+
122+
checkReportsGenerated(PROJECT_NAME,"utplsql/sonar-test-reporter.xml","utplsql/coverage-sonar-reporter.xml");
123+
}
124+
catch (Exception e)
125+
{
126+
e.printStackTrace();
127+
Assert.fail("Unexpected Exception running the test of Definition");
128+
}
129+
}
130+
131+
/**
132+
*
133+
* @param files
134+
*/
135+
private void checkReportsGenerated(String projectName, String... files)
136+
{
137+
for (String filename : files)
138+
{
139+
File outputFile = new File("target/test-classes/"+projectName+"/target",filename);
140+
File expectedOutputFile = new File("target/test-classes/"+projectName+"/expected-output", filename);
141+
142+
Assert.assertTrue("The reporter for " + filename + " was not generated", outputFile.exists());
143+
try {
144+
// Duration is set to 1 before comparing contents as it is always different.
145+
// Path separator is set to "/" to ensure windows / linux / mac compatibility
146+
Stream<String> stream = Files.lines(Paths.get("target","test-classes",projectName,"target",filename));
147+
String outputContent = stream.map(line -> line.replaceAll("(duration=\"[0-9\\.]*\")", "duration=\"1\""))
148+
.map(line -> line.replaceAll("\\\\", "/"))
149+
.map(line -> line.replaceAll("\r", "").replaceAll("\n", ""))
150+
.collect(Collectors.joining("\n"));
151+
152+
stream.close();
153+
Assert.assertEquals("The files differ!",
154+
outputContent,
155+
FileUtils.readFileToString(expectedOutputFile, "utf-8").replace("\r",""));
156+
} catch (IOException e) {
157+
// TODO Auto-generated catch block
158+
e.printStackTrace();
159+
Assert.fail("Unexpected Exception running the test of Definition");
160+
}
161+
}
162+
}
163+
}

utplsql-maven-plugin/src/test/resources/simple-project/expected-output/utplsql/coverage-sonar-reporter.xml renamed to utplsql-maven-plugin-it/src/it/resources/regex-project/expected-output/utplsql/coverage-sonar-reporter.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<coverage version="1">
2-
<file path="src/test/resources/simple-project/scripts/sources/APP.PKG_TEST_ME.bdy">
2+
<file path="scripts/sources/app/packages/PKG_TEST_ME.bdy">
33
<lineToCover lineNumber="8" covered="true"/>
44
<lineToCover lineNumber="9" covered="true"/>
55
<lineToCover lineNumber="10" covered="true"/>

utplsql-maven-plugin/src/test/resources/simple-project/expected-output/utplsql/sonar-test-reporter.xml renamed to utplsql-maven-plugin-it/src/it/resources/regex-project/expected-output/utplsql/sonar-test-reporter.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<testExecutions version="1">
2-
<file path="src/test/resources/simple-project/scripts/tests/APP.TEST_PKG_TEST_ME.bdy">
2+
<file path="scripts/test/app/packages/TEST_PKG_TEST_ME.bdy">
33
<testCase name="test_fc_input_1" duration="1" >
44
</testCase>
55
<testCase name="test_fc_input_0" duration="1" >

0 commit comments

Comments
 (0)