Skip to content

Commit 76dd3d2

Browse files
authored
Porting the legacy integration test suite (#2)
* Working on re-enabling the integration tests * Cleaned up verbose test output * Fixing integration tests * Added event test * Added the real time test * Adding data test back * Fixed the object serialization test * Adding a factory method to MapBuilder * Added transaction integration test * Added rules integration test * Updated rules test * Cleaning up the test code; Removed unnecessary utils and constants * Added more factory methods for MapBuilder; Removed unused legacy dependency * Dropped the jackson test dependency * Fixing some race conditions in ITs * Adding back some logging code; Dropping fblocal URLs * Dropping all references to fblocal * Removing port numbers from test URLs * Separated conjunctive assertions into separate ones for better error reporting.
1 parent 30702e7 commit 76dd3d2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+12451
-1372
lines changed

pom.xml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,22 +108,16 @@
108108
<version>0.6</version>
109109
<scope>test</scope>
110110
</dependency>
111-
<dependency>
112-
<groupId>org.codehaus.jackson</groupId>
113-
<artifactId>jackson-mapper-asl</artifactId>
114-
<version>1.9.13</version>
115-
<scope>test</scope>
116-
</dependency>
117111
<dependency>
118112
<groupId>org.hamcrest</groupId>
119113
<artifactId>hamcrest-library</artifactId>
120114
<version>1.3</version>
121115
<scope>test</scope>
122116
</dependency>
123117
<dependency>
124-
<groupId>com.firebase</groupId>
125-
<artifactId>firebase-token-generator</artifactId>
126-
<version>2.0.0</version>
118+
<groupId>com.cedarsoftware</groupId>
119+
<artifactId>java-util</artifactId>
120+
<version>1.26.0</version>
127121
<scope>test</scope>
128122
</dependency>
129123
<dependency>

src/test/java/com/google/firebase/FirebaseAppTest.java

Lines changed: 3 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static com.google.firebase.internal.Base64Utils.decodeUrlSafeNoPadding;
44
import static java.nio.charset.StandardCharsets.UTF_8;
55
import static org.junit.Assert.assertEquals;
6+
import static org.junit.Assert.assertFalse;
67
import static org.junit.Assert.assertTrue;
78
import static org.junit.Assert.fail;
89
import static org.mockito.Mockito.mock;
@@ -35,7 +36,6 @@
3536
import java.util.concurrent.Callable;
3637
import java.util.concurrent.TimeUnit;
3738
import org.junit.Assert;
38-
import org.junit.Before;
3939
import org.junit.Rule;
4040
import org.junit.Test;
4141
import org.mockito.Mockito;
@@ -55,47 +55,6 @@ public class FirebaseAppTest {
5555

5656
@Rule public FirebaseAppRule firebaseAppRule = new FirebaseAppRule();
5757

58-
@SuppressWarnings("unused")
59-
private static void assertAuthInitialized(FirebaseApp firebaseApp) {
60-
// TODO(depoll): Re-enable once Auth is available.
61-
// assertThat(FirebaseAuth.getInstancesForTest()).containsKey(firebaseApp
62-
// .getPersistenceKey());
63-
// FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(firebaseApp);
64-
// assertThat(firebaseAuth.getFirebaseApp()).isEqualTo(firebaseApp);
65-
}
66-
67-
private static void assertCrashInitialized() {
68-
// TODO(depoll): Re-enable if Crash becomes available.
69-
// assertThat(FirebaseCrash.isSingletonInitialized()).isTrue();
70-
}
71-
72-
private static void assertScionInitialized() {
73-
// TODO(depoll): Re-enable once Scion becomes available.
74-
// assertThat(Scion.getInstanceForTest()).isNotNull();
75-
}
76-
77-
@SuppressWarnings("unused")
78-
private static void assertIidInitialized(FirebaseApp firebaseApp) {
79-
// TODO(depoll): Re-enable once IID becomes available.
80-
// FirebaseInstanceId firebaseInstanceID =
81-
// FirebaseInstanceId.getInstancesForTest()
82-
// .get(firebaseApp.getOptions().getApplicationId());
83-
// assertThat(firebaseInstanceID).isNotNull();
84-
}
85-
86-
// TODO(arondeak): reenable persistence. See b/28158809.
87-
// @Test
88-
// public void testGetApps_persistenceEnabled() {
89-
// FirebaseApp app1 = FirebaseApp.initializeApp(mTargetContext, OPTIONS, "app1");
90-
// FirebaseApp app2 = FirebaseApp.initializeApp(mTargetContext, OPTIONS, "app2");
91-
// FirebaseApp.clearInstancesForTest();
92-
// // Sanity check that instances have been cleared.
93-
// assertThat(FirebaseApp.instances).isEmpty();
94-
// FirebaseApp app3 = FirebaseApp.initializeApp(mTargetContext, OPTIONS, "app3");
95-
// // We rely on FirebaseApp's equals override, app1 and app2 are different instances.
96-
// assertThat(FirebaseApp.getApps(mTargetContext)).containsExactly(app1, app2, app3);
97-
// }
98-
9958
private static void invokePublicInstanceMethodWithDefaultValues(Object instance, Method method)
10059
throws InvocationTargetException, IllegalAccessException {
10160
List<Object> parameters = new ArrayList<>(method.getParameterTypes().length);
@@ -105,12 +64,6 @@ private static void invokePublicInstanceMethodWithDefaultValues(Object instance,
10564
method.invoke(instance, parameters.toArray());
10665
}
10766

108-
@Before
109-
public void setUp() {
110-
// Used by Scion internally.
111-
// Scion.testOnlySetDefaultFactory(new ScionFactory(mTargetContext));
112-
}
113-
11467
@Test(expected = IllegalStateException.class)
11568
public void testGetInstancePersistedNotInitialized() {
11669
String name = "myApp";
@@ -212,24 +165,16 @@ public void testMissingInit() {
212165
}
213166

214167
@Test
215-
public void testAuthInitializedForNonDefaultApp() {
168+
public void testApiInitForNonDefaultApp() {
216169
FirebaseApp firebaseApp = FirebaseApp.initializeApp(OPTIONS, "myApp");
217-
assertAuthInitialized(firebaseApp);
218-
// Measurement is only initialized for the default app.
219-
// TODO(depoll): Re-enable once Scion becomes available.
220-
// assertThat(Scion.getInstanceForTest()).isNull();
170+
assertFalse(ImplFirebaseTrampolines.isDefaultApp(firebaseApp));
221171
}
222172

223173
@Test
224174
public void testApiInitForDefaultApp() {
225175
// Explicit initialization of FirebaseApp instance.
226176
FirebaseApp firebaseApp = FirebaseApp.initializeApp(OPTIONS);
227-
228177
assertTrue(ImplFirebaseTrampolines.isDefaultApp(firebaseApp));
229-
assertAuthInitialized(firebaseApp);
230-
assertCrashInitialized();
231-
assertIidInitialized(firebaseApp);
232-
assertScionInitialized();
233178
}
234179

235180
@Test

src/test/java/com/google/firebase/FirebaseOptionsTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public void onSuccess(GoogleCredential googleCredential) {
5252
}
5353

5454
@Test
55+
@SuppressWarnings("deprecation")
5556
public void createOptionsWithServiceAccountSet() throws IOException, InterruptedException {
5657
final Semaphore semaphore = new Semaphore(0);
5758
FirebaseOptions firebaseOptions =
@@ -115,6 +116,7 @@ public void createOptionsWithCredentialMissing() {
115116
}
116117

117118
@Test(expected = IllegalStateException.class)
119+
@SuppressWarnings("deprecation")
118120
public void createOptionsWithServiceAccountAndCredential() {
119121
new FirebaseOptions.Builder()
120122
.setServiceAccount(ServiceAccount.EDITOR.asStream())

src/test/java/com/google/firebase/auth/FirebaseAuthTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import com.google.firebase.FirebaseOptions;
1717
import com.google.firebase.TestOnlyImplFirebaseTrampolines;
1818
import com.google.firebase.auth.internal.FirebaseCustomAuthToken;
19+
import com.google.firebase.database.MapBuilder;
1920
import com.google.firebase.tasks.Tasks;
2021
import com.google.firebase.testing.ServiceAccount;
2122
import com.google.firebase.testing.TestUtils;
@@ -201,7 +202,7 @@ public void testCreateCustomTokenWithDeveloperClaims() throws Exception {
201202
FirebaseAuth auth = FirebaseAuth.getInstance(app);
202203

203204
String token =
204-
Tasks.await(auth.createCustomToken("user1", ImmutableMap.of("claim", (Object) "value")));
205+
Tasks.await(auth.createCustomToken("user1", MapBuilder.of("claim", "value")));
205206

206207
FirebaseCustomAuthToken parsedToken = FirebaseCustomAuthToken.parse(new GsonFactory(), token);
207208
assertEquals(parsedToken.getPayload().getUid(), "user1");

src/test/java/com/google/firebase/auth/FirebaseCredentialsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void defaultCredentialDoesntRefetch() throws Exception {
7171
Assert.assertEquals(ACCESS_TOKEN, token);
7272

7373
// We should still be able to fetch the token since the certificate is cached
74-
credentialsFile.delete();
74+
Assert.assertTrue(credentialsFile.delete());
7575
token =
7676
Tasks.await(
7777
FirebaseCredentials.applicationDefault(transport, Utils.getDefaultJsonFactory())

src/test/java/com/google/firebase/auth/TestOnlyImplFirebaseAuthTrampolines.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
* Provides trampolines into package-private Auth APIs used by components of Firebase
1616
*
1717
* <p>This class will not be compiled into the shipping library and can only be used in tests.
18-
*
19-
* @hide
2018
*/
2119
public final class TestOnlyImplFirebaseAuthTrampolines {
2220

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package com.google.firebase.database;
2+
3+
import static org.junit.Assert.assertArrayEquals;
4+
import static org.junit.Assert.assertFalse;
5+
import static org.junit.Assert.assertTrue;
6+
7+
import com.google.firebase.TestOnlyImplFirebaseTrampolines;
8+
import com.google.firebase.database.snapshot.IndexedNode;
9+
import com.google.firebase.database.snapshot.Node;
10+
import com.google.firebase.database.snapshot.NodeUtilities;
11+
import java.util.HashMap;
12+
import java.util.Iterator;
13+
import org.junit.AfterClass;
14+
import org.junit.Test;
15+
16+
public class DataSnapshotTest {
17+
18+
@AfterClass
19+
public static void tearDownClass() {
20+
TestOnlyImplFirebaseTrampolines.clearInstancesForTest();
21+
}
22+
23+
private DataSnapshot snapFor(Object data) {
24+
Node node = NodeUtilities.NodeFromJSON(data);
25+
DatabaseReference ref = new DatabaseReference("https://test.firebaseio.com", TestHelpers
26+
.newTestConfig());
27+
return new DataSnapshot(ref, IndexedNode.from(node));
28+
}
29+
30+
@Test
31+
public void testBasicIteration() {
32+
DataSnapshot snap1 = snapFor(null);
33+
34+
assertFalse(snap1.hasChildren());
35+
assertFalse(snap1.getChildren().iterator().hasNext());
36+
37+
DataSnapshot snap2 = snapFor(1L);
38+
assertFalse(snap2.hasChildren());
39+
assertFalse(snap2.getChildren().iterator().hasNext());
40+
41+
DataSnapshot snap3 = snapFor(MapBuilder.of("a", 1L, "b", 2L));
42+
assertTrue(snap3.hasChildren());
43+
Iterator<DataSnapshot> iter = snap3.getChildren().iterator();
44+
assertTrue(iter.hasNext());
45+
46+
String[] children = new String[] {null, null};
47+
int i = 0;
48+
for (DataSnapshot child : snap3.getChildren()) {
49+
children[i] = child.getKey();
50+
i++;
51+
}
52+
assertArrayEquals(children, new String[] {"a", "b"});
53+
}
54+
55+
@Test
56+
public void testExists() {
57+
DataSnapshot snap;
58+
59+
snap = snapFor(new HashMap<>());
60+
assertFalse(snap.exists());
61+
62+
snap = snapFor(MapBuilder.of(".priority", 1));
63+
assertFalse(snap.exists());
64+
65+
snap = snapFor(null);
66+
assertFalse(snap.exists());
67+
68+
snap = snapFor(true);
69+
assertTrue(snap.exists());
70+
71+
snap = snapFor(5);
72+
assertTrue(snap.exists());
73+
74+
snap = snapFor(MapBuilder.of("x", 5));
75+
assertTrue(snap.exists());
76+
}
77+
}

0 commit comments

Comments
 (0)