Skip to content

Commit 0b2284d

Browse files
committed
Add new test for regex params (#12)
1 parent 2d58506 commit 0b2284d

File tree

9 files changed

+391
-0
lines changed

9 files changed

+391
-0
lines changed

utplsql-maven-plugin/src/test/java/org/utpsql/maven/plugin/test/UtPLSQLMojoTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,26 @@ public void testDefinition() throws Exception
3737
Assert.fail("Unexpected Exception running the test of Definition");
3838
}
3939
}
40+
41+
@Test
42+
public void testRegexDefinition() throws Exception
43+
{
44+
try
45+
{
46+
final String PROJECT_NAME = "regex-project";
47+
UtPLSQLMojo myMojo = (UtPLSQLMojo) rule.lookupConfiguredMojo(new File(TARGET_DIRECTORY+"/"+PROJECT_NAME), "test");
48+
49+
Assert.assertNotNull(myMojo);
50+
myMojo.execute();
51+
52+
checkCoverReportsGenerated(PROJECT_NAME,"utplsql/coverage-sonar-reporter.xml", "utplsql/sonar-test-reporter.xml");
53+
}
54+
catch (Exception e)
55+
{
56+
e.printStackTrace();
57+
Assert.fail("Unexpected Exception running the test of Definition");
58+
}
59+
}
4060

4161
/**
4262
*
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<coverage version="1">
2+
<file path="src\test\resources\regex-project\scripts\sources\app\packages\PKG_TEST_ME.bdy">
3+
<lineToCover lineNumber="8" covered="true"/>
4+
<lineToCover lineNumber="9" covered="true"/>
5+
<lineToCover lineNumber="10" covered="true"/>
6+
<lineToCover lineNumber="11" covered="true"/>
7+
<lineToCover lineNumber="13" covered="true"/>
8+
<lineToCover lineNumber="19" covered="true"/>
9+
<lineToCover lineNumber="22" covered="true"/>
10+
<lineToCover lineNumber="23" covered="true"/>
11+
</file>
12+
</coverage>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<testExecutions version="1">
2+
<file path="src\test\resources\regex-project\scripts\test\app\packages\TEST_PKG_TEST_ME.bdy">
3+
<testCase name="test_fc_input_1" duration="1" >
4+
</testCase>
5+
<testCase name="test_fc_input_0" duration="1" >
6+
</testCase>
7+
<testCase name="test_fc_input_null" duration="1" >
8+
</testCase>
9+
<testCase name="test_pr_test_me_null" duration="1" >
10+
</testCase>
11+
<testCase name="test_pr_test_me_not_null" duration="1" >
12+
</testCase>
13+
<testCase name="test_pr_test_me_exists" duration="1" >
14+
</testCase>
15+
<testCase name="test_pr_test_me_cursor" duration="1" >
16+
</testCase>
17+
</file>
18+
</testExecutions>
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>org.utplsql</groupId>
6+
<artifactId>utplsql-maven-plugin-test</artifactId>
7+
<version>1.0.0-SNAPSHOT</version>
8+
<packaging>maven-plugin</packaging>
9+
10+
<name>utplsql-maven-plugin Maven Plugin Test</name>
11+
12+
13+
<properties>
14+
<dbUrl>jdbc:oracle:thin:@127.0.0.1:1521:xe</dbUrl>
15+
<!--
16+
<dbUser>ut3</dbUser>
17+
<dbPass>XNtxj8eEgA6X6b6f</dbPass>
18+
-->
19+
</properties>
20+
21+
<build>
22+
23+
<plugins>
24+
<plugin>
25+
<groupId>${pom.groupId}</groupId>
26+
<artifactId>utplsql-maven-plugin</artifactId>
27+
<version>${pom.version}</version>
28+
<goals>
29+
<goal>test</goal>
30+
</goals>
31+
<configuration>
32+
<!-- Mandatory Attributes -->
33+
34+
<ignoreFailure>false</ignoreFailure>
35+
36+
<paths>
37+
<path>app</path>
38+
</paths>
39+
40+
<reporters>
41+
<reporter>
42+
<name>UT_COVERAGE_SONAR_REPORTER</name>
43+
<fileOutput>utplsql/coverage-sonar-reporter.xml</fileOutput>
44+
<consoleOutput>true</consoleOutput>
45+
</reporter>
46+
<reporter>
47+
<name>UT_SONAR_TEST_REPORTER</name>
48+
<fileOutput>utplsql/sonar-test-reporter.xml</fileOutput>
49+
<consoleOutput>true</consoleOutput>
50+
</reporter>
51+
</reporters>
52+
53+
<sources>
54+
<source>
55+
<directory>src/test/resources/regex-project/scripts/sources</directory>
56+
<includes>
57+
<include>**/*bdy</include>
58+
<include>**/*spc</include>
59+
</includes>
60+
</source>
61+
</sources>
62+
<sourcesRegexExpression>.*(\\|\/)(\w+)(\\|\/)(\w+)(\\|\/)(\w+).(\w{3})</sourcesRegexExpression>
63+
<sourcesOwnerSubexpression>2</sourcesOwnerSubexpression>
64+
<sourcesNameSubexpression>6</sourcesNameSubexpression>
65+
<sourcesTypeSubexpression>7</sourcesTypeSubexpression>
66+
67+
<tests>
68+
<test>
69+
<directory>src/test/resources/regex-project/scripts/test</directory>
70+
<includes>
71+
<include>**/*bdy</include>
72+
<include>**/*spc</include>
73+
</includes>
74+
</test>
75+
</tests>
76+
<testsRegexExpression>.*(\\|\/)(\w+)(\\|\/)(\w+)(\\|\/)(\w+).(\w{3})</testsRegexExpression>
77+
<testsOwnerSubexpression>2</testsOwnerSubexpression>
78+
<testsNameSubexpression>6</testsNameSubexpression>
79+
<testsTypeSubexpression>7</testsTypeSubexpression>
80+
81+
</configuration>
82+
</plugin>
83+
</plugins>
84+
</build>
85+
</project>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
CREATE OR REPLACE PACKAGE BODY APP.PKG_TEST_ME IS
2+
3+
--
4+
-- This
5+
--
6+
FUNCTION FC_TEST_ME(PPARAM1 IN VARCHAR2) RETURN NUMBER IS
7+
BEGIN
8+
IF PPARAM1 IS NULL THEN
9+
RETURN NULL;
10+
ELSIF PPARAM1 = '1' THEN
11+
RETURN 1;
12+
ELSE
13+
RETURN 0;
14+
END IF;
15+
END FC_TEST_ME;
16+
17+
PROCEDURE PR_TEST_ME(PSNAME IN VARCHAR2) IS
18+
BEGIN
19+
IF PSNAME IS NULL THEN
20+
NULL;
21+
ELSE
22+
INSERT INTO TO_TEST_ME (SNAME) VALUES (PSNAME);
23+
COMMIT;
24+
END IF;
25+
END PR_TEST_ME;
26+
27+
END PKG_TEST_ME;
28+
/
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
--
2+
-- This package is used TO demonstrate the utPL/SQL possibilities
3+
--
4+
CREATE OR REPLACE PACKAGE app.PKG_TEST_ME AS
5+
FUNCTION FC_TEST_ME(PPARAM1 IN VARCHAR2) RETURN NUMBER;
6+
PROCEDURE PR_TEST_ME(PSNAME IN VARCHAR2);
7+
END PKG_TEST_ME;
8+
/
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
--
2+
-- This is a table used to demonstrate the UNIT test framework.
3+
--
4+
CREATE TABLE TO_TEST_ME
5+
(
6+
SNAME VARCHAR2(10)
7+
)
8+
/
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
CREATE OR REPLACE PACKAGE BODY app.TEST_PKG_TEST_ME AS
2+
3+
---------------------------------------------------------------------------
4+
PROCEDURE SETUP_GLOBAL IS
5+
BEGIN
6+
-- Put here the code which is valid for all tests and that should be
7+
-- executed once.
8+
NULL;
9+
END SETUP_GLOBAL;
10+
11+
---------------------------------------------------------------------------
12+
PROCEDURE TEARDOWN_GLOBAL IS
13+
BEGIN
14+
-- Put here the code that should be called only once after all the test
15+
-- have executed
16+
NULL;
17+
END TEARDOWN_GLOBAL;
18+
19+
---------------------------------------------------------------------------
20+
PROCEDURE SETUP_TEST IS
21+
BEGIN
22+
-- Nothing to clean up globally
23+
NULL;
24+
END SETUP_TEST;
25+
26+
PROCEDURE TEARDOWN_TEST IS
27+
BEGIN
28+
-- Nothing to clean up globally
29+
NULL;
30+
END TEARDOWN_TEST;
31+
32+
PROCEDURE TEST_FC_INPUT_1 IS
33+
BEGIN
34+
-- Ok this is a real test where I check that the function return 1
35+
-- when called with a '1' parameter
36+
UT.EXPECT(PKG_TEST_ME.FC_TEST_ME('1')).TO_EQUAL(1);
37+
END;
38+
39+
PROCEDURE SETUP_TEST_FC_INPUT_1 IS
40+
BEGIN
41+
-- Nothing to be done really
42+
NULL;
43+
END;
44+
45+
PROCEDURE TEARDOWN_TEST_FC_INPUT_1 IS
46+
BEGIN
47+
-- Nothing to be done really
48+
NULL;
49+
END;
50+
51+
PROCEDURE TEST_FC_INPUT_0 IS
52+
BEGIN
53+
-- Ok this is a real test where I check that the function return 0
54+
-- when called with a '0' parameter
55+
UT.EXPECT(PKG_TEST_ME.FC_TEST_ME('0')).TO_EQUAL(0);
56+
END;
57+
58+
PROCEDURE TEST_FC_INPUT_NULL IS
59+
BEGIN
60+
-- Ok I check that the function return NULL
61+
-- when called with a NULL parameter
62+
UT.EXPECT(PKG_TEST_ME.FC_TEST_ME(NULL)).TO_BE_NULL;
63+
END TEST_FC_INPUT_NULL;
64+
65+
PROCEDURE TEST_PR_TEST_ME_NULL IS
66+
VNCOUNT1 PLS_INTEGER;
67+
VNCOUNT2 PLS_INTEGER;
68+
BEGIN
69+
-- In this example I check that the procedure does
70+
-- not insert anything when passing it a NULL parameter
71+
SELECT COUNT(1) INTO VNCOUNT1 FROM TO_TEST_ME;
72+
PKG_TEST_ME.PR_TEST_ME(NULL);
73+
SELECT COUNT(1) INTO VNCOUNT2 FROM TO_TEST_ME;
74+
UT.EXPECT(VNCOUNT1).TO_EQUAL(VNCOUNT2);
75+
END;
76+
77+
PROCEDURE TEST_PR_TEST_ME_NOT_NULL IS
78+
VNCOUNT1 PLS_INTEGER;
79+
VNCOUNT2 PLS_INTEGER;
80+
VSNAME TO_TEST_ME.SNAME%TYPE;
81+
BEGIN
82+
-- In this test I will check that I do insert a value
83+
-- when the parameter is not null. I futher check that
84+
-- the procedure has inserted the value I specified.
85+
SELECT COUNT(1) INTO VNCOUNT1 FROM TO_TEST_ME;
86+
VSNAME := TO_CHAR(VNCOUNT1);
87+
PKG_TEST_ME.PR_TEST_ME(VSNAME);
88+
SELECT COUNT(1) INTO VNCOUNT2 FROM TO_TEST_ME;
89+
90+
-- Check that I have inserted the value
91+
UT.EXPECT(VNCOUNT1 + 1).TO_EQUAL(VNCOUNT2);
92+
SELECT COUNT(1) INTO VNCOUNT2 FROM TO_TEST_ME T WHERE T.SNAME = VSNAME;
93+
94+
-- Check that I inserted the one I said I would insert
95+
UT.EXPECT(VNCOUNT2).TO_EQUAL(1);
96+
DELETE FROM TO_TEST_ME T WHERE T.SNAME = VSNAME;
97+
COMMIT;
98+
END;
99+
100+
PROCEDURE TEST_PR_TEST_ME_EXISTS IS
101+
BEGIN
102+
-- In case the value exists the procedure should fail with an exception.
103+
BEGIN
104+
PKG_TEST_ME.PR_TEST_ME('EXISTS');
105+
PKG_TEST_ME.PR_TEST_ME('EXISTS');
106+
EXCEPTION
107+
WHEN OTHERS THEN
108+
UT.FAIL('Unexpected exception raised');
109+
END;
110+
END;
111+
112+
PROCEDURE TEST_PR_TEST_ME_CURSOR IS
113+
TYPE REF_CURSOR IS REF CURSOR;
114+
VEXPECTED REF_CURSOR;
115+
VACTUAL REF_CURSOR;
116+
BEGIN
117+
EXECUTE IMMEDIATE 'TRUNCATE TABLE TO_TEST_ME';
118+
OPEN VEXPECTED FOR
119+
SELECT T.SNAME FROM TO_TEST_ME T;
120+
OPEN VACTUAL FOR
121+
SELECT T.SNAME FROM TO_TEST_ME T;
122+
UT.EXPECT(VEXPECTED).TO_(EQUAL(VACTUAL));
123+
END;
124+
125+
END;
126+
/

0 commit comments

Comments
 (0)