Skip to content
This repository was archived by the owner on Sep 16, 2023. It is now read-only.

Commit 3cd680e

Browse files
docs(regen): update sample code to set total timeout, add API client header test
1 parent b8f6707 commit 3cd680e

File tree

4 files changed

+252
-12
lines changed

4 files changed

+252
-12
lines changed

google-cloud-recaptchaenterprise/src/main/java/com/google/cloud/recaptchaenterprise/v1beta1/RecaptchaEnterpriseServiceV1Beta1Settings.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,12 @@
6767
* <code>
6868
* RecaptchaEnterpriseServiceV1Beta1Settings.Builder recaptchaEnterpriseServiceV1Beta1SettingsBuilder =
6969
* RecaptchaEnterpriseServiceV1Beta1Settings.newBuilder();
70-
* recaptchaEnterpriseServiceV1Beta1SettingsBuilder.createAssessmentSettings().getRetrySettings().toBuilder()
71-
* .setTotalTimeout(Duration.ofSeconds(30));
70+
* recaptchaEnterpriseServiceV1Beta1SettingsBuilder
71+
* .createAssessmentSettings()
72+
* .setRetrySettings(
73+
* recaptchaEnterpriseServiceV1Beta1SettingsBuilder.createAssessmentSettings().getRetrySettings().toBuilder()
74+
* .setTotalTimeout(Duration.ofSeconds(30))
75+
* .build());
7276
* RecaptchaEnterpriseServiceV1Beta1Settings recaptchaEnterpriseServiceV1Beta1Settings = recaptchaEnterpriseServiceV1Beta1SettingsBuilder.build();
7377
* </code>
7478
* </pre>

google-cloud-recaptchaenterprise/src/main/java/com/google/cloud/recaptchaenterprise/v1beta1/stub/RecaptchaEnterpriseServiceV1Beta1StubSettings.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,12 @@
8282
* <code>
8383
* RecaptchaEnterpriseServiceV1Beta1StubSettings.Builder recaptchaEnterpriseServiceV1Beta1SettingsBuilder =
8484
* RecaptchaEnterpriseServiceV1Beta1StubSettings.newBuilder();
85-
* recaptchaEnterpriseServiceV1Beta1SettingsBuilder.createAssessmentSettings().getRetrySettings().toBuilder()
86-
* .setTotalTimeout(Duration.ofSeconds(30));
85+
* recaptchaEnterpriseServiceV1Beta1SettingsBuilder
86+
* .createAssessmentSettings()
87+
* .setRetrySettings(
88+
* recaptchaEnterpriseServiceV1Beta1SettingsBuilder.createAssessmentSettings().getRetrySettings().toBuilder()
89+
* .setTotalTimeout(Duration.ofSeconds(30))
90+
* .build());
8791
* RecaptchaEnterpriseServiceV1Beta1StubSettings recaptchaEnterpriseServiceV1Beta1Settings = recaptchaEnterpriseServiceV1Beta1SettingsBuilder.build();
8892
* </code>
8993
* </pre>

google-cloud-recaptchaenterprise/src/test/java/com/google/cloud/recaptchaenterprise/v1beta1/RecaptchaEnterpriseServiceV1Beta1ClientTest.java

Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,32 @@
1515
*/
1616
package com.google.cloud.recaptchaenterprise.v1beta1;
1717

18+
import static com.google.cloud.recaptchaenterprise.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client.ListKeysPagedResponse;
19+
1820
import com.google.api.gax.core.NoCredentialsProvider;
1921
import com.google.api.gax.grpc.GaxGrpcProperties;
2022
import com.google.api.gax.grpc.testing.LocalChannelProvider;
2123
import com.google.api.gax.grpc.testing.MockGrpcService;
2224
import com.google.api.gax.grpc.testing.MockServiceHelper;
2325
import com.google.api.gax.rpc.ApiClientHeaderProvider;
2426
import com.google.api.gax.rpc.InvalidArgumentException;
27+
import com.google.common.collect.Lists;
2528
import com.google.protobuf.AbstractMessage;
29+
import com.google.protobuf.Empty;
2630
import com.google.recaptchaenterprise.v1beta1.AnnotateAssessmentRequest;
2731
import com.google.recaptchaenterprise.v1beta1.AnnotateAssessmentResponse;
2832
import com.google.recaptchaenterprise.v1beta1.Assessment;
2933
import com.google.recaptchaenterprise.v1beta1.AssessmentName;
3034
import com.google.recaptchaenterprise.v1beta1.CreateAssessmentRequest;
35+
import com.google.recaptchaenterprise.v1beta1.CreateKeyRequest;
36+
import com.google.recaptchaenterprise.v1beta1.DeleteKeyRequest;
37+
import com.google.recaptchaenterprise.v1beta1.GetKeyRequest;
38+
import com.google.recaptchaenterprise.v1beta1.Key;
39+
import com.google.recaptchaenterprise.v1beta1.KeyName;
40+
import com.google.recaptchaenterprise.v1beta1.ListKeysRequest;
41+
import com.google.recaptchaenterprise.v1beta1.ListKeysResponse;
3142
import com.google.recaptchaenterprise.v1beta1.ProjectName;
43+
import com.google.recaptchaenterprise.v1beta1.UpdateKeyRequest;
3244
import io.grpc.Status;
3345
import io.grpc.StatusRuntimeException;
3446
import java.io.IOException;
@@ -167,4 +179,224 @@ public void annotateAssessmentExceptionTest() throws Exception {
167179
// Expected exception
168180
}
169181
}
182+
183+
@Test
184+
@SuppressWarnings("all")
185+
public void createKeyTest() {
186+
KeyName name = KeyName.of("[PROJECT]", "[KEY]");
187+
String displayName = "displayName1615086568";
188+
Key expectedResponse =
189+
Key.newBuilder().setName(name.toString()).setDisplayName(displayName).build();
190+
mockRecaptchaEnterpriseServiceV1Beta1.addResponse(expectedResponse);
191+
192+
ProjectName parent = ProjectName.of("[PROJECT]");
193+
Key key = Key.newBuilder().build();
194+
CreateKeyRequest request =
195+
CreateKeyRequest.newBuilder().setParent(parent.toString()).setKey(key).build();
196+
197+
Key actualResponse = client.createKey(request);
198+
Assert.assertEquals(expectedResponse, actualResponse);
199+
200+
List<AbstractMessage> actualRequests = mockRecaptchaEnterpriseServiceV1Beta1.getRequests();
201+
Assert.assertEquals(1, actualRequests.size());
202+
CreateKeyRequest actualRequest = (CreateKeyRequest) actualRequests.get(0);
203+
204+
Assert.assertEquals(parent, ProjectName.parse(actualRequest.getParent()));
205+
Assert.assertEquals(key, actualRequest.getKey());
206+
Assert.assertTrue(
207+
channelProvider.isHeaderSent(
208+
ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
209+
GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
210+
}
211+
212+
@Test
213+
@SuppressWarnings("all")
214+
public void createKeyExceptionTest() throws Exception {
215+
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
216+
mockRecaptchaEnterpriseServiceV1Beta1.addException(exception);
217+
218+
try {
219+
ProjectName parent = ProjectName.of("[PROJECT]");
220+
Key key = Key.newBuilder().build();
221+
CreateKeyRequest request =
222+
CreateKeyRequest.newBuilder().setParent(parent.toString()).setKey(key).build();
223+
224+
client.createKey(request);
225+
Assert.fail("No exception raised");
226+
} catch (InvalidArgumentException e) {
227+
// Expected exception
228+
}
229+
}
230+
231+
@Test
232+
@SuppressWarnings("all")
233+
public void listKeysTest() {
234+
String nextPageToken = "";
235+
Key keysElement = Key.newBuilder().build();
236+
List<Key> keys = Arrays.asList(keysElement);
237+
ListKeysResponse expectedResponse =
238+
ListKeysResponse.newBuilder().setNextPageToken(nextPageToken).addAllKeys(keys).build();
239+
mockRecaptchaEnterpriseServiceV1Beta1.addResponse(expectedResponse);
240+
241+
ProjectName parent = ProjectName.of("[PROJECT]");
242+
ListKeysRequest request = ListKeysRequest.newBuilder().setParent(parent.toString()).build();
243+
244+
ListKeysPagedResponse pagedListResponse = client.listKeys(request);
245+
246+
List<Key> resources = Lists.newArrayList(pagedListResponse.iterateAll());
247+
Assert.assertEquals(1, resources.size());
248+
Assert.assertEquals(expectedResponse.getKeysList().get(0), resources.get(0));
249+
250+
List<AbstractMessage> actualRequests = mockRecaptchaEnterpriseServiceV1Beta1.getRequests();
251+
Assert.assertEquals(1, actualRequests.size());
252+
ListKeysRequest actualRequest = (ListKeysRequest) actualRequests.get(0);
253+
254+
Assert.assertEquals(parent, ProjectName.parse(actualRequest.getParent()));
255+
Assert.assertTrue(
256+
channelProvider.isHeaderSent(
257+
ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
258+
GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
259+
}
260+
261+
@Test
262+
@SuppressWarnings("all")
263+
public void listKeysExceptionTest() throws Exception {
264+
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
265+
mockRecaptchaEnterpriseServiceV1Beta1.addException(exception);
266+
267+
try {
268+
ProjectName parent = ProjectName.of("[PROJECT]");
269+
ListKeysRequest request = ListKeysRequest.newBuilder().setParent(parent.toString()).build();
270+
271+
client.listKeys(request);
272+
Assert.fail("No exception raised");
273+
} catch (InvalidArgumentException e) {
274+
// Expected exception
275+
}
276+
}
277+
278+
@Test
279+
@SuppressWarnings("all")
280+
public void getKeyTest() {
281+
KeyName name2 = KeyName.of("[PROJECT]", "[KEY]");
282+
String displayName = "displayName1615086568";
283+
Key expectedResponse =
284+
Key.newBuilder().setName(name2.toString()).setDisplayName(displayName).build();
285+
mockRecaptchaEnterpriseServiceV1Beta1.addResponse(expectedResponse);
286+
287+
KeyName name = KeyName.of("[PROJECT]", "[KEY]");
288+
GetKeyRequest request = GetKeyRequest.newBuilder().setName(name.toString()).build();
289+
290+
Key actualResponse = client.getKey(request);
291+
Assert.assertEquals(expectedResponse, actualResponse);
292+
293+
List<AbstractMessage> actualRequests = mockRecaptchaEnterpriseServiceV1Beta1.getRequests();
294+
Assert.assertEquals(1, actualRequests.size());
295+
GetKeyRequest actualRequest = (GetKeyRequest) actualRequests.get(0);
296+
297+
Assert.assertEquals(name, KeyName.parse(actualRequest.getName()));
298+
Assert.assertTrue(
299+
channelProvider.isHeaderSent(
300+
ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
301+
GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
302+
}
303+
304+
@Test
305+
@SuppressWarnings("all")
306+
public void getKeyExceptionTest() throws Exception {
307+
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
308+
mockRecaptchaEnterpriseServiceV1Beta1.addException(exception);
309+
310+
try {
311+
KeyName name = KeyName.of("[PROJECT]", "[KEY]");
312+
GetKeyRequest request = GetKeyRequest.newBuilder().setName(name.toString()).build();
313+
314+
client.getKey(request);
315+
Assert.fail("No exception raised");
316+
} catch (InvalidArgumentException e) {
317+
// Expected exception
318+
}
319+
}
320+
321+
@Test
322+
@SuppressWarnings("all")
323+
public void updateKeyTest() {
324+
KeyName name = KeyName.of("[PROJECT]", "[KEY]");
325+
String displayName = "displayName1615086568";
326+
Key expectedResponse =
327+
Key.newBuilder().setName(name.toString()).setDisplayName(displayName).build();
328+
mockRecaptchaEnterpriseServiceV1Beta1.addResponse(expectedResponse);
329+
330+
Key key = Key.newBuilder().build();
331+
UpdateKeyRequest request = UpdateKeyRequest.newBuilder().setKey(key).build();
332+
333+
Key actualResponse = client.updateKey(request);
334+
Assert.assertEquals(expectedResponse, actualResponse);
335+
336+
List<AbstractMessage> actualRequests = mockRecaptchaEnterpriseServiceV1Beta1.getRequests();
337+
Assert.assertEquals(1, actualRequests.size());
338+
UpdateKeyRequest actualRequest = (UpdateKeyRequest) actualRequests.get(0);
339+
340+
Assert.assertEquals(key, actualRequest.getKey());
341+
Assert.assertTrue(
342+
channelProvider.isHeaderSent(
343+
ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
344+
GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
345+
}
346+
347+
@Test
348+
@SuppressWarnings("all")
349+
public void updateKeyExceptionTest() throws Exception {
350+
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
351+
mockRecaptchaEnterpriseServiceV1Beta1.addException(exception);
352+
353+
try {
354+
Key key = Key.newBuilder().build();
355+
UpdateKeyRequest request = UpdateKeyRequest.newBuilder().setKey(key).build();
356+
357+
client.updateKey(request);
358+
Assert.fail("No exception raised");
359+
} catch (InvalidArgumentException e) {
360+
// Expected exception
361+
}
362+
}
363+
364+
@Test
365+
@SuppressWarnings("all")
366+
public void deleteKeyTest() {
367+
Empty expectedResponse = Empty.newBuilder().build();
368+
mockRecaptchaEnterpriseServiceV1Beta1.addResponse(expectedResponse);
369+
370+
KeyName name = KeyName.of("[PROJECT]", "[KEY]");
371+
DeleteKeyRequest request = DeleteKeyRequest.newBuilder().setName(name.toString()).build();
372+
373+
client.deleteKey(request);
374+
375+
List<AbstractMessage> actualRequests = mockRecaptchaEnterpriseServiceV1Beta1.getRequests();
376+
Assert.assertEquals(1, actualRequests.size());
377+
DeleteKeyRequest actualRequest = (DeleteKeyRequest) actualRequests.get(0);
378+
379+
Assert.assertEquals(name, KeyName.parse(actualRequest.getName()));
380+
Assert.assertTrue(
381+
channelProvider.isHeaderSent(
382+
ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
383+
GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
384+
}
385+
386+
@Test
387+
@SuppressWarnings("all")
388+
public void deleteKeyExceptionTest() throws Exception {
389+
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
390+
mockRecaptchaEnterpriseServiceV1Beta1.addException(exception);
391+
392+
try {
393+
KeyName name = KeyName.of("[PROJECT]", "[KEY]");
394+
DeleteKeyRequest request = DeleteKeyRequest.newBuilder().setName(name.toString()).build();
395+
396+
client.deleteKey(request);
397+
Assert.fail("No exception raised");
398+
} catch (InvalidArgumentException e) {
399+
// Expected exception
400+
}
401+
}
170402
}

synth.metadata

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
{
2-
"updateTime": "2020-02-06T23:00:22.112674Z",
2+
"updateTime": "2020-02-08T10:00:47.498975Z",
33
"sources": [
44
{
55
"generator": {
66
"name": "artman",
7-
"version": "0.44.4",
8-
"dockerImage": "googleapis/artman@sha256:19e945954fc960a4bdfee6cb34695898ab21a8cf0bac063ee39b91f00a1faec8"
7+
"version": "0.45.0",
8+
"dockerImage": "googleapis/artman@sha256:6aec9c34db0e4be221cdaf6faba27bdc07cfea846808b3d3b964dfce3a9a0f9b"
99
}
1010
},
1111
{
1212
"generator": {
1313
"name": "artman",
14-
"version": "0.44.4",
15-
"dockerImage": "googleapis/artman@sha256:19e945954fc960a4bdfee6cb34695898ab21a8cf0bac063ee39b91f00a1faec8"
14+
"version": "0.45.0",
15+
"dockerImage": "googleapis/artman@sha256:6aec9c34db0e4be221cdaf6faba27bdc07cfea846808b3d3b964dfce3a9a0f9b"
1616
}
1717
},
1818
{
1919
"git": {
2020
"name": "googleapis",
2121
"remote": "https://github.com/googleapis/googleapis.git",
22-
"sha": "2e23b8fbc45f5d9e200572ca662fe1271bcd6760",
23-
"internalRef": "293666452",
24-
"log": "2e23b8fbc45f5d9e200572ca662fe1271bcd6760\nAdd ListEntryGroups method, add http bindings to support entry group tagging, and update some comments.\n\nPiperOrigin-RevId: 293666452\n\n0275e38a4ca03a13d3f47a9613aac8c8b0d3f1f2\nAdd proto_package field to managedidentities API. It is needed for APIs that still depend on artman generation.\n\nPiperOrigin-RevId: 293643323\n\n4cdfe8278cb6f308106580d70648001c9146e759\nRegenerating public protos for Data Catalog to add new Custom Type Entry feature.\n\nPiperOrigin-RevId: 293614782\n\n45d2a569ab526a1fad3720f95eefb1c7330eaada\nEnable client generation for v1 ManagedIdentities API.\n\nPiperOrigin-RevId: 293515675\n\n2c17086b77e6f3bcf04a1f65758dfb0c3da1568f\nAdd the Actions on Google common types (//google/actions/type/*).\n\nPiperOrigin-RevId: 293478245\n\n781aadb932e64a12fb6ead7cd842698d99588433\nDialogflow weekly v2/v2beta1 library update:\n- Documentation updates\nImportant updates are also posted at\nhttps://cloud.google.com/dialogflow/docs/release-notes\n\nPiperOrigin-RevId: 293443396\n\ne2602608c9138c2fca24162720e67f9307c30b95\nDialogflow weekly v2/v2beta1 library update:\n- Documentation updates\nImportant updates are also posted at\nhttps://cloud.google.com/dialogflow/docs/release-notes\n\nPiperOrigin-RevId: 293442964\n\nc8aef82028d06b7992278fa9294c18570dc86c3d\nAdd cc_proto_library and cc_grpc_library targets for Bigtable protos.\n\nAlso fix indentation of cc_grpc_library targets in Spanner and IAM protos.\n\nPiperOrigin-RevId: 293440538\n\ne2faab04f4cb7f9755072330866689b1943a16e9\ncloudtasks: v2 replace non-standard retry params in gapic config v2\n\nPiperOrigin-RevId: 293424055\n\ndfb4097ea628a8470292c6590a4313aee0c675bd\nerrorreporting: v1beta1 add legacy artman config for php\n\nPiperOrigin-RevId: 293423790\n\nb18aed55b45bfe5b62476292c72759e6c3e573c6\nasset: v1p1beta1 updated comment for `page_size` limit.\n\nPiperOrigin-RevId: 293421386\n\nc9ef36b7956d9859a2fc86ad35fcaa16958ab44f\nbazel: Refactor CI build scripts\n\nPiperOrigin-RevId: 293387911\n\na8ed9d921fdddc61d8467bfd7c1668f0ad90435c\nfix: set Ruby module name for OrgPolicy\n\nPiperOrigin-RevId: 293257997\n\n6c7d28509bd8315de8af0889688ee20099594269\nredis: v1beta1 add UpgradeInstance and connect_mode field to Instance\n\nPiperOrigin-RevId: 293242878\n\nae0abed4fcb4c21f5cb67a82349a049524c4ef68\nredis: v1 add connect_mode field to Instance\n\nPiperOrigin-RevId: 293241914\n\n3f7a0d29b28ee9365771da2b66edf7fa2b4e9c56\nAdds service config definition for bigqueryreservation v1beta1\n\nPiperOrigin-RevId: 293234418\n\n0c88168d5ed6fe353a8cf8cbdc6bf084f6bb66a5\naddition of BUILD & configuration for accessapproval v1\n\nPiperOrigin-RevId: 293219198\n\n39bedc2e30f4778ce81193f6ba1fec56107bcfc4\naccessapproval: v1 publish protos\n\nPiperOrigin-RevId: 293167048\n\n69d9945330a5721cd679f17331a78850e2618226\nAdd file-level `Session` resource definition\n\nPiperOrigin-RevId: 293080182\n\nf6a1a6b417f39694275ca286110bc3c1ca4db0dc\nAdd file-level `Session` resource definition\n\nPiperOrigin-RevId: 293080178\n\n"
22+
"sha": "e7d8a694f4559201e6913f6610069cb08b39274e",
23+
"internalRef": "293903652",
24+
"log": "e7d8a694f4559201e6913f6610069cb08b39274e\nDepend on the latest gapic-generator and resource names plugin.\n\nThis fixes the very old an very annoying bug: https://github.com/googleapis/gapic-generator/pull/3087\n\nPiperOrigin-RevId: 293903652\n\n806b2854a966d55374ee26bb0cef4e30eda17b58\nfix: correct capitalization of Ruby namespaces in SecurityCenter V1p1beta1\n\nPiperOrigin-RevId: 293903613\n\n1b83c92462b14d67a7644e2980f723112472e03a\nPublish annotations and grpc service config for Logging API.\n\nPiperOrigin-RevId: 293893514\n\ne46f761cd6ec15a9e3d5ed4ff321a4bcba8e8585\nGenerate the Bazel build file for recommendengine public api\n\nPiperOrigin-RevId: 293710856\n\n68477017c4173c98addac0373950c6aa9d7b375f\nMake `language_code` optional for UpdateIntentRequest and BatchUpdateIntentsRequest.\n\nThe comments and proto annotations describe this parameter as optional.\n\nPiperOrigin-RevId: 293703548\n\n16f823f578bca4e845a19b88bb9bc5870ea71ab2\nAdd BUILD.bazel files for managedidentities API\n\nPiperOrigin-RevId: 293698246\n\n2f53fd8178c9a9de4ad10fae8dd17a7ba36133f2\nAdd v1p1beta1 config file\n\nPiperOrigin-RevId: 293696729\n\n052b274138fce2be80f97b6dcb83ab343c7c8812\nAdd source field for user event and add field behavior annotations\n\nPiperOrigin-RevId: 293693115\n\n1e89732b2d69151b1b3418fff3d4cc0434f0dded\ndatacatalog: v1beta1 add three new RPCs to gapic v1beta1 config\n\nPiperOrigin-RevId: 293692823\n\n9c8bd09bbdc7c4160a44f1fbab279b73cd7a2337\nchange the name of AccessApproval service to AccessApprovalAdmin\n\nPiperOrigin-RevId: 293690934\n\n"
2525
}
2626
},
2727
{

0 commit comments

Comments
 (0)