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 Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionAbstractCosmosDbJunit(CosmosEmulatorInstance emulatorInstance, CosmosTestDatabase testDatabse) Instantiate.AbstractCosmosDbJunit(CosmosTestDatabase testDatabse) Instantiate. -
Method Summary
Modifier and TypeMethodDescriptioncom.azure.cosmos.CosmosAsyncClientObtains theCosmosAsyncClient.com.azure.cosmos.CosmosAsyncDatabaseObtains theCosmosAsyncDatabasefor testing.com.azure.cosmos.CosmosClientObtains theCosmosClient.com.azure.cosmos.CosmosDatabaseObtains theCosmosDatabasefor testing.Obtains the end point URL.getKey()Obtains the Key for connecting.protected voidhandleTestFailure(Throwable failure, BiFunction<String, Throwable, Exception> skip) Determine if ignoreCosmosException.static booleanIndicates whether skipping failures.static booleanIndicates whether skipping all CosmosDb tests.setupCosmosDbFactory(boolean isSetupCosmosDbFactory) Flags whether to setup theCosmosDbFactoryfor connecting.protected voidStart CosmosDb locally.protected voidStops locally running CosmosDb.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.officefloor.nosql.cosmosdb.test.CosmosEmulatorInstance.FailureFactory
create
-
Field Details
-
PROPERTY_ENABLE_COSMOS_TESTS
Property to flag to indicate if enable Cosmos tests.- See Also:
-
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
Skip message.- See Also:
-
-
Constructor Details
-
AbstractCosmosDbJunit
Instantiate.- Parameters:
testDatabse-CosmosTestDatabase. May benullfor newCosmosTestDatabase.
-
AbstractCosmosDbJunit
public AbstractCosmosDbJunit(CosmosEmulatorInstance emulatorInstance, CosmosTestDatabase testDatabse) Instantiate.- Parameters:
emulatorInstance-CosmosEmulatorInstance. May benullfor defaultCosmosEmulatorInstance.testDatabse-CosmosTestDatabase. May benullfor newCosmosTestDatabase.
-
-
Method Details
-
isSkipTests
public static boolean isSkipTests()Indicates whether skipping all CosmosDb tests.- Returns:
trueif skipping all CosmosDb tests.
-
isSkipFailure
public static boolean isSkipFailure()Indicates whether skipping failures.- Returns:
trueif skipping failures.
-
setupCosmosDbFactory
Flags whether to setup theCosmosDbFactoryfor connecting.- Parameters:
isSetupCosmosDbFactory-trueto setup theCosmosDbFactoryfor connecting.- Returns:
thisfor builder pattern.
-
getEndpointUrl
Obtains the end point URL.- Returns:
- End point URL.
-
getKey
Obtains the Key for connecting.- Returns:
- Key for connecting.
-
getCosmosClient
public com.azure.cosmos.CosmosClient getCosmosClient()Obtains theCosmosClient.- Returns:
CosmosClient.
-
getCosmosDatabase
public com.azure.cosmos.CosmosDatabase getCosmosDatabase()Obtains theCosmosDatabasefor testing.- Returns:
CosmosDatabasefor testing.
-
getCosmosAsyncClient
public com.azure.cosmos.CosmosAsyncClient getCosmosAsyncClient()Obtains theCosmosAsyncClient.- Returns:
CosmosAsyncClient.
-
getCosmosAsyncDatabase
public com.azure.cosmos.CosmosAsyncDatabase getCosmosAsyncDatabase()Obtains theCosmosAsyncDatabasefor testing.- Returns:
CosmosAsyncDatabasefor testing.
-
startCosmosDb
Start CosmosDb locally.- Parameters:
skip- Handles test skip.- Throws:
Exception- If fails to start.
-
handleTestFailure
protected void handleTestFailure(Throwable failure, BiFunction<String, Throwable, throws ThrowableException> skip) Determine if ignoreCosmosException.- Parameters:
failure- Failure of test.skip- Handles the skip.- Throws:
Throwable- Propagation of failure.
-
stopCosmosDb
Stops locally running CosmosDb.- Parameters:
skip- Handles test skip.- Throws:
Throwable- If fails to stop.
-