Skip to content

Commit aab76c9

Browse files
committed
Add file mapping support to TestRunner
1 parent d8da220 commit aab76c9

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-
public static Array buildFileMappingArray(Connection conn, FileMapperOptions mapperOptions) throws SQLException {
22+
public static Array buildFileMappingArray(
23+
Connection conn, List<String> filePaths, FileMapperOptions mapperOptions) throws SQLException {
2324
OracleConnection oraConn = conn.unwrap(OracleConnection.class);
2425

2526
Map typeMap = 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
return callableStatement.getArray(1);
5758
}
5859

59-
public static List<FileMapping> buildFileMappingList(Connection conn, FileMapperOptions mapperOptions) throws SQLException {
60-
java.sql.Array fileMappings = buildFileMappingArray(conn, mapperOptions);
60+
public static List<FileMapping> buildFileMappingList(
61+
Connection conn, List<String> filePaths, FileMapperOptions mapperOptions) throws SQLException {
62+
java.sql.Array fileMappings = buildFileMappingArray(conn, filePaths, mapperOptions);
6163

6264
List<FileMapping> mappingList = new ArrayList<>();
6365
for (Object obj : (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
public class FileMapperOptions {
77

88
private String owner;
9-
private List<String> filePaths;
109
private List<KeyValuePair> typeMappings;
1110
private String regexPattern;
1211
private int ownerSubExpression;
1312
private int typeSubExpression;
1413
private int nameSubExpression;
1514

16-
public FileMapperOptions() {
17-
this.filePaths = new ArrayList<>();
15+
public FileMapperOptions(List<String> filePaths) {
1816
this.typeMappings = new ArrayList<>();
1917
}
2018

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

29-
public List<String> getFilePaths() {
30-
return filePaths;
31-
}
32-
33-
public void setFilePaths(List<String> filePaths) {
34-
this.filePaths = filePaths;
35-
}
36-
3727
public List<KeyValuePair> getTypeMappings() {
3828
return typeMappings;
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
private List<String> testFiles = new ArrayList<>();
2323
private List<String> includeObjects = new ArrayList<>();
2424
private List<String> excludeObjects = new ArrayList<>();
25+
private FileMapperOptions sourceMappingOptions;
26+
private FileMapperOptions testMappingOptions;
2527
private boolean failOnErrors = false;
2628

2729
public TestRunner addPath(String path) {
@@ -74,6 +76,16 @@ public TestRunner excludeObject(String obj) {
7476
return this;
7577
}
7678

79+
public TestRunner sourceMappingOptions(FileMapperOptions mapperOptions) {
80+
this.sourceMappingOptions = mapperOptions;
81+
return this;
82+
}
83+
84+
public TestRunner testMappingOptions(FileMapperOptions mapperOptions) {
85+
this.testMappingOptions = mapperOptions;
86+
return this;
87+
}
88+
7789
public TestRunner failOnErrors(boolean failOnErrors) {
7890
this.failOnErrors = failOnErrors;
7991
return this;
@@ -95,21 +107,29 @@ public void run(Connection conn) throws SomeTestsFailedException, SQLException {
95107
String colorConsoleStr = Boolean.toString(this.colorConsole);
96108
String failOnErrors = Boolean.toString(this.failOnErrors);
97109

110+
String sourceFilesParam = "a_source_files";
111+
if (this.sourceMappingOptions != null && !this.sourceFiles.isEmpty())
112+
sourceFilesParam = "a_source_file_mappings";
113+
114+
String testFilesParam = "a_test_files";
115+
if (this.testMappingOptions != null && !this.testFiles.isEmpty())
116+
sourceFilesParam = "a_test_file_mappings";
117+
98118
OracleConnection oraConn = conn.unwrap(OracleConnection.class);
99119
CallableStatement callableStatement = 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
int paramIdx = 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+
} 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));
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+
} 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));
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(new KeyValuePair("procedures", "PROCEDURE"));
2121
typeMappings.add(new KeyValuePair("functions", "FUNCTION"));
2222

23-
FileMapperOptions mapperOptions = new FileMapperOptions();
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+
FileMapperOptions mapperOptions = new FileMapperOptions(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)