Skip to content

Commit 3a58b3f

Browse files
committed
Added tags functionality
1 parent 1e90eb7 commit 3a58b3f

File tree

7 files changed

+318
-0
lines changed

7 files changed

+318
-0
lines changed

src/it/java/org/utpsql/maven/plugin/test/UtPLSQLMojoIT.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,30 @@ public void testMinimalistProject() throws Exception {
156156
}
157157
}
158158

159+
@Test
160+
public void testTagsProject() throws Exception {
161+
162+
try {
163+
final String PROJECT_NAME = "tags-project";
164+
File testProject = ResourceExtractor.simpleExtractResources(getClass(), "/" + PROJECT_NAME);
165+
166+
Verifier verifier;
167+
verifier = new Verifier(testProject.getAbsolutePath());
168+
verifier.addCliOption("-N");
169+
verifier.addCliOption("-Dutplsql-maven-plugin-version=" + pluginVersion);
170+
verifier.addCliOption("-DdbUrl=" + System.getProperty("dbUrl"));
171+
verifier.addCliOption("-DdbUser=" + System.getProperty("dbUser"));
172+
verifier.addCliOption("-DdbPass=" + System.getProperty("dbPass"));
173+
174+
verifier.executeGoal("test");
175+
176+
checkReportsGenerated(PROJECT_NAME, "utplsql/sonar-test-reporter.xml");
177+
} catch (Exception e) {
178+
e.printStackTrace();
179+
Assert.fail("Unexpected Exception running the test of Definition " + e.getMessage());
180+
}
181+
}
182+
159183
/**
160184
*
161185
* @param files

src/it/resources/simple-project/scripts/tests/APP.TEST_PKG_TEST_ME.spc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,13 @@ CREATE OR REPLACE PACKAGE TEST_PKG_TEST_ME AS
7575
-- %test
7676
-- %displayname(Checking if procedure (NOT NULL) insert while existing)
7777
-- %rollback(manual)
78+
-- $tags(exists)
7879
PROCEDURE TEST_PR_TEST_ME_EXISTS;
7980

8081
-- %test
8182
-- %displayname(Demonstrating the use of cursor)
8283
-- %rollback(manual)
84+
== %tags(cursor)
8385
PROCEDURE TEST_PR_TEST_ME_CURSOR;
8486

8587
END;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<testExecutions version="1">
2+
<file path="scripts/tests/APP.TEST_PKG_TEST_ME.bdy">
3+
<testCase name="test_pr_test_me_exists" duration="1" >
4+
</testCase>
5+
<testCase name="test_pr_test_me_cursor" duration="1" >
6+
</testCase>
7+
</file>
8+
</testExecutions>

src/it/resources/tags-project/pom.xml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>org.utplsql</groupId>
7+
<artifactId>utplsql-maven-plugin-tags</artifactId>
8+
<version>1.0.0</version>
9+
<packaging>pom</packaging>
10+
11+
<name>utplsql-maven-plugin IT Tags</name>
12+
<properties>
13+
<!-- url, user, password are set with dbUrl, dbUser, dbPass system properties -->
14+
</properties>
15+
16+
<build>
17+
<plugins>
18+
<plugin>
19+
<groupId>${project.groupId}</groupId>
20+
<artifactId>utplsql-maven-plugin</artifactId>
21+
<version>${utplsql-maven-plugin-version}</version>
22+
<executions>
23+
<execution>
24+
<goals>
25+
<goal>test</goal>
26+
</goals>
27+
<configuration>
28+
<!-- Mandatory Attributes -->
29+
30+
<ignoreFailure>false</ignoreFailure>
31+
32+
<paths>
33+
<path>app</path>
34+
</paths>
35+
36+
<tags>
37+
<tag>exists</tag>
38+
<tag>cursor</tag>
39+
</tags>
40+
41+
<reporters>
42+
<reporter>
43+
<name>UT_SONAR_TEST_REPORTER</name>
44+
<fileOutput>utplsql/sonar-test-reporter.xml</fileOutput>
45+
<consoleOutput>true</consoleOutput>
46+
</reporter>
47+
</reporters>
48+
49+
<tests>
50+
<test>
51+
<directory>scripts/tests</directory>
52+
<includes>
53+
<include>**/*bdy</include>
54+
<include>**/*spc</include>
55+
</includes>
56+
</test>
57+
</tests>
58+
</configuration>
59+
</execution>
60+
</executions>
61+
</plugin>
62+
</plugins>
63+
</build>
64+
</project>
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
CREATE OR REPLACE PACKAGE BODY 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+
/
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
CREATE OR REPLACE PACKAGE TEST_PKG_TEST_ME AS
2+
-- %suite(TEST_PKG_TEST_ME)
3+
-- %suitepath(plsql.examples)
4+
--
5+
-- This package shows all the possibilities to unit test
6+
-- your PL/SQL package. NOTE that it is not limited to
7+
-- testing your package. You can do that on all your
8+
-- procedure/functions...
9+
--
10+
11+
/**
12+
* This two parameters are used by the test framework in
13+
* order to identify the test suite to run
14+
*/
15+
16+
/*
17+
* This method is invoked once before any other method.
18+
* It should contain all the setup code that is relevant
19+
* for all your test. It might be inserting a register,
20+
* creating a type, etc...
21+
*/
22+
-- %beforeall
23+
PROCEDURE SETUP_GLOBAL;
24+
25+
/*
26+
* This method is invoked once after all other method.
27+
* It can be used to clean up all the resources that
28+
* you created in your script
29+
*/
30+
-- %afterall
31+
PROCEDURE TEARDOWN_GLOBAL;
32+
33+
/*
34+
* This method is called once before each test.
35+
*/
36+
-- %beforeeach
37+
PROCEDURE SETUP_TEST;
38+
39+
/*
40+
* This method is called once after each test.
41+
*/
42+
-- %aftereach
43+
PROCEDURE TEARDOWN_TEST;
44+
45+
/**
46+
* This is a real test. The main test can declare a setup
47+
* and teardown method in order to setup and cleanup things
48+
* for that specific test.
49+
*/
50+
-- %test
51+
-- %displayname(Checking if function ('1') returns 1)
52+
-- %beforetest(SETUP_TEST_FC_INPUT_1)
53+
-- %aftertest(TEARDOWN_TEST_FC_INPUT_1)
54+
PROCEDURE TEST_FC_INPUT_1;
55+
PROCEDURE SETUP_TEST_FC_INPUT_1;
56+
PROCEDURE TEARDOWN_TEST_FC_INPUT_1;
57+
58+
-- %test
59+
-- %displayname(Checking if function ('0') returns 0)
60+
PROCEDURE TEST_FC_INPUT_0;
61+
62+
-- %test
63+
-- %displayname(Checking if function (NULL) returns NULL)
64+
PROCEDURE TEST_FC_INPUT_NULL;
65+
66+
-- %test
67+
-- %displayname(Checking if procedure (NULL) insert)
68+
PROCEDURE TEST_PR_TEST_ME_NULL;
69+
70+
-- %test
71+
-- %displayname(Checking if procedure (NOT NULL) insert)
72+
-- %rollback(manual)
73+
PROCEDURE TEST_PR_TEST_ME_NOT_NULL;
74+
75+
-- %test
76+
-- %displayname(Checking if procedure (NOT NULL) insert while existing)
77+
-- %rollback(manual)
78+
-- $tags(exists)
79+
PROCEDURE TEST_PR_TEST_ME_EXISTS;
80+
81+
-- %test
82+
-- %displayname(Demonstrating the use of cursor)
83+
-- %rollback(manual)
84+
== %tags(cursor)
85+
PROCEDURE TEST_PR_TEST_ME_CURSOR;
86+
87+
END;
88+
/

src/main/java/org/utplsql/maven/plugin/UtPLSQLMojo.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import java.sql.Connection;
55
import java.sql.SQLException;
66
import java.util.ArrayList;
7+
import java.util.LinkedHashSet;
78
import java.util.List;
9+
import java.util.Set;
810

911
import org.apache.commons.lang3.StringUtils;
1012
import org.apache.maven.model.Resource;
@@ -113,6 +115,9 @@ public class UtPLSQLMojo extends AbstractMojo {
113115
@Parameter
114116
private List<CustomTypeMapping> testsCustomTypeMapping;
115117

118+
@Parameter
119+
private Set<String> tags = new LinkedHashSet<>();
120+
116121
@Parameter(defaultValue = "${project.build.directory}", readonly = true)
117122
protected String targetDir;
118123

@@ -159,6 +164,7 @@ public void execute() throws MojoExecutionException {
159164
.testMappingOptions(testMappingOptions)
160165
.skipCompatibilityCheck(skipCompatibilityCheck)
161166
.colorConsole(colorConsole)
167+
.addTags(tags)
162168
.failOnErrors(!ignoreFailure);
163169

164170
if (StringUtils.isNotBlank(excludeObject)) {

0 commit comments

Comments
 (0)