本文整理汇总了Java中com.google.firebase.FirebaseOptions类的典型用法代码示例。如果您正苦于以下问题:Java FirebaseOptions类的具体用法?Java FirebaseOptions怎么用?Java FirebaseOptions使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FirebaseOptions类属于com.google.firebase包,在下文中一共展示了FirebaseOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testVerifyIdTokenWithExplicitProjectId
import com.google.firebase.FirebaseOptions; //导入依赖的package包/类
@Test
public void testVerifyIdTokenWithExplicitProjectId() throws Exception {
GoogleCredentials credentials = TestOnlyImplFirebaseTrampolines.getCredentials(firebaseOptions);
Assume.assumeFalse(
"Skipping testVerifyIdTokenWithExplicitProjectId for service account credentials",
credentials instanceof ServiceAccountCredentials);
FirebaseOptions options =
new FirebaseOptions.Builder(firebaseOptions)
.setProjectId("mock-project-id")
.build();
FirebaseApp app = FirebaseApp.initializeApp(options, "testVerifyIdTokenWithExplicitProjectId");
try {
FirebaseAuth.getInstance(app).verifyIdTokenAsync("foo").get();
fail("Expected exception.");
} catch (ExecutionException expected) {
Assert.assertNotEquals(
"com.google.firebase.FirebaseException: Must initialize FirebaseApp with a project ID "
+ "to call verifyIdToken()",
expected.getMessage());
assertTrue(expected.getCause() instanceof IllegalArgumentException);
}
}
示例2: testDatabaseAuthVariablesAuthorization
import com.google.firebase.FirebaseOptions; //导入依赖的package包/类
@Test
public void testDatabaseAuthVariablesAuthorization() throws InterruptedException {
Map<String, Object> authVariableOverrides = ImmutableMap.<String, Object>of(
"uid", "test",
"custom", "secret"
);
FirebaseOptions options =
new FirebaseOptions.Builder(masterApp.getOptions())
.setDatabaseAuthVariableOverride(authVariableOverrides)
.build();
FirebaseApp testUidApp = FirebaseApp.initializeApp(options, "testGetAppWithUid");
FirebaseDatabase masterDb = FirebaseDatabase.getInstance(masterApp);
FirebaseDatabase testAuthOverridesDb = FirebaseDatabase.getInstance(testUidApp);
assertWriteSucceeds(masterDb.getReference());
// "test" UID can only read/write to /test-uid-only and /test-custom-field-only locations.
assertWriteFails(testAuthOverridesDb.getReference());
assertWriteSucceeds(testAuthOverridesDb.getReference("test-uid-only"));
assertReadSucceeds(testAuthOverridesDb.getReference("test-uid-only"));
assertWriteSucceeds(testAuthOverridesDb.getReference("test-custom-field-only"));
assertReadSucceeds(testAuthOverridesDb.getReference("test-custom-field-only"));
}
示例3: testDatabaseAuthVariablesNoAuthorization
import com.google.firebase.FirebaseOptions; //导入依赖的package包/类
@Test
public void testDatabaseAuthVariablesNoAuthorization() throws InterruptedException {
FirebaseOptions options =
new FirebaseOptions.Builder(masterApp.getOptions())
.setDatabaseAuthVariableOverride(null)
.build();
FirebaseApp testUidApp =
FirebaseApp.initializeApp(options, "testServiceAccountDatabaseWithNoAuth");
FirebaseDatabase masterDb = FirebaseDatabase.getInstance(masterApp);
FirebaseDatabase testAuthOverridesDb = FirebaseDatabase.getInstance(testUidApp);
assertWriteSucceeds(masterDb.getReference());
assertWriteFails(testAuthOverridesDb.getReference("test-uid-only"));
assertReadFails(testAuthOverridesDb.getReference("test-uid-only"));
assertWriteFails(testAuthOverridesDb.getReference("test-custom-field-only"));
assertReadFails(testAuthOverridesDb.getReference("test-custom-field-only"));
assertWriteSucceeds(testAuthOverridesDb.getReference("test-noauth-only"));
}
示例4: setUpClass
import com.google.firebase.FirebaseOptions; //导入依赖的package包/类
@BeforeClass
public static void setUpClass() throws IOException {
// Init app with non-admin privileges
Map<String, Object> auth = MapBuilder.of("uid", "my-service-worker");
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.fromStream(
IntegrationTestUtils.getServiceAccountCertificate()))
.setDatabaseUrl(IntegrationTestUtils.getDatabaseUrl())
.setDatabaseAuthVariableOverride(auth)
.build();
masterApp = FirebaseApp.initializeApp(options, "RulesTestIT");
List<DatabaseReference> refs = IntegrationTestUtils.getRandomNode(masterApp, 2);
reader = refs.get(0);
writer = refs.get(1);
String rules = JsonMapper.serializeJson(
MapBuilder.of("rules", MapBuilder.of(writer.getKey(), testRules)));
uploadRules(rules);
TestHelpers.waitForRoundtrip(writer.getRoot());
}
示例5: testGetToken
import com.google.firebase.FirebaseOptions; //导入依赖的package包/类
@Test
public void testGetToken() throws IOException, InterruptedException {
MockGoogleCredentials credentials = new MockGoogleCredentials("mock-token");
TokenRefreshDetector refreshDetector = new TokenRefreshDetector();
credentials.addChangeListener(refreshDetector);
credentials.refresh();
assertEquals(1, refreshDetector.count);
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(credentials)
.build();
FirebaseApp app = FirebaseApp.initializeApp(options);
JvmAuthTokenProvider provider = new JvmAuthTokenProvider(app, DIRECT_EXECUTOR);
TestGetTokenListener listener = new TestGetTokenListener();
provider.getToken(true, listener);
assertToken(listener.get(), "mock-token", ImmutableMap.<String, Object>of());
assertEquals(2, refreshDetector.count);
}
示例6: testGetTokenNoRefresh
import com.google.firebase.FirebaseOptions; //导入依赖的package包/类
@Test
public void testGetTokenNoRefresh() throws IOException, InterruptedException {
MockGoogleCredentials credentials = new MockGoogleCredentials("mock-token");
TokenRefreshDetector refreshDetector = new TokenRefreshDetector();
credentials.addChangeListener(refreshDetector);
credentials.refresh();
assertEquals(1, refreshDetector.count);
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(credentials)
.build();
FirebaseApp app = FirebaseApp.initializeApp(options);
JvmAuthTokenProvider provider = new JvmAuthTokenProvider(app, DIRECT_EXECUTOR);
TestGetTokenListener listener = new TestGetTokenListener();
provider.getToken(false, listener);
assertToken(listener.get(), "mock-token", ImmutableMap.<String, Object>of());
assertEquals(1, refreshDetector.count);
}
示例7: testGetTokenError
import com.google.firebase.FirebaseOptions; //导入依赖的package包/类
@Test
public void testGetTokenError() throws InterruptedException {
MockGoogleCredentials credentials = new MockGoogleCredentials("mock-token") {
@Override
public AccessToken refreshAccessToken() throws IOException {
throw new RuntimeException("Test error");
}
};
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(credentials)
.build();
FirebaseApp app = FirebaseApp.initializeApp(options);
JvmAuthTokenProvider provider = new JvmAuthTokenProvider(app, DIRECT_EXECUTOR);
TestGetTokenListener listener = new TestGetTokenListener();
provider.getToken(true, listener);
assertEquals("java.lang.RuntimeException: Test error", listener.get());
}
示例8: userAgentHasCorrectParts
import com.google.firebase.FirebaseOptions; //导入依赖的package包/类
@Test
public void userAgentHasCorrectParts() {
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(TestUtils.getCertCredential(ServiceAccount.EDITOR.asStream()))
.build();
FirebaseApp app = FirebaseApp.initializeApp(options, "userAgentApp");
try {
Context cfg = new DatabaseConfig();
cfg.firebaseApp = app;
cfg.freeze();
String userAgent = cfg.getUserAgent();
String[] parts = userAgent.split("/");
assertEquals(5, parts.length);
assertEquals("Firebase", parts[0]); // Firebase
assertEquals(Constants.WIRE_PROTOCOL_VERSION, parts[1]); // Wire protocol version
assertEquals(FirebaseDatabase.getSdkVersion(), parts[2]); // SDK version
assertEquals(System.getProperty("java.version", "Unknown"), parts[3]); // Java "OS" version
assertEquals(Platform.DEVICE, parts[4]); // AdminJava
} finally {
TestOnlyImplFirebaseTrampolines.clearInstancesForTest();
}
}
示例9: testAppDelete
import com.google.firebase.FirebaseOptions; //导入依赖的package包/类
@Test
public void testAppDelete() throws IOException {
FirebaseApp app = FirebaseApp.initializeApp(new FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.fromStream(ServiceAccount.EDITOR.asStream()))
.setStorageBucket("mock-bucket-name")
.build());
assertNotNull(StorageClient.getInstance());
assertNotNull(StorageClient.getInstance(app));
app.delete();
try {
StorageClient.getInstance(app);
fail("No error thrown for deleted app");
} catch (IllegalStateException expected) {
// ignore
}
}
示例10: testGlobalThreadManager
import com.google.firebase.FirebaseOptions; //导入依赖的package包/类
@Test
public void testGlobalThreadManager() {
MockThreadManager threadManager = new MockThreadManager();
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(new MockGoogleCredentials())
.setThreadManager(threadManager)
.build();
FirebaseApp defaultApp = FirebaseApp.initializeApp(options);
assertEquals(1, threadManager.initCount);
ExecutorService exec1 = threadManager.getExecutor(defaultApp);
assertEquals(1, threadManager.initCount);
assertFalse(exec1.isShutdown());
ExecutorService exec2 = threadManager.getExecutor(defaultApp);
assertEquals(1, threadManager.initCount);
assertFalse(exec2.isShutdown());
// Should return the same executor for both invocations.
assertSame(exec1, exec2);
threadManager.releaseExecutor(defaultApp, exec1);
assertTrue(exec1.isShutdown());
}
示例11: testGlobalThreadManagerReInit
import com.google.firebase.FirebaseOptions; //导入依赖的package包/类
@Test
public void testGlobalThreadManagerReInit() {
MockThreadManager threadManager = new MockThreadManager();
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(new MockGoogleCredentials())
.setThreadManager(threadManager)
.build();
FirebaseApp defaultApp = FirebaseApp.initializeApp(options);
assertEquals(1, threadManager.initCount);
ExecutorService exec1 = threadManager.getExecutor(defaultApp);
assertEquals(1, threadManager.initCount);
assertFalse(exec1.isShutdown());
// Simulate app.delete()
threadManager.releaseExecutor(defaultApp, exec1);
assertTrue(exec1.isShutdown());
// Simulate app re-init
ExecutorService exec2 = threadManager.getExecutor(defaultApp);
assertEquals(2, threadManager.initCount);
assertNotSame(exec1, exec2);
threadManager.releaseExecutor(defaultApp, exec2);
assertTrue(exec2.isShutdown());
}
示例12: initFirebase
import com.google.firebase.FirebaseOptions; //导入依赖的package包/类
/**
* Inicializace firebase služby
*/
private void initFirebase() {
try {
InputStream serviceAccount = getClass().getResourceAsStream(FIREBASE_CREDENTAILS);
Map<String, Object> auth = new HashMap<>();
auth.put("uid", "my_resources");
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredential(FirebaseCredentials.fromCertificate(serviceAccount))
.setDatabaseUrl(FIREBASE_URL)
.setDatabaseAuthVariableOverride(auth)
.build();
FirebaseApp.initializeApp(options);
} catch (Exception e) {
logger.info("Nemůžu se připojit k firebase", e);
}
}
示例13: onCreate
import com.google.firebase.FirebaseOptions; //导入依赖的package包/类
/**
* Setup the global firebase parameters
*/
@Override
public void onCreate() {
super.onCreate();
FirebaseOptions firebaseOptions = new FirebaseOptions.Builder()
.setProjectId(getString(R.string.project_id))
.setApplicationId(getString(R.string.google_app_id))
.setDatabaseUrl(getString(R.string.firebase_database_url))
.setGcmSenderId(getString(R.string.gcm_defaultSenderId))
.setApiKey(getString(R.string.google_api_key))
.setStorageBucket(getString(R.string.google_storage_bucket))
.build();
FirebaseApp.initializeApp(this, firebaseOptions);
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
String databaseUrl = FirebaseApp.getInstance().getOptions().getDatabaseUrl();
Log.i("BaseApplication", "DatabaseUrl: " + databaseUrl);
}
示例14: onCreate
import com.google.firebase.FirebaseOptions; //导入依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
FirebaseOptions firebaseOptions = new FirebaseOptions.Builder()
.setProjectId(getString(R.string.mock_project_id))
.setApplicationId(getString(R.string.mock_google_app_id))
.setDatabaseUrl(getString(R.string.mock_firebase_database_url))
.setGcmSenderId(getString(R.string.mock_gcm_defaultSenderId))
.setApiKey(getString(R.string.mock_google_api_key))
.setStorageBucket(getString(R.string.mock_google_storage_bucket))
.build();
FirebaseApp.initializeApp(this, firebaseOptions);
FirebaseAuth.getInstance().signOut();
}
示例15: firebaseApp
import com.google.firebase.FirebaseOptions; //导入依赖的package包/类
@Provides
@Singleton
static FirebaseApp firebaseApp(FirebaseAuthConfig config) {
final FirebaseOptions options;
try {
options =
new FirebaseOptions.Builder()
.setCredential(
FirebaseCredentials.fromCertificate(
new ByteArrayInputStream(
Base64.getDecoder().decode(config.getServiceAccountBase64()))))
.setDatabaseUrl("https://" + config.getProjectId() + ".firebaseio.com")
.build();
} catch (IOException e) {
throw new UncheckedIOException("Could not read certificate.", e);
}
FirebaseApp.initializeApp(options);
return FirebaseApp.getInstance();
}