2727import com .google .api .gax .rpc .InvalidArgumentException ;
2828import com .google .common .collect .Lists ;
2929import com .google .firestore .admin .v1 .CreateIndexRequest ;
30+ import com .google .firestore .admin .v1 .DatabaseName ;
3031import com .google .firestore .admin .v1 .DeleteIndexRequest ;
3132import com .google .firestore .admin .v1 .ExportDocumentsRequest ;
3233import com .google .firestore .admin .v1 .Field ;
34+ import com .google .firestore .admin .v1 .FieldName ;
3335import com .google .firestore .admin .v1 .GetFieldRequest ;
3436import com .google .firestore .admin .v1 .GetIndexRequest ;
3537import com .google .firestore .admin .v1 .ImportDocumentsRequest ;
3638import com .google .firestore .admin .v1 .Index ;
39+ import com .google .firestore .admin .v1 .IndexName ;
3740import com .google .firestore .admin .v1 .ListFieldsRequest ;
3841import com .google .firestore .admin .v1 .ListFieldsResponse ;
3942import com .google .firestore .admin .v1 .ListIndexesRequest ;
4043import com .google .firestore .admin .v1 .ListIndexesResponse ;
44+ import com .google .firestore .admin .v1 .ParentName ;
4145import com .google .firestore .admin .v1 .UpdateFieldRequest ;
4246import com .google .longrunning .Operation ;
4347import com .google .protobuf .Empty ;
@@ -99,8 +103,7 @@ public void createIndexTest() {
99103 Operation expectedResponse = Operation .newBuilder ().setName (name ).setDone (done ).build ();
100104 mockFirestoreAdmin .addResponse (expectedResponse );
101105
102- String formattedParent =
103- FirestoreAdminClient .formatParentName ("[PROJECT]" , "[DATABASE]" , "[COLLECTION_ID]" );
106+ String formattedParent = ParentName .format ("[PROJECT]" , "[DATABASE]" , "[COLLECTION_ID]" );
104107 Index index = Index .newBuilder ().build ();
105108
106109 Operation actualResponse = client .createIndex (formattedParent , index );
@@ -125,8 +128,7 @@ public void createIndexExceptionTest() throws Exception {
125128 mockFirestoreAdmin .addException (exception );
126129
127130 try {
128- String formattedParent =
129- FirestoreAdminClient .formatParentName ("[PROJECT]" , "[DATABASE]" , "[COLLECTION_ID]" );
131+ String formattedParent = ParentName .format ("[PROJECT]" , "[DATABASE]" , "[COLLECTION_ID]" );
130132 Index index = Index .newBuilder ().build ();
131133
132134 client .createIndex (formattedParent , index );
@@ -149,8 +151,7 @@ public void listIndexesTest() {
149151 .build ();
150152 mockFirestoreAdmin .addResponse (expectedResponse );
151153
152- String formattedParent =
153- FirestoreAdminClient .formatParentName ("[PROJECT]" , "[DATABASE]" , "[COLLECTION_ID]" );
154+ String formattedParent = ParentName .format ("[PROJECT]" , "[DATABASE]" , "[COLLECTION_ID]" );
154155
155156 ListIndexesPagedResponse pagedListResponse = client .listIndexes (formattedParent );
156157
@@ -176,8 +177,7 @@ public void listIndexesExceptionTest() throws Exception {
176177 mockFirestoreAdmin .addException (exception );
177178
178179 try {
179- String formattedParent =
180- FirestoreAdminClient .formatParentName ("[PROJECT]" , "[DATABASE]" , "[COLLECTION_ID]" );
180+ String formattedParent = ParentName .format ("[PROJECT]" , "[DATABASE]" , "[COLLECTION_ID]" );
181181
182182 client .listIndexes (formattedParent );
183183 Assert .fail ("No exception raised" );
@@ -193,18 +193,16 @@ public void getIndexTest() {
193193 Index expectedResponse = Index .newBuilder ().setName (name2 ).build ();
194194 mockFirestoreAdmin .addResponse (expectedResponse );
195195
196- String formattedName =
197- FirestoreAdminClient .formatIndexName (
198- "[PROJECT]" , "[DATABASE]" , "[COLLECTION_ID]" , "[INDEX_ID]" );
196+ IndexName name = IndexName .of ("[PROJECT]" , "[DATABASE]" , "[COLLECTION_ID]" , "[INDEX_ID]" );
199197
200- Index actualResponse = client .getIndex (formattedName );
198+ Index actualResponse = client .getIndex (name );
201199 Assert .assertEquals (expectedResponse , actualResponse );
202200
203201 List <GeneratedMessageV3 > actualRequests = mockFirestoreAdmin .getRequests ();
204202 Assert .assertEquals (1 , actualRequests .size ());
205203 GetIndexRequest actualRequest = (GetIndexRequest ) actualRequests .get (0 );
206204
207- Assert .assertEquals (formattedName , actualRequest .getName ());
205+ Assert .assertEquals (name , IndexName . parse ( actualRequest .getName () ));
208206 Assert .assertTrue (
209207 channelProvider .isHeaderSent (
210208 ApiClientHeaderProvider .getDefaultApiClientHeaderKey (),
@@ -218,11 +216,9 @@ public void getIndexExceptionTest() throws Exception {
218216 mockFirestoreAdmin .addException (exception );
219217
220218 try {
221- String formattedName =
222- FirestoreAdminClient .formatIndexName (
223- "[PROJECT]" , "[DATABASE]" , "[COLLECTION_ID]" , "[INDEX_ID]" );
219+ IndexName name = IndexName .of ("[PROJECT]" , "[DATABASE]" , "[COLLECTION_ID]" , "[INDEX_ID]" );
224220
225- client .getIndex (formattedName );
221+ client .getIndex (name );
226222 Assert .fail ("No exception raised" );
227223 } catch (InvalidArgumentException e ) {
228224 // Expected exception
@@ -235,17 +231,15 @@ public void deleteIndexTest() {
235231 Empty expectedResponse = Empty .newBuilder ().build ();
236232 mockFirestoreAdmin .addResponse (expectedResponse );
237233
238- String formattedName =
239- FirestoreAdminClient .formatIndexName (
240- "[PROJECT]" , "[DATABASE]" , "[COLLECTION_ID]" , "[INDEX_ID]" );
234+ IndexName name = IndexName .of ("[PROJECT]" , "[DATABASE]" , "[COLLECTION_ID]" , "[INDEX_ID]" );
241235
242- client .deleteIndex (formattedName );
236+ client .deleteIndex (name );
243237
244238 List <GeneratedMessageV3 > actualRequests = mockFirestoreAdmin .getRequests ();
245239 Assert .assertEquals (1 , actualRequests .size ());
246240 DeleteIndexRequest actualRequest = (DeleteIndexRequest ) actualRequests .get (0 );
247241
248- Assert .assertEquals (formattedName , actualRequest .getName ());
242+ Assert .assertEquals (name , IndexName . parse ( actualRequest .getName () ));
249243 Assert .assertTrue (
250244 channelProvider .isHeaderSent (
251245 ApiClientHeaderProvider .getDefaultApiClientHeaderKey (),
@@ -259,11 +253,9 @@ public void deleteIndexExceptionTest() throws Exception {
259253 mockFirestoreAdmin .addException (exception );
260254
261255 try {
262- String formattedName =
263- FirestoreAdminClient .formatIndexName (
264- "[PROJECT]" , "[DATABASE]" , "[COLLECTION_ID]" , "[INDEX_ID]" );
256+ IndexName name = IndexName .of ("[PROJECT]" , "[DATABASE]" , "[COLLECTION_ID]" , "[INDEX_ID]" );
265257
266- client .deleteIndex (formattedName );
258+ client .deleteIndex (name );
267259 Assert .fail ("No exception raised" );
268260 } catch (InvalidArgumentException e ) {
269261 // Expected exception
@@ -278,16 +270,16 @@ public void importDocumentsTest() {
278270 Operation expectedResponse = Operation .newBuilder ().setName (name2 ).setDone (done ).build ();
279271 mockFirestoreAdmin .addResponse (expectedResponse );
280272
281- String formattedName = FirestoreAdminClient . formatDatabaseName ("[PROJECT]" , "[DATABASE]" );
273+ DatabaseName name = DatabaseName . of ("[PROJECT]" , "[DATABASE]" );
282274
283- Operation actualResponse = client .importDocuments (formattedName );
275+ Operation actualResponse = client .importDocuments (name );
284276 Assert .assertEquals (expectedResponse , actualResponse );
285277
286278 List <GeneratedMessageV3 > actualRequests = mockFirestoreAdmin .getRequests ();
287279 Assert .assertEquals (1 , actualRequests .size ());
288280 ImportDocumentsRequest actualRequest = (ImportDocumentsRequest ) actualRequests .get (0 );
289281
290- Assert .assertEquals (formattedName , actualRequest .getName ());
282+ Assert .assertEquals (name , DatabaseName . parse ( actualRequest .getName () ));
291283 Assert .assertTrue (
292284 channelProvider .isHeaderSent (
293285 ApiClientHeaderProvider .getDefaultApiClientHeaderKey (),
@@ -301,9 +293,9 @@ public void importDocumentsExceptionTest() throws Exception {
301293 mockFirestoreAdmin .addException (exception );
302294
303295 try {
304- String formattedName = FirestoreAdminClient . formatDatabaseName ("[PROJECT]" , "[DATABASE]" );
296+ DatabaseName name = DatabaseName . of ("[PROJECT]" , "[DATABASE]" );
305297
306- client .importDocuments (formattedName );
298+ client .importDocuments (name );
307299 Assert .fail ("No exception raised" );
308300 } catch (InvalidArgumentException e ) {
309301 // Expected exception
@@ -318,16 +310,16 @@ public void exportDocumentsTest() {
318310 Operation expectedResponse = Operation .newBuilder ().setName (name2 ).setDone (done ).build ();
319311 mockFirestoreAdmin .addResponse (expectedResponse );
320312
321- String formattedName = FirestoreAdminClient . formatDatabaseName ("[PROJECT]" , "[DATABASE]" );
313+ DatabaseName name = DatabaseName . of ("[PROJECT]" , "[DATABASE]" );
322314
323- Operation actualResponse = client .exportDocuments (formattedName );
315+ Operation actualResponse = client .exportDocuments (name );
324316 Assert .assertEquals (expectedResponse , actualResponse );
325317
326318 List <GeneratedMessageV3 > actualRequests = mockFirestoreAdmin .getRequests ();
327319 Assert .assertEquals (1 , actualRequests .size ());
328320 ExportDocumentsRequest actualRequest = (ExportDocumentsRequest ) actualRequests .get (0 );
329321
330- Assert .assertEquals (formattedName , actualRequest .getName ());
322+ Assert .assertEquals (name , DatabaseName . parse ( actualRequest .getName () ));
331323 Assert .assertTrue (
332324 channelProvider .isHeaderSent (
333325 ApiClientHeaderProvider .getDefaultApiClientHeaderKey (),
@@ -341,9 +333,9 @@ public void exportDocumentsExceptionTest() throws Exception {
341333 mockFirestoreAdmin .addException (exception );
342334
343335 try {
344- String formattedName = FirestoreAdminClient . formatDatabaseName ("[PROJECT]" , "[DATABASE]" );
336+ DatabaseName name = DatabaseName . of ("[PROJECT]" , "[DATABASE]" );
345337
346- client .exportDocuments (formattedName );
338+ client .exportDocuments (name );
347339 Assert .fail ("No exception raised" );
348340 } catch (InvalidArgumentException e ) {
349341 // Expected exception
@@ -357,18 +349,16 @@ public void getFieldTest() {
357349 Field expectedResponse = Field .newBuilder ().setName (name2 ).build ();
358350 mockFirestoreAdmin .addResponse (expectedResponse );
359351
360- String formattedName =
361- FirestoreAdminClient .formatFieldName (
362- "[PROJECT]" , "[DATABASE]" , "[COLLECTION_ID]" , "[FIELD_ID]" );
352+ FieldName name = FieldName .of ("[PROJECT]" , "[DATABASE]" , "[COLLECTION_ID]" , "[FIELD_ID]" );
363353
364- Field actualResponse = client .getField (formattedName );
354+ Field actualResponse = client .getField (name );
365355 Assert .assertEquals (expectedResponse , actualResponse );
366356
367357 List <GeneratedMessageV3 > actualRequests = mockFirestoreAdmin .getRequests ();
368358 Assert .assertEquals (1 , actualRequests .size ());
369359 GetFieldRequest actualRequest = (GetFieldRequest ) actualRequests .get (0 );
370360
371- Assert .assertEquals (formattedName , actualRequest .getName ());
361+ Assert .assertEquals (name , FieldName . parse ( actualRequest .getName () ));
372362 Assert .assertTrue (
373363 channelProvider .isHeaderSent (
374364 ApiClientHeaderProvider .getDefaultApiClientHeaderKey (),
@@ -382,11 +372,9 @@ public void getFieldExceptionTest() throws Exception {
382372 mockFirestoreAdmin .addException (exception );
383373
384374 try {
385- String formattedName =
386- FirestoreAdminClient .formatFieldName (
387- "[PROJECT]" , "[DATABASE]" , "[COLLECTION_ID]" , "[FIELD_ID]" );
375+ FieldName name = FieldName .of ("[PROJECT]" , "[DATABASE]" , "[COLLECTION_ID]" , "[FIELD_ID]" );
388376
389- client .getField (formattedName );
377+ client .getField (name );
390378 Assert .fail ("No exception raised" );
391379 } catch (InvalidArgumentException e ) {
392380 // Expected exception
@@ -406,8 +394,7 @@ public void listFieldsTest() {
406394 .build ();
407395 mockFirestoreAdmin .addResponse (expectedResponse );
408396
409- String formattedParent =
410- FirestoreAdminClient .formatParentName ("[PROJECT]" , "[DATABASE]" , "[COLLECTION_ID]" );
397+ String formattedParent = ParentName .format ("[PROJECT]" , "[DATABASE]" , "[COLLECTION_ID]" );
411398
412399 ListFieldsPagedResponse pagedListResponse = client .listFields (formattedParent );
413400
@@ -433,8 +420,7 @@ public void listFieldsExceptionTest() throws Exception {
433420 mockFirestoreAdmin .addException (exception );
434421
435422 try {
436- String formattedParent =
437- FirestoreAdminClient .formatParentName ("[PROJECT]" , "[DATABASE]" , "[COLLECTION_ID]" );
423+ String formattedParent = ParentName .format ("[PROJECT]" , "[DATABASE]" , "[COLLECTION_ID]" );
438424
439425 client .listFields (formattedParent );
440426 Assert .fail ("No exception raised" );
0 commit comments