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

Commit9401da7

Browse files
committed
Change TestRunner usage
1 parentc7a5f44 commit9401da7

File tree

4 files changed

+146
-51
lines changed

4 files changed

+146
-51
lines changed

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

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,45 @@
55
importjava.sql.CallableStatement;
66
importjava.sql.Connection;
77
importjava.sql.SQLException;
8+
importjava.sql.Types;
89

910
/**
10-
*Created by Vinicius Avellar on 12/04/2017.
11+
*Database utility functions.
1112
*/
1213
publicfinalclassDBHelper {
1314

15+
/**
16+
* Return a new sys_guid from database.
17+
* @param conn the connection
18+
* @return the new id string
19+
* @throws SQLException any database error
20+
*/
1421
publicstaticStringnewSysGuid(Connectionconn)throwsSQLException {
1522
CallableStatementcallableStatement =null;
1623
try {
17-
callableStatement =conn.prepareCall("BEGIN:id := sys_guid(); END;");
18-
callableStatement.registerOutParameter(":id",OracleTypes.RAW);
24+
callableStatement =conn.prepareCall("BEGIN? := sys_guid(); END;");
25+
callableStatement.registerOutParameter(1,OracleTypes.RAW);
1926
callableStatement.executeUpdate();
20-
returncallableStatement.getString(":id");
27+
returncallableStatement.getString(1);
28+
}finally {
29+
if (callableStatement !=null)
30+
callableStatement.close();
31+
}
32+
}
33+
34+
/**
35+
* Return the current schema name.
36+
* @param conn the connection
37+
* @return the schema name
38+
* @throws SQLException any database error
39+
*/
40+
publicstaticStringgetCurrentSchema(Connectionconn)throwsSQLException {
41+
CallableStatementcallableStatement =null;
42+
try {
43+
callableStatement =conn.prepareCall("BEGIN ? := sys_context('userenv', 'current_schema'); END;");
44+
callableStatement.registerOutParameter(1,Types.VARCHAR);
45+
callableStatement.executeUpdate();
46+
returncallableStatement.getString(1);
2147
}finally {
2248
if (callableStatement !=null)
2349
callableStatement.close();

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

Lines changed: 85 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,111 @@
11
packageio.github.utplsql.api;
22

3+
importio.github.utplsql.api.reporter.DocumentationReporter;
34
importio.github.utplsql.api.reporter.Reporter;
45
importoracle.jdbc.OracleConnection;
56

6-
importjava.sql.Array;
7-
importjava.sql.CallableStatement;
8-
importjava.sql.Connection;
9-
importjava.sql.SQLException;
7+
importjava.sql.*;
8+
importjava.util.ArrayList;
109
importjava.util.List;
1110

1211
/**
1312
* Created by Vinicius Avellar on 12/04/2017.
1413
*/
1514
publicclassTestRunner {
1615

17-
publicTestRunner() {}
16+
privateList<String>pathList =newArrayList<>();
17+
privateList<Reporter>reporterList =newArrayList<>();
18+
privateList<String>coverageSchemes =newArrayList<>();
19+
privateList<String>sourceFiles =newArrayList<>();
20+
privateList<String>testFiles =newArrayList<>();
21+
privateList<String>includeObjects =newArrayList<>();
22+
privateList<String>excludeObjects =newArrayList<>();
1823

19-
publicvoidrun(Connectionconn,Stringpath,Reporterreporter)throwsSQLException {
20-
validateReporter(conn,reporter);
21-
CallableStatementcallableStatement =null;
22-
try {
23-
callableStatement =conn.prepareCall("BEGIN ut_runner.run(a_path => :path, a_reporter => :reporter); END;");
24-
callableStatement.setString(":path",path);
25-
callableStatement.setObject(":reporter",reporter);
26-
callableStatement.execute();
27-
}finally {
28-
if (callableStatement !=null)
29-
callableStatement.close();
30-
}
24+
publicTestRunner() {
25+
}
26+
27+
publicTestRunneraddPath(Stringpath) {
28+
this.pathList.add(path);
29+
returnthis;
30+
}
31+
32+
publicTestRunneraddPathList(List<String>paths) {
33+
this.pathList.addAll(paths);
34+
returnthis;
35+
}
36+
37+
publicTestRunneraddReporter(Reporterreporter) {
38+
this.reporterList.add(reporter);
39+
returnthis;
40+
}
41+
42+
publicTestRunneraddReporterList(List<Reporter>reporterList) {
43+
this.reporterList.addAll(reporterList);
44+
returnthis;
3145
}
3246

33-
publicvoidrun(Connectionconn,List<String>pathList,List<Reporter>reporterList)throwsSQLException {
34-
for (Reporterr :reporterList)
47+
publicTestRunneraddCoverageScheme(StringcoverageScheme) {
48+
this.coverageSchemes.add(coverageScheme);
49+
returnthis;
50+
}
51+
52+
publicTestRunnerwithSourceFiles(List<String>sourceFiles) {
53+
this.sourceFiles.addAll(sourceFiles);
54+
returnthis;
55+
}
56+
57+
publicTestRunnerwithTestFiles(List<String>testFiles) {
58+
this.testFiles.addAll(testFiles);
59+
returnthis;
60+
}
61+
62+
publicTestRunnerincludeObject(Stringobj) {
63+
this.includeObjects.add(obj);
64+
returnthis;
65+
}
66+
67+
publicTestRunnerexcludeObject(Stringobj) {
68+
this.excludeObjects.add(obj);
69+
returnthis;
70+
}
71+
72+
publicvoidrun(Connectionconn)throwsSQLException {
73+
for (Reporterr :this.reporterList)
3574
validateReporter(conn,r);
3675

76+
if (this.pathList.isEmpty()) {
77+
this.pathList.add(DBHelper.getCurrentSchema(conn));
78+
}
79+
80+
if (this.reporterList.isEmpty()) {
81+
this.reporterList.add(newDocumentationReporter().init(conn));
82+
}
83+
3784
OracleConnectionoraConn =conn.unwrap(OracleConnection.class);
38-
ArraypathArray =oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST,pathList.toArray());
39-
ArrayreporterArray =oraConn.createARRAY(CustomTypes.UT_REPORTERS,reporterList.toArray());
85+
ArraypathArray =oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST,this.pathList.toArray());
86+
ArrayreporterArray =oraConn.createARRAY(CustomTypes.UT_REPORTERS,this.reporterList.toArray());
87+
ArraycoverageSchemes =oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST,this.coverageSchemes.toArray());
88+
ArraysourceFiles =oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST,this.sourceFiles.toArray());
89+
ArraytestFiles =oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST,this.testFiles.toArray());
90+
ArrayincludeObjects =oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST,this.includeObjects.toArray());
91+
ArrayexcludeObjects =oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST,this.excludeObjects.toArray());
4092

