Java Code Examples for com.google.firebase.FirebaseApp#enableEmulators()

The following examples show how to use com.google.firebase.FirebaseApp#enableEmulators() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FirebaseFirestoreTest.java    From firebase-android-sdk with Apache License 2.0 6 votes vote down vote up
@Test
public void getInstance_withEmulator() {
  FirebaseApp app = getApp("getInstance_withEmulator");

  app.enableEmulators(
      new EmulatorSettings.Builder()
          .addEmulatedService(
              FirebaseFirestore.EMULATOR, new EmulatedServiceSettings("10.0.2.2", 8080))
          .build());

  FirebaseFirestore firestore = FirebaseFirestore.getInstance(app);
  FirebaseFirestoreSettings settings = firestore.getFirestoreSettings();

  assertEquals(settings.getHost(), "10.0.2.2:8080");
  assertFalse(settings.isSslEnabled());
}
 
Example 2
Source File: FirebaseFirestoreTest.java    From firebase-android-sdk with Apache License 2.0 6 votes vote down vote up
@Test
public void getInstance_withEmulator_mergeSettingsSuccess() {
  FirebaseApp app = getApp("getInstance_withEmulator_mergeSettingsSuccess");
  app.enableEmulators(
      new EmulatorSettings.Builder()
          .addEmulatedService(
              FirebaseFirestore.EMULATOR, new EmulatedServiceSettings("10.0.2.2", 8080))
          .build());

  FirebaseFirestore firestore = FirebaseFirestore.getInstance(app);
  firestore.setFirestoreSettings(
      new FirebaseFirestoreSettings.Builder().setPersistenceEnabled(false).build());

  FirebaseFirestoreSettings settings = firestore.getFirestoreSettings();

  assertEquals(settings.getHost(), "10.0.2.2:8080");
  assertFalse(settings.isSslEnabled());
  assertFalse(settings.isPersistenceEnabled());
}
 
Example 3
Source File: FirebaseFirestoreTest.java    From firebase-android-sdk with Apache License 2.0 6 votes vote down vote up
@Test
public void getInstance_withEmulator_mergeSettingsFailure() {
  FirebaseApp app = getApp("getInstance_withEmulator_mergeSettingsFailure");
  app.enableEmulators(
      new EmulatorSettings.Builder()
          .addEmulatedService(
              FirebaseFirestore.EMULATOR, new EmulatedServiceSettings("10.0.2.2", 8080))
          .build());

  try {
    FirebaseFirestore firestore = FirebaseFirestore.getInstance(app);
    firestore.setFirestoreSettings(
        new FirebaseFirestoreSettings.Builder().setHost("myhost.com").build());
    fail("Exception should be thrown");
  } catch (Exception e) {
    assertTrue(e instanceof IllegalStateException);
    assertEquals(
        e.getMessage(),
        "Cannot specify the host in FirebaseFirestoreSettings when EmulatedServiceSettings is provided.");
  }
}
 
Example 4
Source File: FirebaseFirestoreTest.java    From firebase-android-sdk with Apache License 2.0 6 votes vote down vote up
@Test
public void setSettings_repeatedSuccess_withEmulator() {
  FirebaseApp app = getApp("setSettings_repeatedSuccess_withEmulator");
  app.enableEmulators(
      new EmulatorSettings.Builder()
          .addEmulatedService(
              FirebaseFirestore.EMULATOR, new EmulatedServiceSettings("10.0.2.2", 8080))
          .build());

  FirebaseFirestore firestore = FirebaseFirestore.getInstance(app);

  FirebaseFirestoreSettings settings =
      new FirebaseFirestoreSettings.Builder().setPersistenceEnabled(false).build();
  firestore.setFirestoreSettings(settings);

  // This should 'start' Firestore
  DocumentReference reference = firestore.document("foo/bar");

  // Second settings set should pass because the settings are equal
  firestore.setFirestoreSettings(settings);
}
 
Example 5
Source File: FirebaseDatabaseTest.java    From firebase-android-sdk with Apache License 2.0 6 votes vote down vote up
@Test
public void getInstanceForAppWithEmulator() {
  FirebaseApp app =
      appForDatabaseUrl(IntegrationTestValues.getAltNamespace(), "getInstanceForAppWithEmulator");

  EmulatedServiceSettings serviceSettings = new EmulatedServiceSettings("10.0.2.2", 9000);
  EmulatorSettings emulatorSettings =
      new EmulatorSettings.Builder()
          .addEmulatedService(FirebaseDatabase.EMULATOR, serviceSettings)
          .build();
  app.enableEmulators(emulatorSettings);

  FirebaseDatabase db = FirebaseDatabase.getInstance(app);
  DatabaseReference rootRef = db.getReference();
  assertEquals(rootRef.toString(), "http://10.0.2.2:9000");

  DatabaseReference urlReference = db.getReferenceFromUrl("https://otherns.firebaseio.com");
  assertEquals(urlReference.toString(), "http://10.0.2.2:9000");
}
 
Example 6
Source File: FirebaseFunctionsTest.java    From firebase-android-sdk with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetUrl_withEmulator() {
  FirebaseApp app = getApp("testGetUrl_withEmulator");

  app.enableEmulators(
      new EmulatorSettings.Builder()
          .addEmulatedService(
              FirebaseFunctions.EMULATOR, new EmulatedServiceSettings("10.0.2.2", 5001))
          .build());

  URL withRegion = FirebaseFunctions.getInstance(app, "my-region").getURL("my-endpoint");
  assertEquals("http://10.0.2.2:5001/my-project/my-region/my-endpoint", withRegion.toString());

  URL withoutRegion = FirebaseFunctions.getInstance(app).getURL("my-endpoint");
  assertEquals(
      "http://10.0.2.2:5001/my-project/us-central1/my-endpoint", withoutRegion.toString());
}
 
Example 7
Source File: FirebaseFunctionsTest.java    From firebase-android-sdk with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetUrl_withEmulator_matchesOldImpl() {
  FirebaseApp app = getApp("testGetUrl_withEmulator_matchesOldImpl");

  app.enableEmulators(
      new EmulatorSettings.Builder()
          .addEmulatedService(
              FirebaseFunctions.EMULATOR, new EmulatedServiceSettings("10.0.2.2", 5001))
          .build());

  FirebaseFunctions functions = FirebaseFunctions.getInstance(app);
  URL newImplUrl = functions.getURL("my-endpoint");

  functions.useFunctionsEmulator("http://10.0.2.2:5001");
  URL oldImplUrl = functions.getURL("my-endpoint");

  assertEquals(newImplUrl.toString(), oldImplUrl.toString());
}