Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ You have to be a fully utPLSQL environment available compatible with the Java AP
* `sourcesNameSubexpression`
* Object name is identified by the expression with the specified set of brackets
* `sourcesTypeSubexpression`
* Object Type is identified by the expression with the specified set of brackets
* Object Type is identified by the expression with the specified set of brackets
* `sourcesCustomTypeMapping`
* List of Custom Type Mappings

* `tests`
* Path to project test files
Expand All @@ -53,7 +55,8 @@ You have to be a fully utPLSQL environment available compatible with the Java AP
* Object name is identified by the expression with the specified set of brackets
* `testsTypeSubexpression`
* Object Type is identified by the expression with the specified set of brackets

* `testsCustomTypeMapping`
* List of Custom Type Mappings


### Sample of use
Expand Down Expand Up @@ -111,3 +114,4 @@ The next snippet is a sample of declaration of the pom
More project samples are available in the src/test/resources directory :
* simple-project : minimalist test project with standard project directory structure
* 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.
* type-mapping-project : This project shows how to use regex and custom type parameters togethers.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.utplsql.maven.plugin;

/**
* Bean used by maven to populate its model.
*
* <customTypeMapping>
* <type>...</type>
* <mapping>...</mapping>
* </customTypeMapping>
*
*/
public class CustomTypeMapping {
/**
* Object type.
*/
private String type;

/**
* Custom mapping value.
*/
private String customMapping;

/**
* @return The Object type.
*/
public String getType() {
return type;
}

/**
* @param type The Object type.
*/
public void setType(final String type) {
this.type = type;
}

/**
* @return Custom mapping value.
*/
public String getCustomMapping() {
return customMapping;
}

/**
* @param mapping Custom mapping value.
*/
public void setCustomMapping(final String customMapping) {
this.customMapping = customMapping;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.utplsql.maven.plugin;

import static java.lang.String.format;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
Expand All @@ -18,6 +16,7 @@
import org.apache.maven.plugins.annotations.Parameter;
import org.utplsql.api.DBHelper;
import org.utplsql.api.FileMapperOptions;
import org.utplsql.api.KeyValuePair;
import org.utplsql.api.TestRunner;
import org.utplsql.api.Version;
import org.utplsql.api.exception.SomeTestsFailedException;
Expand Down Expand Up @@ -76,7 +75,9 @@ public class UtPLSQLMojo extends AbstractMojo

@Parameter
private Integer sourcesTypeSubexpression;


@Parameter
private List<CustomTypeMapping> sourcesCustomTypeMapping;

// Tests Configuration

Expand All @@ -95,6 +96,9 @@ public class UtPLSQLMojo extends AbstractMojo
@Parameter
private Integer testsTypeSubexpression;

@Parameter
private List<CustomTypeMapping> testsCustomTypeMapping;


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

if (sourcesCustomTypeMapping != null && sourcesCustomTypeMapping.size() > 0) {
fileMapperOptions.setTypeMappings(new ArrayList<KeyValuePair>());
for (CustomTypeMapping typeMapping : sourcesCustomTypeMapping) {
fileMapperOptions.getTypeMappings().add(new KeyValuePair(typeMapping.getCustomMapping(),typeMapping.getType()));
}
}

return fileMapperOptions;

}
Expand Down Expand Up @@ -288,6 +299,13 @@ private FileMapperOptions buildTestsOptions() throws MojoExecutionException
fileMapperOptions.setTypeSubExpression(testsTypeSubexpression);
}

if (testsCustomTypeMapping != null && testsCustomTypeMapping.size() > 0) {
fileMapperOptions.setTypeMappings(new ArrayList<KeyValuePair>());
for (CustomTypeMapping typeMapping : testsCustomTypeMapping) {
fileMapperOptions.getTypeMappings().add(new KeyValuePair(typeMapping.getCustomMapping(),typeMapping.getType()));
}
}

return fileMapperOptions;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,26 @@ public void testRegexDefinition() throws Exception
Assert.fail("Unexpected Exception running the test of Definition");
}
}

@Test
public void testTypeMappingDefinition() throws Exception
{
try
{
final String PROJECT_NAME = "type-mapping-project";
UtPLSQLMojo myMojo = (UtPLSQLMojo) rule.lookupConfiguredMojo(new File(TARGET_DIRECTORY+"/"+PROJECT_NAME), "test");

Assert.assertNotNull(myMojo);
myMojo.execute();

checkReportsGenerated(PROJECT_NAME,"utplsql/coverage-sonar-reporter.xml", "utplsql/sonar-test-reporter.xml");
}
catch (Exception e)
{
e.printStackTrace();
Assert.fail("Unexpected Exception running the test of Definition");
}
}

