Skip to content

Commit

Permalink
Fix sonar findngs
Browse files Browse the repository at this point in the history
  • Loading branch information
kaklakariada committed Nov 22, 2024
1 parent 391da1d commit 9b61a8f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.ValueSource;
import org.opentest4j.AssertionFailedError;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;

Expand All @@ -47,6 +46,7 @@ abstract class AbstractExasolSqlDialectIT {
private static final String COLUMN1_NAME = "C1";

@Container
@SuppressWarnings("resource") // Will be closed by @Testcontainers
protected static final ExasolContainer<? extends ExasolContainer<?>> EXASOL = new ExasolContainer<>(
IntegrationTestConfiguration.getDockerImageReference()).withReuse(true);
private static ExasolSchema adapterSchema;
Expand Down Expand Up @@ -166,8 +166,6 @@ protected void assertVirtualTableContents(final Table table, final Matcher<Resul
final VirtualSchema virtualSchema = createVirtualSchema(this.sourceSchema);
try {
assertThat(selectAllFromCorrespondingVirtualTable(virtualSchema, table), matcher);
} catch (final SQLException exception) {
throw new AssertionFailedError("Unable to execute assertion query for table " + table.getName(), exception);
} finally {
virtualSchema.drop();
}
Expand All @@ -193,28 +191,27 @@ private Map<String, String> getVirtualSchemaProperties() {
return getConnectionSpecificVirtualSchemaProperties();
}

protected ResultSet selectAllFromCorrespondingVirtualTable(final VirtualSchema virtualSchema, final Table table)
throws SQLException {
protected ResultSet selectAllFromCorrespondingVirtualTable(final VirtualSchema virtualSchema, final Table table) {
return selectAllFrom(getVirtualTableName(virtualSchema, table));
}

private ResultSet selectAllFrom(final String tableName) throws SQLException {
private ResultSet selectAllFrom(final String tableName) {
return query("SELECT * FROM " + tableName);
}

protected String getVirtualTableName(final VirtualSchema virtualSchema, final Table table) {
return virtualSchema.getFullyQualifiedName() + ".\"" + table.getName() + "\"";
}

protected ResultSet query(final String sqlFormatString, final Object... args) throws SQLException {
protected ResultSet query(final String sqlFormatString, final Object... args) {
return query(MessageFormat.format(sqlFormatString, args));
}

protected ResultSet query(final String sql) throws SQLException {
protected ResultSet query(final String sql) {
try {
return connection.createStatement().executeQuery(sql);
} catch (final SQLException exception) {
throw new SQLException("Error executing '" + sql + "': " + exception.getMessage(), exception);
throw new IllegalStateException("Error executing '" + sql + "': " + exception.getMessage(), exception);
}
}

Expand Down Expand Up @@ -374,11 +371,7 @@ void testIdentifierCaseSensitivityOnTable() {
}

protected void assertVsQuery(final String sql, final Matcher<ResultSet> expected) {
try {
assertThat(query(sql), expected);
} catch (final SQLException exception) {
throw new AssertionFailedError("Unable to run assertion query: '" + sql + "'", exception);
}
assertThat(query(sql), expected);
}

@Test
Expand Down Expand Up @@ -588,7 +581,7 @@ private void runQueryExpectedToFail(final String sql) throws SQLException {
}

@Test
void testCreateVirtualSchemaWithIgnoreErrorsProperty() throws SQLException {
void testCreateVirtualSchemaWithIgnoreErrorsProperty() {
final Table table = createSingleColumnTable("BOOLEAN").insert(true);
final Map<String, String> properties = new HashMap<>(getConnectionSpecificVirtualSchemaProperties());
properties.put("IGNORE_ERRORS", EXASOL_TIMESTAMP_WITH_LOCAL_TIME_ZONE_SWITCH);
Expand Down Expand Up @@ -850,7 +843,7 @@ void testNonDefaultIntervalDayToSecond() {
}

@Test
void testCurrentClusterFunction() throws SQLException {
void testCurrentClusterFunction() {
final Table table = createSingleColumnTable("VARCHAR(20) UTF8").insert("_cluster");
final VirtualSchema virtualSchema = createVirtualSchema(this.sourceSchema);
try {
Expand Down Expand Up @@ -882,7 +875,7 @@ static boolean isExasol7OrLower() {
}

@Test
void testWildcards() throws SQLException {
void testWildcards() {
assumeExasol7OrLower();
final String nameWithWildcard = "A_A";
this.sourceSchema.createTable(nameWithWildcard, "A", "VARCHAR(20)");
Expand All @@ -893,7 +886,7 @@ void testWildcards() throws SQLException {
}

@Test
void testWildcardsExasolV8() throws SQLException {
void testWildcardsExasolV8() {
assumeExasol8OrHigher();
final String nameWithWildcard = "A_A";
this.sourceSchema.createTable(nameWithWildcard, "A", "VARCHAR(20)");
Expand All @@ -905,7 +898,7 @@ void testWildcardsExasolV8() throws SQLException {

@Test
@DisplayName("Verify DISTINCT with integer literal")
void testDistinctWithIntegerLiteral() throws SQLException {
void testDistinctWithIntegerLiteral() {
final Table table = createSingleColumnTable("INT") //
.insert(1).insert(1).insert(2).insert(3);
final VirtualSchema virtualSchema = createVirtualSchema(this.sourceSchema);
Expand All @@ -923,7 +916,7 @@ void testDistinctWithIntegerLiteral() throws SQLException {

@Test
@DisplayName("Verify GROUP BY with column number reference")
void testGroupByWithColumnNumber() throws SQLException {
void testGroupByWithColumnNumber() {
final Table table = createSingleColumnTable("INT") //
.insert(1).insert(1).insert(2).insert(3);
final VirtualSchema virtualSchema = createVirtualSchema(this.sourceSchema);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
* <li>{@code GEOMETRY} types are reported with JDBC type name {@code VARCHAR} in ResultSets</li>
* <ul>
*/

class ExasolSqlDialectExaConnectionIT extends AbstractRemoteExasolVirtualSchemaConnectionIT {
private static final String EXA_CONNECTION_NAME = "EXA_CONNECTION";
private ConnectionDefinition exaConnection;
Expand Down Expand Up @@ -102,7 +101,7 @@ void testPasswordNotVisibleInImportFromExa() throws NoDriverFoundException, SQLE
}

@Test
void testAlterVirtualSchemaTriggersPropertyValidation() throws SQLException {
void testAlterVirtualSchemaTriggersPropertyValidation() {
this.virtualSchema = createVirtualSchema(this.sourceSchema);
final String name = this.virtualSchema.getFullyQualifiedName();
final SQLException exception = assertThrows(SQLException.class,
Expand All @@ -111,7 +110,7 @@ void testAlterVirtualSchemaTriggersPropertyValidation() throws SQLException {
assertThat(exception.getMessage(), containsString(expected));
}

private ResultSet explainVirtual(final String sql) throws SQLException {
private ResultSet explainVirtual(final String sql) {
return query("EXPLAIN VIRTUAL " + sql);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void testPasswordNotVisibleInImportFromExa() throws NoDriverFoundException, SQLE
}

@Test
void testAlterVirtualSchemaTriggersPropertyValidation() throws SQLException {
void testAlterVirtualSchemaTriggersPropertyValidation() {
this.virtualSchema = createVirtualSchema(this.sourceSchema);
final String name = this.virtualSchema.getFullyQualifiedName();
final SQLException exception = assertThrows(SQLException.class,
Expand Down

0 comments on commit 9b61a8f

Please sign in to comment.