10 files changed
@@ -108,12 +108,12 @@ public static void failOnVersionCompatibilityCheckFailed( Connection conn ) thro | |||
| 108 | 108 | // Try to find out Framework Version | |
| 109 | 109 | Version v = DBHelper.getDatabaseFrameworkVersion(conn); | |
| 110 | 110 | ||
| 111 | - throw new DatabaseNotCompatibleException( v.getVersionString() ); | ||
| 111 | + throw new DatabaseNotCompatibleException( v ); | ||
| 112 | 112 | } | |
| 113 | 113 | } | |
| 114 | 114 | catch ( SQLException e ) | |
| 115 | 115 | { | |
| 116 | - throw new DatabaseNotCompatibleException("Compatibility-check failed with error. Aborting. Reason: " + e.getMessage(), UTPLSQL_COMPATIBILITY_VERSION, "Unknown", e); | ||
| 116 | + throw new DatabaseNotCompatibleException("Compatibility-check failed with error. Aborting. Reason: " + e.getMessage(), new Version(UTPLSQL_COMPATIBILITY_VERSION), new Version("Unknown"), e); | ||
| 117 | 117 | } | |
| 118 | 118 | } | |
| 119 | 119 | ||
@@ -6,7 +6,6 @@ | |||
| 6 | 6 | import org.utplsql.api.exception.SomeTestsFailedException; | |
| 7 | 7 | import org.utplsql.api.reporter.DocumentationReporter; | |
| 8 | 8 | import org.utplsql.api.reporter.Reporter; | |
| 9 | - import org.utplsql.api.testRunner.AbstractTestRunnerStatement; | ||
| 10 | 9 | import org.utplsql.api.testRunner.TestRunnerStatement; | |
| 11 | 10 | ||
| 12 | 11 | import java.sql.CallableStatement; | |
@@ -48,7 +48,8 @@ private void parseVersionString() | |||
| 48 | 48 | } | |
| 49 | 49 | } | |
| 50 | 50 | ||
| 51 | - public String getOrigString() { | ||
| 51 | + @Override | ||
| 52 | + public String toString() { | ||
| 52 | 53 | return origString; | |
| 53 | 54 | } | |
| 54 | 55 | ||
@@ -76,7 +77,7 @@ public boolean isValid() { | |||
| 76 | 77 | * | |
| 77 | 78 | * @return | |
| 78 | 79 | */ | |
| 79 | - public String getVersionString() | ||
| 80 | + public String getNormalizedString() | ||
| 80 | 81 | { | |
| 81 | 82 | if ( isValid() ) { | |
| 82 | 83 | StringBuilder sb = new StringBuilder(); | |
@@ -2,11 +2,7 @@ | |||
| 2 | 2 | ||
| 3 | 3 | import org.utplsql.api.DBHelper; | |
| 4 | 4 | import org.utplsql.api.TestRunnerOptions; | |
| 5 | - import org.utplsql.api.Version; | ||
| 6 | - import org.utplsql.api.testRunner.AbstractTestRunnerStatement; | ||
| 7 | - import org.utplsql.api.testRunner.Pre303TestRunnerStatement; | ||
| 8 | - import org.utplsql.api.testRunner.ActualTestRunnerStatement; | ||
| 9 | - import org.utplsql.api.testRunner.TestRunnerStatement; | ||
| 5 | + import org.utplsql.api.testRunner.*; | ||
| 10 | 6 | ||
| 11 | 7 | import java.sql.Connection; | |
| 12 | 8 | import java.sql.SQLException; | |
@@ -22,15 +18,6 @@ public class CompatibilityProvider { | |||
| 22 | 18 | ||
| 23 | 19 | public static TestRunnerStatement getTestRunnerStatement(TestRunnerOptions options, Connection conn) throws SQLException | |
| 24 | 20 | { | |
| 25 | - Version version = DBHelper.getDatabaseFrameworkVersion(conn); | ||
| 26 | - | ||
| 27 | - AbstractTestRunnerStatement stmt = null; | ||
| 28 | - | ||
| 29 | - if ( version.getMajor() == 3 && version.getMinor() == 0 && version.getBugfix() <= 2 ) | ||
| 30 | - stmt = new Pre303TestRunnerStatement(options, conn); | ||
| 31 | - else | ||
| 32 | - stmt = new ActualTestRunnerStatement(options, conn); | ||
| 33 | - | ||
| 34 | - return stmt; | ||
| 21 | + return TestRunnerStatementProvider.getCompatibleTestRunnerStatement(DBHelper.getDatabaseFrameworkVersion(conn), options, conn); | ||
| 35 | 22 | } | |
| 36 | 23 | } | |
@@ -1,6 +1,7 @@ | |||
| 1 | 1 | package org.utplsql.api.exception; | |
| 2 | 2 | ||
| 3 | 3 | import org.utplsql.api.DBHelper; | |
| 4 | + import org.utplsql.api.Version; | ||
| 4 | 5 | ||
| 5 | 6 | import java.sql.SQLException; | |
| 6 | 7 | ||
@@ -11,42 +12,42 @@ | |||
| 11 | 12 | */ | |
| 12 | 13 | public class DatabaseNotCompatibleException extends SQLException { | |
| 13 | 14 | ||
| 14 | - private String clientVersion; | ||
| 15 | - private String databaseVersion; | ||
| 15 | + private Version clientVersion; | ||
| 16 | + private Version databaseVersion; | ||
| 16 | 17 | ||
| 17 | - public DatabaseNotCompatibleException( String message, String clientVersion, String databaseVersion, Throwable cause ) | ||
| 18 | + public DatabaseNotCompatibleException( String message, Version clientVersion, Version databaseVersion, Throwable cause ) | ||
| 18 | 19 | { | |
| 19 | 20 | super(message, cause); | |
| 20 | 21 | ||
| 21 | 22 | this.clientVersion = clientVersion; | |
| 22 | 23 | this.databaseVersion = databaseVersion; | |
| 23 | 24 | } | |
| 24 | 25 | ||
| 25 | - public DatabaseNotCompatibleException( String clientVersion, String databaseVersion, Throwable cause ) | ||
| 26 | + public DatabaseNotCompatibleException( Version clientVersion, Version databaseVersion, Throwable cause ) | ||
| 26 | 27 | { | |
| 27 | 28 | this("utPLSQL API (" + String.valueOf(clientVersion) + ") not compatible with database (" + String.valueOf(databaseVersion) + ")", clientVersion, databaseVersion, cause); | |
| 28 | 29 | } | |
| 29 | 30 | ||
| 30 | - public DatabaseNotCompatibleException( String clientVersion, String databaseVersion ) | ||
| 31 | + public DatabaseNotCompatibleException( Version clientVersion, Version databaseVersion ) | ||
| 31 | 32 | { | |
| 32 | 33 | this(clientVersion, databaseVersion, null); | |
| 33 | 34 | } | |
| 34 | 35 | ||
| 35 | - public DatabaseNotCompatibleException( String databaseVersion, Throwable cause ) | ||
| 36 | + public DatabaseNotCompatibleException( Version databaseVersion, Throwable cause ) | ||
| 36 | 37 | { | |
| 37 | - this(DBHelper.UTPLSQL_COMPATIBILITY_VERSION, databaseVersion, cause ); | ||
| 38 | + this(new Version(DBHelper.UTPLSQL_COMPATIBILITY_VERSION), databaseVersion, cause ); | ||
| 38 | 39 | } | |
| 39 | 40 | ||
| 40 | - public DatabaseNotCompatibleException( String databaseVersion ) | ||
| 41 | + public DatabaseNotCompatibleException( Version databaseVersion ) | ||
| 41 | 42 | { | |
| 42 | - this(DBHelper.UTPLSQL_COMPATIBILITY_VERSION, databaseVersion, null ); | ||
| 43 | + this(new Version(DBHelper.UTPLSQL_COMPATIBILITY_VERSION), databaseVersion, null ); | ||
| 43 | 44 | } | |
| 44 | 45 | ||
| 45 | - public String getClientVersion() { | ||
| 46 | + public Version getClientVersion() { | ||
| 46 | 47 | return clientVersion; | |
| 47 | 48 | } | |
| 48 | 49 | ||
| 49 | - public String getDatabaseVersion() | ||
| 50 | + public Version getDatabaseVersion() | ||
| 50 | 51 | { | |
| 51 | 52 | return databaseVersion; | |
| 52 | 53 | } | |
@@ -15,7 +15,7 @@ | |||
| 15 | 15 | * | |
| 16 | 16 | * @author pesse | |
| 17 | 17 | */ | |
| 18 | - public abstract class AbstractTestRunnerStatement implements TestRunnerStatement { | ||
| 18 | + abstract class AbstractTestRunnerStatement implements TestRunnerStatement { | ||
| 19 | 19 | ||
| 20 | 20 | protected TestRunnerOptions options; | |
| 21 | 21 | protected Connection conn; | |
@@ -10,7 +10,7 @@ | |||
| 10 | 10 | * | |
| 11 | 11 | * @author pesse | |
| 12 | 12 | */ | |
| 13 | - public class ActualTestRunnerStatement extends AbstractTestRunnerStatement { | ||
| 13 | + class ActualTestRunnerStatement extends AbstractTestRunnerStatement { | ||
| 14 | 14 | ||
| 15 | 15 | public ActualTestRunnerStatement(TestRunnerOptions options, Connection connection ) throws SQLException { | |
| 16 | 16 | super( options, connection); | |
@@ -10,7 +10,7 @@ | |||
| 10 | 10 | * | |
| 11 | 11 | * @author pesse | |
| 12 | 12 | */ | |
| 13 | - public class Pre303TestRunnerStatement extends AbstractTestRunnerStatement { | ||
| 13 | + class Pre303TestRunnerStatement extends AbstractTestRunnerStatement { | ||
| 14 | 14 | ||
| 15 | 15 | public Pre303TestRunnerStatement(TestRunnerOptions options, Connection conn) throws SQLException { | |
| 16 | 16 | super(options, conn); | |
@@ -0,0 +1,35 @@ | |||
| 1 | + package org.utplsql.api.testRunner; | ||
| 2 | + | ||
| 3 | + import org.utplsql.api.DBHelper; | ||
| 4 | + import org.utplsql.api.TestRunnerOptions; | ||
| 5 | + import org.utplsql.api.Version; | ||
| 6 | + | ||
| 7 | + import java.sql.Connection; | ||
| 8 | + import java.sql.SQLException; | ||
| 9 | + | ||
| 10 | + /** Provides different implementations of TestRunnerStatement based on the version of the database framework | ||
| 11 | + * | ||
| 12 | + * @author pesse | ||
| 13 | + */ | ||
| 14 | + public class TestRunnerStatementProvider { | ||
| 15 | + | ||
| 16 | + /** Returns the TestRunnerStatement-implementation compatible with the given databaseVersion. | ||
| 17 | + * | ||
| 18 | + * @param databaseVersion Version of the database framework | ||
| 19 | + * @param options TestRunnerOptions to be used | ||
| 20 | + * @param conn Active Connection | ||
| 21 | + * @return TestRunnerStatment compatible with the database framework | ||
| 22 | + * @throws SQLException | ||
| 23 | + */ | ||
| 24 | + public static TestRunnerStatement getCompatibleTestRunnerStatement(Version databaseVersion, TestRunnerOptions options, Connection conn ) throws SQLException | ||
| 25 | + { | ||
| 26 | + AbstractTestRunnerStatement stmt = null; | ||
| 27 | + | ||
| 28 | + if ( databaseVersion.getMajor() == 3 && databaseVersion.getMinor() == 0 && databaseVersion.getBugfix() <= 2 ) | ||
| 29 | + stmt = new Pre303TestRunnerStatement(options, conn); | ||
| 30 | + else | ||
| 31 | + stmt = new ActualTestRunnerStatement(options, conn); | ||
| 32 | + | ||
| 33 | + return stmt; | ||
| 34 | + } | ||
| 35 | + } | ||
@@ -14,7 +14,7 @@ public void versionPatternRecognitionFull() { | |||
| 14 | 14 | Assert.assertEquals(3, (long)v.getBugfix()); | |
| 15 | 15 | Assert.assertEquals(1234, (long)v.getBuild()); | |
| 16 | 16 | Assert.assertEquals(true, v.isValid()); | |
| 17 | - Assert.assertEquals("3.1.3.1234", v.getVersionString()); | ||
| 17 | + Assert.assertEquals("3.1.3.1234", v.getNormalizedString()); | ||
| 18 | 18 | } | |
| 19 | 19 | ||
| 20 | 20 | @Test | |
@@ -26,7 +26,7 @@ public void versionPatternRecognitionPartial() { | |||
| 26 | 26 | Assert.assertNull(v.getBugfix()); | |
| 27 | 27 | Assert.assertNull(v.getBuild()); | |
| 28 | 28 | Assert.assertEquals(true, v.isValid()); | |
| 29 | - Assert.assertEquals("3.1", v.getVersionString()); | ||
| 29 | + Assert.assertEquals("3.1", v.getNormalizedString()); | ||
| 30 | 30 | } | |
| 31 | 31 | ||
| 32 | 32 | @Test | |
@@ -38,6 +38,6 @@ public void versionPatternRecognitionInvalid() { | |||
| 38 | 38 | Assert.assertNull(v.getBugfix()); | |
| 39 | 39 | Assert.assertNull(v.getBuild()); | |
| 40 | 40 | Assert.assertEquals(false, v.isValid()); | |
| 41 | - Assert.assertEquals("invalid", v.getVersionString()); | ||
| 41 | + Assert.assertEquals("invalid", v.getNormalizedString()); | ||
| 42 | 42 | } | |
| 43 | 43 | } | |
0 commit comments