Skip to content

Commit 6a7d650

Browse files
committed
Refactoring
1 parent 8bdaf0f commit 6a7d650

File tree

2 files changed

+32
-25
lines changed

2 files changed

+32
-25
lines changed

src/main/java/org/utplsql/cli/RunCommand.java

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public List<String> getTestPaths() {
124124
return testPaths;
125125
}
126126

127-
public void init() {
127+
void init() {
128128
LoggerConfiguration.configure(logSilent, logDebug);
129129
}
130130

@@ -166,29 +166,8 @@ public int run() {
166166

167167
final DataSource dataSource = DataSourceProvider.getDataSource(getConnectionInfo(), getReporterManager().getNumberOfReporters() + 1);
168168

169-
// Do the reporters initialization, so we can use the id to run and gather results.
170-
try (Connection conn = dataSource.getConnection()) {
171-
172-
// Check if orai18n exists if database version is 11g
173-
RunCommandChecker.checkOracleI18nExists(conn);
174-
175-
// First of all do a compatibility check and fail-fast
176-
compatibilityProxy = checkFrameworkCompatibility(conn);
177-
178-
logger.info("Successfully connected to database. UtPLSQL core: " + compatibilityProxy.getDatabaseVersion());
179-
logger.info("Oracle-Version: {}", new DefaultDatabaseInformation().getOracleVersion(conn));
180-
181-
reporterFactory = ReporterFactoryProvider.createReporterFactory(compatibilityProxy);
182-
183-
reporterList = getReporterManager().initReporters(conn, reporterFactory, compatibilityProxy);
184-
185-
} catch (SQLException e) {
186-
if (e.getErrorCode() == 1017 || e.getErrorCode() == 12514) {
187-
throw new DatabaseConnectionFailed(e);
188-
} else {
189-
throw e;
190-
}
191-
}
169+
initDatabase(dataSource);
170+
reporterList = initReporters(dataSource);
192171

193172
// Output a message if --failureExitCode is set but database framework is not capable of
194173
String msg = RunCommandChecker.getCheckFailOnErrorMessage(failureExitCode, compatibilityProxy.getDatabaseVersion());
@@ -263,6 +242,34 @@ private void outputMainInformation() {
263242
logger.info("");
264243
}
265244

245+
private void initDatabase(DataSource dataSource) throws SQLException {
246+
try (Connection conn = dataSource.getConnection()) {
247+
248+
// Check if orai18n exists if database version is 11g
249+
RunCommandChecker.checkOracleI18nExists(conn);
250+
251+
// First of all do a compatibility check and fail-fast
252+
compatibilityProxy = checkFrameworkCompatibility(conn);
253+
254+
logger.info("Successfully connected to database. UtPLSQL core: " + compatibilityProxy.getDatabaseVersion());
255+
logger.info("Oracle-Version: {}", new DefaultDatabaseInformation().getOracleVersion(conn));
256+
}
257+
catch (SQLException e) {
258+
if (e.getErrorCode() == 1017 || e.getErrorCode() == 12514) {
259+
throw new DatabaseConnectionFailed(e);
260+
} else {
261+
throw e;
262+
}
263+
}
264+
}
265+
266+
private List<Reporter> initReporters(DataSource dataSource) throws SQLException {
267+
try (Connection conn = dataSource.getConnection()) {
268+
reporterFactory = ReporterFactoryProvider.createReporterFactory(compatibilityProxy);
269+
return getReporterManager().initReporters(conn, reporterFactory, compatibilityProxy);
270+
}
271+
}
272+
266273
/** Returns FileMapperOptions for the first item of a given param list in a baseDir
267274
*
268275
* @param pathParams

src/test/java/org/utplsql/cli/TestRunCommandChecker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public void getCheckFailOnErrorMessage()
1515
assertNotNull(RunCommandChecker.getCheckFailOnErrorMessage(2, new Version("3.0.0")));
1616
assertNotNull(RunCommandChecker.getCheckFailOnErrorMessage(2, new Version("3.0.1")));
1717
assertNotNull(RunCommandChecker.getCheckFailOnErrorMessage(2, new Version("3.0.2")));
18-
assertNull(RunCommandChecker.getCheckFailOnErrorMessage(2, new Version("3.0.3")));
18+
assertNull(RunCommandChecker.getCheckFailOnErrorMessage(2, new Version("3.0.3.1266")));
1919
assertNull(RunCommandChecker.getCheckFailOnErrorMessage(2, new Version("3.0.4")));
2020
}
2121
}

0 commit comments

Comments
 (0)