4193
CallableStatementcallableStatement =null;
4294
try {
43-
callableStatement =conn.prepareCall("BEGIN ut_runner.run(a_paths => ?, a_reporters => ?); END;");
95+
callableStatement =conn.prepareCall(
96+
"BEGIN " +
97+
"ut_runner.run(" +
98+
"a_paths => ?, a_reporters => ?, a_coverage_schemes => ?," +
99+
"a_source_files => ?, a_test_files => ?, " +
100+
"a_include_objects => ?, a_exclude_objects => ?); " +
101+
"END;");
44102
callableStatement.setArray(1,pathArray);
45103
callableStatement.setArray(2,reporterArray);
104+
callableStatement.setArray(3,coverageSchemes);
105+
callableStatement.setArray(4,sourceFiles);
106+
callableStatement.setArray(5,testFiles);
107+
callableStatement.setArray(6,includeObjects);
108+
callableStatement.setArray(7,excludeObjects);
46109
callableStatement.execute();
47110
}finally {
48111
if (callableStatement !=null)

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
packageio.github.utplsql.api;
22

3-
importio.github.utplsql.api.rules.DatabaseRule;
4-
importio.github.utplsql.api.reporter.Reporter;
53
importio.github.utplsql.api.reporter.DocumentationReporter;
4+
importio.github.utplsql.api.reporter.Reporter;
5+
importio.github.utplsql.api.rules.DatabaseRule;
66
importorg.junit.Assert;
77
importorg.junit.Rule;
88
importorg.junit.Test;
99

10+
importjava.io.File;
1011
importjava.io.FileOutputStream;
1112
importjava.io.PrintStream;
1213
importjava.sql.Connection;
@@ -40,7 +41,10 @@ public void printAvailableLines() {
4041
Future<Object>task1 =executorService.submit(() -> {
4142
try {
4243
Connectionconn =db.newConnection();
43-
newTestRunner().run(conn,"",reporter);
44+
newTestRunner()
45+
.addPath(db.getUser())
46+
.addReporter(reporter)
47+
.run(conn);
4448

4549
returnBoolean.TRUE;
4650
}catch (SQLExceptione) {
@@ -50,9 +54,10 @@ public void printAvailableLines() {
5054

5155
Future<Object>task2 =executorService.submit(() -> {
5256
FileOutputStreamfileOutStream =null;
57+
FileoutFile =newFile("output.txt");
5358
try {
5459
Connectionconn =db.newConnection();
55-
fileOutStream =newFileOutputStream("output.txt");
60+
fileOutStream =newFileOutputStream(outFile);
5661

5762
List<PrintStream>printStreams =newArrayList<>();
5863
printStreams.add(System.out);
@@ -65,8 +70,10 @@ public void printAvailableLines() {
6570
}catch (SQLExceptione) {
6671
returne;
6772
}finally {
68-
if (fileOutStream !=null)
73+
if (fileOutStream !=null) {
6974
fileOutStream.close();
75+
outFile.delete();
76+
}
7077
}
7178
});
7279

@@ -93,7 +100,10 @@ public void fetchAllLines() {
93100
try {
94101
finalReporterreporter =createReporter();
95102
Connectionconn =db.newConnection();
96-
newTestRunner().run(conn,"",reporter);
103+
newTestRunner()
104+
.addPath(db.getUser())
105+
.addReporter(reporter)
106+
.run(conn);
97107

98108
List<String>outputLines =newOutputBuffer(reporter)
99109
.fetchAll(conn);

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

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
packageio.github.utplsql.api;
22

3+
importio.github.utplsql.api.reporter.*;
34
importio.github.utplsql.api.rules.DatabaseRule;
4-
importio.github.utplsql.api.reporter.Reporter;
5-
importio.github.utplsql.api.reporter.CoverageHTMLReporter;
6-
importio.github.utplsql.api.reporter.DocumentationReporter;
75
importorg.junit.Assert;
86
importorg.junit.Rule;
97
importorg.junit.Test;
108

119
importjava.sql.Connection;
1210
importjava.sql.SQLException;
13-
importjava.util.ArrayList;
14-
importjava.util.List;
1511

1612
/**
1713
* Created by Vinicius on 13/04/2017.
@@ -22,30 +18,30 @@ public class TestRunnerTest {
2218
publicfinalDatabaseRuledb =newDatabaseRule();
2319

2420
@Test
25-
publicvoidrunWithDocumentationReporter() {
21+
publicvoidrunWithDefaultParameters() {
2622
try {
2723
Connectionconn =db.newConnection();
28-
Reporterreporter =newDocumentationReporter();
29-
newTestRunner().run(conn,db.getUser(),reporter);
30-
Assert.assertNotNull(reporter.getReporterId());
24+
newTestRunner().run(conn);
3125
}catch (SQLExceptione) {
3226
Assert.fail(e.getMessage());
3327
}
3428
}
3529

3630
@Test
37-
publicvoidrunWithTwoReporters() {
31+
publicvoidrunWithManyReporters() {
3832
try {
3933
Connectionconn =db.newConnection();
40-
41-
List<String>pathList =newArrayList<>();
42-
pathList.add(db.getUser());
43-
44-
List<Reporter>reporterList =newArrayList<>();
45-
reporterList.add(newDocumentationReporter().init(conn));
46-
reporterList.add(newCoverageHTMLReporter().init(conn));
47-
48-
newTestRunner().run(conn,pathList,reporterList);
34+
newTestRunner()
35+
.addPath("ut3")
36+
.addPath(db.getUser())
37+
.addReporter(newDocumentationReporter().init(conn))
38+
.addReporter(newCoverageHTMLReporter().init(conn))
39+
.addReporter(newCoverageSonarReporter().init(conn))
40+
.addReporter(newCoverallsReporter().init(conn))
41+
.addReporter(newSonarTestReporter().init(conn))
42+
.addReporter(newTeamCityReporter().init(conn))
43+
.addReporter(newXUnitReporter().init(conn))
44+
.run(conn);
4945
}catch (SQLExceptione) {
5046
Assert.fail(e.getMessage());
5147
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp