Skip to content

Commit ab28df3

Browse files
committed
Change of CompatibilityProxy
We can now provide an assumed Version and are more flexible with skipping compatibility check. Also added Optional Feature
1 parent 188157a commit ab28df3

File tree

10 files changed

+59
-45
lines changed

10 files changed

+59
-45
lines changed

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.getUtPlsqlVersion());
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/compatibility/CompatibilityProxy.java

Lines changed: 31 additions & 30 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;
@@ -26,28 +27,31 @@ public class CompatibilityProxy {
2627

2728
public static final String UTPLSQL_COMPATIBILITY_VERSION = "3";
2829
private final DatabaseInformation databaseInformation;
29-
private Version databaseVersion;
30+
private Version utPlsqlVersion;
31+
private Version realDbPlsqlVersion;
3032
private boolean compatible = false;
3133

3234
public CompatibilityProxy(Connection conn) throws SQLException {
33-
this(conn, false, null);
35+
this(conn, null, null);
3436
}
3537

36-
public CompatibilityProxy(Connection conn, DatabaseInformation databaseInformation) throws SQLException {
37-
this(conn, false, databaseInformation);
38+
public CompatibilityProxy(Connection conn, @Nullable DatabaseInformation databaseInformation) throws SQLException {
39+
this(conn, null, databaseInformation);
3840
}
3941

40-
public CompatibilityProxy(Connection conn, boolean skipCompatibilityCheck) throws SQLException {
41-
this(conn, skipCompatibilityCheck, null);
42+
public CompatibilityProxy(Connection conn, @Nullable Version assumedUtPlsVersion) throws SQLException {
43+
this(conn, assumedUtPlsVersion, null);
4244
}
4345

44-
public CompatibilityProxy(Connection conn, boolean skipCompatibilityCheck, DatabaseInformation databaseInformation) throws SQLException {
46+
public CompatibilityProxy(Connection conn, @Nullable Version assumedUtPlsqlVersion, @Nullable DatabaseInformation databaseInformation) throws SQLException {
4547
this.databaseInformation = (databaseInformation != null)
4648
? databaseInformation
4749
: new DefaultDatabaseInformation();
4850

49-
if (skipCompatibilityCheck) {
50-
doExpectCompatibility();
51+
realDbPlsqlVersion = this.databaseInformation.getUtPlsqlFrameworkVersion(conn);
52+
if ( assumedUtPlsqlVersion != null ) {
53+
utPlsqlVersion = assumedUtPlsqlVersion;
54+
compatible = utPlsqlVersion.getNormalizedString().startsWith(UTPLSQL_COMPATIBILITY_VERSION);
5155
} else {
5256
doCompatibilityCheckWithDatabase(conn);
5357
}
@@ -61,18 +65,18 @@ public CompatibilityProxy(Connection conn, boolean skipCompatibilityCheck, Datab
6165
* @throws SQLException
6266
*/
6367
private void doCompatibilityCheckWithDatabase(Connection conn) throws SQLException {
64-
databaseVersion = databaseInformation.getUtPlsqlFrameworkVersion(conn);
68+
utPlsqlVersion = realDbPlsqlVersion;
6569
Version clientVersion = Version.create(UTPLSQL_COMPATIBILITY_VERSION);
6670

67-
if (databaseVersion == null) {
71+
if (utPlsqlVersion == null) {
6872
throw new DatabaseNotCompatibleException("Could not get database version", clientVersion, null, null);
6973
}
7074

71-
if (databaseVersion.getMajor() == null) {
72-
throw new DatabaseNotCompatibleException("Illegal database version: " + databaseVersion.toString(), clientVersion, databaseVersion, null);
75+
if (utPlsqlVersion.getMajor() == null) {
76+
throw new DatabaseNotCompatibleException("Illegal database version: " + utPlsqlVersion.toString(), clientVersion, utPlsqlVersion, null);
7377
}
7478

75-
if (OptionalFeatures.FRAMEWORK_COMPATIBILITY_CHECK.isAvailableFor(databaseVersion)) {
79+
if (OptionalFeatures.FRAMEWORK_COMPATIBILITY_CHECK.isAvailableFor(utPlsqlVersion)) {
7680
try {
7781
compatible = versionCompatibilityCheck(conn, UTPLSQL_COMPATIBILITY_VERSION, null);
7882
} catch (SQLException e) {
@@ -83,14 +87,6 @@ private void doCompatibilityCheckWithDatabase(Connection conn) throws SQLExcepti
8387
}
8488
}
8589

86-
/**
87-
* Just prepare the proxy to expect compatibility, expecting the database framework to be the same version as the API
88-
*/
89-
private void doExpectCompatibility() {
90-
databaseVersion = Version.LATEST;
91-
compatible = true;
92-
}
93-
9490
/**
9591
* Check the utPLSQL version compatibility.
9692
*
@@ -120,10 +116,10 @@ private boolean versionCompatibilityCheck(Connection conn, String requested, Str
120116
private boolean versionCompatibilityCheckPre303(String requested) {
121117
Version requestedVersion = Version.create(requested);
122118

123-
Objects.requireNonNull(databaseVersion.getMajor(), "Illegal database Version: " + databaseVersion.toString());
124-
return databaseVersion.getMajor().equals(requestedVersion.getMajor())
119+
Objects.requireNonNull(utPlsqlVersion.getMajor(), "Illegal database Version: " + utPlsqlVersion.toString());
120+
return utPlsqlVersion.getMajor().equals(requestedVersion.getMajor())
125121
&& (requestedVersion.getMinor() == null
126-
|| requestedVersion.getMinor().equals(databaseVersion.getMinor()));
122+
|| requestedVersion.getMinor().equals(utPlsqlVersion.getMinor()));
127123
}
128124

129125
/**
@@ -132,18 +128,23 @@ private boolean versionCompatibilityCheckPre303(String requested) {
132128
*/
133129
public void failOnNotCompatible() throws DatabaseNotCompatibleException {
134130
if (!isCompatible()) {
135-
throw new DatabaseNotCompatibleException(databaseVersion);
131+
throw new DatabaseNotCompatibleException(utPlsqlVersion);
136132
}
137133
}
138134

139135
public boolean isCompatible() {
140136
return compatible;
141137
}
142138

143-
public Version getDatabaseVersion() {
144-
return databaseVersion;
139+
@Deprecated
140+
public Version getDatabaseVersion() { return utPlsqlVersion; }
141+
142+
public Version getUtPlsqlVersion() {
143+
return utPlsqlVersion;
145144
}
146145

146+
public Version getRealDbPlsqlVersion() { return realDbPlsqlVersion; }
147+
147148
/**
148149
* Returns a TestRunnerStatement compatible with the current framework
149150
*
@@ -153,7 +154,7 @@ public Version getDatabaseVersion() {
153154
* @throws SQLException
154155
*/
155156
public TestRunnerStatement getTestRunnerStatement(TestRunnerOptions options, Connection conn) throws SQLException {
156-
return TestRunnerStatementProvider.getCompatibleTestRunnerStatement(databaseVersion, options, conn);
157+
return TestRunnerStatementProvider.getCompatibleTestRunnerStatement(utPlsqlVersion, options, conn);
157158
}
158159

159160
/**
@@ -165,6 +166,6 @@ public TestRunnerStatement getTestRunnerStatement(TestRunnerOptions options, Con
165166
* @throws SQLException
166167
*/
167168
public OutputBuffer getOutputBuffer(Reporter reporter, Connection conn) throws SQLException {
168-
return OutputBufferProvider.getCompatibleOutputBuffer(databaseVersion, reporter, conn);
169+
return OutputBufferProvider.getCompatibleOutputBuffer(utPlsqlVersion, reporter, conn);
169170
}
170171
}

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/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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class OptionalFeaturesIT extends AbstractDatabaseTest {
1414

1515

1616
private Version getDatabaseVersion() throws SQLException {
17-
return new CompatibilityProxy(getConnection()).getDatabaseVersion();
17+
return new CompatibilityProxy(getConnection()).getUtPlsqlVersion();
1818
}
1919

2020
@Test

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)