Skip to content

Commit

Permalink
fix merging mistake and lint.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhumin8 committed Oct 29, 2024
1 parent 4a75bfd commit 1f5be4b
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ void generateGrpcServiceStubClass_autopopulateField() {
Assert.assertEmptySamples(clazz.samples());
}

@Test
void generateGrpcServiceStubClass_callableNameType() {
GapicContext context = GrpcTestProtoLoader.instance().parseCallabeNameType();
Service service = context.services().get(0);
GapicClass clazz = GrpcServiceStubClassComposer.instance().generate(context, service);
Assert.assertGoldenClass(this.getClass(), clazz, "GrpcCallableNameTypeStub.golden");
Assert.assertEmptySamples(clazz.samples());
}

@Test
void generateGrpcServiceStubClass_selectiveGeneration() {
GapicContext context = GrpcTestProtoLoader.instance().parseSelectiveGenerationTesting();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.when;

import com.google.api.*;
import com.google.api.ClientLibrarySettings;
import com.google.api.CommonLanguageSettings;
import com.google.api.CppSettings;
import com.google.api.FieldInfo.Format;
import com.google.api.MethodSettings;
import com.google.api.Publishing;
import com.google.api.SelectiveGapicGeneration;
import com.google.api.Service;
import com.google.api.generator.engine.ast.ConcreteReference;
import com.google.api.generator.engine.ast.Reference;
import com.google.api.generator.engine.ast.TypeNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@
import com.google.showcase.v1beta1.IdentityOuterClass;
import com.google.showcase.v1beta1.MessagingOuterClass;
import com.google.showcase.v1beta1.TestingOuterClass;
import com.google.test.callablenamingtype.CallableNameType;
import com.google.testdata.v1.DeprecatedServiceOuterClass;
import com.google.testgapic.v1beta1.NestedMessageProto;
import com.google.types.testing.TypesTestingProto;
import google.cloud.CommonResources;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -501,6 +503,42 @@ public GapicContext parseLogging() {
.build();
}

public GapicContext parseCallabeNameType() {
FileDescriptor serviceFileDescriptor = CallableNameType.getDescriptor();
ServiceDescriptor serviceDescriptor = serviceFileDescriptor.getServices().get(0);
assertEquals(serviceDescriptor.getName(), "CallableNameTypeService");

List<FileDescriptor> protoFiles = Collections.singletonList(serviceFileDescriptor);

Map<String, ResourceName> resourceNames = new HashMap<>();
Map<String, Message> messageTypes = new HashMap<>();
for (FileDescriptor fileDescriptor : protoFiles) {
resourceNames.putAll(Parser.parseResourceNames(fileDescriptor));
messageTypes.putAll(Parser.parseMessages(fileDescriptor));
}

// Additional resource names.
FileDescriptor commonResourcesFileDescriptor = CommonResources.getDescriptor();
resourceNames.putAll(Parser.parseResourceNames(commonResourcesFileDescriptor));

Set<ResourceName> outputResourceNames = new HashSet<>();
List<Service> services =
Parser.parseService(
serviceFileDescriptor,
messageTypes,
resourceNames,
Optional.empty(),
outputResourceNames);

return GapicContext.builder()
.setMessages(messageTypes)
.setResourceNames(resourceNames)
.setServices(services)
.setHelperResourceNames(outputResourceNames)
.setTransport(transport)
.build();
}

public String getTestFilesDirectory() {
return testFilesDirectory;
}
Expand Down
16 changes: 5 additions & 11 deletions gapic-generator-java/src/test/proto/selective_api_generation.proto
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ option (google.api.resource_definition) = {
// This proto is used to test selective api generation
// covered scenarios:
// - A service with several rpcs, part of them should be generated
// - A service with several rpcs, non of them should be generated
// - A service with several rpcs, none of them should be generated
// This proto should be tested side-by-side with yaml file:
// - selective_api_generation_v1beta1.yaml

Expand All @@ -51,10 +51,7 @@ service EchoServiceShouldGeneratePartial {
post: "/v1beta1/echo:echo"
body: "*"
};
option (google.api.method_signature) = "content";
option (google.api.method_signature) = "error";
option (google.api.method_signature) = "name";
option (google.api.method_signature) = "parent";
option (google.api.method_signature) = "";
}

Expand All @@ -71,13 +68,10 @@ service EchoServiceShouldGeneratePartial {
}

service EchoServiceShouldGenerateNone {
// This service is meant to only run locally on the port 7469 (keypad digits
// for "show").
option (google.api.default_host) = "localhost:7469";
option (google.api.oauth_scopes) =
"https://www.googleapis.com/auth/cloud-platform";

// This method simply echos the request. This method is showcases unary rpcs.
rpc Echo(EchoRequest) returns (EchoResponse) {
option (google.api.method_signature) = "content";
}
Expand Down Expand Up @@ -110,7 +104,7 @@ message Foobarbaz {
string info = 2;
}

// The request message used both RPCs in inclusion list and not.
// RPCs in inclusion list and not in the list both relies on this request message.
message EchoRequest {
string name = 5 [
(google.api.resource_reference).type = "showcase.googleapis.com/Foobar",
Expand All @@ -134,10 +128,10 @@ message EchoRequest {
Foobar foobar = 4;
}

// The request message used for ShouldNotGenerateChat method.
// To demonstrate that if ShouldNotGenerateChat is not included in generation,
// This request message is used by AnExcludedMethod rpc.
// To demonstrate that if AnExcludedMethod is not included in generation,
// then the resource name Foobarbaz, which is only used by this method,
// should also not be generated.
// should not be generated.
message EchoRequestWithFoobarbaz {
string name = 5 [
(google.api.resource_reference).type = "showcase.googleapis.com/Foobarbaz",
Expand Down

0 comments on commit 1f5be4b

Please sign in to comment.