Skip to content

Commit a2c357f

Browse files
committed
Adds support of custom type parameters (#5)
* Adds new parameters : sourcesCustomTypeMapping & testsCustomTypeMapping * Adds one new sample project
1 parent 087505e commit a2c357f

File tree

12 files changed

+477
-5
lines changed

12 files changed

+477
-5
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ You have to be a fully utPLSQL environment available compatible with the Java AP
4141
* `sourcesNameSubexpression`
4242
* Object name is identified by the expression with the specified set of brackets
4343
* `sourcesTypeSubexpression`
44-
* Object Type is identified by the expression with the specified set of brackets
44+
* Object Type is identified by the expression with the specified set of brackets
45+
* `sourcesCustomTypeMapping`
46+
* List of Custom Type Mappings
4547

4648
* `tests`
4749
* Path to project test files
@@ -53,7 +55,8 @@ You have to be a fully utPLSQL environment available compatible with the Java AP
5355
* Object name is identified by the expression with the specified set of brackets
5456
* `testsTypeSubexpression`
5557
* Object Type is identified by the expression with the specified set of brackets
56-
58+
* `testsCustomTypeMapping`
59+
* List of Custom Type Mappings
5760

5861

5962
### Sample of use
@@ -111,3 +114,4 @@ The next snippet is a sample of declaration of the pom
111114
More project samples are available in the src/test/resources directory :
112115
* simple-project : minimalist test project with standard project directory structure
113116
* 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.
117+
* type-mapping-project : This project shows how to use regex and custom type parameters togethers.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package org.utplsql.maven.plugin;
2+
3+
/**
4+
* Bean used by maven to populate its model.
5+
*
6+
* <customTypeMapping>
7+
* <type>...</type>
8+
* <mapping>...</mapping>
9+
* </customTypeMapping>
10+
*
11+
*/
12+
public class CustomTypeMapping {
13+
/**
14+
* Object type.
15+
*/
16+
private String type;
17+
18+
/**
19+
* Custom mapping value.
20+
*/
21+
private String customMapping;
22+
23+
/**
24+
* @return The Object type.
25+
*/
26+
public String getType() {
27+
return type;
28+
}
29+
30+
/**
31+
* @param type The Object type.
32+
*/
33+
public void setType(final String type) {
34+
this.type = type;
35+
}
36+
37+
/**
38+
* @return Custom mapping value.
39+
*/
40+
public String getCustomMapping() {
41+
return customMapping;
42+
}
43+
44+
/**
45+
* @param mapping Custom mapping value.
46+
*/
47+
public void setCustomMapping(final String customMapping) {
48+
this.customMapping = customMapping;
49+
}
50+
}

utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/UtPLSQLMojo.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package org.utplsql.maven.plugin;
22

3-
import static java.lang.String.format;
4-
53
import java.sql.Connection;
64
import java.sql.DriverManager;
75
import java.sql.SQLException;
@@ -18,6 +16,7 @@
1816
import org.apache.maven.plugins.annotations.Parameter;
1917
import org.utplsql.api.DBHelper;
2018
import org.utplsql.api.FileMapperOptions;
19+
import org.utplsql.api.KeyValuePair;
2120
import org.utplsql.api.TestRunner;
2221
import org.utplsql.api.Version;
2322
import org.utplsql.api.exception.SomeTestsFailedException;
@@ -76,7 +75,9 @@ public class UtPLSQLMojo extends AbstractMojo
7675

7776
@Parameter
7877
private Integer sourcesTypeSubexpression;
79-
78+
79+
@Parameter
80+
private List<CustomTypeMapping> sourcesCustomTypeMapping;
8081

8182
// Tests Configuration
8283

@@ -95,6 +96,9 @@ public class UtPLSQLMojo extends AbstractMojo
9596
@Parameter
9697
private Integer testsTypeSubexpression;
9798

99+
@Parameter
100+
private List<CustomTypeMapping> testsCustomTypeMapping;
101+
98102

99103
@Parameter(defaultValue = "${project.build.directory}", readonly = true)
100104
protected String targetDir;
@@ -238,6 +242,13 @@ private FileMapperOptions buildSourcesOptions() throws MojoExecutionException
238242
fileMapperOptions.setTypeSubExpression(sourcesTypeSubexpression);
239243
}
240244

