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

Best Testcontainers-java code snippet using org.testcontainers.containers.CosmosDBEmulatorContainer.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

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful