Skip to content

Porting the legacy integration test suite #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 36 commits into from
Apr 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
428eedb
Initial code migration:
Apr 6, 2017
cfbbd6a
Reformatting code according to check-style plugin conventions
hiranya911 Apr 6, 2017
59842b8
Code reformatting: Fixing javadoc indentation
hiranya911 Apr 6, 2017
fef4ecf
More reformatting: Added google check style config
hiranya911 Apr 6, 2017
a606833
Code formatting continued
hiranya911 Apr 6, 2017
1d2ed82
Code formatting continued
hiranya911 Apr 6, 2017
8972b1b
Reformatting
hiranya911 Apr 6, 2017
e5509c3
Fixed all checkstyle violations; Build configured to fail on lint errors
Apr 6, 2017
0587d52
Updated checkstyle config
Apr 6, 2017
7f2f470
Working on re-enabling the integration tests
Apr 7, 2017
8ee5cfc
Temporarily removing IT test cases
Apr 7, 2017
dbc6ee6
Extending checkstyle coverage to test sourcesw
Apr 7, 2017
c66f35b
Cleaned up verbose test output
Apr 7, 2017
f7cbdc2
Adding 2 integration tests to verify the maven integration test support
Apr 7, 2017
7715b90
Moving test only trampolines to the test/ subtree; Adding a removed m…
Apr 10, 2017
c3591ed
Fixing integration tests
hiranya911 Apr 11, 2017
bc54329
Added event test
hiranya911 Apr 11, 2017
75df20f
Added the real time test
hiranya911 Apr 11, 2017
471d0a9
Adding data test back
hiranya911 Apr 11, 2017
f692bb6
Fixed the object serialization test
hiranya911 Apr 11, 2017
c368248
Adding a factory method to MapBuilder
hiranya911 Apr 11, 2017
a30ae95
Added transaction integration test
hiranya911 Apr 11, 2017
7714024
Added transaction test
hiranya911 Apr 11, 2017
2da7955
Added rules integration test
hiranya911 Apr 11, 2017
094d756
Updated rules test
hiranya911 Apr 11, 2017
f446c79
Merge branch 'hkj-initial-code-migration' into hkj-db-integration-tests
hiranya911 Apr 11, 2017
952c6b0
Cleaning up the test code; Removed unnecessary utils and constants
hiranya911 Apr 12, 2017
594bfbb
Added more factory methods for MapBuilder; Removed unused legacy depe…
hiranya911 Apr 12, 2017
5dc413f
Dropped the jackson test dependency
hiranya911 Apr 12, 2017
2da5b03
Fixed test race condition
Apr 13, 2017
7d39734
Fixing some race conditions in ITs
Apr 13, 2017
4b0361c
Cleaning up EventHelper instances after use
hiranya911 Apr 13, 2017
3d3be22
Adding back some logging code; Dropping fblocal URLs
Apr 13, 2017
eefc4ce
Dropping all references to fblocal
Apr 13, 2017
e911387
Removing port numbers from test URLs
Apr 14, 2017
3c7f98f
Separated conjunctive assertions into separate ones for better error …
hiranya911 Apr 14, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,16 @@
<version>0.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.firebase</groupId>
<artifactId>firebase-token-generator</artifactId>
<version>2.0.0</version>
<groupId>com.cedarsoftware</groupId>
<artifactId>java-util</artifactId>
<version>1.26.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
61 changes: 3 additions & 58 deletions src/test/java/com/google/firebase/FirebaseAppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static com.google.firebase.internal.Base64Utils.decodeUrlSafeNoPadding;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -35,7 +36,6 @@
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mockito;
Expand All @@ -55,47 +55,6 @@ public class FirebaseAppTest {

@Rule public FirebaseAppRule firebaseAppRule = new FirebaseAppRule();

@SuppressWarnings("unused")
private static void assertAuthInitialized(FirebaseApp firebaseApp) {
// TODO(depoll): Re-enable once Auth is available.
// assertThat(FirebaseAuth.getInstancesForTest()).containsKey(firebaseApp
// .getPersistenceKey());
// FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(firebaseApp);
// assertThat(firebaseAuth.getFirebaseApp()).isEqualTo(firebaseApp);
}

private static void assertCrashInitialized() {
// TODO(depoll): Re-enable if Crash becomes available.
// assertThat(FirebaseCrash.isSingletonInitialized()).isTrue();
}

private static void assertScionInitialized() {
// TODO(depoll): Re-enable once Scion becomes available.
// assertThat(Scion.getInstanceForTest()).isNotNull();
}

@SuppressWarnings("unused")
private static void assertIidInitialized(FirebaseApp firebaseApp) {
// TODO(depoll): Re-enable once IID becomes available.
// FirebaseInstanceId firebaseInstanceID =
// FirebaseInstanceId.getInstancesForTest()
// .get(firebaseApp.getOptions().getApplicationId());
// assertThat(firebaseInstanceID).isNotNull();
}

// TODO(arondeak): reenable persistence. See b/28158809.
// @Test
// public void testGetApps_persistenceEnabled() {
// FirebaseApp app1 = FirebaseApp.initializeApp(mTargetContext, OPTIONS, "app1");
// FirebaseApp app2 = FirebaseApp.initializeApp(mTargetContext, OPTIONS, "app2");
// FirebaseApp.clearInstancesForTest();
// // Sanity check that instances have been cleared.
// assertThat(FirebaseApp.instances).isEmpty();
// FirebaseApp app3 = FirebaseApp.initializeApp(mTargetContext, OPTIONS, "app3");
// // We rely on FirebaseApp's equals override, app1 and app2 are different instances.
// assertThat(FirebaseApp.getApps(mTargetContext)).containsExactly(app1, app2, app3);
// }

private static void invokePublicInstanceMethodWithDefaultValues(Object instance, Method method)
throws InvocationTargetException, IllegalAccessException {
List<Object> parameters = new ArrayList<>(method.getParameterTypes().length);
Expand All @@ -105,12 +64,6 @@ private static void invokePublicInstanceMethodWithDefaultValues(Object instance,
method.invoke(instance, parameters.toArray());
}

@Before
public void setUp() {
// Used by Scion internally.
// Scion.testOnlySetDefaultFactory(new ScionFactory(mTargetContext));
}

@Test(expected = IllegalStateException.class)
public void testGetInstancePersistedNotInitialized() {
String name = "myApp";
Expand Down Expand Up @@ -212,24 +165,16 @@ public void testMissingInit() {
}

@Test
public void testAuthInitializedForNonDefaultApp() {
public void testApiInitForNonDefaultApp() {
FirebaseApp firebaseApp = FirebaseApp.initializeApp(OPTIONS, "myApp");
assertAuthInitialized(firebaseApp);
// Measurement is only initialized for the default app.
// TODO(depoll): Re-enable once Scion becomes available.
// assertThat(Scion.getInstanceForTest()).isNull();
assertFalse(ImplFirebaseTrampolines.isDefaultApp(firebaseApp));
}

@Test
public void testApiInitForDefaultApp() {
// Explicit initialization of FirebaseApp instance.
FirebaseApp firebaseApp = FirebaseApp.initializeApp(OPTIONS);

assertTrue(ImplFirebaseTrampolines.isDefaultApp(firebaseApp));
assertAuthInitialized(firebaseApp);
assertCrashInitialized();
assertIidInitialized(firebaseApp);
assertScionInitialized();
}

@Test
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/com/google/firebase/FirebaseOptionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public void onSuccess(GoogleCredential googleCredential) {
}

@Test
@SuppressWarnings("deprecation")
public void createOptionsWithServiceAccountSet() throws IOException, InterruptedException {
final Semaphore semaphore = new Semaphore(0);
FirebaseOptions firebaseOptions =
Expand Down Expand Up @@ -115,6 +116,7 @@ public void createOptionsWithCredentialMissing() {
}

@Test(expected = IllegalStateException.class)
@SuppressWarnings("deprecation")
public void createOptionsWithServiceAccountAndCredential() {
new FirebaseOptions.Builder()
.setServiceAccount(ServiceAccount.EDITOR.asStream())
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/com/google/firebase/auth/FirebaseAuthTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.google.firebase.FirebaseOptions;
import com.google.firebase.TestOnlyImplFirebaseTrampolines;
import com.google.firebase.auth.internal.FirebaseCustomAuthToken;
import com.google.firebase.database.MapBuilder;
import com.google.firebase.tasks.Tasks;
import com.google.firebase.testing.ServiceAccount;
import com.google.firebase.testing.TestUtils;
Expand Down Expand Up @@ -201,7 +202,7 @@ public void testCreateCustomTokenWithDeveloperClaims() throws Exception {
FirebaseAuth auth = FirebaseAuth.getInstance(app);

String token =
Tasks.await(auth.createCustomToken("user1", ImmutableMap.of("claim", (Object) "value")));
Tasks.await(auth.createCustomToken("user1", MapBuilder.of("claim", "value")));

FirebaseCustomAuthToken parsedToken = FirebaseCustomAuthToken.parse(new GsonFactory(), token);
assertEquals(parsedToken.getPayload().getUid(), "user1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void defaultCredentialDoesntRefetch() throws Exception {
Assert.assertEquals(ACCESS_TOKEN, token);

// We should still be able to fetch the token since the certificate is cached
credentialsFile.delete();
Assert.assertTrue(credentialsFile.delete());
token =
Tasks.await(
FirebaseCredentials.applicationDefault(transport, Utils.getDefaultJsonFactory())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
* Provides trampolines into package-private Auth APIs used by components of Firebase
*
* <p>This class will not be compiled into the shipping library and can only be used in tests.
*
* @hide
*/
public final class TestOnlyImplFirebaseAuthTrampolines {

Expand Down
77 changes: 77 additions & 0 deletions src/test/java/com/google/firebase/database/DataSnapshotTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.google.firebase.database;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import com.google.firebase.TestOnlyImplFirebaseTrampolines;
import com.google.firebase.database.snapshot.IndexedNode;
import com.google.firebase.database.snapshot.Node;
import com.google.firebase.database.snapshot.NodeUtilities;
import java.util.HashMap;
import java.util.Iterator;
import org.junit.AfterClass;
import org.junit.Test;

public class DataSnapshotTest {

@AfterClass
public static void tearDownClass() {
TestOnlyImplFirebaseTrampolines.clearInstancesForTest();
}

private DataSnapshot snapFor(Object data) {
Node node = NodeUtilities.NodeFromJSON(data);
DatabaseReference ref = new DatabaseReference("https://test.firebaseio.com", TestHelpers
.newTestConfig());
return new DataSnapshot(ref, IndexedNode.from(node));
}

@Test
public void testBasicIteration() {
DataSnapshot snap1 = snapFor(null);

assertFalse(snap1.hasChildren());
assertFalse(snap1.getChildren().iterator().hasNext());

DataSnapshot snap2 = snapFor(1L);
assertFalse(snap2.hasChildren());
assertFalse(snap2.getChildren().iterator().hasNext());

DataSnapshot snap3 = snapFor(MapBuilder.of("a", 1L, "b", 2L));
assertTrue(snap3.hasChildren());
Iterator<DataSnapshot> iter = snap3.getChildren().iterator();
assertTrue(iter.hasNext());

String[] children = new String[] {null, null};
int i = 0;
for (DataSnapshot child : snap3.getChildren()) {
children[i] = child.getKey();
i++;
}
assertArrayEquals(children, new String[] {"a", "b"});
}

@Test
public void testExists() {
DataSnapshot snap;

snap = snapFor(new HashMap<>());
assertFalse(snap.exists());

snap = snapFor(MapBuilder.of(".priority", 1));
assertFalse(snap.exists());

snap = snapFor(null);
assertFalse(snap.exists());

snap = snapFor(true);
assertTrue(snap.exists());

snap = snapFor(5);
assertTrue(snap.exists());

snap = snapFor(MapBuilder.of("x", 5));
assertTrue(snap.exists());
}
}
Loading