22
33import static org .junit .Assert .assertEquals ;
44import static org .junit .Assert .assertNotNull ;
5+ import static org .junit .Assert .assertSame ;
6+ import static org .junit .Assert .assertTrue ;
57import static org .junit .Assert .fail ;
68
79import com .google .auth .oauth2 .GoogleCredentials ;
810import com .google .cloud .firestore .Firestore ;
11+ import com .google .cloud .firestore .FirestoreOptions ;
912import com .google .firebase .FirebaseApp ;
1013import com .google .firebase .FirebaseOptions ;
14+ import com .google .firebase .FirebaseOptions .Builder ;
15+ import com .google .firebase .ImplFirebaseTrampolines ;
1116import com .google .firebase .TestOnlyImplFirebaseTrampolines ;
1217import com .google .firebase .testing .ServiceAccount ;
1318import java .io .IOException ;
@@ -26,6 +31,9 @@ public void testExplicitProjectId() throws IOException {
2631 FirebaseApp app = FirebaseApp .initializeApp (new FirebaseOptions .Builder ()
2732 .setCredentials (GoogleCredentials .fromStream (ServiceAccount .EDITOR .asStream ()))
2833 .setProjectId ("explicit-project-id" )
34+ .setFirestoreOptions (FirestoreOptions .newBuilder ()
35+ .setTimestampsInSnapshotsEnabled (true )
36+ .build ())
2937 .build ());
3038 Firestore firestore = FirestoreClient .getFirestore (app );
3139 assertEquals ("explicit-project-id" , firestore .getOptions ().getProjectId ());
@@ -38,6 +46,9 @@ public void testExplicitProjectId() throws IOException {
3846 public void testServiceAccountProjectId () throws IOException {
3947 FirebaseApp app = FirebaseApp .initializeApp (new FirebaseOptions .Builder ()
4048 .setCredentials (GoogleCredentials .fromStream (ServiceAccount .EDITOR .asStream ()))
49+ .setFirestoreOptions (FirestoreOptions .newBuilder ()
50+ .setTimestampsInSnapshotsEnabled (true )
51+ .build ())
4152 .build ());
4253 Firestore firestore = FirestoreClient .getFirestore (app );
4354 assertEquals ("mock-project-id" , firestore .getOptions ().getProjectId ());
@@ -46,11 +57,56 @@ public void testServiceAccountProjectId() throws IOException {
4657 assertEquals ("mock-project-id" , firestore .getOptions ().getProjectId ());
4758 }
4859
60+ @ Test
61+ public void testFirestoreOptions () throws IOException {
62+ FirebaseApp app = FirebaseApp .initializeApp (new Builder ()
63+ .setCredentials (GoogleCredentials .fromStream (ServiceAccount .EDITOR .asStream ()))
64+ .setProjectId ("explicit-project-id" )
65+ .setFirestoreOptions (FirestoreOptions .newBuilder ()
66+ .setTimestampsInSnapshotsEnabled (true )
67+ .build ())
68+ .build ());
69+ Firestore firestore = FirestoreClient .getFirestore (app );
70+ assertEquals ("explicit-project-id" , firestore .getOptions ().getProjectId ());
71+ assertTrue (firestore .getOptions ().areTimestampsInSnapshotsEnabled ());
72+
73+ firestore = FirestoreClient .getFirestore ();
74+ assertEquals ("explicit-project-id" , firestore .getOptions ().getProjectId ());
75+ assertTrue (firestore .getOptions ().areTimestampsInSnapshotsEnabled ());
76+ }
77+
78+ @ Test
79+ public void testFirestoreOptionsOverride () throws IOException {
80+ FirebaseApp app = FirebaseApp .initializeApp (new Builder ()
81+ .setCredentials (GoogleCredentials .fromStream (ServiceAccount .EDITOR .asStream ()))
82+ .setProjectId ("explicit-project-id" )
83+ .setFirestoreOptions (FirestoreOptions .newBuilder ()
84+ .setTimestampsInSnapshotsEnabled (true )
85+ .setProjectId ("other-project-id" )
86+ .setCredentials (GoogleCredentials .fromStream (ServiceAccount .EDITOR .asStream ()))
87+ .build ())
88+ .build ());
89+ Firestore firestore = FirestoreClient .getFirestore (app );
90+ assertEquals ("explicit-project-id" , firestore .getOptions ().getProjectId ());
91+ assertTrue (firestore .getOptions ().areTimestampsInSnapshotsEnabled ());
92+ assertSame (ImplFirebaseTrampolines .getCredentials (app ),
93+ firestore .getOptions ().getCredentialsProvider ().getCredentials ());
94+
95+ firestore = FirestoreClient .getFirestore ();
96+ assertEquals ("explicit-project-id" , firestore .getOptions ().getProjectId ());
97+ assertTrue (firestore .getOptions ().areTimestampsInSnapshotsEnabled ());
98+ assertSame (ImplFirebaseTrampolines .getCredentials (app ),
99+ firestore .getOptions ().getCredentialsProvider ().getCredentials ());
100+ }
101+
49102 @ Test
50103 public void testAppDelete () throws IOException {
51104 FirebaseApp app = FirebaseApp .initializeApp (new FirebaseOptions .Builder ()
52105 .setCredentials (GoogleCredentials .fromStream (ServiceAccount .EDITOR .asStream ()))
53106 .setProjectId ("mock-project-id" )
107+ .setFirestoreOptions (FirestoreOptions .newBuilder ()
108+ .setTimestampsInSnapshotsEnabled (true )
109+ .build ())
54110 .build ());
55111
56112 assertNotNull (FirestoreClient .getFirestore (app ));
0 commit comments