-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add add autogenerated javadoc sample for selecting REST transpo…
…rt over gRPC (#983) This is for grpc+rest clients. Also add proper grpc+rest unit tests which were missing.
- Loading branch information
1 parent
9e863f8
commit 051713d
Showing
25 changed files
with
4,577 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
src/test/java/com/google/api/generator/gapic/composer/grpcrest/GrpcRestTestProtoLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright 2022 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.grpcrest; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import com.google.api.generator.gapic.composer.common.TestProtoLoader; | ||
import com.google.api.generator.gapic.model.GapicContext; | ||
import com.google.api.generator.gapic.model.GapicServiceConfig; | ||
import com.google.api.generator.gapic.model.Message; | ||
import com.google.api.generator.gapic.model.ResourceName; | ||
import com.google.api.generator.gapic.model.Service; | ||
import com.google.api.generator.gapic.model.Transport; | ||
import com.google.api.generator.gapic.protoparser.Parser; | ||
import com.google.api.generator.gapic.protoparser.ServiceConfigParser; | ||
import com.google.longrunning.OperationsProto; | ||
import com.google.protobuf.Descriptors.FileDescriptor; | ||
import com.google.protobuf.Descriptors.ServiceDescriptor; | ||
import com.google.showcase.grpcrest.v1beta1.EchoGrpcrest; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
public class GrpcRestTestProtoLoader extends TestProtoLoader { | ||
private static final GrpcRestTestProtoLoader INSTANCE = new GrpcRestTestProtoLoader(); | ||
|
||
protected GrpcRestTestProtoLoader() { | ||
super(Transport.GRPC_REST, "src/test/resources/"); | ||
} | ||
|
||
public static GrpcRestTestProtoLoader instance() { | ||
return INSTANCE; | ||
} | ||
|
||
@Override | ||
public GapicContext parseShowcaseEcho() { | ||
FileDescriptor echoFileDescriptor = EchoGrpcrest.getDescriptor(); | ||
|
||
ServiceDescriptor echoServiceDescriptor = echoFileDescriptor.getServices().get(0); | ||
assertEquals("Echo", echoServiceDescriptor.getName()); | ||
|
||
Map<String, Message> messageTypes = Parser.parseMessages(echoFileDescriptor); | ||
Map<String, Message> operationMessageTypes = | ||
Parser.parseMessages(OperationsProto.getDescriptor()); | ||
messageTypes.putAll(operationMessageTypes); | ||
Map<String, ResourceName> resourceNames = Parser.parseResourceNames(echoFileDescriptor); | ||
Set<ResourceName> outputResourceNames = new HashSet<>(); | ||
List<Service> services = | ||
Parser.parseService( | ||
echoFileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames); | ||
|
||
String jsonFilename = "showcase_grpc_service_config.json"; | ||
Path jsonPath = Paths.get(getTestFilesDirectory(), jsonFilename); | ||
Optional<GapicServiceConfig> configOpt = ServiceConfigParser.parse(jsonPath.toString()); | ||
assertTrue(configOpt.isPresent()); | ||
GapicServiceConfig config = configOpt.get(); | ||
|
||
return GapicContext.builder() | ||
.setMessages(messageTypes) | ||
.setResourceNames(resourceNames) | ||
.setServices(services) | ||
.setServiceConfig(config) | ||
.setHelperResourceNames(outputResourceNames) | ||
.setTransport(getTransport()) | ||
.build(); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...le/api/generator/gapic/composer/grpcrest/GrpcServiceCallableFactoryClassComposerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2022 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.grpcrest; | ||
|
||
import com.google.api.generator.engine.writer.JavaWriterVisitor; | ||
import com.google.api.generator.gapic.composer.grpc.GrpcServiceCallableFactoryClassComposer; | ||
import com.google.api.generator.gapic.model.GapicClass; | ||
import com.google.api.generator.gapic.model.GapicContext; | ||
import com.google.api.generator.gapic.model.Service; | ||
import com.google.api.generator.test.framework.Assert; | ||
import com.google.api.generator.test.framework.Utils; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import org.junit.Test; | ||
|
||
public class GrpcServiceCallableFactoryClassComposerTest { | ||
@Test | ||
public void generateServiceClasses() { | ||
GapicContext context = GrpcRestTestProtoLoader.instance().parseShowcaseEcho(); | ||
Service echoProtoService = context.services().get(0); | ||
GapicClass clazz = | ||
GrpcServiceCallableFactoryClassComposer.instance().generate(context, echoProtoService); | ||
|
||
JavaWriterVisitor visitor = new JavaWriterVisitor(); | ||
clazz.classDefinition().accept(visitor); | ||
Utils.saveCodegenToFile(this.getClass(), "GrpcEchoCallableFactory.golden", visitor.write()); | ||
Path goldenFilePath = | ||
Paths.get(Utils.getGoldenDir(this.getClass()), "GrpcEchoCallableFactory.golden"); | ||
Assert.assertCodeEquals(goldenFilePath, visitor.write()); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...va/com/google/api/generator/gapic/composer/grpcrest/GrpcServiceStubClassComposerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2022 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.grpcrest; | ||
|
||
import com.google.api.generator.engine.writer.JavaWriterVisitor; | ||
import com.google.api.generator.gapic.composer.grpc.GrpcServiceStubClassComposer; | ||
import com.google.api.generator.gapic.model.GapicClass; | ||
import com.google.api.generator.gapic.model.GapicContext; | ||
import com.google.api.generator.gapic.model.Service; | ||
import com.google.api.generator.test.framework.Assert; | ||
import com.google.api.generator.test.framework.Utils; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import org.junit.Test; | ||
|
||
public class GrpcServiceStubClassComposerTest { | ||
@Test | ||
public void generateServiceClasses() { | ||
GapicContext context = GrpcRestTestProtoLoader.instance().parseShowcaseEcho(); | ||
Service echoProtoService = context.services().get(0); | ||
GapicClass clazz = GrpcServiceStubClassComposer.instance().generate(context, echoProtoService); | ||
|
||
JavaWriterVisitor visitor = new JavaWriterVisitor(); | ||
clazz.classDefinition().accept(visitor); | ||
Utils.saveCodegenToFile(this.getClass(), "GrpcEchoStub.golden", visitor.write()); | ||
Path goldenFilePath = Paths.get(Utils.getGoldenDir(this.getClass()), "GrpcEchoStub.golden"); | ||
Assert.assertCodeEquals(goldenFilePath, visitor.write()); | ||
} | ||
} |
Oops, something went wrong.