How to use CosmosDBEmulatorContainer class of org.testcontainers.containers package

Best Testcontainers-java code snippet using org.testcontainers.containers.CosmosDBEmulatorContainer

Source:AbstractIntegrationTest.java Github

copy

Full Screen

...10import org.springframework.context.ConfigurableApplicationContext;11import org.springframework.context.annotation.Bean;12import org.springframework.test.context.ActiveProfiles;13import org.springframework.test.context.ContextConfiguration;14import org.testcontainers.containers.CosmosDBEmulatorContainer;15import org.testcontainers.junit.jupiter.Container;16import org.testcontainers.junit.jupiter.Testcontainers;17import org.testcontainers.utility.DockerImageName;18import java.io.FileOutputStream;19import java.nio.file.Path;20import java.security.KeyStore;21@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)22@ContextConfiguration(initializers = AbstractIntegrationTest.Initializer.class)23@Testcontainers24@ActiveProfiles({"integration-test"})25class AbstractIntegrationTest {26 protected static final int ServerPort = 8090;27 @Container28 private static final CosmosDBEmulatorContainer emulator = new CosmosDBEmulatorContainer(29 DockerImageName.parse("mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest")30 );31 @TempDir32 private static Path tempFolder;33 static class Initializer34 implements ApplicationContextInitializer<ConfigurableApplicationContext> {35 @SneakyThrows36 @Override37 public void initialize(ConfigurableApplicationContext context) {38 Path keyStoreFile = tempFolder.resolve("azure-cosmos-emulator.keystore");39 KeyStore keyStore = emulator.buildNewKeyStore();40 keyStore.store(new FileOutputStream(keyStoreFile.toFile()), emulator.getEmulatorKey().toCharArray());41 System.setProperty("javax.net.ssl.trustStore", keyStoreFile.toString());42 System.setProperty("javax.net.ssl.trustStorePassword", emulator.getEmulatorKey());...

Full Screen

Full Screen

Source:CosmosDatabaseContainer.java Github

copy

Full Screen

1package com.example.cosmos.config;2import org.springframework.stereotype.Component;3import org.testcontainers.containers.CosmosDBEmulatorContainer;4import org.testcontainers.utility.DockerImageName;5import java.io.FileOutputStream;6import java.io.IOException;7import java.nio.file.Files;8import java.nio.file.Path;9import java.security.KeyStore;10import java.security.KeyStoreException;11import java.security.NoSuchAlgorithmException;12import java.security.cert.CertificateException;13import java.util.List;14import java.util.concurrent.atomic.AtomicBoolean;15@Component16public class CosmosDatabaseContainer implements AutoCloseable {17 public static final String IMAGE_NAME = "mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator";18 private CosmosDBEmulatorContainer cosmosDBEmulatorContainer;19 private static AtomicBoolean initialized = new AtomicBoolean();20 private static CosmosDatabaseContainer thisContainer;21 private CosmosDatabaseContainer() {22 if (initialized.compareAndSet(false, true)) {23 this.cosmosDBEmulatorContainer =24 new CosmosDBEmulatorContainer(DockerImageName.parse(IMAGE_NAME));25 cosmosDBEmulatorContainer.setEnv(List.of("AZURE_COSMOS_EMULATOR_PARTITION_COUNT=5"));26 cosmosDBEmulatorContainer.start();27 configureKeyStore();28 }29 }30 public static CosmosDatabaseContainer getInstance() {31 if (thisContainer == null) {32 thisContainer = new CosmosDatabaseContainer();33 }34 return thisContainer;35 }36 @Override37 public void close() throws Exception {38 cosmosDBEmulatorContainer.stop();...

Full Screen

Full Screen

Source:CosmosDBEmulatorContainer.java Github

copy

Full Screen

...4import java.security.KeyStore;5/**6 * An Azure CosmosDB container7 */8public class CosmosDBEmulatorContainer extends GenericContainer<CosmosDBEmulatorContainer> {9 private static final DockerImageName DEFAULT_IMAGE_NAME =10 DockerImageName.parse("mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator");11 private static final int PORT = 8081;12 /**13 * @param dockerImageName specified docker image name to run14 */15 public CosmosDBEmulatorContainer(final DockerImageName dockerImageName) {16 super(dockerImageName);17 dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME);18 withExposedPorts(PORT);19 waitingFor(Wait.forLogMessage("(?s).*Started\\r\\n$", 1));20 }21 /**22 * @return new KeyStore built with PKCS1223 */24 public KeyStore buildNewKeyStore() {25 return KeyStoreBuilder.buildByDownloadingCertificate(getEmulatorEndpoint(), getEmulatorKey());26 }27 /**28 * Emulator key is a known constant and specified in Azure Cosmos DB Documents.29 * This key is also used as password for emulator certificate file....

Full Screen

Full Screen

CosmosDBEmulatorContainer

Using AI Code Generation

copy

Full Screen

1import com.azure.cosmos.CosmosClient;2import com.azure.cosmos.CosmosClientBuilder;3import com.azure.cosmos.CosmosContainer;4import com.azure.cosmos.CosmosDatabase;5import com.azure.cosmos.models.CosmosContainerProperties;6import com.azure.cosmos.models.CosmosItemResponse;7import com.azure.cosmos.models.CosmosQueryRequestOptions;8import com.azure.cosmos.models.FeedResponse;9import com.azure.cosmos.models.PartitionKey;10import com.azure.cosmos.util.CosmosPagedIterable;11import com.azure.data.cosmos.CosmosClientException;12import org.junit.jupiter.api.AfterAll;13import org.junit.jupiter.api.BeforeAll;14import org.junit.jupiter.api.Test;15import org.testcontainers.containers.CosmosDBEmulatorContainer;16import org.testcontainers.utility.DockerImageName;17import java.util.UUID;18import static org.junit.jupiter.api.Assertions.assertEquals;19public class CosmosDBEmulatorContainerTest {20 private static CosmosDBEmulatorContainer cosmosDBEmulatorContainer;21 private static CosmosClient cosmosClient;22 public static void setUp() {23 cosmosDBEmulatorContainer = new CosmosDBEmulatorContainer(DockerImageName.parse("mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:3.19.0"));24 cosmosDBEmulatorContainer.start();25 cosmosClient = new CosmosClientBuilder()26 .endpoint(cosmosDBEmulatorContainer.getEndpoint())27 .key(cosmosDBEmulatorContainer.getMasterKey())28 .buildClient();29 }30 public void testCosmosDBEmulatorContainer() throws CosmosClientException {31 String databaseName = "testDatabase";32 String containerName = "testContainer";33 CosmosDatabase cosmosDatabase = cosmosClient.createDatabase(databaseName);34 CosmosContainer cosmosContainer = cosmosDatabase.createContainer(containerName, "/id", 400);35 String uuid = UUID.randomUUID().toString();36 cosmosContainer.createItem(new TestItem(uuid, "testValue"));37 CosmosQueryRequestOptions cosmosQueryRequestOptions = new CosmosQueryRequestOptions();38 cosmosQueryRequestOptions.setQueryMetricsEnabled(true);39 CosmosPagedIterable<TestItem> cosmosPagedIterable = cosmosContainer.queryItems("select *

Full Screen

Full Screen

CosmosDBEmulatorContainer

Using AI Code Generation

copy

Full Screen

1import com.azure.cosmos.CosmosAsyncClient;2import com.azure.cosmos.CosmosAsyncDatabase;3import com.azure.cosmos.CosmosAsyncContainer;4import com.azure.cosmos.CosmosAsyncItemResponse;5import com.azure.cosmos.CosmosItemRequestOptions;6import com.azure.cosmos.models.CosmosItemResponse;7import com.azure.cosmos.models.PartitionKey;8import com.azure.cosmos.util.CosmosPagedFlux;9import com.azure.cosmos.util.CosmosPagedIterable;10import com.azure.cosmos.models.CosmosQueryRequestOptions;11import com.azure.cosmos.models.FeedResponse;12import com.azure.cosmos.models.SqlQuerySpec;13import com.azure.cosmos.models.ThroughputProperties;14import com.azure.cosmos.util.CosmosItemIterable;15import com.azure.cosmos.util.CosmosItemPagedFlux;16import com.azure.cosmos.util.CosmosItemPagedIterable;17import com.azure.data.cosmos.internal.HttpConstants;18import com.azure.data.cosmos.internal.RequestOptions;19import com.azure.data.cosmos.internal.ResourceResponse;20import com.azure.data.cosmos.internal.SqlParameter;21import com.azure.data.cosmos.internal.SqlQuerySpec;22import com.azure.data.cosmos.internal.TestConfigurations;23import com.azure.data.cosmos.internal.directconnectivity.Protocol;24import com.azure.data.cosmos.internal.directconnectivity.rntbd.RntbdTransportClient.Options;25import com.azure.data.cosmos.internal.http.HttpClient;26import com.azure.data.cosmos.internal.http.HttpClientConfig;27import com.azure.data.cosmos.internal.http.HttpHeaders;28import com.azure.data.cosmos.internal.http.HttpMethod;29import com.azure.data.cosmos.internal.http.HttpRequest;30import com.azure.data.cosmos.internal.http.HttpResponse;31import com.azure.data.cosmos.internal.http.ProxyOptions;32import com.azure.data.cosmos.internal.http.netty.NettyAsyncHttpClientBuilder;33import com.azure.data.cosmos.internal.http.netty.NettyAsyncHttpClientProvider;34import com.azure.data.cosmos.internal.http.netty.ProxyHandlerProvider;35import com.azure.data.cosmos.internal.http.policy.HttpLogDetailLevel;36import com.azure.data.cosmos.internal.http.policy.HttpLogOptions;37import com.azure.data.cosmos.internal.http.policy.HttpPipelinePolicy;38import com.azure.data.cosmos.internal.http.policy.RetryPolicy;39import com.azure.data.cosmos.internal.http.policy.UserAgentPolicy;40import com.azure.data.cosmos.internal.http.policy.UserAgentPolicyFormat;41import com.azure.data.cosmos.internal.http.policy.UserAgentPolicyOptions;42import com.azure.data.cosmos.internal.query.CompositeContin

Full Screen

Full Screen

CosmosDBEmulatorContainer

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.CosmosDBEmulatorContainer;2import org.testcontainers.containers.GenericContainer;3import org.testcontainers.containers.wait.strategy.HttpWaitStrategy;4import org.testcontainers.containers.wait.strategy.Wait;5import org.testcontainers.utility.DockerImageName;6import java.time.Duration;7import java.util.concurrent.TimeUnit;8public class TestCosmosDBEmulatorContainer {9 public static void main(String[] args) {10 try (CosmosDBEmulatorContainer container = new CosmosDBEmulatorContainer(DockerImageName.parse("mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:3.14.0"))) {11 container.start();12 System.out.println("CosmosDBEmulatorContainer connection string: " + container.getConnectionString());13 System.out.println("CosmosDBEmulatorContainer URI: " + container.getUri());14 System.out.println("CosmosDBEmulatorContainer key: " + container.getKey());15 System.out.println("CosmosDBEmulatorContainer database account name: " + container.getDatabaseAccountName());16 System.out.println("CosmosDBEmulatorContainer database account endpoint: " + container.getDatabaseAccountEndpoint());17 System.out.println("CosmosDBEmulatorContainer database account key: " + container.getDatabaseAccountKey());18 System.out.println("CosmosDBEmulatorContainer database account read only key: " + container.getDatabaseAccountReadOnlyKey());19 System.out.println("CosmosDBEmulatorContainer database account connection mode: " + container.getDatabaseAccountConnectionMode());20 System.out.println("CosmosDBEmulatorContainer database account consistency level: " + container.getDatabaseAccountConsistencyLevel());21 System.out.println("CosmosDBEmulatorContainer database account default consistency level: " + container.getDatabaseAccountDefaultConsistencyLevel());

Full Screen

Full Screen

CosmosDBEmulatorContainer

Using AI Code Generation

copy

Full Screen

1import java.util.UUID;2import org.junit.jupiter.api.Test;3import org.testcontainers.containers.CosmosDBEmulatorContainer;4import org.testcontainers.junit.jupiter.Container;5import org.testcontainers.junit.jupiter.Testcontainers;6public class TestCosmosDBEmulatorContainer {7 private CosmosDBEmulatorContainer cosmosDBEmulatorContainer = new CosmosDBEmulatorContainer();8 public void testCosmosDBEmulatorContainer() {9 String connectionString = cosmosDBEmulatorContainer.getEmulatorEndpoint();10 String masterKey = cosmosDBEmulatorContainer.getMasterKey();11 String databaseName = UUID.randomUUID().toString();12 String containerName = UUID.randomUUID().toString();13 }14}15import java.util.UUID;16import org.junit.jupiter.api.Test;17import org.testcontainers.containers.CosmosDBEmulatorContainer;18import org.testcontainers.junit.jupiter.Container;19import org.testcontainers.junit.jupiter.Testcontainers;20public class TestCosmosDBEmulatorContainer {21 private CosmosDBEmulatorContainer cosmosDBEmulatorContainer = new CosmosDBEmulatorContainer();22 public void testCosmosDBEmulatorContainer() {23 String connectionString = cosmosDBEmulatorContainer.getEmulatorEndpoint();24 String masterKey = cosmosDBEmulatorContainer.getMasterKey();25 String databaseName = UUID.randomUUID().toString();26 String containerName = UUID.randomUUID().toString();27 }28}29import java.util.UUID;30import org.junit.jupiter.api.Test;31import org.testcontainers.containers.CosmosDBContainer;32import org.testcontainers.junit.jupiter.Container;33import org.testcontainers.junit.jupiter.Testcontainers;34public class TestCosmosDBContainer {35 private CosmosDBContainer cosmosDBContainer = new CosmosDBContainer();36 public void testCosmosDBContainer() {37 String connectionString = cosmosDBContainer.getEmulatorEndpoint();

Full Screen

Full Screen

CosmosDBEmulatorContainer

Using AI Code Generation

copy

Full Screen

1import com.azure.cosmos.CosmosClient;2import com.azure.cosmos.CosmosClientBuilder;3import com.azure.cosmos.CosmosContainer;4import com.azure.cosmos.CosmosDatabase;5import com.azure.cosmos.models.CosmosContainerProperties;6import com.azure.cosmos.models.CosmosDatabaseResponse;7import com.azure.cosmos.models.ThroughputProperties;8import org.testcontainers.containers.CosmosDBEmulatorContainer;9import org.testcontainers.utility.DockerImageName;10public class 1 {11 public static void main(String[] args) {12 CosmosDBEmulatorContainer cosmosDBEmulatorContainer = new CosmosDBEmulatorContainer(DockerImageName.parse("mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:2.11.0"));13 cosmosDBEmulatorContainer.start();14 CosmosClient cosmosClient = new CosmosClientBuilder()15 .endpoint(cosmosDBEmulatorContainer.getEndpoint())16 .key(cosmosDBEmulatorContainer.getMasterKey())17 .buildClient();18 CosmosDatabase cosmosDatabase = cosmosClient.createDatabaseIfNotExists("TestDB", ThroughputProperties.createManualThroughput(400)).getDatabase();19 CosmosContainer cosmosContainer = cosmosDatabase.createContainerIfNotExists(new CosmosContainerProperties("TestContainer", "/id"), ThroughputProperties.createManualThroughput(400)).getContainer();20 }21}22import com.azure.cosmos.CosmosClient;23import com.azure.cosmos.CosmosClientBuilder;24import com.azure.cosmos.CosmosContainer;25import com.azure.cosmos.CosmosDatabase;26import com.azure.cosmos.models.CosmosContainerProperties;27import com.azure.cosmos.models.CosmosDatabaseResponse;28import com.azure.cosmos.models.ThroughputProperties;29import org.testcontainers.containers.CosmosDBEmulatorContainer;30import org.testcontainers.utility.DockerImageName;31public class 2 {32 public static void main(String[] args) {

Full Screen

Full Screen

CosmosDBEmulatorContainer

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.CosmosDBEmulatorContainer;2public class CosmosDBEmulatorContainerTest {3 public static void main(String[] args) {4 try (CosmosDBEmulatorContainer container = new CosmosDBEmulatorContainer()) {5 container.start();6 System.out.println("Container ID: " + container.getContainerId());7 System.out.println("Container Host: " + container.getHost());8 System.out.println("Container Port: " + container.getPort());9 System.out.println("Container Endpoint: " + container.getEndpoint());10 }11 }12}

Full Screen

Full Screen

CosmosDBEmulatorContainer

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.CosmosDBEmulatorContainer;2import org.testcontainers.utility.DockerImageName;3import com.azure.cosmos.CosmosClient;4import com.azure.cosmos.CosmosClientBuilder;5import com.azure.cosmos.CosmosDatabase;6import com.azure.cosmos.CosmosContainer;7import com.azure.cosmos.models.CosmosContainerProperties;8import com.azure.cosmos.models.CosmosContainerResponse;9import com.azure.cosmos.models.CosmosDatabaseResponse;10import com.azure.cosmos.models.CosmosItemResponse;11import com.azure.cosmos.models.PartitionKey;12import com.azure.cosmos.models.ThroughputProperties;13import com.azure.cosmos.util.CosmosPagedIterable;14import com.azure.cosmos.models.CosmosQueryRequestOptions;15import java.util.Iterator;16import org.json.JSONObject;17import org.json.JSONException;18public class CosmosDBEmulatorContainerDemo {19 public static void main(String[] args) {20 CosmosDBEmulatorContainer cosmosDBEmulatorContainer = new CosmosDBEmulatorContainer(DockerImageName.parse("mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:2.11.4"));21 cosmosDBEmulatorContainer.start();22 String connectionString = cosmosDBEmulatorContainer.getConnectionString();23 CosmosClient cosmosClient = new CosmosClientBuilder()24 .endpoint(connectionString)25 .key("key")26 .buildClient();27 CosmosDatabase cosmosDatabase = cosmosClient.getDatabase("TestDB");28 CosmosContainer cosmosContainer = cosmosDatabase.getContainer("TestContainer");29 JSONObject jsonObject = new JSONObject();30 jsonObject.put("id", "1");31 CosmosItemResponse<JSONObject> cosmosItemResponse = cosmosContainer.createItem(jsonObject, new PartitionKey("1"), new CosmosItemRequestOptions());32 JSONObject jsonObject1 = cosmosItemResponse.getItem();

Full Screen

Full Screen

CosmosDBEmulatorContainer

Using AI Code Generation

copy

Full Screen

1package com.example;2import com.azure.cosmos.CosmosClient;3import com.azure.cosmos.CosmosClientBuilder;4import com.azure.cosmos.CosmosContainer;5import com.azure.cosmos.CosmosDatabase;6import com.azure.cosmos.models.CosmosContainerProperties;7import com.azure.cosmos.models.CosmosContainerResponse;8import com.azure.cosmos.models.CosmosDatabaseProperties;9import com.azure.cosmos.models.CosmosDatabaseResponse;10import com.azure.cosmos.models.ThroughputProperties;11import org.junit.jupiter.api.AfterAll;12import org.junit.jupiter.api.BeforeAll;13import org.junit.jupiter.api.Test;14import org.testcontainers.containers.CosmosDBEmulatorContainer;15import java.util.UUID;16public class CosmosDBEmulatorContainerTest {17 private static CosmosDBEmulatorContainer cosmosDBEmulatorContainer;18 private static CosmosClient cosmosClient;19 private static CosmosDatabase cosmosDatabase;20 private static CosmosContainer cosmosContainer;21 public static void setUp() {22 cosmosDBEmulatorContainer = new CosmosDBEmulatorContainer();23 cosmosDBEmulatorContainer.start();24 cosmosClient = new CosmosClientBuilder()25 .endpoint(cosmosDBEmulatorContainer.getEndpoint())26 .key(cosmosDBEmulatorContainer.getMasterKey())27 .buildClient();28 CosmosDatabaseResponse cosmosDatabaseResponse = cosmosClient.createDatabaseIfNotExists(UUID.randomUUID().toString());29 cosmosDatabase = cosmosClient.getDatabase(cosmosDatabaseResponse.getProperties().getId());30 CosmosContainerProperties cosmosContainerProperties = new CosmosContainerProperties(UUID.randomUUID().toString(), "/id");31 CosmosContainerResponse cosmosContainerResponse = cosmosDatabase.createContainerIfNotExists(cosmosContainerProperties, ThroughputProperties.createManualThroughput(400));32 cosmosContainer = cosmosDatabase.getContainer(cosmosContainerResponse.getProperties().getId());33 }34 public void testCosmosDBEmulatorContainer() {35 System.out.println("CosmosDBEmulatorContainerTest.testCosmosDBEmulatorContainer");36 }37 public static void tearDown() {

Full Screen

Full Screen

CosmosDBEmulatorContainer

Using AI Code Generation

copy

Full Screen

1import com.azure.cosmos.*;2import com.azure.cosmos.models.*;3import com.azure.cosmos.util.CosmosPagedIterable;4import com.azure.data.cosmos.*;5import com.azure.data.cosmos.internal.AsyncDocumentClient;6import com.azure.data.cosmos.internal.ConnectionPolicy;7import com.azure.data.cosmos.internal.DatabaseAccount;8import com.azure.data.cosmos.internal.DocumentCollection;9import com.azure.data.cosmos.internal.HttpConstants;10import com.azure.data.cosmos.internal.RequestOptions;11import com.azure.data.cosmos.internal.ResourceResponse;12import com.azure.data.cosmos.internal.RetryOptions;13import com.azure.data.cosmos.internal.RxDocumentServiceRequest;14import com.azure.data.cosmos.internal.RxDocumentServiceResponse;15import com.azure.data.cosmos.internal.directconnectivity.Protocol;16import com.azure.data.cosmos.internal.directconnectivity.WFConstants;17import com.azure.data.cosmos.internal.http.HttpHeaders;18import com.azure.data.cosmos.internal.http.HttpRequest;19import com.azure.data.cosmos.internal.http.HttpResponse;20import com.azure.data.cosmos.internal.http.HttpResponseDecoder;21import com.azure.data.cosmos.internal.http.ProxyOptions;22import com.azure.data.cosmos.internal.http.RxDocumentServiceRequestToCosmosAsyncHttpRequest;23import com.azure.data.cosmos.internal.query.PartitionedQueryExecutionInfo;24import com.azure.data.cosmos.internal.query.PartitionedQueryExecutionInfoInternal;25import com.azure.data.cosmos.internal.query.PartitionedQueryExecutionInfoSerializer;26import com.azure.data.cosmos.internal.query.PartitionedQueryExecutionInfoWrapper;27import com.azure.data.cosmos.internal.query.PartitionedQueryExecutionInfoWrapperSerializer;28import com.azure.data.cosmos.internal.query.PlanCacheInfo;29import com.azure.data.cosmos.internal.query.PlanCacheInfoSerializer;30import com.azure.data.cosmos.internal.query.QueryInfo;31import com.azure.data.cosmos.internal.query.QueryInfoSerializer;32import

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testcontainers-java automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in CosmosDBEmulatorContainer

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful