Skip to content

Commit 087505e

Browse files
Merge pull request #15 from jgarec/feature/add_regex_test
Feature/add regex test
2 parents 3f3d101 + 4cf00ef commit 087505e

File tree

21 files changed

+488
-48
lines changed

21 files changed

+488
-48
lines changed

.travis/install_demo_project.sh

Lines changed: 5 additions & 5 deletions
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"
4+
PROJECT_FILES_SRC="utplsql-maven-plugin/src/test/resources/simple-project"
55
PROJECT_FILES="resources"
66

77
cat > demo_project.sh.tmp <<EOF
@@ -18,11 +18,11 @@ whenever sqlerror exit failure rollback
1818
whenever oserror exit failure rollback
1919
2020
@scripts/sources/TO_TEST_ME.tab
21-
@scripts/sources/PKG_TEST_ME.spc
22-
@scripts/sources/PKG_TEST_ME.bdy
21+
@scripts/sources/APP.PKG_TEST_ME.spc
22+
@scripts/sources/APP.PKG_TEST_ME.bdy
2323
24-
@scripts/test/TEST_PKG_TEST_ME.spc
25-
@scripts/test/TEST_PKG_TEST_ME.bdy
24+
@scripts/tests/APP.TEST_PKG_TEST_ME.spc
25+
@scripts/tests/APP.TEST_PKG_TEST_ME.bdy
2626
2727
exit
2828
SQL

README.md

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,50 +31,45 @@ You have to be a fully utPLSQL environment available compatible with the Java AP
3131

3232
* `paths`
3333
* Paths of the resources
34+
35+
* `sources`
36+
* Path to project source files
3437
* `sourcesRegexExpression`
35-
*
38+
* utPLSQL will convert file paths into database objects using the following regular expression
3639
* `sourcesOwnerSubexpression`
37-
*
40+
* Object owner is identified by the expression with the specified set of brackets
3841
* `sourcesNameSubexpression`
39-
*
42+
* Object name is identified by the expression with the specified set of brackets
4043
* `sourcesTypeSubexpression`
41-
*
44+
* Object Type is identified by the expression with the specified set of brackets
4245

4346
* `tests`
44-
* Test fo the scripts at the style of the maven resources
47+
* Path to project test files
4548
* `testsRegexExpression`
46-
*
49+
* utPLSQL will convert file paths into database objects using the following regular expression
4750
* `testsOwnerSubexpression`
48-
*
51+
* Owner is identified by the expression with the specified set of brackets
4952
* `testsNameSubexpression`
50-
*
53+
* Object name is identified by the expression with the specified set of brackets
5154
* `testsTypeSubexpression`
52-
53-
* `targetDir`
54-
* Target dir, this is a readonly property
55-
* Default: `${project.build.directory}`
56-
* `includeObject`
57-
* Include Object
58-
* `excludeObject`
59-
* Exclude Objects
55+
* Object Type is identified by the expression with the specified set of brackets
6056

6157

6258

6359
### Sample of use
6460
The next snippet is a sample of declaration of the pom
6561
```xml
66-
<plugin>
62+
<plugin>
6763
<groupId>org.utplsql</groupId>
6864
<artifactId>utplsql-maven-plugin</artifactId>
6965
<version>1.0.0-SNAPSHOT</version>
70-
<goals>
71-
<goal>test</goal>
72-
</goals>
73-
<configuration>
66+
<goals>
67+
<goal>test</goal>
68+
</goals>
69+
<configuration>
7470
<dbUrl>url_of_connection</dbUrl>
7571
<dbUser>user</dbUser>
7672
<dbPass>password</dbPass>
77-
<version>3.1.0</version>
7873
<failOnErrors>false</failOnErrors>
7974
<reporters>
8075
<reporter>
@@ -109,6 +104,10 @@ The next snippet is a sample of declaration of the pom
109104
</includes>
110105
</test>
111106
</tests>
112-
</configuration>
113-
</plugin>
107+
</configuration>
108+
</plugin>
114109
```
110+
111+
More project samples are available in the src/test/resources directory :
112+
* simple-project : minimalist test project with standard project directory structure
113+
* regex-project : override project directory structure and use additional parameters (sourcesRegexExpression, testsRegexExpression, ...) to tell utPLSQL how the project files are to be mapped into database objects.

pom.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99

1010
<name>utplsql-maven-plugin Maven Plugin Build</name>
1111

12-
<!-- FIXME change it to the project's website -->
13-
<url>http://maven.apache.org</url>
12+
<url>https://github.com/utPLSQL/utPLSQL-maven-plugin</url>
1413

1514
<properties>
1615
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

utplsql-maven-plugin/pom.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010

1111
<name>utplsql-maven-plugin Maven Plugin</name>
1212

13-
<!-- FIXME change it to the project's website -->
14-
<url>http://maven.apache.org</url>
13+
<url>https://github.com/utPLSQL/utPLSQL-maven-plugin</url>
1514

1615
<properties>
1716
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
package org.utpsql.maven.plugin.test;
22

33
import java.io.File;
4+
import java.io.IOException;
5+
import java.nio.file.Files;
6+
import java.nio.file.Paths;
7+
import java.util.stream.Collectors;
8+
import java.util.stream.Stream;
49

10+
import org.apache.commons.io.FileUtils;
511
import org.apache.maven.plugin.testing.MojoRule;
612
import org.junit.Assert;
713
import org.junit.Rule;
@@ -10,9 +16,7 @@
1016

1117
public class UtPLSQLMojoTest
1218
{
13-
public static final String POM_PATH = "src/test/resources/";
14-
15-
public static final String OUTPUT_DIRECTORY = "target/test-classes";
19+
public static final String TARGET_DIRECTORY = "target/test-classes";
1620

1721
@Rule
1822
public MojoRule rule = new MojoRule();
@@ -23,31 +27,71 @@ public void testDefinition() throws Exception
2327

2428
try
2529
{
26-
UtPLSQLMojo myMojo = (UtPLSQLMojo) rule.lookupConfiguredMojo(new File(POM_PATH), "test");
30+
final String PROJECT_NAME = "simple-project";
31+
UtPLSQLMojo myMojo = (UtPLSQLMojo) rule.lookupConfiguredMojo(new File(TARGET_DIRECTORY+"/"+PROJECT_NAME), "test");
2732

2833
Assert.assertNotNull(myMojo);
2934
myMojo.execute();
3035

31-
checkCoverReportsGenerated("utplsql/coverage-sonar-reporter.xml", "utplsql/sonar-test-reporter.xml");
36+
checkReportsGenerated(PROJECT_NAME,"utplsql/coverage-sonar-reporter.xml", "utplsql/sonar-test-reporter.xml");
3237
}
3338
catch (Exception e)
3439
{
3540
e.printStackTrace();
3641
Assert.fail("Unexpected Exception running the test of Definition");
3742
}
3843
}
44+
45+
@Test
46+
public void testRegexDefinition() throws Exception
47+
{
48+
try
49+
{
50+
final String PROJECT_NAME = "regex-project";
51+
UtPLSQLMojo myMojo = (UtPLSQLMojo) rule.lookupConfiguredMojo(new File(TARGET_DIRECTORY+"/"+PROJECT_NAME), "test");
52+
53+
Assert.assertNotNull(myMojo);
54+
myMojo.execute();
55+
56+
checkReportsGenerated(PROJECT_NAME,"utplsql/coverage-sonar-reporter.xml", "utplsql/sonar-test-reporter.xml");
57+
}
58+
catch (Exception e)
59+
{
60+
e.printStackTrace();
61+
Assert.fail("Unexpected Exception running the test of Definition");
62+
}
63+
}
3964

