From 2c9a9c398eb2b6f6e3b9587d92382d01b79286e3 Mon Sep 17 00:00:00 2001 From: Ankita Jhawar Date: Mon, 2 Dec 2019 21:34:38 -0800 Subject: [PATCH] Renaming getAuthToken to getToken. --- .../FirebaseInstallationsApi.java | 4 +- firebase-installations/api.txt | 2 +- ...FirebaseInstallationsInstrumentedTest.java | 51 +++++++++---------- .../PersistedInstallationEntrySubject.java | 2 +- .../installations/FirebaseInstallations.java | 2 +- 5 files changed, 28 insertions(+), 33 deletions(-) diff --git a/firebase-installations-interop/src/main/java/com/google/firebase/installations/FirebaseInstallationsApi.java b/firebase-installations-interop/src/main/java/com/google/firebase/installations/FirebaseInstallationsApi.java index 7ecdb6a9961..fb08cb808dc 100644 --- a/firebase-installations-interop/src/main/java/com/google/firebase/installations/FirebaseInstallationsApi.java +++ b/firebase-installations-interop/src/main/java/com/google/firebase/installations/FirebaseInstallationsApi.java @@ -39,7 +39,7 @@ public interface FirebaseInstallationsApi { int DO_NOT_FORCE_REFRESH = 0; /** * AuthToken is forcefully refreshed on calling the {@link - * FirebaseInstallationsApi#getAuthToken(int)}. + * FirebaseInstallationsApi#getToken(int)}. */ int FORCE_REFRESH = 1; @@ -50,7 +50,7 @@ public interface FirebaseInstallationsApi { Task getId(); /** Async function that returns a auth token(public key) of this Firebase app installation. */ - Task getAuthToken(@AuthTokenOption int authTokenOption); + Task getToken(@AuthTokenOption int authTokenOption); /** * Async function that deletes this Firebase app installation from Firebase backend. This call diff --git a/firebase-installations/api.txt b/firebase-installations/api.txt index 06028ad7b5d..630322f0856 100644 --- a/firebase-installations/api.txt +++ b/firebase-installations/api.txt @@ -3,10 +3,10 @@ package com.google.firebase.installations { public class FirebaseInstallations { method @NonNull public Task delete(); - method @NonNull public Task getAuthToken(int); method @NonNull public Task getId(); method @NonNull public static com.google.firebase.installations.FirebaseInstallations getInstance(); method @NonNull public static com.google.firebase.installations.FirebaseInstallations getInstance(@NonNull FirebaseApp); + method @NonNull public Task getToken(int); } public class FirebaseInstallationsException { diff --git a/firebase-installations/src/androidTest/java/com/google/firebase/installations/FirebaseInstallationsInstrumentedTest.java b/firebase-installations/src/androidTest/java/com/google/firebase/installations/FirebaseInstallationsInstrumentedTest.java index 26ae5acd6c8..1f8bb1de203 100644 --- a/firebase-installations/src/androidTest/java/com/google/firebase/installations/FirebaseInstallationsInstrumentedTest.java +++ b/firebase-installations/src/androidTest/java/com/google/firebase/installations/FirebaseInstallationsInstrumentedTest.java @@ -489,7 +489,7 @@ public void testGetAuthToken_fidDoesNotExist_successful() throws Exception { when(mockUtils.isAuthTokenExpired(REGISTERED_INSTALLATION_ENTRY)).thenReturn(/*isValid*/ false); FirebaseInstallations firebaseInstallations = getFirebaseInstallations(); - Tasks.await(firebaseInstallations.getAuthToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH)); + Tasks.await(firebaseInstallations.getToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH)); PersistedInstallationEntry entryValue = persistedInstallation.readPersistedInstallationEntryValue(); @@ -510,8 +510,7 @@ public void testGetAuthToken_PersistedInstallationError_failure() throws Excepti // Expect exception try { - Tasks.await( - firebaseInstallations.getAuthToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH)); + Tasks.await(firebaseInstallations.getToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH)); fail("Could not update local storage."); } catch (ExecutionException expected) { assertWithMessage("Exception class doesn't match") @@ -540,8 +539,7 @@ public void testGetAuthToken_fidExists_successful() throws Exception { mockIidStore); InstallationTokenResult installationTokenResult = - Tasks.await( - firebaseInstallations.getAuthToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH)); + Tasks.await(firebaseInstallations.getToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH)); assertWithMessage("Persisted Auth Token doesn't match") .that(installationTokenResult.getToken()) @@ -551,7 +549,7 @@ public void testGetAuthToken_fidExists_successful() throws Exception { } @Test - public void testGetAuthToken_expiredAuthToken_fetchedNewTokenFromFIS() throws Exception { + public void testGetToken_expiredAuthToken_fetchedNewTokenFromFIS() throws Exception { persistedInstallation.insertOrUpdatePersistedInstallationEntry(EXPIRED_AUTH_TOKEN_ENTRY); when(mockUtils.isAuthTokenExpired(EXPIRED_AUTH_TOKEN_ENTRY)).thenReturn(/*isExpired*/ true); when(mockUtils.isAuthTokenExpired(UPDATED_AUTH_TOKEN_ENTRY)).thenReturn(/*isValid*/ false); @@ -559,8 +557,7 @@ public void testGetAuthToken_expiredAuthToken_fetchedNewTokenFromFIS() throws Ex FirebaseInstallations firebaseInstallations = getFirebaseInstallations(); InstallationTokenResult installationTokenResult = - Tasks.await( - firebaseInstallations.getAuthToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH)); + Tasks.await(firebaseInstallations.getToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH)); assertWithMessage("Persisted Auth Token doesn't match") .that(installationTokenResult.getToken()) @@ -570,8 +567,8 @@ public void testGetAuthToken_expiredAuthToken_fetchedNewTokenFromFIS() throws Ex } @Test - public void testGetAuthToken_unregisteredFid_fetchedNewTokenFromFIS() throws Exception { - // Update local storage with a unregistered installation entry to validate that getAuthToken + public void testGetToken_unregisteredFid_fetchedNewTokenFromFIS() throws Exception { + // Update local storage with a unregistered installation entry to validate that getToken // calls getId to ensure FID registration and returns a valid auth token. persistedInstallation.insertOrUpdatePersistedInstallationEntry(UNREGISTERED_INSTALLATION_ENTRY); when(mockUtils.isAuthTokenExpired(REGISTERED_INSTALLATION_ENTRY)).thenReturn(/*isValid*/ false); @@ -579,8 +576,7 @@ public void testGetAuthToken_unregisteredFid_fetchedNewTokenFromFIS() throws Exc FirebaseInstallations firebaseInstallations = getFirebaseInstallations(); InstallationTokenResult installationTokenResult = - Tasks.await( - firebaseInstallations.getAuthToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH)); + Tasks.await(firebaseInstallations.getToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH)); assertWithMessage("Persisted Auth Token doesn't match") .that(installationTokenResult.getToken()) @@ -590,7 +586,7 @@ public void testGetAuthToken_unregisteredFid_fetchedNewTokenFromFIS() throws Exc } @Test - public void testGetAuthToken_fidError_persistedInstallationCleared() throws Exception { + public void testGetToken_fidError_persistedInstallationCleared() throws Exception { // Update local storage with an expired installation entry to ensure that generate auth token // is called. persistedInstallation.insertOrUpdatePersistedInstallationEntry(EXPIRED_AUTH_TOKEN_ENTRY); @@ -606,8 +602,8 @@ public void testGetAuthToken_fidError_persistedInstallationCleared() throws Exce // Expect exception try { - Tasks.await(firebaseInstallations.getAuthToken(FirebaseInstallationsApi.FORCE_REFRESH)); - fail("getAuthToken() failed due to Server Error."); + Tasks.await(firebaseInstallations.getToken(FirebaseInstallationsApi.FORCE_REFRESH)); + fail("getToken() failed due to Server Error."); } catch (ExecutionException expected) { assertWithMessage("Exception class doesn't match") .that(expected) @@ -626,7 +622,7 @@ public void testGetAuthToken_fidError_persistedInstallationCleared() throws Exce } @Test - public void testGetAuthToken_serverError_failure() throws Exception { + public void testGetToken_serverError_failure() throws Exception { when(mockPersistedInstallation.readPersistedInstallationEntryValue()) .thenReturn(REGISTERED_INSTALLATION_ENTRY); when(backendClientReturnsError.generateAuthToken( @@ -645,8 +641,8 @@ public void testGetAuthToken_serverError_failure() throws Exception { // Expect exception try { - Tasks.await(firebaseInstallations.getAuthToken(FirebaseInstallationsApi.FORCE_REFRESH)); - fail("getAuthToken() failed due to Server Error."); + Tasks.await(firebaseInstallations.getToken(FirebaseInstallationsApi.FORCE_REFRESH)); + fail("getToken() failed due to Server Error."); } catch (ExecutionException expected) { assertWithMessage("Exception class doesn't match") .that(expected) @@ -659,8 +655,7 @@ public void testGetAuthToken_serverError_failure() throws Exception { } @Test - public void testGetAuthToken_multipleCallsDoNotForceRefresh_fetchedNewTokenOnce() - throws Exception { + public void testGetToken_multipleCallsDoNotForceRefresh_fetchedNewTokenOnce() throws Exception { // Update local storage with a EXPIRED_AUTH_TOKEN_ENTRY to validate the flow of multiple tasks // triggered simultaneously. Task2 waits for Task1 to complete. On task1 completion, task2 reads // the UPDATED_AUTH_TOKEN_FID_ENTRY generated by Task1. @@ -670,11 +665,11 @@ public void testGetAuthToken_multipleCallsDoNotForceRefresh_fetchedNewTokenOnce( FirebaseInstallations firebaseInstallations = getFirebaseInstallations(); - // Call getAuthToken multiple times with DO_NOT_FORCE_REFRESH option + // Call getToken multiple times with DO_NOT_FORCE_REFRESH option Task task1 = - firebaseInstallations.getAuthToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH); + firebaseInstallations.getToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH); Task task2 = - firebaseInstallations.getAuthToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH); + firebaseInstallations.getToken(FirebaseInstallationsApi.DO_NOT_FORCE_REFRESH); Tasks.await(Tasks.whenAllComplete(task1, task2)); @@ -689,10 +684,10 @@ public void testGetAuthToken_multipleCallsDoNotForceRefresh_fetchedNewTokenOnce( } @Test - public void testGetAuthToken_multipleCallsForceRefresh_fetchedNewTokenTwice() throws Exception { + public void testGetToken_multipleCallsForceRefresh_fetchedNewTokenTwice() throws Exception { persistedInstallation.insertOrUpdatePersistedInstallationEntry(REGISTERED_INSTALLATION_ENTRY); // Use a mock ServiceClient for network calls with delay(500ms) to ensure first task is not - // completed before the second task starts. Hence, we can test multiple calls to getAuthToken() + // completed before the second task starts. Hence, we can test multiple calls to getToken() // and verify one task waits for another task to complete. doAnswer( @@ -719,11 +714,11 @@ public void testGetAuthToken_multipleCallsForceRefresh_fetchedNewTokenTwice() th FirebaseInstallations firebaseInstallations = getFirebaseInstallations(); - // Call getAuthToken multiple times with FORCE_REFRESH option. + // Call getToken multiple times with FORCE_REFRESH option. Task task1 = - firebaseInstallations.getAuthToken(FirebaseInstallationsApi.FORCE_REFRESH); + firebaseInstallations.getToken(FirebaseInstallationsApi.FORCE_REFRESH); Task task2 = - firebaseInstallations.getAuthToken(FirebaseInstallationsApi.FORCE_REFRESH); + firebaseInstallations.getToken(FirebaseInstallationsApi.FORCE_REFRESH); Tasks.await(Tasks.whenAllComplete(task1, task2)); // As we cannot ensure which task got executed first, verifying with both expected values diff --git a/firebase-installations/src/androidTest/java/com/google/firebase/installations/local/PersistedInstallationEntrySubject.java b/firebase-installations/src/androidTest/java/com/google/firebase/installations/local/PersistedInstallationEntrySubject.java index 84c738ef42c..702b4684d2a 100644 --- a/firebase-installations/src/androidTest/java/com/google/firebase/installations/local/PersistedInstallationEntrySubject.java +++ b/firebase-installations/src/androidTest/java/com/google/firebase/installations/local/PersistedInstallationEntrySubject.java @@ -63,7 +63,7 @@ public void hasFid(String fid) { } public void hasAuthToken(String authToken) { - check("getAuthToken()").that(actual.getAuthToken()).isEqualTo(authToken); + check("getToken()").that(actual.getAuthToken()).isEqualTo(authToken); } public void hasRefreshToken(String refreshToken) { diff --git a/firebase-installations/src/main/java/com/google/firebase/installations/FirebaseInstallations.java b/firebase-installations/src/main/java/com/google/firebase/installations/FirebaseInstallations.java index b0aff260fd1..9dc2ec666d1 100644 --- a/firebase-installations/src/main/java/com/google/firebase/installations/FirebaseInstallations.java +++ b/firebase-installations/src/main/java/com/google/firebase/installations/FirebaseInstallations.java @@ -151,7 +151,7 @@ public Task getId() { */ @NonNull @Override - public Task getAuthToken(@AuthTokenOption int authTokenOption) { + public Task getToken(@AuthTokenOption int authTokenOption) { Task task = addGetAuthTokenListener(authTokenOption); executor.execute(this::doRegistration); return task;