Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitec292cf

Browse files
committed
Add support for multiple reporters
1 parente453df0 commitec292cf

File tree

5 files changed

+60
-13
lines changed

5 files changed

+60
-13
lines changed

‎src/main/java/io/github/utplsql/api/TestRunner.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
packageio.github.utplsql.api;
22

33
importio.github.utplsql.api.types.BaseReporter;
4+
importio.github.utplsql.api.types.CustomTypes;
5+
importoracle.jdbc.OracleConnection;
46

7+
importjava.sql.Array;
58
importjava.sql.CallableStatement;
69
importjava.sql.Connection;
710
importjava.sql.SQLException;
11+
importjava.util.List;
812

913
/**
1014
* Created by Vinicius Avellar on 12/04/2017.
@@ -27,6 +31,26 @@ public void run(Connection conn, String path, BaseReporter reporter) throws SQLE
2731
}
2832
}
2933

34+
publicvoidrun(Connectionconn,List<String>pathList,List<BaseReporter>reporterList)throwsSQLException {
35+
for (BaseReporterr :reporterList)
36+
validateReporter(conn,r);
37+
38+
OracleConnectionoraConn =conn.unwrap(OracleConnection.class);
39+
ArraypathArray =oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST,pathList.toArray());
40+
ArrayreporterArray =oraConn.createARRAY(CustomTypes.UT_REPORTERS,reporterList.toArray());
41+
42+
CallableStatementcallableStatement =null;
43+
try {
44+
callableStatement =conn.prepareCall("BEGIN ut_runner.run(a_paths => ?, a_reporters => ?); END;");
45+
callableStatement.setArray(1,pathArray);
46+
callableStatement.setArray(2,reporterArray);
47+
callableStatement.execute();
48+
}finally {
49+
if (callableStatement !=null)
50+
callableStatement.close();
51+
}
52+
}
53+
3054
/**
3155
* Check if the reporter was initialized, if not call reporter.init.
3256
* @param conn the database connection

‎src/main/java/io/github/utplsql/api/types/CoverageHTMLReporter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class CoverageHTMLReporter extends BaseReporter {
99

1010
@Override
1111
publicStringgetSQLTypeName()throwsSQLException {
12-
returnCustomTypes.UT_COVERAGE_HTML_REPORTER.getName();
12+
returnCustomTypes.UT_COVERAGE_HTML_REPORTER;
1313
}
1414

1515
}

‎src/main/java/io/github/utplsql/api/types/CustomTypes.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@
33
/**
44
* Database custom data types.
55
*/
6-
publicenumCustomTypes {
7-
// Object names must be upper case.
8-
UT_DOCUMENTATION_REPORTER("UT_DOCUMENTATION_REPORTER"),
9-
UT_COVERAGE_HTML_REPORTER("UT_COVERAGE_HTML_REPORTER"),
10-
UT_VARCHAR2_LIST("UT_VARCHAR2_LIST");
6+
publicfinalclassCustomTypes {
117

12-
privateStringtypeName;
8+
// Object names must be upper case.
9+
publicstaticfinalStringUT_REPORTERS ="UT_REPORTERS";
10+
publicstaticfinalStringUT_DOCUMENTATION_REPORTER ="UT_DOCUMENTATION_REPORTER";
11+
publicstaticfinalStringUT_COVERAGE_HTML_REPORTER ="UT_COVERAGE_HTML_REPORTER";
12+
publicstaticfinalStringUT_VARCHAR2_LIST ="UT_VARCHAR2_LIST";
1313

14-
CustomTypes(StringtypeName) {
15-
this.typeName =typeName;
16-
}
14+
privateCustomTypes() {}
1715

18-
publicStringgetName() {
19-
returnthis.typeName;
16+
publicstaticBaseReportercreateReporter(StringreporterName) {
17+
switch (reporterName.toUpperCase()) {
18+
caseUT_DOCUMENTATION_REPORTER:returnnewDocumentationReporter();
19+
caseUT_COVERAGE_HTML_REPORTER:returnnewCoverageHTMLReporter();
20+
}
21+
thrownewRuntimeException("Reporter " +reporterName +" not implemented.");
2022
}
2123

2224
}

‎src/main/java/io/github/utplsql/api/types/DocumentationReporter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class DocumentationReporter extends BaseReporter {
99

1010
@Override
1111
publicStringgetSQLTypeName()throwsSQLException {
12-
returnCustomTypes.UT_DOCUMENTATION_REPORTER.getName();
12+
returnCustomTypes.UT_DOCUMENTATION_REPORTER;
1313
}
1414

1515
}

‎src/test/java/io/github/utplsql/api/TestRunnerTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22

33
importio.github.utplsql.api.rules.DatabaseRule;
44
importio.github.utplsql.api.types.BaseReporter;
5+
importio.github.utplsql.api.types.CoverageHTMLReporter;
56
importio.github.utplsql.api.types.DocumentationReporter;
67
importorg.junit.Assert;
78
importorg.junit.Rule;
89
importorg.junit.Test;
910

1011
importjava.sql.Connection;
1112
importjava.sql.SQLException;
13+
importjava.util.ArrayList;
14+
importjava.util.List;
1215

1316
/**
1417
* Created by Vinicius on 13/04/2017.
@@ -30,4 +33,22 @@ public void runWithDocumentationReporter() {
3033
}
3134
}
3235

36+
@Test
37+
publicvoidrunWithTwoReporters() {
38+
try {
39+
Connectionconn =db.newConnection();
40+
41+
List<String>pathList =newArrayList<>();
42+
pathList.add("app");
43+
44+
List<BaseReporter>reporterList =newArrayList<>();
45+
reporterList.add(newDocumentationReporter().init(conn));
46+
reporterList.add(newCoverageHTMLReporter().init(conn));
47+
48+
newTestRunner().run(conn,pathList,reporterList);
49+
}catch (SQLExceptione) {
50+
Assert.fail(e.getMessage());
51+
}
52+
}
53+
3354
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp