diff --git a/src/main/java/com/google/api/generator/gapic/composer/Composer.java b/src/main/java/com/google/api/generator/gapic/composer/Composer.java index 02e1dc9bcc..adf5f03432 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/Composer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/Composer.java @@ -60,8 +60,8 @@ public static List generateServiceClasses( @Nonnull Map resourceNames, @Nonnull Map messageTypes) { List clazzes = new ArrayList<>(); - clazzes.addAll(generateStubClasses(service, serviceConfig, messageTypes)); - clazzes.addAll(generateClientSettingsClasses(service, messageTypes)); + clazzes.addAll(generateStubClasses(service, serviceConfig, messageTypes, resourceNames)); + clazzes.addAll(generateClientSettingsClasses(service, messageTypes, resourceNames)); clazzes.addAll(generateMocksAndTestClasses(service, resourceNames, messageTypes)); // TODO(miraleung): Generate test classes. return clazzes; @@ -76,7 +76,10 @@ public static List generateResourceNameHelperClasses( } public static List generateStubClasses( - Service service, GapicServiceConfig serviceConfig, Map messageTypes) { + Service service, + GapicServiceConfig serviceConfig, + Map messageTypes, + Map resourceNames) { List clazzes = new ArrayList<>(); clazzes.add(ServiceStubClassComposer.instance().generate(service, messageTypes)); clazzes.add( @@ -87,9 +90,10 @@ public static List generateStubClasses( } public static List generateClientSettingsClasses( - Service service, Map messageTypes) { + Service service, Map messageTypes, Map resourceNames) { List clazzes = new ArrayList<>(); - clazzes.add(ServiceClientClassComposer.instance().generate(service, messageTypes)); + clazzes.add( + ServiceClientClassComposer.instance().generate(service, messageTypes, resourceNames)); clazzes.add(ServiceSettingsClassComposer.instance().generate(service, messageTypes)); return clazzes; } diff --git a/src/main/java/com/google/api/generator/gapic/composer/ServiceClientClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/ServiceClientClassComposer.java index e6fec42bd9..97982a32c4 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/ServiceClientClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/ServiceClientClassComposer.java @@ -62,6 +62,7 @@ import com.google.api.generator.gapic.model.Method; import com.google.api.generator.gapic.model.Method.Stream; import com.google.api.generator.gapic.model.MethodArgument; +import com.google.api.generator.gapic.model.ResourceName; import com.google.api.generator.gapic.model.Service; import com.google.api.generator.gapic.utils.JavaStyle; import com.google.common.annotations.VisibleForTesting; @@ -79,12 +80,13 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Optional; import java.util.concurrent.TimeUnit; import java.util.function.Function; import java.util.stream.Collectors; import javax.annotation.Generated; -public class ServiceClientClassComposer implements ClassComposer { +public class ServiceClientClassComposer { private static final ServiceClientClassComposer INSTANCE = new ServiceClientClassComposer(); private static final String PAGED_RESPONSE_TYPE_NAME_PATTERN = "%sPagedResponse"; private static final String CALLABLE_NAME_PATTERN = "%sCallable"; @@ -108,8 +110,8 @@ public static ServiceClientClassComposer instance() { return INSTANCE; } - @Override - public GapicClass generate(Service service, Map messageTypes) { + public GapicClass generate( + Service service, Map messageTypes, Map resourceNames) { Map types = createTypes(service, messageTypes); String className = getClientClassName(service); GapicClass.Kind kind = Kind.MAIN; @@ -129,7 +131,8 @@ public GapicClass generate(Service service, Map messageTypes) { .setName(className) .setImplementsTypes(createClassImplements(types)) .setStatements(createFieldDeclarations(service, types, hasLroClient)) - .setMethods(createClassMethods(service, messageTypes, types, hasLroClient)) + .setMethods( + createClassMethods(service, messageTypes, types, resourceNames, hasLroClient)) .setNestedClasses(createNestedPagingClasses(service, messageTypes, types)) .build(); return GapicClass.create(kind, classDef); @@ -152,12 +155,13 @@ private static List createClassMethods( Service service, Map messageTypes, Map types, + Map resourceNames, boolean hasLroClient) { List methods = new ArrayList<>(); methods.addAll(createStaticCreatorMethods(service, types)); methods.addAll(createConstructorMethods(service, types, hasLroClient)); methods.addAll(createGetterMethods(service, types, hasLroClient)); - methods.addAll(createServiceMethods(service, messageTypes, types)); + methods.addAll(createServiceMethods(service, messageTypes, types, resourceNames)); methods.addAll(createBackgroundResourceMethods(service, types)); return methods; } @@ -471,11 +475,16 @@ private static List createGetterMethods( } private static List createServiceMethods( - Service service, Map messageTypes, Map types) { + Service service, + Map messageTypes, + Map types, + Map resourceNames) { List javaMethods = new ArrayList<>(); for (Method method : service.methods()) { if (method.stream().equals(Stream.NONE)) { - javaMethods.addAll(createMethodVariants(method, messageTypes, types)); + javaMethods.addAll( + createMethodVariants( + method, getClientClassName(service), messageTypes, types, resourceNames)); javaMethods.add(createMethodDefaultMethod(method, types)); } if (method.hasLro()) { @@ -490,7 +499,11 @@ private static List createServiceMethods( } private static List createMethodVariants( - Method method, Map messageTypes, Map types) { + Method method, + String clientName, + Map messageTypes, + Map types, + Map resourceNames) { List javaMethods = new ArrayList<>(); String methodName = JavaStyle.toLowerCamelCase(method.name()); TypeNode methodInputType = method.inputType(); @@ -552,10 +565,20 @@ private static List createMethodVariants( .setReturnType(methodOutputType) .build(); + Optional methodSampleCode = Optional.empty(); + if (!method.isPaged() && !method.hasLro()) { + // TODO(summerji): Remove the condition check once finished the implementation on paged + // sample code and lro sample code. + methodSampleCode = + Optional.of( + ServiceClientSampleCodeComposer.composeRpcMethodHeaderSampleCode( + method, types.get(clientName), signature, resourceNames)); + } MethodDefinition.Builder methodVariantBuilder = MethodDefinition.builder() .setHeaderCommentStatements( - ServiceClientCommentComposer.createRpcMethodHeaderComment(method, signature)) + ServiceClientCommentComposer.createRpcMethodHeaderComment( + method, signature, methodSampleCode)) .setScope(ScopeNode.PUBLIC) .setIsFinal(true) .setName(String.format(method.hasLro() ? "%sAsync" : "%s", methodName)) diff --git a/src/main/java/com/google/api/generator/gapic/composer/ServiceClientCommentComposer.java b/src/main/java/com/google/api/generator/gapic/composer/ServiceClientCommentComposer.java index 09507cd30f..2522f5afa5 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/ServiceClientCommentComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/ServiceClientCommentComposer.java @@ -25,6 +25,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -162,7 +163,7 @@ static CommentStatement createCreateMethodStubArgComment( } static List createRpcMethodHeaderComment( - Method method, List methodArguments) { + Method method, List methodArguments, Optional sampleCode) { JavaDocComment.Builder methodJavadocBuilder = JavaDocComment.builder(); if (method.hasDescription()) { @@ -170,8 +171,10 @@ static List createRpcMethodHeaderComment( processProtobufComment(method.description(), methodJavadocBuilder, null); } - // methodJavadocBuilder.addParagraph(METHOD_DESCRIPTION_SAMPLE_CODE_SUMMARY_STRING); - // TODO(summerji): Add sample code here and uncomment the above. + if (sampleCode.isPresent()) { + methodJavadocBuilder.addParagraph(METHOD_DESCRIPTION_SAMPLE_CODE_SUMMARY_STRING); + methodJavadocBuilder.addSampleCode(sampleCode.get()); + } if (methodArguments.isEmpty()) { methodJavadocBuilder.addParam( @@ -196,7 +199,8 @@ static List createRpcMethodHeaderComment( } static List createRpcMethodHeaderComment(Method method) { - return createRpcMethodHeaderComment(method, Collections.emptyList()); + // TODO(summerji): Refactor this method when implement default method sample code. + return createRpcMethodHeaderComment(method, Collections.emptyList(), Optional.empty()); } static CommentStatement createMethodNoArgComment(String serviceName) { diff --git a/src/main/java/com/google/api/generator/gapic/composer/ServiceClientSampleCodeComposer.java b/src/main/java/com/google/api/generator/gapic/composer/ServiceClientSampleCodeComposer.java index 98d66d3148..b009d079c4 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/ServiceClientSampleCodeComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/ServiceClientSampleCodeComposer.java @@ -20,18 +20,29 @@ import com.google.api.generator.engine.ast.Expr; import com.google.api.generator.engine.ast.ExprStatement; import com.google.api.generator.engine.ast.MethodInvocationExpr; +import com.google.api.generator.engine.ast.TryCatchStatement; import com.google.api.generator.engine.ast.TypeNode; import com.google.api.generator.engine.ast.VaporReference; import com.google.api.generator.engine.ast.Variable; import com.google.api.generator.engine.ast.VariableExpr; import com.google.api.generator.gapic.composer.samplecode.SampleCodeWriter; +import com.google.api.generator.gapic.model.Method; +import com.google.api.generator.gapic.model.MethodArgument; +import com.google.api.generator.gapic.model.ResourceName; import com.google.api.generator.gapic.utils.JavaStyle; +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Preconditions; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.IntStream; public class ServiceClientSampleCodeComposer { - // TODO(summerji): Add unit tests for ServiceClientSampleCodeComposer. public static String composeClassHeaderCredentialsSampleCode( + // TODO(summerji): Add unit tests for composeClassHeaderCredentialsSampleCode. TypeNode clientType, TypeNode settingsType) { // Initialize clientSettings with builder() method. // e.g. EchoSettings echoSettings = @@ -105,6 +116,7 @@ public static String composeClassHeaderCredentialsSampleCode( } public static String composeClassHeaderEndpointSampleCode( + // TODO(summerji): Add unit tests for composeClassHeaderEndpointSampleCode. TypeNode clientType, TypeNode settingsType) { // Initialize client settings with builder() method. // e.g. EchoSettings echoSettings = EchoSettings.newBuilder().setEndpoint("myEndpoint").build(); @@ -169,4 +181,141 @@ public static String composeClassHeaderEndpointSampleCode( ExprStatement.withExpr(initSettingsVarExpr), ExprStatement.withExpr(initClientVarExpr))); } + + public static String composeRpcMethodHeaderSampleCode( + Method method, + TypeNode clientType, + List arguments, + Map resourceNames) { + // TODO(summerji): Add other types RPC methods' sample code. + return SampleCodeWriter.write( + composeUnaryRpcMethodSampleCode(method, clientType, arguments, resourceNames)); + } + + @VisibleForTesting + static TryCatchStatement composeUnaryRpcMethodSampleCode( + Method method, + TypeNode clientType, + List arguments, + Map resourceNames) { + VariableExpr clientVarExpr = + VariableExpr.withVariable( + Variable.builder() + .setName(JavaStyle.toLowerCamelCase(clientType.reference().name())) + .setType(clientType) + .build()); + // List of rpc method arguments' variable expressions. + List rpcMethodArgVarExprs = + arguments.stream() + .map( + arg -> + VariableExpr.withVariable( + Variable.builder() + .setName(JavaStyle.toLowerCamelCase(arg.name())) + .setType(arg.type()) + .build())) + .collect(Collectors.toList()); + // List of rpc method arguments' default value expression. + List resourceNameList = + resourceNames.values().stream().collect(Collectors.toList()); + List rpcMethodArgDefaultValueExprs = + arguments.stream() + .map( + arg -> + !isStringTypedResourceName(arg, resourceNames) + ? DefaultValueComposer.createDefaultValue(arg, resourceNames) + : MethodInvocationExpr.builder() + .setExprReferenceExpr( + DefaultValueComposer.createDefaultValue( + resourceNames.get( + arg.field().resourceReference().resourceTypeString()), + resourceNameList, + arg.field().name())) + .setMethodName("toString") + .setReturnType(TypeNode.STRING) + .build()) + .collect(Collectors.toList()); + + List bodyExprs = new ArrayList<>(); + Preconditions.checkState( + rpcMethodArgVarExprs.size() == rpcMethodArgDefaultValueExprs.size(), + "Expected the number of method arguments to match the number of default values."); + bodyExprs.addAll( + IntStream.range(0, rpcMethodArgVarExprs.size()) + .mapToObj( + i -> + AssignmentExpr.builder() + .setVariableExpr( + (rpcMethodArgVarExprs.get(i)).toBuilder().setIsDecl(true).build()) + .setValueExpr(rpcMethodArgDefaultValueExprs.get(i)) + .build()) + .collect(Collectors.toList())); + // Invoke current method based on return type. + // e.g. if return void, echoClient.echo(..); or, + // e.g. if return other type, EchoResponse response = echoClient.echo(...); + boolean returnsVoid = isProtoEmptyType(method.outputType()); + if (returnsVoid) { + bodyExprs.add( + MethodInvocationExpr.builder() + .setExprReferenceExpr(clientVarExpr) + .setMethodName(JavaStyle.toLowerCamelCase(method.name())) + .setArguments( + rpcMethodArgVarExprs.stream().map(e -> (Expr) e).collect(Collectors.toList())) + .setReturnType(clientType) + .build()); + } else { + VariableExpr responseVarExpr = + VariableExpr.withVariable( + Variable.builder().setName("response").setType(method.outputType()).build()); + MethodInvocationExpr clientMethodInvocationExpr = + MethodInvocationExpr.builder() + .setExprReferenceExpr(clientVarExpr) + .setMethodName(JavaStyle.toLowerCamelCase(method.name())) + .setArguments( + rpcMethodArgVarExprs.stream().map(e -> (Expr) e).collect(Collectors.toList())) + .setReturnType(responseVarExpr.variable().type()) + .build(); + bodyExprs.add( + AssignmentExpr.builder() + .setVariableExpr(responseVarExpr.toBuilder().setIsDecl(true).build()) + .setValueExpr(clientMethodInvocationExpr) + .build()); + } + + return TryCatchStatement.builder() + .setTryResourceExpr(assignClientVariableWithCreateMethodExpr(clientVarExpr)) + .setTryBody( + bodyExprs.stream().map(e -> ExprStatement.withExpr(e)).collect(Collectors.toList())) + .setIsSampleCode(true) + .build(); + } + + // ==================================Helpers===================================================// + + // Assign client variable expr with create client. + // e.g EchoClient echoClient = EchoClient.create() + private static AssignmentExpr assignClientVariableWithCreateMethodExpr( + VariableExpr clientVarExpr) { + return AssignmentExpr.builder() + .setVariableExpr(clientVarExpr.toBuilder().setIsDecl(true).build()) + .setValueExpr( + MethodInvocationExpr.builder() + .setStaticReferenceType(clientVarExpr.variable().type()) + .setReturnType(clientVarExpr.variable().type()) + .setMethodName("create") + .build()) + .build(); + } + + private static boolean isStringTypedResourceName( + MethodArgument arg, Map resourceNames) { + return arg.type().equals(TypeNode.STRING) + && arg.field().hasResourceReference() + && resourceNames.containsKey(arg.field().resourceReference().resourceTypeString()); + } + + private static boolean isProtoEmptyType(TypeNode type) { + return type.reference().pakkage().equals("com.google.protobuf") + && type.reference().name().equals("Empty"); + } } diff --git a/src/test/java/com/google/api/generator/gapic/composer/BUILD.bazel b/src/test/java/com/google/api/generator/gapic/composer/BUILD.bazel index 0e0e941a90..4a91509696 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/BUILD.bazel +++ b/src/test/java/com/google/api/generator/gapic/composer/BUILD.bazel @@ -22,6 +22,7 @@ TESTS = UPDATE_GOLDENS_TESTS + [ "DefaultValueComposerTest", "ResourceNameTokenizerTest", "RetrySettingsComposerTest", + "ServiceClientSampleCodeComposerTest", ] TEST_DEPS = [ @@ -38,6 +39,7 @@ TEST_DEPS = [ "//src/main/java/com/google/api/generator/gapic/protoparser", "//src/test/java/com/google/api/generator/gapic/testdata:showcase_java_proto", "//src/test/java/com/google/api/generator/gapic/testdata:testgapic_java_proto", + "@com_google_api_api_common//jar", "@com_google_api_gax_java//gax", "@com_google_googleapis//google/logging/v2:logging_java_proto", "@com_google_googleapis//google/pubsub/v1:pubsub_java_proto", diff --git a/src/test/java/com/google/api/generator/gapic/composer/ServiceClientClassComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/ServiceClientClassComposerTest.java index 1a882a6a30..a45784aaa2 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/ServiceClientClassComposerTest.java +++ b/src/test/java/com/google/api/generator/gapic/composer/ServiceClientClassComposerTest.java @@ -53,7 +53,8 @@ public void generateServiceClasses() { Service echoProtoService = services.get(0); GapicClass clazz = - ServiceClientClassComposer.instance().generate(echoProtoService, messageTypes); + ServiceClientClassComposer.instance() + .generate(echoProtoService, messageTypes, resourceNames); JavaWriterVisitor visitor = new JavaWriterVisitor(); clazz.classDefinition().accept(visitor); @@ -76,7 +77,8 @@ public void generateServiceClasses_methodSignatureHasNestedFields() { fileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames); Service protoService = services.get(0); - GapicClass clazz = ServiceClientClassComposer.instance().generate(protoService, messageTypes); + GapicClass clazz = + ServiceClientClassComposer.instance().generate(protoService, messageTypes, resourceNames); JavaWriterVisitor visitor = new JavaWriterVisitor(); clazz.classDefinition().accept(visitor); diff --git a/src/test/java/com/google/api/generator/gapic/composer/ServiceClientSampleCodeComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/ServiceClientSampleCodeComposerTest.java new file mode 100644 index 0000000000..384f2d97c1 --- /dev/null +++ b/src/test/java/com/google/api/generator/gapic/composer/ServiceClientSampleCodeComposerTest.java @@ -0,0 +1,654 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.api.generator.gapic.composer; + +import static junit.framework.Assert.assertEquals; + +import com.google.api.generator.engine.ast.ConcreteReference; +import com.google.api.generator.engine.ast.Reference; +import com.google.api.generator.engine.ast.TypeNode; +import com.google.api.generator.engine.ast.VaporReference; +import com.google.api.generator.gapic.composer.samplecode.SampleCodeWriter; +import com.google.api.generator.gapic.model.Field; +import com.google.api.generator.gapic.model.Method; +import com.google.api.generator.gapic.model.MethodArgument; +import com.google.api.generator.gapic.model.ResourceName; +import com.google.api.generator.gapic.model.ResourceReference; +import com.google.api.generator.gapic.protoparser.Parser; +import com.google.api.generator.testutils.LineFormatter; +import com.google.protobuf.Descriptors.FileDescriptor; +import com.google.showcase.v1beta1.EchoOuterClass; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import org.junit.Assert; +import org.junit.Test; + +public class ServiceClientSampleCodeComposerTest { + private static final String SHOWCASE_PACKAGE_NAME = "com.google.showcase.v1beta1"; + + @Test + public void validComposeRpcMethodHeaderSampleCode_pureUnaryRpc() { + FileDescriptor echoFileDescriptor = EchoOuterClass.getDescriptor(); + Map resourceNames = Parser.parseResourceNames(echoFileDescriptor); + TypeNode clientType = + TypeNode.withReference( + VaporReference.builder() + .setName("EchoClient") + .setPakkage(SHOWCASE_PACKAGE_NAME) + .build()); + TypeNode inputType = + TypeNode.withReference( + VaporReference.builder() + .setName("EchoRequest") + .setPakkage(SHOWCASE_PACKAGE_NAME) + .build()); + TypeNode outputType = + TypeNode.withReference( + VaporReference.builder() + .setName("EchoResponse") + .setPakkage(SHOWCASE_PACKAGE_NAME) + .build()); + List methodArguments = Collections.emptyList(); + Method method = + Method.builder() + .setName("echo") + .setMethodSignatures(Arrays.asList(methodArguments)) + .setInputType(inputType) + .setOutputType(outputType) + .build(); + String results = + ServiceClientSampleCodeComposer.composeRpcMethodHeaderSampleCode( + method, clientType, methodArguments, resourceNames); + String expected = + LineFormatter.lines( + "try (EchoClient echoClient = EchoClient.create()) {\n", + " EchoResponse response = echoClient.echo();\n", + "}"); + assertEquals(expected, results); + } + + @Test + public void composeUnaryRpcMethodSampleCode_resourceNameMethodArgument() { + FileDescriptor echoFileDescriptor = EchoOuterClass.getDescriptor(); + Map resourceNames = Parser.parseResourceNames(echoFileDescriptor); + TypeNode clientType = + TypeNode.withReference( + VaporReference.builder() + .setName("EchoClient") + .setPakkage(SHOWCASE_PACKAGE_NAME) + .build()); + TypeNode inputType = + TypeNode.withReference( + VaporReference.builder() + .setName("EchoRequest") + .setPakkage(SHOWCASE_PACKAGE_NAME) + .build()); + TypeNode outputType = + TypeNode.withReference( + VaporReference.builder() + .setName("EchoResponse") + .setPakkage(SHOWCASE_PACKAGE_NAME) + .build()); + TypeNode resourceNameType = + TypeNode.withReference( + ConcreteReference.withClazz(com.google.api.resourcenames.ResourceName.class)); + MethodArgument arg = + MethodArgument.builder() + .setName("parent") + .setType(resourceNameType) + .setField( + Field.builder() + .setName("parent") + .setType(TypeNode.STRING) + .setResourceReference( + ResourceReference.withType("showcase.googleapis.com/AnythingGoes")) + .build()) + .setIsResourceNameHelper(true) + .build(); + List> signatures = Arrays.asList(Arrays.asList(arg)); + Method unaryMethod = + Method.builder() + .setName("echo") + .setMethodSignatures(signatures) + .setInputType(inputType) + .setOutputType(outputType) + .build(); + String results = + SampleCodeWriter.write( + ServiceClientSampleCodeComposer.composeUnaryRpcMethodSampleCode( + unaryMethod, clientType, signatures.get(0), resourceNames)); + String expected = + LineFormatter.lines( + "try (EchoClient echoClient = EchoClient.create()) {\n", + " ResourceName parent = FoobarName.ofProjectFoobarName(\"[PROJECT]\", \"[FOOBAR]\");\n", + " EchoResponse response = echoClient.echo(parent);\n", + "}"); + assertEquals(expected, results); + } + + @Test + public void composeUnaryRpcMethodSampleCode_superReferenceIsResourceNameMethodArgument() { + FileDescriptor echoFileDescriptor = EchoOuterClass.getDescriptor(); + Map resourceNames = Parser.parseResourceNames(echoFileDescriptor); + TypeNode clientType = + TypeNode.withReference( + VaporReference.builder() + .setName("EchoClient") + .setPakkage(SHOWCASE_PACKAGE_NAME) + .build()); + TypeNode inputType = + TypeNode.withReference( + VaporReference.builder() + .setName("EchoRequest") + .setPakkage(SHOWCASE_PACKAGE_NAME) + .build()); + TypeNode outputType = + TypeNode.withReference( + VaporReference.builder() + .setName("EchoResponse") + .setPakkage(SHOWCASE_PACKAGE_NAME) + .build()); + TypeNode methodArgType = + TypeNode.withReference( + VaporReference.builder() + .setName("FoobarName") + .setPakkage(SHOWCASE_PACKAGE_NAME) + .setSupertypeReference( + ConcreteReference.withClazz(com.google.api.resourcenames.ResourceName.class)) + .build()); + Field methodArgField = + Field.builder() + .setName("name") + .setType(TypeNode.STRING) + .setResourceReference(ResourceReference.withType("showcase.googleapis.com/Foobar")) + .build(); + MethodArgument arg = + MethodArgument.builder() + .setName("name") + .setType(methodArgType) + .setField(methodArgField) + .setIsResourceNameHelper(true) + .build(); + List> signatures = Arrays.asList(Arrays.asList(arg)); + Method unaryMethod = + Method.builder() + .setName("echo") + .setMethodSignatures(signatures) + .setInputType(inputType) + .setOutputType(outputType) + .build(); + String results = + SampleCodeWriter.write( + ServiceClientSampleCodeComposer.composeUnaryRpcMethodSampleCode( + unaryMethod, clientType, signatures.get(0), resourceNames)); + String expected = + LineFormatter.lines( + "try (EchoClient echoClient = EchoClient.create()) {\n", + " FoobarName name = FoobarName.ofProjectFoobarName(\"[PROJECT]\", \"[FOOBAR]\");\n", + " EchoResponse response = echoClient.echo(name);\n", + "}"); + assertEquals(expected, results); + } + + @Test + public void composeUnaryRpcMethodSampleCode_stringWithResourceReferenceMethodArgument() { + FileDescriptor echoFileDescriptor = EchoOuterClass.getDescriptor(); + Map resourceNames = Parser.parseResourceNames(echoFileDescriptor); + TypeNode clientType = + TypeNode.withReference( + VaporReference.builder() + .setName("EchoClient") + .setPakkage(SHOWCASE_PACKAGE_NAME) + .build()); + TypeNode inputType = + TypeNode.withReference( + VaporReference.builder() + .setName("EchoRequest") + .setPakkage(SHOWCASE_PACKAGE_NAME) + .build()); + TypeNode outputType = + TypeNode.withReference( + VaporReference.builder() + .setName("EchoResponse") + .setPakkage(SHOWCASE_PACKAGE_NAME) + .build()); + Field methodArgField = + Field.builder() + .setName("name") + .setType(TypeNode.STRING) + .setResourceReference(ResourceReference.withType("showcase.googleapis.com/Foobar")) + .build(); + MethodArgument arg = + MethodArgument.builder() + .setName("name") + .setType(TypeNode.STRING) + .setField(methodArgField) + .build(); + List> signatures = Arrays.asList(Arrays.asList(arg)); + Method unaryMethod = + Method.builder() + .setName("echo") + .setMethodSignatures(signatures) + .setInputType(inputType) + .setOutputType(outputType) + .build(); + String results = + SampleCodeWriter.write( + ServiceClientSampleCodeComposer.composeUnaryRpcMethodSampleCode( + unaryMethod, clientType, signatures.get(0), resourceNames)); + String expected = + LineFormatter.lines( + "try (EchoClient echoClient = EchoClient.create()) {\n", + " String name = FoobarName.ofProjectFoobarName(\"[PROJECT]\", \"[FOOBAR]\").toString();\n", + " EchoResponse response = echoClient.echo(name);\n", + "}"); + assertEquals(expected, results); + } + + @Test + public void composeUnaryRpcMethodSampleCode_stringWithParentResourceReferenceMethodArgument() { + FileDescriptor echoFileDescriptor = EchoOuterClass.getDescriptor(); + Map resourceNames = Parser.parseResourceNames(echoFileDescriptor); + TypeNode clientType = + TypeNode.withReference( + VaporReference.builder() + .setName("EchoClient") + .setPakkage(SHOWCASE_PACKAGE_NAME) + .build()); + TypeNode inputType = + TypeNode.withReference( + VaporReference.builder() + .setName("EchoRequest") + .setPakkage(SHOWCASE_PACKAGE_NAME) + .build()); + TypeNode outputType = + TypeNode.withReference( + VaporReference.builder() + .setName("EchoResponse") + .setPakkage(SHOWCASE_PACKAGE_NAME) + .build()); + Field methodArgField = + Field.builder() + .setName("parent") + .setType(TypeNode.STRING) + .setResourceReference( + ResourceReference.withChildType("showcase.googleapis.com/AnythingGoes")) + .build(); + MethodArgument arg = + MethodArgument.builder() + .setName("parent") + .setType(TypeNode.STRING) + .setField(methodArgField) + .build(); + List> signatures = Arrays.asList(Arrays.asList(arg)); + Method unaryMethod = + Method.builder() + .setName("echo") + .setMethodSignatures(signatures) + .setInputType(inputType) + .setOutputType(outputType) + .build(); + String results = + SampleCodeWriter.write( + ServiceClientSampleCodeComposer.composeUnaryRpcMethodSampleCode( + unaryMethod, clientType, signatures.get(0), resourceNames)); + String expected = + LineFormatter.lines( + "try (EchoClient echoClient = EchoClient.create()) {\n", + " String parent = FoobarName.ofProjectFoobarName(\"[PROJECT]\", \"[FOOBAR]\").toString();\n", + " EchoResponse response = echoClient.echo(parent);\n", + "}"); + assertEquals(expected, results); + } + + @Test + public void composeUnaryRpcMethodSampleCode_isMessageMethodArgument() { + FileDescriptor echoFileDescriptor = EchoOuterClass.getDescriptor(); + Map resourceNames = Parser.parseResourceNames(echoFileDescriptor); + TypeNode clientType = + TypeNode.withReference( + VaporReference.builder() + .setName("EchoClient") + .setPakkage(SHOWCASE_PACKAGE_NAME) + .build()); + TypeNode inputType = + TypeNode.withReference( + VaporReference.builder() + .setName("EchoRequest") + .setPakkage(SHOWCASE_PACKAGE_NAME) + .build()); + TypeNode outputType = + TypeNode.withReference( + VaporReference.builder() + .setName("EchoResponse") + .setPakkage(SHOWCASE_PACKAGE_NAME) + .build()); + TypeNode methodArgType = + TypeNode.withReference( + VaporReference.builder().setName("Status").setPakkage("com.google.rpc").build()); + Field methodArgField = + Field.builder() + .setName("error") + .setType(methodArgType) + .setIsMessage(true) + .setIsContainedInOneof(true) + .build(); + MethodArgument arg = + MethodArgument.builder() + .setName("error") + .setType(methodArgType) + .setField(methodArgField) + .build(); + List> signatures = Arrays.asList(Arrays.asList(arg)); + Method unaryMethod = + Method.builder() + .setName("echo") + .setMethodSignatures(signatures) + .setInputType(inputType) + .setOutputType(outputType) + .build(); + String results = + SampleCodeWriter.write( + ServiceClientSampleCodeComposer.composeUnaryRpcMethodSampleCode( + unaryMethod, clientType, signatures.get(0), resourceNames)); + String expected = + LineFormatter.lines( + "try (EchoClient echoClient = EchoClient.create()) {\n", + " Status error = Status.newBuilder().build();\n", + " EchoResponse response = echoClient.echo(error);\n", + "}"); + assertEquals(expected, results); + } + + @Test + public void composeUnaryRpcMethodSampleCode_multipleWordNameMethodArgument() { + FileDescriptor echoFileDescriptor = EchoOuterClass.getDescriptor(); + Map resourceNames = Parser.parseResourceNames(echoFileDescriptor); + TypeNode clientType = + TypeNode.withReference( + VaporReference.builder() + .setName("EchoClient") + .setPakkage(SHOWCASE_PACKAGE_NAME) + .build()); + TypeNode inputType = + TypeNode.withReference( + VaporReference.builder() + .setName("EchoRequest") + .setPakkage(SHOWCASE_PACKAGE_NAME) + .build()); + TypeNode outputType = + TypeNode.withReference( + VaporReference.builder() + .setName("EchoResponse") + .setPakkage(SHOWCASE_PACKAGE_NAME) + .build()); + Field methodArgField = + Field.builder() + .setName("display_name") + .setType(TypeNode.STRING) + .setResourceReference( + ResourceReference.withChildType("showcase.googleapis.com/AnythingGoes")) + .build(); + Reference userRef = + VaporReference.builder().setName("User").setPakkage(SHOWCASE_PACKAGE_NAME).build(); + Field nestFiled = + Field.builder() + .setName("user") + .setType(TypeNode.withReference(userRef)) + .setIsMessage(true) + .build(); + MethodArgument argDisplayName = + MethodArgument.builder() + .setName("display_name") + .setType(TypeNode.STRING) + .setField(methodArgField) + .setNestedFields(Arrays.asList(nestFiled)) + .build(); + MethodArgument argOtherName = + MethodArgument.builder() + .setName("other_name") + .setType(TypeNode.STRING) + .setField(Field.builder().setName("other_name").setType(TypeNode.STRING).build()) + .setNestedFields(Arrays.asList(nestFiled)) + .build(); + List> signatures = + Arrays.asList(Arrays.asList(argDisplayName, argOtherName)); + Method unaryMethod = + Method.builder() + .setName("echo") + .setMethodSignatures(signatures) + .setInputType(inputType) + .setOutputType(outputType) + .build(); + String results = + SampleCodeWriter.write( + ServiceClientSampleCodeComposer.composeUnaryRpcMethodSampleCode( + unaryMethod, clientType, signatures.get(0), resourceNames)); + String expected = + LineFormatter.lines( + "try (EchoClient echoClient = EchoClient.create()) {\n", + " String displayName = FoobarName.ofProjectFoobarName(\"[PROJECT]\", \"[FOOBAR]\").toString();\n", + " String otherName = \"otherName-1946065477\";\n", + " EchoResponse response = echoClient.echo(displayName, otherName);\n", + "}"); + assertEquals(expected, results); + } + + @Test + public void composeUnaryRpcMethodSampleCode_stringIsContainedInOneOfMethodArgument() { + FileDescriptor echoFileDescriptor = EchoOuterClass.getDescriptor(); + Map resourceNames = Parser.parseResourceNames(echoFileDescriptor); + TypeNode clientType = + TypeNode.withReference( + VaporReference.builder() + .setName("EchoClient") + .setPakkage(SHOWCASE_PACKAGE_NAME) + .build()); + TypeNode inputType = + TypeNode.withReference( + VaporReference.builder() + .setName("EchoRequest") + .setPakkage(SHOWCASE_PACKAGE_NAME) + .build()); + TypeNode outputType = + TypeNode.withReference( + VaporReference.builder() + .setName("EchoResponse") + .setPakkage(SHOWCASE_PACKAGE_NAME) + .build()); + Field methodArgField = + Field.builder() + .setName("content") + .setType(TypeNode.STRING) + .setIsContainedInOneof(true) + .build(); + MethodArgument arg = + MethodArgument.builder() + .setName("content") + .setType(TypeNode.STRING) + .setField(methodArgField) + .build(); + List> signatures = Arrays.asList(Arrays.asList(arg)); + Method unaryMethod = + Method.builder() + .setName("echo") + .setMethodSignatures(signatures) + .setInputType(inputType) + .setOutputType(outputType) + .build(); + String results = + SampleCodeWriter.write( + ServiceClientSampleCodeComposer.composeUnaryRpcMethodSampleCode( + unaryMethod, clientType, signatures.get(0), resourceNames)); + String expected = + LineFormatter.lines( + "try (EchoClient echoClient = EchoClient.create()) {\n", + " String content = \"content951530617\";\n", + " EchoResponse response = echoClient.echo(content);\n", + "}"); + assertEquals(expected, results); + } + + @Test + public void composeUnaryRpcMethodSampleCode_multipleMethodArguments() { + FileDescriptor echoFileDescriptor = EchoOuterClass.getDescriptor(); + Map resourceNames = Parser.parseResourceNames(echoFileDescriptor); + TypeNode clientType = + TypeNode.withReference( + VaporReference.builder() + .setName("EchoClient") + .setPakkage(SHOWCASE_PACKAGE_NAME) + .build()); + TypeNode inputType = + TypeNode.withReference( + VaporReference.builder() + .setName("EchoRequest") + .setPakkage(SHOWCASE_PACKAGE_NAME) + .build()); + TypeNode outputType = + TypeNode.withReference( + VaporReference.builder() + .setName("EchoResponse") + .setPakkage(SHOWCASE_PACKAGE_NAME) + .build()); + MethodArgument arg1 = + MethodArgument.builder() + .setName("content") + .setType(TypeNode.STRING) + .setField(Field.builder().setName("content").setType(TypeNode.STRING).build()) + .build(); + TypeNode severityType = + TypeNode.withReference( + VaporReference.builder().setName("Severity").setPakkage(SHOWCASE_PACKAGE_NAME).build()); + MethodArgument arg2 = + MethodArgument.builder() + .setName("severity") + .setType(severityType) + .setField( + Field.builder().setName("severity").setType(severityType).setIsEnum(true).build()) + .build(); + List> signatures = Arrays.asList(Arrays.asList(arg1, arg2)); + Method unaryMethod = + Method.builder() + .setName("echo") + .setMethodSignatures(signatures) + .setInputType(inputType) + .setOutputType(outputType) + .build(); + String results = + SampleCodeWriter.write( + ServiceClientSampleCodeComposer.composeUnaryRpcMethodSampleCode( + unaryMethod, clientType, signatures.get(0), resourceNames)); + String expected = + LineFormatter.lines( + "try (EchoClient echoClient = EchoClient.create()) {\n", + " String content = \"content951530617\";\n", + " Severity severity = Severity.forNumber(0);\n", + " EchoResponse response = echoClient.echo(content, severity);\n", + "}"); + assertEquals(expected, results); + } + + @Test + public void composeUnaryRpcMethodSampleCode_noMethodArguments() { + FileDescriptor echoFileDescriptor = EchoOuterClass.getDescriptor(); + Map resourceNames = Parser.parseResourceNames(echoFileDescriptor); + TypeNode clientType = + TypeNode.withReference( + VaporReference.builder() + .setName("EchoClient") + .setPakkage(SHOWCASE_PACKAGE_NAME) + .build()); + TypeNode inputType = + TypeNode.withReference( + VaporReference.builder() + .setName("EchoRequest") + .setPakkage(SHOWCASE_PACKAGE_NAME) + .build()); + TypeNode outputType = + TypeNode.withReference( + VaporReference.builder() + .setName("EchoResponse") + .setPakkage(SHOWCASE_PACKAGE_NAME) + .build()); + List> signatures = Arrays.asList(Collections.emptyList()); + Method unaryMethod = + Method.builder() + .setName("echo") + .setMethodSignatures(signatures) + .setInputType(inputType) + .setOutputType(outputType) + .build(); + String results = + SampleCodeWriter.write( + ServiceClientSampleCodeComposer.composeUnaryRpcMethodSampleCode( + unaryMethod, clientType, signatures.get(0), resourceNames)); + String expected = + LineFormatter.lines( + "try (EchoClient echoClient = EchoClient.create()) {\n", + " EchoResponse response = echoClient.echo();\n", + "}"); + assertEquals(expected, results); + } + + @Test + public void composeUnaryRpcMethodSampleCode_methodReturnVoid() { + FileDescriptor echoFileDescriptor = EchoOuterClass.getDescriptor(); + Map resourceNames = Parser.parseResourceNames(echoFileDescriptor); + TypeNode clientType = + TypeNode.withReference( + VaporReference.builder() + .setName("EchoClient") + .setPakkage(SHOWCASE_PACKAGE_NAME) + .build()); + TypeNode inputType = + TypeNode.withReference( + VaporReference.builder() + .setName("DeleteUserRequest") + .setPakkage("com.google.showcase.v1beta1") + .build()); + TypeNode outputType = + TypeNode.withReference( + VaporReference.builder().setName("Empty").setPakkage("com.google.protobuf").build()); + List> methodSignatures = + Arrays.asList( + Arrays.asList( + MethodArgument.builder() + .setName("name") + .setType(TypeNode.STRING) + .setField(Field.builder().setName("name").setType(TypeNode.STRING).build()) + .build())); + Method unaryMethod = + Method.builder() + .setName("delete") + .setMethodSignatures(methodSignatures) + .setInputType(inputType) + .setOutputType(outputType) + .build(); + String results = + SampleCodeWriter.write( + ServiceClientSampleCodeComposer.composeUnaryRpcMethodSampleCode( + unaryMethod, clientType, methodSignatures.get(0), resourceNames)); + String expected = + LineFormatter.lines( + "try (EchoClient echoClient = EchoClient.create()) {\n", + " String name = \"name3373707\";\n", + " echoClient.delete(name);\n", + "}"); + Assert.assertEquals(results, expected); + } +} diff --git a/src/test/java/com/google/api/generator/gapic/composer/goldens/EchoClient.golden b/src/test/java/com/google/api/generator/gapic/composer/goldens/EchoClient.golden index 45cfef387a..3750febf6c 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/goldens/EchoClient.golden +++ b/src/test/java/com/google/api/generator/gapic/composer/goldens/EchoClient.golden @@ -144,6 +144,14 @@ public class EchoClient implements BackgroundResource { // AUTO-GENERATED DOCUMENTATION AND METHOD. /** + * Sample code: + * + *
{@code
+   * try (EchoClient echoClient = EchoClient.create()) {
+   *   EchoResponse response = echoClient.echo();
+   * }
+   * }
+ * * @param request The request object containing all of the parameters for the API call. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @@ -154,6 +162,15 @@ public class EchoClient implements BackgroundResource { // AUTO-GENERATED DOCUMENTATION AND METHOD. /** + * Sample code: + * + *
{@code
+   * try (EchoClient echoClient = EchoClient.create()) {
+   *   ResourceName parent = FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]");
+   *   EchoResponse response = echoClient.echo(parent);
+   * }
+   * }
+ * * @param parent * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @@ -165,6 +182,15 @@ public class EchoClient implements BackgroundResource { // AUTO-GENERATED DOCUMENTATION AND METHOD. /** + * Sample code: + * + *
{@code
+   * try (EchoClient echoClient = EchoClient.create()) {
+   *   Status error = Status.newBuilder().build();
+   *   EchoResponse response = echoClient.echo(error);
+   * }
+   * }
+ * * @param error * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @@ -175,6 +201,15 @@ public class EchoClient implements BackgroundResource { // AUTO-GENERATED DOCUMENTATION AND METHOD. /** + * Sample code: + * + *
{@code
+   * try (EchoClient echoClient = EchoClient.create()) {
+   *   FoobarName name = FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]");
+   *   EchoResponse response = echoClient.echo(name);
+   * }
+   * }
+ * * @param name * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @@ -186,6 +221,15 @@ public class EchoClient implements BackgroundResource { // AUTO-GENERATED DOCUMENTATION AND METHOD. /** + * Sample code: + * + *
{@code
+   * try (EchoClient echoClient = EchoClient.create()) {
+   *   String content = "content951530617";
+   *   EchoResponse response = echoClient.echo(content);
+   * }
+   * }
+ * * @param content * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @@ -196,6 +240,15 @@ public class EchoClient implements BackgroundResource { // AUTO-GENERATED DOCUMENTATION AND METHOD. /** + * Sample code: + * + *
{@code
+   * try (EchoClient echoClient = EchoClient.create()) {
+   *   String name = FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString();
+   *   EchoResponse response = echoClient.echo(name);
+   * }
+   * }
+ * * @param name * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @@ -206,6 +259,15 @@ public class EchoClient implements BackgroundResource { // AUTO-GENERATED DOCUMENTATION AND METHOD. /** + * Sample code: + * + *
{@code
+   * try (EchoClient echoClient = EchoClient.create()) {
+   *   String parent = FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString();
+   *   EchoResponse response = echoClient.echo(parent);
+   * }
+   * }
+ * * @param parent * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @@ -216,6 +278,16 @@ public class EchoClient implements BackgroundResource { // AUTO-GENERATED DOCUMENTATION AND METHOD. /** + * Sample code: + * + *
{@code
+   * try (EchoClient echoClient = EchoClient.create()) {
+   *   String content = "content951530617";
+   *   Severity severity = Severity.forNumber(0);
+   *   EchoResponse response = echoClient.echo(content, severity);
+   * }
+   * }
+ * * @param content * @param severity * @throws com.google.api.gax.rpc.ApiException if the remote call fails diff --git a/src/test/java/com/google/api/generator/gapic/composer/goldens/IdentityClient.golden b/src/test/java/com/google/api/generator/gapic/composer/goldens/IdentityClient.golden index db54847763..4ea2ee3319 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/goldens/IdentityClient.golden +++ b/src/test/java/com/google/api/generator/gapic/composer/goldens/IdentityClient.golden @@ -124,6 +124,17 @@ public class IdentityClient implements BackgroundResource { // AUTO-GENERATED DOCUMENTATION AND METHOD. /** + * Sample code: + * + *
{@code
+   * try (IdentityClient identityClient = IdentityClient.create()) {
+   *   String parent = UserName.of("[USER]").toString();
+   *   String displayName = "displayName1714148973";
+   *   String email = "email96619420";
+   *   User response = identityClient.createUser(parent, displayName, email);
+   * }
+   * }
+ * * @param parent * @param display_name * @param email @@ -141,6 +152,23 @@ public class IdentityClient implements BackgroundResource { // AUTO-GENERATED DOCUMENTATION AND METHOD. /** + * Sample code: + * + *
{@code
+   * try (IdentityClient identityClient = IdentityClient.create()) {
+   *   String parent = UserName.of("[USER]").toString();
+   *   String displayName = "displayName1714148973";
+   *   String email = "email96619420";
+   *   int age = 96511;
+   *   String nickname = "nickname70690926";
+   *   boolean enableNotifications = true;
+   *   double heightFeet = -1032737338;
+   *   User response =
+   *       identityClient.createUser(
+   *           parent, displayName, email, age, nickname, enableNotifications, heightFeet);
+   * }
+   * }
+ * * @param parent * @param display_name * @param email @@ -188,6 +216,15 @@ public class IdentityClient implements BackgroundResource { // AUTO-GENERATED DOCUMENTATION AND METHOD. /** + * Sample code: + * + *
{@code
+   * try (IdentityClient identityClient = IdentityClient.create()) {
+   *   UserName name = UserName.of("[USER]");
+   *   User response = identityClient.getUser(name);
+   * }
+   * }
+ * * @param name * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @@ -199,6 +236,15 @@ public class IdentityClient implements BackgroundResource { // AUTO-GENERATED DOCUMENTATION AND METHOD. /** + * Sample code: + * + *
{@code
+   * try (IdentityClient identityClient = IdentityClient.create()) {
+   *   String name = UserName.of("[USER]").toString();
+   *   User response = identityClient.getUser(name);
+   * }
+   * }
+ * * @param name * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @@ -239,6 +285,15 @@ public class IdentityClient implements BackgroundResource { // AUTO-GENERATED DOCUMENTATION AND METHOD. /** + * Sample code: + * + *
{@code
+   * try (IdentityClient identityClient = IdentityClient.create()) {
+   *   UserName name = UserName.of("[USER]");
+   *   identityClient.deleteUser(name);
+   * }
+   * }
+ * * @param name * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @@ -250,6 +305,15 @@ public class IdentityClient implements BackgroundResource { // AUTO-GENERATED DOCUMENTATION AND METHOD. /** + * Sample code: + * + *
{@code
+   * try (IdentityClient identityClient = IdentityClient.create()) {
+   *   String name = UserName.of("[USER]").toString();
+   *   identityClient.deleteUser(name);
+   * }
+   * }
+ * * @param name * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ diff --git a/test/integration/goldens/asset/AssetServiceClient.java b/test/integration/goldens/asset/AssetServiceClient.java index 2ade6c30d5..b9ccab0f57 100644 --- a/test/integration/goldens/asset/AssetServiceClient.java +++ b/test/integration/goldens/asset/AssetServiceClient.java @@ -245,6 +245,15 @@ public final BatchGetAssetsHistoryResponse batchGetAssetsHistory( /** * Creates a feed in a parent project/folder/organization to listen to its asset updates. * + *

Sample code: + * + *

{@code
+   * try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
+   *   String parent = "parent-995424086";
+   *   Feed response = assetServiceClient.createFeed(parent);
+   * }
+   * }
+ * * @param parent Required. The name of the project/folder/organization where this feed should be * created in. It can only be an organization number (such as "organizations/123"), a folder * number (such as "folders/123"), a project ID (such as "projects/my-project-id")", or a @@ -281,6 +290,15 @@ public final UnaryCallable createFeedCallable() { /** * Gets details about an asset feed. * + *

Sample code: + * + *

{@code
+   * try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
+   *   FeedName name = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]");
+   *   Feed response = assetServiceClient.getFeed(name);
+   * }
+   * }
+ * * @param name Required. The name of the Feed and it must be in the format of: * projects/project_number/feeds/feed_id folders/folder_number/feeds/feed_id * organizations/organization_number/feeds/feed_id @@ -296,6 +314,15 @@ public final Feed getFeed(FeedName name) { /** * Gets details about an asset feed. * + *

Sample code: + * + *

{@code
+   * try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
+   *   String name = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString();
+   *   Feed response = assetServiceClient.getFeed(name);
+   * }
+   * }
+ * * @param name Required. The name of the Feed and it must be in the format of: * projects/project_number/feeds/feed_id folders/folder_number/feeds/feed_id * organizations/organization_number/feeds/feed_id @@ -331,6 +358,15 @@ public final UnaryCallable getFeedCallable() { /** * Lists all asset feeds in a parent project/folder/organization. * + *

Sample code: + * + *

{@code
+   * try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
+   *   String parent = "parent-995424086";
+   *   ListFeedsResponse response = assetServiceClient.listFeeds(parent);
+   * }
+   * }
+ * * @param parent Required. The parent project/folder/organization whose feeds are to be listed. It * can only be using project/folder/organization number (such as "folders/12345")", or a * project ID (such as "projects/my-project-id"). @@ -366,6 +402,15 @@ public final UnaryCallable listFeedsCallabl /** * Updates an asset feed configuration. * + *

Sample code: + * + *

{@code
+   * try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
+   *   Feed feed = Feed.newBuilder().build();
+   *   Feed response = assetServiceClient.updateFeed(feed);
+   * }
+   * }
+ * * @param feed Required. The new values of feed details. It must match an existing feed and the * field `name` must be in the format of: projects/project_number/feeds/feed_id or * folders/folder_number/feeds/feed_id or organizations/organization_number/feeds/feed_id. @@ -401,6 +446,15 @@ public final UnaryCallable updateFeedCallable() { /** * Deletes an asset feed. * + *

Sample code: + * + *

{@code
+   * try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
+   *   FeedName name = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]");
+   *   assetServiceClient.deleteFeed(name);
+   * }
+   * }
+ * * @param name Required. The name of the feed and it must be in the format of: * projects/project_number/feeds/feed_id folders/folder_number/feeds/feed_id * organizations/organization_number/feeds/feed_id @@ -416,6 +470,15 @@ public final void deleteFeed(FeedName name) { /** * Deletes an asset feed. * + *

Sample code: + * + *

{@code
+   * try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
+   *   String name = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString();
+   *   assetServiceClient.deleteFeed(name);
+   * }
+   * }
+ * * @param name Required. The name of the feed and it must be in the format of: * projects/project_number/feeds/feed_id folders/folder_number/feeds/feed_id * organizations/organization_number/feeds/feed_id diff --git a/test/integration/goldens/library/LibraryServiceClient.java b/test/integration/goldens/library/LibraryServiceClient.java index 033e0b3b3d..a87ec39ef7 100644 --- a/test/integration/goldens/library/LibraryServiceClient.java +++ b/test/integration/goldens/library/LibraryServiceClient.java @@ -170,6 +170,15 @@ public LibraryServiceStub getStub() { /** * Creates a shelf, and returns the new Shelf. * + *

Sample code: + * + *

{@code
+   * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
+   *   Shelf shelf = Shelf.newBuilder().build();
+   *   Shelf response = libraryServiceClient.createShelf(shelf);
+   * }
+   * }
+ * * @param shelf The shelf to create. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @@ -203,6 +212,15 @@ public final UnaryCallable createShelfCallable() { /** * Gets a shelf. Returns NOT_FOUND if the shelf does not exist. * + *

Sample code: + * + *

{@code
+   * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
+   *   ShelfName name = ShelfName.of("[SHELF_ID]");
+   *   Shelf response = libraryServiceClient.getShelf(name);
+   * }
+   * }
+ * * @param name The name of the shelf to retrieve. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @@ -216,6 +234,15 @@ public final Shelf getShelf(ShelfName name) { /** * Gets a shelf. Returns NOT_FOUND if the shelf does not exist. * + *

Sample code: + * + *

{@code
+   * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
+   *   String name = "name3373707";
+   *   Shelf response = libraryServiceClient.getShelf(name);
+   * }
+   * }
+ * * @param name The name of the shelf to retrieve. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @@ -284,6 +311,15 @@ public final UnaryCallable listShelvesC /** * Deletes a shelf. Returns NOT_FOUND if the shelf does not exist. * + *

Sample code: + * + *

{@code
+   * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
+   *   ShelfName name = ShelfName.of("[SHELF_ID]");
+   *   libraryServiceClient.deleteShelf(name);
+   * }
+   * }
+ * * @param name The name of the shelf to delete. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @@ -297,6 +333,15 @@ public final void deleteShelf(ShelfName name) { /** * Deletes a shelf. Returns NOT_FOUND if the shelf does not exist. * + *

Sample code: + * + *

{@code
+   * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
+   *   String name = "name3373707";
+   *   libraryServiceClient.deleteShelf(name);
+   * }
+   * }
+ * * @param name The name of the shelf to delete. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @@ -335,6 +380,16 @@ public final UnaryCallable deleteShelfCallable() { *

Returns NOT_FOUND if either shelf does not exist. This call is a no-op if the specified * shelves are the same. * + *

Sample code: + * + *

{@code
+   * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
+   *   ShelfName name = ShelfName.of("[SHELF_ID]");
+   *   ShelfName otherShelfName = ShelfName.of("[SHELF_ID]");
+   *   Shelf response = libraryServiceClient.mergeShelves(name, otherShelfName);
+   * }
+   * }
+ * * @param name The name of the shelf we're adding books to. * @param other_shelf_name The name of the shelf we're removing books from and deleting. * @throws com.google.api.gax.rpc.ApiException if the remote call fails @@ -357,6 +412,16 @@ public final Shelf mergeShelves(ShelfName name, ShelfName otherShelfName) { *

Returns NOT_FOUND if either shelf does not exist. This call is a no-op if the specified * shelves are the same. * + *

Sample code: + * + *

{@code
+   * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
+   *   ShelfName name = ShelfName.of("[SHELF_ID]");
+   *   String otherShelfName = "otherShelfName-1942963547";
+   *   Shelf response = libraryServiceClient.mergeShelves(name, otherShelfName);
+   * }
+   * }
+ * * @param name The name of the shelf we're adding books to. * @param other_shelf_name The name of the shelf we're removing books from and deleting. * @throws com.google.api.gax.rpc.ApiException if the remote call fails @@ -379,6 +444,16 @@ public final Shelf mergeShelves(ShelfName name, String otherShelfName) { *

Returns NOT_FOUND if either shelf does not exist. This call is a no-op if the specified * shelves are the same. * + *

Sample code: + * + *

{@code
+   * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
+   *   String name = "name3373707";
+   *   ShelfName otherShelfName = ShelfName.of("[SHELF_ID]");
+   *   Shelf response = libraryServiceClient.mergeShelves(name, otherShelfName);
+   * }
+   * }
+ * * @param name The name of the shelf we're adding books to. * @param other_shelf_name The name of the shelf we're removing books from and deleting. * @throws com.google.api.gax.rpc.ApiException if the remote call fails @@ -401,6 +476,16 @@ public final Shelf mergeShelves(String name, ShelfName otherShelfName) { *

Returns NOT_FOUND if either shelf does not exist. This call is a no-op if the specified * shelves are the same. * + *

Sample code: + * + *

{@code
+   * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
+   *   String name = "name3373707";
+   *   String otherShelfName = "otherShelfName-1942963547";
+   *   Shelf response = libraryServiceClient.mergeShelves(name, otherShelfName);
+   * }
+   * }
+ * * @param name The name of the shelf we're adding books to. * @param other_shelf_name The name of the shelf we're removing books from and deleting. * @throws com.google.api.gax.rpc.ApiException if the remote call fails @@ -446,6 +531,16 @@ public final UnaryCallable mergeShelvesCallable() { /** * Creates a book, and returns the new Book. * + *

Sample code: + * + *

{@code
+   * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
+   *   ShelfName name = ShelfName.of("[SHELF_ID]");
+   *   Book book = Book.newBuilder().build();
+   *   Book response = libraryServiceClient.createBook(name, book);
+   * }
+   * }
+ * * @param name The name of the shelf in which the book is created. * @param book The book to create. * @throws com.google.api.gax.rpc.ApiException if the remote call fails @@ -463,6 +558,16 @@ public final Book createBook(ShelfName name, Book book) { /** * Creates a book, and returns the new Book. * + *

Sample code: + * + *

{@code
+   * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
+   *   String name = "name3373707";
+   *   Book book = Book.newBuilder().build();
+   *   Book response = libraryServiceClient.createBook(name, book);
+   * }
+   * }
+ * * @param name The name of the shelf in which the book is created. * @param book The book to create. * @throws com.google.api.gax.rpc.ApiException if the remote call fails @@ -497,6 +602,15 @@ public final UnaryCallable createBookCallable() { /** * Gets a book. Returns NOT_FOUND if the book does not exist. * + *

Sample code: + * + *

{@code
+   * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
+   *   BookName name = BookName.of("[SHELF_ID]", "[BOOK_ID]");
+   *   Book response = libraryServiceClient.getBook(name);
+   * }
+   * }
+ * * @param name The name of the book to retrieve. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @@ -510,6 +624,15 @@ public final Book getBook(BookName name) { /** * Gets a book. Returns NOT_FOUND if the book does not exist. * + *

Sample code: + * + *

{@code
+   * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
+   *   String name = "name3373707";
+   *   Book response = libraryServiceClient.getBook(name);
+   * }
+   * }
+ * * @param name The name of the book to retrieve. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @@ -631,6 +754,15 @@ public final UnaryCallable deleteBookCallable() { * Updates a book. Returns INVALID_ARGUMENT if the name of the book is non-empty and does not * equal the existing name. * + *

Sample code: + * + *

{@code
+   * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
+   *   Book book = Book.newBuilder().build();
+   *   Book response = libraryServiceClient.updateBook(book);
+   * }
+   * }
+ * * @param book The book to update with. The name must match or be empty. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @@ -667,6 +799,16 @@ public final UnaryCallable updateBookCallable() { * Moves a book to another shelf, and returns the new book. The book id of the new book may not be * the same as the original book. * + *

Sample code: + * + *

{@code
+   * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
+   *   BookName name = BookName.of("[SHELF_ID]", "[BOOK_ID]");
+   *   ShelfName otherShelfName = ShelfName.of("[SHELF_ID]");
+   *   Book response = libraryServiceClient.moveBook(name, otherShelfName);
+   * }
+   * }
+ * * @param name The name of the book to move. * @param other_shelf_name The name of the destination shelf. * @throws com.google.api.gax.rpc.ApiException if the remote call fails @@ -685,6 +827,16 @@ public final Book moveBook(BookName name, ShelfName otherShelfName) { * Moves a book to another shelf, and returns the new book. The book id of the new book may not be * the same as the original book. * + *

Sample code: + * + *

{@code
+   * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
+   *   BookName name = BookName.of("[SHELF_ID]", "[BOOK_ID]");
+   *   String otherShelfName = "otherShelfName-1942963547";
+   *   Book response = libraryServiceClient.moveBook(name, otherShelfName);
+   * }
+   * }
+ * * @param name The name of the book to move. * @param other_shelf_name The name of the destination shelf. * @throws com.google.api.gax.rpc.ApiException if the remote call fails @@ -703,6 +855,16 @@ public final Book moveBook(BookName name, String otherShelfName) { * Moves a book to another shelf, and returns the new book. The book id of the new book may not be * the same as the original book. * + *

Sample code: + * + *

{@code
+   * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
+   *   String name = "name3373707";
+   *   ShelfName otherShelfName = ShelfName.of("[SHELF_ID]");
+   *   Book response = libraryServiceClient.moveBook(name, otherShelfName);
+   * }
+   * }
+ * * @param name The name of the book to move. * @param other_shelf_name The name of the destination shelf. * @throws com.google.api.gax.rpc.ApiException if the remote call fails @@ -721,6 +883,16 @@ public final Book moveBook(String name, ShelfName otherShelfName) { * Moves a book to another shelf, and returns the new book. The book id of the new book may not be * the same as the original book. * + *

Sample code: + * + *

{@code
+   * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
+   *   String name = "name3373707";
+   *   String otherShelfName = "otherShelfName-1942963547";
+   *   Book response = libraryServiceClient.moveBook(name, otherShelfName);
+   * }
+   * }
+ * * @param name The name of the book to move. * @param other_shelf_name The name of the destination shelf. * @throws com.google.api.gax.rpc.ApiException if the remote call fails diff --git a/test/integration/goldens/logging/ConfigClient.java b/test/integration/goldens/logging/ConfigClient.java index 507ea5ed4a..3ced45d449 100644 --- a/test/integration/goldens/logging/ConfigClient.java +++ b/test/integration/goldens/logging/ConfigClient.java @@ -475,6 +475,15 @@ public final UnaryCallable listSinksCallabl /** * Gets a sink. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   LogSinkName sinkName = LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]");
+   *   LogSink response = configClient.getSink(sinkName);
+   * }
+   * }
+ * * @param sink_name Required. The resource name of the sink: *

"projects/[PROJECT_ID]/sinks/[SINK_ID]" * "organizations/[ORGANIZATION_ID]/sinks/[SINK_ID]" @@ -495,6 +504,15 @@ public final LogSink getSink(LogSinkName sinkName) { /** * Gets a sink. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   String sinkName = LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]").toString();
+   *   LogSink response = configClient.getSink(sinkName);
+   * }
+   * }
+ * * @param sink_name Required. The resource name of the sink: *

"projects/[PROJECT_ID]/sinks/[SINK_ID]" * "organizations/[ORGANIZATION_ID]/sinks/[SINK_ID]" @@ -536,6 +554,16 @@ public final UnaryCallable getSinkCallable() { * permitted to write to the destination. A sink can export log entries only from the resource * owning the sink. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   BillingAccountName parent = BillingAccountName.of("[BILLING_ACCOUNT]");
+   *   LogSink sink = LogSink.newBuilder().build();
+   *   LogSink response = configClient.createSink(parent, sink);
+   * }
+   * }
+ * * @param parent Required. The resource in which to create the sink: *

"projects/[PROJECT_ID]" "organizations/[ORGANIZATION_ID]" * "billingAccounts/[BILLING_ACCOUNT_ID]" "folders/[FOLDER_ID]" @@ -560,6 +588,16 @@ public final LogSink createSink(BillingAccountName parent, LogSink sink) { * permitted to write to the destination. A sink can export log entries only from the resource * owning the sink. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   FolderName parent = FolderName.of("[FOLDER]");
+   *   LogSink sink = LogSink.newBuilder().build();
+   *   LogSink response = configClient.createSink(parent, sink);
+   * }
+   * }
+ * * @param parent Required. The resource in which to create the sink: *

"projects/[PROJECT_ID]" "organizations/[ORGANIZATION_ID]" * "billingAccounts/[BILLING_ACCOUNT_ID]" "folders/[FOLDER_ID]" @@ -584,6 +622,16 @@ public final LogSink createSink(FolderName parent, LogSink sink) { * permitted to write to the destination. A sink can export log entries only from the resource * owning the sink. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
+   *   LogSink sink = LogSink.newBuilder().build();
+   *   LogSink response = configClient.createSink(parent, sink);
+   * }
+   * }
+ * * @param parent Required. The resource in which to create the sink: *

"projects/[PROJECT_ID]" "organizations/[ORGANIZATION_ID]" * "billingAccounts/[BILLING_ACCOUNT_ID]" "folders/[FOLDER_ID]" @@ -608,6 +656,16 @@ public final LogSink createSink(OrganizationName parent, LogSink sink) { * permitted to write to the destination. A sink can export log entries only from the resource * owning the sink. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   ProjectName parent = ProjectName.of("[PROJECT]");
+   *   LogSink sink = LogSink.newBuilder().build();
+   *   LogSink response = configClient.createSink(parent, sink);
+   * }
+   * }
+ * * @param parent Required. The resource in which to create the sink: *

"projects/[PROJECT_ID]" "organizations/[ORGANIZATION_ID]" * "billingAccounts/[BILLING_ACCOUNT_ID]" "folders/[FOLDER_ID]" @@ -632,6 +690,16 @@ public final LogSink createSink(ProjectName parent, LogSink sink) { * permitted to write to the destination. A sink can export log entries only from the resource * owning the sink. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   String parent = LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]").toString();
+   *   LogSink sink = LogSink.newBuilder().build();
+   *   LogSink response = configClient.createSink(parent, sink);
+   * }
+   * }
+ * * @param parent Required. The resource in which to create the sink: *

"projects/[PROJECT_ID]" "organizations/[ORGANIZATION_ID]" * "billingAccounts/[BILLING_ACCOUNT_ID]" "folders/[FOLDER_ID]" @@ -681,6 +749,16 @@ public final UnaryCallable createSinkCallable() { *

The updated sink might also have a new `writer_identity`; see the `unique_writer_identity` * field. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   LogSinkName sinkName = LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]");
+   *   LogSink sink = LogSink.newBuilder().build();
+   *   LogSink response = configClient.updateSink(sinkName, sink);
+   * }
+   * }
+ * * @param sink_name Required. The full resource name of the sink to update, including the parent * resource and the sink identifier: *

"projects/[PROJECT_ID]/sinks/[SINK_ID]" @@ -709,6 +787,16 @@ public final LogSink updateSink(LogSinkName sinkName, LogSink sink) { *

The updated sink might also have a new `writer_identity`; see the `unique_writer_identity` * field. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   String sinkName = LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]").toString();
+   *   LogSink sink = LogSink.newBuilder().build();
+   *   LogSink response = configClient.updateSink(sinkName, sink);
+   * }
+   * }
+ * * @param sink_name Required. The full resource name of the sink to update, including the parent * resource and the sink identifier: *

"projects/[PROJECT_ID]/sinks/[SINK_ID]" @@ -734,6 +822,17 @@ public final LogSink updateSink(String sinkName, LogSink sink) { *

The updated sink might also have a new `writer_identity`; see the `unique_writer_identity` * field. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   LogSinkName sinkName = LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]");
+   *   LogSink sink = LogSink.newBuilder().build();
+   *   FieldMask updateMask = FieldMask.newBuilder().build();
+   *   LogSink response = configClient.updateSink(sinkName, sink, updateMask);
+   * }
+   * }
+ * * @param sink_name Required. The full resource name of the sink to update, including the parent * resource and the sink identifier: *

"projects/[PROJECT_ID]/sinks/[SINK_ID]" @@ -772,6 +871,17 @@ public final LogSink updateSink(LogSinkName sinkName, LogSink sink, FieldMask up *

The updated sink might also have a new `writer_identity`; see the `unique_writer_identity` * field. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   String sinkName = LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]").toString();
+   *   LogSink sink = LogSink.newBuilder().build();
+   *   FieldMask updateMask = FieldMask.newBuilder().build();
+   *   LogSink response = configClient.updateSink(sinkName, sink, updateMask);
+   * }
+   * }
+ * * @param sink_name Required. The full resource name of the sink to update, including the parent * resource and the sink identifier: *

"projects/[PROJECT_ID]/sinks/[SINK_ID]" @@ -836,6 +946,15 @@ public final UnaryCallable updateSinkCallable() { * Deletes a sink. If the sink has a unique `writer_identity`, then that service account is also * deleted. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   LogSinkName sinkName = LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]");
+   *   configClient.deleteSink(sinkName);
+   * }
+   * }
+ * * @param sink_name Required. The full resource name of the sink to delete, including the parent * resource and the sink identifier: *

"projects/[PROJECT_ID]/sinks/[SINK_ID]" @@ -858,6 +977,15 @@ public final void deleteSink(LogSinkName sinkName) { * Deletes a sink. If the sink has a unique `writer_identity`, then that service account is also * deleted. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   String sinkName = LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]").toString();
+   *   configClient.deleteSink(sinkName);
+   * }
+   * }
+ * * @param sink_name Required. The full resource name of the sink to delete, including the parent * resource and the sink identifier: *

"projects/[PROJECT_ID]/sinks/[SINK_ID]" @@ -1014,6 +1142,15 @@ public final ListExclusionsPagedResponse listExclusions(ListExclusionsRequest re /** * Gets the description of an exclusion. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   LogExclusionName name = LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]");
+   *   LogExclusion response = configClient.getExclusion(name);
+   * }
+   * }
+ * * @param name Required. The resource name of an existing exclusion: *

"projects/[PROJECT_ID]/exclusions/[EXCLUSION_ID]" * "organizations/[ORGANIZATION_ID]/exclusions/[EXCLUSION_ID]" @@ -1032,6 +1169,15 @@ public final LogExclusion getExclusion(LogExclusionName name) { /** * Gets the description of an exclusion. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   String name = LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]").toString();
+   *   LogExclusion response = configClient.getExclusion(name);
+   * }
+   * }
+ * * @param name Required. The resource name of an existing exclusion: *

"projects/[PROJECT_ID]/exclusions/[EXCLUSION_ID]" * "organizations/[ORGANIZATION_ID]/exclusions/[EXCLUSION_ID]" @@ -1071,6 +1217,16 @@ public final UnaryCallable getExclusionCallab * Creates a new exclusion in a specified parent resource. Only log entries belonging to that * resource can be excluded. You can have up to 10 exclusions in a resource. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   BillingAccountName parent = BillingAccountName.of("[BILLING_ACCOUNT]");
+   *   LogExclusion exclusion = LogExclusion.newBuilder().build();
+   *   LogExclusion response = configClient.createExclusion(parent, exclusion);
+   * }
+   * }
+ * * @param parent Required. The parent resource in which to create the exclusion: *

"projects/[PROJECT_ID]" "organizations/[ORGANIZATION_ID]" * "billingAccounts/[BILLING_ACCOUNT_ID]" "folders/[FOLDER_ID]" @@ -1093,6 +1249,16 @@ public final LogExclusion createExclusion(BillingAccountName parent, LogExclusio * Creates a new exclusion in a specified parent resource. Only log entries belonging to that * resource can be excluded. You can have up to 10 exclusions in a resource. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   FolderName parent = FolderName.of("[FOLDER]");
+   *   LogExclusion exclusion = LogExclusion.newBuilder().build();
+   *   LogExclusion response = configClient.createExclusion(parent, exclusion);
+   * }
+   * }
+ * * @param parent Required. The parent resource in which to create the exclusion: *

"projects/[PROJECT_ID]" "organizations/[ORGANIZATION_ID]" * "billingAccounts/[BILLING_ACCOUNT_ID]" "folders/[FOLDER_ID]" @@ -1115,6 +1281,16 @@ public final LogExclusion createExclusion(FolderName parent, LogExclusion exclus * Creates a new exclusion in a specified parent resource. Only log entries belonging to that * resource can be excluded. You can have up to 10 exclusions in a resource. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
+   *   LogExclusion exclusion = LogExclusion.newBuilder().build();
+   *   LogExclusion response = configClient.createExclusion(parent, exclusion);
+   * }
+   * }
+ * * @param parent Required. The parent resource in which to create the exclusion: *

"projects/[PROJECT_ID]" "organizations/[ORGANIZATION_ID]" * "billingAccounts/[BILLING_ACCOUNT_ID]" "folders/[FOLDER_ID]" @@ -1137,6 +1313,16 @@ public final LogExclusion createExclusion(OrganizationName parent, LogExclusion * Creates a new exclusion in a specified parent resource. Only log entries belonging to that * resource can be excluded. You can have up to 10 exclusions in a resource. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   ProjectName parent = ProjectName.of("[PROJECT]");
+   *   LogExclusion exclusion = LogExclusion.newBuilder().build();
+   *   LogExclusion response = configClient.createExclusion(parent, exclusion);
+   * }
+   * }
+ * * @param parent Required. The parent resource in which to create the exclusion: *

"projects/[PROJECT_ID]" "organizations/[ORGANIZATION_ID]" * "billingAccounts/[BILLING_ACCOUNT_ID]" "folders/[FOLDER_ID]" @@ -1159,6 +1345,17 @@ public final LogExclusion createExclusion(ProjectName parent, LogExclusion exclu * Creates a new exclusion in a specified parent resource. Only log entries belonging to that * resource can be excluded. You can have up to 10 exclusions in a resource. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   String parent =
+   *       LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]").toString();
+   *   LogExclusion exclusion = LogExclusion.newBuilder().build();
+   *   LogExclusion response = configClient.createExclusion(parent, exclusion);
+   * }
+   * }
+ * * @param parent Required. The parent resource in which to create the exclusion: *

"projects/[PROJECT_ID]" "organizations/[ORGANIZATION_ID]" * "billingAccounts/[BILLING_ACCOUNT_ID]" "folders/[FOLDER_ID]" @@ -1200,6 +1397,17 @@ public final UnaryCallable createExclusion /** * Changes one or more properties of an existing exclusion. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   LogExclusionName name = LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]");
+   *   LogExclusion exclusion = LogExclusion.newBuilder().build();
+   *   FieldMask updateMask = FieldMask.newBuilder().build();
+   *   LogExclusion response = configClient.updateExclusion(name, exclusion, updateMask);
+   * }
+   * }
+ * * @param name Required. The resource name of the exclusion to update: *

"projects/[PROJECT_ID]/exclusions/[EXCLUSION_ID]" * "organizations/[ORGANIZATION_ID]/exclusions/[EXCLUSION_ID]" @@ -1231,6 +1439,17 @@ public final LogExclusion updateExclusion( /** * Changes one or more properties of an existing exclusion. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   String name = LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]").toString();
+   *   LogExclusion exclusion = LogExclusion.newBuilder().build();
+   *   FieldMask updateMask = FieldMask.newBuilder().build();
+   *   LogExclusion response = configClient.updateExclusion(name, exclusion, updateMask);
+   * }
+   * }
+ * * @param name Required. The resource name of the exclusion to update: *

"projects/[PROJECT_ID]/exclusions/[EXCLUSION_ID]" * "organizations/[ORGANIZATION_ID]/exclusions/[EXCLUSION_ID]" @@ -1283,6 +1502,15 @@ public final UnaryCallable updateExclusion /** * Deletes an exclusion. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   LogExclusionName name = LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]");
+   *   configClient.deleteExclusion(name);
+   * }
+   * }
+ * * @param name Required. The resource name of an existing exclusion to delete: *

"projects/[PROJECT_ID]/exclusions/[EXCLUSION_ID]" * "organizations/[ORGANIZATION_ID]/exclusions/[EXCLUSION_ID]" @@ -1301,6 +1529,15 @@ public final void deleteExclusion(LogExclusionName name) { /** * Deletes an exclusion. * + *

Sample code: + * + *

{@code
+   * try (ConfigClient configClient = ConfigClient.create()) {
+   *   String name = LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]").toString();
+   *   configClient.deleteExclusion(name);
+   * }
+   * }
+ * * @param name Required. The resource name of an existing exclusion to delete: *

"projects/[PROJECT_ID]/exclusions/[EXCLUSION_ID]" * "organizations/[ORGANIZATION_ID]/exclusions/[EXCLUSION_ID]" diff --git a/test/integration/goldens/logging/LoggingClient.java b/test/integration/goldens/logging/LoggingClient.java index 2b7cef1ad5..b9f4814950 100644 --- a/test/integration/goldens/logging/LoggingClient.java +++ b/test/integration/goldens/logging/LoggingClient.java @@ -163,6 +163,15 @@ public LoggingServiceV2Stub getStub() { * written shortly before the delete operation might not be deleted. Entries received after the * delete operation with a timestamp before the operation will be deleted. * + *

Sample code: + * + *

{@code
+   * try (LoggingClient loggingClient = LoggingClient.create()) {
+   *   LogName logName = LogName.ofProjectLogName("[PROJECT]", "[LOG]");
+   *   loggingClient.deleteLog(logName);
+   * }
+   * }
+ * * @param log_name Required. The resource name of the log to delete: *

"projects/[PROJECT_ID]/logs/[LOG_ID]" "organizations/[ORGANIZATION_ID]/logs/[LOG_ID]" * "billingAccounts/[BILLING_ACCOUNT_ID]/logs/[LOG_ID]" "folders/[FOLDER_ID]/logs/[LOG_ID]" @@ -185,6 +194,15 @@ public final void deleteLog(LogName logName) { * written shortly before the delete operation might not be deleted. Entries received after the * delete operation with a timestamp before the operation will be deleted. * + *

Sample code: + * + *

{@code
+   * try (LoggingClient loggingClient = LoggingClient.create()) {
+   *   String logName = LogName.ofProjectLogName("[PROJECT]", "[LOG]").toString();
+   *   loggingClient.deleteLog(logName);
+   * }
+   * }
+ * * @param log_name Required. The resource name of the log to delete: *

"projects/[PROJECT_ID]/logs/[LOG_ID]" "organizations/[ORGANIZATION_ID]/logs/[LOG_ID]" * "billingAccounts/[BILLING_ACCOUNT_ID]/logs/[LOG_ID]" "folders/[FOLDER_ID]/logs/[LOG_ID]" @@ -230,6 +248,19 @@ public final UnaryCallable deleteLogCallable() { * libraries configured to use Logging. A single request may contain log entries for a maximum of * 1000 different resources (projects, organizations, billing accounts or folders) * + *

Sample code: + * + *

{@code
+   * try (LoggingClient loggingClient = LoggingClient.create()) {
+   *   LogName logName = LogName.ofProjectLogName("[PROJECT]", "[LOG]");
+   *   MonitoredResource resource = MonitoredResource.newBuilder().build();
+   *   Map labels = new HashMap<>();
+   *   List entries = new ArrayList<>();
+   *   WriteLogEntriesResponse response =
+   *       loggingClient.writeLogEntries(logName, resource, labels, entries);
+   * }
+   * }
+ * * @param log_name Optional. A default log resource name that is assigned to all log entries in * `entries` that do not specify a value for `log_name`: *

"projects/[PROJECT_ID]/logs/[LOG_ID]" "organizations/[ORGANIZATION_ID]/logs/[LOG_ID]" @@ -292,6 +323,19 @@ public final WriteLogEntriesResponse writeLogEntries( * libraries configured to use Logging. A single request may contain log entries for a maximum of * 1000 different resources (projects, organizations, billing accounts or folders) * + *

Sample code: + * + *

{@code
+   * try (LoggingClient loggingClient = LoggingClient.create()) {
+   *   String logName = LogName.ofProjectLogName("[PROJECT]", "[LOG]").toString();
+   *   MonitoredResource resource = MonitoredResource.newBuilder().build();
+   *   Map labels = new HashMap<>();
+   *   List entries = new ArrayList<>();
+   *   WriteLogEntriesResponse response =
+   *       loggingClient.writeLogEntries(logName, resource, labels, entries);
+   * }
+   * }
+ * * @param log_name Optional. A default log resource name that is assigned to all log entries in * `entries` that do not specify a value for `log_name`: *

"projects/[PROJECT_ID]/logs/[LOG_ID]" "organizations/[ORGANIZATION_ID]/logs/[LOG_ID]" diff --git a/test/integration/goldens/logging/MetricsClient.java b/test/integration/goldens/logging/MetricsClient.java index a7a58f48b8..7ae9d336af 100644 --- a/test/integration/goldens/logging/MetricsClient.java +++ b/test/integration/goldens/logging/MetricsClient.java @@ -214,6 +214,15 @@ public final ListLogMetricsPagedResponse listLogMetrics(ListLogMetricsRequest re /** * Gets a logs-based metric. * + *

Sample code: + * + *

{@code
+   * try (MetricsClient metricsClient = MetricsClient.create()) {
+   *   LogMetricName metricName = LogMetricName.of("[PROJECT]", "[METRIC]");
+   *   LogMetric response = metricsClient.getLogMetric(metricName);
+   * }
+   * }
+ * * @param metric_name Required. The resource name of the desired metric: *

"projects/[PROJECT_ID]/metrics/[METRIC_ID]" * @throws com.google.api.gax.rpc.ApiException if the remote call fails @@ -230,6 +239,15 @@ public final LogMetric getLogMetric(LogMetricName metricName) { /** * Gets a logs-based metric. * + *

Sample code: + * + *

{@code
+   * try (MetricsClient metricsClient = MetricsClient.create()) {
+   *   String metricName = LogMetricName.of("[PROJECT]", "[METRIC]").toString();
+   *   LogMetric response = metricsClient.getLogMetric(metricName);
+   * }
+   * }
+ * * @param metric_name Required. The resource name of the desired metric: *

"projects/[PROJECT_ID]/metrics/[METRIC_ID]" * @throws com.google.api.gax.rpc.ApiException if the remote call fails @@ -265,6 +283,16 @@ public final UnaryCallable getLogMetricCallable( /** * Creates a logs-based metric. * + *

Sample code: + * + *

{@code
+   * try (MetricsClient metricsClient = MetricsClient.create()) {
+   *   ProjectName parent = ProjectName.of("[PROJECT]");
+   *   LogMetric metric = LogMetric.newBuilder().build();
+   *   LogMetric response = metricsClient.createLogMetric(parent, metric);
+   * }
+   * }
+ * * @param parent Required. The resource name of the project in which to create the metric: *

"projects/[PROJECT_ID]" *

The new metric must be provided in the request. @@ -285,6 +313,16 @@ public final LogMetric createLogMetric(ProjectName parent, LogMetric metric) { /** * Creates a logs-based metric. * + *

Sample code: + * + *

{@code
+   * try (MetricsClient metricsClient = MetricsClient.create()) {
+   *   String parent = LogMetricName.of("[PROJECT]", "[METRIC]").toString();
+   *   LogMetric metric = LogMetric.newBuilder().build();
+   *   LogMetric response = metricsClient.createLogMetric(parent, metric);
+   * }
+   * }
+ * * @param parent Required. The resource name of the project in which to create the metric: *

"projects/[PROJECT_ID]" *

The new metric must be provided in the request. @@ -323,6 +361,16 @@ public final UnaryCallable createLogMetricCal /** * Creates or updates a logs-based metric. * + *

Sample code: + * + *

{@code
+   * try (MetricsClient metricsClient = MetricsClient.create()) {
+   *   LogMetricName metricName = LogMetricName.of("[PROJECT]", "[METRIC]");
+   *   LogMetric metric = LogMetric.newBuilder().build();
+   *   LogMetric response = metricsClient.updateLogMetric(metricName, metric);
+   * }
+   * }
+ * * @param metric_name Required. The resource name of the metric to update: *

"projects/[PROJECT_ID]/metrics/[METRIC_ID]" *

The updated metric must be provided in the request and it's `name` field must be the @@ -344,6 +392,16 @@ public final LogMetric updateLogMetric(LogMetricName metricName, LogMetric metri /** * Creates or updates a logs-based metric. * + *

Sample code: + * + *

{@code
+   * try (MetricsClient metricsClient = MetricsClient.create()) {
+   *   String metricName = LogMetricName.of("[PROJECT]", "[METRIC]").toString();
+   *   LogMetric metric = LogMetric.newBuilder().build();
+   *   LogMetric response = metricsClient.updateLogMetric(metricName, metric);
+   * }
+   * }
+ * * @param metric_name Required. The resource name of the metric to update: *

"projects/[PROJECT_ID]/metrics/[METRIC_ID]" *

The updated metric must be provided in the request and it's `name` field must be the @@ -383,6 +441,15 @@ public final UnaryCallable updateLogMetricCal /** * Deletes a logs-based metric. * + *

Sample code: + * + *

{@code
+   * try (MetricsClient metricsClient = MetricsClient.create()) {
+   *   LogMetricName metricName = LogMetricName.of("[PROJECT]", "[METRIC]");
+   *   metricsClient.deleteLogMetric(metricName);
+   * }
+   * }
+ * * @param metric_name Required. The resource name of the metric to delete: *

"projects/[PROJECT_ID]/metrics/[METRIC_ID]" * @throws com.google.api.gax.rpc.ApiException if the remote call fails @@ -399,6 +466,15 @@ public final void deleteLogMetric(LogMetricName metricName) { /** * Deletes a logs-based metric. * + *

Sample code: + * + *

{@code
+   * try (MetricsClient metricsClient = MetricsClient.create()) {
+   *   String metricName = LogMetricName.of("[PROJECT]", "[METRIC]").toString();
+   *   metricsClient.deleteLogMetric(metricName);
+   * }
+   * }
+ * * @param metric_name Required. The resource name of the metric to delete: *

"projects/[PROJECT_ID]/metrics/[METRIC_ID]" * @throws com.google.api.gax.rpc.ApiException if the remote call fails diff --git a/test/integration/goldens/redis/CloudRedisClient.java b/test/integration/goldens/redis/CloudRedisClient.java index d58b981828..0aa0479a15 100644 --- a/test/integration/goldens/redis/CloudRedisClient.java +++ b/test/integration/goldens/redis/CloudRedisClient.java @@ -290,6 +290,15 @@ public final UnaryCallable listInst /** * Gets the details of a specific Redis instance. * + *

Sample code: + * + *

{@code
+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
+   *   Instance response = cloudRedisClient.getInstance(name);
+   * }
+   * }
+ * * @param name Required. Redis instance resource name using the form: * `projects/{project_id}/locations/{location_id}/instances/{instance_id}` where `location_id` * refers to a GCP region. @@ -305,6 +314,15 @@ public final Instance getInstance(InstanceName name) { /** * Gets the details of a specific Redis instance. * + *

Sample code: + * + *

{@code
+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   String name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString();
+   *   Instance response = cloudRedisClient.getInstance(name);
+   * }
+   * }
+ * * @param name Required. Redis instance resource name using the form: * `projects/{project_id}/locations/{location_id}/instances/{instance_id}` where `location_id` * refers to a GCP region.