8000 Slow approach towards new DynamicTestRunner-Statement · utPLSQL/utPLSQL-java-api@6100f3c · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 6100f3c

Browse files
committed
Slow approach towards new DynamicTestRunner-Statement
1 parent 2ce1e79 commit 6100f3c

File tree

2 files changed

+84
-10
lines changed

2 files changed

+84
-10
lines changed
Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,85 @@
11
package org.utplsql.api.testRunner;
22

3+
import oracle.jdbc.OracleConnection;
4+
import org.utplsql.api.CustomTypes;
5+
import org.utplsql.api.TestRunnerOptions;
36
import org.utplsql.api.Version;
7+
import org.utplsql.api.db.DynamicParameterList;
48

59
import java.sql.CallableStatement;
610
import java.sql.Connection;
711
import java.sql.SQLException;
812

913
public class DynamicTestRunnerStatement implements TestRunnerStatement {
1014

11-
private CallableStatement callableStatement;
12-
private final Connection connection;
15+
private CallableStatement stmt;
16+
private final OracleConnection oracleConnection;
1317
private final Version utPlSQlVersion;
18+
private final TestRunnerOptions options;
19+
private final DynamicParameterList dynamicParameterList;
1420

15-
private DynamicTestRunnerStatement( Version utPlSQlVersion, Connection connection ) {
21+
private DynamicTestRunnerStatement( Version utPlSQlVersion, OracleConnection connection, TestRunnerOptions options, CallableStatement statement ) throws SQLException {
1622
this.utPlSQlVersion = utPlSQlVersion;
17-
this.connection = connection;
23+
this.oracleConnection = connection;
24+
this.options = options;
25+
this.stmt = statement;
26+
27+
this.dynamicParameterList = initParameterList();
28+
29+
prepareStatement();
30+
}
31+
32+
private DynamicParameterList initParameterList() throws SQLException {
33+
/*
34+
"BEGIN " +
35+
"ut_runner.run(" +
36+
"a_paths => ?, " +
37+
"a_reporters => ?, " +
38+
"a_color_console => " + colorConsoleStr + ", " +
39+
"a_coverage_schemes => ?, " +
40+
"a_source_file_mappings => ?, " +
41+
"a_test_file_mappings => ?, " +
42+
"a_include_objects => ?, " +
43+
"a_exclude_objects => ?, " +
44+
"a_fail_on_errors => " + failOnErrors + ", " +
45+
"a_client_character_set => ?, " +
46+
"a_random_test_order => " + randomExecutionOrder + ", " +
47+
"a_random_test_order_seed => ?, "+
48+
"a_tags => ?"+
49+
"); " +
50+
"END;";
51+
*/
52+
return DynamicParameterList.builder()
53+
.addIfNotEmpty("a_paths", options.pathList.toArray(), CustomTypes.UT_VARCHAR2_LIST, oracleConnection)
54+
.build();
55+
}
56+
57+
private void prepareStatement() throws SQLException {
58+
if ( stmt == null )
59+
oracleConnection.prepareCall(dynamicParameterList.getSql());
60+
61+
dynamicParameterList.setParamsStartWithIndex(stmt, 1);
1862
}
1963

2064
@Override
2165
public void execute() throws SQLException {
66+
2267
// Implement
2368
}
2469

70+
@Override
71+
public String getSql() {
72+
return dynamicParameterList.getSql();
73+
}
74+
2575
@Override
2676
public void close() throws SQLException {
27-
if (callableStatement != null) {
28-
callableStatement.close();
77+
if (stmt != null) {
78+
stmt.close();
2979
}
3080
}
3181

32-
public static DynamicTestRunnerStatement forVersion(Version version, Connection connection) {
33-
return new DynamicTestRunnerStatement(version, connection);
82+
public static DynamicTestRunnerStatement forVersion(Version version, OracleConnection connection, TestRunnerOptions options, CallableStatement statement ) throws SQLException {
83+
return new DynamicTestRunnerStatement(version, connection, options, statement);
3484
}
3585
}
Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,36 @@
11
package org.utplsql.api.testRunner;
22

3+
import oracle.jdbc.OracleConnection;
34
import org.junit.jupiter.api.Test;
5+
import org.utplsql.api.CustomTypes;
6+
import org.utplsql.api.TestRunnerOptions;
47
import org.utplsql.api.Version;
58

9+
import java.sql.CallableStatement;
10+
import java.sql.SQLException;
11+
import java.util.concurr 6D40 ent.Callable;
12+
13+
import static org.hamcrest.CoreMatchers.containsString;
14+
import static org.hamcrest.MatcherAssert.assertThat;
15+
import static org.mockito.Mockito.mock;
16+
import static org.mockito.Mockito.verify;
17+
618
public class DynamicTestRunnerStatementTest {
719

820
@Test
9-
void explore() {
10-
DynamicTestRunnerStatement testRunnerStatement = DynamicTestRunnerStatement.forVersion(Version.V3_1_7, null);
21+
void explore() throws SQLException {
22+
23+
OracleConnection oracleConnection = mock(OracleConnection.class);
24+
CallableStatement callableStatement = mock(CallableStatement.class);
25+
26+
TestRunnerOptions options = TestRunnerStatementProviderIT.getCompletelyFilledOptions();
27+
28+
DynamicTestRunnerStatement te 5FA1 stRunnerStatement = DynamicTestRunnerStatement
29+
.forVersion(Version.V3_1_7, oracleConnection, options, callableStatement);
30+
31+
assertThat(testRunnerStatement.getSql(), containsString("a_paths => ?"));
32+
33+
verify(callableStatement).setArray(1, null);
34+
verify(oracleConnection).createOracleArray(CustomTypes.UT_VARCHAR2_LIST, options.pathList.toArray());
1135
}
1236
}

0 commit comments

Comments
 (0)
0