-
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.
separated tests of different connections
- Loading branch information
1 parent
cd9b0b2
commit 3d8f4e4
Showing
5 changed files
with
148 additions
and
51 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
71 changes: 71 additions & 0 deletions
71
.../java/com/firebolt/jdbc/connection/FireboltConnectionServiceSecretAuthenticationTest.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,71 @@ | ||
package com.firebolt.jdbc.connection; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
|
||
import java.sql.DatabaseMetaData; | ||
import java.sql.SQLException; | ||
import java.util.Properties; | ||
|
||
import static java.lang.String.format; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.argThat; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.verifyNoInteractions; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class FireboltConnectionServiceSecretAuthenticationTest extends FireboltConnectionTest { | ||
private static final String SYSTEM_ENGINE_URL = "jdbc:firebolt:db?env=dev&account=dev"; | ||
|
||
@Test | ||
void shouldNotValidateConnectionWhenCallingIsValidWhenUsingSystemEngine() throws SQLException { | ||
Properties propertiesWithSystemEngine = new Properties(connectionProperties); | ||
try (FireboltConnection fireboltConnection = createConnection(SYSTEM_ENGINE_URL, propertiesWithSystemEngine)) { | ||
fireboltConnection.isValid(500); | ||
verifyNoInteractions(fireboltStatementService); | ||
} | ||
} | ||
|
||
@Test | ||
void shouldNotGetEngineUrlOrDefaultEngineUrlWhenUsingSystemEngine() throws SQLException { | ||
connectionProperties.put("database", "my_db"); | ||
when(fireboltGatewayUrlService.getUrl(any(), any())).thenReturn("http://my_endpoint"); | ||
|
||
try (FireboltConnection connection = createConnection(SYSTEM_ENGINE_URL, connectionProperties)) { | ||
verify(fireboltEngineService, times(0)).getEngine(argThat(props -> "my_db".equals(props.getDatabase()))); | ||
assertEquals("my_endpoint", connection.getSessionProperties().getHost()); | ||
} | ||
} | ||
|
||
@Test | ||
void noEngineAndDb() throws SQLException { | ||
when(fireboltGatewayUrlService.getUrl(any(), any())).thenReturn("http://my_endpoint"); | ||
|
||
try (FireboltConnection connection = createConnection("jdbc:firebolt:?env=dev&account=dev", connectionProperties)) { | ||
assertEquals("my_endpoint", connection.getSessionProperties().getHost()); | ||
assertNull(connection.getSessionProperties().getEngine()); | ||
assertTrue(connection.getSessionProperties().isSystemEngine()); | ||
} | ||
} | ||
|
||
@ParameterizedTest(name = "{0}") | ||
@CsvSource({ | ||
"regular engine,&engine=eng,false", | ||
"system engine,'',true" // system engine is readonly | ||
}) | ||
void getMetadata(String testName, String engineParameter, boolean readOnly) throws SQLException { | ||
try (FireboltConnection connection = createConnection(format("jdbc:firebolt:db?env=dev&account=dev%s", engineParameter), connectionProperties)) { | ||
DatabaseMetaData dbmd = connection.getMetaData(); | ||
assertEquals(readOnly, dbmd.isReadOnly()); | ||
} | ||
} | ||
|
||
protected FireboltConnection createConnection(String url, Properties props) throws SQLException { | ||
return new FireboltConnectionServiceSecretAuthentication(url, props, fireboltAuthenticationService, fireboltGatewayUrlService, fireboltStatementService, fireboltEngineService, fireboltAccountIdService); | ||
} | ||
} |
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
65 changes: 65 additions & 0 deletions
65
...t/java/com/firebolt/jdbc/connection/FireboltConnectionUserPasswordAuthenticationTest.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,65 @@ | ||
package com.firebolt.jdbc.connection; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
|
||
import java.sql.DatabaseMetaData; | ||
import java.sql.SQLException; | ||
import java.util.Properties; | ||
|
||
import static java.lang.String.format; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.mockito.ArgumentMatchers.argThat; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.verifyNoInteractions; | ||
|
||
public class FireboltConnectionUserPasswordAuthenticationTest extends FireboltConnectionTest { | ||
private static final String SYSTEM_ENGINE_URL = "jdbc:firebolt:db?env=dev&account=dev&engine=system"; | ||
@Test | ||
void shouldNotValidateConnectionWhenCallingIsValidWhenUsingSystemEngine() throws SQLException { | ||
Properties propertiesWithSystemEngine = new Properties(connectionProperties); | ||
try (FireboltConnection fireboltConnection = createConnection(SYSTEM_ENGINE_URL, propertiesWithSystemEngine)) { | ||
fireboltConnection.isValid(500); | ||
verifyNoInteractions(fireboltStatementService); | ||
} | ||
} | ||
|
||
@Test | ||
void shouldNotGetEngineUrlOrDefaultEngineUrlWhenUsingSystemEngine() throws SQLException { | ||
connectionProperties.put("database", "my_db"); | ||
try (FireboltConnection connection = createConnection(SYSTEM_ENGINE_URL, connectionProperties)) { | ||
verify(fireboltEngineService, times(1)).getEngine(argThat(props -> "my_db".equals(props.getDatabase()) && "system".equals(props.getEngine()))); | ||
assertEquals("endpoint", connection.getSessionProperties().getHost()); | ||
} | ||
} | ||
|
||
|
||
@Test | ||
void noEngineAndDb() throws SQLException { | ||
try (FireboltConnection connection = createConnection("jdbc:firebolt:?env=dev&account=dev", connectionProperties)) { | ||
assertEquals("endpoint", connection.getSessionProperties().getHost()); | ||
assertNotNull(connection.getSessionProperties().getEngine()); | ||
assertFalse(connection.getSessionProperties().isSystemEngine()); | ||
} | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource({ | ||
"eng,false", | ||
"system,true" // system engine is readonly | ||
}) | ||
void getMetadata(String engine, boolean readOnly) throws SQLException { | ||
try (FireboltConnection connection = createConnection(format("jdbc:firebolt:db?env=dev&engine=%s&account=dev", engine), connectionProperties)) { | ||
DatabaseMetaData dbmd = connection.getMetaData(); | ||
assertEquals(readOnly, dbmd.isReadOnly()); | ||
} | ||
} | ||
|
||
protected FireboltConnection createConnection(String url, Properties props) throws SQLException { | ||
return new FireboltConnectionUserPasswordAuthentication(url, props, fireboltAuthenticationService, fireboltStatementService, fireboltEngineService); | ||
} | ||
} |