Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
  • Loading branch information
simasch committed Dec 3, 2021
2 parents adbb375 + c2f33ad commit 87b6710
Show file tree
Hide file tree
Showing 17 changed files with 365 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

services:
oracle:
image: gvenzl/oracle-xe:18.4.0-slim
image: gvenzl/oracle-xe:21-slim
env:
ORACLE_PASSWORD: oracle
ports:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:

services:
oracle:
image: gvenzl/oracle-xe:18.4.0-slim
image: gvenzl/oracle-xe:21-slim
env:
ORACLE_PASSWORD: oracle
ports:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ Please refer to the following usage example for the parameters descriptions:
<!-- REQUIRED PARAMETERS -->

<!-- A list of tests suite paths. -->

<!-- The path(s) can be in one of the following formats: -->
<!-- schema[.package[.procedure]] -->
<!-- schema:suite[.suite[.suite][...]][.procedure] -->
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.utplsql</groupId>
<artifactId>utplsql-maven-plugin</artifactId>
<version>3.1.6</version>
<version>3.1.7</version>
<packaging>maven-plugin</packaging>

<name>utPLSQL Maven Plugin</name>
Expand Down
2 changes: 1 addition & 1 deletion scripts/0_start_db.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
docker run -d --name ora-utplsql -p 1521:1521 -e ORACLE_PASSWORD=oracle gvenzl/oracle-xe:18.4.0-slim
docker run -d --name ora-utplsql -p 1521:1521 -e ORACLE_PASSWORD=oracle gvenzl/oracle-xe:21-slim
16 changes: 14 additions & 2 deletions src/main/java/org/utplsql/maven/plugin/UtPlsqlMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
Expand Down Expand Up @@ -162,10 +163,21 @@ public void execute() throws MojoExecutionException {
.failOnErrors(!ignoreFailure);

if (isNotBlank(excludeObject)) {
runner.excludeObject(excludeObject);
if (excludeObject.contains(",")) {
String[] excludes = excludeObject.split(",");
runner.excludeObjects(Arrays.asList(excludes));
} else {
runner.excludeObject(excludeObject);
}

}
if (isNotBlank(includeObject)) {
runner.includeObject(includeObject);
if (includeObject.contains(",")) {
String[] includes = includeObject.split(",");
runner.excludeObjects(Arrays.asList(includes));
} else {
runner.excludeObject(includeObject);
}
}

runner.run(connection);
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/org/utplsql/maven/plugin/UtPlsqlMojoIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,11 @@ void type_mapping(MavenExecutionResult result) {

assertThatReportsAreGeneratedAsExpected(result, "sonar-test-report.xml", "coverage-sonar-report.xml");
}

@MavenTest
void exclude_object(MavenExecutionResult result) {
assertThat(result).isSuccessful();

assertThatReportsAreGeneratedAsExpected(result, "sonar-test-report.xml", "coverage-sonar-report.xml");
}
}
7 changes: 3 additions & 4 deletions src/test/java/org/utplsql/maven/plugin/UtPlsqlMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,14 +313,13 @@ public void db_config_using_system_properties() throws Exception {
* Then : System Properties must be used to configure database
*/
@Test
public void include_and_exclude_objects() throws Exception {
UtPlsqlMojo utPlsqlMojo = createUtPlsqlMojo("include_and_exclude_objects");
public void exclude_object() throws Exception {
UtPlsqlMojo utPlsqlMojo = createUtPlsqlMojo("exclude_object");
assertNotNull(utPlsqlMojo);

utPlsqlMojo.execute();

assertEquals("abc", utPlsqlMojo.includeObject);
assertEquals("xyz", utPlsqlMojo.excludeObject);
assertEquals("app.pkg_test_me,app.test_pkg_test_me", utPlsqlMojo.excludeObject);
}

private UtPlsqlMojo createUtPlsqlMojo(String directory) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<coverage version="1">
</coverage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<testExecutions version="1">
<file path="plsql.examples.test_pkg_test_me">
<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,52 @@
<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>owner-param</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>

<properties>
<dbUrl>jdbc:oracle:thin:@localhost:1521:xe</dbUrl>
<dbUser>UT3</dbUser>
<dbPass>UT3</dbPass>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.utplsql</groupId>
<artifactId>utplsql-maven-plugin</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<goals>
<goal>test</goal>
</goals>
<configuration>
<ignoreFailure>false</ignoreFailure>
<paths>
<path>TESTS_OWNER</path>
</paths>
<reporters>
<reporter>
<name>UT_COVERAGE_SONAR_REPORTER</name>
<fileOutput>utplsql/coverage-sonar-report.xml</fileOutput>
<consoleOutput>true</consoleOutput>
</reporter>
<reporter>
<name>UT_SONAR_TEST_REPORTER</name>
<fileOutput>utplsql/sonar-test-report.xml</fileOutput>
<consoleOutput>true</consoleOutput>
</reporter>
</reporters>
<excludeObject>tests_owner.test_pkg_test_me</excludeObject>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
CREATE OR REPLACE PACKAGE BODY CODE_OWNER.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 CODE_OWNER.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)
)
/
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
CREATE OR REPLACE PACKAGE BODY TESTS_OWNER.TEST_PKG_TEST_ME AS

---------------------------------------------------------------------------
PROCEDURE SETUP_GLOBAL IS
BEGIN
-- Put here the code which is valid for all tests and that should be
-- executed once.
NULL;
END SETUP_GLOBAL;

---------------------------------------------------------------------------
PROCEDURE TEARDOWN_GLOBAL IS
BEGIN
-- Put here the code that should be called only once after all the test
-- have executed
NULL;
END TEARDOWN_GLOBAL;

---------------------------------------------------------------------------
PROCEDURE SETUP_TEST IS
BEGIN
-- Nothing to clean up globally
NULL;
END SETUP_TEST;

PROCEDURE TEARDOWN_TEST IS
BEGIN
-- Nothing to clean up globally
NULL;
END TEARDOWN_TEST;

PROCEDURE TEST_FC_INPUT_1 IS
BEGIN
-- Ok this is a real test where I check that the function return 1
-- when called with a '1' parameter
UT.EXPECT(PKG_TEST_ME.FC_TEST_ME('1')).TO_EQUAL(1);
END;

PROCEDURE SETUP_TEST_FC_INPUT_1 IS
BEGIN
-- Nothing to be done really
NULL;
END;

PROCEDURE TEARDOWN_TEST_FC_INPUT_1 IS
BEGIN
-- Nothing to be done really
NULL;
END;

PROCEDURE TEST_FC_INPUT_0 IS
BEGIN
-- Ok this is a real test where I check that the function return 0
-- when called with a '0' parameter
UT.EXPECT(PKG_TEST_ME.FC_TEST_ME('0')).TO_EQUAL(0);
END;

PROCEDURE TEST_FC_INPUT_NULL IS
BEGIN
-- Ok I check that the function return NULL
-- when called with a NULL parameter
UT.EXPECT(PKG_TEST_ME.FC_TEST_ME(NULL)).TO_BE_NULL;
END TEST_FC_INPUT_NULL;

PROCEDURE TEST_PR_TEST_ME_NULL IS
VNCOUNT1 PLS_INTEGER;
VNCOUNT2 PLS_INTEGER;
BEGIN
-- In this example I check that the procedure does
-- not insert anything when passing it a NULL parameter
SELECT COUNT(1) INTO VNCOUNT1 FROM TO_TEST_ME;
PKG_TEST_ME.PR_TEST_ME(NULL);
SELECT COUNT(1) INTO VNCOUNT2 FROM TO_TEST_ME;
UT.EXPECT(VNCOUNT1).TO_EQUAL(VNCOUNT2);
END;

PROCEDURE TEST_PR_TEST_ME_NOT_NULL IS
VNCOUNT1 PLS_INTEGER;
VNCOUNT2 PLS_INTEGER;
VSNAME TO_TEST_ME.SNAME%TYPE;
BEGIN
-- In this test I will check that I do insert a value
-- when the parameter is not null. I futher check that
-- the procedure has inserted the value I specified.
SELECT COUNT(1) INTO VNCOUNT1 FROM TO_TEST_ME;
VSNAME := TO_CHAR(VNCOUNT1);
PKG_TEST_ME.PR_TEST_ME(VSNAME);
SELECT COUNT(1) INTO VNCOUNT2 FROM TO_TEST_ME;

-- Check that I have inserted the value
UT.EXPECT(VNCOUNT1 + 1).TO_EQUAL(VNCOUNT2);
SELECT COUNT(1) INTO VNCOUNT2 FROM TO_TEST_ME T WHERE T.SNAME = VSNAME;

-- Check that I inserted the one I said I would insert
UT.EXPECT(VNCOUNT2).TO_EQUAL(1);
DELETE FROM TO_TEST_ME T WHERE T.SNAME = VSNAME;
COMMIT;
END;

PROCEDURE TEST_PR_TEST_ME_EXISTS IS
BEGIN
-- In case the value exists the procedure should fail with an exception.
BEGIN
PKG_TEST_ME.PR_TEST_ME('EXISTS');
PKG_TEST_ME.PR_TEST_ME('EXISTS');
EXCEPTION
WHEN OTHERS THEN
UT.FAIL('Unexpected exception raised');
END;
END;

PROCEDURE TEST_PR_TEST_ME_CURSOR IS
TYPE REF_CURSOR IS REF CURSOR;
VEXPECTED REF_CURSOR;
VACTUAL REF_CURSOR;
BEGIN
EXECUTE IMMEDIATE 'TRUNCATE TABLE CODE_OWNER.TO_TEST_ME';
OPEN VEXPECTED FOR
SELECT T.SNAME FROM TO_TEST_ME T;
OPEN VACTUAL FOR
SELECT T.SNAME FROM TO_TEST_ME T;
UT.EXPECT(VEXPECTED).TO_(EQUAL(VACTUAL));
END;

END;
/
Loading

0 comments on commit 87b6710

Please sign in to comment.