/**
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<coverage version="1">
<file path="src/test/resources/type-mapping-project/scripts/sources/app/package_bodies/PKG_TEST_ME.sql">
<lineToCover lineNumber="8" covered="true"/>
<lineToCover lineNumber="9" covered="true"/>
<lineToCover lineNumber="10" covered="true"/>
<lineToCover lineNumber="11" covered="true"/>
<lineToCover lineNumber="13" covered="true"/>
<lineToCover lineNumber="19" covered="true"/>
<lineToCover lineNumber="22" covered="true"/>
<lineToCover lineNumber="23" covered="true"/>
</file>
</coverage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<testExecutions version="1">
<file path="src/test/resources/type-mapping-project/scripts/test/app/package_bodies/TEST_PKG_TEST_ME.sql">
<testCase name="test_fc_input_1" duration="1" >
</testCase>
<testCase name="test_fc_input_0" duration="1" >
</testCase>
<testCase name="test_fc_input_null" duration="1" >
</testCase>
<testCase name="test_pr_test_me_null" duration="1" >
</testCase>
<testCase name="test_pr_test_me_not_null" duration="1" >
</testCase>
<testCase name="test_pr_test_me_exists" duration="1" >
</testCase>
<testCase name="test_pr_test_me_cursor" duration="1" >
</testCase>
</file>
</testExecutions>
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.utplsql</groupId>
<artifactId>utplsql-maven-plugin-test</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>maven-plugin</packaging>

<name>utplsql-maven-plugin Maven Plugin Test</name>


<properties>
<dbUrl>jdbc:oracle:thin:@127.0.0.1:1521:xe</dbUrl>
<!--
<dbUser>ut3</dbUser>
<dbPass>XNtxj8eEgA6X6b6f</dbPass>
-->
</properties>

<build>

<plugins>
<plugin>
<groupId>${pom.groupId}</groupId>
<artifactId>utplsql-maven-plugin</artifactId>
<version>${pom.version}</version>
<goals>
<goal>test</goal>
</goals>
<configuration>
<!-- Mandatory Attributes -->

<ignoreFailure>false</ignoreFailure>

<paths>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we change from paths to suitepaths? paths seem too ambiguous and not self-descriptive enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Followed in #17

<path>app</path>
</paths>

<reporters>
<reporter>
<name>UT_COVERAGE_SONAR_REPORTER</name>
<fileOutput>utplsql/coverage-sonar-reporter.xml</fileOutput>
<consoleOutput>true</consoleOutput>
</reporter>
<reporter>
<name>UT_SONAR_TEST_REPORTER</name>
<fileOutput>utplsql/sonar-test-reporter.xml</fileOutput>
<consoleOutput>true</consoleOutput>
</reporter>
</reporters>

<sources>
<source>
<directory>src/test/resources/type-mapping-project/scripts/sources</directory>
<includes>
<include>**/*sql</include>
</includes>
</source>
</sources>
<sourcesRegexExpression>.*(\\|\/)(\w+)(\\|\/)(\w+)(\\|\/)(\w+).(\w{3})</sourcesRegexExpression>
<sourcesOwnerSubexpression>2</sourcesOwnerSubexpression>
<sourcesNameSubexpression>6</sourcesNameSubexpression>
<sourcesTypeSubexpression>4</sourcesTypeSubexpression>
<sourcesCustomTypeMapping>
<customTypeMapping>
<type>package body</type>
<customMapping>package_bodies</customMapping>
</customTypeMapping>
</sourcesCustomTypeMapping>

<tests>
<test>
<directory>src/test/resources/type-mapping-project/scripts/test</directory>
<includes>
<include>**/*sql</include>
</includes>
</test>
</tests>
<testsRegexExpression>.*(\\|\/)(\w+)(\\|\/)(\w+)(\\|\/)(\w+).(\w{3})</testsRegexExpression>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wirh utPLSQL v3.1 the regex can be of a simplified form. See doc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you point the documentation about this ? :)
I need to use the "owner" parameter ?

<testsOwnerSubexpression>2</testsOwnerSubexpression>
<testsNameSubexpression>6</testsNameSubexpression>
<testsTypeSubexpression>4</testsTypeSubexpression>
<testsCustomTypeMapping>
<customTypeMapping>
<type>package body</type>
<customMapping>package_bodies</customMapping>
</customTypeMapping>
</testsCustomTypeMapping>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
CREATE OR REPLACE PACKAGE BODY APP.PKG_TEST_ME IS

--
-- This
--
FUNCTION FC_TEST_ME(PPARAM1 IN VARCHAR2) RETURN NUMBER IS
BEGIN
IF PPARAM1 IS NULL THEN
RETURN NULL;
ELSIF PPARAM1 = '1' THEN
RETURN 1;
ELSE
RETURN 0;
END IF;
END FC_TEST_ME;

PROCEDURE PR_TEST_ME(PSNAME IN VARCHAR2) IS
BEGIN
IF PSNAME IS NULL THEN
NULL;
ELSE
INSERT INTO TO_TEST_ME (SNAME) VALUES (PSNAME);
COMMIT;
END IF;
END PR_TEST_ME;

END PKG_TEST_ME;
/
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
--
-- This package is used TO demonstrate the utPL/SQL possibilities
--
CREATE OR REPLACE PACKAGE app.PKG_TEST_ME AS
FUNCTION FC_TEST_ME(PPARAM1 IN VARCHAR2) RETURN NUMBER;
PROCEDURE PR_TEST_ME(PSNAME IN VARCHAR2);
END PKG_TEST_ME;
/
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
--
-- This is a table used to demonstrate the UNIT test framework.
--
CREATE TABLE TO_TEST_ME
(
SNAME VARCHAR2(10)
)
/
Loading