Skip to content

Commit 6b134b2

Browse files
authored
Add new smoke tests for Storage and Database. (#331)
* Add new smoke tests for Storage and Database. * Rename test methods.
1 parent 13df083 commit 6b134b2

File tree

5 files changed

+197
-3
lines changed

5 files changed

+197
-3
lines changed

smoke-tests/build.gradle

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,20 @@ android {
3838
flavorDimensions "systemUnderTest"
3939

4040
productFlavors {
41+
database {
42+
dimension "systemUnderTest"
43+
applicationId "com.google.firebase.testing.database"
44+
}
45+
4146
firestore {
4247
dimension "systemUnderTest"
4348
applicationId "com.google.firebase.testing.firestore"
4449
}
50+
51+
storage {
52+
dimension "systemUnderTest"
53+
applicationId "com.google.firebase.testing.storage"
54+
}
4555
}
4656
}
4757

@@ -52,19 +62,24 @@ repositories {
5262

5363
dependencies {
5464
// Common
55-
5665
api "androidx.test:runner:1.1.0"
66+
api "com.google.truth:truth:0.43"
5767
api "junit:junit:4.12"
5868

5969
implementation "androidx.test:rules:1.1.0"
6070
implementation "com.google.firebase:firebase-common:16.0.7"
6171

72+
// Database
73+
databaseImplementation "com.google.firebase:firebase-auth:16.1.0"
74+
databaseImplementation "com.google.firebase:firebase-database:16.1.0"
75+
6276
// Firestore
63-
firestoreImplementation "com.google.android.gms:play-services-tasks:16.0.1"
6477
firestoreImplementation "com.google.firebase:firebase-auth:16.1.0"
6578
firestoreImplementation "com.google.firebase:firebase-firestore:18.1.0"
66-
firestoreImplementation "com.google.truth:truth:0.43"
6779

80+
// Storage
81+
storageImplementation "com.google.firebase:firebase-auth:16.1.0"
82+
storageImplementation "com.google.firebase:firebase-storage:16.1.0"
6883
}
6984

7085
apply plugin: "com.google.gms.google-services"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.google.firebase.testing">
3+
4+
<uses-permission android:name="android.permission.INTERNET" />
5+
6+
<application>
7+
<activity android:name="android.app.Activity">
8+
<intent-filter>
9+
<action android:name="android.intent.action.MAIN" />
10+
<category android:name="android.intent.category.LAUNCHER" />
11+
</intent-filter>
12+
</activity>
13+
14+
<meta-data android:name="com.google.firebase.testing.classes"
15+
android:value="com.google.firebase.testing.database.DatabaseTest" />
16+
</application>
17+
</manifest>
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// Copyright 2018 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.firebase.testing.database;
16+
17+
import static com.google.common.truth.Truth.assertThat;
18+
19+
import android.app.Activity;
20+
import androidx.test.rule.ActivityTestRule;
21+
import androidx.test.runner.AndroidJUnit4;
22+
import com.google.android.gms.tasks.Task;
23+
import com.google.android.gms.tasks.TaskCompletionSource;
24+
import com.google.firebase.auth.FirebaseAuth;
25+
import com.google.firebase.database.DataSnapshot;
26+
import com.google.firebase.database.DatabaseError;
27+
import com.google.firebase.database.DatabaseReference;
28+
import com.google.firebase.database.FirebaseDatabase;
29+
import com.google.firebase.database.ValueEventListener;
30+
import com.google.firebase.testing.common.Tasks2;
31+
import java.util.HashMap;
32+
import org.junit.Rule;
33+
import org.junit.Test;
34+
import org.junit.runner.RunWith;
35+
36+
/** Database smoke tests. */
37+
@RunWith(AndroidJUnit4.class)
38+
public final class DatabaseTest {
39+
40+
@Rule public final ActivityTestRule<Activity> activity = new ActivityTestRule<>(Activity.class);
41+
42+
@Test
43+
public void setValueShouldTriggerListenerWithNewlySetData() throws Exception {
44+
FirebaseAuth auth = FirebaseAuth.getInstance();
45+
FirebaseDatabase database = FirebaseDatabase.getInstance();
46+
47+
auth.signOut();
48+
Task<?> signInTask = auth.signInWithEmailAndPassword("[email protected]", "password");
49+
Tasks2.waitForSuccess(signInTask);
50+
51+
DatabaseReference doc = database.getReference("restaurants").child("Baadal");
52+
SnapshotListener listener = new SnapshotListener();
53+
doc.addListenerForSingleValueEvent(listener);
54+
55+
HashMap<String, Object> data = new HashMap<>();
56+
data.put("location", "Google NYC");
57+
58+
Task<?> setTask = doc.setValue(new HashMap<>(data));
59+
Task<DataSnapshot> snapshotTask = listener.toTask();
60+
Tasks2.waitForSuccess(setTask);
61+
Tasks2.waitForSuccess(snapshotTask);
62+
63+
DataSnapshot result = snapshotTask.getResult();
64+
assertThat(result.getValue()).isEqualTo(data);
65+
}
66+
67+
private static class SnapshotListener implements ValueEventListener {
68+
private final TaskCompletionSource<DataSnapshot> taskFactory = new TaskCompletionSource<>();
69+
70+
@Override
71+
public void onCancelled(DatabaseError error) {
72+
taskFactory.trySetException(error.toException());
73+
}
74+
75+
@Override
76+
public void onDataChange(DataSnapshot snapshot) {
77+
taskFactory.trySetResult(snapshot);
78+
}
79+
80+
public Task<DataSnapshot> toTask() {
81+
return taskFactory.getTask();
82+
}
83+
}
84+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.google.firebase.testing">
3+
4+
<uses-permission android:name="android.permission.INTERNET" />
5+
6+
<application>
7+
<activity android:name="android.app.Activity">
8+
<intent-filter>
9+
<action android:name="android.intent.action.MAIN" />
10+
<category android:name="android.intent.category.LAUNCHER" />
11+
</intent-filter>
12+
</activity>
13+
14+
<meta-data android:name="com.google.firebase.testing.classes"
15+
android:value="com.google.firebase.testing.storage.StorageTest" />
16+
</application>
17+
</manifest>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright 2018 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.firebase.testing.storage;
16+
17+
import static com.google.common.truth.Truth.assertThat;
18+
19+
import android.app.Activity;
20+
import androidx.test.rule.ActivityTestRule;
21+
import androidx.test.runner.AndroidJUnit4;
22+
import com.google.android.gms.tasks.Task;
23+
import com.google.firebase.auth.FirebaseAuth;
24+
import com.google.firebase.storage.FirebaseStorage;
25+
import com.google.firebase.storage.StorageReference;
26+
import com.google.firebase.testing.common.Tasks2;
27+
import java.nio.charset.StandardCharsets;
28+
import java.util.Arrays;
29+
import org.junit.Rule;
30+
import org.junit.Test;
31+
import org.junit.runner.RunWith;
32+
33+
/** Storage smoke tests. */
34+
@RunWith(AndroidJUnit4.class)
35+
public final class StorageTest {
36+
37+
@Rule public final ActivityTestRule<Activity> activity = new ActivityTestRule<>(Activity.class);
38+
39+
@Test
40+
public void getShouldReturnNewlyPutData() throws Exception {
41+
FirebaseAuth auth = FirebaseAuth.getInstance();
42+
FirebaseStorage storage = FirebaseStorage.getInstance();
43+
44+
auth.signOut();
45+
Task<?> signInTask = auth.signInWithEmailAndPassword("[email protected]", "password");
46+
Tasks2.waitForSuccess(signInTask);
47+
48+
StorageReference blob = storage.getReference("restaurants/Baadal");
49+
50+
byte[] data = "Google NYC".getBytes(StandardCharsets.UTF_8);
51+
52+
Task<?> putTask = blob.putBytes(Arrays.copyOf(data, data.length));
53+
Tasks2.waitForSuccess(putTask);
54+
55+
Task<byte[]> getTask = blob.getBytes(128);
56+
Tasks2.waitForSuccess(getTask);
57+
58+
byte[] result = getTask.getResult();
59+
assertThat(result).isEqualTo(data);
60+
}
61+
}

0 commit comments

Comments
 (0)