diff --git a/BUILD.bazel b/BUILD.bazel index 37fd12d8b5..7edfa6b8ac 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -53,11 +53,15 @@ java_binary( srcs = [ "//src/test/java/com/google/api/generator/gapic/dummy:dummy_files", "//src/test/java/com/google/api/generator/engine:engine_files", + "//src/test/java/com/google/api/generator/gapic/composer:composer_files", "//src/test/java/com/google/api/generator/test/framework:framework_files", ], data = [ "//src/test/java/com/google/api/generator/gapic/dummy/goldens:goldens_files", "//src/test/java/com/google/api/generator/engine/goldens:goldens_files", + "//src/test/java/com/google/api/generator/gapic/composer/goldens:goldens_files", + "//src/test/java/com/google/api/generator/gapic/testdata:gapic_config_files", + "//src/test/java/com/google/api/generator/gapic/testdata:service_config_files", ], jvm_flags = ["-Xmx512m"], main_class = "com.google.api.generator.test.framework.SingleJUnitTestRunner", @@ -67,7 +71,19 @@ java_binary( "//src/main/java/com/google/api/generator/engine/writer", "//src/test/java/com/google/api/generator/test/framework", "//src/main/java/com/google/api/generator/engine/lexicon", + "//src/main/java/com/google/api/generator/gapic/composer", + "//src/main/java/com/google/api/generator/gapic/model", + "//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", + "//src/test/java/com/google/api/generator/gapic/composer:common_resources_java_proto", "@com_google_guava_guava//:com_google_guava_guava", + "@com_google_api_gax_java//gax", + "@com_google_googleapis//google/logging/v2:logging_java_proto", + "@com_google_googleapis//google/pubsub/v1:pubsub_java_proto", + "@com_google_googleapis//google/rpc:rpc_java_proto", + "@com_google_protobuf//:protobuf_java", + "//:service_config_java_proto", "@com_google_truth_truth//jar", "@io_github_java_diff_utils//jar", "@junit_junit//jar", diff --git a/rules_bazel/java/java_diff_test.bzl b/rules_bazel/java/java_diff_test.bzl index 08ce5ebf5f..41ba278117 100644 --- a/rules_bazel/java/java_diff_test.bzl +++ b/rules_bazel/java/java_diff_test.bzl @@ -39,7 +39,7 @@ junit_output_zip = rule( ), }, outputs = { - "output": "%{name}%.zip", + "output": "%{name}.zip", }, implementation = _junit_output_impl, ) 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 1e86c323b6..6e02d520d4 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 @@ -1,3 +1,5 @@ +load("//:rules_bazel/java/java_diff_test.bzl", "golden_update") + package(default_visibility = ["//visibility:public"]) TESTS = [ @@ -18,6 +20,19 @@ TESTS = [ "ServiceStubClassComposerTest", ] +UPDATE_GOLDENS_TESTS = [ + "BatchingDescriptorComposerTest", + "ComposerTest", + "GrpcServiceCallableFactoryClassComposerTest", + "GrpcServiceStubClassComposerTest", + "MockServiceClassComposerTest", + "MockServiceImplClassComposerTest", + "ResourceNameHelperClassComposerTest", + "ServiceSettingsClassComposerTest", + "ServiceStubSettingsClassComposerTest", + "ServiceStubClassComposerTest", +] + filegroup( name = "composer_files", srcs = glob(["*.java"]), @@ -69,3 +84,20 @@ java_proto_library( "@junit_junit//jar", ], ) for test_name in TESTS] + + + +TEST_CLASS_DIR = "com.google.api.generator.gapic.composer." +# Run `bazel run src/test/java/com/google/api/generator/gapic/composer:testTargetName_update` +# to update goldens as expected generated code. +# `ServiceClient*` tests are not supported now since they are still in active development. + +[golden_update( + name = test_name + "_update", + srcs = [ + ":composer_files", + "//src/test/java/com/google/api/generator/gapic/testdata:gapic_config_files", + "//src/test/java/com/google/api/generator/gapic/testdata:service_config_files", + ], + test_class_name = TEST_CLASS_DIR + test_name, +) for test_name in UPDATE_GOLDENS_TESTS] diff --git a/src/test/java/com/google/api/generator/gapic/composer/BatchingDescriptorComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/BatchingDescriptorComposerTest.java index a556b191f0..8802489354 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/BatchingDescriptorComposerTest.java +++ b/src/test/java/com/google/api/generator/gapic/composer/BatchingDescriptorComposerTest.java @@ -29,6 +29,7 @@ import com.google.api.generator.gapic.protoparser.Parser; import com.google.api.generator.gapic.protoparser.ServiceConfigParser; import com.google.api.generator.test.framework.Assert; +import com.google.api.generator.test.framework.Utils; import com.google.logging.v2.LogEntryProto; import com.google.logging.v2.LoggingConfigProto; import com.google.logging.v2.LoggingMetricsProto; @@ -99,6 +100,8 @@ public void batchingDescriptor_hasSubresponseField() { method, batchingSetting, messageTypes); batchingDescriptorExpr.accept(writerVisitor); + Utils.saveCodegenToFile( + this.getClass(), "BatchingDescriptorComposerTestSubresponse.golden", writerVisitor.write()); Path goldenFilePath = Paths.get( ComposerConstants.GOLDENFILES_DIRECTORY, @@ -155,6 +158,10 @@ public void batchingDescriptor_noSubresponseField() { method, batchingSetting, messageTypes); batchingDescriptorExpr.accept(writerVisitor); + Utils.saveCodegenToFile( + this.getClass(), + "BatchingDescriptorComposerTestNoSubresponse.golden", + writerVisitor.write()); Path goldenFilePath = Paths.get( ComposerConstants.GOLDENFILES_DIRECTORY, diff --git a/src/test/java/com/google/api/generator/gapic/composer/ComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/ComposerTest.java index 3f2980bede..95270eecef 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/ComposerTest.java +++ b/src/test/java/com/google/api/generator/gapic/composer/ComposerTest.java @@ -20,6 +20,7 @@ import com.google.api.generator.gapic.model.GapicClass; import com.google.api.generator.gapic.model.GapicClass.Kind; 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 java.util.Arrays; @@ -39,6 +40,7 @@ public void gapicClass_addApacheLicense() { Composer.addApacheLicense(Arrays.asList(GapicClass.create(Kind.TEST, classDef))); JavaWriterVisitor visitor = new JavaWriterVisitor(); gapicClassWithHeaderList.get(0).classDefinition().accept(visitor); + Utils.saveCodegenToFile(this.getClass(), "ComposerTest.golden", visitor.write()); Path goldenFilePath = Paths.get(ComposerConstants.GOLDENFILES_DIRECTORY, "ComposerTest.golden"); Assert.assertCodeEquals(goldenFilePath, visitor.write()); } diff --git a/src/test/java/com/google/api/generator/gapic/composer/GrpcServiceCallableFactoryClassComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/GrpcServiceCallableFactoryClassComposerTest.java index 32414a301b..4437b3a166 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/GrpcServiceCallableFactoryClassComposerTest.java +++ b/src/test/java/com/google/api/generator/gapic/composer/GrpcServiceCallableFactoryClassComposerTest.java @@ -23,6 +23,7 @@ import com.google.api.generator.gapic.model.Service; import com.google.api.generator.gapic.protoparser.Parser; import com.google.api.generator.test.framework.Assert; +import com.google.api.generator.test.framework.Utils; import com.google.protobuf.Descriptors.FileDescriptor; import com.google.protobuf.Descriptors.ServiceDescriptor; import com.google.showcase.v1beta1.EchoOuterClass; @@ -60,6 +61,7 @@ public void generateServiceClasses() { JavaWriterVisitor visitor = new JavaWriterVisitor(); clazz.classDefinition().accept(visitor); + Utils.saveCodegenToFile(this.getClass(), "GrpcEchoCallableFactory.golden", visitor.write()); Path goldenFilePath = Paths.get(ComposerConstants.GOLDENFILES_DIRECTORY, "GrpcEchoCallableFactory.golden"); Assert.assertCodeEquals(goldenFilePath, visitor.write()); diff --git a/src/test/java/com/google/api/generator/gapic/composer/GrpcServiceStubClassComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/GrpcServiceStubClassComposerTest.java index 53ea2c413e..e3f63dcaa8 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/GrpcServiceStubClassComposerTest.java +++ b/src/test/java/com/google/api/generator/gapic/composer/GrpcServiceStubClassComposerTest.java @@ -23,6 +23,7 @@ import com.google.api.generator.gapic.model.Service; import com.google.api.generator.gapic.protoparser.Parser; import com.google.api.generator.test.framework.Assert; +import com.google.api.generator.test.framework.Utils; import com.google.protobuf.Descriptors.FileDescriptor; import com.google.protobuf.Descriptors.ServiceDescriptor; import com.google.showcase.v1beta1.EchoOuterClass; @@ -59,6 +60,7 @@ public void generateServiceClasses() { JavaWriterVisitor visitor = new JavaWriterVisitor(); clazz.classDefinition().accept(visitor); + Utils.saveCodegenToFile(this.getClass(), "GrpcEchoStub.golden", visitor.write()); Path goldenFilePath = Paths.get(ComposerConstants.GOLDENFILES_DIRECTORY, "GrpcEchoStub.golden"); Assert.assertCodeEquals(goldenFilePath, visitor.write()); } diff --git a/src/test/java/com/google/api/generator/gapic/composer/MockServiceClassComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/MockServiceClassComposerTest.java index 5303ab557a..aa4e19b271 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/MockServiceClassComposerTest.java +++ b/src/test/java/com/google/api/generator/gapic/composer/MockServiceClassComposerTest.java @@ -23,6 +23,7 @@ import com.google.api.generator.gapic.model.Service; import com.google.api.generator.gapic.protoparser.Parser; import com.google.api.generator.test.framework.Assert; +import com.google.api.generator.test.framework.Utils; import com.google.protobuf.Descriptors.FileDescriptor; import com.google.protobuf.Descriptors.ServiceDescriptor; import com.google.showcase.v1beta1.EchoOuterClass; @@ -59,6 +60,7 @@ public void generateServiceClasses() { JavaWriterVisitor visitor = new JavaWriterVisitor(); clazz.classDefinition().accept(visitor); + Utils.saveCodegenToFile(this.getClass(), "MockEcho.golden", visitor.write()); Path goldenFilePath = Paths.get(ComposerConstants.GOLDENFILES_DIRECTORY, "MockEcho.golden"); Assert.assertCodeEquals(goldenFilePath, visitor.write()); } diff --git a/src/test/java/com/google/api/generator/gapic/composer/MockServiceImplClassComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/MockServiceImplClassComposerTest.java index cd2fb25b2e..6e0295adb2 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/MockServiceImplClassComposerTest.java +++ b/src/test/java/com/google/api/generator/gapic/composer/MockServiceImplClassComposerTest.java @@ -23,6 +23,7 @@ import com.google.api.generator.gapic.model.Service; import com.google.api.generator.gapic.protoparser.Parser; import com.google.api.generator.test.framework.Assert; +import com.google.api.generator.test.framework.Utils; import com.google.protobuf.Descriptors.FileDescriptor; import com.google.protobuf.Descriptors.ServiceDescriptor; import com.google.showcase.v1beta1.EchoOuterClass; @@ -60,6 +61,7 @@ public void generateServiceClasses() { JavaWriterVisitor visitor = new JavaWriterVisitor(); clazz.classDefinition().accept(visitor); + Utils.saveCodegenToFile(this.getClass(), "MockEchoImpl.golden", visitor.write()); Path goldenFilePath = Paths.get(ComposerConstants.GOLDENFILES_DIRECTORY, "MockEchoImpl.golden"); Assert.assertCodeEquals(goldenFilePath, visitor.write()); } diff --git a/src/test/java/com/google/api/generator/gapic/composer/ResourceNameHelperClassComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/ResourceNameHelperClassComposerTest.java index 1a8b3b954d..39b76b2d85 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/ResourceNameHelperClassComposerTest.java +++ b/src/test/java/com/google/api/generator/gapic/composer/ResourceNameHelperClassComposerTest.java @@ -24,6 +24,7 @@ import com.google.api.generator.gapic.model.Service; import com.google.api.generator.gapic.protoparser.Parser; import com.google.api.generator.test.framework.Assert; +import com.google.api.generator.test.framework.Utils; import com.google.protobuf.Descriptors.FileDescriptor; import com.google.protobuf.Descriptors.ServiceDescriptor; import com.google.showcase.v1beta1.EchoOuterClass; @@ -97,6 +98,7 @@ public void generateResourceNameClass_echoFoobarMultiplePatterns() { JavaWriterVisitor visitor = new JavaWriterVisitor(); clazz.classDefinition().accept(visitor); + Utils.saveCodegenToFile(this.getClass(), "FoobarName.golden", visitor.write()); Path goldenFilePath = Paths.get(ComposerConstants.GOLDENFILES_DIRECTORY, "FoobarName.golden"); Assert.assertCodeEquals(goldenFilePath, visitor.write()); } @@ -122,6 +124,7 @@ public void generateResourceNameClass_testingSessionOnePattern() { JavaWriterVisitor visitor = new JavaWriterVisitor(); clazz.classDefinition().accept(visitor); + Utils.saveCodegenToFile(this.getClass(), "SessionName.golden", visitor.write()); Path goldenFilePath = Paths.get(ComposerConstants.GOLDENFILES_DIRECTORY, "SessionName.golden"); Assert.assertCodeEquals(goldenFilePath, visitor.write()); } diff --git a/src/test/java/com/google/api/generator/gapic/composer/ServiceSettingsClassComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/ServiceSettingsClassComposerTest.java index 0ba1c09956..17aa47ed38 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/ServiceSettingsClassComposerTest.java +++ b/src/test/java/com/google/api/generator/gapic/composer/ServiceSettingsClassComposerTest.java @@ -23,6 +23,7 @@ import com.google.api.generator.gapic.model.Service; import com.google.api.generator.gapic.protoparser.Parser; import com.google.api.generator.test.framework.Assert; +import com.google.api.generator.test.framework.Utils; import com.google.protobuf.Descriptors.FileDescriptor; import com.google.protobuf.Descriptors.ServiceDescriptor; import com.google.showcase.v1beta1.EchoOuterClass; @@ -60,6 +61,7 @@ public void generateServiceClasses() { JavaWriterVisitor visitor = new JavaWriterVisitor(); clazz.classDefinition().accept(visitor); + Utils.saveCodegenToFile(this.getClass(), "EchoSettings.golden", visitor.write()); Path goldenFilePath = Paths.get(ComposerConstants.GOLDENFILES_DIRECTORY, "EchoSettings.golden"); Assert.assertCodeEquals(goldenFilePath, visitor.write()); } diff --git a/src/test/java/com/google/api/generator/gapic/composer/ServiceStubClassComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/ServiceStubClassComposerTest.java index e282bec281..87417b7c6e 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/ServiceStubClassComposerTest.java +++ b/src/test/java/com/google/api/generator/gapic/composer/ServiceStubClassComposerTest.java @@ -23,6 +23,7 @@ import com.google.api.generator.gapic.model.Service; import com.google.api.generator.gapic.protoparser.Parser; import com.google.api.generator.test.framework.Assert; +import com.google.api.generator.test.framework.Utils; import com.google.protobuf.Descriptors.FileDescriptor; import com.google.protobuf.Descriptors.ServiceDescriptor; import com.google.showcase.v1beta1.EchoOuterClass; @@ -59,6 +60,7 @@ public void generateServiceClasses() { JavaWriterVisitor visitor = new JavaWriterVisitor(); clazz.classDefinition().accept(visitor); + Utils.saveCodegenToFile(this.getClass(), "EchoStub.golden", visitor.write()); Path goldenFilePath = Paths.get(ComposerConstants.GOLDENFILES_DIRECTORY, "EchoStub.golden"); Assert.assertCodeEquals(goldenFilePath, visitor.write()); } diff --git a/src/test/java/com/google/api/generator/gapic/composer/ServiceStubSettingsClassComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/ServiceStubSettingsClassComposerTest.java index da0308a349..21048a3189 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/ServiceStubSettingsClassComposerTest.java +++ b/src/test/java/com/google/api/generator/gapic/composer/ServiceStubSettingsClassComposerTest.java @@ -28,6 +28,7 @@ import com.google.api.generator.gapic.protoparser.Parser; import com.google.api.generator.gapic.protoparser.ServiceConfigParser; import com.google.api.generator.test.framework.Assert; +import com.google.api.generator.test.framework.Utils; import com.google.logging.v2.LogEntryProto; import com.google.logging.v2.LoggingConfigProto; import com.google.logging.v2.LoggingMetricsProto; @@ -93,6 +94,8 @@ public void generateServiceStubSettingsClasses_batchingWithEmptyResponses() thro JavaWriterVisitor visitor = new JavaWriterVisitor(); clazz.classDefinition().accept(visitor); + Utils.saveCodegenToFile( + this.getClass(), "LoggingServiceV2StubSettings.golden", visitor.write()); Path goldenFilePath = Paths.get(ComposerConstants.GOLDENFILES_DIRECTORY, "LoggingServiceV2StubSettings.golden"); Assert.assertCodeEquals(goldenFilePath, visitor.write()); @@ -135,6 +138,7 @@ public void generateServiceStubSettingsClasses_batchingWithNonemptyResponses() JavaWriterVisitor visitor = new JavaWriterVisitor(); clazz.classDefinition().accept(visitor); + Utils.saveCodegenToFile(this.getClass(), "PublisherStubSettings.golden", visitor.write()); Path goldenFilePath = Paths.get(ComposerConstants.GOLDENFILES_DIRECTORY, "PublisherStubSettings.golden"); Assert.assertCodeEquals(goldenFilePath, visitor.write()); @@ -165,6 +169,7 @@ public void generateServiceStubSettingsClasses_basic() throws IOException { JavaWriterVisitor visitor = new JavaWriterVisitor(); clazz.classDefinition().accept(visitor); + Utils.saveCodegenToFile(this.getClass(), "EchoStubSettings.golden", visitor.write()); Path goldenFilePath = Paths.get(ComposerConstants.GOLDENFILES_DIRECTORY, "EchoStubSettings.golden"); Assert.assertCodeEquals(goldenFilePath, visitor.write()); diff --git a/src/test/java/com/google/api/generator/gapic/composer/goldens/BatchingDescriptorComposerTestSubresponse.golden b/src/test/java/com/google/api/generator/gapic/composer/goldens/BatchingDescriptorComposerTestSubresponse.golden index 1ebfca8696..a322c69aec 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/goldens/BatchingDescriptorComposerTestSubresponse.golden +++ b/src/test/java/com/google/api/generator/gapic/composer/goldens/BatchingDescriptorComposerTestSubresponse.golden @@ -56,4 +56,4 @@ public long countBytes(PublishRequest request) { return request.getSerializedSize(); } -} +} \ No newline at end of file