10000 FileMappings are more complicated to pass around · utPLSQL/utPLSQL-java-api@5ff0ee2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5ff0ee2

Browse files
committed
FileMappings are more complicated to pass around
Needed some ugly mocking, probably something to refactor in future
1 parent f2e1e01 commit 5ff0ee2

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

src/main/java/org/utplsql/api/db/DynamicParameterList.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ public void setParam(CallableStatement statement, int index) throws SQLException
210210
statement.setNull(index, Types.ARRAY, customTypeName);
211211
} else {
212212
statement.setArray(
213-
index, oraConnection.createOracleArray(customTypeName, value)
213+
index,
214+
oraConnection.createOracleArray(customTypeName, value)
214215
);
215216
}
216217
}

src/main/java/org/utplsql/api/testRunner/DynamicTestRunnerStatement.java

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

33
import oracle.jdbc.OracleConnection;
44
import org.utplsql.api.CustomTypes;
5+
import org.utplsql.api.FileMapping;
56
import org.utplsql.api.TestRunnerOptions;
67
import org.utplsql.api.Version;
78
import org.utplsql.api.db.DynamicParameterList;
89

910
import java.sql.CallableStatement;
1011
import java.sql.Connection;
1112
import java.sql.SQLException;
13+
import java.util.List;
1214

1315
public class DynamicTestRunnerStatement implements TestRunnerStatement {
1416

@@ -49,11 +51,16 @@ private DynamicParameterList initParameterList() throws SQLException {
4951
"); " +
5052
"END;";
5153
*/
54+
55+
Object[] sourceMappings = (options.sourceMappingOptions!=null)
56+
?FileMapper.buildFileMappingList(oracleConnection, options.sourceMappingOptions).toArray()
57+
:null;
5258
return DynamicParameterList.builder()
5359
.addIfNotEmpty("a_paths", options.pathList.toArray(), CustomTypes.UT_VARCHAR2_LIST, oracleConnection)
5460
.addIfNotEmpty("a_reporters", options.reporterList.toArray(), CustomTypes.UT_REPORTERS, oracleConnection)
5561
.addIfNotEmpty("a_color_console", options.colorConsole)
5662
.addIfNotEmpty("a_coverage_schemes", options.coverageSchemes.toArray(), CustomTypes.UT_VARCHAR2_LIST, oracleConnection)
63+
.addIfNotEmpty("a_source_file_mappings", sourceMappings, CustomTypes.UT_FILE_MAPPINGS, oracleConnection)
5764
.build();
5865
}
5966

src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,48 @@
33
import oracle.jdbc.OracleConnection;
44
import org.junit.jupiter.api.Test;
55
import org.utplsql.api.CustomTypes;
6+
import org.utplsql.api.FileMapping;
67
import org.utplsql.api.TestRunnerOptions;
78
import org.utplsql.api.Version;
89

10+
import java.sql.Array;
911
import java.sql.CallableStatement;
1012
import java.sql.SQLException;
13+
import java.util.List;
1114
import java.util.concurrent.Callable;
1215

1316
import static org.hamcrest.CoreMatchers.containsString;
1417
import static org.hamcrest.MatcherAssert.assertThat;
15-
import static org.mockito.Mockito.mock;
16-
import static org.mockito.Mockito.verify;
18+
import static org.mockito.Mockito.*;
1719

1820
public class DynamicTestRunnerStatementTest {
1921

2022
@Test
2123
void explore() throws SQLException {
24+
// Expectation objects
25+
Object[] expectedSourceFileMapping = new Object[]{new FileMapping("source", "owner", "source", "PACKAGE")};
26+
Object[] expectedTestFileMapping = new Object[]{new FileMapping("test", "owner", "test", "PACKAGE")};
2227

28+
// Mock some internals. This is not pretty, but a first step
2329
OracleConnection oracleConnection = mock(OracleConnection.class);
30+
when(oracleConnection.unwrap(OracleConnection.class))
31+
.thenReturn(oracleConnection);
2432
CallableStatement callableStatement = mock(CallableStatement.class);
2533

34+
// FileMapper mocks
35+
CallableStatement fileMapperStatement = mock(CallableStatement.class);
36+
when(
37+
oracleConnection.prepareCall(argThat(
38+
a -> a.startsWith("BEGIN ? := ut_file_mapper.build_file_mappings("))
39+
))
40+
.thenReturn(fileMapperStatement);
41+
Array fileMapperArray = mock(Array.class);
42+
when(fileMapperStatement.getArray(1))
43+
.thenReturn(fileMapperArray);
44+
when(fileMapperArray.getArray())
45+
.thenReturn(expectedSourceFileMapping);
46+
47+
// Act
2648
TestRunnerOptions options = TestRunnerStatementProviderIT.getCompletelyFilledOptions();
2749

2850
DynamicTestRunnerStatement testRunnerStatement = DynamicTestRunnerStatement
@@ -61,6 +83,10 @@ void explore() throws SQLException {
6183
verify(callableStatement).setArray(4, null);
6284
verify(oracleConnection).createOracleArray(CustomTypes.UT_VARCHAR2_LIST, options.coverageSchemes.toArray());
6385

86+
assertThat(testRunnerStatement.getSql(), containsString("a_source_file_mappings => ?"));
87+
verify(callableStatement).setArray(5, null);
88+
verify(oracleConnection).createOracleArray(CustomTypes.UT_FILE_MAPPINGS, expectedSourceFileMapping);
89+
6490

6591
}
6692
}

0 commit comments

Comments
 (0)
0