Skip to content

Commit e6625e3

Browse files
authored
Merge pull request #81 from utPLSQL/feature/update_list_core_reporters
Feature/update list core reporters Fixes utPLSQL/utPLSQL-cli#136
2 parents 2ea07e4 + fd62bdc commit e6625e3

15 files changed

+158
-64
lines changed

RELEASE-CHECKLIST.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# TODO's before releasing a new java-api version
2+
3+
- Update `CoreReporters`
4+
- Update `Version`: knownVersions, LATEST
5+
- Update `build.gradle.kts`: baseVersion

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,12 @@ public void run(Connection conn) throws SQLException {
152152

153153
DatabaseInformation databaseInformation = new DefaultDatabaseInformation();
154154

155-
compatibilityProxy = new CompatibilityProxy(conn, options.skipCompatibilityCheck, databaseInformation);
156-
logger.info("Running on utPLSQL {}", compatibilityProxy.getDatabaseVersion());
155+
if ( options.skipCompatibilityCheck ) {
156+
compatibilityProxy = new CompatibilityProxy(conn, Version.LATEST, databaseInformation);
157+
} else {
158+
compatibilityProxy = new CompatibilityProxy(conn, databaseInformation);
159+
}
160+
logger.info("Running on utPLSQL {}", compatibilityProxy.getVersionDescription());
157161

158162
if (reporterFactory == null) {
159163
reporterFactory = ReporterFactory.createDefault(compatibilityProxy);
@@ -236,7 +240,7 @@ private void validateReporter(Connection conn, Reporter reporter) throws SQLExce
236240
*/
237241
public Version getUsedDatabaseVersion() {
238242
if (compatibilityProxy != null) {
239-
return compatibilityProxy.getDatabaseVersion();
243+
return compatibilityProxy.getUtPlsqlVersion();
240244
} else {
241245
return null;
242246
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,14 @@ public class Version implements Comparable<Version> {
2727
public final static Version V3_1_0 = new Version("3.1.0", 3, 1, 0, null, true);
2828
public final static Version V3_1_1 = new Version("3.1.1", 3, 1, 1, null, true);
2929
public final static Version V3_1_2 = new Version("3.1.2", 3, 1, 2, null, true);
30+
public final static Version V3_1_3 = new Version("3.1.3", 3, 1, 3, null, true);
31+
public final static Version V3_1_4 = new Version("3.1.4", 3, 1, 4, null, true);
32+
public final static Version V3_1_5 = new Version("3.1.5", 3, 1, 5, null, true);
33+
public final static Version V3_1_6 = new Version("3.1.6", 3, 1, 6, null, true);
3034
private final static Map<String, Version> knownVersions =
31-
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)
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)
3236
.collect(toMap(Version::toString, Function.identity()));
37+
public final static Version LATEST = V3_1_6;
3338

3439
private final String origString;
3540
private final Integer major;

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

Lines changed: 49 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.utplsql.api.testRunner.TestRunnerStatement;
1212
import org.utplsql.api.testRunner.TestRunnerStatementProvider;
1313

14+
import javax.annotation.Nullable;
1415
import java.sql.Connection;
1516
import java.sql.SQLException;
1617
import java.util.Objects;
@@ -25,30 +26,42 @@
2526
public class CompatibilityProxy {
2627

2728
public static final String UTPLSQL_COMPATIBILITY_VERSION = "3";
28-
private static final String UTPLSQL_API_VERSION = "3.1.1";
2929
private final DatabaseInformation databaseInformation;
30-
private Version databaseVersion;
30+
private Version utPlsqlVersion;
31+
private Version realDbPlsqlVersion;
3132
private boolean compatible = false;
3233

3334
public CompatibilityProxy(Connection conn) throws SQLException {
34-
this(conn, false, null);
35+
this(conn, null, null);
3536
}
3637

37-
public CompatibilityProxy(Connection conn, DatabaseInformation databaseInformation) throws SQLException {
38-
this(conn, false, databaseInformation);
38+
@Deprecated
39+
public CompatibilityProxy(Connection conn, boolean skipCompatibilityCheck ) throws SQLException {
40+
this(conn, skipCompatibilityCheck, null);
3941
}
4042

41-
public CompatibilityProxy(Connection conn, boolean skipCompatibilityCheck) throws SQLException {
42-
this(conn, skipCompatibilityCheck, null);
43+
@Deprecated
44+
public CompatibilityProxy(Connection conn, boolean skipCompatibilityCheck, @Nullable DatabaseInformation databaseInformation ) throws SQLException {
45+
this(conn, skipCompatibilityCheck ? Version.LATEST : null, databaseInformation);
46+
}
47+
48+
public CompatibilityProxy(Connection conn, @Nullable DatabaseInformation databaseInformation) throws SQLException {
49+
this(conn, null, databaseInformation);
4350
}
4451

45-
public CompatibilityProxy(Connection conn, boolean skipCompatibilityCheck, DatabaseInformation databaseInformation) throws SQLException {
52+
public CompatibilityProxy(Connection conn, @Nullable Version assumedUtPlsVersion) throws SQLException {
53+
this(conn, assumedUtPlsVersion, null);
54+
}
55+
56+
public CompatibilityProxy(Connection conn, @Nullable Version assumedUtPlsqlVersion, @Nullable DatabaseInformation databaseInformation) throws SQLException {
4657
this.databaseInformation = (databaseInformation != null)
4758
? databaseInformation
4859
: new DefaultDatabaseInformation();
4960

50-
if (skipCompatibilityCheck) {
51-
doExpectCompatibility();
61+
realDbPlsqlVersion = this.databaseInformation.getUtPlsqlFrameworkVersion(conn);
62+
if ( assumedUtPlsqlVersion != null ) {
63+
utPlsqlVersion = assumedUtPlsqlVersion;
64+
compatible = utPlsqlVersion.getNormalizedString().startsWith(UTPLSQL_COMPATIBILITY_VERSION);
5265
} else {
5366
doCompatibilityCheckWithDatabase(conn);
5467
}
@@ -62,18 +75,18 @@ public CompatibilityProxy(Connection conn, boolean skipCompatibilityCheck, Datab
6275
* @throws SQLException
6376
*/
6477
private void doCompatibilityCheckWithDatabase(Connection conn) throws SQLException {
65-
databaseVersion = databaseInformation.getUtPlsqlFrameworkVersion(conn);
78+
utPlsqlVersion = realDbPlsqlVersion;
6679
Version clientVersion = Version.create(UTPLSQL_COMPATIBILITY_VERSION);
6780

68-
if (databaseVersion == null) {
81+
if (utPlsqlVersion == null) {
6982
throw new DatabaseNotCompatibleException("Could not get database version", clientVersion, null, null);
7083
}
7184

72-
if (databaseVersion.getMajor() == null) {
73-
throw new DatabaseNotCompatibleException("Illegal database version: " + databaseVersion.toString(), clientVersion, databaseVersion, null);
85+
if (utPlsqlVersion.getMajor() == null) {
86+
throw new DatabaseNotCompatibleException("Illegal database version: " + utPlsqlVersion.toString(), clientVersion, utPlsqlVersion, null);
7487
}
7588

76-
if (OptionalFeatures.FRAMEWORK_COMPATIBILITY_CHECK.isAvailableFor(databaseVersion)) {
89+
if (OptionalFeatures.FRAMEWORK_COMPATIBILITY_CHECK.isAvailableFor(utPlsqlVersion)) {
7790
try {
7891
compatible = versionCompatibilityCheck(conn, UTPLSQL_COMPATIBILITY_VERSION, null);
7992
} catch (SQLException e) {
@@ -84,14 +97,6 @@ private void doCompatibilityCheckWithDatabase(Connection conn) throws SQLExcepti
8497
}
8598
}
8699

87-
/**
88-
* Just prepare the proxy to expect compatibility, expecting the database framework to be the same version as the API
89-
*/
90-
private void doExpectCompatibility() {
91-
databaseVersion = Version.create(UTPLSQL_API_VERSION);
92-
compatible = true;
93-
}
94-
95100
/**
96101
* Check the utPLSQL version compatibility.
97102
*
@@ -121,10 +126,10 @@ private boolean versionCompatibilityCheck(Connection conn, String requested, Str
121126
private boolean versionCompatibilityCheckPre303(String requested) {
122127
Version requestedVersion = Version.create(requested);
123128

124-
Objects.requireNonNull(databaseVersion.getMajor(), "Illegal database Version: " + databaseVersion.toString());
125-
return databaseVersion.getMajor().equals(requestedVersion.getMajor())
129+
Objects.requireNonNull(utPlsqlVersion.getMajor(), "Illegal database Version: " + utPlsqlVersion.toString());
130+
return utPlsqlVersion.getMajor().equals(requestedVersion.getMajor())
126131
&& (requestedVersion.getMinor() == null
127-
|| requestedVersion.getMinor().equals(databaseVersion.getMinor()));
132+
|| requestedVersion.getMinor().equals(utPlsqlVersion.getMinor()));
128133
}
129134

130135
/**
@@ -133,16 +138,29 @@ private boolean versionCompatibilityCheckPre303(String requested) {
133138
*/
134139
public void failOnNotCompatible() throws DatabaseNotCompatibleException {
135140
if (!isCompatible()) {
136-
throw new DatabaseNotCompatibleException(databaseVersion);
141+
throw new DatabaseNotCompatibleException(utPlsqlVersion);
137142
}
138143
}
139144

140145
public boolean isCompatible() {
141146
return compatible;
142147
}
143148

144-
public Version getDatabaseVersion() {
145-
return databaseVersion;
149+
@Deprecated
150+
public Version getDatabaseVersion() { return utPlsqlVersion; }
151+
152+
public Version getUtPlsqlVersion() {
153+
return utPlsqlVersion;
154+
}
155+
156+
public Version getRealDbPlsqlVersion() { return realDbPlsqlVersion; }
157+
158+
public String getVersionDescription() {
159+
if ( utPlsqlVersion != realDbPlsqlVersion ) {
160+
return realDbPlsqlVersion.toString() + " (Assumed: " + utPlsqlVersion.toString() + ")";
161+
} else {
162+
return utPlsqlVersion.toString();
163+
}
146164
}
147165

148166
/**
@@ -154,7 +172,7 @@ public Version getDatabaseVersion() {
154172
* @throws SQLException
155173
*/
156174
public TestRunnerStatement getTestRunnerStatement(TestRunnerOptions options, Connection conn) throws SQLException {
157-
return TestRunnerStatementProvider.getCompatibleTestRunnerStatement(databaseVersion, options, conn);
175+
return TestRunnerStatementProvider.getCompatibleTestRunnerStatement(utPlsqlVersion, options, conn);
158176
}
159177

160178
/**
@@ -166,6 +184,6 @@ public TestRunnerStatement getTestRunnerStatement(TestRunnerOptions options, Con
166184
* @throws SQLException
167185
*/
168186
public OutputBuffer getOutputBuffer(Reporter reporter, Connection conn) throws SQLException {
169-
return OutputBufferProvider.getCompatibleOutputBuffer(databaseVersion, reporter, conn);
187+
return OutputBufferProvider.getCompatibleOutputBuffer(utPlsqlVersion, reporter, conn);
170188
}
171189
}

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ public enum OptionalFeatures {
1010

1111
FAIL_ON_ERROR("3.0.3.1266", null),
1212
FRAMEWORK_COMPATIBILITY_CHECK("3.0.3.1266", null),
13-
CUSTOM_REPORTERS("3.1.0.1849", null);
13+
CUSTOM_REPORTERS("3.1.0.1849", null),
14+
CLIENT_CHARACTER_SET("3.1.2.2130", null);
1415

1516
private final Version minVersion;
1617
private final Version maxVersion;
@@ -32,6 +33,10 @@ public boolean isAvailableFor(Version version) {
3233

3334
public boolean isAvailableFor(Connection conn) throws SQLException {
3435
CompatibilityProxy proxy = new CompatibilityProxy(conn);
35-
return isAvailableFor(proxy.getDatabaseVersion());
36+
return isAvailableFor(proxy.getUtPlsqlVersion());
3637
}
38+
39+
public Version getMinVersion() { return minVersion; }
40+
41+
public Version getMaxVersion() { return maxVersion; }
3742
}

src/main/java/org/utplsql/api/reporter/CoreReporters.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@
1111
*/
1212
public enum CoreReporters {
1313

14+
UT_COVERAGE_COBERTURA_REPORTER(Version.V3_1_0, null),
1415
UT_COVERAGE_HTML_REPORTER(Version.V3_0_0, null),
15-
UT_DOCUMENTATION_REPORTER(Version.V3_0_0, null),
16-
UT_TEAMCITY_REPORTER(Version.V3_0_0, null),
17-
UT_XUNIT_REPORTER(Version.V3_0_0, null),
18-
UT_COVERALLS_REPORTER(Version.V3_0_0, null),
1916
UT_COVERAGE_SONAR_REPORTER(Version.V3_0_0, null),
17+
UT_COVERALLS_REPORTER(Version.V3_0_0, null),
18+
UT_DEBUG_REPORTER(Version.V3_1_4, null),
19+
UT_DOCUMENTATION_REPORTER(Version.V3_0_0, null),
20+
UT_JUNIT_REPORTER(Version.V3_1_0, null),
21+
UT_REALTIME_REPORTER(Version.V3_1_4, null),
2022
UT_SONAR_TEST_REPORTER(Version.V3_0_0, null),
21-
UT_COVERAGE_COBERTURA_REPORTER(Version.V3_1_0, null);
23+
UT_TEAMCITY_REPORTER(Version.V3_0_0, null),
24+
UT_TFS_JUNIT_REPORTER(Version.V3_1_0, null),
25+
UT_XUNIT_REPORTER(Version.V3_0_0, null);
2226

2327
private final Version since;
2428
private final Version until;

src/main/java/org/utplsql/api/reporter/inspect/ReporterInspector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static ReporterInspector create(ReporterFactory reporterFactory, Connection conn
3131

3232
CompatibilityProxy proxy = new CompatibilityProxy(conn);
3333

34-
if (proxy.getDatabaseVersion().isGreaterOrEqualThan(Version.V3_1_0)) {
34+
if (proxy.getUtPlsqlVersion().isGreaterOrEqualThan(Version.V3_1_0)) {
3535
return new ReporterInspector310(reporterFactory, conn);
3636
} else {
3737
return new ReporterInspectorPre310(reporterFactory, conn);

src/main/java/org/utplsql/api/reporter/inspect/ReporterInspectorPre310.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ReporterInspectorPre310 extends AbstractReporterInspector {
2121
registeredReporterFactoryMethods = reporterFactory.getRegisteredReporterInfo();
2222
initDefaultDescriptions();
2323

24-
Version databaseVersion = new CompatibilityProxy(connection).getDatabaseVersion();
24+
Version databaseVersion = new CompatibilityProxy(connection).getUtPlsqlVersion();
2525
this.infos = Arrays.stream(CoreReporters.values())
2626
.filter(r -> r.isAvailableFor(databaseVersion))
2727
.map(this::getReporterInfo)

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ void compatibleVersion() throws SQLException {
1919

2020
@Test
2121
void skipCompatibilityCheck() throws SQLException {
22-
CompatibilityProxy proxy = new CompatibilityProxy(getConnection(), true);
22+
CompatibilityProxy proxy = new CompatibilityProxy(getConnection(), Version.LATEST);
2323
proxy.failOnNotCompatible();
2424
assertTrue(proxy.isCompatible());
25-
2625
}
2726
}

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.utplsql.api;
22

33
import org.junit.jupiter.api.Test;
4+
import org.omg.CORBA.DynAnyPackage.Invalid;
45
import org.utplsql.api.compatibility.CompatibilityProxy;
56
import org.utplsql.api.compatibility.OptionalFeatures;
67
import org.utplsql.api.exception.InvalidVersionException;
@@ -14,7 +15,7 @@ class OptionalFeaturesIT extends AbstractDatabaseTest {
1415

1516

1617
private Version getDatabaseVersion() throws SQLException {
17-
return new CompatibilityProxy(getConnection()).getDatabaseVersion();
18+
return new CompatibilityProxy(getConnection()).getUtPlsqlVersion();
1819
}
1920

2021
@Test
@@ -52,4 +53,15 @@ void customReporters() throws SQLException, InvalidVersionException {
5253
assertFalse(available);
5354
}
5455
}
56+
57+
@Test
58+
void clientCharset() throws SQLException, InvalidVersionException {
59+
boolean available = OptionalFeatures.CLIENT_CHARACTER_SET.isAvailableFor(getConnection());
60+
61+
if (getDatabaseVersion().isGreaterOrEqualThan(Version.V3_1_2)) {
62+
assertTrue(available);
63+
} else {
64+
assertFalse(available);
65+
}
66+
}
5567
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ void getOutputFromSonarReporter() throws SQLException {
131131
void sonarReporterHasEncodingSet() throws SQLException, InvalidVersionException {
132132
CompatibilityProxy proxy = new CompatibilityProxy(newConnection());
133133

134-
if (proxy.getDatabaseVersion().isGreaterOrEqualThan(Version.V3_1_2)) {
134+
if (proxy.getUtPlsqlVersion().isGreaterOrEqualThan(Version.V3_1_2)) {
135135
Reporter reporter = new DefaultReporter(CoreReporters.UT_SONAR_TEST_REPORTER.name(), null).init(getConnection());
136136

137137
TestRunner tr = new TestRunner()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void testGetReporterInfo() throws SQLException, InvalidVersionException {
3939
assertEquals(infos.get(CoreReporters.UT_TEAMCITY_REPORTER.name()).getType(), ReporterInfo.Type.SQL);
4040
assertEquals(infos.get(CoreReporters.UT_XUNIT_REPORTER.name()).getType(), ReporterInfo.Type.SQL);
4141

42-
if (CoreReporters.UT_COVERAGE_COBERTURA_REPORTER.isAvailableFor(proxy.getDatabaseVersion())) {
42+
if (CoreReporters.UT_COVERAGE_COBERTURA_REPORTER.isAvailableFor(proxy.getUtPlsqlVersion())) {
4343
assertEquals(infos.get(CoreReporters.UT_COVERAGE_COBERTURA_REPORTER.name()).getType(), ReporterInfo.Type.SQL);
4444
}
4545
}

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import org.junit.jupiter.api.Test;
44
import org.junit.jupiter.api.function.Executable;
55
import org.utplsql.api.compatibility.CompatibilityProxy;
6+
import org.utplsql.api.compatibility.OptionalFeatures;
7+
import org.utplsql.api.db.DatabaseInformation;
8+
import org.utplsql.api.db.DefaultDatabaseInformation;
69
import org.utplsql.api.exception.InvalidVersionException;
710
import org.utplsql.api.exception.SomeTestsFailedException;
811
import org.utplsql.api.reporter.CoreReporters;
@@ -31,9 +34,11 @@ void runWithDefaultParameters() throws SQLException {
3134
*/
3235
@Test
3336
void runWithoutCompatibilityCheck() throws SQLException, InvalidVersionException {
34-
CompatibilityProxy proxy = new CompatibilityProxy(getConnection());
3537

36-
if (proxy.getDatabaseVersion().isGreaterOrEqualThan(Version.V3_0_3)) {
38+
DatabaseInformation databaseInformation = new DefaultDatabaseInformation();
39+
40+
// We can only test this for the versions of the latest TestRunnerStatement-Change
41+
if ( OptionalFeatures.CLIENT_CHARACTER_SET.isAvailableFor(databaseInformation.getUtPlsqlFrameworkVersion(getConnection())) ) {
3742
new TestRunner()
3843
.skipCompatibilityCheck(true)
3944
.run(getConnection());
@@ -65,7 +70,7 @@ void failOnErrors() throws SQLException, InvalidVersionException {
6570

6671
CompatibilityProxy proxy = new CompatibilityProxy(conn);
6772

68-
if (proxy.getDatabaseVersion().isGreaterOrEqualThan(Version.V3_0_3)) {
73+
if (proxy.getUtPlsqlVersion().isGreaterOrEqualThan(Version.V3_0_3)) {
6974
Executable throwingTestRunner = () -> new TestRunner()
7075
.failOnErrors(true)
7176
.run(conn);

0 commit comments

Comments
 (0)