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

Commitaab76c9

Browse files
committed
Add file mapping support to TestRunner
1 parentd8da220 commitaab76c9

File tree

4 files changed

+54
-29
lines changed

4 files changed

+54
-29
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ private FileMapper() {}
1919
/**
2020
* Call the database api to build the custom file mappings.
2121
*/
22-
publicstaticArraybuildFileMappingArray(Connectionconn,FileMapperOptionsmapperOptions)throwsSQLException {
22+
publicstaticArraybuildFileMappingArray(
23+
Connectionconn,List<String>filePaths,FileMapperOptionsmapperOptions)throwsSQLException {
2324
OracleConnectionoraConn =conn.unwrap(OracleConnection.class);
2425

2526
MaptypeMap =conn.getTypeMap();
@@ -44,7 +45,7 @@ public static Array buildFileMappingArray(Connection conn, FileMapperOptions map
4445

4546
callableStatement.setString(++paramIdx,mapperOptions.getOwner());
4647
callableStatement.setArray(
47-
++paramIdx,oraConn.createOracleArray(CustomTypes.UT_VARCHAR2_LIST,mapperOptions.getFilePaths().toArray()));
48+
++paramIdx,oraConn.createOracleArray(CustomTypes.UT_VARCHAR2_LIST,filePaths.toArray()));
4849
callableStatement.setArray(
4950
++paramIdx,oraConn.createOracleArray(CustomTypes.UT_KEY_VALUE_PAIRS,mapperOptions.getTypeMappings().toArray()));
5051
callableStatement.setString(++paramIdx,mapperOptions.getRegexPattern());
@@ -56,8 +57,9 @@ public static Array buildFileMappingArray(Connection conn, FileMapperOptions map
5657
returncallableStatement.getArray(1);
5758
}
5859

59-
publicstaticList<FileMapping>buildFileMappingList(Connectionconn,FileMapperOptionsmapperOptions)throwsSQLException {
60-
java.sql.ArrayfileMappings =buildFileMappingArray(conn,mapperOptions);
60+
publicstaticList<FileMapping>buildFileMappingList(
61+
Connectionconn,List<String>filePaths,FileMapperOptionsmapperOptions)throwsSQLException {
62+
java.sql.ArrayfileMappings =buildFileMappingArray(conn,filePaths,mapperOptions);
6163

6264
List<FileMapping>mappingList =newArrayList<>();
6365
for (Objectobj : (Object[])fileMappings.getArray()) {

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@
66
publicclassFileMapperOptions {
77

88
privateStringowner;
9-
privateList<String>filePaths;
109
privateList<KeyValuePair>typeMappings;
1110
privateStringregexPattern;
1211
privateintownerSubExpression;
1312
privateinttypeSubExpression;
1413
privateintnameSubExpression;
1514

16-
publicFileMapperOptions() {
17-
this.filePaths =newArrayList<>();
15+
publicFileMapperOptions(List<String>filePaths) {
1816
this.typeMappings =newArrayList<>();
1917
}
2018

@@ -26,14 +24,6 @@ public void setOwner(String owner) {
2624
this.owner =owner;
2725
}
2826

29-
publicList<String>getFilePaths() {
30-
returnfilePaths;
31-
}
32-
33-
publicvoidsetFilePaths(List<String>filePaths) {
34-
this.filePaths =filePaths;
35-
}
36-
3727
publicList<KeyValuePair>getTypeMappings() {
3828
returntypeMappings;
3929
}

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

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public class TestRunner {
2222
privateList<String>testFiles =newArrayList<>();
2323
privateList<String>includeObjects =newArrayList<>();
2424
privateList<String>excludeObjects =newArrayList<>();
25+
privateFileMapperOptionssourceMappingOptions;
26+
privateFileMapperOptionstestMappingOptions;
2527
privatebooleanfailOnErrors =false;
2628

2729
publicTestRunneraddPath(Stringpath) {
@@ -74,6 +76,16 @@ public TestRunner excludeObject(String obj) {
7476
returnthis;
7577
}
7678

79+
publicTestRunnersourceMappingOptions(FileMapperOptionsmapperOptions) {
80+
this.sourceMappingOptions =mapperOptions;
81+
returnthis;
82+
}
83+
84+
publicTestRunnertestMappingOptions(FileMapperOptionsmapperOptions) {
85+
this.testMappingOptions =mapperOptions;
86+
returnthis;
87+
}
88+
7789
publicTestRunnerfailOnErrors(booleanfailOnErrors) {
7890
this.failOnErrors =failOnErrors;
7991
returnthis;
@@ -95,21 +107,29 @@ public void run(Connection conn) throws SomeTestsFailedException, SQLException {
95107
StringcolorConsoleStr =Boolean.toString(this.colorConsole);
96108
StringfailOnErrors =Boolean.toString(this.failOnErrors);
97109

110+
StringsourceFilesParam ="a_source_files";
111+
if (this.sourceMappingOptions !=null && !this.sourceFiles.isEmpty())
112+
sourceFilesParam ="a_source_file_mappings";
113+
114+
StringtestFilesParam ="a_test_files";
115+
if (this.testMappingOptions !=null && !this.testFiles.isEmpty())
116+
sourceFilesParam ="a_test_file_mappings";
117+
98118
OracleConnectionoraConn =conn.unwrap(OracleConnection.class);
99119
CallableStatementcallableStatement =null;
100120
try {
101121
callableStatement =conn.prepareCall(
102122
"BEGIN " +
103123
"ut_runner.run(" +
104-
"a_paths => ?, " +
105-
"a_reporters => ?, " +
106-
"a_color_console => " +colorConsoleStr +", " +
107-
"a_coverage_schemes => ?, " +
108-
"a_source_files => ?, " +
109-
"a_test_files => ?, " +
110-
"a_include_objects => ?, " +
111-
"a_exclude_objects => ?, " +
112-
"a_fail_on_errors => " +failOnErrors +"); " +
124+
"a_paths=> ?, " +
125+
"a_reporters=> ?, " +
126+
"a_color_console=> " +colorConsoleStr +", " +
127+
"a_coverage_schemes=> ?, " +
128+
sourceFilesParam +" => ?, " +
129+
testFilesParam +" => ?, " +
130+
"a_include_objects=> ?, " +
131+
"a_exclude_objects=> ?, " +
132+
"a_fail_on_errors=> " +failOnErrors +"); " +
113133
"END;");
114134

115135
intparamIdx =0;
@@ -129,13 +149,25 @@ public void run(Connection conn) throws SomeTestsFailedException, SQLException {
129149

130150
if (this.sourceFiles.isEmpty()) {
131151
callableStatement.setNull(++paramIdx,Types.ARRAY,CustomTypes.UT_VARCHAR2_LIST);
152+
}elseif (this.sourceMappingOptions !=null) {
153+
ArraysourceMappings =FileMapper.buildFileMappingArray(
154+
conn,this.sourceFiles,this.sourceMappingOptions);
155+
156+
callableStatement.setArray(
157+
++paramIdx,oraConn.createOracleArray(CustomTypes.UT_FILE_MAPPINGS,sourceMappings));
132158
}else {
133159
callableStatement.setArray(
134160
++paramIdx,oraConn.createOracleArray(CustomTypes.UT_VARCHAR2_LIST,this.sourceFiles.toArray()));
135161
}
136162

137163
if (this.testFiles.isEmpty()) {
138164
callableStatement.setNull(++paramIdx,Types.ARRAY,CustomTypes.UT_VARCHAR2_LIST);
165+
}elseif (this.testMappingOptions !=null) {
166+
ArraysourceMappings =FileMapper.buildFileMappingArray(
167+
conn,this.testFiles,this.testMappingOptions);
168+
169+
callableStatement.setArray(
170+
++paramIdx,oraConn.createOracleArray(CustomTypes.UT_FILE_MAPPINGS,sourceMappings));
139171
}else {
140172
callableStatement.setArray(
141173
++paramIdx,oraConn.createOracleArray(CustomTypes.UT_VARCHAR2_LIST,this.testFiles.toArray()));

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,19 @@ public void testFileMapper() throws SQLException {
2020
typeMappings.add(newKeyValuePair("procedures","PROCEDURE"));
2121
typeMappings.add(newKeyValuePair("functions","FUNCTION"));
2222

23-
FileMapperOptionsmapperOptions =newFileMapperOptions();
24-
mapperOptions.setOwner("APP");
25-
mapperOptions.setFilePaths(java.util.Arrays.asList(
23+
List<String>filePaths =java.util.Arrays.asList(
2624
"sources/app/procedures/award_bonus.sql",
27-
"sources/app/functions/betwnstr.sql"));
25+
"sources/app/functions/betwnstr.sql");
26+
27+
FileMapperOptionsmapperOptions =newFileMapperOptions(filePaths);
28+
mapperOptions.setOwner("APP");
2829
mapperOptions.setTypeMappings(typeMappings);
2930
mapperOptions.setRegexPattern("\\w+[\\\\\\/](\\w+)[\\\\\\/](\\w+)[\\\\\\/](\\w+)[.](\\w{3})");
3031
mapperOptions.setOwnerSubExpression(1);
3132
mapperOptions.setTypeSubExpression(2);
3233
mapperOptions.setNameSubExpression(3);
3334

34-
List<FileMapping>fileMappings =FileMapper.buildFileMappingList(db.newConnection(),mapperOptions);
35+
List<FileMapping>fileMappings =FileMapper.buildFileMappingList(db.newConnection(),filePaths,mapperOptions);
3536

3637
if (fileMappings.size() !=2)
3738
Assert.fail("Wrong mapping list size.");

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp