Skip to content
10 changes: 5 additions & 5 deletions .travis/install_demo_project.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
set -ev

PROJECT_FILES_SRC="utplsql-maven-plugin/src/test/resources"
PROJECT_FILES_SRC="utplsql-maven-plugin/src/test/resources/simple-project"
PROJECT_FILES="resources"

cat > demo_project.sh.tmp <<EOF
Expand All @@ -18,11 +18,11 @@ whenever sqlerror exit failure rollback
whenever oserror exit failure rollback

@scripts/sources/TO_TEST_ME.tab
@scripts/sources/PKG_TEST_ME.spc
@scripts/sources/PKG_TEST_ME.bdy
@scripts/sources/APP.PKG_TEST_ME.spc
@scripts/sources/APP.PKG_TEST_ME.bdy

@scripts/test/TEST_PKG_TEST_ME.spc
@scripts/test/TEST_PKG_TEST_ME.bdy
@scripts/tests/APP.TEST_PKG_TEST_ME.spc
@scripts/tests/APP.TEST_PKG_TEST_ME.bdy

exit
SQL
Expand Down
47 changes: 23 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,50 +31,45 @@ 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`

* `targetDir`
* Target dir, this is a readonly property
* Default: `${project.build.directory}`
* `includeObject`
* Include Object
* `excludeObject`
* Exclude Objects
* Object Type is identified by the expression with the specified set of brackets



### 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>
<version>3.1.0</version>
<failOnErrors>false</failOnErrors>
<reporters>
<reporter>
Expand Down Expand Up @@ -109,6 +104,10 @@ 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 parameters (sourcesRegexExpression, testsRegexExpression, ...) 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,13 @@
package org.utpsql.maven.plugin.test;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.commons.io.FileUtils;
import org.apache.maven.plugin.testing.MojoRule;
import org.junit.Assert;
import org.junit.Rule;
Expand All @@ -10,9 +16,7 @@

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();
Expand All @@ -23,31 +27,71 @@ public void testDefinition() 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");
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");
}
}

@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();

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

/**
*
* @param files
*/
private void checkCoverReportsGenerated(String... files)
private void checkReportsGenerated(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 as it is always different.
// Path separator is set to "/" to ensure windows / linux / mac compatibility
Stream<String> stream = Files.lines(Paths.get(TARGET_DIRECTORY,projectName,"target",filename));
String outputContent = stream.map(line -> line.replaceAll("(duration=\"[0-9\\.]*\")", "duration=\"1\""))
.map(line -> line.replaceAll("\\\\", "/"))
.map(line -> line.replaceAll("\r", "").replaceAll("\n", ""))
.collect(Collectors.joining("\n"));

stream.close();
Assert.assertEquals("The files differ!",
outputContent,
FileUtils.readFileToString(expectedOutputFile, "utf-8").replace("\r",""));
} 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:@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>
<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