Skip to content

Commit 507f675

Browse files
committed
Add custom mapping to TestRunner
1 parent aab76c9 commit 507f675

File tree

4 files changed

+51
-38
lines changed

4 files changed

+51
-38
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static Array buildFileMappingArray(
4343
int paramIdx = 0;
4444
callableStatement.registerOutParameter(++paramIdx, OracleTypes.ARRAY, CustomTypes.UT_FILE_MAPPINGS);
4545

46-
callableStatement.setString(++paramIdx, mapperOptions.getOwner());
46+
callableStatement.setString(++paramIdx, mapperOptions.getObjectOwner());
4747
callableStatement.setArray(
4848
++paramIdx, oraConn.createOracleArray(CustomTypes.UT_VARCHAR2_LIST, filePaths.toArray()));
4949
callableStatement.setArray(

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@
55

66
public class FileMapperOptions {
77

8-
private String owner;
8+
private String objectOwner;
99
private List<KeyValuePair> typeMappings;
1010
private String regexPattern;
1111
private int ownerSubExpression;
1212
private int typeSubExpression;
1313
private int nameSubExpression;
1414

15-
public FileMapperOptions(List<String> filePaths) {
15+
public FileMapperOptions() {
1616
this.typeMappings = new ArrayList<>();
1717
}
1818

19-
public String getOwner() {
20-
return owner;
19+
public String getObjectOwner() {
20+
return objectOwner;
2121
}
2222

23-
public void setOwner(String owner) {
24-
this.owner = owner;
23+
public void setObjectOwner(String owner) {
24+
this.objectOwner = owner;
2525
}
2626

2727
public List<KeyValuePair> getTypeMappings() {

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

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
import io.github.utplsql.api.reporter.Reporter;
66
import oracle.jdbc.OracleConnection;
77

8-
import java.sql.*;
8+
import java.sql.CallableStatement;
9+
import java.sql.Connection;
10+
import java.sql.SQLException;
11+
import java.sql.Types;
912
import java.util.ArrayList;
1013
import java.util.List;
1114

@@ -108,12 +111,12 @@ public void run(Connection conn) throws SomeTestsFailedException, SQLException {
108111
String failOnErrors = Boolean.toString(this.failOnErrors);
109112

110113
String sourceFilesParam = "a_source_files";
111-
if (this.sourceMappingOptions != null && !this.sourceFiles.isEmpty())
112-
sourceFilesParam = "a_source_file_mappings";
113-
114114
String testFilesParam = "a_test_files";
115-
if (this.testMappingOptions != null && !this.testFiles.isEmpty())
116-
sourceFilesParam = "a_test_file_mappings";
115+
116+
if (this.sourceMappingOptions != null || this.testMappingOptions != null) {
117+
sourceFilesParam = "a_source_file_mappings";
118+
testFilesParam = "a_test_file_mappings";
119+
}
117120

118121
OracleConnection oraConn = conn.unwrap(OracleConnection.class);
119122
CallableStatement callableStatement = null;
@@ -147,30 +150,40 @@ public void run(Connection conn) throws SomeTestsFailedException, SQLException {
147150
++paramIdx, oraConn.createOracleArray(CustomTypes.UT_VARCHAR2_LIST, this.coverageSchemes.toArray()));
148151
}
149152

150-
if (this.sourceFiles.isEmpty()) {
151-
callableStatement.setNull(++paramIdx, Types.ARRAY, CustomTypes.UT_VARCHAR2_LIST);
152-
} else if (this.sourceMappingOptions != null) {
153-
Array sourceMappings = FileMapper.buildFileMappingArray(
154-
conn, this.sourceFiles, this.sourceMappingOptions);
155-
156-
callableStatement.setArray(
157-
++paramIdx, oraConn.createOracleArray(CustomTypes.UT_FILE_MAPPINGS, sourceMappings));
158-
} else {
159-
callableStatement.setArray(
160-
++paramIdx, oraConn.createOracleArray(CustomTypes.UT_VARCHAR2_LIST, this.sourceFiles.toArray()));
161-
}
162-
163-
if (this.testFiles.isEmpty()) {
164-
callableStatement.setNull(++paramIdx, Types.ARRAY, CustomTypes.UT_VARCHAR2_LIST);
165-
} else if (this.testMappingOptions != null) {
166-
Array sourceMappings = FileMapper.buildFileMappingArray(
167-
conn, this.testFiles, this.testMappingOptions);
168-
169-
callableStatement.setArray(
170-
++paramIdx, oraConn.createOracleArray(CustomTypes.UT_FILE_MAPPINGS, sourceMappings));
153+
if (this.sourceMappingOptions != null || this.testMappingOptions != null) {
154+
if (this.sourceMappingOptions != null) {
155+
List<FileMapping> sourceMappings = FileMapper.buildFileMappingList(
156+
conn, this.sourceFiles, this.sourceMappingOptions);
157+
158+
callableStatement.setArray(
159+
++paramIdx, oraConn.createOracleArray(CustomTypes.UT_FILE_MAPPINGS, sourceMappings.toArray()));
160+
} else {
161+
callableStatement.setNull(++paramIdx, Types.ARRAY, CustomTypes.UT_FILE_MAPPINGS);
162+
}
163+
164+
if (this.testMappingOptions != null) {
165+
List<FileMapping> sourceMappings = FileMapper.buildFileMappingList(
166+
conn, this.testFiles, this.testMappingOptions);
167+
168+
callableStatement.setArray(
169+
++paramIdx, oraConn.createOracleArray(CustomTypes.UT_FILE_MAPPINGS, sourceMappings.toArray()));
170+
} else {
171+
callableStatement.setNull(++paramIdx, Types.ARRAY, CustomTypes.UT_FILE_MAPPINGS);
172+
}
171173
} else {
172-
callableStatement.setArray(
173-
++paramIdx, oraConn.createOracleArray(CustomTypes.UT_VARCHAR2_LIST, this.testFiles.toArray()));
174+
if (this.sourceFiles.isEmpty()) {
175+
callableStatement.setNull(++paramIdx, Types.ARRAY, CustomTypes.UT_VARCHAR2_LIST);
176+
} else {
177+
callableStatement.setArray(
178+
++paramIdx, oraConn.createOracleArray(CustomTypes.UT_VARCHAR2_LIST, this.sourceFiles.toArray()));
179+
}
180+
181+
if (this.testFiles.isEmpty()) {
182+
callableStatement.setNull(++paramIdx, Types.ARRAY, CustomTypes.UT_VARCHAR2_LIST);
183+
} else {
184+
callableStatement.setArray(
185+
++paramIdx, oraConn.createOracleArray(CustomTypes.UT_VARCHAR2_LIST, this.testFiles.toArray()));
186+
}
174187
}
175188

176189
if (this.includeObjects.isEmpty()) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ public void testFileMapper() throws SQLException {
2424
"sources/app/procedures/award_bonus.sql",
2525
"sources/app/functions/betwnstr.sql");
2626

27-
FileMapperOptions mapperOptions = new FileMapperOptions(filePaths);
28-
mapperOptions.setOwner("APP");
27+
FileMapperOptions mapperOptions = new FileMapperOptions();
28+
mapperOptions.setObjectOwner("APP");
2929
mapperOptions.setTypeMappings(typeMappings);
3030
mapperOptions.setRegexPattern("\\w+[\\\\\\/](\\w+)[\\\\\\/](\\w+)[\\\\\\/](\\w+)[.](\\w{3})");
3131
mapperOptions.setOwnerSubExpression(1);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy