Skip to content
Prev Previous commit
Next Next commit
Add new test for regex params (#12)
  • Loading branch information
jgarec committed May 23, 2018
commit 0b2284d823191ce51d033e2cc847b4ae11e8098f
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,26 @@ public void testDefinition() throws Exception
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");
}
}

/**
*
Expand Down
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)
)
/
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
CREATE OR REPLACE PACKAGE BODY app.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 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