Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
41 changes: 25 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,29 @@ You have to be a fully utPLSQL environment available compatible with the Java AP

* `paths`
* Paths of the resources
* `sources`
* Path to project source files

* `sourcesRegexExpression`
*
* utPLSQL will convert file paths into database objects using the following regular expression
* `sourcesOwnerSubexpression`
*
* Object owner is identified by the expression with the specified set of brackets
* `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

* `tests`
* Test fo the scripts at the style of the maven resources
* Path to project test files
* `testsRegexExpression`
*
* utPLSQL will convert file paths into database objects using the following regular expression
* `testsOwnerSubexpression`
*
* Owner is identified by the expression with the specified set of brackets
* `testsNameSubexpression`
*
* 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

* `targetDir`
* Target dir, this is a readonly property
* Default: `${project.build.directory}`
Expand All @@ -63,14 +67,14 @@ You have to be a fully utPLSQL environment available compatible with the Java AP
### Sample of use
The next snippet is a sample of declaration of the pom
```xml
<plugin>
<plugin>
<groupId>org.utplsql</groupId>
<artifactId>utplsql-maven-plugin</artifactId>
<version>1.0.0-SNAPSHOT</version>
<goals>
<goal>test</goal>
</goals>
<configuration>
<goals>
<goal>test</goal>
</goals>
<configuration>
<dbUrl>url_of_connection</dbUrl>
<dbUser>user</dbUser>
<dbPass>password</dbPass>
Expand Down Expand Up @@ -109,6 +113,11 @@ The next snippet is a sample of declaration of the pom
</includes>
</test>
</tests>
</configuration>
</plugin>
</configuration>
</plugin>
```

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 configuration (sourcesRegexExpression, testsRegexExpression, ...) parameters to tell utPLSQL how the project files are to be mapped into database objects.

3 changes: 1 addition & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

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

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

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
3 changes: 1 addition & 2 deletions utplsql-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

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

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

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.utpsql.maven.plugin.test;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.apache.maven.plugin.testing.MojoRule;
import org.junit.Assert;
import org.junit.Rule;
Expand All @@ -10,44 +12,75 @@

public class UtPLSQLMojoTest
{
public static final String POM_PATH = "src/test/resources/";

public static final String OUTPUT_DIRECTORY = "target/test-classes";
public static final String TARGET_DIRECTORY = "target/test-classes";

@Rule
public MojoRule rule = new MojoRule();

@Test
public void testDefinition() throws Exception
public void testSimpleDefinition() throws Exception
{

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

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

checkCoverReportsGenerated("utplsql/coverage-sonar-reporter.xml", "utplsql/sonar-test-reporter.xml");
checkCoverReportsGenerated(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");
}
}

@Test
public void testRegexDefinition() throws Exception
{

try
{
final String PROJECT_NAME = "regex-project";
UtPLSQLMojo myMojo = (UtPLSQLMojo) rule.lookupConfiguredMojo(new File(TARGET_DIRECTORY+"/"+PROJECT_NAME), "test");

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

checkCoverReportsGenerated(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");
}
}

/**
*
* @param files
*/
private void checkCoverReportsGenerated(String... files)
private void checkCoverReportsGenerated(String projectName, String... files)
{
for (String filename : files)
{
File file = new File(OUTPUT_DIRECTORY, filename);
Assert.assertTrue("The reporter for " + filename + " was not generated", file.exists());
File outputFile = new File(TARGET_DIRECTORY+"/"+projectName+"/target/", filename);
File expectedOutputFile = new File(TARGET_DIRECTORY+"/"+projectName+"/expected-output/", filename);

Assert.assertTrue("The reporter for " + filename + " was not generated", outputFile.exists());
try {
// Duration is set to 1 before comparing contents.
Assert.assertEquals("The files differ!",
FileUtils.readFileToString(outputFile, "utf-8").replaceAll("(duration=\"[0-9\\.]*\")", "duration=\"1\""),
FileUtils.readFileToString(expectedOutputFile, "utf-8"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Assert.fail("Unexpected Exception running the test of Definition");
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<coverage version="1">
<file path="src\test\resources\regex-project\scripts\sources\app\packages\PKG_TEST_ME.bdy">
<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\regex-project\scripts\test\app\packages\TEST_PKG_TEST_ME.bdy">
<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>
85 changes: 85 additions & 0 deletions utplsql-maven-plugin/src/test/resources/regex-project/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<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:@s00vl9977879:1521/D11236CP10</dbUrl>

<dbUser>USR_11236_POC_BDD_UTP</dbUser>
<dbPass>USR_11236_POC_utp_123</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>
<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/regex-project/scripts/sources</directory>
<includes>
<include>**/*bdy</include>
<include>**/*spc</include>
</includes>
</source>
</sources>
<sourcesRegexExpression>.*(\\|\/)(\w+)(\\|\/)(\w+)(\\|\/)(\w+).(\w{3})</sourcesRegexExpression>
<sourcesOwnerSubexpression>2</sourcesOwnerSubexpression>
<sourcesNameSubexpression>6</sourcesNameSubexpression>
<sourcesTypeSubexpression>7</sourcesTypeSubexpression>

<tests>
<test>
<directory>src/test/resources/regex-project/scripts/test</directory>
<includes>
<include>**/*bdy</include>
<include>**/*spc</include>
</includes>
</test>
</tests>
<testsRegexExpression>.*(\\|\/)(\w+)(\\|\/)(\w+)(\\|\/)(\w+).(\w{3})</testsRegexExpression>
<testsOwnerSubexpression>2</testsOwnerSubexpression>
<testsNameSubexpression>6</testsNameSubexpression>
<testsTypeSubexpression>7</testsTypeSubexpression>

</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