245+
if (sourcesCustomTypeMapping != null && sourcesCustomTypeMapping.size() > 0) {
246+
fileMapperOptions.setTypeMappings(new ArrayList<KeyValuePair>());
247+
for (CustomTypeMapping typeMapping : sourcesCustomTypeMapping) {
248+
fileMapperOptions.getTypeMappings().add(new KeyValuePair(typeMapping.getCustomMapping(),typeMapping.getType()));
249+
}
250+
}
251+
241252
return fileMapperOptions;
242253

243254
}
@@ -288,6 +299,13 @@ private FileMapperOptions buildTestsOptions() throws MojoExecutionException
288299
fileMapperOptions.setTypeSubExpression(testsTypeSubexpression);
289300
}
290301

302+
if (testsCustomTypeMapping != null && testsCustomTypeMapping.size() > 0) {
303+
fileMapperOptions.setTypeMappings(new ArrayList<KeyValuePair>());
304+
for (CustomTypeMapping typeMapping : testsCustomTypeMapping) {
305+
fileMapperOptions.getTypeMappings().add(new KeyValuePair(typeMapping.getCustomMapping(),typeMapping.getType()));
306+
}
307+
}
308+
291309
return fileMapperOptions;
292310

293311
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,26 @@ public void testRegexDefinition() throws Exception
6161
Assert.fail("Unexpected Exception running the test of Definition");
6262
}
6363
}
64+
65+
@Test
66+
public void testTypeMappingDefinition() throws Exception
67+
{
68+
try
69+
{
70+
final String PROJECT_NAME = "type-mapping-project";
71+
UtPLSQLMojo myMojo = (UtPLSQLMojo) rule.lookupConfiguredMojo(new File(TARGET_DIRECTORY+"/"+PROJECT_NAME), "test");
72+
73+
Assert.assertNotNull(myMojo);
74+
myMojo.execute();
75+
76+
checkReportsGenerated(PROJECT_NAME,"utplsql/coverage-sonar-reporter.xml", "utplsql/sonar-test-reporter.xml");
77+
}
78+
catch (Exception e)
79+
{
80+
e.printStackTrace();
81+
Assert.fail("Unexpected Exception running the test of Definition");
82+
}
83+
}
6484

6585
/**
6686
*
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/type-mapping-project/scripts/sources/app/package_bodies/PKG_TEST_ME.sql">
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/type-mapping-project/scripts/test/app/package_bodies/TEST_PKG_TEST_ME.sql">
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: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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/type-mapping-project/scripts/sources</directory>
56+
<includes>
57+
<include>**/*sql</include>
58+
</includes>
59+
</source>
60+
</sources>
61+
<sourcesRegexExpression>.*(\\|\/)(\w+)(\\|\/)(\w+)(\\|\/)(\w+).(\w{3})</sourcesRegexExpression>
62+
<sourcesOwnerSubexpression>2</sourcesOwnerSubexpression>
63+
<sourcesNameSubexpression>6</sourcesNameSubexpression>
64+
<sourcesTypeSubexpression>4</sourcesTypeSubexpression>
65+
<sourcesCustomTypeMapping>
66+
<customTypeMapping>
67+
<type>package body</type>
68+
<customMapping>package_bodies</customMapping>
69+
</customTypeMapping>
70+
</sourcesCustomTypeMapping>
71+
72+
<tests>
73+
<test>
74+
<directory>src/test/resources/type-mapping-project/scripts/test</directory>
75+
<includes>
76+
<include>**/*sql</include>
77+
</includes>
78+
</test>
79+
</tests>
80+
<testsRegexExpression>.*(\\|\/)(\w+)(\\|\/)(\w+)(\\|\/)(\w+).(\w{3})</testsRegexExpression>
81+
<testsOwnerSubexpression>2</testsOwnerSubexpression>
82+
<testsNameSubexpression>6</testsNameSubexpression>
83+
<testsTypeSubexpression>4</testsTypeSubexpression>
84+
<testsCustomTypeMapping>
85+
<customTypeMapping>
86+
<type>package body</type>
87+
<customMapping>package_bodies</customMapping>
88+
</customTypeMapping>
89+
</testsCustomTypeMapping>
90+
</configuration>
91+
</plugin>
92+
</plugins>
93+
</build>
94+
</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+
/
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
--
2+
-- This is a table used to demonstrate the UNIT test framework.
3+
--
4+
CREATE TABLE TO_TEST_ME
5+
(
6+
SNAME VARCHAR2(10)
7+
)
8+
/

0 commit comments

Comments
 (0)