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

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

Source:FirestoreTestBase.java Github

copy

Full Screen

...16import org.springframework.boot.test.mock.mockito.MockBean;17import org.springframework.context.annotation.Bean;18import org.springframework.context.annotation.Primary;19import org.springframework.test.context.ActiveProfiles;20import org.testcontainers.containers.FirestoreEmulatorContainer;21import org.testcontainers.junit.jupiter.Container;22import org.testcontainers.junit.jupiter.Testcontainers;23import org.testcontainers.utility.DockerImageName;24import uk.gov.ons.ctp.common.cloud.FirestoreProvider;25import uk.gov.ons.ctp.common.event.EventPublisher;26import uk.gov.ons.ctp.common.firestore.TestCloudDataStore;27import uk.gov.ons.ctp.common.utility.ParallelTestLocks;28/** Base class for Firestore integration tests using TestContainers. */29@SpringBootTest(webEnvironment = WebEnvironment.NONE)30@ActiveProfiles("test-containers-firestore")31@Testcontainers32@MockBean({EventPublisher.class, PubSubTemplate.class})33@MockBean(name = "caseEventInbound", value = PubSubInboundChannelAdapter.class)34@MockBean(name = "uacEventInbound", value = PubSubInboundChannelAdapter.class)35@MockBean(name = "surveyEventInbound", value = PubSubInboundChannelAdapter.class)36@MockBean(name = "collectionExerciseEventInbound", value = PubSubInboundChannelAdapter.class)37@ResourceLock(value = ParallelTestLocks.SPRING_TEST, mode = READ_WRITE)38@Tag("firestore")39@Slf4j40public abstract class FirestoreTestBase {41 private static final String EMULATOR_IMG =42 "gcr.io/google.com/cloudsdktool/cloud-sdk:366.0.0-emulators";43 /**44 * This value must be kept in sync with spring.cloud.gcp.firestore.project-id value in the45 * application yaml files. It is hard-coded here in order to be picked up statically before the46 * application context gets created.47 */48 private static final String GCP_PROJECT = "rh-testcontainers";49 protected static final String CASE_SCHEMA = GCP_PROJECT + "-case";50 protected static final String UAC_SCHEMA = GCP_PROJECT + "-uac";51 protected static final String COLLEX_SCHEMA = GCP_PROJECT + "-collection_exercise";52 protected static final String SURVEY_SCHEMA = GCP_PROJECT + "-survey";53 @Autowired protected TestCloudDataStore testDataStore;54 private static TestFirestoreProvider provider;55 @Container56 private static final FirestoreEmulatorContainer firestoreEmulator =57 new FirestoreEmulatorContainer(DockerImageName.parse(EMULATOR_IMG));58 /**59 * The dockerised emulator will change its endpoint for each new test class, so therefore60 * firestore must be reconfigured for each test class that runs.61 */62 @BeforeAll63 public static void classSetup() {64 log.info(65 "Initialising test firestoreProvider against emulator: {}",66 firestoreEmulator.getEmulatorEndpoint());67 if (provider == null) {68 provider = new TestFirestoreProvider();69 }70 provider.init(GCP_PROJECT, firestoreEmulator);71 }72 /**73 * Configure any firestore provider in our test environment to use the emulator. This74 * FirestoreProvider bean will be picked up by everywhere using firestore and override the usual75 * implementation.76 */77 @TestConfiguration78 static class FirestoreConfiguration {79 @Bean80 @Primary81 FirestoreProvider firestoreProvider() {82 return provider;83 }84 }85 protected void deleteAllCollections() {86 testDataStore.deleteCollection(SURVEY_SCHEMA);87 testDataStore.deleteCollection(COLLEX_SCHEMA);88 testDataStore.deleteCollection(UAC_SCHEMA);89 testDataStore.deleteCollection(CASE_SCHEMA);90 }91 /** An implementation of FirestoreProvider that uses the emulator. */92 public static class TestFirestoreProvider implements FirestoreProvider {93 private Firestore firestore;94 public TestFirestoreProvider init(String gcpProject, FirestoreEmulatorContainer emulator) {95 firestore =96 FirestoreOptions.newBuilder()97 .setProjectId(gcpProject)98 .setHost(emulator.getEmulatorEndpoint())99 .setCredentials(NoCredentials.getInstance())100 .build()101 .getService();102 return this;103 }104 public Firestore get() {105 return firestore;106 }107 }108}...

