-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support of new identity: code, tests and CI + VERSION 3.0.0-SNAPSHOT
- Loading branch information
1 parent
0e17fe3
commit 7dc734c
Showing
64 changed files
with
1,482 additions
and
1,559 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
version=2.4.5-SNAPSHOT | ||
version=3.0.0-SNAPSHOT | ||
jdbcVersion=4.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,92 @@ | ||
package integration; | ||
|
||
import lombok.Value; | ||
|
||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.stream.Stream; | ||
|
||
import static java.lang.String.format; | ||
import static java.lang.System.getProperty; | ||
import static java.util.stream.Collectors.joining; | ||
|
||
@Value | ||
public class ConnectionInfo { | ||
private static ConnectionInfo INSTANCE; | ||
String password; | ||
String user; | ||
String api; | ||
String database; | ||
private static final String JDBC_URL_PREFIX = "jdbc:firebolt:"; | ||
private static volatile ConnectionInfo INSTANCE; | ||
// principal and secret are used here instead of client_id and client_secret respectively as more common term also used in java security API. | ||
private final String principal; | ||
private final String secret; | ||
private final String env; | ||
private final String database; | ||
private final String account; | ||
private final String engine; | ||
|
||
private ConnectionInfo() { | ||
password = Optional.ofNullable(System.getProperty("password")).map(p -> p.replace("\"", "")).orElse(null); | ||
user = Optional.ofNullable(System.getProperty("user")).map(u -> u.replace("\"", "")).orElse(null); | ||
api = System.getProperty("api"); | ||
database = System.getProperty("db"); | ||
this( | ||
getTrimmedProperty("client_id", "user"), | ||
getTrimmedProperty("client_secret", "password"), | ||
getProperty("env"), | ||
getProperty("db"), | ||
getProperty("account"), | ||
getProperty("engine") | ||
); | ||
} | ||
|
||
public ConnectionInfo(String principal, String secret, String env, String database, String account, String engine) { | ||
this.principal = principal; | ||
this.secret = secret; | ||
this.env = env; | ||
this.database = database; | ||
this.account = account; | ||
this.engine = engine; | ||
} | ||
|
||
public static ConnectionInfo getInstance() { | ||
if (INSTANCE == null) { | ||
INSTANCE = new ConnectionInfo(); | ||
synchronized (ConnectionInfo.class) { | ||
if (INSTANCE == null) { | ||
INSTANCE = new ConnectionInfo(); | ||
} | ||
} | ||
} | ||
return INSTANCE; | ||
} | ||
|
||
private static String getTrimmedProperty(String name, String alias) { | ||
return Optional.ofNullable(getProperty(name, getProperty(alias))).map(u -> u.replace("\"", "")).orElse(null); | ||
} | ||
|
||
public String getPrincipal() { | ||
return principal; | ||
} | ||
|
||
public String getSecret() { | ||
return secret; | ||
} | ||
|
||
public String getEnv() { | ||
return env; | ||
} | ||
|
||
public String getDatabase() { | ||
return database; | ||
} | ||
|
||
public String getAccount() { | ||
return account; | ||
} | ||
|
||
public String getEngine() { | ||
return engine; | ||
} | ||
|
||
public String toJdbcUrl() { | ||
String params = Stream.of(param("env", env), param("engine", engine), param("account", account)).filter(Objects::nonNull).collect(joining("&")); | ||
if (!params.isEmpty()) { | ||
params = "?" + params; | ||
} | ||
return JDBC_URL_PREFIX + database + params; | ||
} | ||
|
||
private String param(String name, String value) { | ||
return value == null ? null : format("%s=%s", name, value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/integrationTest/java/integration/MockWebServerAwareIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package integration; | ||
|
||
import okhttp3.mockwebserver.MockResponse; | ||
import okhttp3.mockwebserver.MockWebServer; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
|
||
import java.io.IOException; | ||
|
||
import static java.lang.String.format; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public abstract class MockWebServerAwareIntegrationTest extends IntegrationTest { | ||
protected MockWebServer mockBackEnd; | ||
private final int INIT_STATEMENTS_COUNT = 1; // The statement that validates that DB exists. | ||
|
||
@BeforeEach | ||
void setUp() throws IOException { | ||
mockBackEnd = new MockWebServer(); | ||
mockBackEnd.start(); | ||
mockBackEnd.enqueue(new MockResponse().setResponseCode(200).setBody(format("database_name%nstring%n%s", System.getProperty("db")))); | ||
} | ||
|
||
@AfterEach | ||
void tearDown() throws IOException { | ||
mockBackEnd.close(); | ||
} | ||
|
||
|
||
protected void assertMockBackendRequestsCount(int expected) { | ||
assertEquals(INIT_STATEMENTS_COUNT + expected, mockBackEnd.getRequestCount()); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/integrationTest/java/integration/tests/NumericTypesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package integration.tests; | ||
|
||
import integration.IntegrationTest; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.sql.Connection; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.sql.Statement; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class NumericTypesTest extends IntegrationTest { | ||
@Test | ||
void shouldHaveCorrectInfo() throws SQLException { | ||
try (Connection connection = this.createConnection(null); | ||
Statement statement = connection.createStatement(); | ||
ResultSet resultSet = statement.executeQuery("SELECT 3::decimal")) { | ||
resultSet.next(); | ||
assertEquals(9, resultSet.getMetaData().getScale(1)); | ||
assertEquals(38, resultSet.getMetaData().getPrecision(1)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.