|
3 | 3 | import oracle.jdbc.OracleConnection;
|
4 | 4 | import org.junit.jupiter.api.Test;
|
5 | 5 | import org.utplsql.api.CustomTypes;
|
| 6 | +import org.utplsql.api.FileMapping; |
6 | 7 | import org.utplsql.api.TestRunnerOptions;
|
7 | 8 | import org.utplsql.api.Version;
|
8 | 9 |
|
| 10 | +import java.sql.Array; |
9 | 11 | import java.sql.CallableStatement;
|
10 | 12 | import java.sql.SQLException;
|
| 13 | +import java.util.List; |
11 | 14 | import java.util.concurrent.Callable;
|
12 | 15 |
|
13 | 16 | import static org.hamcrest.CoreMatchers.containsString;
|
14 | 17 | 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.*; |
17 | 19 |
|
18 | 20 | public class DynamicTestRunnerStatementTest {
|
19 | 21 |
|
20 | 22 | @Test
|
21 | 23 | 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")}; |
22 | 27 |
|
| 28 | + // Mock some internals. This is not pretty, but a first step |
23 | 29 | OracleConnection oracleConnection = mock(OracleConnection.class);
|
| 30 | + when(oracleConnection.unwrap(OracleConnection.class)) |
| 31 | + .thenReturn(oracleConnection); |
24 | 32 | CallableStatement callableStatement = mock(CallableStatement.class);
|
25 | 33 |
|
| 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 |
26 | 48 | TestRunnerOptions options = TestRunnerStatementProviderIT.getCompletelyFilledOptions();
|
27 | 49 |
|
28 | 50 | DynamicTestRunnerStatement testRunnerStatement = DynamicTestRunnerStatement
|
@@ -61,6 +83,10 @@ void explore() throws SQLException {
|
61 | 83 | verify(callableStatement).setArray(4, null);
|
62 | 84 | verify(oracleConnection).createOracleArray(CustomTypes.UT_VARCHAR2_LIST, options.coverageSchemes.toArray());
|
63 | 85 |
|
| 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 | + |
64 | 90 |
|
65 | 91 | }
|
66 | 92 | }
|
0 commit comments