Full Screen

Full Screen

Source:AbstractInterationTest.java Github

copy

Full Screen

2import com.google.api.client.http.HttpMethods;3import java.net.URI;4import java.util.Map;5import org.junit.jupiter.api.extension.ExtendWith;6import org.testcontainers.containers.FirestoreEmulatorContainer;7import org.testcontainers.junit.jupiter.Container;8import org.testcontainers.junit.jupiter.Testcontainers;9import org.testcontainers.utility.DockerImageName;10import uk.org.webcompere.systemstubs.environment.EnvironmentVariables;11import uk.org.webcompere.systemstubs.jupiter.SystemStub;12import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension;13@ExtendWith(SystemStubsExtension.class)14@Testcontainers15public abstract class AbstractInterationTest {16 @Container17 public final static FirestoreEmulatorContainer FIRESTORE_EMULATOR = new FirestoreEmulatorContainer(18 DockerImageName.parse("gcr.io/google.com/cloudsdktool/cloud-sdk:317.0.0-emulators"));19 public final static String uriString = "https://LOCATION-PROJECT_ID.cloudfunctions.net/clockify-webhook";20 public final static String CLOCKIFY_SIGNATURE = "verySecretSignature";21 @SystemStub22 public final EnvironmentVariables environmentVariables = new EnvironmentVariables() //23 .set("GOOGLE_CLOUD_PROJECT", "test-project") //24 .set("CLOCKIFY_SIGNATURE", CLOCKIFY_SIGNATURE) //25 .set("FIRESTORE_EMULATOR_HOST", FIRESTORE_EMULATOR.getEmulatorEndpoint());26 public final Map<String, String> headerMap = Map.of( //27 "Clockify-Signature", CLOCKIFY_SIGNATURE, //28 "Content-Type", "application/json");29 public final JavaHttpRequest.JavaHttpRequestBuilder requestBuilder = JavaHttpRequest.builder() //30 .uri(URI.create(uriString)).method(HttpMethods.POST).httpHeaders(headerMap);31}...

Full Screen

Full Screen

Source:FirestoreMetricsReproducerApplicationTests.java Github

copy

Full Screen

...4import org.junit.jupiter.api.Test;5import org.springframework.boot.test.context.SpringBootTest;6import org.springframework.test.context.DynamicPropertyRegistry;7import org.springframework.test.context.DynamicPropertySource;8import org.testcontainers.containers.FirestoreEmulatorContainer;9import org.testcontainers.junit.jupiter.Container;10import org.testcontainers.junit.jupiter.Testcontainers;11import org.testcontainers.utility.DockerImageName;12@SpringBootTest13@Testcontainers14class FirestoreMetricsReproducerApplicationTests {15 @Container16 private static FirestoreEmulatorContainer emulator = new FirestoreEmulatorContainer(17 DockerImageName.parse("google/cloud-sdk:382.0.0-emulators")18 .asCompatibleSubstituteFor("gcr.io/google.com/cloudsdktool/cloud-sdk")19 );20 @DynamicPropertySource21 static void redisProperties(DynamicPropertyRegistry registry) {22 registry.add("spring.cloud.gcp.firestore.emulator.enabled", () -> true);23 registry.add("spring.cloud.gcp.firestore.host-port", emulator::getEmulatorEndpoint);24 }25 @Test26 void contextLoads() {27 Assertions.assertTrue(true, "The app should start successfully");28 }29}...

Full Screen

Full Screen

FirestoreEmulatorContainer

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.FirestoreEmulatorContainer;2public class 1 {3 public static void main(String[] args) {4 FirestoreEmulatorContainer container = new FirestoreEmulatorContainer();5 container.start();6 String host = container.getHost();7 int port = container.getPort();8 System.out.println("Host: " + host);9 System.out.println("Port: " + port);10 }11}

Full Screen

Full Screen

FirestoreEmulatorContainer

Using AI Code Generation

copy

Full Screen

1import java.util.List;2import java.util.ArrayList;3import java.util.Map;4import java.util.HashMap;5import com.google.cloud.firestore.Firestore;6import com.google.cloud.firestore.FirestoreOptions;7import com.google.cloud.firestore.WriteResult;8import com.google.cloud.firestore.DocumentReference;9import com.google.cloud.firestore.DocumentSnapshot;10import com.google.cloud.firestore.QueryDocumentSnapshot;11import com.google.cloud.firestore.QuerySnapshot;12import com.google.cloud.firestore.Query;13import com.google.cloud.firestore.Query.Direction;14import com.google.cloud.firestore.Query.QueryOptions;15import com.google.cloud.firestore.CollectionReference;16import com.google.cloud.firestore.EventListener;17import com.google.cloud.firestore.ListenerRegistration;18import com.google.cloud.firestore.FirestoreException;19import com.google.cloud.firestore.QuerySnapshot;20import com.google.api.core.ApiFuture;21import com.google.api.core.ApiFutures;22import com.google.cloud.firestore.DocumentChange;23import com.google.cloud.firestore.DocumentChange.Type;24import com.google.cloud.firestore.FirestoreException;25import com.google.cloud.firestore.FirestoreOptions;26import com.google.cloud.firestore.Firestore;27import com.google.cloud.firestore.CollectionReference;28import com.google.cloud.firestore.DocumentReference;29import com.google.cloud.firestore.DocumentSnapshot;30import com.google.cloud.firestore.Query;31import com.google.cloud.firestore.Query.Direction;32import com.google.cloud.firestore.QueryDocumentSnapshot;33import com.google.cloud.firestore.QuerySnapshot;34import com.google.cloud.firestore.WriteResult;35import com.google.common.collect.Lists;36import com.google.common.collect.Maps;37import com.google.common.util.concurrent.MoreExecutors;38import com.google.firestore.v1.StructuredQuery;39import com.google.firestore.v1.StructuredQuery.Direction;40import com.google.firestore.v1.StructuredQuery.FieldFilter;41import com.google.firestore.v1.StructuredQuery.FieldReference;42import com.google.firestore.v1.StructuredQuery.Filter;43import com.google.firestore.v1.StructuredQuery.Order;44import com.google.firestore.v1.StructuredQuery.UnaryFilter;45import com.google.firestore.v1.StructuredQuery.UnaryFilter.Operator;46import com.google.firestore.v1.Value;47import com.google.protobuf.BoolValue;48import com.google.protobuf.Int32Value;49import com.google.protobuf.Int64Value;50import com.google.protobuf.StringValue;51import com.google.protobuf.Timestamp;52import com.google.protobuf.DoubleValue;53import com.google.protobuf.NullValue;54import com.google.protobuf.ByteString;55import com.google.protobuf.Empty;56import com.google.protobuf.GeneratedMessageV3;57import com.google.protobuf.InvalidProtocolBufferException;58import com.google.protobuf.Message;59import com.google.protobuf.util.JsonFormat;60import com.google.protobuf.util.Timestamps;61import

Full Screen

Full Screen

FirestoreEmulatorContainer

Using AI Code Generation

copy

Full Screen

1public class FirestoreEmulatorContainerTest {2 public void testFirestoreEmulatorContainer() throws IOException, InterruptedException {3 FirestoreEmulatorContainer container = new FirestoreEmulatorContainer();4 container.start();5 FirestoreOptions options = FirestoreOptions.newBuilder()6 .setProjectId(container.getProjectId())7 .setHost(container.getEmulatorEndpoint())8 .setChannelProvider(container.getEmulatorChannelProvider())9 .setCredentialsProvider(container.getEmulatorCredentialsProvider())10 .build();11 Firestore firestore = options.getService();12 ApiFuture<WriteResult> future = firestore.collection("cities").document("BJ").set(ImmutableMap.of("name", "Beijing"));13 WriteResult writeResult = future.get();14 System.out.println(writeResult.getUpdateTime());15 container.stop();16 }17}18getProjectId()19getEmulatorEndpoint()20getEmulatorChannelProvider()21getEmulatorCredentialsProvider()

Full Screen

Full Screen

FirestoreEmulatorContainer

Using AI Code Generation

copy

Full Screen

1package com.mycompany.app;2import org.testcontainers.containers.FirestoreEmulatorContainer;3import org.testcontainers.utility.DockerImageName;4import org.testcontainers.containers.Container;5import org.testcontainers.containers.GenericContainer;6import org.testcontainers.containers.Network;7import org.testcontainers.containers.output.Slf4jLogConsumer;8import org.testcontainers.containers.output.OutputFrame;9import org.testcontainers.containers.output.ToStringConsumer;10import org.testcontainers.containers.output.WaitingConsumer;11import org.testcontainers.containers.output.FrameConsumerResultCallback;12import org.testcontainers.utility.DockerImageName;13import java.util.concurrent.TimeUnit;14import java.util.concurrent.TimeoutException;15import java.util.concurrent.CompletionException;16import java.util.concurrent.CompletableFuture;17import org.slf4j.Logger;18import org.slf4j.LoggerFactory;19import com.google.api.core.ApiFuture;20import com.google.auth.oauth2.GoogleCredentials;21import com.google.cloud.firestore.Firestore;22import com.google.cloud.firestore.FirestoreOptions;23import com.google.cloud.firestore.QueryDocumentSnapshot;24import com.google.cloud.firestore.QuerySnapshot;25import com.google.cloud.firestore.DocumentReference;26import com.google.cloud.firestore.DocumentSnapshot;27import com.google.cloud.firestore.WriteResult;28import com.google.cloud.firestore.FirestoreException;29import com.google.cloud.firestore.Transaction;30import com.google.cloud.firestore.Transaction.Function;31import com.google.cloud.firestore.DocumentReference;32import com.google.cloud.firestore.DocumentSnapshot;33import com.google.cloud.firestore.WriteResult;34import com.google.cloud.firestore.FirestoreException;35import com.google.cloud.firestore.Transaction;36import com.google.cloud.firestore.Transaction.Function;37import java.util.concurrent.ExecutionException;38import java.util.HashMap;39import java.util.Map;40import java.util.concurrent.ExecutionException;41import java.util.concurrent.TimeUnit;42import java.util.concurrent.TimeoutException;43import java.util.concurrent.CompletionException;44import java.util.concurrent.CompletableFuture;45import org.slf4j.Logger;46import org.slf4j.LoggerFactory;47{48 public static void main( String[] args ) throws InterruptedException, ExecutionException, TimeoutException49 {50 Logger logger = LoggerFactory.getLogger(App.class);51 FirestoreEmulatorContainer container = new FirestoreEmulatorContainer(DockerImageName.parse("gcr.io/google.com/cloudsdktool/cloud-sdk:latest"));52 container.start();53 FirestoreOptions.newBuilder()54 .setProjectId("test")55 .setCredentials(GoogleCredentials.getApplicationDefault())56 .setHost(container.getEmulatorEndpoint())57 .build();58 Firestore db = firestoreOptions.getService();

Full Screen

Full Screen

FirestoreEmulatorContainer

Using AI Code Generation

copy

Full Screen

1public class FirestoreEmulatorContainerTest {2 public void testFirestoreEmulatorContainer() throws IOException, InterruptedException {3 FirestoreEmulatorContainer container = new FirestoreEmulatorContainer();4 container.start();5 FirestoreOptions options = FirestoreOptions.newBuilder()6 .setProjectId(container.getProjectId())7 .setHost(container.getEmulatorEndpoint())8 .setChannelProvider(container.getEmulatorChannelProvider())9 .setCredentialsProvider(container.getEmulatorCredentialsProvider())10 .build();11 Firestore firestore = options.getService();12 ApiFuture<WriteResult> future = firestore.collection("cities").document("BJ").set(ImmutableMap.of("name", "Beijing"));13 WriteResult writeResult = future.get();14 System.out.println(writeResult.getUpdateTime());15 container.stop();16 }17}18getProjectId()19getEmulatorEndpoint()20getEmulatorChannelProvider()21getEmulatorCredentialsProvider()

Full Screen

Full Screen

FirestoreEmulatorContainer

Using AI Code Generation

copy

Full Screen

1package com.mycompany.app;2import org.testcontainers.containers.FirestoreEmulatorContainer;3import org.testcontainers.utility.DockerImageName;4import org.testcontainers.containers.Container;5import org.testcontainers.containers.GenericContainer;6import org.testcontainers.containers.Network;7import org.testcontainers.containers.output.Slf4jLogConsumer;8import org.testcontainers.containers.output.OutputFrame;9import org.testcontainers.containers.output.ToStringConsumer;10import org.testcontainers.containers.output.WaitingConsumer;11import org.testcontainers.containers.output.FrameConsumerResultCallback;12import org.testcontainers.utility.DockerImageName;13import java.util.concurrent.TimeUnit;14import java.util.concurrent.TimeoutException;15import java.util.concurrent.CompletionException;16import java.util.concurrent.CompletableFuture;17import org.slf4j.Logger;18import org.slf4j.LoggerFactory;19import com.google.api.core.ApiFuture;20import com.google.auth.oauth2.GoogleCredentials;21import com.google.cloud.firestore.Firestore;22import com.google.cloud.firestore.FirestoreOptions;23import com.google.cloud.firestore.QueryDocumentSnapshot;24import com.google.cloud.firestore.QuerySnapshot;25import com.google.cloud.firestore.DocumentReference;26import com.google.cloud.firestore.DocumentSnapshot;27import com.google.cloud.firestore.WriteResult;28import com.google.cloud.firestore.FirestoreException;29import com.google.cloud.firestore.Transaction;30import com.google.cloud.firestore.Transaction.Function;31import com.google.cloud.firestore.DocumentReference;32import com.google.cloud.firestore.DocumentSnapshot;33import com.google.cloud.firestore.WriteResult;34import com.google.cloud.firestore.FirestoreException;35import com.google.cloud.firestore.Transaction;36import com.google.cloud.firestore.Transaction.Function;37import java.util.concurrent.ExecutionException;38import java.util.HashMap;39import java.util.Map;40import java.util.concurrent.ExecutionException;41import java.util.concurrent.TimeUnit;42import java.util.concurrent.TimeoutException;43import java.util.concurrent.CompletionException;44import java.util.concurrent.CompletableFuture;45import org.slf4j.Logger;46import org.slf4j.LoggerFactory;47{48 public static void main( String[] args ) throws InterruptedException, ExecutionException, TimeoutException49 {50 Logger logger = LoggerFactory.getLogger(App.class);51 FirestoreEmulatorContainer container = new FirestoreEmulatorContainer(DockerImageName.parse("gcr.io/google.com/cloudsdktool/cloud-sdk:latest"));52 container.start();53 FirestoreOptions.newBuilder()54 .setProjectId("test")55 .setCredentials(GoogleCredentials.getApplicationDefault())56 .setHost(container.getEmulatorEndpoint())57 .build();58 Firestore db = firestoreOptions.getService();

Full Screen

Full Screen

FirestoreEmulatorContainer

Using AI Code Generation

copy

Full Screen

1public class FirestoreEmulatorContainerTest {2 private static FirestoreEmulatorContainer container;3 private static Firestore firestore;4 public static void setUp() {5 container = new FirestoreEmulatorContainer("1.10.4");6 container.start();7 FirestoreOptions options = FirestoreOptions.newBuilder()8 .setProjectId("test")9 .setHost(container.getHost())10 .setPort(container.getPort())11 .setCredentials(NoCredentials.getInstance())12 .build();13 firestore = options.getService();14 }15 public static void tearDown() {16 container.stop();17 }18 public void testFirestoreEmulator() {19 DocumentReference document = firestore.collection("test").document("test");20 document.set(Collections.singletonMap("test", "test"));21 ApiFuture<DocumentSnapshot> future = document.get();22 DocumentSnapshot documentSnapshot = null;23 try {24 documentSnapshot = future.get();25 } catch (InterruptedException | ExecutionException e) {26 e.printStackTrace();27 }28 assertEquals("test", documentSnapshot.getString("test"));29 }30}31public class FirestoreEmulatorContainerTest {32 private static FirestoreEmulatorContainer container;33 private static Firestore firestore;34 public static void setUp() {35 container = new FirestoreEmulatorContainer("1.10.4");36 container.start();37 FirestoreOptions options = FirestoreOptions.newBuilder()38 .setProjectId("test")39 .setHost(container.getHost())40 .setPort(container.getPort())41 .setCredentials(NoCredentials.getInstance())42 .build();43 firestore = options.getService();44 }45 public static void tearDown() {46 container.stop();47 }48 public void testFirestoreEmulator() {49 DocumentReference document = firestore.collection("test").document("test");50 document.set(Collections.singletonMap("test", "test"));51 ApiFuture<DocumentSnapshot> future = document.get();52 DocumentSnapshot documentSnapshot = null;53 try {54 documentSnapshot = future.get();55 } catch (InterruptedException | ExecutionException e) {56 e.printStackTrace();57 }58 assertEquals("test", documentSnapshot.getString("test"));59 }60}

Full Screen

Full Screen

FirestoreEmulatorContainer

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.FirestoreEmulatorContainer;2import org.testcontainers.junit.jupiter.Container;3import org.testcontainers.junit.jupiter.Testcontainers;4public class MyTest {5 private static FirestoreEmulatorContainer firestoreEmulator = new FirestoreEmulatorContainer();6 public void testFirestore() {7 }8}

Full Screen

Full Screen

FirestoreEmulatorContainer

Using AI Code Generation

copy

Full Screen

1package com.dzone.albanoj2.zeal.testcontainers;2import static java.util.Collections.singletonList;3import java.util.List;4import org.junit.jupiter.api.Test;5import org.testcontainers.containers.FirestoreEmulatorContainer;6import org.testcontainers.junit.jupiter.Container;7import org.testcontainers.junit.jupiter.Testcontainers;8import com.google.cloud.firestore.Firestore;9import com.google.cloud.firestore.FirestoreOptions;10import com.google.cloud.firestore.QueryDocumentSnapshot;11import com.google.cloud.firestore.QuerySnapshot;12public class FirestoreEmulatorContainerTest {13 private static final FirestoreEmulatorContainer CONTAINER = new FirestoreEmulatorContainer();14 public void shouldQueryFirestore() throws Exception {15 FirestoreOptions options = FirestoreOptions.newBuilder()16 .setProjectId(FirestoreOptions.getDefaultProjectId())17 .setHost(CONTAINER.getEmulatorEndpoint())18 .setCredentials(FirestoreOptions.getDefaultCredentialsProvider().getCredentials())19 .build();20 Firestore firestore = options.getService();21 firestore.collection("cities").document("SF").set(singletonList("name")).get();22 firestore.collection("cities").document("LA").set(singletonList("name")).get();23 firestore.collection("cities").document("DC").set(singletonList("name")).get();24 QuerySnapshot querySnapshot = firestore.collection("cities").get().get();25 List<QueryDocumentSnapshot> documents = querySnapshot.getDocuments();26 System.out.println("Found " + documents.size() + " cities");27 }28}

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 method in FirestoreEmulatorContainer

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful