-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use stringbuilder to construct default jdbc connection string and add…
… unit tests
- Loading branch information
Showing
6 changed files
with
231 additions
and
8 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
59 changes: 59 additions & 0 deletions
59
...test/java/com/amazonaws/athena/connector/lambda/connection/EnvironmentPropertiesTest.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,59 @@ | ||
package com.amazonaws.athena.connector.lambda.connection; | ||
|
||
/*- | ||
* #%L | ||
* Amazon Athena Query Federation SDK | ||
* %% | ||
* Copyright (C) 2019 Amazon Web Services | ||
* %% | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* #L% | ||
*/ | ||
|
||
import software.amazon.awssdk.services.glue.model.AuthenticationConfiguration; | ||
|
||
import org.junit.Test; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static com.amazonaws.athena.connector.lambda.connection.EnvironmentConstants.KMS_KEY_ID; | ||
import static com.amazonaws.athena.connector.lambda.connection.EnvironmentConstants.SECRET_NAME; | ||
import static com.amazonaws.athena.connector.lambda.connection.EnvironmentConstants.SPILL_KMS_KEY_ID; | ||
import static org.junit.Assert.*; | ||
|
||
public class EnvironmentPropertiesTest | ||
{ | ||
private static final String EXAMPLE_SECRET_ARN = "arn:aws:secretsmanager:us-east-1:012345678912:secret:secretname-CMyiKm"; | ||
private static final String EXAMPLE_KMS_KEY_ID = "1234abcd-12ab-34cd-56ef-1234567890ab"; | ||
|
||
@Test | ||
public void authenticationConfigurationToMapTest() | ||
{ | ||
AuthenticationConfiguration auth = AuthenticationConfiguration.builder().secretArn(EXAMPLE_SECRET_ARN).build(); | ||
Map<String, String> authMap = new EnvironmentProperties().authenticationConfigurationToMap(auth); | ||
assertEquals("secretname", authMap.get(SECRET_NAME)); | ||
} | ||
|
||
@Test | ||
public void athenaPropertiesToEnvironmentTest() | ||
{ | ||
Map<String, String> athenaProperties = new HashMap<>(); | ||
athenaProperties.put(SPILL_KMS_KEY_ID, EXAMPLE_KMS_KEY_ID); | ||
athenaProperties = new EnvironmentProperties().athenaPropertiesToEnvironment(athenaProperties); | ||
|
||
assertFalse(athenaProperties.containsKey(SPILL_KMS_KEY_ID)); | ||
assertTrue(athenaProperties.containsKey(KMS_KEY_ID)); | ||
assertEquals(EXAMPLE_KMS_KEY_ID, athenaProperties.get(KMS_KEY_ID)); | ||
} | ||
} |
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
54 changes: 54 additions & 0 deletions
54
...l/src/test/java/com/amazonaws/athena/connectors/mysql/MySqlEnvironmentPropertiesTest.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,54 @@ | ||
package com.amazonaws.athena.connectors.mysql; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static com.amazonaws.athena.connector.lambda.connection.EnvironmentConstants.DATABASE; | ||
import static com.amazonaws.athena.connector.lambda.connection.EnvironmentConstants.DEFAULT; | ||
import static com.amazonaws.athena.connector.lambda.connection.EnvironmentConstants.HOST; | ||
import static com.amazonaws.athena.connector.lambda.connection.EnvironmentConstants.JDBC_PARAMS; | ||
import static com.amazonaws.athena.connector.lambda.connection.EnvironmentConstants.PORT; | ||
import static com.amazonaws.athena.connector.lambda.connection.EnvironmentConstants.SECRET_NAME; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class MySqlEnvironmentPropertiesTest | ||
{ | ||
Map<String, String> connectionProperties; | ||
MySqlEnvironmentProperties mySqlEnvironmentProperties; | ||
|
||
@Before | ||
public void setUp() | ||
{ | ||
connectionProperties = new HashMap<>(); | ||
connectionProperties.put(HOST, "mysql.host"); | ||
connectionProperties.put(PORT, "3306"); | ||
connectionProperties.put(DATABASE, "test"); | ||
connectionProperties.put(JDBC_PARAMS, "key=value&key2=value2"); | ||
connectionProperties.put(SECRET_NAME, "secret"); | ||
mySqlEnvironmentProperties = new MySqlEnvironmentProperties(); | ||
} | ||
|
||
@Test | ||
public void connectionPropertiesWithJdbcParams() | ||
{ | ||
String connectionString = "mysql://jdbc:mysql://mysql.host:3306/test?key=value&key2=value2&${secret}"; | ||
Map<String, String> mysqlConnectionProperties = mySqlEnvironmentProperties.connectionPropertiesToEnvironment(connectionProperties); | ||
assertTrue(mysqlConnectionProperties.containsKey(DEFAULT)); | ||
assertEquals(connectionString, mysqlConnectionProperties.get(DEFAULT)); | ||
} | ||
|
||
@Test | ||
public void connectionPropertiesWithoutJdbcParams() | ||
{ | ||
Map<String, String> noJdbcParams = new HashMap<>(connectionProperties); | ||
noJdbcParams.remove(JDBC_PARAMS); | ||
String connectionString = "mysql://jdbc:mysql://mysql.host:3306/test?${secret}"; | ||
Map<String, String> mysqlConnectionProperties = mySqlEnvironmentProperties.connectionPropertiesToEnvironment(noJdbcParams); | ||
assertTrue(mysqlConnectionProperties.containsKey(DEFAULT)); | ||
assertEquals(connectionString, mysqlConnectionProperties.get(DEFAULT)); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
.../java/com/amazonaws/athena/connectors/postgresql/PostGreSqlEnvironmentPropertiesTest.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,54 @@ | ||
package com.amazonaws.athena.connectors.postgresql; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static com.amazonaws.athena.connector.lambda.connection.EnvironmentConstants.DATABASE; | ||
import static com.amazonaws.athena.connector.lambda.connection.EnvironmentConstants.DEFAULT; | ||
import static com.amazonaws.athena.connector.lambda.connection.EnvironmentConstants.HOST; | ||
import static com.amazonaws.athena.connector.lambda.connection.EnvironmentConstants.JDBC_PARAMS; | ||
import static com.amazonaws.athena.connector.lambda.connection.EnvironmentConstants.PORT; | ||
import static com.amazonaws.athena.connector.lambda.connection.EnvironmentConstants.SECRET_NAME; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class PostGreSqlEnvironmentPropertiesTest | ||
{ | ||
Map<String, String> connectionProperties; | ||
PostGreSqlEnvironmentProperties postGreSqlEnvironmentProperties; | ||
|
||
@Before | ||
public void setUp() | ||
{ | ||
connectionProperties = new HashMap<>(); | ||
connectionProperties.put(HOST, "postgres.host"); | ||
connectionProperties.put(PORT, "5432"); | ||
connectionProperties.put(DATABASE, "default"); | ||
connectionProperties.put(JDBC_PARAMS, "key=value&key2=value2"); | ||
connectionProperties.put(SECRET_NAME, "secret"); | ||
postGreSqlEnvironmentProperties = new PostGreSqlEnvironmentProperties(); | ||
} | ||
|
||
@Test | ||
public void connectionPropertiesWithJdbcParams() | ||
{ | ||
String connectionString = "postgres://jdbc:postgresql://postgres.host:5432/default?key=value&key2=value2&${secret}"; | ||
Map<String, String> pgsqlConnectionProperties = postGreSqlEnvironmentProperties.connectionPropertiesToEnvironment(connectionProperties); | ||
assertTrue(pgsqlConnectionProperties.containsKey(DEFAULT)); | ||
assertEquals(connectionString, pgsqlConnectionProperties.get(DEFAULT)); | ||
} | ||
|
||
@Test | ||
public void connectionPropertiesWithoutJdbcParams() | ||
{ | ||
Map<String, String> noJdbcParams = new HashMap<>(connectionProperties); | ||
noJdbcParams.remove(JDBC_PARAMS); | ||
String connectionString = "postgres://jdbc:postgresql://postgres.host:5432/default?${secret}"; | ||
Map<String, String> pgsqlConnectionProperties = postGreSqlEnvironmentProperties.connectionPropertiesToEnvironment(noJdbcParams); | ||
assertTrue(pgsqlConnectionProperties.containsKey(DEFAULT)); | ||
assertEquals(connectionString, pgsqlConnectionProperties.get(DEFAULT)); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...test/java/com/amazonaws/athena/connectors/redshift/RedshiftEnvironmentPropertiesTest.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,54 @@ | ||
package com.amazonaws.athena.connectors.redshift; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static com.amazonaws.athena.connector.lambda.connection.EnvironmentConstants.DATABASE; | ||
import static com.amazonaws.athena.connector.lambda.connection.EnvironmentConstants.DEFAULT; | ||
import static com.amazonaws.athena.connector.lambda.connection.EnvironmentConstants.HOST; | ||
import static com.amazonaws.athena.connector.lambda.connection.EnvironmentConstants.JDBC_PARAMS; | ||
import static com.amazonaws.athena.connector.lambda.connection.EnvironmentConstants.PORT; | ||
import static com.amazonaws.athena.connector.lambda.connection.EnvironmentConstants.SECRET_NAME; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class RedshiftEnvironmentPropertiesTest | ||
{ | ||
Map<String, String> connectionProperties; | ||
RedshiftEnvironmentProperties redshiftEnvironmentProperties; | ||
|
||
@Before | ||
public void setUp() | ||
{ | ||
connectionProperties = new HashMap<>(); | ||
connectionProperties.put(HOST, "redshift.host"); | ||
connectionProperties.put(PORT, "5439"); | ||
connectionProperties.put(DATABASE, "default"); | ||
connectionProperties.put(JDBC_PARAMS, "key=value&key2=value2"); | ||
connectionProperties.put(SECRET_NAME, "secret"); | ||
redshiftEnvironmentProperties = new RedshiftEnvironmentProperties(); | ||
} | ||
|
||
@Test | ||
public void connectionPropertiesWithJdbcParams() | ||
{ | ||
String connectionString = "redshift://jdbc:redshift://redshift.host:5439/default?key=value&key2=value2&${secret}"; | ||
Map<String, String> mysqlConnectionProperties = redshiftEnvironmentProperties.connectionPropertiesToEnvironment(connectionProperties); | ||
assertTrue(mysqlConnectionProperties.containsKey(DEFAULT)); | ||
assertEquals(connectionString, mysqlConnectionProperties.get(DEFAULT)); | ||
} | ||
|
||
@Test | ||
public void connectionPropertiesWithoutJdbcParams() | ||
{ | ||
Map<String, String> noJdbcParams = new HashMap<>(connectionProperties); | ||
noJdbcParams.remove(JDBC_PARAMS); | ||
String connectionString = "redshift://jdbc:redshift://redshift.host:5439/default?${secret}"; | ||
Map<String, String> mysqlConnectionProperties = redshiftEnvironmentProperties.connectionPropertiesToEnvironment(noJdbcParams); | ||
assertTrue(mysqlConnectionProperties.containsKey(DEFAULT)); | ||
assertEquals(connectionString, mysqlConnectionProperties.get(DEFAULT)); | ||
} | ||
} |