Skip to content

Commit 2d58506

Browse files
jgarecJerome Garec
authored andcommitted
Refactor test project
* Move test project to a dedicated location * Fix generated coverage, and check file paths for #11 * Checks output file content (duration should be set to 1)
1 parent 774b265 commit 2d58506

File tree

9 files changed

+55
-14
lines changed

9 files changed

+55
-14
lines changed

utplsql-maven-plugin/src/test/java/org/utpsql/maven/plugin/test/UtPLSQLMojoTest.java

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package org.utpsql.maven.plugin.test;
22

33
import java.io.File;
4+
import java.io.IOException;
45

6+
import org.apache.commons.io.FileUtils;
57
import org.apache.maven.plugin.testing.MojoRule;
68
import org.junit.Assert;
79
import org.junit.Rule;
@@ -10,9 +12,7 @@
1012

1113
public class UtPLSQLMojoTest
1214
{
13-
public static final String POM_PATH = "src/test/resources/";
14-
15-
public static final String OUTPUT_DIRECTORY = "target/test-classes";
15+
public static final String TARGET_DIRECTORY = "target/test-classes";
1616

1717
@Rule
1818
public MojoRule rule = new MojoRule();
@@ -23,12 +23,13 @@ public void testDefinition() throws Exception
2323

2424
try
2525
{
26-
UtPLSQLMojo myMojo = (UtPLSQLMojo) rule.lookupConfiguredMojo(new File(POM_PATH), "test");
26+
final String PROJECT_NAME = "simple-project";
27+
UtPLSQLMojo myMojo = (UtPLSQLMojo) rule.lookupConfiguredMojo(new File(TARGET_DIRECTORY+"/"+PROJECT_NAME), "test");
2728

2829
Assert.assertNotNull(myMojo);
2930
myMojo.execute();
3031

31-
checkCoverReportsGenerated("utplsql/coverage-sonar-reporter.xml", "utplsql/sonar-test-reporter.xml");
32+
checkCoverReportsGenerated(PROJECT_NAME,"utplsql/coverage-sonar-reporter.xml", "utplsql/sonar-test-reporter.xml");
3233
}
3334
catch (Exception e)
3435
{
@@ -41,12 +42,24 @@ public void testDefinition() throws Exception
4142
*
4243
* @param files
4344
*/
44-
private void checkCoverReportsGenerated(String... files)
45+
private void checkCoverReportsGenerated(String projectName, String... files)
4546
{
4647
for (String filename : files)
4748
{
48-
File file = new File(OUTPUT_DIRECTORY, filename);
49-
Assert.assertTrue("The reporter for " + filename + " was not generated", file.exists());
49+
File outputFile = new File(TARGET_DIRECTORY+"/"+projectName+"/target/", filename);
50+
File expectedOutputFile = new File(TARGET_DIRECTORY+"/"+projectName+"/expected-output/", filename);
51+
52+
Assert.assertTrue("The reporter for " + filename + " was not generated", outputFile.exists());
53+
try {
54+
// Duration is set to 1 before comparing contents.
55+
Assert.assertEquals("The files differ!",
56+
FileUtils.readFileToString(outputFile, "utf-8").replaceAll("(duration=\"[0-9\\.]*\")", "duration=\"1\""),
57+
FileUtils.readFileToString(expectedOutputFile, "utf-8"));
58+
} catch (IOException e) {
59+
// TODO Auto-generated catch block
60+
e.printStackTrace();
61+
Assert.fail("Unexpected Exception running the test of Definition");
62+
}
5063
}
5164
}
5265

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<coverage version="1">
2+
<file path="src\test\resources\simple-project\scripts\sources\APP.PKG_TEST_ME.bdy">
3+
<lineToCover lineNumber="8" covered="true"/>
4+
<lineToCover lineNumber="9" covered="true"/>
5+
<lineToCover lineNumber="10" covered="true"/>
6+
<lineToCover lineNumber="11" covered="true"/>
7+
<lineToCover lineNumber="13" covered="true"/>
8+
<lineToCover lineNumber="19" covered="true"/>
9+
<lineToCover lineNumber="22" covered="true"/>
10+
<lineToCover lineNumber="23" covered="true"/>
11+
</file>
12+
</coverage>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<testExecutions version="1">
2+
<file path="src\test\resources\simple-project\scripts\tests\APP.TEST_PKG_TEST_ME.bdy">
3+
<testCase name="test_fc_input_1" duration="1" >
4+
</testCase>
5+
<testCase name="test_fc_input_0" duration="1" >
6+
</testCase>
7+
<testCase name="test_fc_input_null" duration="1" >
8+
</testCase>
9+
<testCase name="test_pr_test_me_null" duration="1" >
10+
</testCase>
11+
<testCase name="test_pr_test_me_not_null" duration="1" >
12+
</testCase>
13+
<testCase name="test_pr_test_me_exists" duration="1" >
14+
</testCase>
15+
<testCase name="test_pr_test_me_cursor" duration="1" >
16+
</testCase>
17+
</file>
18+
</testExecutions>

utplsql-maven-plugin/src/test/resources/pom.xml renamed to utplsql-maven-plugin/src/test/resources/simple-project/pom.xml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,14 @@
1111

1212

1313
<properties>
14-
<dbUrl>jdbc:oracle:thin:@127.0.0.1:1521:xe</dbUrl>
14+
<dbUrl>jdbc:oracle:thin:@127.0.0.1:1521:xe</dbUrl>
1515
<!--
1616
<dbUser>ut3</dbUser>
1717
<dbPass>XNtxj8eEgA6X6b6f</dbPass>
1818
-->
1919
</properties>
2020

2121
<build>
22-
<directory>../../../target/test-classes</directory>
23-
2422
<plugins>
2523
<plugin>
2624
<groupId>${pom.groupId}</groupId>
@@ -35,7 +33,7 @@
3533
<ignoreFailure>false</ignoreFailure>
3634

3735
<paths>
38-
<path>ut3</path>
36+
<path>app</path>
3937
</paths>
4038

4139
<reporters>
@@ -53,7 +51,7 @@
5351

5452
<sources>
5553
<source>
56-
<directory>src/test/resources/scripts/sources</directory>
54+
<directory>src/test/resources/simple-project/scripts/sources</directory>
5755
<includes>
5856
<include>**/*bdy</include>
5957
<include>**/*spc</include>
@@ -63,7 +61,7 @@
6361

6462
<tests>
6563
<test>
66-
<directory>src/test/resources/scripts/test</directory>
64+
<directory>src/test/resources/simple-project/scripts/tests</directory>
6765
<includes>
6866
<include>**/*bdy</include>
6967
<include>**/*spc</include>

utplsql-maven-plugin/src/test/resources/scripts/sources/PKG_TEST_ME.bdy renamed to utplsql-maven-plugin/src/test/resources/simple-project/scripts/sources/APP.PKG_TEST_ME.bdy

File renamed without changes.

utplsql-maven-plugin/src/test/resources/scripts/sources/PKG_TEST_ME.spc renamed to utplsql-maven-plugin/src/test/resources/simple-project/scripts/sources/APP.PKG_TEST_ME.spc

File renamed without changes.

utplsql-maven-plugin/src/test/resources/scripts/sources/TO_TEST_ME.tab renamed to utplsql-maven-plugin/src/test/resources/simple-project/scripts/sources/TO_TEST_ME.tab

File renamed without changes.

utplsql-maven-plugin/src/test/resources/scripts/test/TEST_PKG_TEST_ME.bdy renamed to utplsql-maven-plugin/src/test/resources/simple-project/scripts/tests/APP.TEST_PKG_TEST_ME.bdy

File renamed without changes.

utplsql-maven-plugin/src/test/resources/scripts/test/TEST_PKG_TEST_ME.spc renamed to utplsql-maven-plugin/src/test/resources/simple-project/scripts/tests/APP.TEST_PKG_TEST_ME.spc

File renamed without changes.

0 commit comments

Comments
 (0)