Skip to content

Latest commit

 

History

History
187 lines (127 loc) · 7.44 KB

File metadata and controls

187 lines (127 loc) · 7.44 KB

Azure Module

!!! note This module is INCUBATING. While it is ready for use and operational in the current version of Testcontainers, it is possible that it may receive breaking changes in the future. See our contributing guidelines for more information on our incubating modules policy.

Testcontainers module for the Microsoft Azure's SDK.

Currently, the module supports Azurite, Azure Event Hubs, Azure Service Bus and CosmosDB emulators. In order to use them, you should use the following classes:

Class Container Image
AzuriteContainer mcr.microsoft.com/azure-storage/azurite
EventHubsEmulatorContainer mcr.microsoft.com/azure-messaging/eventhubs-emulator
ServiceBusEmulatorContainer mcr.microsoft.com/azure-messaging/servicebus-emulator
CosmosDBEmulatorContainer mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator

Usage example

Azurite Storage Emulator

Start Azurite Emulator during a test:

Starting an Azurite container inside_block:emulatorContainer

!!! note SSL configuration is possible using the withSsl(MountableFile, String) and withSsl(MountableFile, MountableFile) methods.

If the tested application needs to use more than one set of credentials, the container can be configured to use custom credentials. Please see some examples below.

Starting an Azurite Blob container with one account and two keys inside_block:withTwoAccountKeys

Starting an Azurite Blob container with more accounts and keys inside_block:withMoreAccounts

Using with Blob

Build Azure Blob client:

Build Azure Blob Service client inside_block:createBlobClient

In case the application needs to use custom credentials, we can obtain them with a different method:

Obtain connection string with non-default credentials inside_block:useNonDefaultCredentials

Using with Queue

Build Azure Queue client:

Build Azure Queue Service client inside_block:createQueueClient

!!! note We can use custom credentials the same way as defined in the Blob section.

Using with Table

Build Azure Table client:

Build Azure Table Service client inside_block:createTableClient

!!! note We can use custom credentials the same way as defined in the Blob section.

Azure Event Hubs Emulator

Configuring the Azure Event Hubs Emulator container

Start Azure Event Hubs Emulator during a test:

Setting up a network inside_block:network

Starting an Azurite container as dependency inside_block:azuriteContainer

Starting an Azure Event Hubs Emulator container inside_block:emulatorContainer

Using Azure Event Hubs clients

Configure the consumer and the producer clients:

Configuring the clients inside_block:createProducerAndConsumer

Azure Service Bus Emulator

Configuring the Azure Service Bus Emulator container

Start Azure Service Bus Emulator during a test:

Setting up a network inside_block:network

Starting a SQL Server container as dependency inside_block:sqlContainer

Starting a Service Bus Emulator container inside_block:emulatorContainer

Using Azure Service Bus clients

Configure the sender and the processor clients:

Configuring the sender client inside_block:senderClient

Configuring the processor client inside_block:processorClient

CosmosDB

Start Azure CosmosDB Emulator during a test:

Starting an Azure CosmosDB Emulator container inside_block:emulatorContainer

Prepare KeyStore to use for SSL.

Building KeyStore from certificate within container inside_block:buildAndSaveNewKeyStore

Set system trust-store parameters to use already built KeyStore:

Set system trust-store parameters inside_block:setSystemTrustStoreParameters

Build Azure CosmosDB client:

Build Azure CosmosDB client inside_block:buildClient

Test against the Emulator:

Testing against Azure CosmosDB Emulator container inside_block:testWithClientAgainstEmulatorContainer

Adding this module to your project dependencies

Add the following dependency to your pom.xml/build.gradle file:

=== "Gradle" groovy testImplementation "org.testcontainers:azure:{{latest_version}}"

=== "Maven" xml <dependency> <groupId>org.testcontainers</groupId> <artifactId>azure</artifactId> <version>{{latest_version}}</version> <scope>test</scope> </dependency>