diff --git a/build.gradle b/build.gradle index 27679db0f..f76040cf9 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ import java.util.jar.JarFile plugins { id 'java' id 'jacoco' - id "org.sonarqube" version "4.0.0.2929" + id "org.sonarqube" version "4.3.0.3225" id 'maven-publish' id 'com.github.johnrengelman.shadow' version '8.0.0' } @@ -56,35 +56,35 @@ sourceSets { } dependencies { - implementation 'org.apache.commons:commons-lang3:3.12.0' - implementation 'com.google.guava:guava:31.1-jre' + implementation 'com.google.code.findbugs:jsr305:3.0.2' implementation 'com.fasterxml.jackson.core:jackson-databind:2.15.2' - implementation 'commons-codec:commons-codec:1.15' + implementation 'com.squareup.okhttp3:okhttp:4.11.0' implementation 'net.jodah:expiringmap:0.5.10' + implementation 'org.apache.commons:commons-lang3:3.13.0' implementation 'org.apache.commons:commons-text:1.10.0' implementation 'org.lz4:lz4-java:1.8.0' - implementation 'com.squareup.okhttp3:okhttp:4.11.0' implementation 'javax.xml.bind:jaxb-api:2.3.1' + implementation fileTree(dir: 'libs', includes: ['*.jar']) - compileOnly 'org.slf4j:slf4j-api:2.0.7' - compileOnly 'org.projectlombok:lombok:1.18.26' - annotationProcessor 'org.projectlombok:lombok:1.18.26' - testCompileOnly 'org.projectlombok:lombok:1.18.26' - testAnnotationProcessor 'org.projectlombok:lombok:1.18.26' + compileOnly 'org.slf4j:slf4j-api:2.0.7' + compileOnly 'org.projectlombok:lombok:1.18.28' + annotationProcessor 'org.projectlombok:lombok:1.18.28' + testCompileOnly 'org.projectlombok:lombok:1.18.28' + testAnnotationProcessor 'org.projectlombok:lombok:1.18.28' testImplementation 'ch.qos.logback:logback-classic:1.4.9' testImplementation 'org.mockito:mockito-junit-jupiter:4.11.0' testImplementation 'org.mockito:mockito-core:4.11.0' testImplementation 'org.mockito:mockito-inline:4.11.0' - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.2' - testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.9.2' - testImplementation 'org.junit.jupiter:junit-jupiter-params:5.9.2' + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.0' + testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.10.0' + testImplementation 'org.junit.jupiter:junit-jupiter-params:5.10.0' testImplementation 'org.junit-pioneer:junit-pioneer:1.9.1' testImplementation 'org.hamcrest:hamcrest-library:2.2' - testImplementation 'com.squareup.okhttp3:mockwebserver:4.10.0' - testImplementation 'com.squareup.okhttp3:okhttp-tls:4.10.0' - testImplementation 'io.zonky.test:embedded-postgres:2.0.3' + testImplementation 'com.squareup.okhttp3:mockwebserver:4.11.0' + testImplementation 'com.squareup.okhttp3:okhttp-tls:4.11.0' + testImplementation 'io.zonky.test:embedded-postgres:2.0.4' testCompileOnly 'org.slf4j:slf4j-api:2.0.7' testCommonImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.0' testImplementation sourceSets.testCommon.output diff --git a/src/integrationTest/java/integration/IntegrationTest.java b/src/integrationTest/java/integration/IntegrationTest.java index aff322ced..59fff8f15 100644 --- a/src/integrationTest/java/integration/IntegrationTest.java +++ b/src/integrationTest/java/integration/IntegrationTest.java @@ -1,5 +1,11 @@ package integration; +import com.firebolt.jdbc.client.HttpClientConfig; +import lombok.CustomLog; +import lombok.SneakyThrows; +import org.junit.jupiter.api.TestInstance; + +import java.io.InputStream; import java.lang.reflect.Field; import java.nio.charset.StandardCharsets; import java.sql.Connection; @@ -8,13 +14,7 @@ import java.sql.Statement; import java.util.Optional; -import org.junit.jupiter.api.TestInstance; - -import com.firebolt.jdbc.client.HttpClientConfig; -import com.google.common.io.Resources; - -import lombok.CustomLog; -import lombok.SneakyThrows; +import static org.junit.jupiter.api.Assertions.assertNotNull; @CustomLog @TestInstance(TestInstance.Lifecycle.PER_CLASS) @@ -58,8 +58,9 @@ protected void executeStatementFromFile(String path) { @SneakyThrows protected void executeStatementFromFile(String path, String engine) { - try (Connection connection = createConnection(engine); Statement statement = connection.createStatement()) { - String sql = Resources.toString(IntegrationTest.class.getResource(path), StandardCharsets.UTF_8); + try (Connection connection = createConnection(engine); Statement statement = connection.createStatement(); InputStream is = IntegrationTest.class.getResourceAsStream(path)) { + assertNotNull(is); + String sql = new String(is.readAllBytes(), StandardCharsets.UTF_8); statement.execute(sql); } } diff --git a/src/main/java/com/firebolt/jdbc/client/UsageTrackerUtil.java b/src/main/java/com/firebolt/jdbc/client/UsageTrackerUtil.java index 0c2548860..0d6312fb9 100644 --- a/src/main/java/com/firebolt/jdbc/client/UsageTrackerUtil.java +++ b/src/main/java/com/firebolt/jdbc/client/UsageTrackerUtil.java @@ -1,24 +1,24 @@ package com.firebolt.jdbc.client; -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.lang3.StringUtils; - import com.firebolt.jdbc.util.VersionUtil; -import com.google.common.collect.ImmutableMap; - import lombok.CustomLog; import lombok.experimental.UtilityClass; +import org.apache.commons.lang3.StringUtils; + +import java.util.HashMap; +import java.util.Map; @CustomLog @UtilityClass public class UsageTrackerUtil { - public static final Map CLIENT_MAP = ImmutableMap.of("Tableau", "com.tableau", "Looker", - "com.looker", "Calcite", "org.apache.calcite", "Metabase", "metabase"); + public static final Map CLIENT_MAP = Map.of( + "Tableau", "com.tableau", + "Looker", "com.looker", + "Calcite", "org.apache.calcite", + "Metabase", "metabase"); - public static final Map DRIVER_MAP = ImmutableMap.of(); + public static final Map DRIVER_MAP = Map.of(); private static String getVersionForClass(String name) { try { diff --git a/src/main/java/com/firebolt/jdbc/client/authentication/FireboltAuthenticationClient.java b/src/main/java/com/firebolt/jdbc/client/authentication/FireboltAuthenticationClient.java index 3813555a9..3cf6d6148 100644 --- a/src/main/java/com/firebolt/jdbc/client/authentication/FireboltAuthenticationClient.java +++ b/src/main/java/com/firebolt/jdbc/client/authentication/FireboltAuthenticationClient.java @@ -1,21 +1,18 @@ package com.firebolt.jdbc.client.authentication; -import java.io.IOException; - -import org.apache.commons.lang3.StringUtils; - import com.fasterxml.jackson.databind.ObjectMapper; import com.firebolt.jdbc.client.FireboltClient; import com.firebolt.jdbc.client.authentication.response.FireboltAuthenticationResponse; import com.firebolt.jdbc.connection.FireboltConnection; import com.firebolt.jdbc.connection.FireboltConnectionTokens; import com.firebolt.jdbc.exception.FireboltException; - import lombok.CustomLog; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; +import java.io.IOException; + @CustomLog public class FireboltAuthenticationClient extends FireboltClient { @@ -54,16 +51,16 @@ public FireboltConnectionTokens postConnectionTokens(String host, String user, S } private void logToken(FireboltAuthenticationResponse connectionTokens) { - - if (!StringUtils.isEmpty(connectionTokens.getAccessToken())) { - log.debug("Retrieved access_token"); + logIfPresent(connectionTokens.getAccessToken(), "Retrieved access_token"); + logIfPresent(connectionTokens.getRefreshToken(), "Retrieved refresh_token"); + if (connectionTokens.getExpiresIn() >=- 0) { + log.debug("Retrieved expires_in"); } + } - if (!StringUtils.isEmpty(connectionTokens.getRefreshToken())) { - log.debug("Retrieved refresh_token"); - } - if (0 <= connectionTokens.getExpiresIn()) { - log.debug("Retrieved expires_in"); + private void logIfPresent(String token, String message) { + if (token != null && !token.isEmpty()) { + log.debug(message); } } } diff --git a/src/main/java/com/firebolt/jdbc/client/query/StatementClientImpl.java b/src/main/java/com/firebolt/jdbc/client/query/StatementClientImpl.java index b98509add..8ef8f1eff 100644 --- a/src/main/java/com/firebolt/jdbc/client/query/StatementClientImpl.java +++ b/src/main/java/com/firebolt/jdbc/client/query/StatementClientImpl.java @@ -12,7 +12,6 @@ import com.firebolt.jdbc.statement.rawstatement.RawStatement; import com.firebolt.jdbc.util.CloseableUtil; import com.firebolt.jdbc.util.PropertyUtil; -import com.google.common.collect.ImmutableMap; import lombok.CustomLog; import lombok.NonNull; import okhttp3.Call; @@ -232,7 +231,7 @@ private Optional> getResponseFormatParameter(boolean isQuer } private Map getCancelParameters(String statementId) { - return ImmutableMap.of(FireboltQueryParameterKey.QUERY_ID.getKey(), statementId); + return Map.of(FireboltQueryParameterKey.QUERY_ID.getKey(), statementId); } } diff --git a/src/main/java/com/firebolt/jdbc/service/FireboltAuthenticationService.java b/src/main/java/com/firebolt/jdbc/service/FireboltAuthenticationService.java index 9c393d287..c6681fc70 100644 --- a/src/main/java/com/firebolt/jdbc/service/FireboltAuthenticationService.java +++ b/src/main/java/com/firebolt/jdbc/service/FireboltAuthenticationService.java @@ -1,23 +1,21 @@ package com.firebolt.jdbc.service; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.Optional; -import java.util.concurrent.TimeUnit; - -import org.apache.commons.codec.binary.Hex; -import org.apache.commons.lang3.StringUtils; - import com.firebolt.jdbc.client.authentication.FireboltAuthenticationClient; import com.firebolt.jdbc.connection.FireboltConnectionTokens; import com.firebolt.jdbc.connection.settings.FireboltProperties; import com.firebolt.jdbc.exception.FireboltException; - import lombok.CustomLog; import lombok.EqualsAndHashCode; import lombok.RequiredArgsConstructor; import net.jodah.expiringmap.ExpirationPolicy; import net.jodah.expiringmap.ExpiringMap; +import org.apache.commons.lang3.StringUtils; + +import javax.xml.bind.DatatypeConverter; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Optional; +import java.util.concurrent.TimeUnit; @RequiredArgsConstructor @CustomLog @@ -101,7 +99,7 @@ public ConnectParams(String fireboltHost, String user, String password) throws N MessageDigest sha256Instance = MessageDigest.getInstance("SHA-256"); Optional.ofNullable(user).map(String::getBytes).ifPresent(sha256Instance::update); Optional.ofNullable(password).map(String::getBytes).ifPresent(sha256Instance::update); - this.credentialsHash = new String(Hex.encodeHex(sha256Instance.digest())); + this.credentialsHash = DatatypeConverter.printHexBinary(sha256Instance.digest()); } } } diff --git a/src/main/java/com/firebolt/jdbc/type/BaseType.java b/src/main/java/com/firebolt/jdbc/type/BaseType.java index 8edb64582..e7109ad00 100644 --- a/src/main/java/com/firebolt/jdbc/type/BaseType.java +++ b/src/main/java/com/firebolt/jdbc/type/BaseType.java @@ -1,24 +1,25 @@ package com.firebolt.jdbc.type; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.sql.*; -import java.util.TimeZone; - -import javax.xml.bind.DatatypeConverter; - -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.text.StringEscapeUtils; - import com.firebolt.jdbc.CheckedFunction; import com.firebolt.jdbc.exception.FireboltException; import com.firebolt.jdbc.resultset.column.Column; import com.firebolt.jdbc.type.array.SqlArrayUtil; import com.firebolt.jdbc.type.date.SqlDateUtil; - import lombok.Builder; import lombok.CustomLog; import lombok.Value; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.text.StringEscapeUtils; + +import javax.xml.bind.DatatypeConverter; +import java.math.BigDecimal; +import java.math.BigInteger; +import java.sql.Array; +import java.sql.Date; +import java.sql.SQLException; +import java.sql.Time; +import java.sql.Timestamp; +import java.util.TimeZone; /** This class contains the java types the Firebolt datatypes are mapped to */ @CustomLog @@ -73,14 +74,14 @@ public enum BaseType { conversion -> SqlArrayUtil.transformToSqlArray(conversion.getValue(), conversion.getColumn().getType())), BYTEA(byte[].class, conversion -> { String s = conversion.getValue(); - if (StringUtils.startsWith(s, "\\x")) { - return DatatypeConverter.parseHexBinary(s.substring(2)); - } else if (StringUtils.isEmpty(s)) { + if (s == null || s.isEmpty()) { return new byte[] {}; - } else { - // Cannot convert from other formats (such as 'Escape') for the moment - throw new FireboltException("Cannot convert binary string in non-hex format to byte array"); } + if (s.startsWith("\\x")) { + return DatatypeConverter.parseHexBinary(s.substring(2)); + } + // Cannot convert from other formats (such as 'Escape') for the moment + throw new FireboltException("Cannot convert binary string in non-hex format to byte array"); }); public static final String NULL_VALUE = "\\N"; diff --git a/src/main/java/com/firebolt/jdbc/type/array/SqlArrayUtil.java b/src/main/java/com/firebolt/jdbc/type/array/SqlArrayUtil.java index df794a851..a2ba6b117 100644 --- a/src/main/java/com/firebolt/jdbc/type/array/SqlArrayUtil.java +++ b/src/main/java/com/firebolt/jdbc/type/array/SqlArrayUtil.java @@ -1,22 +1,19 @@ package com.firebolt.jdbc.type.array; -import java.lang.reflect.Array; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -import org.apache.commons.lang3.StringUtils; - import com.firebolt.jdbc.exception.FireboltException; import com.firebolt.jdbc.resultset.column.ColumnType; import com.firebolt.jdbc.type.FireboltDataType; import com.firebolt.jdbc.type.JavaTypeToFireboltSQLString; -import com.google.common.base.CharMatcher; - import lombok.CustomLog; import lombok.NonNull; import lombok.experimental.UtilityClass; +import org.apache.commons.lang3.StringUtils; + +import java.lang.reflect.Array; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; @UtilityClass @CustomLog @@ -102,10 +99,7 @@ private static String getArraySeparator(int dimension) { } private static String removeQuotesAndTransformNull(String s) { - if (StringUtils.equals(s, "NULL")) { - return "\\N"; - } - return CharMatcher.is('\'').trimFrom(s); + return "NULL".equals(s) ? "\\N" : StringUtils.strip(s, "'"); } private static String removeParenthesis(String s) { diff --git a/src/test/java/com/firebolt/jdbc/client/account/FireboltAccountClientTest.java b/src/test/java/com/firebolt/jdbc/client/account/FireboltAccountClientTest.java index 908d24d5c..2ba837462 100644 --- a/src/test/java/com/firebolt/jdbc/client/account/FireboltAccountClientTest.java +++ b/src/test/java/com/firebolt/jdbc/client/account/FireboltAccountClientTest.java @@ -8,8 +8,11 @@ import com.firebolt.jdbc.client.account.response.FireboltEngineResponse; import com.firebolt.jdbc.connection.FireboltConnection; import com.firebolt.jdbc.exception.FireboltException; -import com.google.common.collect.ImmutableMap; -import okhttp3.*; +import okhttp3.Call; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import okhttp3.ResponseBody; import org.junit.function.ThrowingRunnable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -25,11 +28,15 @@ import static com.firebolt.jdbc.client.UserAgentFormatter.userAgent; import static java.lang.String.format; -import static java.net.HttpURLConnection.*; +import static java.net.HttpURLConnection.HTTP_BAD_GATEWAY; +import static java.net.HttpURLConnection.HTTP_NOT_FOUND; +import static java.net.HttpURLConnection.HTTP_OK; import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class FireboltAccountClientTest { @@ -74,7 +81,7 @@ void shouldGetAccountId() throws Exception { FireboltAccountResponse account = fireboltAccountClient.getAccount(HOST, ACCOUNT, ACCESS_TOKEN); - Map expectedHeader = ImmutableMap.of("User-Agent", + Map expectedHeader = Map.of("User-Agent", userAgent("ConnB/2.0.9 JDBC/%s (Java %s; %s %s; ) ConnA/1.0.9"), "Authorization", "Bearer " + ACCESS_TOKEN); @@ -99,7 +106,7 @@ void shouldGetEngineEndpoint() throws Exception { FireboltEngineResponse engine = fireboltAccountClient.getEngine(HOST, ENGINE_NAME, DB_NAME, ACCOUNT_ID, ACCESS_TOKEN); - Map expectedHeader = ImmutableMap.of("User-Agent", + Map expectedHeader = Map.of("User-Agent", userAgent("ConnB/2.0.9 JDBC/%s (Java %s; %s %s; ) ConnA/1.0.9"), "Authorization", "Bearer " + ACCESS_TOKEN); @@ -125,7 +132,7 @@ void shouldGetDbAddress() throws Exception { FireboltDefaultDatabaseEngineResponse fireboltDefaultDatabaseEngineResponse = fireboltAccountClient .getDefaultEngineByDatabaseName(HOST, ACCOUNT_ID, DB_NAME, ACCESS_TOKEN); - Map expectedHeader = ImmutableMap.of("User-Agent", + Map expectedHeader = Map.of("User-Agent", userAgent("ConnB/2.0.9 JDBC/%s (Java %s; %s %s; ) ConnA/1.0.9"), "Authorization", "Bearer " + ACCESS_TOKEN); @@ -149,7 +156,7 @@ void shouldGetEngineId() throws Exception { FireboltEngineIdResponse fireboltEngineIdResponse = fireboltAccountClient.getEngineId(HOST, ACCOUNT_ID, ENGINE_NAME, ACCESS_TOKEN); - Map expectedHeader = ImmutableMap.of("User-Agent", + Map expectedHeader = Map.of("User-Agent", userAgent("ConnB/2.0.9 JDBC/%s (Java %s; %s %s; ) ConnA/1.0.9"), "Authorization", "Bearer " + ACCESS_TOKEN); diff --git a/src/test/java/com/firebolt/jdbc/util/StatementUtilTest.java b/src/test/java/com/firebolt/jdbc/util/StatementUtilTest.java index 805a2cc7f..f051ea3e5 100644 --- a/src/test/java/com/firebolt/jdbc/util/StatementUtilTest.java +++ b/src/test/java/com/firebolt/jdbc/util/StatementUtilTest.java @@ -1,26 +1,32 @@ package com.firebolt.jdbc.util; -import static com.firebolt.jdbc.statement.StatementType.PARAM_SETTING; -import static com.firebolt.jdbc.statement.StatementUtil.isQuery; -import static com.firebolt.jdbc.statement.StatementUtil.replaceParameterMarksWithValues; -import static org.junit.jupiter.api.Assertions.*; +import com.firebolt.jdbc.statement.ParamMarker; +import com.firebolt.jdbc.statement.StatementUtil; +import com.firebolt.jdbc.statement.rawstatement.QueryRawStatement; +import com.firebolt.jdbc.statement.rawstatement.RawStatementWrapper; +import com.firebolt.jdbc.statement.rawstatement.SetParamRawStatement; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.junit.jupiter.api.Test; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; -import java.util.*; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; import java.util.stream.Collectors; -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.junit.jupiter.api.Test; - -import com.firebolt.jdbc.statement.ParamMarker; -import com.firebolt.jdbc.statement.StatementUtil; -import com.firebolt.jdbc.statement.rawstatement.QueryRawStatement; -import com.firebolt.jdbc.statement.rawstatement.RawStatementWrapper; -import com.firebolt.jdbc.statement.rawstatement.SetParamRawStatement; -import com.google.common.collect.ImmutableMap; +import static com.firebolt.jdbc.statement.StatementType.PARAM_SETTING; +import static com.firebolt.jdbc.statement.StatementUtil.isQuery; +import static com.firebolt.jdbc.statement.StatementUtil.replaceParameterMarksWithValues; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; class StatementUtilTest { @@ -178,56 +184,56 @@ void shouldCountParametersFromLongQueryWithComments() { @Test void shouldGetAllQueryParams() { String sql = "SElECT * FROM EMPLOYEES WHERE id = ?"; - assertEquals(ImmutableMap.of(1, 35), StatementUtil.getParamMarketsPositions(sql)); + assertEquals(Map.of(1, 35), StatementUtil.getParamMarketsPositions(sql)); assertEquals(1, StatementUtil.parseToRawStatementWrapper(sql).getSubStatements().size()); } @Test void shouldGetAllQueryParamsWithoutTrimmingRequest() { String sql = " SElECT * FROM EMPLOYEES WHERE id = ?"; - assertEquals(ImmutableMap.of(1, 40), StatementUtil.getParamMarketsPositions(sql)); + assertEquals(Map.of(1, 40), StatementUtil.getParamMarketsPositions(sql)); assertEquals(1, StatementUtil.parseToRawStatementWrapper(sql).getSubStatements().size()); } @Test void shouldGetAllQueryParamsFromIn() { String sql = "SElECT * FROM EMPLOYEES WHERE id IN (?,?)"; - assertEquals(ImmutableMap.of(1, 37, 2, 39), StatementUtil.getParamMarketsPositions(sql)); + assertEquals(Map.of(1, 37, 2, 39), StatementUtil.getParamMarketsPositions(sql)); assertEquals(1, StatementUtil.parseToRawStatementWrapper(sql).getSubStatements().size()); } @Test void shouldGetAllQueryParamsThatAreNotInComments() { String sql = "SElECT * FROM EMPLOYEES WHERE /* ?*/id IN (?,?)"; - assertEquals(ImmutableMap.of(1, 43, 2, 45), StatementUtil.getParamMarketsPositions(sql)); + assertEquals(Map.of(1, 43, 2, 45), StatementUtil.getParamMarketsPositions(sql)); assertEquals(1, StatementUtil.parseToRawStatementWrapper(sql).getSubStatements().size()); } @Test void shouldGetAllQueryParamsThatAreNotInComments2() { String sql = "SElECT * FROM EMPLOYEES WHERE /* ?id IN (?,?)*/"; - assertEquals(ImmutableMap.of(), StatementUtil.getParamMarketsPositions(sql)); + assertEquals(Map.of(), StatementUtil.getParamMarketsPositions(sql)); assertEquals(1, StatementUtil.parseToRawStatementWrapper(sql).getSubStatements().size()); } @Test void shouldGetAllQueryParamsThatAreNotInSingleLineComment() { String sql = "SElECT * FROM EMPLOYEES WHERE id IN --(?,?)\n"; - assertEquals(ImmutableMap.of(), StatementUtil.getParamMarketsPositions(sql)); + assertEquals(Map.of(), StatementUtil.getParamMarketsPositions(sql)); assertEquals(1, StatementUtil.parseToRawStatementWrapper(sql).getSubStatements().size()); } @Test void shouldGetAllQueryParamsThatAreNotInSingleLineComment2() { String sql = "SElECT * FROM EMPLOYEES WHERE id IN --\n(?,?)"; - assertEquals(ImmutableMap.of(1, 40, 2, 42), StatementUtil.getParamMarketsPositions(sql)); + assertEquals(Map.of(1, 40, 2, 42), StatementUtil.getParamMarketsPositions(sql)); assertEquals(1, StatementUtil.parseToRawStatementWrapper(sql).getSubStatements().size()); } @Test void shouldGetAllQueryParamsThatAreNotInBetweenQuotesOrComments() { String sql = "SElECT * FROM EMPLOYEES WHERE id IN --(?,?)\n AND name NOT LIKE '? Hello ? ' AND address LIKE ? AND my_date = ?"; - assertEquals(ImmutableMap.of(1, 93, 2, 109), StatementUtil.getParamMarketsPositions(sql)); + assertEquals(Map.of(1, 93, 2, 109), StatementUtil.getParamMarketsPositions(sql)); assertEquals(1, StatementUtil.parseToRawStatementWrapper(sql).getSubStatements().size()); } @@ -235,7 +241,7 @@ void shouldGetAllQueryParamsThatAreNotInBetweenQuotesOrComments() { void shouldReplaceOneQueryParamsThatAreNotInBetweenQuotesOrComments() { String sql = "SElECT * FROM EMPLOYEES WHERE id IN --(?,?)\n AND name NOT LIKE '? Hello ? ' AND address LIKE ?"; String expectedSql = "SElECT * FROM EMPLOYEES WHERE id IN --(?,?)\n AND name NOT LIKE '? Hello ? ' AND address LIKE '55 Liverpool road%'"; - Map params = ImmutableMap.of(1, "'55 Liverpool road%'"); + Map params = Map.of(1, "'55 Liverpool road%'"); assertEquals(expectedSql, replaceParameterMarksWithValues(params, sql).get(0).getSql()); } @@ -243,7 +249,7 @@ void shouldReplaceOneQueryParamsThatAreNotInBetweenQuotesOrComments() { void shouldReplaceAQueryParam() { String sql = "SElECT * FROM EMPLOYEES WHERE id is ?"; String expectedSql = "SElECT * FROM EMPLOYEES WHERE id is 5"; - Map params = ImmutableMap.of(1, "5"); + Map params = Map.of(1, "5"); assertEquals(expectedSql, replaceParameterMarksWithValues(params, sql).get(0).getSql()); } @@ -251,7 +257,7 @@ void shouldReplaceAQueryParam() { void shouldReplaceMultipleQueryParams() { String sql = "SElECT * FROM EMPLOYEES WHERE id = ? AND name LIKE ? AND dob = ? "; String expectedSql = "SElECT * FROM EMPLOYEES WHERE id = 5 AND name LIKE 'George' AND dob = '1980-05-22' "; - Map params = ImmutableMap.of(1, "5", 2, "'George'", 3, "'1980-05-22'"); + Map params = Map.of(1, "5", 2, "'George'", 3, "'1980-05-22'"); assertEquals(expectedSql, replaceParameterMarksWithValues(params, sql).get(0).getSql()); } @@ -259,7 +265,7 @@ void shouldReplaceMultipleQueryParams() { void shouldReplaceAllQueryParamsThatAreNotInBetweenQuotesOrComments() { String sql = "SElECT * FROM EMPLOYEES WHERE id IN --(?,?)\n AND name NOT LIKE '? Hello ? ' AND address LIKE ? AND my_date = ? AND age = /* */ ?"; String expectedSql = "SElECT * FROM EMPLOYEES WHERE id IN --(?,?)\n AND name NOT LIKE '? Hello ? ' AND address LIKE '55 Liverpool road%' AND my_date = '2022-01-01' AND age = /* */ 5"; - Map params = ImmutableMap.of(1, "'55 Liverpool road%'", 2, "'2022-01-01'", 3, "5"); + Map params = Map.of(1, "'55 Liverpool road%'", 2, "'2022-01-01'", 3, "5"); assertEquals(expectedSql, replaceParameterMarksWithValues(params, sql).get(0).getSql()); } @@ -269,7 +275,7 @@ void shouldReplaceMultipleQueryParamsInaMultiStatement() { String expectedFirstSql = "SElECT * FROM EMPLOYEES WHERE id = 5 AND name LIKE 'George' AND dob = '1980-05-22' ; "; String expectedSecondSql = "SELECT * FROM cats WHERE name IN ('Elizabeth', 'Charles')"; - Map params = ImmutableMap.of(1, "5", 2, "'George'", 3, "'1980-05-22'", 4, "'Elizabeth'", 5, + Map params = Map.of(1, "5", 2, "'George'", 3, "'1980-05-22'", 4, "'Elizabeth'", 5, "'Charles'"); assertEquals(expectedFirstSql, replaceParameterMarksWithValues(params, sql).get(0).getSql()); assertEquals(expectedSecondSql, replaceParameterMarksWithValues(params, sql).get(1).getSql()); @@ -277,7 +283,7 @@ void shouldReplaceMultipleQueryParamsInaMultiStatement() { @Test void shouldThrowExceptionWhenTheNumberOfParamsIsNotTheSameAsTheNumberOfParamMarkers() { - Map params = ImmutableMap.of(1, "1"); + Map params = Map.of(1, "1"); IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> replaceParameterMarksWithValues(params, "SELECT 1;")); assertEquals(