Class AbstractCosmosDbJunit<T extends AbstractCosmosDbJunit<T>>

java.lang.Object
net.officefloor.nosql.cosmosdb.test.AbstractCosmosDbJunit<T>
All Implemented Interfaces:
CosmosEmulatorInstance.FailureFactory
Direct Known Subclasses:
CosmosDbExtension, CosmosDbRule

public abstract class AbstractCosmosDbJunit<T extends AbstractCosmosDbJunit<T>> extends Object implements CosmosEmulatorInstance.FailureFactory

Abstract JUnit CosmosDb functionality.

Given the slow nature of CosmosDb emulator, keeps running for all tests and only shuts down on JVM exit. However, will wipe databases between tests to have consistent starting state.

Author:
Daniel Sagenschneider
  • Field Details

    • PROPERTY_ENABLE_COSMOS_TESTS

      public static final String PROPERTY_ENABLE_COSMOS_TESTS
      Property to flag to indicate if enable Cosmos tests.
      See Also:
    • PROPERTY_SKIP_FAILED_COSMOS

      public static final String PROPERTY_SKIP_FAILED_COSMOS
      Property to flag skipping failed Cosmos DB tests. This is useful, as the Cosmos DB Emulator is found to not be stable on linux. Happy to be provided improvements, however this is currently necessary for clean builds.
      See Also:
    • SKIP_MESSAGE

      protected static final String SKIP_MESSAGE
      Skip message.
      See Also:
  • Constructor Details

  • Method Details

    • isSkipTests

      public static boolean isSkipTests()
      Indicates whether skipping all CosmosDb tests.
      Returns:
      true if skipping all CosmosDb tests.
    • isSkipFailure

      public static boolean isSkipFailure()
      Indicates whether skipping failures.
      Returns:
      true if skipping failures.
    • setupCosmosDbFactory

      public T setupCosmosDbFactory(boolean isSetupCosmosDbFactory)
      Flags whether to setup the CosmosDbFactory for connecting.
      Parameters:
      isSetupCosmosDbFactory - true to setup the CosmosDbFactory for connecting.
      Returns:
      this for builder pattern.
    • getEndpointUrl

      public String getEndpointUrl()
      Obtains the end point URL.
      Returns:
      End point URL.
    • getKey

      public String getKey()
      Obtains the Key for connecting.
      Returns:
      Key for connecting.
    • getCosmosClient

      public com.azure.cosmos.CosmosClient getCosmosClient()
      Obtains the CosmosClient.
      Returns:
      CosmosClient.
    • getCosmosDatabase

      public com.azure.cosmos.CosmosDatabase getCosmosDatabase()
      Obtains the CosmosDatabase for testing.
      Returns:
      CosmosDatabase for testing.
    • getCosmosAsyncClient

      public com.azure.cosmos.CosmosAsyncClient getCosmosAsyncClient()
      Obtains the CosmosAsyncClient.
      Returns:
      CosmosAsyncClient.
    • getCosmosAsyncDatabase

      public com.azure.cosmos.CosmosAsyncDatabase getCosmosAsyncDatabase()
      Obtains the CosmosAsyncDatabase for testing.
      Returns:
      CosmosAsyncDatabase for testing.
    • startCosmosDb

      protected void startCosmosDb(BiFunction<String,Throwable,Exception> skip) throws Exception
      Start CosmosDb locally.
      Parameters:
      skip - Handles test skip.
      Throws:
      Exception - If fails to start.
    • handleTestFailure

      protected void handleTestFailure(Throwable failure, BiFunction<String,Throwable,Exception> skip) throws Throwable
      Determine if ignore CosmosException.
      Parameters:
      failure - Failure of test.
      skip - Handles the skip.
      Throws:
      Throwable - Propagation of failure.
    • stopCosmosDb

      protected void stopCosmosDb(BiFunction<String,Throwable,Exception> skip) throws Throwable
      Stops locally running CosmosDb.
      Parameters:
      skip - Handles test skip.
      Throws:
      Throwable - If fails to stop.