Package net.shibboleth.shared.testing

# Class DatabaseTestingSupport

java.lang.Object
net.shibboleth.shared.testing.DatabaseTestingSupport

public final class DatabaseTestingSupport extends Object
Helper class for testing database-backed classes using custom DDL and SQL.

## Field Summary

Fields
Modifier and Type
Field
Description
`private static org.slf4j.Logger`
`log`
Logger.

## Constructor Summary

Constructors
Modifier
Constructor
Description
`private`
`DatabaseTestingSupport()`
Hidden constructor.

## Method Summary

Modifier and Type
Method
Description
`protected static void`
`ExecuteUpdate(String sql, DataSource source)`
Execute an SQP update.
`static DataSource`
`GetDataSourceFromHsqlServer(String initializingSQLFile, String server)`
Summons up a database connection to an hsqldb server running somewhere.
`protected static DataSource`
`GetDataSourceFromUrl(String initializingSQLFile, String JdbcUri)`
Createa data source from a provided URL.
`static DataSource`
`GetMockDataSource(String initializingSQLFile, String identifier)`
Summons up an in memory database with the provided identifier.
`static void`
`InitializeDataSource(String initializingSQLFile, DataSource source)`
Initialize SQL database.
`static void`
`InitializeDataSourceFromFile(String sqlFile, DataSource source)`
Initialize SQL database.
`protected static String`
`ReadSqlFromFile(String initializingSQLFile)`
Read some SQL from a file.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### log

@Nonnull private static org.slf4j.Logger log
Logger.

## Constructor Details

### DatabaseTestingSupport

private DatabaseTestingSupport()
Hidden constructor.

## Method Details

### InitializeDataSource

public static void InitializeDataSource(@Nullable String initializingSQLFile, @Nonnull DataSource source)
Initialize SQL database.

Parameters:
  `initializingSQLFile` - path to SQL to run at init time
  `source` - the data source

### ReadSqlFromFile

@Nullable protected static String ReadSqlFromFile(@Nullable String initializingSQLFile)
Read some SQL from a file.

Parameters:
  `initializingSQLFile` - the file name
Returns:
  the data

### ExecuteUpdate

protected static void ExecuteUpdate(@Nullable String sql, DataSource source)
Execute an SQP update.

Parameters:
  `sql` - what to execute
  `source` - what to executer it on

### GetMockDataSource

@Nonnull public static DataSource GetMockDataSource(@Nonnull String initializingSQLFile, @Nonnull String identifier)
Summons up an in memory database with the provided identifier. The contents of the resource stream (if any) are then submitted to the database (so as to allow initializing to a known state.

Parameters:
  `initializingSQLFile` - a file in the classpath with SQL files
  `identifier` - a name to uniquify this database.
Returns:
  a DataSource which can then be used for testing.

### GetDataSourceFromHsqlServer

@Nonnull public static DataSource GetDataSourceFromHsqlServer(@Nonnull String initializingSQLFile, @Nonnull String server)
Summons up a database connection to an hsqldb server running somewhere.

Parameters:
  `initializingSQLFile` - a file in the classpath with SQL files
  `server` - the server name and database name. For instance "//localhost/testdb"
Returns:
  a DataSource which can then be used for testing

### InitializeDataSourceFromFile

public static void InitializeDataSourceFromFile(String sqlFile, DataSource source)
Initialize SQL database.

Parameters:
  `sqlFile` - path to file containing multiple SQL statements separated by semicolons.
  `source` - data source

### GetDataSourceFromUrl

@Nonnull protected static DataSource GetDataSourceFromUrl(@Nonnull String initializingSQLFile, @Nonnull String JdbcUri)
Createa data source from a provided URL.

Parameters:
  `initializingSQLFile` - what to initialize with
  `JdbcUri` - the URI
Returns:
  the `DataSource`