diff --git a/src/main/java/com/google/api/generator/gapic/composer/ClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/ClassComposer.java index 5579c1bd6e..46b6180965 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/ClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/ClassComposer.java @@ -22,5 +22,7 @@ public interface ClassComposer { GapicClass generate( + // TODO(miraleung): clean up the hierarchy to avoid pass another parameter (resourceNames is + // only used for composing sample code). Service service, Map messageTypes, Map resourceNames); } diff --git a/src/main/java/com/google/api/generator/gapic/composer/SampleCodeHelperComposer.java b/src/main/java/com/google/api/generator/gapic/composer/SampleCodeHelperComposer.java index 00c34e2165..443dd68fff 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/SampleCodeHelperComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/SampleCodeHelperComposer.java @@ -16,6 +16,8 @@ import com.google.api.generator.engine.ast.AssignmentExpr; import com.google.api.generator.engine.ast.CommentStatement; +import com.google.api.generator.engine.ast.Expr; +import com.google.api.generator.engine.ast.ExprStatement; import com.google.api.generator.engine.ast.LineComment; import com.google.api.generator.engine.ast.MethodInvocationExpr; import com.google.api.generator.engine.ast.TryCatchStatement; @@ -26,17 +28,26 @@ 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.base.Preconditions; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; public final class SampleCodeHelperComposer { + private static String RESPONSE = "response"; public static TryCatchStatement composeRpcMethodSampleCode( Method method, List arguments, TypeNode clientType, Map resourceNames) { + Preconditions.checkState( + !arguments.isEmpty(), + "If method %s's arguments is none, it should pass %s as argument.", + method.name(), + method.inputType().reference().name()); // Paged Unary RPC method. if (method.isPaged()) { return composePagedUnaryRpcMethodSampleCode(method, arguments, clientType, resourceNames); @@ -71,14 +82,45 @@ private static TryCatchStatement composeUnaryRpcMethodSampleCode( List arguments, TypeNode clientType, Map resourceNames) { - // TODO(summerji): compose sample code for unary rpc method. VariableExpr clientVarExpr = createVariableExpr(getClientName(clientType), clientType); + // Assign each method arguments with its default value. + Map methodArgVarExprMap = mapMethodArgumentsToVariableExprs(arguments); + List methodArgumentsAssignmentExpr = + assignMethodArgumentsWithDefaultValues(arguments, methodArgVarExprMap, resourceNames); + List methodVarExprs = + arguments.stream() + .map(arg -> methodArgVarExprMap.get(arg.name())) + .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()); + Expr responseExpr = null; + if (returnsVoid) { + responseExpr = + MethodInvocationExpr.builder() + .setExprReferenceExpr(clientVarExpr) + .setMethodName(JavaStyle.toLowerCamelCase(method.name())) + .setArguments(methodVarExprs) + .setReturnType(clientType) + .build(); + } else { + responseExpr = + createAssignExprForVariableWithClientMethod( + createVariableExpr(RESPONSE, method.outputType()), + clientVarExpr, + JavaStyle.toLowerCamelCase(method.name()), + methodVarExprs); + } + + List bodyExpr = new ArrayList<>(); + bodyExpr.addAll(methodArgumentsAssignmentExpr); + bodyExpr.add(responseExpr); + return TryCatchStatement.builder() .setTryResourceExpr(assignClientVariableWithCreateMethodExpr(clientVarExpr)) .setTryBody( - Arrays.asList( - createLineCommentStatement( - "Note: Not implemented yet, placeholder for pure unary rpc method sample code."))) + bodyExpr.stream().map(e -> ExprStatement.withExpr(e)).collect(Collectors.toList())) .setIsSampleCode(true) .build(); } @@ -89,6 +131,7 @@ private static TryCatchStatement composeLroUnaryRpcMethodSampleCode( TypeNode clientType, Map resourceNames) { // TODO(summerji): compose sample code for unary lro rpc method. + // TODO(summerji): Add unit tests. VariableExpr clientVarExpr = createVariableExpr(getClientName(clientType), clientType); return TryCatchStatement.builder() .setTryResourceExpr(assignClientVariableWithCreateMethodExpr(clientVarExpr)) @@ -106,6 +149,7 @@ private static TryCatchStatement composePagedUnaryRpcMethodSampleCode( TypeNode clientType, Map resourceNames) { // TODO(summerji): compose sample code for unary paged rpc method. + // TODO(summerji): Add unit tests. VariableExpr clientVarExpr = createVariableExpr(getClientName(clientType), clientType); return TryCatchStatement.builder() .setTryResourceExpr(assignClientVariableWithCreateMethodExpr(clientVarExpr)) @@ -116,7 +160,6 @@ private static TryCatchStatement composePagedUnaryRpcMethodSampleCode( .setIsSampleCode(true) .build(); } - // ==================================Helpers===================================================// // Assign client variable expr with create client. @@ -134,6 +177,55 @@ private static AssignmentExpr assignClientVariableWithCreateMethodExpr( .build(); } + private static List assignMethodArgumentsWithDefaultValues( + List arguments, + Map argVarExprs, + Map resourceNames) { + return arguments.stream() + .map( + arg -> + createAssignmentExpr( + argVarExprs.get(arg.name()), + DefaultValueComposer.createDefaultValue(arg, resourceNames))) + .collect(Collectors.toList()); + } + + private static AssignmentExpr createAssignmentExpr(VariableExpr variableExpr, Expr valueExpr) { + return AssignmentExpr.builder() + .setVariableExpr(variableExpr.toBuilder().setIsDecl(true).build()) + .setValueExpr(valueExpr) + .build(); + } + + private static Expr createAssignExprForVariableWithClientMethod( + VariableExpr variableExpr, + VariableExpr clientVarExpr, + String methodName, + List argumentsVarExprs) { + MethodInvocationExpr clientMethodInvocationExpr = + MethodInvocationExpr.builder() + .setExprReferenceExpr(clientVarExpr) + .setMethodName(JavaStyle.toLowerCamelCase(methodName)) + .setArguments(argumentsVarExprs) + .setReturnType(variableExpr.variable().type()) + .build(); + return AssignmentExpr.builder() + .setVariableExpr(variableExpr.toBuilder().setIsDecl(true).build()) + .setValueExpr(clientMethodInvocationExpr) + .build(); + } + + private static Map mapMethodArgumentsToVariableExprs( + List arguments) { + return arguments.stream() + .collect( + Collectors.toMap( + methodArg -> methodArg.name(), + methodArg -> + createVariableExpr( + JavaStyle.toLowerCamelCase(methodArg.name()), methodArg.type()))); + } + private static String getClientName(TypeNode clientType) { return JavaStyle.toLowerCamelCase(clientType.reference().name()); } @@ -157,4 +249,9 @@ private static VariableExpr createVariableExpr( .setIsDecl(isDecl) .build(); } + + private static boolean isProtoEmptyType(TypeNode type) { + return type.reference().pakkage().equals("com.google.protobuf") + && type.reference().name().equals("Empty"); + } } 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 e09c1f22ab..0b050841e8 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 @@ -1,6 +1,6 @@ // Copyright 2020 Google LLC // -// Licensed under the Apache License, Version 2.0 (the "License");\ +// 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 // 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..dd574a567e 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", + "SampleCodeHelperComposerTest" ] 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/SampleCodeHelperComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/SampleCodeHelperComposerTest.java new file mode 100644 index 0000000000..4678fa8294 --- /dev/null +++ b/src/test/java/com/google/api/generator/gapic/composer/SampleCodeHelperComposerTest.java @@ -0,0 +1,485 @@ +// 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 static org.junit.Assert.assertThrows; + +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 java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class SampleCodeHelperComposerTest { + private static final String PACKAGE_NAME = "com.google.showcase.v1beta1"; + private static final TypeNode clientType = + TypeNode.withReference( + VaporReference.builder().setName("EchoClient").setPakkage(PACKAGE_NAME).build()); + Map resourceNames = new HashMap<>(); + + @Before + public void setUp() { + ResourceName foobarResourceName = + ResourceName.builder() + .setVariableName("foobar") + .setPakkage(PACKAGE_NAME) + .setResourceTypeString("showcase.googleapis.com/Foobar") + .setPatterns( + Arrays.asList( + "projects/{project}/foobars/{foobar}", + "projects/{project}/chocolate/variants/{variant}/foobars/{foobar}", + "foobars/{foobar}", + "bar_foo/{bar_foo}/foobars/{foobar}")) + .setParentMessageName("Foobar") + .build(); + ResourceName anythingGoesResourceName = + ResourceName.createWildcard("showcase.googleapis.com/AnythingGoes", PACKAGE_NAME); + resourceNames.put("showcase.googleapis.com/Foobar", foobarResourceName); + resourceNames.put("showcase.googleapis.com/AnythingGoes", anythingGoesResourceName); + } + + @Test + public void composeUnaryRpcMethodSampleCode_resourceNameHelperMethodArgument() { + TypeNode inputType = + TypeNode.withReference( + VaporReference.builder().setName("EchoRequest").setPakkage(PACKAGE_NAME).build()); + TypeNode outputType = + TypeNode.withReference( + VaporReference.builder().setName("EchoResponse").setPakkage(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( + SampleCodeHelperComposer.composeRpcMethodSampleCode( + unaryMethod, signatures.get(0), clientType, resourceNames)); + String expected = + "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_isMessageMethodArgument() { + TypeNode inputType = + TypeNode.withReference( + VaporReference.builder().setName("EchoRequest").setPakkage(PACKAGE_NAME).build()); + TypeNode outputType = + TypeNode.withReference( + VaporReference.builder().setName("EchoResponse").setPakkage(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( + SampleCodeHelperComposer.composeRpcMethodSampleCode( + unaryMethod, signatures.get(0), clientType, resourceNames)); + String expected = + "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_superReferenceIsResourceNameMethodArgument() { + TypeNode inputType = + TypeNode.withReference( + VaporReference.builder().setName("EchoRequest").setPakkage(PACKAGE_NAME).build()); + TypeNode outputType = + TypeNode.withReference( + VaporReference.builder().setName("EchoResponse").setPakkage(PACKAGE_NAME).build()); + TypeNode methodArgType = + TypeNode.withReference( + VaporReference.builder() + .setName("FoobarName") + .setPakkage(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( + SampleCodeHelperComposer.composeRpcMethodSampleCode( + unaryMethod, signatures.get(0), clientType, resourceNames)); + String expected = + "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_stringIsContainedInOneOfMethodArgument() { + TypeNode inputType = + TypeNode.withReference( + VaporReference.builder().setName("EchoRequest").setPakkage(PACKAGE_NAME).build()); + TypeNode outputType = + TypeNode.withReference( + VaporReference.builder().setName("EchoResponse").setPakkage(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( + SampleCodeHelperComposer.composeRpcMethodSampleCode( + unaryMethod, signatures.get(0), clientType, resourceNames)); + String expected = + "try (EchoClient echoClient = EchoClient.create()) {\n" + + " String content = \"content951530617\";\n" + + " EchoResponse response = echoClient.echo(content);\n" + + "}"; + assertEquals(expected, results); + } + + @Test + public void composeUnaryRpcMethodSampleCode_strinWithResourceReferenceMethodArgument() { + TypeNode inputType = + TypeNode.withReference( + VaporReference.builder().setName("EchoRequest").setPakkage(PACKAGE_NAME).build()); + TypeNode outputType = + TypeNode.withReference( + VaporReference.builder().setName("EchoResponse").setPakkage(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( + SampleCodeHelperComposer.composeRpcMethodSampleCode( + unaryMethod, signatures.get(0), clientType, resourceNames)); + String expected = + "try (EchoClient echoClient = EchoClient.create()) {\n" + + " String name = \"name3373707\";\n" + + " EchoResponse response = echoClient.echo(name);\n" + + "}"; + assertEquals(expected, results); + } + + @Test + public void composeUnaryRpcMethodSampleCode_stringWithParentResourceReferenceMethodArgument() { + TypeNode inputType = + TypeNode.withReference( + VaporReference.builder().setName("EchoRequest").setPakkage(PACKAGE_NAME).build()); + TypeNode outputType = + TypeNode.withReference( + VaporReference.builder().setName("EchoResponse").setPakkage(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( + SampleCodeHelperComposer.composeRpcMethodSampleCode( + unaryMethod, signatures.get(0), clientType, resourceNames)); + String expected = + "try (EchoClient echoClient = EchoClient.create()) {\n" + + " String parent = \"parent-995424086\";\n" + + " EchoResponse response = echoClient.echo(parent);\n" + + "}"; + assertEquals(expected, results); + } + + @Test + public void composeUnaryRpcMethodSampleCode_multipleWordNameMethodArgument() { + TypeNode inputType = + TypeNode.withReference( + VaporReference.builder().setName("EchoRequest").setPakkage(PACKAGE_NAME).build()); + TypeNode outputType = + TypeNode.withReference( + VaporReference.builder().setName("EchoResponse").setPakkage(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(PACKAGE_NAME).build(); + Field nestFiled = + Field.builder() + .setName("user") + .setType(TypeNode.withReference(userRef)) + .setIsMessage(true) + .build(); + MethodArgument arg = + MethodArgument.builder() + .setName("display_name") + .setType(TypeNode.STRING) + .setField(methodArgField) + .setNestedFields(Arrays.asList(nestFiled)) + .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( + SampleCodeHelperComposer.composeRpcMethodSampleCode( + unaryMethod, signatures.get(0), clientType, resourceNames)); + String expected = + "try (EchoClient echoClient = EchoClient.create()) {\n" + + " String displayName = \"display_name1615086568\";\n" + + " EchoResponse response = echoClient.echo(displayName);\n" + + "}"; + assertEquals(expected, results); + } + + @Test + public void composeUnaryRpcMethodSampleCode_multipleMethodArguments() { + TypeNode inputType = + TypeNode.withReference( + VaporReference.builder().setName("EchoRequest").setPakkage(PACKAGE_NAME).build()); + TypeNode outputType = + TypeNode.withReference( + VaporReference.builder().setName("EchoResponse").setPakkage(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(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( + SampleCodeHelperComposer.composeRpcMethodSampleCode( + unaryMethod, signatures.get(0), clientType, resourceNames)); + String expected = + "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() { + TypeNode inputType = + TypeNode.withReference( + VaporReference.builder() + .setName("GetUserRequest") + .setPakkage("com.google.showcase.v1beta1") + .build()); + TypeNode outputType = + TypeNode.withReference( + VaporReference.builder() + .setName("GetUserResponse") + .setPakkage("com.google.showcase.v1beta1") + .build()); + Method unaryMethod = + Method.builder() + .setName("getUser") + .setMethodSignatures(Collections.emptyList()) + .setInputType(inputType) + .setOutputType(outputType) + .build(); + assertThrows( + IllegalStateException.class, + () -> + SampleCodeWriter.write( + SampleCodeHelperComposer.composeRpcMethodSampleCode( + unaryMethod, Collections.emptyList(), clientType, resourceNames))); + } + + @Test + public void composeUnaryRpcMethodSampleCode_methodReturnVoid() { + 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( + SampleCodeHelperComposer.composeRpcMethodSampleCode( + unaryMethod, methodSignatures.get(0), clientType, resourceNames)); + String expected = + "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 bf4c69bc42..91d56b1b62 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 @@ -147,7 +147,8 @@ public class EchoClient implements BackgroundResource { * *
{@code
    * try (EchoClient echoClient = EchoClient.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   ResourceName parent = FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]");
+   *   EchoResponse response = echoClient.echo(parent);
    * }
    * }
* @@ -168,7 +169,8 @@ public class EchoClient implements BackgroundResource { * *
{@code
    * try (EchoClient echoClient = EchoClient.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   Status error = Status.newBuilder().build();
+   *   EchoResponse response = echoClient.echo(error);
    * }
    * }
* @@ -186,7 +188,8 @@ public class EchoClient implements BackgroundResource { * *
{@code
    * try (EchoClient echoClient = EchoClient.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   FoobarName name = FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]");
+   *   EchoResponse response = echoClient.echo(name);
    * }
    * }
* @@ -205,7 +208,8 @@ public class EchoClient implements BackgroundResource { * *
{@code
    * try (EchoClient echoClient = EchoClient.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   String content = "content951530617";
+   *   EchoResponse response = echoClient.echo(content);
    * }
    * }
* @@ -223,7 +227,8 @@ public class EchoClient implements BackgroundResource { * *
{@code
    * try (EchoClient echoClient = EchoClient.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   String name = "name3373707";
+   *   EchoResponse response = echoClient.echo(name);
    * }
    * }
* @@ -241,7 +246,8 @@ public class EchoClient implements BackgroundResource { * *
{@code
    * try (EchoClient echoClient = EchoClient.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   String parent = "parent-995424086";
+   *   EchoResponse response = echoClient.echo(parent);
    * }
    * }
* @@ -259,7 +265,9 @@ public class EchoClient implements BackgroundResource { * *
{@code
    * try (EchoClient echoClient = EchoClient.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   String content = "content951530617";
+   *   Severity severity = Severity.forNumber(0);
+   *   EchoResponse response = echoClient.echo(content, severity);
    * }
    * }
* 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 b52c927a08..b238f27485 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 @@ -127,7 +127,10 @@ public class IdentityClient implements BackgroundResource { * *
{@code
    * try (IdentityClient identityClient = IdentityClient.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   String parent = "parent-995424086";
+   *   String displayName = "display_name1615086568";
+   *   String email = "email96619420";
+   *   User response = identityClient.createUser(parent, displayName, email);
    * }
    * }
* @@ -152,7 +155,16 @@ public class IdentityClient implements BackgroundResource { * *
{@code
    * try (IdentityClient identityClient = IdentityClient.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   String parent = "parent-995424086";
+   *   String displayName = "display_name1615086568";
+   *   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);
    * }
    * }
* @@ -215,7 +227,8 @@ public class IdentityClient implements BackgroundResource { * *
{@code
    * try (IdentityClient identityClient = IdentityClient.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   UserName name = UserName.of("[USER]");
+   *   User response = identityClient.getUser(name);
    * }
    * }
* @@ -234,7 +247,8 @@ public class IdentityClient implements BackgroundResource { * *
{@code
    * try (IdentityClient identityClient = IdentityClient.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   String name = "name3373707";
+   *   User response = identityClient.getUser(name);
    * }
    * }
* @@ -298,7 +312,8 @@ public class IdentityClient implements BackgroundResource { * *
{@code
    * try (IdentityClient identityClient = IdentityClient.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   UserName name = UserName.of("[USER]");
+   *   identityClient.deleteUser(name);
    * }
    * }
* @@ -319,7 +334,8 @@ public class IdentityClient implements BackgroundResource { * *
{@code
    * try (IdentityClient identityClient = IdentityClient.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   String name = "name3373707";
+   *   identityClient.deleteUser(name);
    * }
    * }
* diff --git a/test/integration/goldens/asset/AssetServiceClient.java b/test/integration/goldens/asset/AssetServiceClient.java index b4db49d5e5..82e033948b 100644 --- a/test/integration/goldens/asset/AssetServiceClient.java +++ b/test/integration/goldens/asset/AssetServiceClient.java @@ -264,7 +264,8 @@ public final BatchGetAssetsHistoryResponse batchGetAssetsHistory( * *
{@code
    * try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   String parent = "parent-995424086";
+   *   Feed response = assetServiceClient.createFeed(parent);
    * }
    * }
* @@ -316,7 +317,8 @@ public final UnaryCallable createFeedCallable() { * *
{@code
    * try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   FeedName name = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]");
+   *   Feed response = assetServiceClient.getFeed(name);
    * }
    * }
* @@ -339,7 +341,8 @@ public final Feed getFeed(FeedName name) { * *
{@code
    * try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   String name = "name3373707";
+   *   Feed response = assetServiceClient.getFeed(name);
    * }
    * }
* @@ -390,7 +393,8 @@ public final UnaryCallable getFeedCallable() { * *
{@code
    * try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   String parent = "parent-995424086";
+   *   ListFeedsResponse response = assetServiceClient.listFeeds(parent);
    * }
    * }
* @@ -441,7 +445,8 @@ public final UnaryCallable listFeedsCallabl * *
{@code
    * try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   Feed feed = Feed.newBuilder().build();
+   *   Feed response = assetServiceClient.updateFeed(feed);
    * }
    * }
* @@ -492,7 +497,8 @@ public final UnaryCallable updateFeedCallable() { * *
{@code
    * try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   FeedName name = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]");
+   *   assetServiceClient.deleteFeed(name);
    * }
    * }
* @@ -517,7 +523,8 @@ public final void deleteFeed(FeedName name) { * *
{@code
    * try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   String name = "name3373707";
+   *   assetServiceClient.deleteFeed(name);
    * }
    * }
* diff --git a/test/integration/goldens/logging/ConfigServiceV2Client.java b/test/integration/goldens/logging/ConfigServiceV2Client.java index abb28b82cc..857ced6fd5 100644 --- a/test/integration/goldens/logging/ConfigServiceV2Client.java +++ b/test/integration/goldens/logging/ConfigServiceV2Client.java @@ -572,7 +572,8 @@ public final UnaryCallable listSinksCallabl * *
{@code
    * try (ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   LogSinkName sinkName = LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]");
+   *   LogSink response = configServiceV2Client.getSink(sinkName);
    * }
    * }
* @@ -600,7 +601,8 @@ public final LogSink getSink(LogSinkName sinkName) { * *
{@code
    * try (ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   String sinkName = "sink_name-1391757129";
+   *   LogSink response = configServiceV2Client.getSink(sinkName);
    * }
    * }
* @@ -657,7 +659,9 @@ public final UnaryCallable getSinkCallable() { * *
{@code
    * try (ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   BillingAccountName parent = BillingAccountName.of("[BILLING_ACCOUNT]");
+   *   LogSink sink = LogSink.newBuilder().build();
+   *   LogSink response = configServiceV2Client.createSink(parent, sink);
    * }
    * }
* @@ -689,7 +693,9 @@ public final LogSink createSink(BillingAccountName parent, LogSink sink) { * *
{@code
    * try (ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   FolderName parent = FolderName.of("[FOLDER]");
+   *   LogSink sink = LogSink.newBuilder().build();
+   *   LogSink response = configServiceV2Client.createSink(parent, sink);
    * }
    * }
* @@ -721,7 +727,9 @@ public final LogSink createSink(FolderName parent, LogSink sink) { * *
{@code
    * try (ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
+   *   LogSink sink = LogSink.newBuilder().build();
+   *   LogSink response = configServiceV2Client.createSink(parent, sink);
    * }
    * }
* @@ -753,7 +761,9 @@ public final LogSink createSink(OrganizationName parent, LogSink sink) { * *
{@code
    * try (ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   ProjectName parent = ProjectName.of("[PROJECT]");
+   *   LogSink sink = LogSink.newBuilder().build();
+   *   LogSink response = configServiceV2Client.createSink(parent, sink);
    * }
    * }
* @@ -785,7 +795,9 @@ public final LogSink createSink(ProjectName parent, LogSink sink) { * *
{@code
    * try (ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   String parent = "parent-995424086";
+   *   LogSink sink = LogSink.newBuilder().build();
+   *   LogSink response = configServiceV2Client.createSink(parent, sink);
    * }
    * }
* @@ -850,7 +862,9 @@ public final UnaryCallable createSinkCallable() { * *
{@code
    * try (ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   LogSinkName sinkName = LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]");
+   *   LogSink sink = LogSink.newBuilder().build();
+   *   LogSink response = configServiceV2Client.updateSink(sinkName, sink);
    * }
    * }
* @@ -886,7 +900,9 @@ public final LogSink updateSink(LogSinkName sinkName, LogSink sink) { * *
{@code
    * try (ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   String sinkName = "sink_name-1391757129";
+   *   LogSink sink = LogSink.newBuilder().build();
+   *   LogSink response = configServiceV2Client.updateSink(sinkName, sink);
    * }
    * }
* @@ -919,7 +935,10 @@ public final LogSink updateSink(String sinkName, LogSink sink) { * *
{@code
    * try (ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   LogSinkName sinkName = LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]");
+   *   LogSink sink = LogSink.newBuilder().build();
+   *   FieldMask updateMask = FieldMask.newBuilder().build();
+   *   LogSink response = configServiceV2Client.updateSink(sinkName, sink, updateMask);
    * }
    * }
* @@ -965,7 +984,10 @@ public final LogSink updateSink(LogSinkName sinkName, LogSink sink, FieldMask up * *
{@code
    * try (ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   String sinkName = "sink_name-1391757129";
+   *   LogSink sink = LogSink.newBuilder().build();
+   *   FieldMask updateMask = FieldMask.newBuilder().build();
+   *   LogSink response = configServiceV2Client.updateSink(sinkName, sink, updateMask);
    * }
    * }
* @@ -1045,7 +1067,8 @@ public final UnaryCallable updateSinkCallable() { * *
{@code
    * try (ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   LogSinkName sinkName = LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]");
+   *   configServiceV2Client.deleteSink(sinkName);
    * }
    * }
* @@ -1075,7 +1098,8 @@ public final void deleteSink(LogSinkName sinkName) { * *
{@code
    * try (ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   String sinkName = "sink_name-1391757129";
+   *   configServiceV2Client.deleteSink(sinkName);
    * }
    * }
* @@ -1295,7 +1319,8 @@ public final ListExclusionsPagedResponse listExclusions(ListExclusionsRequest re * *
{@code
    * try (ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   LogExclusionName name = LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]");
+   *   LogExclusion response = configServiceV2Client.getExclusion(name);
    * }
    * }
* @@ -1323,7 +1348,8 @@ public final LogExclusion getExclusion(LogExclusionName name) { * *
{@code
    * try (ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   String name = "name3373707";
+   *   LogExclusion response = configServiceV2Client.getExclusion(name);
    * }
    * }
* @@ -1378,7 +1404,9 @@ public final UnaryCallable getExclusionCallab * *
{@code
    * try (ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   BillingAccountName parent = BillingAccountName.of("[BILLING_ACCOUNT]");
+   *   LogExclusion exclusion = LogExclusion.newBuilder().build();
+   *   LogExclusion response = configServiceV2Client.createExclusion(parent, exclusion);
    * }
    * }
* @@ -1408,7 +1436,9 @@ public final LogExclusion createExclusion(BillingAccountName parent, LogExclusio * *
{@code
    * try (ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   FolderName parent = FolderName.of("[FOLDER]");
+   *   LogExclusion exclusion = LogExclusion.newBuilder().build();
+   *   LogExclusion response = configServiceV2Client.createExclusion(parent, exclusion);
    * }
    * }
* @@ -1438,7 +1468,9 @@ public final LogExclusion createExclusion(FolderName parent, LogExclusion exclus * *
{@code
    * try (ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
+   *   LogExclusion exclusion = LogExclusion.newBuilder().build();
+   *   LogExclusion response = configServiceV2Client.createExclusion(parent, exclusion);
    * }
    * }
* @@ -1468,7 +1500,9 @@ public final LogExclusion createExclusion(OrganizationName parent, LogExclusion * *
{@code
    * try (ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   ProjectName parent = ProjectName.of("[PROJECT]");
+   *   LogExclusion exclusion = LogExclusion.newBuilder().build();
+   *   LogExclusion response = configServiceV2Client.createExclusion(parent, exclusion);
    * }
    * }
* @@ -1498,7 +1532,9 @@ public final LogExclusion createExclusion(ProjectName parent, LogExclusion exclu * *
{@code
    * try (ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   String parent = "parent-995424086";
+   *   LogExclusion exclusion = LogExclusion.newBuilder().build();
+   *   LogExclusion response = configServiceV2Client.createExclusion(parent, exclusion);
    * }
    * }
* @@ -1555,7 +1591,10 @@ public final UnaryCallable createExclusion * *
{@code
    * try (ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   LogExclusionName name = LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]");
+   *   LogExclusion exclusion = LogExclusion.newBuilder().build();
+   *   FieldMask updateMask = FieldMask.newBuilder().build();
+   *   LogExclusion response = configServiceV2Client.updateExclusion(name, exclusion, updateMask);
    * }
    * }
* @@ -1594,7 +1633,10 @@ public final LogExclusion updateExclusion( * *
{@code
    * try (ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   String name = "name3373707";
+   *   LogExclusion exclusion = LogExclusion.newBuilder().build();
+   *   FieldMask updateMask = FieldMask.newBuilder().build();
+   *   LogExclusion response = configServiceV2Client.updateExclusion(name, exclusion, updateMask);
    * }
    * }
* @@ -1662,7 +1704,8 @@ public final UnaryCallable updateExclusion * *
{@code
    * try (ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   LogExclusionName name = LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]");
+   *   configServiceV2Client.deleteExclusion(name);
    * }
    * }
* @@ -1690,7 +1733,8 @@ public final void deleteExclusion(LogExclusionName name) { * *
{@code
    * try (ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   String name = "name3373707";
+   *   configServiceV2Client.deleteExclusion(name);
    * }
    * }
* diff --git a/test/integration/goldens/logging/LoggingServiceV2Client.java b/test/integration/goldens/logging/LoggingServiceV2Client.java index 8295abad48..ab78be2c23 100644 --- a/test/integration/goldens/logging/LoggingServiceV2Client.java +++ b/test/integration/goldens/logging/LoggingServiceV2Client.java @@ -157,7 +157,8 @@ public LoggingServiceV2Stub getStub() { * *
{@code
    * try (LoggingServiceV2Client loggingServiceV2Client = LoggingServiceV2Client.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   LogName logName = LogName.ofProjectLogName("[PROJECT]", "[LOG]");
+   *   loggingServiceV2Client.deleteLog(logName);
    * }
    * }
* @@ -187,7 +188,8 @@ public final void deleteLog(LogName logName) { * *
{@code
    * try (LoggingServiceV2Client loggingServiceV2Client = LoggingServiceV2Client.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   String logName = "log_name2013526694";
+   *   loggingServiceV2Client.deleteLog(logName);
    * }
    * }
* @@ -248,7 +250,12 @@ public final UnaryCallable deleteLogCallable() { * *
{@code
    * try (LoggingServiceV2Client loggingServiceV2Client = LoggingServiceV2Client.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   LogName logName = LogName.ofProjectLogName("[PROJECT]", "[LOG]");
+   *   MonitoredResource resource = MonitoredResource.newBuilder().build();
+   *   Map labels = new HashMap<>();
+   *   List entries = new ArrayList<>();
+   *   WriteLogEntriesResponse response =
+   *       loggingServiceV2Client.writeLogEntries(logName, resource, labels, entries);
    * }
    * }
* @@ -318,7 +325,12 @@ public final WriteLogEntriesResponse writeLogEntries( * *
{@code
    * try (LoggingServiceV2Client loggingServiceV2Client = LoggingServiceV2Client.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   String logName = "log_name2013526694";
+   *   MonitoredResource resource = MonitoredResource.newBuilder().build();
+   *   Map labels = new HashMap<>();
+   *   List entries = new ArrayList<>();
+   *   WriteLogEntriesResponse response =
+   *       loggingServiceV2Client.writeLogEntries(logName, resource, labels, entries);
    * }
    * }
* diff --git a/test/integration/goldens/logging/MetricsServiceV2Client.java b/test/integration/goldens/logging/MetricsServiceV2Client.java index c78c041cc6..5900ae89df 100644 --- a/test/integration/goldens/logging/MetricsServiceV2Client.java +++ b/test/integration/goldens/logging/MetricsServiceV2Client.java @@ -238,7 +238,8 @@ public final ListLogMetricsPagedResponse listLogMetrics(ListLogMetricsRequest re * *
{@code
    * try (MetricsServiceV2Client metricsServiceV2Client = MetricsServiceV2Client.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   LogMetricName metricName = LogMetricName.of("[PROJECT]", "[METRIC]");
+   *   LogMetric response = metricsServiceV2Client.getLogMetric(metricName);
    * }
    * }
* @@ -262,7 +263,8 @@ public final LogMetric getLogMetric(LogMetricName metricName) { * *
{@code
    * try (MetricsServiceV2Client metricsServiceV2Client = MetricsServiceV2Client.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   String metricName = "metric_name-1737602118";
+   *   LogMetric response = metricsServiceV2Client.getLogMetric(metricName);
    * }
    * }
* @@ -313,7 +315,9 @@ public final UnaryCallable getLogMetricCallable( * *
{@code
    * try (MetricsServiceV2Client metricsServiceV2Client = MetricsServiceV2Client.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   ProjectName parent = ProjectName.of("[PROJECT]");
+   *   LogMetric metric = LogMetric.newBuilder().build();
+   *   LogMetric response = metricsServiceV2Client.createLogMetric(parent, metric);
    * }
    * }
* @@ -341,7 +345,9 @@ public final LogMetric createLogMetric(ProjectName parent, LogMetric metric) { * *
{@code
    * try (MetricsServiceV2Client metricsServiceV2Client = MetricsServiceV2Client.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   String parent = "parent-995424086";
+   *   LogMetric metric = LogMetric.newBuilder().build();
+   *   LogMetric response = metricsServiceV2Client.createLogMetric(parent, metric);
    * }
    * }
* @@ -395,7 +401,9 @@ public final UnaryCallable createLogMetricCal * *
{@code
    * try (MetricsServiceV2Client metricsServiceV2Client = MetricsServiceV2Client.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   LogMetricName metricName = LogMetricName.of("[PROJECT]", "[METRIC]");
+   *   LogMetric metric = LogMetric.newBuilder().build();
+   *   LogMetric response = metricsServiceV2Client.updateLogMetric(metricName, metric);
    * }
    * }
* @@ -424,7 +432,9 @@ public final LogMetric updateLogMetric(LogMetricName metricName, LogMetric metri * *
{@code
    * try (MetricsServiceV2Client metricsServiceV2Client = MetricsServiceV2Client.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   String metricName = "metric_name-1737602118";
+   *   LogMetric metric = LogMetric.newBuilder().build();
+   *   LogMetric response = metricsServiceV2Client.updateLogMetric(metricName, metric);
    * }
    * }
* @@ -479,7 +489,8 @@ public final UnaryCallable updateLogMetricCal * *
{@code
    * try (MetricsServiceV2Client metricsServiceV2Client = MetricsServiceV2Client.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   LogMetricName metricName = LogMetricName.of("[PROJECT]", "[METRIC]");
+   *   metricsServiceV2Client.deleteLogMetric(metricName);
    * }
    * }
* @@ -503,7 +514,8 @@ public final void deleteLogMetric(LogMetricName metricName) { * *
{@code
    * try (MetricsServiceV2Client metricsServiceV2Client = MetricsServiceV2Client.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   String metricName = "metric_name-1737602118";
+   *   metricsServiceV2Client.deleteLogMetric(metricName);
    * }
    * }
* diff --git a/test/integration/goldens/redis/CloudRedisClient.java b/test/integration/goldens/redis/CloudRedisClient.java index 4dcb5689bf..7fb9c008a4 100644 --- a/test/integration/goldens/redis/CloudRedisClient.java +++ b/test/integration/goldens/redis/CloudRedisClient.java @@ -317,7 +317,8 @@ public final UnaryCallable listInst * *
{@code
    * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
+   *   Instance response = cloudRedisClient.getInstance(name);
    * }
    * }
* @@ -342,7 +343,8 @@ public final Instance getInstance(InstanceName name) { * *
{@code
    * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   // Note: Not implemented yet, placeholder for pure unary rpc method sample code.
+   *   String name = "name3373707";
+   *   Instance response = cloudRedisClient.getInstance(name);
    * }
    * }
*