Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1b9e0b2

Browse files
committed
Add tests for all utPLSQL versions
1 parent 32b7d56 commit 1b9e0b2

File tree

2 files changed

+207
-39
lines changed

2 files changed

+207
-39
lines changed

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

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

33
import oracle.jdbc.OracleConnection;
44
import org.utplsql.api.CustomTypes;
5-
import org.utplsql.api.FileMapping;
65
import org.utplsql.api.TestRunnerOptions;
76
import org.utplsql.api.Version;
7+
import org.utplsql.api.compatibility.OptionalFeatures;
88
import org.utplsql.api.db.DynamicParameterList;
99

1010
import java.sql.CallableStatement;
11-
import java.sql.Connection;
1211
import java.sql.SQLException;
13-
import java.util.List;
1412

1513
public class DynamicTestRunnerStatement implements TestRunnerStatement {
1614

@@ -40,21 +38,31 @@ private DynamicParameterList initParameterList() throws SQLException {
4038
?FileMapper.buildFileMappingList(oracleConnection, options.testMappingOptions).toArray()
4139
:null;
4240

43-
return DynamicParameterList.builder()
41+
DynamicParameterList.DynamicParameterListBuilder builder = DynamicParameterList.builder()
4442
.addIfNotEmpty("a_paths", options.pathList.toArray(), CustomTypes.UT_VARCHAR2_LIST, oracleConnection)
4543
.addIfNotEmpty("a_reporters", options.reporterList.toArray(), CustomTypes.UT_REPORTERS, oracleConnection)
4644
.addIfNotEmpty("a_color_console", options.colorConsole)
4745
.addIfNotEmpty("a_coverage_schemes", options.coverageSchemes.toArray(), CustomTypes.UT_VARCHAR2_LIST, oracleConnection)
4846
.addIfNotEmpty("a_source_file_mappings", sourceMappings, CustomTypes.UT_FILE_MAPPINGS, oracleConnection)
4947
.addIfNotEmpty("a_test_file_mappings", testMappings, CustomTypes.UT_FILE_MAPPINGS, oracleConnection)
5048
.addIfNotEmpty("a_include_objects", options.includeObjects.toArray(), CustomTypes.UT_VARCHAR2_LIST, oracleConnection)
51-
.addIfNotEmpty("a_exclude_objects", options.excludeObjects.toArray(), CustomTypes.UT_VARCHAR2_LIST, oracleConnection)
52-
.addIfNotEmpty("a_fail_on_errors", options.failOnErrors)
53-
.addIfNotEmpty("a_client_character_set", options.clientCharacterSet)
54-
.addIfNotEmpty("a_random_test_order", options.randomTestOrder)
55-
.addIfNotEmpty("a_random_test_order_seed", options.randomTestOrderSeed)
56-
.addIfNotEmpty("a_tags", options.getTagsAsString())
57-
.build();
49+
.addIfNotEmpty("a_exclude_objects", options.excludeObjects.toArray(), CustomTypes.UT_VARCHAR2_LIST, oracleConnection);
50+
51+
if (OptionalFeatures.FAIL_ON_ERROR.isAvailableFor(utPlSQlVersion)) {
52+
builder.addIfNotEmpty("a_fail_on_errors", options.failOnErrors);
53+
}
54+
if (OptionalFeatures.CLIENT_CHARACTER_SET.isAvailableFor(utPlSQlVersion)) {
55+
builder.addIfNotEmpty("a_client_character_set", options.clientCharacterSet);
56+
}
57+
if (OptionalFeatures.RANDOM_EXECUTION_ORDER.isAvailableFor(utPlSQlVersion)) {
58+
builder.addIfNotEmpty("a_random_test_order", options.randomTestOrder)
59+
.addIfNotEmpty("a_random_test_order_seed", options.randomTestOrderSeed);
60+
}
61+
if (OptionalFeatures.TAGS.isAvailableFor(utPlSQlVersion)) {
62+
builder.addIfNotEmpty("a_tags", options.getTagsAsString());
63+
}
64+
65+
return builder.build();
5866
}
5967

6068
private void prepareStatement() throws SQLException {
Lines changed: 188 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package org.utplsql.api.testRunner;
22

33
import oracle.jdbc.OracleConnection;
4+
import org.hamcrest.Matcher;
5+
import org.junit.jupiter.api.BeforeEach;
46
import org.junit.jupiter.api.Test;
7+
import org.mockito.verification.VerificationMode;
58
import org.utplsql.api.CustomTypes;
69
import org.utplsql.api.FileMapping;
710
import org.utplsql.api.TestRunnerOptions;
@@ -13,41 +16,58 @@
1316

1417
import static org.hamcrest.CoreMatchers.containsString;
1518
import static org.hamcrest.MatcherAssert.assertThat;
19+
import static org.hamcrest.Matchers.not;
1620
import static org.mockito.Mockito.*;
1721

1822
public class DynamicTestRunnerStatementTest {
1923

20-
@Test
21-
void explore() throws SQLException {
22-
// Expectation objects
23-
Object[] expectedFileMapping = new Object[]{new FileMapping("someFile", "owner", "object", "PACKAGE")};
24+
private DynamicTestRunnerStatement testRunnerStatement;
25+
private CallableStatement callableStatement;
26+
private OracleConnection oracleConnection;
27+
private TestRunnerOptions options;
28+
private Object[] expectedFileMapping;
2429

25-
// Mock some internals. This is not pretty, but a first step
30+
private OracleConnection getMockedOracleConnection( Object[] expectedFileMapping ) throws SQLException {
2631
OracleConnection oracleConnection = mock(OracleConnection.class);
2732
when(oracleConnection.unwrap(OracleConnection.class))
2833
.thenReturn(oracleConnection);
29-
CallableStatement callableStatement = mock(CallableStatement.class);
34+
mockFileMapper(oracleConnection, expectedFileMapping);
35+
return oracleConnection;
36+
}
3037

31-
// FileMapper mocks
38+
private void mockFileMapper( OracleConnection mockedOracleConnection, Object[] expectedFileMapping ) throws SQLException {
39+
Array fileMapperArray = mock(Array.class);
3240
CallableStatement fileMapperStatement = mock(CallableStatement.class);
41+
42+
when(fileMapperArray.getArray())
43+
.thenReturn(expectedFileMapping);
44+
when(fileMapperStatement.getArray(1))
45+
.thenReturn(fileMapperArray);
3346
when(
34-
oracleConnection.prepareCall(argThat(
47+
mockedOracleConnection.prepareCall(argThat(
3548
a -> a.startsWith("BEGIN ? := ut_file_mapper.build_file_mappings("))
3649
))
3750
.thenReturn(fileMapperStatement);
38-
Array fileMapperArray = mock(Array.class);
39-
when(fileMapperStatement.getArray(1))
40-
.thenReturn(fileMapperArray);
41-
when(fileMapperArray.getArray())
42-
.thenReturn(expectedFileMapping);
51+
}
4352

44-
// Act
45-
TestRunnerOptions options = TestRunnerStatementProviderIT.getCompletelyFilledOptions();
53+
private Matcher<String> doesOrDoesNotContainString( String string, boolean shouldBeThere ) {
54+
return (shouldBeThere)
55+
? containsString(string)
56+
: not(containsString(string));
57+
}
4658

47-
DynamicTestRunnerStatement testRunnerStatement = DynamicTestRunnerStatement
48-
.forVersion(Version.V3_1_7, oracleConnection, options, callableStatement);
59+
private VerificationMode doesOrDoesNotGetCalled( boolean shouldBeThere ) {
60+
return (shouldBeThere)
61+
? times(1)
62+
: never();
63+
}
4964

50-
// Assert all parameters are set appropriately
65+
private void initTestRunnerStatementForVersion( Version version ) throws SQLException {
66+
testRunnerStatement = DynamicTestRunnerStatement
67+
.forVersion(version, oracleConnection, options, callableStatement);
68+
}
69+
70+
private void checkBaseParameters() throws SQLException {
5171
assertThat(testRunnerStatement.getSql(), containsString("a_paths => ?"));
5272
verify(callableStatement).setArray(1, null);
5373
verify(oracleConnection).createOracleArray(CustomTypes.UT_VARCHAR2_LIST, options.pathList.toArray());
@@ -77,20 +97,160 @@ void explore() throws SQLException {
7797
assertThat(testRunnerStatement.getSql(), containsString("a_exclude_objects => ?"));
7898
verify(callableStatement).setArray(8, null);
7999
verify(oracleConnection).createOracleArray(CustomTypes.UT_VARCHAR2_LIST, options.includeObjects.toArray());
100+
}
101+
102+
private void checkFailOnError( boolean shouldBeThere ) throws SQLException {
103+
assertThat(testRunnerStatement.getSql(), doesOrDoesNotContainString("a_fail_on_errors => (case ? when 1 then true else false)", shouldBeThere));
104+
verify(callableStatement, doesOrDoesNotGetCalled(shouldBeThere)).setInt(9, 1);
105+
}
106+
107+
private void checkClientCharacterSet( boolean shouldBeThere ) throws SQLException {
108+
assertThat(testRunnerStatement.getSql(), doesOrDoesNotContainString("a_client_character_set => ?", shouldBeThere));
109+
verify(callableStatement, doesOrDoesNotGetCalled(shouldBeThere)).setString(10, "UTF8");
110+
}
111+
112+
private void checkRandomTestOrder( boolean shouldBeThere ) throws SQLException {
113+
assertThat(testRunnerStatement.getSql(), doesOrDoesNotContainString("a_random_test_order => (case ? when 1 then true else false)", shouldBeThere));
114+
verify(callableStatement, doesOrDoesNotGetCalled(shouldBeThere)).setInt(11, 1);
115+
assertThat(testRunnerStatement.getSql(), doesOrDoesNotContainString("a_random_test_order_seed => ?", shouldBeThere));
116+
verify(callableStatement, doesOrDoesNotGetCalled(shouldBeThere)).setInt(12, 123);
117+
}
118+
119+
private void checkTags( boolean shouldBeThere ) throws SQLException {
120+
assertThat(testRunnerStatement.getSql(), doesOrDoesNotContainString("a_tags => ?", shouldBeThere));
121+
verify(callableStatement, doesOrDoesNotGetCalled(shouldBeThere)).setString(13, "WIP,long_running");
122+
}
80123

81-
assertThat(testRunnerStatement.getSql(), containsString("a_fail_on_errors => (case ? when 1 then true else false)"));
82-
verify(callableStatement).setInt(9, 1);
124+
@BeforeEach
125+
void initParameters() throws SQLException {
126+
expectedFileMapping = new Object[]{new FileMapping("someFile", "owner", "object", "PACKAGE")};
83127

84-
assertThat(testRunnerStatement.getSql(), containsString("a_client_character_set => ?"));
85-
verify(callableStatement).setString(10, "UTF8");
128+
// Mock some internals. This is not pretty, but a first step
129+
oracleConnection = getMockedOracleConnection(expectedFileMapping);
130+
callableStatement = mock(CallableStatement.class);
86131

87-
assertThat(testRunnerStatement.getSql(), containsString("a_random_test_order => (case ? when 1 then true else false)"));
88-
verify(callableStatement).setInt(11, 1);
132+
// Act
133+
options = TestRunnerStatementProviderIT.getCompletelyFilledOptions();
134+
}
89135

90-
assertThat(testRunnerStatement.getSql(), containsString("a_random_test_order_seed => ?"));
91-
verify(callableStatement).setInt(12, 123);
136+
@Test
137+
void version_3_0_2_parameters() throws SQLException {
138+
initTestRunnerStatementForVersion(Version.V3_0_2);
139+
140+
checkBaseParameters();
141+
checkFailOnError(false);
142+
checkClientCharacterSet(false);
143+
checkRandomTestOrder(false);
144+
checkTags(false);
145+
}
146+
147+
@Test
148+
void version_3_0_3_parameters() throws SQLException {
149+
initTestRunnerStatementForVersion(Version.V3_0_3);
150+
151+
checkBaseParameters();
152+
checkFailOnError(true);
153+
checkClientCharacterSet(false);
154+
checkRandomTestOrder(false);
155+
checkTags(false);
156+
}
157+
158+
@Test
159+
void version_3_0_4_parameters() throws SQLException {
160+
initTestRunnerStatementForVersion(Version.V3_0_4);
161+
162+
checkBaseParameters();
163+
checkFailOnError(true);
164+
checkClientCharacterSet(false);
165+
checkRandomTestOrder(false);
166+
checkTags(false);
167+
}
168+
169+
@Test
170+
void version_3_1_0_parameters() throws SQLException {
171+
initTestRunnerStatementForVersion(Version.V3_1_0);
172+
173+
checkBaseParameters();
174+
checkFailOnError(true);
175+
checkClientCharacterSet(false);
176+
checkRandomTestOrder(false);
177+
checkTags(false);
178+
}
179+
180+
@Test
181+
void version_3_1_1_parameters() throws SQLException {
182+
initTestRunnerStatementForVersion(Version.V3_1_1);
183+
184+
checkBaseParameters();
185+
checkFailOnError(true);
186+
checkClientCharacterSet(false);
187+
checkRandomTestOrder(false);
188+
checkTags(false);
189+
}
190+
191+
@Test
192+
void version_3_1_2_parameters() throws SQLException {
193+
initTestRunnerStatementForVersion(Version.V3_1_2);
194+
195+
checkBaseParameters();
196+
checkFailOnError(true);
197+
checkClientCharacterSet(true);
198+
checkRandomTestOrder(false);
199+
checkTags(false);
200+
}
201+
202+
@Test
203+
void version_3_1_3_parameters() throws SQLException {
204+
initTestRunnerStatementForVersion(Version.V3_1_3);
205+
206+
checkBaseParameters();
207+
checkFailOnError(true);
208+
checkClientCharacterSet(true);
209+
checkRandomTestOrder(false);
210+
checkTags(false);
211+
}
212+
213+
@Test
214+
void version_3_1_4_parameters() throws SQLException {
215+
initTestRunnerStatementForVersion(Version.V3_1_4);
216+
217+
checkBaseParameters();
218+
checkFailOnError(true);
219+
checkClientCharacterSet(true);
220+
checkRandomTestOrder(false);
221+
checkTags(false);
222+
}
223+
224+
@Test
225+
void version_3_1_5_parameters() throws SQLException {
226+
initTestRunnerStatementForVersion(Version.V3_1_5);
227+
228+
checkBaseParameters();
229+
checkFailOnError(true);
230+
checkClientCharacterSet(true);
231+
checkRandomTestOrder(false);
232+
checkTags(false);
233+
}
234+
235+
@Test
236+
void version_3_1_6_parameters() throws SQLException {
237+
initTestRunnerStatementForVersion(Version.V3_1_6);
238+
239+
checkBaseParameters();
240+
checkFailOnError(true);
241+
checkClientCharacterSet(true);
242+
checkRandomTestOrder(false);
243+
checkTags(false);
244+
}
245+
246+
@Test
247+
void version_3_1_7_parameters() throws SQLException {
248+
initTestRunnerStatementForVersion(Version.V3_1_7);
92249

93-
assertThat(testRunnerStatement.getSql(), containsString("a_tags => ?"));
94-
verify(callableStatement).setString(13, "WIP,long_running");
250+
checkBaseParameters();
251+
checkFailOnError(true);
252+
checkClientCharacterSet(true);
253+
checkRandomTestOrder(true);
254+
checkTags(true);
95255
}
96256
}

0 commit comments

Comments
 (0)