Package csw.testkit
Class DatabaseTestKit
java.lang.Object
csw.testkit.DatabaseTestKit
- All Implemented Interfaces:
EmbeddedPG
DatabaseTestKit supports starting Database server using embedded postgres
and registering it with location service, and creating a client for the database server
Example:
private val testKit = DatabaseTestKit()
// starting postgres server
// it will also register DatabaseService with location service
testKit.startDatabaseService()
// stopping postgres server
testKit.shutdownDatabaseService()
//creates an instance of database service factory
val dbServiceFactory = testKit.databaseServiceFactory()
//creates a client for the particular database in database server
val dsl = testKit.dslContext()
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic DatabaseTestKit
apply
(akka.actor.typed.ActorSystem<akka.actor.typed.SpawnProtocol.Command> actorSystem, TestKitSettings testKitSettings) Create a DatabaseTestKitdatabaseServiceFactory
(String dbUserName, String dbPassword) Create an instance of DatabaseServiceFactory with given username and passwordorg.jooq.DSLContext
dslContext
(String dbName) Create a client for the database server of the given dbName with default username and password(both are postgres)protected csw.location.api.scaladsl.LocationService
void
Shutdown Database servicecsw.location.api.scaladsl.RegistrationResult
startDatabaseService
(int serverPort) Scala API to Start Database serviceakka.actor.typed.ActorSystem<?>
system()
akka.util.Timeout
timeout()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface csw.testkit.database.EmbeddedPG
addJvmShutdownHook, shutdown, start
-
Constructor Details
-
DatabaseTestKit
public DatabaseTestKit()
-
-
Method Details
-
apply
public static DatabaseTestKit apply(akka.actor.typed.ActorSystem<akka.actor.typed.SpawnProtocol.Command> actorSystem, TestKitSettings testKitSettings) Create a DatabaseTestKitWhen the test has completed you should shutdown the Database service with
EmbeddedPG.shutdown()
.- Parameters:
actorSystem
- (undocumented)testKitSettings
- (undocumented)- Returns:
- handle to DatabaseTestKit which can be used to start and stop Database service
-
locationService
protected csw.location.api.scaladsl.LocationService locationService()- Specified by:
locationService
in interfaceEmbeddedPG
-
system
public akka.actor.typed.ActorSystem<?> system()- Specified by:
system
in interfaceEmbeddedPG
-
timeout
public akka.util.Timeout timeout()- Specified by:
timeout
in interfaceEmbeddedPG
-
startDatabaseService
public csw.location.api.scaladsl.RegistrationResult startDatabaseService(int serverPort) Scala API to Start Database serviceIt will start postgres server on provided port and then register's Database service with location service
- Parameters:
serverPort
- (undocumented)- Returns:
- (undocumented)
-
shutdownDatabaseService
public void shutdownDatabaseService()Shutdown Database serviceWhen the test has completed, make sure you shutdown Database service. This will terminate actor system and postgres server.
-
databaseServiceFactory
Create an instance of DatabaseServiceFactory with given username and password- Parameters:
dbUserName
- - username to be used to create the database client with the DatabaseServiceFactorydbPassword
- - password to be used to create the database client with the DatabaseServiceFactory- Returns:
- a handle of
DatabaseServiceFactory
-
dslContext
Create a client for the database server of the given dbName with default username and password(both are postgres)- Parameters:
dbName
- - name of the database in database server in which queries will be made- Returns:
- a handle of
DSLContext
to make sql query
-