Package csw.testkit

Class DatabaseTestKit

java.lang.Object
csw.testkit.DatabaseTestKit
All Implemented Interfaces:
EmbeddedPG

public final class DatabaseTestKit extends Object implements 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 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 DatabaseTestKit

      When 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 interface EmbeddedPG
    • system

      public akka.actor.typed.ActorSystem<?> system()
      Specified by:
      system in interface EmbeddedPG
    • timeout

      public akka.util.Timeout timeout()
      Specified by:
      timeout in interface EmbeddedPG
    • startDatabaseService

      public csw.location.api.scaladsl.RegistrationResult startDatabaseService(int serverPort)
      Scala API to Start Database service

      It 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 service

      When the test has completed, make sure you shutdown Database service. This will terminate actor system and postgres server.

    • databaseServiceFactory

      public DatabaseServiceFactory databaseServiceFactory(String dbUserName, String dbPassword)
      Create an instance of DatabaseServiceFactory with given username and password

      Parameters:
      dbUserName - - username to be used to create the database client with the DatabaseServiceFactory
      dbPassword - - password to be used to create the database client with the DatabaseServiceFactory
      Returns:
      a handle of DatabaseServiceFactory
    • dslContext

      public org.jooq.DSLContext dslContext(String dbName)
      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