Skip to content

Commit

Permalink
Provide a way to override global env properties in a test ConnectionP…
Browse files Browse the repository at this point in the history
…roviderBuilder
  • Loading branch information
marko-bekhta authored and beikov committed May 13, 2024
1 parent 7321ca4 commit 641a7dd
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collections;
import java.util.Map;
import java.util.Properties;
import javax.sql.DataSource;

Expand All @@ -26,7 +27,6 @@

import org.hibernate.testing.DialectCheck;
import org.hibernate.testing.jdbc.ConnectionProviderDelegate;
import org.hibernate.testing.jdbc.SharedDriverManagerConnectionProviderImpl;
import org.hibernate.testing.util.ServiceRegistryUtil;

/**
Expand All @@ -46,7 +46,14 @@ public class ConnectionProviderBuilder implements DialectCheck {
public static final String PASS = "";

public static Properties getConnectionProviderProperties(String dbName) {
return getConnectionProviderProperties( dbName, Collections.emptyMap() );
}

public static Properties getConnectionProviderProperties(String dbName, Map<String, String> environmentOverrides) {
final Properties globalProperties = Environment.getProperties();
// since returned global properties are a copy, we just add our overrides to them:
globalProperties.putAll( environmentOverrides );

assert globalProperties.getProperty( Environment.URL ).startsWith( "jdbc:h2:" )
: "Connection provider properties are only usable when running against H2";
final Properties props = new Properties( null );
Expand Down Expand Up @@ -95,6 +102,10 @@ public static ConnectionProvider buildConnectionProvider(String dbName) {
return buildConnectionProvider( getConnectionProviderProperties( dbName ), false );
}

public static ConnectionProvider buildConnectionProvider(String dbName, Map<String, String> environmentOverrides) {
return buildConnectionProvider( getConnectionProviderProperties( dbName, environmentOverrides ), false );
}

public static ConnectionProvider buildDataSourceConnectionProvider(String dbName) {
final Properties globalProperties = Environment.getProperties();
assert globalProperties.getProperty( Environment.URL ).startsWith( "jdbc:h2:" )
Expand Down

0 comments on commit 641a7dd

Please sign in to comment.