Skip to content

Commit 8fb3072

Browse files
committed
New Optional Feature RANDOM_EXECUTION_ORDER
Also new TestRunnerStatement and TestRunnerOptions
1 parent e6625e3 commit 8fb3072

File tree

10 files changed

+108
-5
lines changed

10 files changed

+108
-5
lines changed

src/main/java/org/utplsql/api/TestRunner.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,17 @@ public TestRunner setReporterFactory(ReporterFactory reporterFactory) {
118118
return this;
119119
}
120120

121+
public TestRunner randomTestOrder(boolean randomTestOrder ) {
122+
this.options.randomTestOrder = randomTestOrder;
123+
return this;
124+
}
125+
126+
public TestRunner randomTestOrderSeed( Integer seed ) {
127+
this.options.randomTestOrderSeed = seed;
128+
if ( seed != null ) this.options.randomTestOrder = true;
129+
return this;
130+
}
131+
121132
private void delayedAddReporters() {
122133
if (reporterFactory != null) {
123134
reporterNames.forEach(this::addReporter);

src/main/java/org/utplsql/api/TestRunnerOptions.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ public class TestRunnerOptions {
2525
public boolean failOnErrors = false;
2626
public boolean skipCompatibilityCheck = false;
2727
public String clientCharacterSet = Charset.defaultCharset().toString();
28+
public boolean randomTestOrder = false;
29+
public Integer randomTestOrderSeed;
2830
}

src/main/java/org/utplsql/api/Version.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ public class Version implements Comparable<Version> {
3131
public final static Version V3_1_4 = new Version("3.1.4", 3, 1, 4, null, true);
3232
public final static Version V3_1_5 = new Version("3.1.5", 3, 1, 5, null, true);
3333
public final static Version V3_1_6 = new Version("3.1.6", 3, 1, 6, null, true);
34+
public final static Version V3_1_7 = new Version("3.1.7", 3, 1, 7, null, true);
3435
private final static Map<String, Version> knownVersions =
35-
Stream.of(V3_0_0, V3_0_1, V3_0_2, V3_0_3, V3_0_4, V3_1_0, V3_1_1, V3_1_2, V3_1_3, V3_1_4, V3_1_5, V3_1_6)
36+
Stream.of(V3_0_0, V3_0_1, V3_0_2, V3_0_3, V3_0_4, V3_1_0, V3_1_1, V3_1_2, V3_1_3, V3_1_4, V3_1_5, V3_1_6, V3_1_7)
3637
.collect(toMap(Version::toString, Function.identity()));
37-
public final static Version LATEST = V3_1_6;
38+
public final static Version LATEST = V3_1_7;
3839

3940
private final String origString;
4041
private final Integer major;

src/main/java/org/utplsql/api/compatibility/OptionalFeatures.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ public enum OptionalFeatures {
1111
FAIL_ON_ERROR("3.0.3.1266", null),
1212
FRAMEWORK_COMPATIBILITY_CHECK("3.0.3.1266", null),
1313
CUSTOM_REPORTERS("3.1.0.1849", null),
14-
CLIENT_CHARACTER_SET("3.1.2.2130", null);
14+
CLIENT_CHARACTER_SET("3.1.2.2130", null),
15+
RANDOM_EXECUTION_ORDER("3.1.7.2795", null);
1516

1617
private final Version minVersion;
1718
private final Version maxVersion;

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ protected String getSql() {
2222
// Workaround because Oracle JDBC doesn't support passing boolean to stored procedures.
2323
String colorConsoleStr = Boolean.toString(options.colorConsole);
2424
String failOnErrors = Boolean.toString(options.failOnErrors);
25+
String randomExecutionOrder = Boolean.toString(options.randomTestOrder);
2526

2627
return
2728
"BEGIN " +
@@ -35,7 +36,9 @@ protected String getSql() {
3536
"a_include_objects => ?, " +
3637
"a_exclude_objects => ?, " +
3738
"a_fail_on_errors => " + failOnErrors + ", " +
38-
"a_client_character_set => ?); " +
39+
"a_client_character_set => ?" +
40+
//(options.randomTestOrderSeed != null ) ?
41+
"); " +
3942
"END;";
4043
}
4144

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package org.utplsql.api.testRunner;
2+
3+
import org.utplsql.api.TestRunnerOptions;
4+
5+
import java.sql.Connection;
6+
import java.sql.SQLException;
7+
8+
/**
9+
* Provides the call to run tests for the most actual Framework version.
10+
* Includes fail on error
11+
*
12+
* @author pesse
13+
*/
14+
class Pre317TestRunnerStatement extends AbstractTestRunnerStatement {
15+
16+
public Pre317TestRunnerStatement(TestRunnerOptions options, Connection connection) throws SQLException {
17+
super(options, connection);
18+
}
19+
20+
@Override
21+
protected String getSql() {
22+
// Workaround because Oracle JDBC doesn't support passing boolean to stored procedures.
23+
String colorConsoleStr = Boolean.toString(options.colorConsole);
24+
String failOnErrors = Boolean.toString(options.failOnErrors);
25+
26+
return
27+
"BEGIN " +
28+
"ut_runner.run(" +
29+
"a_paths => ?, " +
30+
"a_reporters => ?, " +
31+
"a_color_console => " + colorConsoleStr + ", " +
32+
"a_coverage_schemes => ?, " +
33+
"a_source_file_mappings => ?, " +
34+
"a_test_file_mappings => ?, " +
35+
"a_include_objects => ?, " +
36+
"a_exclude_objects => ?, " +
37+
"a_fail_on_errors => " + failOnErrors + ", " +
38+
"a_client_character_set => ?); " +
39+
"END;";
40+
}
41+
42+
@Override
43+
protected int createStatement() throws SQLException {
44+
int curParamIdx = super.createStatement();
45+
46+
callableStatement.setString(++curParamIdx, options.clientCharacterSet);
47+
48+
return curParamIdx;
49+
}
50+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public static TestRunnerStatement getCompatibleTestRunnerStatement(Version datab
3535
stmt = new Pre303TestRunnerStatement(options, conn);
3636
} else if (databaseVersion.isLessThan(Version.V3_1_2)) {
3737
stmt = new Pre312TestRunnerStatement(options, conn);
38+
} else if (databaseVersion.isLessThan(Version.V3_1_7)) {
39+
stmt = new Pre317TestRunnerStatement(options, conn);
3840
}
3941

4042
} catch (InvalidVersionException ignored) {

src/test/java/org/utplsql/api/OptionalFeaturesIT.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,15 @@ void clientCharset() throws SQLException, InvalidVersionException {
6464
assertFalse(available);
6565
}
6666
}
67+
68+
@Test
69+
void randomExecutionOrder() throws SQLException, InvalidVersionException {
70+
boolean available = OptionalFeatures.RANDOM_EXECUTION_ORDER.isAvailableFor(getConnection());
71+
72+
if (getDatabaseVersion().isGreaterOrEqualThan(Version.V3_1_7)) {
73+
assertTrue(available);
74+
} else {
75+
assertFalse(available);
76+
}
77+
}
6778
}

src/test/java/org/utplsql/api/TestRunnerIT.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,14 @@ void failOnErrors() throws SQLException, InvalidVersionException {
7878
}
7979
}
8080

81+
@Test
82+
void runWithRandomExecutionOrder() throws SQLException {
83+
CompatibilityProxy proxy = new CompatibilityProxy(getConnection());
84+
85+
new TestRunner()
86+
.randomTestOrder(true)
87+
.randomTestOrderSeed(123)
88+
.run(getConnection());
89+
}
90+
8191
}

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,20 @@ void testGettingPre312Version_from_311() throws SQLException {
3131
}
3232

3333
@Test
34-
void testGettingActualVersion() throws SQLException {
34+
void testGettingPre317Version_from_312() throws SQLException {
3535
TestRunnerStatement stmt = TestRunnerStatementProvider.getCompatibleTestRunnerStatement(Version.V3_1_2, new TestRunnerOptions(), getConnection());
36+
assertEquals(Pre317TestRunnerStatement.class, stmt.getClass());
37+
}
38+
39+
@Test
40+
void testGettingPre317Version_from_316() throws SQLException {
41+
TestRunnerStatement stmt = TestRunnerStatementProvider.getCompatibleTestRunnerStatement(Version.V3_1_6, new TestRunnerOptions(), getConnection());
42+
assertEquals(Pre317TestRunnerStatement.class, stmt.getClass());
43+
}
44+
45+
@Test
46+
void testGettingActualVersion_from_latest() throws SQLException {
47+
TestRunnerStatement stmt = TestRunnerStatementProvider.getCompatibleTestRunnerStatement(Version.LATEST, new TestRunnerOptions(), getConnection());
3648
assertEquals(ActualTestRunnerStatement.class, stmt.getClass());
3749
}
3850
}

0 commit comments

Comments
 (0)