4065
/**
4166
*
4267
* @param files
4368
*/
44-
private void checkCoverReportsGenerated(String... files)
69+
private void checkReportsGenerated(String projectName, String... files)
4570
{
4671
for (String filename : files)
4772
{
48-
File file = new File(OUTPUT_DIRECTORY, filename);
49-
Assert.assertTrue("The reporter for " + filename + " was not generated", file.exists());
73+
File outputFile = new File(TARGET_DIRECTORY+"/"+projectName+"/target/", filename);
74+
File expectedOutputFile = new File(TARGET_DIRECTORY+"/"+projectName+"/expected-output/", filename);
75+
76+
Assert.assertTrue("The reporter for " + filename + " was not generated", outputFile.exists());
77+
try {
78+
// Duration is set to 1 before comparing contents as it is always different.
79+
// Path separator is set to "/" to ensure windows / linux / mac compatibility
80+
Stream<String> stream = Files.lines(Paths.get(TARGET_DIRECTORY,projectName,"target",filename));
81+
String outputContent = stream.map(line -> line.replaceAll("(duration=\"[0-9\\.]*\")", "duration=\"1\""))
82+
.map(line -> line.replaceAll("\\\\", "/"))
83+
.map(line -> line.replaceAll("\r", "").replaceAll("\n", ""))
84+
.collect(Collectors.joining("\n"));
85+
86+
stream.close();
87+
Assert.assertEquals("The files differ!",
88+
outputContent,
89+
FileUtils.readFileToString(expectedOutputFile, "utf-8").replace("\r",""));
90+
} catch (IOException e) {
91+
// TODO Auto-generated catch block
92+
e.printStackTrace();
93+
Assert.fail("Unexpected Exception running the test of Definition");
94+
}
5095
}
5196
}
52-
5397
}
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/regex-project/scripts/sources/app/packages/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/regex-project/scripts/test/app/packages/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>
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
<groupId>org.utplsql</groupId>
6+
<artifactId>utplsql-maven-plugin-test</artifactId>
7+
<version>1.0.0-SNAPSHOT</version>
8+
<packaging>maven-plugin</packaging>
9+
10+
<name>utplsql-maven-plugin Maven Plugin Test</name>
11+
12+
13+
<properties>
14+
<dbUrl>jdbc:oracle:thin:@127.0.0.1:1521:xe</dbUrl>
15+
<!--
16+
<dbUser>ut3</dbUser>
17+
<dbPass>XNtxj8eEgA6X6b6f</dbPass>
18+
-->
19+
</properties>
20+
21+
<build>
22+
23+
<plugins>
24+
<plugin>
25+
<groupId>${pom.groupId}</groupId>
26+
<artifactId>utplsql-maven-plugin</artifactId>
27+
<version>${pom.version}</version>
28+
<goals>
29+
<goal>test</goal>
30+
</goals>
31+
<configuration>
32+
<!-- Mandatory Attributes -->
33+
34+
<ignoreFailure>false</ignoreFailure>
35+
36+
<paths>
37+
<path>app</path>
38+
</paths>
39+
40+
<reporters>
41+
<reporter>
42+
<name>UT_COVERAGE_SONAR_REPORTER</name>
43+
<fileOutput>utplsql/coverage-sonar-reporter.xml</fileOutput>
44+
<consoleOutput>true</consoleOutput>
45+
</reporter>
46+
<reporter>
47+
<name>UT_SONAR_TEST_REPORTER</name>
48+
<fileOutput>utplsql/sonar-test-reporter.xml</fileOutput>
49+
<consoleOutput>true</consoleOutput>
50+
</reporter>
51+
</reporters>
52+
53+
<sources>
54+
<source>
55+
<directory>src/test/resources/regex-project/scripts/sources</directory>
56+
<includes>
57+
<include>**/*bdy</include>
58+
<include>**/*spc</include>
59+
</includes>
60+
</source>
61+
</sources>
62+
<sourcesRegexExpression>.*(\\|\/)(\w+)(\\|\/)(\w+)(\\|\/)(\w+).(\w{3})</sourcesRegexExpression>
63+
<sourcesOwnerSubexpression>2</sourcesOwnerSubexpression>
64+
<sourcesNameSubexpression>6</sourcesNameSubexpression>
65+
<sourcesTypeSubexpression>7</sourcesTypeSubexpression>
66+
67+
<tests>
68+
<test>
69+
<directory>src/test/resources/regex-project/scripts/test</directory>
70+
<includes>
71+
<include>**/*bdy</include>
72+
<include>**/*spc</include>
73+
</includes>
74+
</test>
75+
</tests>
76+
<testsRegexExpression>.*(\\|\/)(\w+)(\\|\/)(\w+)(\\|\/)(\w+).(\w{3})</testsRegexExpression>
77+
<testsOwnerSubexpression>2</testsOwnerSubexpression>
78+
<testsNameSubexpression>6</testsNameSubexpression>
79+
<testsTypeSubexpression>7</testsTypeSubexpression>
80+
81+
</configuration>
82+
</plugin>
83+
</plugins>
84+
</build>
85+
</project>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
CREATE OR REPLACE PACKAGE BODY APP.PKG_TEST_ME IS
2+
3+
--
4+
-- This
5+
--
6+
FUNCTION FC_TEST_ME(PPARAM1 IN VARCHAR2) RETURN NUMBER IS
7+
BEGIN
8+
IF PPARAM1 IS NULL THEN
9+
RETURN NULL;
10+
ELSIF PPARAM1 = '1' THEN
11+
RETURN 1;
12+
ELSE
13+
RETURN 0;
14+
END IF;
15+
END FC_TEST_ME;
16+
17+
PROCEDURE PR_TEST_ME(PSNAME IN VARCHAR2) IS
18+
BEGIN
19+
IF PSNAME IS NULL THEN
20+
NULL;
21+
ELSE
22+
INSERT INTO TO_TEST_ME (SNAME) VALUES (PSNAME);
23+
COMMIT;
24+
END IF;
25+
END PR_TEST_ME;
26+
27+
END PKG_TEST_ME;
28+
/
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
--
2+
-- This package is used TO demonstrate the utPL/SQL possibilities
3+
--
4+
CREATE OR REPLACE PACKAGE app.PKG_TEST_ME AS
5+
FUNCTION FC_TEST_ME(PPARAM1 IN VARCHAR2) RETURN NUMBER;
6+
PROCEDURE PR_TEST_ME(PSNAME IN VARCHAR2);
7+
END PKG_TEST_ME;
8+
/

0 commit comments

Comments
 (0)