diff --git a/.bazelrc b/.bazelrc index 48b81165fe..4a1006ad99 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,3 +1,4 @@ startup --batch +build --show_timestamps build --protocopt=--experimental_allow_proto3_optional diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index e99dba0136..c233d19ee4 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -10,7 +10,7 @@ jobs: strategy: matrix: - java: [8, 11] + java: [ 8, 11 ] steps: - uses: actions/checkout@v2 - uses: actions/setup-java@v3 diff --git a/.gitignore b/.gitignore index 913a2a8e6e..3b7b1a4ed2 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ target/ # IDE .idea .ijwb +*.iml # Vim. *.sw* diff --git a/BUILD.bazel b/BUILD.bazel index e8e17887a3..01165253f3 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -183,6 +183,7 @@ test_suite(name = "units", tags = ["small"]) GOLDEN_UPDATING_UNIT_TESTS = [ "com.google.api.generator.engine.JavaCodeGeneratorTest", "com.google.api.generator.gapic.composer.ComposerTest", + "com.google.api.generator.gapic.composer.ClientLibraryPackageInfoComposerTest", "com.google.api.generator.gapic.composer.common.BatchingDescriptorComposerTest", "com.google.api.generator.gapic.composer.grpc.GrpcServiceCallableFactoryClassComposerTest", "com.google.api.generator.gapic.composer.grpc.GrpcServiceStubClassComposerTest", diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c3772c261..5a951b4113 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## [2.11.0](https://github.com/googleapis/gapic-generator-java/compare/v2.10.3...v2.11.0) (2022-11-30) + + +### Features + +* **ast:** Array expressions ([#1080](https://github.com/googleapis/gapic-generator-java/issues/1080)) ([bd9532c](https://github.com/googleapis/gapic-generator-java/commit/bd9532c6663f2e8f9d9978cd0a3cffde821960ec)) + + +### Bug Fixes + +* **ast:** Add import generation for annotations on VariableExpr ([#1076](https://github.com/googleapis/gapic-generator-java/issues/1076)) ([f5d5524](https://github.com/googleapis/gapic-generator-java/commit/f5d5524e626f26ef53d4ae6c02118ef70ace205a)) +* **deps:** Update dependency com.google.cloud:google-cloud-shared-dependencies to v3.0.6 ([#1088](https://github.com/googleapis/gapic-generator-java/issues/1088)) ([0e75338](https://github.com/googleapis/gapic-generator-java/commit/0e75338dcb083c4cccd35d8682ba9cbe4e314ef8)) +* Support testing nested argument method signatures and 'double' field assertions ([#1094](https://github.com/googleapis/gapic-generator-java/issues/1094)) ([4bf419f](https://github.com/googleapis/gapic-generator-java/commit/4bf419f764e2ecfdac9caf03968f40a8cd564655)) + ## [2.10.3](https://github.com/googleapis/gapic-generator-java/compare/v2.10.2...v2.10.3) (2022-11-01) diff --git a/WORKSPACE b/WORKSPACE index 32f311e27e..e73de98dff 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -52,13 +52,15 @@ load("@com_google_api_gax_java//:repositories.bzl", "com_google_api_gax_java_rep com_google_api_gax_java_repositories() +_googleapis_commit = "44d6bef0ca6db8bba3fb324c8186e694bcc4829c" + http_archive( - name = "com_google_googleapis", - strip_prefix = "googleapis-44d6bef0ca6db8bba3fb324c8186e694bcc4829c", - urls = [ - "https://github.com/googleapis/googleapis/archive/44d6bef0ca6db8bba3fb324c8186e694bcc4829c.zip", - ], - ) + name = "com_google_googleapis", + strip_prefix = "googleapis-%s" % _googleapis_commit, + urls = [ + "https://github.com/googleapis/googleapis/archive/%s.zip" % _googleapis_commit, + ], +) load("//:repositories.bzl", "gapic_generator_java_repositories") @@ -66,17 +68,17 @@ gapic_generator_java_repositories() # protobuf RULES_JVM_EXTERNAL_TAG = "4.2" + RULES_JVM_EXTERNAL_SHA = "cd1a77b7b02e8e008439ca76fd34f5b07aecb8c752961f9640dea15e9e5ba1ca" http_archive( name = "rules_jvm_external", - strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG, sha256 = RULES_JVM_EXTERNAL_SHA, + strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG, url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG, ) load("@com_google_protobuf//:protobuf_deps.bzl", "PROTOBUF_MAVEN_ARTIFACTS", "protobuf_deps") - load("@rules_jvm_external//:defs.bzl", "maven_install") maven_install( @@ -112,8 +114,22 @@ load("@io_grpc_grpc_java//:repositories.bzl", "grpc_java_repositories") grpc_java_repositories() +_disco_to_proto3_converter_commit = "ce8d8732120cdfb5bf4847c3238b5be8acde87e3" + http_archive( name = "com_google_disco_to_proto3_converter", - strip_prefix = "disco-to-proto3-converter-ce8d8732120cdfb5bf4847c3238b5be8acde87e3", - urls = ["https://github.com/googleapis/disco-to-proto3-converter/archive/ce8d8732120cdfb5bf4847c3238b5be8acde87e3.zip"], + strip_prefix = "disco-to-proto3-converter-%s" % _disco_to_proto3_converter_commit, + urls = ["https://github.com/googleapis/disco-to-proto3-converter/archive/%s.zip" % _disco_to_proto3_converter_commit], +) + +# Showcase +_showcase_commit = "90d73532a0cab753a85f45c158394f24fc21d91a" + +http_archive( + name = "com_google_gapic_showcase", + strip_prefix = "gapic-showcase-%s" % _showcase_commit, + urls = [ + # "https://github.com/googleapis/gapic-showcase/archive/refs/tags/v%s.zip" % _showcase_version, + "https://github.com/googleapis/gapic-showcase/archive/%s.zip" % _showcase_commit, + ], ) diff --git a/gapic-generator-java/pom.xml b/gapic-generator-java/pom.xml new file mode 100644 index 0000000000..deb40e1031 --- /dev/null +++ b/gapic-generator-java/pom.xml @@ -0,0 +1,388 @@ + + 4.0.0 + com.google.api + gapic-generator-java + 0.0.1-SNAPSHOT + + + UTF-8 + + 44d6bef0ca6db8bba3fb324c8186e694bcc4829c + + + + + + com.google.cloud + google-cloud-shared-dependencies + 3.0.6 + pom + import + + + + + + ../src/main/java + + + ../src/ + + + ../src/test/java + ../target + + + + kr.motd.maven + os-maven-plugin + 1.7.1 + + + + + + maven-compiler-plugin + 3.10.1 + + 8 + 8 + + + com.google.auto.value + auto-value + 1.10.1 + + + + + + + com.coveo + fmt-maven-plugin + 2.9.1 + + + + com.googlecode.maven-download-plugin + download-maven-plugin + 1.6.8 + + + download-metadata-proto + generate-sources + + wget + + + + https://raw.githubusercontent.com/googleapis/googleapis/${googleapis.commit}/gapic/metadata/gapic_metadata.proto + + ../target/generated-sources/proto + + + + download-common-resources-proto + generate-test-sources + + wget + + + + https://raw.githubusercontent.com/googleapis/googleapis/${googleapis.commit}/google/cloud/common_resources.proto + + ../target/generated-test-sources/proto + + + + download-pubsub-proto + generate-test-sources + + wget + + + + https://raw.githubusercontent.com/googleapis/googleapis/${googleapis.commit}/google/pubsub/v1/pubsub.proto + + ../target/generated-test-sources/proto + + + + download-schema-proto + generate-test-sources + + wget + + + + https://raw.githubusercontent.com/googleapis/googleapis/${googleapis.commit}/google/pubsub/v1/schema.proto + + ../target/generated-test-sources/proto/google/pubsub/v1 + + + + + download-logging-proto + generate-test-sources + + wget + + + + https://raw.githubusercontent.com/googleapis/googleapis/${googleapis.commit}/google/logging/v2/logging.proto + + ../target/generated-test-sources/proto + + + + download-log-entry-proto + generate-test-sources + + wget + + + + https://raw.githubusercontent.com/googleapis/googleapis/${googleapis.commit}/google/logging/v2/log_entry.proto + + ../target/generated-test-sources/proto/google/logging/v2 + + + + + download-logging-config-proto + generate-test-sources + + wget + + + + https://raw.githubusercontent.com/googleapis/googleapis/${googleapis.commit}/google/logging/v2/logging_config.proto + + ../target/generated-test-sources/proto/google/logging/v2 + + + + + download-logging-metrics-proto + generate-test-sources + + wget + + + + https://raw.githubusercontent.com/googleapis/googleapis/${googleapis.commit}/google/logging/v2/logging_metrics.proto + + ../target/generated-test-sources/proto/google/logging/v2 + + + + + + + + org.xolstice.maven.plugins + protobuf-maven-plugin + 0.6.1 + + com.google.protobuf:protoc:3.21.7:exe:${os.detected.classifier} + + + + + compile-protos + + compile + + + ../src/main/proto + + + + compile-downloaded-protos + + compile + + + ../target/generated-sources/proto + false + + + + compile-test-protos + + test-compile + + + ../src/test/proto + true + true + true + test-proto.descriptorset + + + + compile-downloaded-test-protos + + test-compile + + + ../target/generated-test-sources/proto + false + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M7 + + + + ../target/generated-test-resources/protobuf/descriptor-sets + + + ../ + + + + + + org.jacoco + jacoco-maven-plugin + 0.8.8 + + + + prepare-agent + + + + report + test + + report + + + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.4.1 + + + package + + shade + + + false + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + + + + + + + + + + com.google.guava + guava + + + com.google.api + gax + + + com.google.api + gax + testlib + + + com.google.api + gax-grpc + + + com.google.api + gax-grpc + testlib + + + com.google.api + gax-httpjson + + + com.google.api + gax-httpjson + testlib + + + com.google.auto.value + auto-value-annotations + + + com.google.protobuf + protobuf-java-util + + + io.grpc + grpc-stub + + + io.grpc + grpc-protobuf + + + org.yaml + snakeyaml + 1.33 + + + com.google.googlejavaformat + google-java-format + 1.7 + + + junit + junit + 4.13.2 + + + + + javax.annotation + javax.annotation-api + + + + com.google.truth + truth + 1.1.3 + test + + + io.github.java-diff-utils + java-diff-utils + 4.12 + test + + + diff --git a/pom.xml b/pom.xml index 76416d39da..ad31faffd7 100644 --- a/pom.xml +++ b/pom.xml @@ -1,349 +1,33 @@ - + + 4.0.0 com.google.api - gapic-generator-java + gapic-generator-java-parent 0.0.1-SNAPSHOT + pom - - UTF-8 - - 44d6bef0ca6db8bba3fb324c8186e694bcc4829c - - - - - - com.google.cloud - google-cloud-shared-dependencies - 3.0.5 - pom - import - - - + + gapic-generator-java + + - - - kr.motd.maven - os-maven-plugin - 1.7.0 - - - - maven-compiler-plugin - 3.10.1 + org.apache.maven.plugins + maven-deploy-plugin + 3.0.0 - 8 - 8 - - - com.google.auto.value - auto-value - 1.10 - - + true - com.coveo fmt-maven-plugin 2.9.1 - - - com.googlecode.maven-download-plugin - download-maven-plugin - 1.6.8 - - - download-metadata-proto - generate-sources - - wget - - - https://raw.githubusercontent.com/googleapis/googleapis/${googleapis.commit}/gapic/metadata/gapic_metadata.proto - ${project.build.directory}/generated-sources/proto/ - - - - download-common-resources-proto - generate-test-sources - - wget - - - https://raw.githubusercontent.com/googleapis/googleapis/${googleapis.commit}/google/cloud/common_resources.proto - ${project.build.directory}/generated-test-sources/proto/ - - - - download-pubsub-proto - generate-test-sources - - wget - - - https://raw.githubusercontent.com/googleapis/googleapis/${googleapis.commit}/google/pubsub/v1/pubsub.proto - ${project.build.directory}/generated-test-sources/proto/ - - - - download-schema-proto - generate-test-sources - - wget - - - https://raw.githubusercontent.com/googleapis/googleapis/${googleapis.commit}/google/pubsub/v1/schema.proto - ${project.build.directory}/generated-test-sources/proto/google/pubsub/v1/ - - - - download-logging-proto - generate-test-sources - - wget - - - https://raw.githubusercontent.com/googleapis/googleapis/${googleapis.commit}/google/logging/v2/logging.proto - ${project.build.directory}/generated-test-sources/proto/ - - - - download-log-entry-proto - generate-test-sources - - wget - - - https://raw.githubusercontent.com/googleapis/googleapis/${googleapis.commit}/google/logging/v2/log_entry.proto - ${project.build.directory}/generated-test-sources/proto/google/logging/v2/ - - - - download-logging-config-proto - generate-test-sources - - wget - - - https://raw.githubusercontent.com/googleapis/googleapis/${googleapis.commit}/google/logging/v2/logging_config.proto - ${project.build.directory}/generated-test-sources/proto/google/logging/v2/ - - - - download-logging-metrics-proto - generate-test-sources - - wget - - - https://raw.githubusercontent.com/googleapis/googleapis/${googleapis.commit}/google/logging/v2/logging_metrics.proto - ${project.build.directory}/generated-test-sources/proto/google/logging/v2/ - - - - - - - org.xolstice.maven.plugins - protobuf-maven-plugin - 0.6.1 - - com.google.protobuf:protoc:3.21.7:exe:${os.detected.classifier} - - - - compile-protos - - compile - - - - compile-downloaded-protos - - compile - - - ${project.build.directory}/generated-sources/proto/ - false - - - - compile-test-protos - - test-compile - - - true - true - true - test-proto.descriptorset - - - - compile-downloaded-test-protos - - test-compile - - - ${project.build.directory}/generated-test-sources/proto/ - false - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 3.0.0-M7 - - - ${project.build.directory}/generated-test-resources/protobuf/descriptor-sets/ - - - - - - - org.jacoco - jacoco-maven-plugin - 0.8.8 - - - - prepare-agent - - - - report - test - - report - - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.4.1 - - - package - - shade - - - false - - - *:* - - META-INF/*.SF - META-INF/*.DSA - META-INF/*.RSA - - - - - - - - - - - com.google.guava - guava - - - com.google.api - gax - - - com.google.api - gax - testlib - - - com.google.api - gax-grpc - - - com.google.api - gax-grpc - testlib - - - com.google.api - gax-httpjson - - - com.google.api - gax-httpjson - testlib - - - com.google.auto.value - auto-value-annotations - - - com.google.protobuf - protobuf-java-util - - - io.grpc - grpc-stub - - - io.grpc - grpc-protobuf - - - org.yaml - snakeyaml - 1.33 - - - com.google.googlejavaformat - google-java-format - 1.7 - - - junit - junit - 4.13.2 - - - - - javax.annotation - javax.annotation-api - - - - com.google.truth - truth - 1.1.3 - test - - - io.github.java-diff-utils - java-diff-utils - 4.12 - test - - - + \ No newline at end of file diff --git a/rules_java_gapic/resources/gradle/gradle/wrapper/gradle-wrapper.properties b/rules_java_gapic/resources/gradle/gradle/wrapper/gradle-wrapper.properties index ae04661ee7..070cb702f0 100644 --- a/rules_java_gapic/resources/gradle/gradle/wrapper/gradle-wrapper.properties +++ b/rules_java_gapic/resources/gradle/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/scripts/update_golden.sh b/scripts/update_golden.sh index ece95265d5..98203b15f2 100755 --- a/scripts/update_golden.sh +++ b/scripts/update_golden.sh @@ -3,7 +3,7 @@ set -o errexit API_NAME=$1 -RAW_SRCJAR=$( find . -name '*_java_gapic_srcjar_raw.srcjar' ) +RAW_SRCJAR=$(find . -name '*_java_gapic_srcjar_raw.srcjar') rm -rf srcjar_unpacked mkdir srcjar_unpacked @@ -25,5 +25,6 @@ cp -r ${UNPACK_DIR}/src/test/java/* ./src mkdir -p ./samples/snippets/generated cp -r ${UNPACK_DIR}/samples/snippets/generated/**/* ./samples/snippets/generated +find . -name '.DS_Store' -delete find . -name 'PlaceholderFile.java' -delete find . -type d -empty -delete diff --git a/src/main/java/com/google/api/generator/engine/ast/AnnotationNode.java b/src/main/java/com/google/api/generator/engine/ast/AnnotationNode.java index 45464b333b..7cb0f5ec37 100644 --- a/src/main/java/com/google/api/generator/engine/ast/AnnotationNode.java +++ b/src/main/java/com/google/api/generator/engine/ast/AnnotationNode.java @@ -108,6 +108,17 @@ public Builder setDescription(VariableExpr variableExpr) { return setDescriptionExprs(Arrays.asList(variableExpr)); } + /** + * To set single ArrayExpr as description. + * + * @param arrayExpr + * @return Builder + */ + public Builder setDescription(ArrayExpr arrayExpr) { + Preconditions.checkState(descriptionExprs() == null, REPEAT_SINGLE_EXCEPTION_MESSAGE); + return setDescriptionExprs(Arrays.asList(arrayExpr)); + } + /** * To add an AssignmentExpr as parameter. Can be used repeatedly to add multiple parameters. * diff --git a/src/main/java/com/google/api/generator/engine/ast/ArrayExpr.java b/src/main/java/com/google/api/generator/engine/ast/ArrayExpr.java new file mode 100644 index 0000000000..92d79246a1 --- /dev/null +++ b/src/main/java/com/google/api/generator/engine/ast/ArrayExpr.java @@ -0,0 +1,92 @@ +// 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.engine.ast; + +import com.google.auto.value.AutoValue; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; +import java.util.Arrays; +import java.util.List; + +@AutoValue +public abstract class ArrayExpr implements Expr { + + public abstract List exprs(); + + public abstract TypeNode type(); + + @Override + public void accept(AstNodeVisitor visitor) { + visitor.visit(this); + } + + public static ArrayExpr.Builder builder() { + return new AutoValue_ArrayExpr.Builder().setExprs(ImmutableList.of()); + } + + public static ArrayExpr withStrings(String... stringValues) { + ArrayExpr.Builder builder = ArrayExpr.builder(); + Arrays.asList(stringValues).stream().forEach(s -> builder.addExpr(s)); + return builder.build(); + } + + public static ArrayExpr withExprs(Expr... exprs) { + return ArrayExpr.builder().setExprs(Arrays.asList(exprs)).build(); + } + + @AutoValue.Builder + public abstract static class Builder { + + private static final String SAME_TYPE_EXPRS_MESSAGE = + "All expressions must be of the type" + " specified in this ArrayExpr"; + private static final String EXPR_ALLOWED_CLASSES_MESSAGE = + "Only VariableExpr and ValueExpr can be used as elements of ArrayExpr"; + + abstract List exprs(); + + abstract TypeNode type(); + + /** + * To add a string expression same-type validation is performed + * + * @param expr + * @return Builder + */ + public ArrayExpr.Builder addExpr(String expr) { + return addExpr(ValueExpr.withValue(StringObjectValue.withValue(expr))); + } + + public ArrayExpr.Builder addExpr(Expr expr) { + return setExprs((new ImmutableList.Builder().addAll(exprs()).add(expr).build())); + } + + public abstract ArrayExpr.Builder setExprs(List exprs); + + public abstract ArrayExpr.Builder setType(TypeNode type); + + abstract ArrayExpr autoBuild(); + + public ArrayExpr build() { + Preconditions.checkState( + exprs().stream().allMatch(exp -> exp instanceof ValueExpr || exp instanceof VariableExpr), + EXPR_ALLOWED_CLASSES_MESSAGE); + TypeNode elementType = TypeNode.createElementTypeFromArrayType(type()); + Preconditions.checkState( + exprs().stream().allMatch(exp -> exp.type().equals(elementType)), + SAME_TYPE_EXPRS_MESSAGE); + return autoBuild(); + } + } +} diff --git a/src/main/java/com/google/api/generator/engine/ast/AstNodeVisitor.java b/src/main/java/com/google/api/generator/engine/ast/AstNodeVisitor.java index 3d3fbe8c47..8680e94fcb 100644 --- a/src/main/java/com/google/api/generator/engine/ast/AstNodeVisitor.java +++ b/src/main/java/com/google/api/generator/engine/ast/AstNodeVisitor.java @@ -24,6 +24,8 @@ public interface AstNodeVisitor { public void visit(AnnotationNode annotation); + public void visit(ArrayExpr expr); + public void visit(ConcreteReference reference); public void visit(VaporReference reference); diff --git a/src/main/java/com/google/api/generator/engine/ast/TypeNode.java b/src/main/java/com/google/api/generator/engine/ast/TypeNode.java index 1814be11aa..b217feb057 100644 --- a/src/main/java/com/google/api/generator/engine/ast/TypeNode.java +++ b/src/main/java/com/google/api/generator/engine/ast/TypeNode.java @@ -101,6 +101,23 @@ public enum TypeKind { public abstract boolean isArray(); + public static TypeNode createArrayTypeOf(TypeNode type) { + return builder() + .setTypeKind(type.typeKind()) + .setReference(type.reference()) + .setIsArray(true) + .build(); + } + + public static TypeNode createElementTypeFromArrayType(TypeNode type) { + Preconditions.checkArgument(type.isArray(), "Input type must be an array"); + return builder() + .setTypeKind(type.typeKind()) + .setReference(type.reference()) + .setIsArray(false) + .build(); + } + @Nullable public abstract Reference reference(); diff --git a/src/main/java/com/google/api/generator/engine/writer/ImportWriterVisitor.java b/src/main/java/com/google/api/generator/engine/writer/ImportWriterVisitor.java index 0967cea087..37dd4a5733 100644 --- a/src/main/java/com/google/api/generator/engine/writer/ImportWriterVisitor.java +++ b/src/main/java/com/google/api/generator/engine/writer/ImportWriterVisitor.java @@ -17,6 +17,7 @@ import com.google.api.generator.engine.ast.AnnotationNode; import com.google.api.generator.engine.ast.AnonymousClassExpr; import com.google.api.generator.engine.ast.ArithmeticOperationExpr; +import com.google.api.generator.engine.ast.ArrayExpr; import com.google.api.generator.engine.ast.AssignmentExpr; import com.google.api.generator.engine.ast.AssignmentOperationExpr; import com.google.api.generator.engine.ast.AstNodeVisitor; @@ -167,6 +168,11 @@ public void visit(AnnotationNode annotation) { annotation.type().accept(this); } + @Override + public void visit(ArrayExpr expr) { + expr.type().accept(this); + } + /** =============================== EXPRESSIONS =============================== */ @Override public void visit(ValueExpr valueExpr) { @@ -183,6 +189,7 @@ public void visit(TernaryExpr ternaryExpr) { @Override public void visit(VariableExpr variableExpr) { variableExpr.variable().type().accept(this); + annotations(variableExpr.annotations()); if (variableExpr.exprReferenceExpr() != null) { variableExpr.exprReferenceExpr().accept(this); } diff --git a/src/main/java/com/google/api/generator/engine/writer/JavaWriterVisitor.java b/src/main/java/com/google/api/generator/engine/writer/JavaWriterVisitor.java index 731411bab6..e092f1c69c 100644 --- a/src/main/java/com/google/api/generator/engine/writer/JavaWriterVisitor.java +++ b/src/main/java/com/google/api/generator/engine/writer/JavaWriterVisitor.java @@ -17,6 +17,7 @@ import com.google.api.generator.engine.ast.AnnotationNode; import com.google.api.generator.engine.ast.AnonymousClassExpr; import com.google.api.generator.engine.ast.ArithmeticOperationExpr; +import com.google.api.generator.engine.ast.ArrayExpr; import com.google.api.generator.engine.ast.AssignmentExpr; import com.google.api.generator.engine.ast.AssignmentOperationExpr; import com.google.api.generator.engine.ast.AstNodeVisitor; @@ -165,6 +166,19 @@ public void visit(ScopeNode scope) { buffer.append(scope.toString()); } + @Override + public void visit(ArrayExpr expr) { + buffer.append(LEFT_BRACE); + for (int i = 0; i < expr.exprs().size(); i++) { + expr.exprs().get(i).accept(this); + if (i < expr.exprs().size() - 1) { + buffer.append(COMMA); + buffer.append(SPACE); + } + } + buffer.append(RIGHT_BRACE); + } + @Override public void visit(AnnotationNode annotation) { buffer.append(AT); diff --git a/src/main/java/com/google/api/generator/gapic/composer/ClientLibraryPackageInfoComposer.java b/src/main/java/com/google/api/generator/gapic/composer/ClientLibraryPackageInfoComposer.java index d268a60299..cb794b4230 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/ClientLibraryPackageInfoComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/ClientLibraryPackageInfoComposer.java @@ -24,15 +24,13 @@ import com.google.api.generator.gapic.composer.samplecode.SampleCodeWriter; import com.google.api.generator.gapic.composer.samplecode.ServiceClientHeaderSampleComposer; import com.google.api.generator.gapic.composer.utils.ClassNames; +import com.google.api.generator.gapic.composer.utils.CommentFormatter; import com.google.api.generator.gapic.model.GapicContext; import com.google.api.generator.gapic.model.GapicPackageInfo; import com.google.api.generator.gapic.model.Sample; import com.google.api.generator.gapic.model.Service; import com.google.common.base.Preconditions; import com.google.common.base.Strings; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; import javax.annotation.Generated; public class ClientLibraryPackageInfoComposer { @@ -80,36 +78,11 @@ private static CommentStatement createPackageInfoJavadoc(GapicContext context) { javaDocCommentBuilder.addParagraph( String.format("%s %s %s", DIVIDER, javaClientName, DIVIDER)); - // TODO(miraleung): Replace this with a comment converter when we support CommonMark. if (service.hasDescription()) { - String[] descriptionParagraphs = service.description().split("\\n\\n"); - for (int i = 0; i < descriptionParagraphs.length; i++) { - boolean startsWithItemizedList = descriptionParagraphs[i].startsWith(" * "); - // Split by listed items, then join newlines. - List listItems = - Stream.of(descriptionParagraphs[i].split("\\n \\*")) - .map(s -> s.replace("\n", "")) - .collect(Collectors.toList()); - if (startsWithItemizedList) { - // Remove the first asterisk. - listItems.set(0, listItems.get(0).substring(2)); - } - - if (!startsWithItemizedList) { - if (i == 0) { - javaDocCommentBuilder = - javaDocCommentBuilder.addParagraph( - String.format(SERVICE_DESCRIPTION_HEADER_PATTERN, listItems.get(0))); - } else { - javaDocCommentBuilder = javaDocCommentBuilder.addParagraph(listItems.get(0)); - } - } - if (listItems.size() > 1 || startsWithItemizedList) { - javaDocCommentBuilder = - javaDocCommentBuilder.addUnorderedList( - listItems.subList(startsWithItemizedList ? 0 : 1, listItems.size())); - } - } + String descriptionComment = + CommentFormatter.formatAsJavaDocComment( + service.description(), SERVICE_DESCRIPTION_HEADER_PATTERN); + javaDocCommentBuilder = javaDocCommentBuilder.addUnescapedComment(descriptionComment); } javaDocCommentBuilder = diff --git a/src/main/java/com/google/api/generator/gapic/composer/comment/ServiceClientCommentComposer.java b/src/main/java/com/google/api/generator/gapic/composer/comment/ServiceClientCommentComposer.java index 7401143754..5835c77935 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/comment/ServiceClientCommentComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/comment/ServiceClientCommentComposer.java @@ -18,18 +18,16 @@ import com.google.api.generator.engine.ast.JavaDocComment; import com.google.api.generator.engine.ast.TypeNode; import com.google.api.generator.gapic.composer.utils.ClassNames; +import com.google.api.generator.gapic.composer.utils.CommentFormatter; import com.google.api.generator.gapic.model.Method; import com.google.api.generator.gapic.model.MethodArgument; import com.google.api.generator.gapic.model.Service; import com.google.api.generator.gapic.utils.JavaStyle; -import com.google.common.base.Strings; import java.util.ArrayList; 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; public class ServiceClientCommentComposer { // Tokens. @@ -120,11 +118,10 @@ public static List createClassHeaderComments( String secondaryTransport) { JavaDocComment.Builder classHeaderJavadocBuilder = JavaDocComment.builder(); if (service.hasDescription()) { - classHeaderJavadocBuilder = - processProtobufComment( - service.description(), - classHeaderJavadocBuilder, - SERVICE_DESCRIPTION_SUMMARY_PATTERN); + String descriptionComment = + CommentFormatter.formatAsJavaDocComment( + service.description(), SERVICE_DESCRIPTION_SUMMARY_PATTERN); + classHeaderJavadocBuilder = classHeaderJavadocBuilder.addUnescapedComment(descriptionComment); } // Service introduction. @@ -181,8 +178,9 @@ public static List createRpcMethodHeaderComment( JavaDocComment.Builder methodJavadocBuilder = JavaDocComment.builder(); if (method.hasDescription()) { - methodJavadocBuilder = - processProtobufComment(method.description(), methodJavadocBuilder, null); + String descriptionComment = + CommentFormatter.formatAsJavaDocComment(method.description(), null); + methodJavadocBuilder = methodJavadocBuilder.addUnescapedComment(descriptionComment); } if (sampleCodeOpt.isPresent()) { @@ -239,8 +237,9 @@ public static List createRpcCallableMethodHeaderComment( JavaDocComment.Builder methodJavadocBuilder = JavaDocComment.builder(); if (method.hasDescription()) { - methodJavadocBuilder = - processProtobufComment(method.description(), methodJavadocBuilder, null); + String descriptionComment = + CommentFormatter.formatAsJavaDocComment(method.description(), null); + methodJavadocBuilder = methodJavadocBuilder.addUnescapedComment(descriptionComment); } methodJavadocBuilder.addParagraph(METHOD_DESCRIPTION_SAMPLE_CODE_SUMMARY_STRING); @@ -260,42 +259,4 @@ public static List createRpcCallableMethodHeaderComment( private static CommentStatement toSimpleComment(String comment) { return CommentStatement.withComment(JavaDocComment.withComment(comment)); } - - // TODO(miraleung): Replace this with a comment converter when we support CommonMark. - private static JavaDocComment.Builder processProtobufComment( - String rawComment, JavaDocComment.Builder originalCommentBuilder, String firstPattern) { - JavaDocComment.Builder commentBuilder = originalCommentBuilder; - String[] descriptionParagraphs = rawComment.split("\\n\\n"); - for (int i = 0; i < descriptionParagraphs.length; i++) { - boolean startsWithItemizedList = descriptionParagraphs[i].startsWith(" * "); - // Split by listed items, then join newlines. - List listItems = - Stream.of(descriptionParagraphs[i].split("\\n \\*")) - .map(s -> s.replace("\n", "")) - .collect(Collectors.toList()); - if (startsWithItemizedList) { - // Remove the first asterisk. - listItems.set(0, listItems.get(0).substring(2)); - } - if (!startsWithItemizedList) { - if (i == 0) { - if (!Strings.isNullOrEmpty(firstPattern)) { - commentBuilder = - commentBuilder.addParagraph(String.format(firstPattern, listItems.get(0))); - } else { - commentBuilder = commentBuilder.addParagraph(listItems.get(0)); - } - } else { - commentBuilder = commentBuilder.addParagraph(listItems.get(0)); - } - } - if (listItems.size() > 1 || startsWithItemizedList) { - commentBuilder = - commentBuilder.addUnorderedList( - listItems.subList(startsWithItemizedList ? 0 : 1, listItems.size())); - } - } - - return commentBuilder; - } } diff --git a/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceClientTestClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceClientTestClassComposer.java index 896607982c..fd6686212f 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceClientTestClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceClientTestClassComposer.java @@ -82,6 +82,7 @@ import org.junit.Test; public abstract class AbstractServiceClientTestClassComposer implements ClassComposer { + protected static final Statement EMPTY_LINE_STATEMENT = EmptyLineStatement.create(); protected static final String CLIENT_VAR_NAME = "client"; @@ -689,19 +690,15 @@ private MethodDefinition createRpcTestMethod( methodExprs.clear(); methodStatements.add(EMPTY_LINE_STATEMENT); - methodStatements.addAll( - methodExprs.stream().map(e -> ExprStatement.withExpr(e)).collect(Collectors.toList())); - methodExprs.clear(); - methodStatements.addAll( constructRpcTestCheckerLogic( method, + methodSignature, rpcService, isRequestArg, classMemberVarExprs, requestVarExpr, - requestMessage, - argExprs)); + requestMessage)); String testMethodName = String.format( @@ -720,12 +717,12 @@ private MethodDefinition createRpcTestMethod( protected abstract List constructRpcTestCheckerLogic( Method method, + List methodSignature, Service service, boolean isRequestArg, Map classMemberVarExprs, VariableExpr requestVarExpr, - Message requestMessage, - List argExprs); + Message requestMessage); protected abstract MethodDefinition createStreamingRpcTestMethod( Service service, diff --git a/src/main/java/com/google/api/generator/gapic/composer/grpc/ServiceClientTestClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/grpc/ServiceClientTestClassComposer.java index 36f45326af..b43d4a4fc2 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/grpc/ServiceClientTestClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/grpc/ServiceClientTestClassComposer.java @@ -66,6 +66,7 @@ import java.util.stream.Collectors; public class ServiceClientTestClassComposer extends AbstractServiceClientTestClassComposer { + private static final String SERVICE_HELPER_VAR_NAME = "mockServiceHelper"; private static final String CHANNEL_PROVIDER_VAR_NAME = "channelProvider"; @@ -359,12 +360,12 @@ protected MethodDefinition createTearDownMethod( @Override protected List constructRpcTestCheckerLogic( Method method, + List methodSignature, Service service, boolean isRequestArg, Map classMemberVarExprs, - VariableExpr requestVarExpr, - Message requestMessage, - List argExprs) { + VariableExpr requestVarExpr, // Nullable + Message requestMessage) { List methodExprs = new ArrayList<>(); List methodStatements = new ArrayList<>(); @@ -435,71 +436,33 @@ protected List constructRpcTestCheckerLogic( Preconditions.checkNotNull(requestVarExpr); Preconditions.checkNotNull(requestMessage); for (Field field : requestMessage.fields()) { - String fieldGetterMethodNamePatternTemp = "get%s"; - if (field.isRepeated()) { - fieldGetterMethodNamePatternTemp = field.isMap() ? "get%sMap" : "get%sList"; - } - final String fieldGetterMethodNamePattern = fieldGetterMethodNamePatternTemp; - Function checkExprFn = - v -> - MethodInvocationExpr.builder() - .setExprReferenceExpr(v) - .setMethodName( - String.format( - fieldGetterMethodNamePattern, JavaStyle.toUpperCamelCase(field.name()))) - .build(); - Expr expectedFieldExpr = checkExprFn.apply(requestVarExpr); - Expr actualFieldExpr = checkExprFn.apply(actualRequestVarExpr); - List assertEqualsArguments = new ArrayList<>(); - assertEqualsArguments.add(expectedFieldExpr); - assertEqualsArguments.add(actualFieldExpr); - if (TypeNode.isFloatingPointType(field.type())) { - boolean isFloat = field.type().equals(TypeNode.FLOAT); - assertEqualsArguments.add( - ValueExpr.withValue( - PrimitiveValue.builder() - .setType(isFloat ? TypeNode.FLOAT : TypeNode.DOUBLE) - .setValue(String.format("0.0001%s", isFloat ? "f" : "")) - .build())); - } - methodExprs.add( - MethodInvocationExpr.builder() - .setStaticReferenceType(FIXED_TYPESTORE.get("Assert")) - .setMethodName("assertEquals") - .setArguments(assertEqualsArguments) - .build()); + Expr expectedFieldExpr = createGetter(requestVarExpr, field); + Expr actualFieldExpr = createGetter(actualRequestVarExpr, field); + methodExprs.add(createAssertEquals(expectedFieldExpr, actualFieldExpr, field.type())); } } else { - for (VariableExpr argVarExpr : argExprs) { - Variable variable = argVarExpr.variable(); - String fieldGetterMethodNamePattern = "get%s"; - if (LIST_TYPE.isSupertypeOrEquals(variable.type())) { - fieldGetterMethodNamePattern = "get%sList"; - } else if (MAP_TYPE.isSupertypeOrEquals(variable.type())) { - fieldGetterMethodNamePattern = "get%sMap"; + for (MethodArgument arg : methodSignature) { + Expr root = actualRequestVarExpr; + for (Field field : arg.nestedFields()) { + root = createGetter(root, field); } - Expr actualFieldExpr = - MethodInvocationExpr.builder() - .setExprReferenceExpr(actualRequestVarExpr) - .setMethodName( - String.format( - fieldGetterMethodNamePattern, - JavaStyle.toUpperCamelCase(variable.identifier().name()))) - .build(); - Expr expectedFieldExpr = argVarExpr; - if (RESOURCE_NAME_TYPE.isSupertypeOrEquals(argVarExpr.type())) { + MethodInvocationExpr actual = createGetter(root, arg.field()); + + Expr expectedFieldExpr = + VariableExpr.withVariable( + Variable.builder() + .setName(JavaStyle.toLowerCamelCase(arg.name())) + .setType(arg.type()) + .build()); + if (RESOURCE_NAME_TYPE.isSupertypeOrEquals(arg.type())) { expectedFieldExpr = MethodInvocationExpr.builder() - .setExprReferenceExpr(argVarExpr) + .setExprReferenceExpr(expectedFieldExpr) .setMethodName("toString") .build(); } - methodExprs.add( - MethodInvocationExpr.builder() - .setStaticReferenceType(FIXED_TYPESTORE.get("Assert")) - .setMethodName("assertEquals") - .setArguments(expectedFieldExpr, actualFieldExpr) - .build()); + + methodExprs.add(createAssertEquals(expectedFieldExpr, actual, arg.type())); } } @@ -533,6 +496,49 @@ protected List constructRpcTestCheckerLogic( return methodStatements; } + private static MethodInvocationExpr createAssertEquals( + Expr expected, Expr actual, TypeNode type) { + + ArrayList assertionArgs = new ArrayList<>(); + assertionArgs.add(expected); + assertionArgs.add(actual); + + if (TypeNode.isFloatingPointType(type)) { + boolean isFloat = type.equals(TypeNode.FLOAT); + assertionArgs.add( + ValueExpr.withValue( + PrimitiveValue.builder() + .setType(isFloat ? TypeNode.FLOAT : TypeNode.DOUBLE) + .setValue(String.format("0.0001%s", isFloat ? "f" : "")) + .build())); + } + + return MethodInvocationExpr.builder() + .setStaticReferenceType(FIXED_TYPESTORE.get("Assert")) + .setMethodName("assertEquals") + .setArguments(assertionArgs) + .build(); + } + + private static MethodInvocationExpr createGetter(Expr exprReference, Field field) { + return MethodInvocationExpr.builder() + .setExprReferenceExpr(exprReference) + .setMethodName( + String.format( + createGetterNamePattern(field.type()), JavaStyle.toUpperCamelCase(field.name()))) + .build(); + } + + private static String createGetterNamePattern(TypeNode type) { + String fieldGetterMethodNamePattern = "get%s"; + if (LIST_TYPE.isSupertypeOrEquals(type)) { + fieldGetterMethodNamePattern = "get%sList"; + } else if (MAP_TYPE.isSupertypeOrEquals(type)) { + fieldGetterMethodNamePattern = "get%sMap"; + } + return fieldGetterMethodNamePattern; + } + @Override protected MethodDefinition createStreamingRpcTestMethod( Service service, diff --git a/src/main/java/com/google/api/generator/gapic/composer/rest/ServiceClientTestClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/rest/ServiceClientTestClassComposer.java index bfc69954de..d9fc2843cd 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/rest/ServiceClientTestClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/rest/ServiceClientTestClassComposer.java @@ -60,6 +60,7 @@ import java.util.stream.Collectors; public class ServiceClientTestClassComposer extends AbstractServiceClientTestClassComposer { + private static final String MOCK_SERVICE_VAR_NAME = "mockService"; private static final ServiceClientTestClassComposer INSTANCE = @@ -297,12 +298,12 @@ protected MethodDefinition createTearDownMethod( @Override protected List constructRpcTestCheckerLogic( Method method, + List methodSignature, Service service, boolean isRequestArg, Map classMemberVarExprs, VariableExpr requestVarExpr, - Message requestMessage, - List argExprs) { + Message requestMessage) { VariableExpr actualRequestsVarExpr = VariableExpr.withVariable( diff --git a/src/main/java/com/google/api/generator/gapic/composer/utils/CommentFormatter.java b/src/main/java/com/google/api/generator/gapic/composer/utils/CommentFormatter.java new file mode 100644 index 0000000000..b0fc487162 --- /dev/null +++ b/src/main/java/com/google/api/generator/gapic/composer/utils/CommentFormatter.java @@ -0,0 +1,62 @@ +// 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.utils; + +import com.google.api.generator.engine.ast.JavaDocComment; +import com.google.common.base.Strings; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class CommentFormatter { + + private CommentFormatter() {} + + // Additional formatting logic for converting protobuf comment to Javadoc + public static String formatAsJavaDocComment(String comment, String prefixPattern) { + + JavaDocComment.Builder javaDocCommentBuilder = JavaDocComment.builder(); + + String[] descriptionParagraphs = comment.split("\\n\\n"); + for (int i = 0; i < descriptionParagraphs.length; i++) { + boolean startsWithItemizedList = descriptionParagraphs[i].startsWith(" * "); + // Split by listed items, then join newlines. + List listItems = + Stream.of(descriptionParagraphs[i].split("\\n \\*")) + .map(s -> s.replace("\n", "")) + .collect(Collectors.toList()); + if (startsWithItemizedList) { + // Remove the first asterisk. + listItems.set(0, listItems.get(0).substring(2)); + } + + if (!startsWithItemizedList) { + if (i == 0 && !Strings.isNullOrEmpty(prefixPattern)) { + javaDocCommentBuilder = + javaDocCommentBuilder.addParagraph(String.format(prefixPattern, listItems.get(0))); + } else { + javaDocCommentBuilder = javaDocCommentBuilder.addParagraph(listItems.get(0)); + } + } + if (listItems.size() > 1 || startsWithItemizedList) { + javaDocCommentBuilder = + javaDocCommentBuilder.addUnorderedList( + listItems.subList(startsWithItemizedList ? 0 : 1, listItems.size())); + } + } + + return javaDocCommentBuilder.build().comment(); + } +} diff --git a/src/test/java/com/google/api/generator/engine/JavaCodeGeneratorTest.java b/src/test/java/com/google/api/generator/engine/JavaCodeGeneratorTest.java index 607ccd89f6..3bbc0808de 100644 --- a/src/test/java/com/google/api/generator/engine/JavaCodeGeneratorTest.java +++ b/src/test/java/com/google/api/generator/engine/JavaCodeGeneratorTest.java @@ -63,6 +63,7 @@ import org.junit.Test; public class JavaCodeGeneratorTest { + private static final String GOLDENFILES_DIRECTORY = "src/test/java/com/google/api/generator/engine/goldens/"; // Create shared VaporReferences. diff --git a/src/test/java/com/google/api/generator/engine/ast/ArrayExprTest.java b/src/test/java/com/google/api/generator/engine/ast/ArrayExprTest.java new file mode 100644 index 0000000000..723c60ad4f --- /dev/null +++ b/src/test/java/com/google/api/generator/engine/ast/ArrayExprTest.java @@ -0,0 +1,69 @@ +// 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.engine.ast; + +import static com.google.common.truth.Truth.assertThat; +import static org.junit.Assert.assertThrows; + +import com.google.api.generator.util.TestUtils; +import org.junit.Test; + +public class ArrayExprTest { + + @Test + public void validAnonymousArray_sametype() { + ArrayExpr.Builder exprBuilder = + ArrayExpr.builder() + .setType(TypeNode.createArrayTypeOf(TypeNode.STRING)) + .addExpr(TestUtils.generateStringValueExpr("test1")) + .addExpr(TestUtils.generateStringValueExpr("test2")) + .addExpr(TestUtils.generateStringValueExpr("test3")) + .addExpr( + ValueExpr.withValue( + PrimitiveValue.builder().setValue("1").setType(TypeNode.INT).build())); + + Exception thrown = assertThrows(IllegalStateException.class, () -> exprBuilder.build()); + assertThat(thrown) + .hasMessageThat() + .contains("All expressions must be of the type specified in this ArrayExpr"); + } + + @Test + public void validAnonymousArray_unsetTypeThrows() { + ArrayExpr.Builder exprBuilder = ArrayExpr.builder(); + IllegalStateException thrown = + assertThrows(IllegalStateException.class, () -> exprBuilder.build()); + assertThat(thrown).hasMessageThat().contains("Property \"type\" has not been set"); + } + + @Test + public void validAnonymousArray_onlyVariableAndValueExprs() { + ArrayExpr.Builder exprBuilder = + ArrayExpr.builder().setType(TypeNode.createArrayTypeOf(TypeNode.INT)); + Variable variable = Variable.builder().setName("x").setType(TypeNode.INT).build(); + VariableExpr variableExpr = + VariableExpr.builder().setVariable(variable).setIsDecl(true).build(); + Value value = PrimitiveValue.builder().setType(TypeNode.INT).setValue("3").build(); + Expr valueExpr = ValueExpr.builder().setValue(value).build(); + AssignmentExpr assignExpr = + AssignmentExpr.builder().setVariableExpr(variableExpr).setValueExpr(valueExpr).build(); + exprBuilder.addExpr(assignExpr); + IllegalStateException thrown = + assertThrows(IllegalStateException.class, () -> exprBuilder.build()); + assertThat(thrown) + .hasMessageThat() + .contains("Only VariableExpr and ValueExpr can be used as elements of ArrayExpr"); + } +} diff --git a/src/test/java/com/google/api/generator/engine/writer/ImportWriterVisitorTest.java b/src/test/java/com/google/api/generator/engine/writer/ImportWriterVisitorTest.java index 07be47a996..865f505a62 100644 --- a/src/test/java/com/google/api/generator/engine/writer/ImportWriterVisitorTest.java +++ b/src/test/java/com/google/api/generator/engine/writer/ImportWriterVisitorTest.java @@ -20,6 +20,7 @@ import com.google.api.generator.engine.ast.AnnotationNode; import com.google.api.generator.engine.ast.AnonymousClassExpr; import com.google.api.generator.engine.ast.ArithmeticOperationExpr; +import com.google.api.generator.engine.ast.ArrayExpr; import com.google.api.generator.engine.ast.AssignmentExpr; import com.google.api.generator.engine.ast.BlockComment; import com.google.api.generator.engine.ast.CommentStatement; @@ -363,6 +364,32 @@ public void writeVariableExprImports_nestedReference() { writerVisitor.write()); } + @Test + public void writeVariableExprImports_withAnnotations() { + Variable variable = + Variable.builder() + .setName("expr") + .setType(TypeNode.withReference(ConcreteReference.withClazz(Expr.class))) + .build(); + + VariableExpr variableExpr = + VariableExpr.builder() + .setVariable(variable) + .setIsDecl(true) + .setAnnotations( + Arrays.asList( + AnnotationNode.withType( + TypeNode.withReference(ConcreteReference.withClazz(Generated.class))))) + .build(); + + variableExpr.accept(writerVisitor); + assertEquals( + LineFormatter.lines( + "import com.google.api.generator.engine.ast.Expr;\n", + "import javax.annotation.Generated;\n\n"), + writerVisitor.write()); + } + @Test public void writeAnonymousClassExprImports() { // [Constructing] Function, MethodDefinition> @@ -893,6 +920,20 @@ public void writeLambdaExprImports() { writerVisitor.write()); } + @Test + public void importArrayExprTypes() { + ArrayExpr arrayExpr = + ArrayExpr.builder() + .setType( + TypeNode.createArrayTypeOf( + TypeNode.withReference(ConcreteReference.withClazz(UnaryOperationExpr.class)))) + .build(); + arrayExpr.accept(writerVisitor); + assertEquals( + "import com.google.api.generator.engine.ast.UnaryOperationExpr;\n\n", + writerVisitor.write()); + } + /** =============================== HELPERS =============================== */ private static Variable createVariable(String variableName, TypeNode type) { return Variable.builder().setName(variableName).setType(type).build(); diff --git a/src/test/java/com/google/api/generator/engine/writer/JavaWriterVisitorTest.java b/src/test/java/com/google/api/generator/engine/writer/JavaWriterVisitorTest.java index 713aa57939..9852b44a65 100644 --- a/src/test/java/com/google/api/generator/engine/writer/JavaWriterVisitorTest.java +++ b/src/test/java/com/google/api/generator/engine/writer/JavaWriterVisitorTest.java @@ -21,6 +21,7 @@ import com.google.api.generator.engine.ast.AnnotationNode; import com.google.api.generator.engine.ast.AnonymousClassExpr; import com.google.api.generator.engine.ast.ArithmeticOperationExpr; +import com.google.api.generator.engine.ast.ArrayExpr; import com.google.api.generator.engine.ast.AssignmentExpr; import com.google.api.generator.engine.ast.AssignmentOperationExpr; import com.google.api.generator.engine.ast.BlockComment; @@ -71,6 +72,7 @@ import com.google.api.generator.engine.ast.VariableExpr; import com.google.api.generator.engine.ast.WhileStatement; import com.google.api.generator.testutils.LineFormatter; +import com.google.api.generator.util.TestUtils; import com.google.common.base.Function; import java.io.IOException; import java.util.Arrays; @@ -308,6 +310,148 @@ public void writeAnnotation_withInvalidDescriptions() { .contains("Multiple parameters must have names"); } + @Test + public void writeAnnotation_withArrayExpr() { + TypeNode fakeAnnotationType = + TypeNode.withReference( + VaporReference.builder().setName("FakeAnnotation").setPakkage("com.foo.bar").build()); + AnnotationNode annotation = + AnnotationNode.builder() + .setType(fakeAnnotationType) + .setDescription( + ArrayExpr.builder() + .setType(TypeNode.createArrayTypeOf(TypeNode.CLASS_OBJECT)) + .addExpr(TestUtils.generateClassValueExpr("Class1")) + .addExpr(TestUtils.generateClassValueExpr("Class2")) + .build()) + .build(); + annotation.accept(writerVisitor); + assertEquals("@FakeAnnotation({Class1.class, Class2.class})\n", writerVisitor.write()); + } + + @Test + public void writeAnnotation_withArrayExprAssignment() { + TypeNode fakeAnnotationType = + TypeNode.withReference( + VaporReference.builder().setName("FakeAnnotation").setPakkage("com.foo.bar").build()); + ArrayExpr arrayExpr = + ArrayExpr.builder() + .setType(TypeNode.createArrayTypeOf(TypeNode.CLASS_OBJECT)) + .addExpr(TestUtils.generateClassValueExpr("Class1")) + .addExpr(TestUtils.generateClassValueExpr("Class2")) + .build(); + AssignmentExpr clazz1AssignExpr = + AssignmentExpr.builder() + .setVariableExpr( + VariableExpr.builder() + .setVariable( + Variable.builder() + .setName("value1") + .setType(TypeNode.createArrayTypeOf(TypeNode.CLASS_OBJECT)) + .build()) + .build()) + .setValueExpr(arrayExpr) + .build(); + AssignmentExpr clazz2AssignExpr = + AssignmentExpr.builder() + .setVariableExpr( + VariableExpr.withVariable( + Variable.builder() + .setName("value2") + .setType(TypeNode.createArrayTypeOf(TypeNode.CLASS_OBJECT)) + .build())) + .setValueExpr(arrayExpr) + .build(); + AnnotationNode annotation = + AnnotationNode.builder() + .setType(fakeAnnotationType) + .addDescription(clazz1AssignExpr) + .addDescription(clazz2AssignExpr) + .build(); + annotation.accept(writerVisitor); + assertEquals( + "@FakeAnnotation(value1 = {Class1.class, Class2.class}, " + + "value2 = {Class1.class, Class2.class})\n", + writerVisitor.write()); + } + + @Test + public void writeArrayExpr_add1StringExpr() { + ArrayExpr expr = + ArrayExpr.builder() + .setType(TypeNode.createArrayTypeOf(TypeNode.STRING)) + .addExpr(ValueExpr.builder().setValue(StringObjectValue.withValue("test1")).build()) + .build(); + expr.accept(writerVisitor); + assertEquals("{\"test1\"}", writerVisitor.write()); + } + + @Test + public void writeArrayExpr_addManyStrExpr() { + ArrayExpr expr = + ArrayExpr.builder() + .setType(TypeNode.createArrayTypeOf(TypeNode.STRING)) + .addExpr(TestUtils.generateStringValueExpr("test1")) + .addExpr(TestUtils.generateStringValueExpr("test2")) + .addExpr(TestUtils.generateStringValueExpr("test3")) + .build(); + expr.accept(writerVisitor); + assertEquals("{\"test1\", \"test2\", \"test3\"}", writerVisitor.write()); + } + + @Test + public void writeArrayExpr_addManyClassExpr() { + ArrayExpr expr = + ArrayExpr.builder() + .setType(TypeNode.createArrayTypeOf(TypeNode.CLASS_OBJECT)) + .addExpr(TestUtils.generateClassValueExpr("Class1")) + .addExpr(TestUtils.generateClassValueExpr("Class2")) + .addExpr(TestUtils.generateClassValueExpr("Class3")) + .build(); + expr.accept(writerVisitor); + assertEquals("{Class1.class, Class2.class, Class3.class}", writerVisitor.write()); + } + + @Test + public void writeArrayExpr_mixedVariablesStaticAndNormalReference() { + VariableExpr clazzVar = + VariableExpr.builder() + .setVariable( + Variable.builder().setName("clazz1Var").setType(TypeNode.CLASS_OBJECT).build()) + .build(); + ArrayExpr expr = + ArrayExpr.builder() + .setType(TypeNode.createArrayTypeOf(TypeNode.CLASS_OBJECT)) + .addExpr(clazzVar) + .addExpr(TestUtils.generateClassValueExpr("Class2")) + .build(); + expr.accept(writerVisitor); + assertEquals("{clazz1Var, Class2.class}", writerVisitor.write()); + } + + @Test + public void writeArrayExpr_assignemntWithDeclaration() { + VariableExpr varExpr = + VariableExpr.builder() + .setVariable( + Variable.builder() + .setName("varExpr") + .setType(TypeNode.createArrayTypeOf(TypeNode.STRING)) + .build()) + .setIsDecl(true) + .build(); + ArrayExpr expr = + ArrayExpr.builder() + .setType(TypeNode.createArrayTypeOf(TypeNode.STRING)) + .addExpr(TestUtils.generateStringValueExpr("str1")) + .addExpr(TestUtils.generateStringValueExpr("str2")) + .build(); + AssignmentExpr assignmentExpr = + AssignmentExpr.builder().setVariableExpr(varExpr).setValueExpr(expr).build(); + assignmentExpr.accept(writerVisitor); + assertEquals("String[] varExpr = {\"str1\", \"str2\"}", writerVisitor.write()); + } + @Test public void writeNewObjectExpr_basic() { // isGeneric() is true, but generics() is empty. diff --git a/src/test/java/com/google/api/generator/gapic/composer/ClientLibraryPackageInfoComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/ClientLibraryPackageInfoComposerTest.java new file mode 100644 index 0000000000..f827bfc63e --- /dev/null +++ b/src/test/java/com/google/api/generator/gapic/composer/ClientLibraryPackageInfoComposerTest.java @@ -0,0 +1,40 @@ +// 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; + +import com.google.api.generator.engine.writer.JavaWriterVisitor; +import com.google.api.generator.gapic.composer.common.TestProtoLoader; +import com.google.api.generator.gapic.model.GapicContext; +import com.google.api.generator.gapic.model.GapicPackageInfo; +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 ClientLibraryPackageInfoComposerTest { + private GapicContext context = TestProtoLoader.instance().parseShowcaseEcho(); + + @Test + public void composePackageInfo_showcase() { + GapicPackageInfo packageInfo = ClientLibraryPackageInfoComposer.generatePackageInfo(context); + JavaWriterVisitor visitor = new JavaWriterVisitor(); + packageInfo.packageInfo().accept(visitor); + Utils.saveCodegenToFile(this.getClass(), "ShowcaseWithEchoPackageInfo.golden", visitor.write()); + Path goldenFilePath = + Paths.get(Utils.getGoldenDir(this.getClass()), "ShowcaseWithEchoPackageInfo.golden"); + Assert.assertCodeEquals(goldenFilePath, visitor.write()); + } +} diff --git a/src/test/java/com/google/api/generator/gapic/composer/common/TestProtoLoader.java b/src/test/java/com/google/api/generator/gapic/composer/common/TestProtoLoader.java index dd17414f80..4df5052b6b 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/common/TestProtoLoader.java +++ b/src/test/java/com/google/api/generator/gapic/composer/common/TestProtoLoader.java @@ -51,11 +51,18 @@ import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.stream.Collectors; public class TestProtoLoader { private static final TestProtoLoader INSTANCE = new TestProtoLoader(Transport.GRPC, "src/test/resources/"); + private static final String ECHO_SERVICE_DESCRIPTION = + "This service is used showcase the four main types of rpcs - unary, server\n" + + " side streaming, client side streaming, and bidirectional streaming. This\n" + + " service also exposes methods that explicitly implement server delay, and\n" + + " paginated calls. Set the 'showcase-trailer' metadata key on any method\n" + + " to have the values echoed in the response trailers."; private final String testFilesDirectory; private final Transport transport; @@ -136,6 +143,13 @@ public GapicContext parseShowcaseEcho() { Parser.parseService( echoFileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames); + // Explicitly adds service description, since this is not parsed from source code location + // in test protos, as it would from a protoc CodeGeneratorRequest + List servicesWithDescription = + services.stream() + .map(s -> s.toBuilder().setDescription(ECHO_SERVICE_DESCRIPTION).build()) + .collect(Collectors.toList()); + String jsonFilename = "showcase_grpc_service_config.json"; Path jsonPath = Paths.get(testFilesDirectory, jsonFilename); Optional configOpt = ServiceConfigParser.parse(jsonPath.toString()); @@ -145,7 +159,7 @@ public GapicContext parseShowcaseEcho() { return GapicContext.builder() .setMessages(messageTypes) .setResourceNames(resourceNames) - .setServices(services) + .setServices(servicesWithDescription) .setServiceConfig(config) .setHelperResourceNames(outputResourceNames) .setTransport(transport) diff --git a/src/test/java/com/google/api/generator/gapic/composer/goldens/ShowcaseWithEchoPackageInfo.golden b/src/test/java/com/google/api/generator/gapic/composer/goldens/ShowcaseWithEchoPackageInfo.golden new file mode 100644 index 0000000000..a2c213eb11 --- /dev/null +++ b/src/test/java/com/google/api/generator/gapic/composer/goldens/ShowcaseWithEchoPackageInfo.golden @@ -0,0 +1,27 @@ +/** + * The interfaces provided are listed below, along with usage samples. + * + *

======================= EchoClient ======================= + * + *

Service Description: This service is used showcase the four main types of rpcs - unary, server + * side streaming, client side streaming, and bidirectional streaming. This service also exposes + * methods that explicitly implement server delay, and paginated calls. Set the 'showcase-trailer' + * metadata key on any method to have the values echoed in the response trailers. + * + *

Sample for EchoClient: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (EchoClient echoClient = EchoClient.create()) {
+ *   EchoResponse response = echoClient.echo();
+ * }
+ * }
+ */ +@Generated("by gapic-generator-java") +package com.google.showcase.v1beta1; + +import javax.annotation.Generated; diff --git a/src/test/java/com/google/api/generator/gapic/composer/grpc/GrpcTestProtoLoader.java b/src/test/java/com/google/api/generator/gapic/composer/grpc/GrpcTestProtoLoader.java index 7270a2f14b..c6249121e5 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/grpc/GrpcTestProtoLoader.java +++ b/src/test/java/com/google/api/generator/gapic/composer/grpc/GrpcTestProtoLoader.java @@ -18,6 +18,7 @@ import com.google.api.generator.gapic.model.Transport; public class GrpcTestProtoLoader extends TestProtoLoader { + private static final GrpcTestProtoLoader INSTANCE = new GrpcTestProtoLoader(); protected GrpcTestProtoLoader() { diff --git a/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/EchoClient.golden b/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/EchoClient.golden index 5d60b70463..5bc547af78 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/EchoClient.golden +++ b/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/EchoClient.golden @@ -30,8 +30,13 @@ import javax.annotation.Generated; // AUTO-GENERATED DOCUMENTATION AND CLASS. /** - * This class provides the ability to make remote calls to the backing service through method calls - * that map to API methods. Sample code to get started: + * Service Description: This service is used showcase the four main types of rpcs - unary, server + * side streaming, client side streaming, and bidirectional streaming. This service also exposes + * methods that explicitly implement server delay, and paginated calls. Set the 'showcase-trailer' + * metadata key on any method to have the values echoed in the response trailers. + * + *

This class provides the ability to make remote calls to the backing service through method + * calls that map to API methods. Sample code to get started: * *

{@code
  * // This snippet has been automatically generated and should be regarded as a code template only.
diff --git a/src/test/java/com/google/api/generator/gapic/composer/utils/CommentFormatterTest.java b/src/test/java/com/google/api/generator/gapic/composer/utils/CommentFormatterTest.java
new file mode 100644
index 0000000000..8f562de47c
--- /dev/null
+++ b/src/test/java/com/google/api/generator/gapic/composer/utils/CommentFormatterTest.java
@@ -0,0 +1,96 @@
+// 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.utils;
+
+import static org.junit.Assert.assertEquals;
+
+import com.google.api.generator.testutils.LineFormatter;
+import org.junit.Test;
+
+public class CommentFormatterTest {
+  private static final String SERVICE_DESCRIPTION_HEADER_PATTERN = "Service Description: %s";
+
+  @Test
+  public void parseCommentWithItemizedList_paragraphContainsList() {
+    String protobufComment =
+        LineFormatter.lines(
+            "Service Name\n\n",
+            "One line initial description. Here is a list of items:\n",
+            " * This is item one\n",
+            " * This is item two");
+    String result = CommentFormatter.formatAsJavaDocComment(protobufComment, null);
+    String expectedJavaDocComment =
+        LineFormatter.lines(
+            "

Service Name\n", + "

One line initial description. Here is a list of items:\n", + "

    \n", + "
  • This is item one\n", + "
  • This is item two\n", + "
"); + assertEquals(expectedJavaDocComment, result); + } + + @Test + public void parseCommentWithItemizedList_paragraphStartsWithList() { + String protobufComment = + LineFormatter.lines( + "Paragraphs starting with list items should still be parsed as list:\n\n", + " * This is item one\n", + " * This is item two"); + String result = CommentFormatter.formatAsJavaDocComment(protobufComment, null); + String expectedJavaDocComment = + LineFormatter.lines( + "

Paragraphs starting with list items should still be parsed as list:\n", + "

    \n", + "
  • This is item one\n", + "
  • This is item two\n", + "
"); + assertEquals(expectedJavaDocComment, result); + } + + @Test + public void parseCommentWithPrefixPattern_addIfStartsWithParagraph() { + String protobufComment = + LineFormatter.lines( + "Service Name\n\n", + "Here is a list of items:\n", + " * This is item one\n", + " * This is item two"); + String result = + CommentFormatter.formatAsJavaDocComment( + protobufComment, SERVICE_DESCRIPTION_HEADER_PATTERN); + String expectedJavaDocComment = + LineFormatter.lines( + "

Service Description: Service Name\n", + "

Here is a list of items:\n", + "

    \n", + "
  • This is item one\n", + "
  • This is item two\n", + "
"); + assertEquals(expectedJavaDocComment, result); + } + + @Test + public void parseCommentWithPrefixPattern_ignoreIfStartsWithList() { + String protobufComment = LineFormatter.lines(" * This is item one\n", " * This is item two"); + String result = + CommentFormatter.formatAsJavaDocComment( + protobufComment, SERVICE_DESCRIPTION_HEADER_PATTERN); + String expectedJavaDocComment = + LineFormatter.lines( + "
    \n", "
  • This is item one\n", "
  • This is item two\n", "
"); + assertEquals(expectedJavaDocComment, result); + } +} diff --git a/src/test/java/com/google/api/generator/gapic/model/GapicServiceConfigTest.java b/src/test/java/com/google/api/generator/gapic/model/GapicServiceConfigTest.java index d7aefc8733..ca4cd84418 100644 --- a/src/test/java/com/google/api/generator/gapic/model/GapicServiceConfigTest.java +++ b/src/test/java/com/google/api/generator/gapic/model/GapicServiceConfigTest.java @@ -37,6 +37,7 @@ import org.junit.Test; public class GapicServiceConfigTest { + private static final double EPSILON = 1e-4; private static final String TESTDATA_DIRECTORY = "src/test/resources/"; diff --git a/src/test/java/com/google/api/generator/gapic/protoparser/BatchingSettingsConfigParserTest.java b/src/test/java/com/google/api/generator/gapic/protoparser/BatchingSettingsConfigParserTest.java index 3dfc6373c0..3430c2585d 100644 --- a/src/test/java/com/google/api/generator/gapic/protoparser/BatchingSettingsConfigParserTest.java +++ b/src/test/java/com/google/api/generator/gapic/protoparser/BatchingSettingsConfigParserTest.java @@ -27,6 +27,7 @@ import org.junit.Test; public class BatchingSettingsConfigParserTest { + private static final String YAML_DIRECTORY = "src/test/resources/"; @Test diff --git a/src/test/java/com/google/api/generator/gapic/protoparser/GapicLanguageSettingsParserTest.java b/src/test/java/com/google/api/generator/gapic/protoparser/GapicLanguageSettingsParserTest.java index 3a6fbed745..868231d516 100644 --- a/src/test/java/com/google/api/generator/gapic/protoparser/GapicLanguageSettingsParserTest.java +++ b/src/test/java/com/google/api/generator/gapic/protoparser/GapicLanguageSettingsParserTest.java @@ -24,6 +24,7 @@ import org.junit.Test; public class GapicLanguageSettingsParserTest { + private static final String YAML_DIRECTORY = "src/test/resources/"; @Test diff --git a/src/test/java/com/google/api/generator/gapic/protoparser/GapicLroRetrySettingsParserTest.java b/src/test/java/com/google/api/generator/gapic/protoparser/GapicLroRetrySettingsParserTest.java index 37eb4bdd5f..0c7f8e7d82 100644 --- a/src/test/java/com/google/api/generator/gapic/protoparser/GapicLroRetrySettingsParserTest.java +++ b/src/test/java/com/google/api/generator/gapic/protoparser/GapicLroRetrySettingsParserTest.java @@ -25,6 +25,7 @@ import org.junit.Test; public class GapicLroRetrySettingsParserTest { + private static final double DELTA = 0.0001; private static final String YAML_DIRECTORY = "src/test/resources/"; diff --git a/src/test/java/com/google/api/generator/gapic/protoparser/ServiceConfigParserTest.java b/src/test/java/com/google/api/generator/gapic/protoparser/ServiceConfigParserTest.java index 6d9318969e..8a27f7fd4f 100644 --- a/src/test/java/com/google/api/generator/gapic/protoparser/ServiceConfigParserTest.java +++ b/src/test/java/com/google/api/generator/gapic/protoparser/ServiceConfigParserTest.java @@ -28,6 +28,7 @@ import org.junit.Test; public class ServiceConfigParserTest { + private static final String JSON_DIRECTORY = "src/test/resources/"; private static final double EPSILON = 1e-4; diff --git a/src/test/java/com/google/api/generator/gapic/protoparser/ServiceYamlParserTest.java b/src/test/java/com/google/api/generator/gapic/protoparser/ServiceYamlParserTest.java index dd38903051..8df9ddcf84 100644 --- a/src/test/java/com/google/api/generator/gapic/protoparser/ServiceYamlParserTest.java +++ b/src/test/java/com/google/api/generator/gapic/protoparser/ServiceYamlParserTest.java @@ -23,6 +23,7 @@ import org.junit.Test; public class ServiceYamlParserTest { + private static final String YAML_DIRECTORY = "src/test/resources/"; @Test diff --git a/src/test/java/com/google/api/generator/gapic/protoparser/SourceCodeInfoParserTest.java b/src/test/java/com/google/api/generator/gapic/protoparser/SourceCodeInfoParserTest.java index 36ca5d15f8..40b9eb12f0 100644 --- a/src/test/java/com/google/api/generator/gapic/protoparser/SourceCodeInfoParserTest.java +++ b/src/test/java/com/google/api/generator/gapic/protoparser/SourceCodeInfoParserTest.java @@ -25,14 +25,18 @@ import com.google.protobuf.Descriptors.FileDescriptor; import com.google.protobuf.Descriptors.OneofDescriptor; import com.google.protobuf.Descriptors.ServiceDescriptor; -import java.io.FileInputStream; +import java.io.IOException; import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import org.junit.Before; import org.junit.Test; public class SourceCodeInfoParserTest { + private static final String BASIC_PROTO = "basic.proto"; private static final String PROTO_DESCRIPTOR_SET = "test-proto.descriptorset"; @@ -151,12 +155,7 @@ public void getOnoeofInfo() { * @return the top level target protoFile descriptor */ private static FileDescriptor buildFileDescriptor() throws Exception { - InputStream testProto = - SourceCodeInfoParserTest.class.getClassLoader().getResourceAsStream(PROTO_DESCRIPTOR_SET); - if (testProto == null) { // TODO: only for Bazel build. Remove when we don't build with Bazel. - testProto = new FileInputStream(PROTO_DESCRIPTOR_SET); - } - try (InputStream in = testProto) { + try (InputStream in = newDescriptorSetInputStream()) { List protoFileList = FileDescriptorSet.parseFrom(in).getFileList(); List deps = new ArrayList<>(); for (FileDescriptorProto proto : protoFileList) { @@ -170,4 +169,15 @@ private static FileDescriptor buildFileDescriptor() throws Exception { } return null; } + + private static InputStream newDescriptorSetInputStream() throws IOException { + Path path = + Paths.get("target/generated-test-resources/protobuf/descriptor-sets", PROTO_DESCRIPTOR_SET); + + if (path.toFile().exists()) { + return Files.newInputStream(path); + } + // TODO: only for Bazel build. Remove when we don't build with Bazel. + return Files.newInputStream(Paths.get(PROTO_DESCRIPTOR_SET)); + } } diff --git a/src/test/java/com/google/api/generator/test/framework/Utils.java b/src/test/java/com/google/api/generator/test/framework/Utils.java index cb423046fb..5960b722ef 100644 --- a/src/test/java/com/google/api/generator/test/framework/Utils.java +++ b/src/test/java/com/google/api/generator/test/framework/Utils.java @@ -20,6 +20,7 @@ import java.nio.file.Paths; public class Utils { + /** * Save the generated code from JUnit test to a file for updating goldens. The relative path * `com/google/..` which is identical with the location of goldens files which will help us easily @@ -74,6 +75,7 @@ public static String getGoldenDir(Class clazz) { } public static class SaveCodegenToFileException extends RuntimeException { + public SaveCodegenToFileException(String errorMessage) { super(errorMessage); } diff --git a/src/test/java/com/google/api/generator/util/TestUtils.java b/src/test/java/com/google/api/generator/util/TestUtils.java new file mode 100644 index 0000000000..ee509e0fee --- /dev/null +++ b/src/test/java/com/google/api/generator/util/TestUtils.java @@ -0,0 +1,42 @@ +// 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.util; + +import com.google.api.generator.engine.ast.StringObjectValue; +import com.google.api.generator.engine.ast.TypeNode; +import com.google.api.generator.engine.ast.TypeNode.TypeKind; +import com.google.api.generator.engine.ast.ValueExpr; +import com.google.api.generator.engine.ast.VaporReference; +import com.google.api.generator.engine.ast.Variable; +import com.google.api.generator.engine.ast.VariableExpr; + +public class TestUtils { + + public static ValueExpr generateStringValueExpr(String value) { + return ValueExpr.builder().setValue(StringObjectValue.withValue(value)).build(); + } + + public static VariableExpr generateClassValueExpr(String clazzName) { + return VariableExpr.builder() + .setVariable(Variable.builder().setType(TypeNode.CLASS_OBJECT).setName("class").build()) + .setStaticReferenceType( + TypeNode.builder() + .setReference( + VaporReference.builder().setName(clazzName).setPakkage("com.test").build()) + .setTypeKind(TypeKind.OBJECT) + .build()) + .build(); + } +} diff --git a/test/integration/BUILD.bazel b/test/integration/BUILD.bazel index 4597c5ad35..a79cc24124 100644 --- a/test/integration/BUILD.bazel +++ b/test/integration/BUILD.bazel @@ -14,6 +14,8 @@ load("@rules_proto//proto:defs.bzl", "proto_library") API_GAPIC_TARGETS = { # basic case "asset": "@com_google_googleapis//google/cloud/asset/v1:asset_java_gapic", + # Showcase provides wide feature set coverage. + "showcase": "//test/showcase:showcase_java_gapic", # Check that the capital name edge case is handled. "credentials": "@com_google_googleapis//google/iam/credentials/v1:credentials_java_gapic", # Mixin-only special-case API can build on its own. @@ -49,8 +51,8 @@ API_GAPIC_TARGETS = { srcs = ["//scripts:diff_gen_and_golden.sh"], args = [lib_name], data = [ - ":%s_goldens_files" % lib_name, - "%s_srcjar_raw.srcjar" % gapic_target, + ":%s_goldens_files" % lib_name, + "%s_srcjar_raw.srcjar" % gapic_target, ], ) for lib_name, gapic_target in API_GAPIC_TARGETS.items()] @@ -59,8 +61,8 @@ API_GAPIC_TARGETS = { srcs = ["//scripts:update_golden.sh"], args = [lib_name], data = [ - ":%s_goldens_files" % lib_name, - "%s_srcjar_raw.srcjar" % gapic_target, + ":%s_goldens_files" % lib_name, + "%s_srcjar_raw.srcjar" % gapic_target, ], ) for lib_name, gapic_target in API_GAPIC_TARGETS.items()] @@ -76,6 +78,20 @@ java_gapic_test( runtime_deps = ["@com_google_googleapis//google/cloud/asset/v1:asset_java_gapic_test"], ) +# Showcase API. +java_gapic_test( + name = "showcase_java_gapic_test_suite", + test_classes = [ + "com.google.showcase.v1beta1.ComplianceClientTest", + "com.google.showcase.v1beta1.EchoClientTest", + "com.google.showcase.v1beta1.IdentityClientTest", + "com.google.showcase.v1beta1.MessagingClientTest", + "com.google.showcase.v1beta1.SequenceServiceClientTest", + "com.google.showcase.v1beta1.TestingClientTest", + ], + runtime_deps = ["//test/showcase:showcase_java_gapic_test"], +) + # Redis API. java_gapic_test( name = "redis_java_gapic_test_suite", diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/create/SyncCreateSetCredentialsProvider.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/create/SyncCreateSetCredentialsProvider.java new file mode 100644 index 0000000000..46846134bb --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/create/SyncCreateSetCredentialsProvider.java @@ -0,0 +1,44 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Compliance_Create_SetCredentialsProvider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.showcase.v1beta1.ComplianceClient; +import com.google.showcase.v1beta1.ComplianceSettings; +import com.google.showcase.v1beta1.myCredentials; + +public class SyncCreateSetCredentialsProvider { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider(); + } + + public static void syncCreateSetCredentialsProvider() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + ComplianceSettings complianceSettings = + ComplianceSettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + ComplianceClient complianceClient = ComplianceClient.create(complianceSettings); + } +} +// [END localhost7469_v1beta1_generated_Compliance_Create_SetCredentialsProvider_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/create/SyncCreateSetCredentialsProvider1.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 0000000000..f28602378a --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/create/SyncCreateSetCredentialsProvider1.java @@ -0,0 +1,39 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Compliance_Create_SetCredentialsProvider1_sync] +import com.google.showcase.v1beta1.ComplianceClient; +import com.google.showcase.v1beta1.ComplianceSettings; + +public class SyncCreateSetCredentialsProvider1 { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider1(); + } + + public static void syncCreateSetCredentialsProvider1() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + ComplianceSettings complianceSettings = ComplianceSettings.newHttpJsonBuilder().build(); + ComplianceClient complianceClient = ComplianceClient.create(complianceSettings); + } +} +// [END localhost7469_v1beta1_generated_Compliance_Create_SetCredentialsProvider1_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/create/SyncCreateSetEndpoint.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/create/SyncCreateSetEndpoint.java new file mode 100644 index 0000000000..40b937f7f3 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/create/SyncCreateSetEndpoint.java @@ -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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Compliance_Create_SetEndpoint_sync] +import com.google.showcase.v1beta1.ComplianceClient; +import com.google.showcase.v1beta1.ComplianceSettings; +import com.google.showcase.v1beta1.myEndpoint; + +public class SyncCreateSetEndpoint { + + public static void main(String[] args) throws Exception { + syncCreateSetEndpoint(); + } + + public static void syncCreateSetEndpoint() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + ComplianceSettings complianceSettings = + ComplianceSettings.newBuilder().setEndpoint(myEndpoint).build(); + ComplianceClient complianceClient = ComplianceClient.create(complianceSettings); + } +} +// [END localhost7469_v1beta1_generated_Compliance_Create_SetEndpoint_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/getenum/AsyncGetEnum.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/getenum/AsyncGetEnum.java new file mode 100644 index 0000000000..464c666e72 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/getenum/AsyncGetEnum.java @@ -0,0 +1,45 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Compliance_GetEnum_async] +import com.google.api.core.ApiFuture; +import com.google.showcase.v1beta1.ComplianceClient; +import com.google.showcase.v1beta1.EnumRequest; +import com.google.showcase.v1beta1.EnumResponse; + +public class AsyncGetEnum { + + public static void main(String[] args) throws Exception { + asyncGetEnum(); + } + + public static void asyncGetEnum() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (ComplianceClient complianceClient = ComplianceClient.create()) { + EnumRequest request = EnumRequest.newBuilder().setUnknownEnum(true).build(); + ApiFuture future = complianceClient.getEnumCallable().futureCall(request); + // Do something. + EnumResponse response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Compliance_GetEnum_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/getenum/SyncGetEnum.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/getenum/SyncGetEnum.java new file mode 100644 index 0000000000..25e134f2a3 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/getenum/SyncGetEnum.java @@ -0,0 +1,42 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Compliance_GetEnum_sync] +import com.google.showcase.v1beta1.ComplianceClient; +import com.google.showcase.v1beta1.EnumRequest; +import com.google.showcase.v1beta1.EnumResponse; + +public class SyncGetEnum { + + public static void main(String[] args) throws Exception { + syncGetEnum(); + } + + public static void syncGetEnum() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (ComplianceClient complianceClient = ComplianceClient.create()) { + EnumRequest request = EnumRequest.newBuilder().setUnknownEnum(true).build(); + EnumResponse response = complianceClient.getEnum(request); + } + } +} +// [END localhost7469_v1beta1_generated_Compliance_GetEnum_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatabody/AsyncRepeatDataBody.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatabody/AsyncRepeatDataBody.java new file mode 100644 index 0000000000..02379d2e01 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatabody/AsyncRepeatDataBody.java @@ -0,0 +1,59 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Compliance_RepeatDataBody_async] +import com.google.api.core.ApiFuture; +import com.google.showcase.v1beta1.ComplianceClient; +import com.google.showcase.v1beta1.ComplianceData; +import com.google.showcase.v1beta1.RepeatRequest; +import com.google.showcase.v1beta1.RepeatResponse; + +public class AsyncRepeatDataBody { + + public static void main(String[] args) throws Exception { + asyncRepeatDataBody(); + } + + public static void asyncRepeatDataBody() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (ComplianceClient complianceClient = ComplianceClient.create()) { + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + ApiFuture future = + complianceClient.repeatDataBodyCallable().futureCall(request); + // Do something. + RepeatResponse response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Compliance_RepeatDataBody_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatabody/SyncRepeatDataBody.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatabody/SyncRepeatDataBody.java new file mode 100644 index 0000000000..9769ea47da --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatabody/SyncRepeatDataBody.java @@ -0,0 +1,55 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Compliance_RepeatDataBody_sync] +import com.google.showcase.v1beta1.ComplianceClient; +import com.google.showcase.v1beta1.ComplianceData; +import com.google.showcase.v1beta1.RepeatRequest; +import com.google.showcase.v1beta1.RepeatResponse; + +public class SyncRepeatDataBody { + + public static void main(String[] args) throws Exception { + syncRepeatDataBody(); + } + + public static void syncRepeatDataBody() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (ComplianceClient complianceClient = ComplianceClient.create()) { + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + RepeatResponse response = complianceClient.repeatDataBody(request); + } + } +} +// [END localhost7469_v1beta1_generated_Compliance_RepeatDataBody_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatabodyinfo/AsyncRepeatDataBodyInfo.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatabodyinfo/AsyncRepeatDataBodyInfo.java new file mode 100644 index 0000000000..80138be72f --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatabodyinfo/AsyncRepeatDataBodyInfo.java @@ -0,0 +1,59 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Compliance_RepeatDataBodyInfo_async] +import com.google.api.core.ApiFuture; +import com.google.showcase.v1beta1.ComplianceClient; +import com.google.showcase.v1beta1.ComplianceData; +import com.google.showcase.v1beta1.RepeatRequest; +import com.google.showcase.v1beta1.RepeatResponse; + +public class AsyncRepeatDataBodyInfo { + + public static void main(String[] args) throws Exception { + asyncRepeatDataBodyInfo(); + } + + public static void asyncRepeatDataBodyInfo() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (ComplianceClient complianceClient = ComplianceClient.create()) { + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + ApiFuture future = + complianceClient.repeatDataBodyInfoCallable().futureCall(request); + // Do something. + RepeatResponse response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Compliance_RepeatDataBodyInfo_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatabodyinfo/SyncRepeatDataBodyInfo.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatabodyinfo/SyncRepeatDataBodyInfo.java new file mode 100644 index 0000000000..c3b00bd27e --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatabodyinfo/SyncRepeatDataBodyInfo.java @@ -0,0 +1,55 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Compliance_RepeatDataBodyInfo_sync] +import com.google.showcase.v1beta1.ComplianceClient; +import com.google.showcase.v1beta1.ComplianceData; +import com.google.showcase.v1beta1.RepeatRequest; +import com.google.showcase.v1beta1.RepeatResponse; + +public class SyncRepeatDataBodyInfo { + + public static void main(String[] args) throws Exception { + syncRepeatDataBodyInfo(); + } + + public static void syncRepeatDataBodyInfo() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (ComplianceClient complianceClient = ComplianceClient.create()) { + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + RepeatResponse response = complianceClient.repeatDataBodyInfo(request); + } + } +} +// [END localhost7469_v1beta1_generated_Compliance_RepeatDataBodyInfo_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatabodypatch/AsyncRepeatDataBodyPatch.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatabodypatch/AsyncRepeatDataBodyPatch.java new file mode 100644 index 0000000000..d62dcd97b9 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatabodypatch/AsyncRepeatDataBodyPatch.java @@ -0,0 +1,59 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Compliance_RepeatDataBodyPatch_async] +import com.google.api.core.ApiFuture; +import com.google.showcase.v1beta1.ComplianceClient; +import com.google.showcase.v1beta1.ComplianceData; +import com.google.showcase.v1beta1.RepeatRequest; +import com.google.showcase.v1beta1.RepeatResponse; + +public class AsyncRepeatDataBodyPatch { + + public static void main(String[] args) throws Exception { + asyncRepeatDataBodyPatch(); + } + + public static void asyncRepeatDataBodyPatch() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (ComplianceClient complianceClient = ComplianceClient.create()) { + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + ApiFuture future = + complianceClient.repeatDataBodyPatchCallable().futureCall(request); + // Do something. + RepeatResponse response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Compliance_RepeatDataBodyPatch_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatabodypatch/SyncRepeatDataBodyPatch.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatabodypatch/SyncRepeatDataBodyPatch.java new file mode 100644 index 0000000000..1e53216e8d --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatabodypatch/SyncRepeatDataBodyPatch.java @@ -0,0 +1,55 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Compliance_RepeatDataBodyPatch_sync] +import com.google.showcase.v1beta1.ComplianceClient; +import com.google.showcase.v1beta1.ComplianceData; +import com.google.showcase.v1beta1.RepeatRequest; +import com.google.showcase.v1beta1.RepeatResponse; + +public class SyncRepeatDataBodyPatch { + + public static void main(String[] args) throws Exception { + syncRepeatDataBodyPatch(); + } + + public static void syncRepeatDataBodyPatch() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (ComplianceClient complianceClient = ComplianceClient.create()) { + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + RepeatResponse response = complianceClient.repeatDataBodyPatch(request); + } + } +} +// [END localhost7469_v1beta1_generated_Compliance_RepeatDataBodyPatch_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatabodyput/AsyncRepeatDataBodyPut.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatabodyput/AsyncRepeatDataBodyPut.java new file mode 100644 index 0000000000..61fb607032 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatabodyput/AsyncRepeatDataBodyPut.java @@ -0,0 +1,59 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Compliance_RepeatDataBodyPut_async] +import com.google.api.core.ApiFuture; +import com.google.showcase.v1beta1.ComplianceClient; +import com.google.showcase.v1beta1.ComplianceData; +import com.google.showcase.v1beta1.RepeatRequest; +import com.google.showcase.v1beta1.RepeatResponse; + +public class AsyncRepeatDataBodyPut { + + public static void main(String[] args) throws Exception { + asyncRepeatDataBodyPut(); + } + + public static void asyncRepeatDataBodyPut() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (ComplianceClient complianceClient = ComplianceClient.create()) { + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + ApiFuture future = + complianceClient.repeatDataBodyPutCallable().futureCall(request); + // Do something. + RepeatResponse response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Compliance_RepeatDataBodyPut_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatabodyput/SyncRepeatDataBodyPut.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatabodyput/SyncRepeatDataBodyPut.java new file mode 100644 index 0000000000..4f4d65a084 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatabodyput/SyncRepeatDataBodyPut.java @@ -0,0 +1,55 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Compliance_RepeatDataBodyPut_sync] +import com.google.showcase.v1beta1.ComplianceClient; +import com.google.showcase.v1beta1.ComplianceData; +import com.google.showcase.v1beta1.RepeatRequest; +import com.google.showcase.v1beta1.RepeatResponse; + +public class SyncRepeatDataBodyPut { + + public static void main(String[] args) throws Exception { + syncRepeatDataBodyPut(); + } + + public static void syncRepeatDataBodyPut() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (ComplianceClient complianceClient = ComplianceClient.create()) { + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + RepeatResponse response = complianceClient.repeatDataBodyPut(request); + } + } +} +// [END localhost7469_v1beta1_generated_Compliance_RepeatDataBodyPut_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatapathresource/AsyncRepeatDataPathResource.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatapathresource/AsyncRepeatDataPathResource.java new file mode 100644 index 0000000000..020978c742 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatapathresource/AsyncRepeatDataPathResource.java @@ -0,0 +1,59 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Compliance_RepeatDataPathResource_async] +import com.google.api.core.ApiFuture; +import com.google.showcase.v1beta1.ComplianceClient; +import com.google.showcase.v1beta1.ComplianceData; +import com.google.showcase.v1beta1.RepeatRequest; +import com.google.showcase.v1beta1.RepeatResponse; + +public class AsyncRepeatDataPathResource { + + public static void main(String[] args) throws Exception { + asyncRepeatDataPathResource(); + } + + public static void asyncRepeatDataPathResource() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (ComplianceClient complianceClient = ComplianceClient.create()) { + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + ApiFuture future = + complianceClient.repeatDataPathResourceCallable().futureCall(request); + // Do something. + RepeatResponse response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Compliance_RepeatDataPathResource_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatapathresource/SyncRepeatDataPathResource.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatapathresource/SyncRepeatDataPathResource.java new file mode 100644 index 0000000000..3a0e60981f --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatapathresource/SyncRepeatDataPathResource.java @@ -0,0 +1,55 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Compliance_RepeatDataPathResource_sync] +import com.google.showcase.v1beta1.ComplianceClient; +import com.google.showcase.v1beta1.ComplianceData; +import com.google.showcase.v1beta1.RepeatRequest; +import com.google.showcase.v1beta1.RepeatResponse; + +public class SyncRepeatDataPathResource { + + public static void main(String[] args) throws Exception { + syncRepeatDataPathResource(); + } + + public static void syncRepeatDataPathResource() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (ComplianceClient complianceClient = ComplianceClient.create()) { + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + RepeatResponse response = complianceClient.repeatDataPathResource(request); + } + } +} +// [END localhost7469_v1beta1_generated_Compliance_RepeatDataPathResource_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatapathtrailingresource/AsyncRepeatDataPathTrailingResource.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatapathtrailingresource/AsyncRepeatDataPathTrailingResource.java new file mode 100644 index 0000000000..1c3b305371 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatapathtrailingresource/AsyncRepeatDataPathTrailingResource.java @@ -0,0 +1,59 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Compliance_RepeatDataPathTrailingResource_async] +import com.google.api.core.ApiFuture; +import com.google.showcase.v1beta1.ComplianceClient; +import com.google.showcase.v1beta1.ComplianceData; +import com.google.showcase.v1beta1.RepeatRequest; +import com.google.showcase.v1beta1.RepeatResponse; + +public class AsyncRepeatDataPathTrailingResource { + + public static void main(String[] args) throws Exception { + asyncRepeatDataPathTrailingResource(); + } + + public static void asyncRepeatDataPathTrailingResource() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (ComplianceClient complianceClient = ComplianceClient.create()) { + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + ApiFuture future = + complianceClient.repeatDataPathTrailingResourceCallable().futureCall(request); + // Do something. + RepeatResponse response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Compliance_RepeatDataPathTrailingResource_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatapathtrailingresource/SyncRepeatDataPathTrailingResource.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatapathtrailingresource/SyncRepeatDataPathTrailingResource.java new file mode 100644 index 0000000000..73883a1773 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatapathtrailingresource/SyncRepeatDataPathTrailingResource.java @@ -0,0 +1,55 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Compliance_RepeatDataPathTrailingResource_sync] +import com.google.showcase.v1beta1.ComplianceClient; +import com.google.showcase.v1beta1.ComplianceData; +import com.google.showcase.v1beta1.RepeatRequest; +import com.google.showcase.v1beta1.RepeatResponse; + +public class SyncRepeatDataPathTrailingResource { + + public static void main(String[] args) throws Exception { + syncRepeatDataPathTrailingResource(); + } + + public static void syncRepeatDataPathTrailingResource() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (ComplianceClient complianceClient = ComplianceClient.create()) { + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + RepeatResponse response = complianceClient.repeatDataPathTrailingResource(request); + } + } +} +// [END localhost7469_v1beta1_generated_Compliance_RepeatDataPathTrailingResource_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdataquery/AsyncRepeatDataQuery.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdataquery/AsyncRepeatDataQuery.java new file mode 100644 index 0000000000..c174e28a01 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdataquery/AsyncRepeatDataQuery.java @@ -0,0 +1,59 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Compliance_RepeatDataQuery_async] +import com.google.api.core.ApiFuture; +import com.google.showcase.v1beta1.ComplianceClient; +import com.google.showcase.v1beta1.ComplianceData; +import com.google.showcase.v1beta1.RepeatRequest; +import com.google.showcase.v1beta1.RepeatResponse; + +public class AsyncRepeatDataQuery { + + public static void main(String[] args) throws Exception { + asyncRepeatDataQuery(); + } + + public static void asyncRepeatDataQuery() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (ComplianceClient complianceClient = ComplianceClient.create()) { + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + ApiFuture future = + complianceClient.repeatDataQueryCallable().futureCall(request); + // Do something. + RepeatResponse response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Compliance_RepeatDataQuery_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdataquery/SyncRepeatDataQuery.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdataquery/SyncRepeatDataQuery.java new file mode 100644 index 0000000000..2f4dd67b42 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdataquery/SyncRepeatDataQuery.java @@ -0,0 +1,55 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Compliance_RepeatDataQuery_sync] +import com.google.showcase.v1beta1.ComplianceClient; +import com.google.showcase.v1beta1.ComplianceData; +import com.google.showcase.v1beta1.RepeatRequest; +import com.google.showcase.v1beta1.RepeatResponse; + +public class SyncRepeatDataQuery { + + public static void main(String[] args) throws Exception { + syncRepeatDataQuery(); + } + + public static void syncRepeatDataQuery() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (ComplianceClient complianceClient = ComplianceClient.create()) { + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + RepeatResponse response = complianceClient.repeatDataQuery(request); + } + } +} +// [END localhost7469_v1beta1_generated_Compliance_RepeatDataQuery_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatasimplepath/AsyncRepeatDataSimplePath.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatasimplepath/AsyncRepeatDataSimplePath.java new file mode 100644 index 0000000000..ff20f79853 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatasimplepath/AsyncRepeatDataSimplePath.java @@ -0,0 +1,59 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Compliance_RepeatDataSimplePath_async] +import com.google.api.core.ApiFuture; +import com.google.showcase.v1beta1.ComplianceClient; +import com.google.showcase.v1beta1.ComplianceData; +import com.google.showcase.v1beta1.RepeatRequest; +import com.google.showcase.v1beta1.RepeatResponse; + +public class AsyncRepeatDataSimplePath { + + public static void main(String[] args) throws Exception { + asyncRepeatDataSimplePath(); + } + + public static void asyncRepeatDataSimplePath() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (ComplianceClient complianceClient = ComplianceClient.create()) { + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + ApiFuture future = + complianceClient.repeatDataSimplePathCallable().futureCall(request); + // Do something. + RepeatResponse response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Compliance_RepeatDataSimplePath_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatasimplepath/SyncRepeatDataSimplePath.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatasimplepath/SyncRepeatDataSimplePath.java new file mode 100644 index 0000000000..4cec930750 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/repeatdatasimplepath/SyncRepeatDataSimplePath.java @@ -0,0 +1,55 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Compliance_RepeatDataSimplePath_sync] +import com.google.showcase.v1beta1.ComplianceClient; +import com.google.showcase.v1beta1.ComplianceData; +import com.google.showcase.v1beta1.RepeatRequest; +import com.google.showcase.v1beta1.RepeatResponse; + +public class SyncRepeatDataSimplePath { + + public static void main(String[] args) throws Exception { + syncRepeatDataSimplePath(); + } + + public static void syncRepeatDataSimplePath() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (ComplianceClient complianceClient = ComplianceClient.create()) { + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + RepeatResponse response = complianceClient.repeatDataSimplePath(request); + } + } +} +// [END localhost7469_v1beta1_generated_Compliance_RepeatDataSimplePath_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/verifyenum/AsyncVerifyEnum.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/verifyenum/AsyncVerifyEnum.java new file mode 100644 index 0000000000..ceae5e5edc --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/verifyenum/AsyncVerifyEnum.java @@ -0,0 +1,50 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Compliance_VerifyEnum_async] +import com.google.api.core.ApiFuture; +import com.google.showcase.v1beta1.ComplianceClient; +import com.google.showcase.v1beta1.Continent; +import com.google.showcase.v1beta1.EnumRequest; +import com.google.showcase.v1beta1.EnumResponse; + +public class AsyncVerifyEnum { + + public static void main(String[] args) throws Exception { + asyncVerifyEnum(); + } + + public static void asyncVerifyEnum() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (ComplianceClient complianceClient = ComplianceClient.create()) { + EnumResponse request = + EnumResponse.newBuilder() + .setRequest(EnumRequest.newBuilder().build()) + .setContinent(Continent.forNumber(0)) + .build(); + ApiFuture future = complianceClient.verifyEnumCallable().futureCall(request); + // Do something. + EnumResponse response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Compliance_VerifyEnum_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/verifyenum/SyncVerifyEnum.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/verifyenum/SyncVerifyEnum.java new file mode 100644 index 0000000000..cf742f475d --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliance/verifyenum/SyncVerifyEnum.java @@ -0,0 +1,47 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Compliance_VerifyEnum_sync] +import com.google.showcase.v1beta1.ComplianceClient; +import com.google.showcase.v1beta1.Continent; +import com.google.showcase.v1beta1.EnumRequest; +import com.google.showcase.v1beta1.EnumResponse; + +public class SyncVerifyEnum { + + public static void main(String[] args) throws Exception { + syncVerifyEnum(); + } + + public static void syncVerifyEnum() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (ComplianceClient complianceClient = ComplianceClient.create()) { + EnumResponse request = + EnumResponse.newBuilder() + .setRequest(EnumRequest.newBuilder().build()) + .setContinent(Continent.forNumber(0)) + .build(); + EnumResponse response = complianceClient.verifyEnum(request); + } + } +} +// [END localhost7469_v1beta1_generated_Compliance_VerifyEnum_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliancesettings/repeatdatabody/SyncRepeatDataBody.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliancesettings/repeatdatabody/SyncRepeatDataBody.java new file mode 100644 index 0000000000..50c6680f41 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/compliancesettings/repeatdatabody/SyncRepeatDataBody.java @@ -0,0 +1,48 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_ComplianceSettings_RepeatDataBody_sync] +import com.google.showcase.v1beta1.ComplianceSettings; +import java.time.Duration; + +public class SyncRepeatDataBody { + + public static void main(String[] args) throws Exception { + syncRepeatDataBody(); + } + + public static void syncRepeatDataBody() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + ComplianceSettings.Builder complianceSettingsBuilder = ComplianceSettings.newBuilder(); + complianceSettingsBuilder + .repeatDataBodySettings() + .setRetrySettings( + complianceSettingsBuilder + .repeatDataBodySettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + ComplianceSettings complianceSettings = complianceSettingsBuilder.build(); + } +} +// [END localhost7469_v1beta1_generated_ComplianceSettings_RepeatDataBody_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/block/AsyncBlock.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/block/AsyncBlock.java new file mode 100644 index 0000000000..5d1e13ec6b --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/block/AsyncBlock.java @@ -0,0 +1,47 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Echo_Block_async] +import com.google.api.core.ApiFuture; +import com.google.protobuf.Duration; +import com.google.showcase.v1beta1.BlockRequest; +import com.google.showcase.v1beta1.BlockResponse; +import com.google.showcase.v1beta1.EchoClient; + +public class AsyncBlock { + + public static void main(String[] args) throws Exception { + asyncBlock(); + } + + public static void asyncBlock() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoClient echoClient = EchoClient.create()) { + BlockRequest request = + BlockRequest.newBuilder().setResponseDelay(Duration.newBuilder().build()).build(); + ApiFuture future = echoClient.blockCallable().futureCall(request); + // Do something. + BlockResponse response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Echo_Block_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/block/SyncBlock.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/block/SyncBlock.java new file mode 100644 index 0000000000..33e753f91c --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/block/SyncBlock.java @@ -0,0 +1,44 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Echo_Block_sync] +import com.google.protobuf.Duration; +import com.google.showcase.v1beta1.BlockRequest; +import com.google.showcase.v1beta1.BlockResponse; +import com.google.showcase.v1beta1.EchoClient; + +public class SyncBlock { + + public static void main(String[] args) throws Exception { + syncBlock(); + } + + public static void syncBlock() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoClient echoClient = EchoClient.create()) { + BlockRequest request = + BlockRequest.newBuilder().setResponseDelay(Duration.newBuilder().build()).build(); + BlockResponse response = echoClient.block(request); + } + } +} +// [END localhost7469_v1beta1_generated_Echo_Block_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/chat/AsyncChat.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/chat/AsyncChat.java new file mode 100644 index 0000000000..fc7ae4a2fd --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/chat/AsyncChat.java @@ -0,0 +1,53 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Echo_Chat_async] +import com.google.api.gax.rpc.BidiStream; +import com.google.showcase.v1beta1.EchoClient; +import com.google.showcase.v1beta1.EchoRequest; +import com.google.showcase.v1beta1.EchoResponse; +import com.google.showcase.v1beta1.Severity; + +public class AsyncChat { + + public static void main(String[] args) throws Exception { + asyncChat(); + } + + public static void asyncChat() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoClient echoClient = EchoClient.create()) { + BidiStream bidiStream = echoClient.chatCallable().call(); + EchoRequest request = + EchoRequest.newBuilder() + .setSeverity(Severity.forNumber(0)) + .setHeader("header-1221270899") + .setOtherHeader("otherHeader-2026585667") + .build(); + bidiStream.send(request); + for (EchoResponse response : bidiStream) { + // Do something when a response is received. + } + } + } +} +// [END localhost7469_v1beta1_generated_Echo_Chat_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/collect/AsyncCollect.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/collect/AsyncCollect.java new file mode 100644 index 0000000000..faace6e726 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/collect/AsyncCollect.java @@ -0,0 +1,68 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Echo_Collect_async] +import com.google.api.gax.rpc.ApiStreamObserver; +import com.google.showcase.v1beta1.EchoClient; +import com.google.showcase.v1beta1.EchoRequest; +import com.google.showcase.v1beta1.EchoResponse; +import com.google.showcase.v1beta1.Severity; + +public class AsyncCollect { + + public static void main(String[] args) throws Exception { + asyncCollect(); + } + + public static void asyncCollect() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoClient echoClient = EchoClient.create()) { + ApiStreamObserver responseObserver = + new ApiStreamObserver() { + @Override + public void onNext(EchoResponse response) { + // Do something when a response is received. + } + + @Override + public void onError(Throwable t) { + // Add error-handling + } + + @Override + public void onCompleted() { + // Do something when complete. + } + }; + ApiStreamObserver requestObserver = + echoClient.collect().clientStreamingCall(responseObserver); + EchoRequest request = + EchoRequest.newBuilder() + .setSeverity(Severity.forNumber(0)) + .setHeader("header-1221270899") + .setOtherHeader("otherHeader-2026585667") + .build(); + requestObserver.onNext(request); + } + } +} +// [END localhost7469_v1beta1_generated_Echo_Collect_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/create/SyncCreateSetCredentialsProvider.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/create/SyncCreateSetCredentialsProvider.java new file mode 100644 index 0000000000..a9ebbf7ae9 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/create/SyncCreateSetCredentialsProvider.java @@ -0,0 +1,44 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Echo_Create_SetCredentialsProvider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.showcase.v1beta1.EchoClient; +import com.google.showcase.v1beta1.EchoSettings; +import com.google.showcase.v1beta1.myCredentials; + +public class SyncCreateSetCredentialsProvider { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider(); + } + + public static void syncCreateSetCredentialsProvider() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + EchoSettings echoSettings = + EchoSettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + EchoClient echoClient = EchoClient.create(echoSettings); + } +} +// [END localhost7469_v1beta1_generated_Echo_Create_SetCredentialsProvider_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/create/SyncCreateSetCredentialsProvider1.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 0000000000..cb6c708da6 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/create/SyncCreateSetCredentialsProvider1.java @@ -0,0 +1,39 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Echo_Create_SetCredentialsProvider1_sync] +import com.google.showcase.v1beta1.EchoClient; +import com.google.showcase.v1beta1.EchoSettings; + +public class SyncCreateSetCredentialsProvider1 { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider1(); + } + + public static void syncCreateSetCredentialsProvider1() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + EchoSettings echoSettings = EchoSettings.newHttpJsonBuilder().build(); + EchoClient echoClient = EchoClient.create(echoSettings); + } +} +// [END localhost7469_v1beta1_generated_Echo_Create_SetCredentialsProvider1_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/create/SyncCreateSetEndpoint.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/create/SyncCreateSetEndpoint.java new file mode 100644 index 0000000000..ad36585408 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/create/SyncCreateSetEndpoint.java @@ -0,0 +1,40 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Echo_Create_SetEndpoint_sync] +import com.google.showcase.v1beta1.EchoClient; +import com.google.showcase.v1beta1.EchoSettings; +import com.google.showcase.v1beta1.myEndpoint; + +public class SyncCreateSetEndpoint { + + public static void main(String[] args) throws Exception { + syncCreateSetEndpoint(); + } + + public static void syncCreateSetEndpoint() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + EchoSettings echoSettings = EchoSettings.newBuilder().setEndpoint(myEndpoint).build(); + EchoClient echoClient = EchoClient.create(echoSettings); + } +} +// [END localhost7469_v1beta1_generated_Echo_Create_SetEndpoint_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/echo/AsyncEcho.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/echo/AsyncEcho.java new file mode 100644 index 0000000000..705e8c273b --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/echo/AsyncEcho.java @@ -0,0 +1,51 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Echo_Echo_async] +import com.google.api.core.ApiFuture; +import com.google.showcase.v1beta1.EchoClient; +import com.google.showcase.v1beta1.EchoRequest; +import com.google.showcase.v1beta1.EchoResponse; +import com.google.showcase.v1beta1.Severity; + +public class AsyncEcho { + + public static void main(String[] args) throws Exception { + asyncEcho(); + } + + public static void asyncEcho() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoClient echoClient = EchoClient.create()) { + EchoRequest request = + EchoRequest.newBuilder() + .setSeverity(Severity.forNumber(0)) + .setHeader("header-1221270899") + .setOtherHeader("otherHeader-2026585667") + .build(); + ApiFuture future = echoClient.echoCallable().futureCall(request); + // Do something. + EchoResponse response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Echo_Echo_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/echo/SyncEcho.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/echo/SyncEcho.java new file mode 100644 index 0000000000..37388425b1 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/echo/SyncEcho.java @@ -0,0 +1,48 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Echo_Echo_sync] +import com.google.showcase.v1beta1.EchoClient; +import com.google.showcase.v1beta1.EchoRequest; +import com.google.showcase.v1beta1.EchoResponse; +import com.google.showcase.v1beta1.Severity; + +public class SyncEcho { + + public static void main(String[] args) throws Exception { + syncEcho(); + } + + public static void syncEcho() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoClient echoClient = EchoClient.create()) { + EchoRequest request = + EchoRequest.newBuilder() + .setSeverity(Severity.forNumber(0)) + .setHeader("header-1221270899") + .setOtherHeader("otherHeader-2026585667") + .build(); + EchoResponse response = echoClient.echo(request); + } + } +} +// [END localhost7469_v1beta1_generated_Echo_Echo_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/expand/AsyncExpand.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/expand/AsyncExpand.java new file mode 100644 index 0000000000..80c5f6d6b4 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/expand/AsyncExpand.java @@ -0,0 +1,51 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Echo_Expand_async] +import com.google.api.gax.rpc.ServerStream; +import com.google.rpc.Status; +import com.google.showcase.v1beta1.EchoClient; +import com.google.showcase.v1beta1.EchoResponse; +import com.google.showcase.v1beta1.ExpandRequest; + +public class AsyncExpand { + + public static void main(String[] args) throws Exception { + asyncExpand(); + } + + public static void asyncExpand() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoClient echoClient = EchoClient.create()) { + ExpandRequest request = + ExpandRequest.newBuilder() + .setContent("content951530617") + .setError(Status.newBuilder().build()) + .build(); + ServerStream stream = echoClient.expandCallable().call(request); + for (EchoResponse response : stream) { + // Do something when a response is received. + } + } + } +} +// [END localhost7469_v1beta1_generated_Echo_Expand_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/pagedexpand/AsyncPagedExpand.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/pagedexpand/AsyncPagedExpand.java new file mode 100644 index 0000000000..46257d1453 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/pagedexpand/AsyncPagedExpand.java @@ -0,0 +1,52 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Echo_PagedExpand_async] +import com.google.api.core.ApiFuture; +import com.google.showcase.v1beta1.EchoClient; +import com.google.showcase.v1beta1.EchoResponse; +import com.google.showcase.v1beta1.PagedExpandRequest; + +public class AsyncPagedExpand { + + public static void main(String[] args) throws Exception { + asyncPagedExpand(); + } + + public static void asyncPagedExpand() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoClient echoClient = EchoClient.create()) { + PagedExpandRequest request = + PagedExpandRequest.newBuilder() + .setContent("content951530617") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + ApiFuture future = echoClient.pagedExpandPagedCallable().futureCall(request); + // Do something. + for (EchoResponse element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END localhost7469_v1beta1_generated_Echo_PagedExpand_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/pagedexpand/AsyncPagedExpandPaged.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/pagedexpand/AsyncPagedExpandPaged.java new file mode 100644 index 0000000000..28a19a69af --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/pagedexpand/AsyncPagedExpandPaged.java @@ -0,0 +1,60 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Echo_PagedExpand_Paged_async] +import com.google.common.base.Strings; +import com.google.showcase.v1beta1.EchoClient; +import com.google.showcase.v1beta1.EchoResponse; +import com.google.showcase.v1beta1.PagedExpandRequest; +import com.google.showcase.v1beta1.PagedExpandResponse; + +public class AsyncPagedExpandPaged { + + public static void main(String[] args) throws Exception { + asyncPagedExpandPaged(); + } + + public static void asyncPagedExpandPaged() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoClient echoClient = EchoClient.create()) { + PagedExpandRequest request = + PagedExpandRequest.newBuilder() + .setContent("content951530617") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + while (true) { + PagedExpandResponse response = echoClient.pagedExpandCallable().call(request); + for (EchoResponse element : response.getResponsesList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END localhost7469_v1beta1_generated_Echo_PagedExpand_Paged_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/pagedexpand/SyncPagedExpand.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/pagedexpand/SyncPagedExpand.java new file mode 100644 index 0000000000..c9c1a85279 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/pagedexpand/SyncPagedExpand.java @@ -0,0 +1,49 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Echo_PagedExpand_sync] +import com.google.showcase.v1beta1.EchoClient; +import com.google.showcase.v1beta1.EchoResponse; +import com.google.showcase.v1beta1.PagedExpandRequest; + +public class SyncPagedExpand { + + public static void main(String[] args) throws Exception { + syncPagedExpand(); + } + + public static void syncPagedExpand() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoClient echoClient = EchoClient.create()) { + PagedExpandRequest request = + PagedExpandRequest.newBuilder() + .setContent("content951530617") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + for (EchoResponse element : echoClient.pagedExpand(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END localhost7469_v1beta1_generated_Echo_PagedExpand_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/pagedexpandlegacy/AsyncPagedExpandLegacy.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/pagedexpandlegacy/AsyncPagedExpandLegacy.java new file mode 100644 index 0000000000..624e4caec1 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/pagedexpandlegacy/AsyncPagedExpandLegacy.java @@ -0,0 +1,51 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Echo_PagedExpandLegacy_async] +import com.google.api.core.ApiFuture; +import com.google.showcase.v1beta1.EchoClient; +import com.google.showcase.v1beta1.PagedExpandLegacyRequest; +import com.google.showcase.v1beta1.PagedExpandResponse; + +public class AsyncPagedExpandLegacy { + + public static void main(String[] args) throws Exception { + asyncPagedExpandLegacy(); + } + + public static void asyncPagedExpandLegacy() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoClient echoClient = EchoClient.create()) { + PagedExpandLegacyRequest request = + PagedExpandLegacyRequest.newBuilder() + .setContent("content951530617") + .setMaxResults(1128457243) + .setPageToken("pageToken873572522") + .build(); + ApiFuture future = + echoClient.pagedExpandLegacyCallable().futureCall(request); + // Do something. + PagedExpandResponse response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Echo_PagedExpandLegacy_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/pagedexpandlegacy/SyncPagedExpandLegacy.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/pagedexpandlegacy/SyncPagedExpandLegacy.java new file mode 100644 index 0000000000..c82b7bbae7 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/pagedexpandlegacy/SyncPagedExpandLegacy.java @@ -0,0 +1,47 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Echo_PagedExpandLegacy_sync] +import com.google.showcase.v1beta1.EchoClient; +import com.google.showcase.v1beta1.PagedExpandLegacyRequest; +import com.google.showcase.v1beta1.PagedExpandResponse; + +public class SyncPagedExpandLegacy { + + public static void main(String[] args) throws Exception { + syncPagedExpandLegacy(); + } + + public static void syncPagedExpandLegacy() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoClient echoClient = EchoClient.create()) { + PagedExpandLegacyRequest request = + PagedExpandLegacyRequest.newBuilder() + .setContent("content951530617") + .setMaxResults(1128457243) + .setPageToken("pageToken873572522") + .build(); + PagedExpandResponse response = echoClient.pagedExpandLegacy(request); + } + } +} +// [END localhost7469_v1beta1_generated_Echo_PagedExpandLegacy_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/pagedexpandlegacymapped/AsyncPagedExpandLegacyMapped.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/pagedexpandlegacymapped/AsyncPagedExpandLegacyMapped.java new file mode 100644 index 0000000000..be038a2fb5 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/pagedexpandlegacymapped/AsyncPagedExpandLegacyMapped.java @@ -0,0 +1,54 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Echo_PagedExpandLegacyMapped_async] +import com.google.api.core.ApiFuture; +import com.google.showcase.v1beta1.EchoClient; +import com.google.showcase.v1beta1.PagedExpandRequest; +import com.google.showcase.v1beta1.PagedExpandResponseList; +import java.util.Map; + +public class AsyncPagedExpandLegacyMapped { + + public static void main(String[] args) throws Exception { + asyncPagedExpandLegacyMapped(); + } + + public static void asyncPagedExpandLegacyMapped() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoClient echoClient = EchoClient.create()) { + PagedExpandRequest request = + PagedExpandRequest.newBuilder() + .setContent("content951530617") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + ApiFuture> future = + echoClient.pagedExpandLegacyMappedPagedCallable().futureCall(request); + // Do something. + for (Map.Entry element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END localhost7469_v1beta1_generated_Echo_PagedExpandLegacyMapped_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/pagedexpandlegacymapped/AsyncPagedExpandLegacyMappedPaged.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/pagedexpandlegacymapped/AsyncPagedExpandLegacyMappedPaged.java new file mode 100644 index 0000000000..538a3247e8 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/pagedexpandlegacymapped/AsyncPagedExpandLegacyMappedPaged.java @@ -0,0 +1,62 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Echo_PagedExpandLegacyMapped_Paged_async] +import com.google.common.base.Strings; +import com.google.showcase.v1beta1.EchoClient; +import com.google.showcase.v1beta1.PagedExpandLegacyMappedResponse; +import com.google.showcase.v1beta1.PagedExpandRequest; +import com.google.showcase.v1beta1.PagedExpandResponseList; +import java.util.Map; + +public class AsyncPagedExpandLegacyMappedPaged { + + public static void main(String[] args) throws Exception { + asyncPagedExpandLegacyMappedPaged(); + } + + public static void asyncPagedExpandLegacyMappedPaged() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoClient echoClient = EchoClient.create()) { + PagedExpandRequest request = + PagedExpandRequest.newBuilder() + .setContent("content951530617") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + while (true) { + PagedExpandLegacyMappedResponse response = + echoClient.pagedExpandLegacyMappedCallable().call(request); + for (Map.Entry element : response.getAlphabetizedList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END localhost7469_v1beta1_generated_Echo_PagedExpandLegacyMapped_Paged_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/pagedexpandlegacymapped/SyncPagedExpandLegacyMapped.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/pagedexpandlegacymapped/SyncPagedExpandLegacyMapped.java new file mode 100644 index 0000000000..2b644c8837 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/pagedexpandlegacymapped/SyncPagedExpandLegacyMapped.java @@ -0,0 +1,51 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Echo_PagedExpandLegacyMapped_sync] +import com.google.showcase.v1beta1.EchoClient; +import com.google.showcase.v1beta1.PagedExpandRequest; +import com.google.showcase.v1beta1.PagedExpandResponseList; +import java.util.Map; + +public class SyncPagedExpandLegacyMapped { + + public static void main(String[] args) throws Exception { + syncPagedExpandLegacyMapped(); + } + + public static void syncPagedExpandLegacyMapped() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoClient echoClient = EchoClient.create()) { + PagedExpandRequest request = + PagedExpandRequest.newBuilder() + .setContent("content951530617") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + for (Map.Entry element : + echoClient.pagedExpandLegacyMapped(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END localhost7469_v1beta1_generated_Echo_PagedExpandLegacyMapped_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/wait/AsyncWait.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/wait/AsyncWait.java new file mode 100644 index 0000000000..4fe1f78ed2 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/wait/AsyncWait.java @@ -0,0 +1,45 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Echo_Wait_async] +import com.google.api.core.ApiFuture; +import com.google.longrunning.Operation; +import com.google.showcase.v1beta1.EchoClient; +import com.google.showcase.v1beta1.WaitRequest; + +public class AsyncWait { + + public static void main(String[] args) throws Exception { + asyncWait(); + } + + public static void asyncWait() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoClient echoClient = EchoClient.create()) { + WaitRequest request = WaitRequest.newBuilder().build(); + ApiFuture future = echoClient.waitCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Echo_Wait_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/wait/AsyncWaitLRO.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/wait/AsyncWaitLRO.java new file mode 100644 index 0000000000..450ec96d94 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/wait/AsyncWaitLRO.java @@ -0,0 +1,47 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Echo_Wait_LRO_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.showcase.v1beta1.EchoClient; +import com.google.showcase.v1beta1.WaitMetadata; +import com.google.showcase.v1beta1.WaitRequest; +import com.google.showcase.v1beta1.WaitResponse; + +public class AsyncWaitLRO { + + public static void main(String[] args) throws Exception { + asyncWaitLRO(); + } + + public static void asyncWaitLRO() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoClient echoClient = EchoClient.create()) { + WaitRequest request = WaitRequest.newBuilder().build(); + OperationFuture future = + echoClient.waitOperationCallable().futureCall(request); + // Do something. + WaitResponse response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Echo_Wait_LRO_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/wait/SyncWait.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/wait/SyncWait.java new file mode 100644 index 0000000000..b79a0c4abe --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echo/wait/SyncWait.java @@ -0,0 +1,42 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Echo_Wait_sync] +import com.google.showcase.v1beta1.EchoClient; +import com.google.showcase.v1beta1.WaitRequest; +import com.google.showcase.v1beta1.WaitResponse; + +public class SyncWait { + + public static void main(String[] args) throws Exception { + syncWait(); + } + + public static void syncWait() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoClient echoClient = EchoClient.create()) { + WaitRequest request = WaitRequest.newBuilder().build(); + WaitResponse response = echoClient.waitAsync(request).get(); + } + } +} +// [END localhost7469_v1beta1_generated_Echo_Wait_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echosettings/echo/SyncEcho.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echosettings/echo/SyncEcho.java new file mode 100644 index 0000000000..8297f9021e --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/echosettings/echo/SyncEcho.java @@ -0,0 +1,48 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_EchoSettings_Echo_sync] +import com.google.showcase.v1beta1.EchoSettings; +import java.time.Duration; + +public class SyncEcho { + + public static void main(String[] args) throws Exception { + syncEcho(); + } + + public static void syncEcho() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + EchoSettings.Builder echoSettingsBuilder = EchoSettings.newBuilder(); + echoSettingsBuilder + .echoSettings() + .setRetrySettings( + echoSettingsBuilder + .echoSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + EchoSettings echoSettings = echoSettingsBuilder.build(); + } +} +// [END localhost7469_v1beta1_generated_EchoSettings_Echo_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/create/SyncCreateSetCredentialsProvider.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/create/SyncCreateSetCredentialsProvider.java new file mode 100644 index 0000000000..2ebcf3d498 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/create/SyncCreateSetCredentialsProvider.java @@ -0,0 +1,44 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Identity_Create_SetCredentialsProvider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.showcase.v1beta1.IdentityClient; +import com.google.showcase.v1beta1.IdentitySettings; +import com.google.showcase.v1beta1.myCredentials; + +public class SyncCreateSetCredentialsProvider { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider(); + } + + public static void syncCreateSetCredentialsProvider() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + IdentitySettings identitySettings = + IdentitySettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + IdentityClient identityClient = IdentityClient.create(identitySettings); + } +} +// [END localhost7469_v1beta1_generated_Identity_Create_SetCredentialsProvider_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/create/SyncCreateSetCredentialsProvider1.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 0000000000..4ef4b5c388 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/create/SyncCreateSetCredentialsProvider1.java @@ -0,0 +1,39 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Identity_Create_SetCredentialsProvider1_sync] +import com.google.showcase.v1beta1.IdentityClient; +import com.google.showcase.v1beta1.IdentitySettings; + +public class SyncCreateSetCredentialsProvider1 { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider1(); + } + + public static void syncCreateSetCredentialsProvider1() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + IdentitySettings identitySettings = IdentitySettings.newHttpJsonBuilder().build(); + IdentityClient identityClient = IdentityClient.create(identitySettings); + } +} +// [END localhost7469_v1beta1_generated_Identity_Create_SetCredentialsProvider1_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/create/SyncCreateSetEndpoint.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/create/SyncCreateSetEndpoint.java new file mode 100644 index 0000000000..56a9453ba2 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/create/SyncCreateSetEndpoint.java @@ -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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Identity_Create_SetEndpoint_sync] +import com.google.showcase.v1beta1.IdentityClient; +import com.google.showcase.v1beta1.IdentitySettings; +import com.google.showcase.v1beta1.myEndpoint; + +public class SyncCreateSetEndpoint { + + public static void main(String[] args) throws Exception { + syncCreateSetEndpoint(); + } + + public static void syncCreateSetEndpoint() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + IdentitySettings identitySettings = + IdentitySettings.newBuilder().setEndpoint(myEndpoint).build(); + IdentityClient identityClient = IdentityClient.create(identitySettings); + } +} +// [END localhost7469_v1beta1_generated_Identity_Create_SetEndpoint_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/createuser/AsyncCreateUser.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/createuser/AsyncCreateUser.java new file mode 100644 index 0000000000..6159e29f8b --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/createuser/AsyncCreateUser.java @@ -0,0 +1,46 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Identity_CreateUser_async] +import com.google.api.core.ApiFuture; +import com.google.showcase.v1beta1.CreateUserRequest; +import com.google.showcase.v1beta1.IdentityClient; +import com.google.showcase.v1beta1.User; + +public class AsyncCreateUser { + + public static void main(String[] args) throws Exception { + asyncCreateUser(); + } + + public static void asyncCreateUser() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (IdentityClient identityClient = IdentityClient.create()) { + CreateUserRequest request = + CreateUserRequest.newBuilder().setUser(User.newBuilder().build()).build(); + ApiFuture future = identityClient.createUserCallable().futureCall(request); + // Do something. + User response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Identity_CreateUser_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/createuser/SyncCreateUser.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/createuser/SyncCreateUser.java new file mode 100644 index 0000000000..efced6437d --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/createuser/SyncCreateUser.java @@ -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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Identity_CreateUser_sync] +import com.google.showcase.v1beta1.CreateUserRequest; +import com.google.showcase.v1beta1.IdentityClient; +import com.google.showcase.v1beta1.User; + +public class SyncCreateUser { + + public static void main(String[] args) throws Exception { + syncCreateUser(); + } + + public static void syncCreateUser() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (IdentityClient identityClient = IdentityClient.create()) { + CreateUserRequest request = + CreateUserRequest.newBuilder().setUser(User.newBuilder().build()).build(); + User response = identityClient.createUser(request); + } + } +} +// [END localhost7469_v1beta1_generated_Identity_CreateUser_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/createuser/SyncCreateUserStringString.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/createuser/SyncCreateUserStringString.java new file mode 100644 index 0000000000..54552b0fae --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/createuser/SyncCreateUserStringString.java @@ -0,0 +1,42 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Identity_CreateUser_StringString_sync] +import com.google.showcase.v1beta1.IdentityClient; +import com.google.showcase.v1beta1.User; + +public class SyncCreateUserStringString { + + public static void main(String[] args) throws Exception { + syncCreateUserStringString(); + } + + public static void syncCreateUserStringString() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (IdentityClient identityClient = IdentityClient.create()) { + String displayName = "displayName1714148973"; + String email = "email96619420"; + User response = identityClient.createUser(displayName, email); + } + } +} +// [END localhost7469_v1beta1_generated_Identity_CreateUser_StringString_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/createuser/SyncCreateUserStringStringIntStringBooleanDouble.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/createuser/SyncCreateUserStringStringIntStringBooleanDouble.java new file mode 100644 index 0000000000..61705d69f3 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/createuser/SyncCreateUserStringStringIntStringBooleanDouble.java @@ -0,0 +1,48 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Identity_CreateUser_StringStringIntStringBooleanDouble_sync] +import com.google.showcase.v1beta1.IdentityClient; +import com.google.showcase.v1beta1.User; + +public class SyncCreateUserStringStringIntStringBooleanDouble { + + public static void main(String[] args) throws Exception { + syncCreateUserStringStringIntStringBooleanDouble(); + } + + public static void syncCreateUserStringStringIntStringBooleanDouble() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (IdentityClient identityClient = IdentityClient.create()) { + String displayName = "displayName1714148973"; + String email = "email96619420"; + int age = 96511; + String nickname = "nickname70690926"; + boolean enableNotifications = true; + double heightFeet = -1032737338; + User response = + identityClient.createUser( + displayName, email, age, nickname, enableNotifications, heightFeet); + } + } +} +// [END localhost7469_v1beta1_generated_Identity_CreateUser_StringStringIntStringBooleanDouble_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/deleteuser/AsyncDeleteUser.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/deleteuser/AsyncDeleteUser.java new file mode 100644 index 0000000000..8d8de43b47 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/deleteuser/AsyncDeleteUser.java @@ -0,0 +1,47 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Identity_DeleteUser_async] +import com.google.api.core.ApiFuture; +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.DeleteUserRequest; +import com.google.showcase.v1beta1.IdentityClient; +import com.google.showcase.v1beta1.UserName; + +public class AsyncDeleteUser { + + public static void main(String[] args) throws Exception { + asyncDeleteUser(); + } + + public static void asyncDeleteUser() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (IdentityClient identityClient = IdentityClient.create()) { + DeleteUserRequest request = + DeleteUserRequest.newBuilder().setName(UserName.of("[USER]").toString()).build(); + ApiFuture future = identityClient.deleteUserCallable().futureCall(request); + // Do something. + future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Identity_DeleteUser_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/deleteuser/SyncDeleteUser.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/deleteuser/SyncDeleteUser.java new file mode 100644 index 0000000000..9bdce522e9 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/deleteuser/SyncDeleteUser.java @@ -0,0 +1,44 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Identity_DeleteUser_sync] +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.DeleteUserRequest; +import com.google.showcase.v1beta1.IdentityClient; +import com.google.showcase.v1beta1.UserName; + +public class SyncDeleteUser { + + public static void main(String[] args) throws Exception { + syncDeleteUser(); + } + + public static void syncDeleteUser() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (IdentityClient identityClient = IdentityClient.create()) { + DeleteUserRequest request = + DeleteUserRequest.newBuilder().setName(UserName.of("[USER]").toString()).build(); + identityClient.deleteUser(request); + } + } +} +// [END localhost7469_v1beta1_generated_Identity_DeleteUser_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/deleteuser/SyncDeleteUserString.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/deleteuser/SyncDeleteUserString.java new file mode 100644 index 0000000000..bb894748d3 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/deleteuser/SyncDeleteUserString.java @@ -0,0 +1,42 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Identity_DeleteUser_String_sync] +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.IdentityClient; +import com.google.showcase.v1beta1.UserName; + +public class SyncDeleteUserString { + + public static void main(String[] args) throws Exception { + syncDeleteUserString(); + } + + public static void syncDeleteUserString() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (IdentityClient identityClient = IdentityClient.create()) { + String name = UserName.of("[USER]").toString(); + identityClient.deleteUser(name); + } + } +} +// [END localhost7469_v1beta1_generated_Identity_DeleteUser_String_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/deleteuser/SyncDeleteUserUsername.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/deleteuser/SyncDeleteUserUsername.java new file mode 100644 index 0000000000..b61c33d83c --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/deleteuser/SyncDeleteUserUsername.java @@ -0,0 +1,42 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Identity_DeleteUser_Username_sync] +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.IdentityClient; +import com.google.showcase.v1beta1.UserName; + +public class SyncDeleteUserUsername { + + public static void main(String[] args) throws Exception { + syncDeleteUserUsername(); + } + + public static void syncDeleteUserUsername() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (IdentityClient identityClient = IdentityClient.create()) { + UserName name = UserName.of("[USER]"); + identityClient.deleteUser(name); + } + } +} +// [END localhost7469_v1beta1_generated_Identity_DeleteUser_Username_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/getuser/AsyncGetUser.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/getuser/AsyncGetUser.java new file mode 100644 index 0000000000..640d726784 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/getuser/AsyncGetUser.java @@ -0,0 +1,47 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Identity_GetUser_async] +import com.google.api.core.ApiFuture; +import com.google.showcase.v1beta1.GetUserRequest; +import com.google.showcase.v1beta1.IdentityClient; +import com.google.showcase.v1beta1.User; +import com.google.showcase.v1beta1.UserName; + +public class AsyncGetUser { + + public static void main(String[] args) throws Exception { + asyncGetUser(); + } + + public static void asyncGetUser() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (IdentityClient identityClient = IdentityClient.create()) { + GetUserRequest request = + GetUserRequest.newBuilder().setName(UserName.of("[USER]").toString()).build(); + ApiFuture future = identityClient.getUserCallable().futureCall(request); + // Do something. + User response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Identity_GetUser_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/getuser/SyncGetUser.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/getuser/SyncGetUser.java new file mode 100644 index 0000000000..9e6adc257c --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/getuser/SyncGetUser.java @@ -0,0 +1,44 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Identity_GetUser_sync] +import com.google.showcase.v1beta1.GetUserRequest; +import com.google.showcase.v1beta1.IdentityClient; +import com.google.showcase.v1beta1.User; +import com.google.showcase.v1beta1.UserName; + +public class SyncGetUser { + + public static void main(String[] args) throws Exception { + syncGetUser(); + } + + public static void syncGetUser() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (IdentityClient identityClient = IdentityClient.create()) { + GetUserRequest request = + GetUserRequest.newBuilder().setName(UserName.of("[USER]").toString()).build(); + User response = identityClient.getUser(request); + } + } +} +// [END localhost7469_v1beta1_generated_Identity_GetUser_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/getuser/SyncGetUserString.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/getuser/SyncGetUserString.java new file mode 100644 index 0000000000..3443054f45 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/getuser/SyncGetUserString.java @@ -0,0 +1,42 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Identity_GetUser_String_sync] +import com.google.showcase.v1beta1.IdentityClient; +import com.google.showcase.v1beta1.User; +import com.google.showcase.v1beta1.UserName; + +public class SyncGetUserString { + + public static void main(String[] args) throws Exception { + syncGetUserString(); + } + + public static void syncGetUserString() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (IdentityClient identityClient = IdentityClient.create()) { + String name = UserName.of("[USER]").toString(); + User response = identityClient.getUser(name); + } + } +} +// [END localhost7469_v1beta1_generated_Identity_GetUser_String_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/getuser/SyncGetUserUsername.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/getuser/SyncGetUserUsername.java new file mode 100644 index 0000000000..53313b1f09 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/getuser/SyncGetUserUsername.java @@ -0,0 +1,42 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Identity_GetUser_Username_sync] +import com.google.showcase.v1beta1.IdentityClient; +import com.google.showcase.v1beta1.User; +import com.google.showcase.v1beta1.UserName; + +public class SyncGetUserUsername { + + public static void main(String[] args) throws Exception { + syncGetUserUsername(); + } + + public static void syncGetUserUsername() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (IdentityClient identityClient = IdentityClient.create()) { + UserName name = UserName.of("[USER]"); + User response = identityClient.getUser(name); + } + } +} +// [END localhost7469_v1beta1_generated_Identity_GetUser_Username_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/listusers/AsyncListUsers.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/listusers/AsyncListUsers.java new file mode 100644 index 0000000000..b72d2c1f7f --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/listusers/AsyncListUsers.java @@ -0,0 +1,51 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Identity_ListUsers_async] +import com.google.api.core.ApiFuture; +import com.google.showcase.v1beta1.IdentityClient; +import com.google.showcase.v1beta1.ListUsersRequest; +import com.google.showcase.v1beta1.User; + +public class AsyncListUsers { + + public static void main(String[] args) throws Exception { + asyncListUsers(); + } + + public static void asyncListUsers() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (IdentityClient identityClient = IdentityClient.create()) { + ListUsersRequest request = + ListUsersRequest.newBuilder() + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + ApiFuture future = identityClient.listUsersPagedCallable().futureCall(request); + // Do something. + for (User element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END localhost7469_v1beta1_generated_Identity_ListUsers_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/listusers/AsyncListUsersPaged.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/listusers/AsyncListUsersPaged.java new file mode 100644 index 0000000000..50351698b4 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/listusers/AsyncListUsersPaged.java @@ -0,0 +1,59 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Identity_ListUsers_Paged_async] +import com.google.common.base.Strings; +import com.google.showcase.v1beta1.IdentityClient; +import com.google.showcase.v1beta1.ListUsersRequest; +import com.google.showcase.v1beta1.ListUsersResponse; +import com.google.showcase.v1beta1.User; + +public class AsyncListUsersPaged { + + public static void main(String[] args) throws Exception { + asyncListUsersPaged(); + } + + public static void asyncListUsersPaged() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (IdentityClient identityClient = IdentityClient.create()) { + ListUsersRequest request = + ListUsersRequest.newBuilder() + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + while (true) { + ListUsersResponse response = identityClient.listUsersCallable().call(request); + for (User element : response.getUsersList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END localhost7469_v1beta1_generated_Identity_ListUsers_Paged_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/listusers/SyncListUsers.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/listusers/SyncListUsers.java new file mode 100644 index 0000000000..ea0578c12a --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/listusers/SyncListUsers.java @@ -0,0 +1,48 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Identity_ListUsers_sync] +import com.google.showcase.v1beta1.IdentityClient; +import com.google.showcase.v1beta1.ListUsersRequest; +import com.google.showcase.v1beta1.User; + +public class SyncListUsers { + + public static void main(String[] args) throws Exception { + syncListUsers(); + } + + public static void syncListUsers() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (IdentityClient identityClient = IdentityClient.create()) { + ListUsersRequest request = + ListUsersRequest.newBuilder() + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + for (User element : identityClient.listUsers(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END localhost7469_v1beta1_generated_Identity_ListUsers_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/updateuser/AsyncUpdateUser.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/updateuser/AsyncUpdateUser.java new file mode 100644 index 0000000000..5d2fc84649 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/updateuser/AsyncUpdateUser.java @@ -0,0 +1,50 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Identity_UpdateUser_async] +import com.google.api.core.ApiFuture; +import com.google.protobuf.FieldMask; +import com.google.showcase.v1beta1.IdentityClient; +import com.google.showcase.v1beta1.UpdateUserRequest; +import com.google.showcase.v1beta1.User; + +public class AsyncUpdateUser { + + public static void main(String[] args) throws Exception { + asyncUpdateUser(); + } + + public static void asyncUpdateUser() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (IdentityClient identityClient = IdentityClient.create()) { + UpdateUserRequest request = + UpdateUserRequest.newBuilder() + .setUser(User.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + ApiFuture future = identityClient.updateUserCallable().futureCall(request); + // Do something. + User response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Identity_UpdateUser_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/updateuser/SyncUpdateUser.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/updateuser/SyncUpdateUser.java new file mode 100644 index 0000000000..23b62e3bbc --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identity/updateuser/SyncUpdateUser.java @@ -0,0 +1,47 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Identity_UpdateUser_sync] +import com.google.protobuf.FieldMask; +import com.google.showcase.v1beta1.IdentityClient; +import com.google.showcase.v1beta1.UpdateUserRequest; +import com.google.showcase.v1beta1.User; + +public class SyncUpdateUser { + + public static void main(String[] args) throws Exception { + syncUpdateUser(); + } + + public static void syncUpdateUser() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (IdentityClient identityClient = IdentityClient.create()) { + UpdateUserRequest request = + UpdateUserRequest.newBuilder() + .setUser(User.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + User response = identityClient.updateUser(request); + } + } +} +// [END localhost7469_v1beta1_generated_Identity_UpdateUser_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identitysettings/createuser/SyncCreateUser.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identitysettings/createuser/SyncCreateUser.java new file mode 100644 index 0000000000..ecc969af0e --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/identitysettings/createuser/SyncCreateUser.java @@ -0,0 +1,48 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_IdentitySettings_CreateUser_sync] +import com.google.showcase.v1beta1.IdentitySettings; +import java.time.Duration; + +public class SyncCreateUser { + + public static void main(String[] args) throws Exception { + syncCreateUser(); + } + + public static void syncCreateUser() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + IdentitySettings.Builder identitySettingsBuilder = IdentitySettings.newBuilder(); + identitySettingsBuilder + .createUserSettings() + .setRetrySettings( + identitySettingsBuilder + .createUserSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + IdentitySettings identitySettings = identitySettingsBuilder.build(); + } +} +// [END localhost7469_v1beta1_generated_IdentitySettings_CreateUser_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/connect/AsyncConnect.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/connect/AsyncConnect.java new file mode 100644 index 0000000000..34f70c0c41 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/connect/AsyncConnect.java @@ -0,0 +1,48 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_Connect_async] +import com.google.api.gax.rpc.BidiStream; +import com.google.showcase.v1beta1.ConnectRequest; +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.StreamBlurbsResponse; + +public class AsyncConnect { + + public static void main(String[] args) throws Exception { + asyncConnect(); + } + + public static void asyncConnect() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + BidiStream bidiStream = + messagingClient.connectCallable().call(); + ConnectRequest request = ConnectRequest.newBuilder().build(); + bidiStream.send(request); + for (StreamBlurbsResponse response : bidiStream) { + // Do something when a response is received. + } + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_Connect_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/create/SyncCreateSetCredentialsProvider.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/create/SyncCreateSetCredentialsProvider.java new file mode 100644 index 0000000000..c6c26a4fae --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/create/SyncCreateSetCredentialsProvider.java @@ -0,0 +1,44 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_Create_SetCredentialsProvider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.MessagingSettings; +import com.google.showcase.v1beta1.myCredentials; + +public class SyncCreateSetCredentialsProvider { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider(); + } + + public static void syncCreateSetCredentialsProvider() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + MessagingSettings messagingSettings = + MessagingSettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + MessagingClient messagingClient = MessagingClient.create(messagingSettings); + } +} +// [END localhost7469_v1beta1_generated_Messaging_Create_SetCredentialsProvider_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/create/SyncCreateSetCredentialsProvider1.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 0000000000..ac54a1ca4e --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/create/SyncCreateSetCredentialsProvider1.java @@ -0,0 +1,39 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_Create_SetCredentialsProvider1_sync] +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.MessagingSettings; + +public class SyncCreateSetCredentialsProvider1 { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider1(); + } + + public static void syncCreateSetCredentialsProvider1() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + MessagingSettings messagingSettings = MessagingSettings.newHttpJsonBuilder().build(); + MessagingClient messagingClient = MessagingClient.create(messagingSettings); + } +} +// [END localhost7469_v1beta1_generated_Messaging_Create_SetCredentialsProvider1_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/create/SyncCreateSetEndpoint.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/create/SyncCreateSetEndpoint.java new file mode 100644 index 0000000000..0380588c4a --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/create/SyncCreateSetEndpoint.java @@ -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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_Create_SetEndpoint_sync] +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.MessagingSettings; +import com.google.showcase.v1beta1.myEndpoint; + +public class SyncCreateSetEndpoint { + + public static void main(String[] args) throws Exception { + syncCreateSetEndpoint(); + } + + public static void syncCreateSetEndpoint() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + MessagingSettings messagingSettings = + MessagingSettings.newBuilder().setEndpoint(myEndpoint).build(); + MessagingClient messagingClient = MessagingClient.create(messagingSettings); + } +} +// [END localhost7469_v1beta1_generated_Messaging_Create_SetEndpoint_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/AsyncCreateBlurb.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/AsyncCreateBlurb.java new file mode 100644 index 0000000000..ab21cabfa7 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/AsyncCreateBlurb.java @@ -0,0 +1,50 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_CreateBlurb_async] +import com.google.api.core.ApiFuture; +import com.google.showcase.v1beta1.Blurb; +import com.google.showcase.v1beta1.CreateBlurbRequest; +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.ProfileName; + +public class AsyncCreateBlurb { + + public static void main(String[] args) throws Exception { + asyncCreateBlurb(); + } + + public static void asyncCreateBlurb() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + CreateBlurbRequest request = + CreateBlurbRequest.newBuilder() + .setParent(ProfileName.of("[USER]").toString()) + .setBlurb(Blurb.newBuilder().build()) + .build(); + ApiFuture future = messagingClient.createBlurbCallable().futureCall(request); + // Do something. + Blurb response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_CreateBlurb_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/SyncCreateBlurb.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/SyncCreateBlurb.java new file mode 100644 index 0000000000..10f979355d --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/SyncCreateBlurb.java @@ -0,0 +1,47 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_CreateBlurb_sync] +import com.google.showcase.v1beta1.Blurb; +import com.google.showcase.v1beta1.CreateBlurbRequest; +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.ProfileName; + +public class SyncCreateBlurb { + + public static void main(String[] args) throws Exception { + syncCreateBlurb(); + } + + public static void syncCreateBlurb() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + CreateBlurbRequest request = + CreateBlurbRequest.newBuilder() + .setParent(ProfileName.of("[USER]").toString()) + .setBlurb(Blurb.newBuilder().build()) + .build(); + Blurb response = messagingClient.createBlurb(request); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_CreateBlurb_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/SyncCreateBlurbProfilenameStringBytestring.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/SyncCreateBlurbProfilenameStringBytestring.java new file mode 100644 index 0000000000..8fe16595eb --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/SyncCreateBlurbProfilenameStringBytestring.java @@ -0,0 +1,46 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_CreateBlurb_ProfilenameStringBytestring_sync] +import com.google.protobuf.ByteString; +import com.google.showcase.v1beta1.Blurb; +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.ProfileName; +import com.google.showcase.v1beta1.UserName; + +public class SyncCreateBlurbProfilenameStringBytestring { + + public static void main(String[] args) throws Exception { + syncCreateBlurbProfilenameStringBytestring(); + } + + public static void syncCreateBlurbProfilenameStringBytestring() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + ProfileName parent = ProfileName.of("[USER]"); + String user = UserName.of("[USER]").toString(); + ByteString image = ByteString.EMPTY; + Blurb response = messagingClient.createBlurb(parent, user, image); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_CreateBlurb_ProfilenameStringBytestring_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/SyncCreateBlurbProfilenameStringString.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/SyncCreateBlurbProfilenameStringString.java new file mode 100644 index 0000000000..5d4c8e8986 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/SyncCreateBlurbProfilenameStringString.java @@ -0,0 +1,45 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_CreateBlurb_ProfilenameStringString_sync] +import com.google.showcase.v1beta1.Blurb; +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.ProfileName; +import com.google.showcase.v1beta1.UserName; + +public class SyncCreateBlurbProfilenameStringString { + + public static void main(String[] args) throws Exception { + syncCreateBlurbProfilenameStringString(); + } + + public static void syncCreateBlurbProfilenameStringString() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + ProfileName parent = ProfileName.of("[USER]"); + String user = UserName.of("[USER]").toString(); + String text = "text3556653"; + Blurb response = messagingClient.createBlurb(parent, user, text); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_CreateBlurb_ProfilenameStringString_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/SyncCreateBlurbProfilenameUsernameBytestring.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/SyncCreateBlurbProfilenameUsernameBytestring.java new file mode 100644 index 0000000000..9c3d7b8c98 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/SyncCreateBlurbProfilenameUsernameBytestring.java @@ -0,0 +1,46 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_CreateBlurb_ProfilenameUsernameBytestring_sync] +import com.google.protobuf.ByteString; +import com.google.showcase.v1beta1.Blurb; +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.ProfileName; +import com.google.showcase.v1beta1.UserName; + +public class SyncCreateBlurbProfilenameUsernameBytestring { + + public static void main(String[] args) throws Exception { + syncCreateBlurbProfilenameUsernameBytestring(); + } + + public static void syncCreateBlurbProfilenameUsernameBytestring() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + ProfileName parent = ProfileName.of("[USER]"); + UserName user = UserName.of("[USER]"); + ByteString image = ByteString.EMPTY; + Blurb response = messagingClient.createBlurb(parent, user, image); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_CreateBlurb_ProfilenameUsernameBytestring_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/SyncCreateBlurbProfilenameUsernameString.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/SyncCreateBlurbProfilenameUsernameString.java new file mode 100644 index 0000000000..f431a92155 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/SyncCreateBlurbProfilenameUsernameString.java @@ -0,0 +1,45 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_CreateBlurb_ProfilenameUsernameString_sync] +import com.google.showcase.v1beta1.Blurb; +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.ProfileName; +import com.google.showcase.v1beta1.UserName; + +public class SyncCreateBlurbProfilenameUsernameString { + + public static void main(String[] args) throws Exception { + syncCreateBlurbProfilenameUsernameString(); + } + + public static void syncCreateBlurbProfilenameUsernameString() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + ProfileName parent = ProfileName.of("[USER]"); + UserName user = UserName.of("[USER]"); + String text = "text3556653"; + Blurb response = messagingClient.createBlurb(parent, user, text); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_CreateBlurb_ProfilenameUsernameString_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/SyncCreateBlurbRoomnameStringBytestring.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/SyncCreateBlurbRoomnameStringBytestring.java new file mode 100644 index 0000000000..477ed0b163 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/SyncCreateBlurbRoomnameStringBytestring.java @@ -0,0 +1,46 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_CreateBlurb_RoomnameStringBytestring_sync] +import com.google.protobuf.ByteString; +import com.google.showcase.v1beta1.Blurb; +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.RoomName; +import com.google.showcase.v1beta1.UserName; + +public class SyncCreateBlurbRoomnameStringBytestring { + + public static void main(String[] args) throws Exception { + syncCreateBlurbRoomnameStringBytestring(); + } + + public static void syncCreateBlurbRoomnameStringBytestring() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + RoomName parent = RoomName.of("[ROOM]"); + String user = UserName.of("[USER]").toString(); + ByteString image = ByteString.EMPTY; + Blurb response = messagingClient.createBlurb(parent, user, image); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_CreateBlurb_RoomnameStringBytestring_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/SyncCreateBlurbRoomnameStringString.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/SyncCreateBlurbRoomnameStringString.java new file mode 100644 index 0000000000..07dc451756 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/SyncCreateBlurbRoomnameStringString.java @@ -0,0 +1,45 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_CreateBlurb_RoomnameStringString_sync] +import com.google.showcase.v1beta1.Blurb; +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.RoomName; +import com.google.showcase.v1beta1.UserName; + +public class SyncCreateBlurbRoomnameStringString { + + public static void main(String[] args) throws Exception { + syncCreateBlurbRoomnameStringString(); + } + + public static void syncCreateBlurbRoomnameStringString() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + RoomName parent = RoomName.of("[ROOM]"); + String user = UserName.of("[USER]").toString(); + String text = "text3556653"; + Blurb response = messagingClient.createBlurb(parent, user, text); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_CreateBlurb_RoomnameStringString_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/SyncCreateBlurbRoomnameUsernameBytestring.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/SyncCreateBlurbRoomnameUsernameBytestring.java new file mode 100644 index 0000000000..a4cff9e110 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/SyncCreateBlurbRoomnameUsernameBytestring.java @@ -0,0 +1,46 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_CreateBlurb_RoomnameUsernameBytestring_sync] +import com.google.protobuf.ByteString; +import com.google.showcase.v1beta1.Blurb; +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.RoomName; +import com.google.showcase.v1beta1.UserName; + +public class SyncCreateBlurbRoomnameUsernameBytestring { + + public static void main(String[] args) throws Exception { + syncCreateBlurbRoomnameUsernameBytestring(); + } + + public static void syncCreateBlurbRoomnameUsernameBytestring() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + RoomName parent = RoomName.of("[ROOM]"); + UserName user = UserName.of("[USER]"); + ByteString image = ByteString.EMPTY; + Blurb response = messagingClient.createBlurb(parent, user, image); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_CreateBlurb_RoomnameUsernameBytestring_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/SyncCreateBlurbRoomnameUsernameString.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/SyncCreateBlurbRoomnameUsernameString.java new file mode 100644 index 0000000000..5e71b33344 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/SyncCreateBlurbRoomnameUsernameString.java @@ -0,0 +1,45 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_CreateBlurb_RoomnameUsernameString_sync] +import com.google.showcase.v1beta1.Blurb; +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.RoomName; +import com.google.showcase.v1beta1.UserName; + +public class SyncCreateBlurbRoomnameUsernameString { + + public static void main(String[] args) throws Exception { + syncCreateBlurbRoomnameUsernameString(); + } + + public static void syncCreateBlurbRoomnameUsernameString() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + RoomName parent = RoomName.of("[ROOM]"); + UserName user = UserName.of("[USER]"); + String text = "text3556653"; + Blurb response = messagingClient.createBlurb(parent, user, text); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_CreateBlurb_RoomnameUsernameString_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/SyncCreateBlurbStringStringBytestring.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/SyncCreateBlurbStringStringBytestring.java new file mode 100644 index 0000000000..bfed9b8941 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/SyncCreateBlurbStringStringBytestring.java @@ -0,0 +1,46 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_CreateBlurb_StringStringBytestring_sync] +import com.google.protobuf.ByteString; +import com.google.showcase.v1beta1.Blurb; +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.ProfileName; +import com.google.showcase.v1beta1.UserName; + +public class SyncCreateBlurbStringStringBytestring { + + public static void main(String[] args) throws Exception { + syncCreateBlurbStringStringBytestring(); + } + + public static void syncCreateBlurbStringStringBytestring() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + String parent = ProfileName.of("[USER]").toString(); + String user = UserName.of("[USER]").toString(); + ByteString image = ByteString.EMPTY; + Blurb response = messagingClient.createBlurb(parent, user, image); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_CreateBlurb_StringStringBytestring_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/SyncCreateBlurbStringStringString.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/SyncCreateBlurbStringStringString.java new file mode 100644 index 0000000000..f2611ad321 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/SyncCreateBlurbStringStringString.java @@ -0,0 +1,45 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_CreateBlurb_StringStringString_sync] +import com.google.showcase.v1beta1.Blurb; +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.ProfileName; +import com.google.showcase.v1beta1.UserName; + +public class SyncCreateBlurbStringStringString { + + public static void main(String[] args) throws Exception { + syncCreateBlurbStringStringString(); + } + + public static void syncCreateBlurbStringStringString() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + String parent = ProfileName.of("[USER]").toString(); + String user = UserName.of("[USER]").toString(); + String text = "text3556653"; + Blurb response = messagingClient.createBlurb(parent, user, text); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_CreateBlurb_StringStringString_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/SyncCreateBlurbStringUsernameBytestring.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/SyncCreateBlurbStringUsernameBytestring.java new file mode 100644 index 0000000000..20ac75deb0 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/SyncCreateBlurbStringUsernameBytestring.java @@ -0,0 +1,46 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_CreateBlurb_StringUsernameBytestring_sync] +import com.google.protobuf.ByteString; +import com.google.showcase.v1beta1.Blurb; +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.ProfileName; +import com.google.showcase.v1beta1.UserName; + +public class SyncCreateBlurbStringUsernameBytestring { + + public static void main(String[] args) throws Exception { + syncCreateBlurbStringUsernameBytestring(); + } + + public static void syncCreateBlurbStringUsernameBytestring() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + String parent = ProfileName.of("[USER]").toString(); + UserName user = UserName.of("[USER]"); + ByteString image = ByteString.EMPTY; + Blurb response = messagingClient.createBlurb(parent, user, image); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_CreateBlurb_StringUsernameBytestring_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/SyncCreateBlurbStringUsernameString.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/SyncCreateBlurbStringUsernameString.java new file mode 100644 index 0000000000..a9a3cd4af8 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createblurb/SyncCreateBlurbStringUsernameString.java @@ -0,0 +1,45 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_CreateBlurb_StringUsernameString_sync] +import com.google.showcase.v1beta1.Blurb; +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.ProfileName; +import com.google.showcase.v1beta1.UserName; + +public class SyncCreateBlurbStringUsernameString { + + public static void main(String[] args) throws Exception { + syncCreateBlurbStringUsernameString(); + } + + public static void syncCreateBlurbStringUsernameString() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + String parent = ProfileName.of("[USER]").toString(); + UserName user = UserName.of("[USER]"); + String text = "text3556653"; + Blurb response = messagingClient.createBlurb(parent, user, text); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_CreateBlurb_StringUsernameString_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createroom/AsyncCreateRoom.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createroom/AsyncCreateRoom.java new file mode 100644 index 0000000000..70a76f23b0 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createroom/AsyncCreateRoom.java @@ -0,0 +1,46 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_CreateRoom_async] +import com.google.api.core.ApiFuture; +import com.google.showcase.v1beta1.CreateRoomRequest; +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.Room; + +public class AsyncCreateRoom { + + public static void main(String[] args) throws Exception { + asyncCreateRoom(); + } + + public static void asyncCreateRoom() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + CreateRoomRequest request = + CreateRoomRequest.newBuilder().setRoom(Room.newBuilder().build()).build(); + ApiFuture future = messagingClient.createRoomCallable().futureCall(request); + // Do something. + Room response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_CreateRoom_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createroom/SyncCreateRoom.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createroom/SyncCreateRoom.java new file mode 100644 index 0000000000..5aa1b3e94e --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createroom/SyncCreateRoom.java @@ -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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_CreateRoom_sync] +import com.google.showcase.v1beta1.CreateRoomRequest; +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.Room; + +public class SyncCreateRoom { + + public static void main(String[] args) throws Exception { + syncCreateRoom(); + } + + public static void syncCreateRoom() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + CreateRoomRequest request = + CreateRoomRequest.newBuilder().setRoom(Room.newBuilder().build()).build(); + Room response = messagingClient.createRoom(request); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_CreateRoom_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createroom/SyncCreateRoomStringString.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createroom/SyncCreateRoomStringString.java new file mode 100644 index 0000000000..7fcd4b7c45 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/createroom/SyncCreateRoomStringString.java @@ -0,0 +1,42 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_CreateRoom_StringString_sync] +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.Room; + +public class SyncCreateRoomStringString { + + public static void main(String[] args) throws Exception { + syncCreateRoomStringString(); + } + + public static void syncCreateRoomStringString() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + String displayName = "displayName1714148973"; + String description = "description-1724546052"; + Room response = messagingClient.createRoom(displayName, description); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_CreateRoom_StringString_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/deleteblurb/AsyncDeleteBlurb.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/deleteblurb/AsyncDeleteBlurb.java new file mode 100644 index 0000000000..664a34bc76 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/deleteblurb/AsyncDeleteBlurb.java @@ -0,0 +1,49 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_DeleteBlurb_async] +import com.google.api.core.ApiFuture; +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.DeleteBlurbRequest; +import com.google.showcase.v1beta1.MessagingClient; + +public class AsyncDeleteBlurb { + + public static void main(String[] args) throws Exception { + asyncDeleteBlurb(); + } + + public static void asyncDeleteBlurb() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + DeleteBlurbRequest request = + DeleteBlurbRequest.newBuilder() + .setName(BlurbName.ofRoomBlurbName("[ROOM]", "[BLURB]").toString()) + .build(); + ApiFuture future = messagingClient.deleteBlurbCallable().futureCall(request); + // Do something. + future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_DeleteBlurb_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/deleteblurb/SyncDeleteBlurb.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/deleteblurb/SyncDeleteBlurb.java new file mode 100644 index 0000000000..cd93918820 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/deleteblurb/SyncDeleteBlurb.java @@ -0,0 +1,46 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_DeleteBlurb_sync] +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.DeleteBlurbRequest; +import com.google.showcase.v1beta1.MessagingClient; + +public class SyncDeleteBlurb { + + public static void main(String[] args) throws Exception { + syncDeleteBlurb(); + } + + public static void syncDeleteBlurb() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + DeleteBlurbRequest request = + DeleteBlurbRequest.newBuilder() + .setName(BlurbName.ofRoomBlurbName("[ROOM]", "[BLURB]").toString()) + .build(); + messagingClient.deleteBlurb(request); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_DeleteBlurb_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/deleteblurb/SyncDeleteBlurbBlurbname.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/deleteblurb/SyncDeleteBlurbBlurbname.java new file mode 100644 index 0000000000..815c598962 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/deleteblurb/SyncDeleteBlurbBlurbname.java @@ -0,0 +1,42 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_DeleteBlurb_Blurbname_sync] +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.MessagingClient; + +public class SyncDeleteBlurbBlurbname { + + public static void main(String[] args) throws Exception { + syncDeleteBlurbBlurbname(); + } + + public static void syncDeleteBlurbBlurbname() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + BlurbName name = BlurbName.ofRoomBlurbName("[ROOM]", "[BLURB]"); + messagingClient.deleteBlurb(name); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_DeleteBlurb_Blurbname_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/deleteblurb/SyncDeleteBlurbString.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/deleteblurb/SyncDeleteBlurbString.java new file mode 100644 index 0000000000..30d35e96cb --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/deleteblurb/SyncDeleteBlurbString.java @@ -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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_DeleteBlurb_String_sync] +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.MessagingClient; + +public class SyncDeleteBlurbString { + + public static void main(String[] args) throws Exception { + syncDeleteBlurbString(); + } + + public static void syncDeleteBlurbString() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + String name = + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]").toString(); + messagingClient.deleteBlurb(name); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_DeleteBlurb_String_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/deleteroom/AsyncDeleteRoom.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/deleteroom/AsyncDeleteRoom.java new file mode 100644 index 0000000000..f521ea0ab6 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/deleteroom/AsyncDeleteRoom.java @@ -0,0 +1,47 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_DeleteRoom_async] +import com.google.api.core.ApiFuture; +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.DeleteRoomRequest; +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.RoomName; + +public class AsyncDeleteRoom { + + public static void main(String[] args) throws Exception { + asyncDeleteRoom(); + } + + public static void asyncDeleteRoom() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + DeleteRoomRequest request = + DeleteRoomRequest.newBuilder().setName(RoomName.of("[ROOM]").toString()).build(); + ApiFuture future = messagingClient.deleteRoomCallable().futureCall(request); + // Do something. + future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_DeleteRoom_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/deleteroom/SyncDeleteRoom.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/deleteroom/SyncDeleteRoom.java new file mode 100644 index 0000000000..bcb643cbea --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/deleteroom/SyncDeleteRoom.java @@ -0,0 +1,44 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_DeleteRoom_sync] +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.DeleteRoomRequest; +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.RoomName; + +public class SyncDeleteRoom { + + public static void main(String[] args) throws Exception { + syncDeleteRoom(); + } + + public static void syncDeleteRoom() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + DeleteRoomRequest request = + DeleteRoomRequest.newBuilder().setName(RoomName.of("[ROOM]").toString()).build(); + messagingClient.deleteRoom(request); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_DeleteRoom_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/deleteroom/SyncDeleteRoomRoomname.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/deleteroom/SyncDeleteRoomRoomname.java new file mode 100644 index 0000000000..bed6bd6339 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/deleteroom/SyncDeleteRoomRoomname.java @@ -0,0 +1,42 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_DeleteRoom_Roomname_sync] +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.RoomName; + +public class SyncDeleteRoomRoomname { + + public static void main(String[] args) throws Exception { + syncDeleteRoomRoomname(); + } + + public static void syncDeleteRoomRoomname() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + RoomName name = RoomName.of("[ROOM]"); + messagingClient.deleteRoom(name); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_DeleteRoom_Roomname_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/deleteroom/SyncDeleteRoomString.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/deleteroom/SyncDeleteRoomString.java new file mode 100644 index 0000000000..c8ef55c8f0 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/deleteroom/SyncDeleteRoomString.java @@ -0,0 +1,42 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_DeleteRoom_String_sync] +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.RoomName; + +public class SyncDeleteRoomString { + + public static void main(String[] args) throws Exception { + syncDeleteRoomString(); + } + + public static void syncDeleteRoomString() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + String name = RoomName.of("[ROOM]").toString(); + messagingClient.deleteRoom(name); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_DeleteRoom_String_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/getblurb/AsyncGetBlurb.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/getblurb/AsyncGetBlurb.java new file mode 100644 index 0000000000..3bcdc0dfa2 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/getblurb/AsyncGetBlurb.java @@ -0,0 +1,49 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_GetBlurb_async] +import com.google.api.core.ApiFuture; +import com.google.showcase.v1beta1.Blurb; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.GetBlurbRequest; +import com.google.showcase.v1beta1.MessagingClient; + +public class AsyncGetBlurb { + + public static void main(String[] args) throws Exception { + asyncGetBlurb(); + } + + public static void asyncGetBlurb() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + GetBlurbRequest request = + GetBlurbRequest.newBuilder() + .setName(BlurbName.ofRoomBlurbName("[ROOM]", "[BLURB]").toString()) + .build(); + ApiFuture future = messagingClient.getBlurbCallable().futureCall(request); + // Do something. + Blurb response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_GetBlurb_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/getblurb/SyncGetBlurb.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/getblurb/SyncGetBlurb.java new file mode 100644 index 0000000000..0ca916ecfb --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/getblurb/SyncGetBlurb.java @@ -0,0 +1,46 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_GetBlurb_sync] +import com.google.showcase.v1beta1.Blurb; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.GetBlurbRequest; +import com.google.showcase.v1beta1.MessagingClient; + +public class SyncGetBlurb { + + public static void main(String[] args) throws Exception { + syncGetBlurb(); + } + + public static void syncGetBlurb() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + GetBlurbRequest request = + GetBlurbRequest.newBuilder() + .setName(BlurbName.ofRoomBlurbName("[ROOM]", "[BLURB]").toString()) + .build(); + Blurb response = messagingClient.getBlurb(request); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_GetBlurb_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/getblurb/SyncGetBlurbBlurbname.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/getblurb/SyncGetBlurbBlurbname.java new file mode 100644 index 0000000000..8288ba1002 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/getblurb/SyncGetBlurbBlurbname.java @@ -0,0 +1,42 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_GetBlurb_Blurbname_sync] +import com.google.showcase.v1beta1.Blurb; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.MessagingClient; + +public class SyncGetBlurbBlurbname { + + public static void main(String[] args) throws Exception { + syncGetBlurbBlurbname(); + } + + public static void syncGetBlurbBlurbname() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + BlurbName name = BlurbName.ofRoomBlurbName("[ROOM]", "[BLURB]"); + Blurb response = messagingClient.getBlurb(name); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_GetBlurb_Blurbname_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/getblurb/SyncGetBlurbString.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/getblurb/SyncGetBlurbString.java new file mode 100644 index 0000000000..3a7f190d7b --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/getblurb/SyncGetBlurbString.java @@ -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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_GetBlurb_String_sync] +import com.google.showcase.v1beta1.Blurb; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.MessagingClient; + +public class SyncGetBlurbString { + + public static void main(String[] args) throws Exception { + syncGetBlurbString(); + } + + public static void syncGetBlurbString() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + String name = + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]").toString(); + Blurb response = messagingClient.getBlurb(name); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_GetBlurb_String_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/getroom/AsyncGetRoom.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/getroom/AsyncGetRoom.java new file mode 100644 index 0000000000..7449457aec --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/getroom/AsyncGetRoom.java @@ -0,0 +1,47 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_GetRoom_async] +import com.google.api.core.ApiFuture; +import com.google.showcase.v1beta1.GetRoomRequest; +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.Room; +import com.google.showcase.v1beta1.RoomName; + +public class AsyncGetRoom { + + public static void main(String[] args) throws Exception { + asyncGetRoom(); + } + + public static void asyncGetRoom() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + GetRoomRequest request = + GetRoomRequest.newBuilder().setName(RoomName.of("[ROOM]").toString()).build(); + ApiFuture future = messagingClient.getRoomCallable().futureCall(request); + // Do something. + Room response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_GetRoom_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/getroom/SyncGetRoom.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/getroom/SyncGetRoom.java new file mode 100644 index 0000000000..50195f0808 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/getroom/SyncGetRoom.java @@ -0,0 +1,44 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_GetRoom_sync] +import com.google.showcase.v1beta1.GetRoomRequest; +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.Room; +import com.google.showcase.v1beta1.RoomName; + +public class SyncGetRoom { + + public static void main(String[] args) throws Exception { + syncGetRoom(); + } + + public static void syncGetRoom() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + GetRoomRequest request = + GetRoomRequest.newBuilder().setName(RoomName.of("[ROOM]").toString()).build(); + Room response = messagingClient.getRoom(request); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_GetRoom_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/getroom/SyncGetRoomRoomname.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/getroom/SyncGetRoomRoomname.java new file mode 100644 index 0000000000..330ff415e6 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/getroom/SyncGetRoomRoomname.java @@ -0,0 +1,42 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_GetRoom_Roomname_sync] +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.Room; +import com.google.showcase.v1beta1.RoomName; + +public class SyncGetRoomRoomname { + + public static void main(String[] args) throws Exception { + syncGetRoomRoomname(); + } + + public static void syncGetRoomRoomname() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + RoomName name = RoomName.of("[ROOM]"); + Room response = messagingClient.getRoom(name); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_GetRoom_Roomname_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/getroom/SyncGetRoomString.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/getroom/SyncGetRoomString.java new file mode 100644 index 0000000000..a0d1d29738 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/getroom/SyncGetRoomString.java @@ -0,0 +1,42 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_GetRoom_String_sync] +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.Room; +import com.google.showcase.v1beta1.RoomName; + +public class SyncGetRoomString { + + public static void main(String[] args) throws Exception { + syncGetRoomString(); + } + + public static void syncGetRoomString() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + String name = RoomName.of("[ROOM]").toString(); + Room response = messagingClient.getRoom(name); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_GetRoom_String_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/listblurbs/AsyncListBlurbs.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/listblurbs/AsyncListBlurbs.java new file mode 100644 index 0000000000..e1ed6b891e --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/listblurbs/AsyncListBlurbs.java @@ -0,0 +1,53 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_ListBlurbs_async] +import com.google.api.core.ApiFuture; +import com.google.showcase.v1beta1.Blurb; +import com.google.showcase.v1beta1.ListBlurbsRequest; +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.ProfileName; + +public class AsyncListBlurbs { + + public static void main(String[] args) throws Exception { + asyncListBlurbs(); + } + + public static void asyncListBlurbs() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + ListBlurbsRequest request = + ListBlurbsRequest.newBuilder() + .setParent(ProfileName.of("[USER]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + ApiFuture future = messagingClient.listBlurbsPagedCallable().futureCall(request); + // Do something. + for (Blurb element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_ListBlurbs_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/listblurbs/AsyncListBlurbsPaged.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/listblurbs/AsyncListBlurbsPaged.java new file mode 100644 index 0000000000..4fe5854968 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/listblurbs/AsyncListBlurbsPaged.java @@ -0,0 +1,61 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_ListBlurbs_Paged_async] +import com.google.common.base.Strings; +import com.google.showcase.v1beta1.Blurb; +import com.google.showcase.v1beta1.ListBlurbsRequest; +import com.google.showcase.v1beta1.ListBlurbsResponse; +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.ProfileName; + +public class AsyncListBlurbsPaged { + + public static void main(String[] args) throws Exception { + asyncListBlurbsPaged(); + } + + public static void asyncListBlurbsPaged() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + ListBlurbsRequest request = + ListBlurbsRequest.newBuilder() + .setParent(ProfileName.of("[USER]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + while (true) { + ListBlurbsResponse response = messagingClient.listBlurbsCallable().call(request); + for (Blurb element : response.getBlurbsList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_ListBlurbs_Paged_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/listblurbs/SyncListBlurbs.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/listblurbs/SyncListBlurbs.java new file mode 100644 index 0000000000..ad1fe7ca00 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/listblurbs/SyncListBlurbs.java @@ -0,0 +1,50 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_ListBlurbs_sync] +import com.google.showcase.v1beta1.Blurb; +import com.google.showcase.v1beta1.ListBlurbsRequest; +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.ProfileName; + +public class SyncListBlurbs { + + public static void main(String[] args) throws Exception { + syncListBlurbs(); + } + + public static void syncListBlurbs() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + ListBlurbsRequest request = + ListBlurbsRequest.newBuilder() + .setParent(ProfileName.of("[USER]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + for (Blurb element : messagingClient.listBlurbs(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_ListBlurbs_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/listblurbs/SyncListBlurbsProfilename.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/listblurbs/SyncListBlurbsProfilename.java new file mode 100644 index 0000000000..cd576614b4 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/listblurbs/SyncListBlurbsProfilename.java @@ -0,0 +1,44 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_ListBlurbs_Profilename_sync] +import com.google.showcase.v1beta1.Blurb; +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.ProfileName; + +public class SyncListBlurbsProfilename { + + public static void main(String[] args) throws Exception { + syncListBlurbsProfilename(); + } + + public static void syncListBlurbsProfilename() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + ProfileName parent = ProfileName.of("[USER]"); + for (Blurb element : messagingClient.listBlurbs(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_ListBlurbs_Profilename_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/listblurbs/SyncListBlurbsRoomname.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/listblurbs/SyncListBlurbsRoomname.java new file mode 100644 index 0000000000..e4e34b5327 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/listblurbs/SyncListBlurbsRoomname.java @@ -0,0 +1,44 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_ListBlurbs_Roomname_sync] +import com.google.showcase.v1beta1.Blurb; +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.RoomName; + +public class SyncListBlurbsRoomname { + + public static void main(String[] args) throws Exception { + syncListBlurbsRoomname(); + } + + public static void syncListBlurbsRoomname() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + RoomName parent = RoomName.of("[ROOM]"); + for (Blurb element : messagingClient.listBlurbs(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_ListBlurbs_Roomname_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/listblurbs/SyncListBlurbsString.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/listblurbs/SyncListBlurbsString.java new file mode 100644 index 0000000000..77b1f2b68d --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/listblurbs/SyncListBlurbsString.java @@ -0,0 +1,44 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_ListBlurbs_String_sync] +import com.google.showcase.v1beta1.Blurb; +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.ProfileName; + +public class SyncListBlurbsString { + + public static void main(String[] args) throws Exception { + syncListBlurbsString(); + } + + public static void syncListBlurbsString() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + String parent = ProfileName.of("[USER]").toString(); + for (Blurb element : messagingClient.listBlurbs(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_ListBlurbs_String_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/listrooms/AsyncListRooms.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/listrooms/AsyncListRooms.java new file mode 100644 index 0000000000..245db794fc --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/listrooms/AsyncListRooms.java @@ -0,0 +1,51 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_ListRooms_async] +import com.google.api.core.ApiFuture; +import com.google.showcase.v1beta1.ListRoomsRequest; +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.Room; + +public class AsyncListRooms { + + public static void main(String[] args) throws Exception { + asyncListRooms(); + } + + public static void asyncListRooms() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + ListRoomsRequest request = + ListRoomsRequest.newBuilder() + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + ApiFuture future = messagingClient.listRoomsPagedCallable().futureCall(request); + // Do something. + for (Room element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_ListRooms_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/listrooms/AsyncListRoomsPaged.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/listrooms/AsyncListRoomsPaged.java new file mode 100644 index 0000000000..faf33d3da5 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/listrooms/AsyncListRoomsPaged.java @@ -0,0 +1,59 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_ListRooms_Paged_async] +import com.google.common.base.Strings; +import com.google.showcase.v1beta1.ListRoomsRequest; +import com.google.showcase.v1beta1.ListRoomsResponse; +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.Room; + +public class AsyncListRoomsPaged { + + public static void main(String[] args) throws Exception { + asyncListRoomsPaged(); + } + + public static void asyncListRoomsPaged() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + ListRoomsRequest request = + ListRoomsRequest.newBuilder() + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + while (true) { + ListRoomsResponse response = messagingClient.listRoomsCallable().call(request); + for (Room element : response.getRoomsList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_ListRooms_Paged_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/listrooms/SyncListRooms.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/listrooms/SyncListRooms.java new file mode 100644 index 0000000000..f8196f7e96 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/listrooms/SyncListRooms.java @@ -0,0 +1,48 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_ListRooms_sync] +import com.google.showcase.v1beta1.ListRoomsRequest; +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.Room; + +public class SyncListRooms { + + public static void main(String[] args) throws Exception { + syncListRooms(); + } + + public static void syncListRooms() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + ListRoomsRequest request = + ListRoomsRequest.newBuilder() + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + for (Room element : messagingClient.listRooms(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_ListRooms_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/searchblurbs/AsyncSearchBlurbs.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/searchblurbs/AsyncSearchBlurbs.java new file mode 100644 index 0000000000..f74d6da297 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/searchblurbs/AsyncSearchBlurbs.java @@ -0,0 +1,52 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_SearchBlurbs_async] +import com.google.api.core.ApiFuture; +import com.google.longrunning.Operation; +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.ProfileName; +import com.google.showcase.v1beta1.SearchBlurbsRequest; + +public class AsyncSearchBlurbs { + + public static void main(String[] args) throws Exception { + asyncSearchBlurbs(); + } + + public static void asyncSearchBlurbs() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + SearchBlurbsRequest request = + SearchBlurbsRequest.newBuilder() + .setQuery("query107944136") + .setParent(ProfileName.of("[USER]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + ApiFuture future = messagingClient.searchBlurbsCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_SearchBlurbs_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/searchblurbs/AsyncSearchBlurbsLRO.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/searchblurbs/AsyncSearchBlurbsLRO.java new file mode 100644 index 0000000000..70be85e24a --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/searchblurbs/AsyncSearchBlurbsLRO.java @@ -0,0 +1,54 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_SearchBlurbs_LRO_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.ProfileName; +import com.google.showcase.v1beta1.SearchBlurbsMetadata; +import com.google.showcase.v1beta1.SearchBlurbsRequest; +import com.google.showcase.v1beta1.SearchBlurbsResponse; + +public class AsyncSearchBlurbsLRO { + + public static void main(String[] args) throws Exception { + asyncSearchBlurbsLRO(); + } + + public static void asyncSearchBlurbsLRO() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + SearchBlurbsRequest request = + SearchBlurbsRequest.newBuilder() + .setQuery("query107944136") + .setParent(ProfileName.of("[USER]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + OperationFuture future = + messagingClient.searchBlurbsOperationCallable().futureCall(request); + // Do something. + SearchBlurbsResponse response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_SearchBlurbs_LRO_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/searchblurbs/SyncSearchBlurbs.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/searchblurbs/SyncSearchBlurbs.java new file mode 100644 index 0000000000..9185a19d58 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/searchblurbs/SyncSearchBlurbs.java @@ -0,0 +1,49 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_SearchBlurbs_sync] +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.ProfileName; +import com.google.showcase.v1beta1.SearchBlurbsRequest; +import com.google.showcase.v1beta1.SearchBlurbsResponse; + +public class SyncSearchBlurbs { + + public static void main(String[] args) throws Exception { + syncSearchBlurbs(); + } + + public static void syncSearchBlurbs() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + SearchBlurbsRequest request = + SearchBlurbsRequest.newBuilder() + .setQuery("query107944136") + .setParent(ProfileName.of("[USER]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + SearchBlurbsResponse response = messagingClient.searchBlurbsAsync(request).get(); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_SearchBlurbs_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/searchblurbs/SyncSearchBlurbsProfilenameString.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/searchblurbs/SyncSearchBlurbsProfilenameString.java new file mode 100644 index 0000000000..3601c897d4 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/searchblurbs/SyncSearchBlurbsProfilenameString.java @@ -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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_SearchBlurbs_ProfilenameString_sync] +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.ProfileName; +import com.google.showcase.v1beta1.SearchBlurbsResponse; + +public class SyncSearchBlurbsProfilenameString { + + public static void main(String[] args) throws Exception { + syncSearchBlurbsProfilenameString(); + } + + public static void syncSearchBlurbsProfilenameString() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + ProfileName parent = ProfileName.of("[USER]"); + String query = "query107944136"; + SearchBlurbsResponse response = messagingClient.searchBlurbsAsync(parent, query).get(); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_SearchBlurbs_ProfilenameString_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/searchblurbs/SyncSearchBlurbsRoomnameString.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/searchblurbs/SyncSearchBlurbsRoomnameString.java new file mode 100644 index 0000000000..164a2a0d52 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/searchblurbs/SyncSearchBlurbsRoomnameString.java @@ -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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_SearchBlurbs_RoomnameString_sync] +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.RoomName; +import com.google.showcase.v1beta1.SearchBlurbsResponse; + +public class SyncSearchBlurbsRoomnameString { + + public static void main(String[] args) throws Exception { + syncSearchBlurbsRoomnameString(); + } + + public static void syncSearchBlurbsRoomnameString() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + RoomName parent = RoomName.of("[ROOM]"); + String query = "query107944136"; + SearchBlurbsResponse response = messagingClient.searchBlurbsAsync(parent, query).get(); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_SearchBlurbs_RoomnameString_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/searchblurbs/SyncSearchBlurbsStringString.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/searchblurbs/SyncSearchBlurbsStringString.java new file mode 100644 index 0000000000..dffc4662fd --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/searchblurbs/SyncSearchBlurbsStringString.java @@ -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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_SearchBlurbs_StringString_sync] +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.ProfileName; +import com.google.showcase.v1beta1.SearchBlurbsResponse; + +public class SyncSearchBlurbsStringString { + + public static void main(String[] args) throws Exception { + syncSearchBlurbsStringString(); + } + + public static void syncSearchBlurbsStringString() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + String parent = ProfileName.of("[USER]").toString(); + String query = "query107944136"; + SearchBlurbsResponse response = messagingClient.searchBlurbsAsync(parent, query).get(); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_SearchBlurbs_StringString_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/sendblurbs/AsyncSendBlurbs.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/sendblurbs/AsyncSendBlurbs.java new file mode 100644 index 0000000000..88c6d67af7 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/sendblurbs/AsyncSendBlurbs.java @@ -0,0 +1,68 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_SendBlurbs_async] +import com.google.api.gax.rpc.ApiStreamObserver; +import com.google.showcase.v1beta1.Blurb; +import com.google.showcase.v1beta1.CreateBlurbRequest; +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.ProfileName; +import com.google.showcase.v1beta1.SendBlurbsResponse; + +public class AsyncSendBlurbs { + + public static void main(String[] args) throws Exception { + asyncSendBlurbs(); + } + + public static void asyncSendBlurbs() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + ApiStreamObserver responseObserver = + new ApiStreamObserver() { + @Override + public void onNext(SendBlurbsResponse response) { + // Do something when a response is received. + } + + @Override + public void onError(Throwable t) { + // Add error-handling + } + + @Override + public void onCompleted() { + // Do something when complete. + } + }; + ApiStreamObserver requestObserver = + messagingClient.sendBlurbs().clientStreamingCall(responseObserver); + CreateBlurbRequest request = + CreateBlurbRequest.newBuilder() + .setParent(ProfileName.of("[USER]").toString()) + .setBlurb(Blurb.newBuilder().build()) + .build(); + requestObserver.onNext(request); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_SendBlurbs_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/streamblurbs/AsyncStreamBlurbs.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/streamblurbs/AsyncStreamBlurbs.java new file mode 100644 index 0000000000..22d85305d4 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/streamblurbs/AsyncStreamBlurbs.java @@ -0,0 +1,53 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_StreamBlurbs_async] +import com.google.api.gax.rpc.ServerStream; +import com.google.protobuf.Timestamp; +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.ProfileName; +import com.google.showcase.v1beta1.StreamBlurbsRequest; +import com.google.showcase.v1beta1.StreamBlurbsResponse; + +public class AsyncStreamBlurbs { + + public static void main(String[] args) throws Exception { + asyncStreamBlurbs(); + } + + public static void asyncStreamBlurbs() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + StreamBlurbsRequest request = + StreamBlurbsRequest.newBuilder() + .setName(ProfileName.of("[USER]").toString()) + .setExpireTime(Timestamp.newBuilder().build()) + .build(); + ServerStream stream = + messagingClient.streamBlurbsCallable().call(request); + for (StreamBlurbsResponse response : stream) { + // Do something when a response is received. + } + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_StreamBlurbs_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/updateblurb/AsyncUpdateBlurb.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/updateblurb/AsyncUpdateBlurb.java new file mode 100644 index 0000000000..5f26fbdccc --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/updateblurb/AsyncUpdateBlurb.java @@ -0,0 +1,50 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_UpdateBlurb_async] +import com.google.api.core.ApiFuture; +import com.google.protobuf.FieldMask; +import com.google.showcase.v1beta1.Blurb; +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.UpdateBlurbRequest; + +public class AsyncUpdateBlurb { + + public static void main(String[] args) throws Exception { + asyncUpdateBlurb(); + } + + public static void asyncUpdateBlurb() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + UpdateBlurbRequest request = + UpdateBlurbRequest.newBuilder() + .setBlurb(Blurb.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + ApiFuture future = messagingClient.updateBlurbCallable().futureCall(request); + // Do something. + Blurb response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_UpdateBlurb_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/updateblurb/SyncUpdateBlurb.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/updateblurb/SyncUpdateBlurb.java new file mode 100644 index 0000000000..415b326718 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/updateblurb/SyncUpdateBlurb.java @@ -0,0 +1,47 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_UpdateBlurb_sync] +import com.google.protobuf.FieldMask; +import com.google.showcase.v1beta1.Blurb; +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.UpdateBlurbRequest; + +public class SyncUpdateBlurb { + + public static void main(String[] args) throws Exception { + syncUpdateBlurb(); + } + + public static void syncUpdateBlurb() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + UpdateBlurbRequest request = + UpdateBlurbRequest.newBuilder() + .setBlurb(Blurb.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + Blurb response = messagingClient.updateBlurb(request); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_UpdateBlurb_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/updateroom/AsyncUpdateRoom.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/updateroom/AsyncUpdateRoom.java new file mode 100644 index 0000000000..6e7b19ad5c --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/updateroom/AsyncUpdateRoom.java @@ -0,0 +1,50 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_UpdateRoom_async] +import com.google.api.core.ApiFuture; +import com.google.protobuf.FieldMask; +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.Room; +import com.google.showcase.v1beta1.UpdateRoomRequest; + +public class AsyncUpdateRoom { + + public static void main(String[] args) throws Exception { + asyncUpdateRoom(); + } + + public static void asyncUpdateRoom() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + UpdateRoomRequest request = + UpdateRoomRequest.newBuilder() + .setRoom(Room.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + ApiFuture future = messagingClient.updateRoomCallable().futureCall(request); + // Do something. + Room response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_UpdateRoom_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/updateroom/SyncUpdateRoom.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/updateroom/SyncUpdateRoom.java new file mode 100644 index 0000000000..915b84c12e --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messaging/updateroom/SyncUpdateRoom.java @@ -0,0 +1,47 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_UpdateRoom_sync] +import com.google.protobuf.FieldMask; +import com.google.showcase.v1beta1.MessagingClient; +import com.google.showcase.v1beta1.Room; +import com.google.showcase.v1beta1.UpdateRoomRequest; + +public class SyncUpdateRoom { + + public static void main(String[] args) throws Exception { + syncUpdateRoom(); + } + + public static void syncUpdateRoom() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + UpdateRoomRequest request = + UpdateRoomRequest.newBuilder() + .setRoom(Room.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + Room response = messagingClient.updateRoom(request); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_UpdateRoom_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messagingsettings/createroom/SyncCreateRoom.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messagingsettings/createroom/SyncCreateRoom.java new file mode 100644 index 0000000000..2ab7cbe27e --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/messagingsettings/createroom/SyncCreateRoom.java @@ -0,0 +1,48 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_MessagingSettings_CreateRoom_sync] +import com.google.showcase.v1beta1.MessagingSettings; +import java.time.Duration; + +public class SyncCreateRoom { + + public static void main(String[] args) throws Exception { + syncCreateRoom(); + } + + public static void syncCreateRoom() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + MessagingSettings.Builder messagingSettingsBuilder = MessagingSettings.newBuilder(); + messagingSettingsBuilder + .createRoomSettings() + .setRetrySettings( + messagingSettingsBuilder + .createRoomSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + MessagingSettings messagingSettings = messagingSettingsBuilder.build(); + } +} +// [END localhost7469_v1beta1_generated_MessagingSettings_CreateRoom_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/attemptsequence/AsyncAttemptSequence.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/attemptsequence/AsyncAttemptSequence.java new file mode 100644 index 0000000000..b8cbd41577 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/attemptsequence/AsyncAttemptSequence.java @@ -0,0 +1,49 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_SequenceService_AttemptSequence_async] +import com.google.api.core.ApiFuture; +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.AttemptSequenceRequest; +import com.google.showcase.v1beta1.SequenceName; +import com.google.showcase.v1beta1.SequenceServiceClient; + +public class AsyncAttemptSequence { + + public static void main(String[] args) throws Exception { + asyncAttemptSequence(); + } + + public static void asyncAttemptSequence() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (SequenceServiceClient sequenceServiceClient = SequenceServiceClient.create()) { + AttemptSequenceRequest request = + AttemptSequenceRequest.newBuilder() + .setName(SequenceName.of("[SEQUENCE]").toString()) + .build(); + ApiFuture future = sequenceServiceClient.attemptSequenceCallable().futureCall(request); + // Do something. + future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_SequenceService_AttemptSequence_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/attemptsequence/SyncAttemptSequence.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/attemptsequence/SyncAttemptSequence.java new file mode 100644 index 0000000000..3d6637e455 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/attemptsequence/SyncAttemptSequence.java @@ -0,0 +1,46 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_SequenceService_AttemptSequence_sync] +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.AttemptSequenceRequest; +import com.google.showcase.v1beta1.SequenceName; +import com.google.showcase.v1beta1.SequenceServiceClient; + +public class SyncAttemptSequence { + + public static void main(String[] args) throws Exception { + syncAttemptSequence(); + } + + public static void syncAttemptSequence() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (SequenceServiceClient sequenceServiceClient = SequenceServiceClient.create()) { + AttemptSequenceRequest request = + AttemptSequenceRequest.newBuilder() + .setName(SequenceName.of("[SEQUENCE]").toString()) + .build(); + sequenceServiceClient.attemptSequence(request); + } + } +} +// [END localhost7469_v1beta1_generated_SequenceService_AttemptSequence_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/attemptsequence/SyncAttemptSequenceSequencename.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/attemptsequence/SyncAttemptSequenceSequencename.java new file mode 100644 index 0000000000..0e9a0ff985 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/attemptsequence/SyncAttemptSequenceSequencename.java @@ -0,0 +1,42 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_SequenceService_AttemptSequence_Sequencename_sync] +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.SequenceName; +import com.google.showcase.v1beta1.SequenceServiceClient; + +public class SyncAttemptSequenceSequencename { + + public static void main(String[] args) throws Exception { + syncAttemptSequenceSequencename(); + } + + public static void syncAttemptSequenceSequencename() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (SequenceServiceClient sequenceServiceClient = SequenceServiceClient.create()) { + SequenceName name = SequenceName.of("[SEQUENCE]"); + sequenceServiceClient.attemptSequence(name); + } + } +} +// [END localhost7469_v1beta1_generated_SequenceService_AttemptSequence_Sequencename_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/attemptsequence/SyncAttemptSequenceString.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/attemptsequence/SyncAttemptSequenceString.java new file mode 100644 index 0000000000..cfc94a15c6 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/attemptsequence/SyncAttemptSequenceString.java @@ -0,0 +1,42 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_SequenceService_AttemptSequence_String_sync] +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.SequenceName; +import com.google.showcase.v1beta1.SequenceServiceClient; + +public class SyncAttemptSequenceString { + + public static void main(String[] args) throws Exception { + syncAttemptSequenceString(); + } + + public static void syncAttemptSequenceString() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (SequenceServiceClient sequenceServiceClient = SequenceServiceClient.create()) { + String name = SequenceName.of("[SEQUENCE]").toString(); + sequenceServiceClient.attemptSequence(name); + } + } +} +// [END localhost7469_v1beta1_generated_SequenceService_AttemptSequence_String_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/create/SyncCreateSetCredentialsProvider.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/create/SyncCreateSetCredentialsProvider.java new file mode 100644 index 0000000000..b1c0a96894 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/create/SyncCreateSetCredentialsProvider.java @@ -0,0 +1,45 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_SequenceService_Create_SetCredentialsProvider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.showcase.v1beta1.SequenceServiceClient; +import com.google.showcase.v1beta1.SequenceServiceSettings; +import com.google.showcase.v1beta1.myCredentials; + +public class SyncCreateSetCredentialsProvider { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider(); + } + + public static void syncCreateSetCredentialsProvider() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + SequenceServiceSettings sequenceServiceSettings = + SequenceServiceSettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + SequenceServiceClient sequenceServiceClient = + SequenceServiceClient.create(sequenceServiceSettings); + } +} +// [END localhost7469_v1beta1_generated_SequenceService_Create_SetCredentialsProvider_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/create/SyncCreateSetCredentialsProvider1.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 0000000000..5f6f2f63f8 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/create/SyncCreateSetCredentialsProvider1.java @@ -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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_SequenceService_Create_SetCredentialsProvider1_sync] +import com.google.showcase.v1beta1.SequenceServiceClient; +import com.google.showcase.v1beta1.SequenceServiceSettings; + +public class SyncCreateSetCredentialsProvider1 { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider1(); + } + + public static void syncCreateSetCredentialsProvider1() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + SequenceServiceSettings sequenceServiceSettings = + SequenceServiceSettings.newHttpJsonBuilder().build(); + SequenceServiceClient sequenceServiceClient = + SequenceServiceClient.create(sequenceServiceSettings); + } +} +// [END localhost7469_v1beta1_generated_SequenceService_Create_SetCredentialsProvider1_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/create/SyncCreateSetEndpoint.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/create/SyncCreateSetEndpoint.java new file mode 100644 index 0000000000..80d2a57c02 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/create/SyncCreateSetEndpoint.java @@ -0,0 +1,42 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_SequenceService_Create_SetEndpoint_sync] +import com.google.showcase.v1beta1.SequenceServiceClient; +import com.google.showcase.v1beta1.SequenceServiceSettings; +import com.google.showcase.v1beta1.myEndpoint; + +public class SyncCreateSetEndpoint { + + public static void main(String[] args) throws Exception { + syncCreateSetEndpoint(); + } + + public static void syncCreateSetEndpoint() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + SequenceServiceSettings sequenceServiceSettings = + SequenceServiceSettings.newBuilder().setEndpoint(myEndpoint).build(); + SequenceServiceClient sequenceServiceClient = + SequenceServiceClient.create(sequenceServiceSettings); + } +} +// [END localhost7469_v1beta1_generated_SequenceService_Create_SetEndpoint_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/createsequence/AsyncCreateSequence.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/createsequence/AsyncCreateSequence.java new file mode 100644 index 0000000000..75bd7fdd4a --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/createsequence/AsyncCreateSequence.java @@ -0,0 +1,47 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_SequenceService_CreateSequence_async] +import com.google.api.core.ApiFuture; +import com.google.showcase.v1beta1.CreateSequenceRequest; +import com.google.showcase.v1beta1.Sequence; +import com.google.showcase.v1beta1.SequenceServiceClient; + +public class AsyncCreateSequence { + + public static void main(String[] args) throws Exception { + asyncCreateSequence(); + } + + public static void asyncCreateSequence() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (SequenceServiceClient sequenceServiceClient = SequenceServiceClient.create()) { + CreateSequenceRequest request = + CreateSequenceRequest.newBuilder().setSequence(Sequence.newBuilder().build()).build(); + ApiFuture future = + sequenceServiceClient.createSequenceCallable().futureCall(request); + // Do something. + Sequence response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_SequenceService_CreateSequence_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/createsequence/SyncCreateSequence.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/createsequence/SyncCreateSequence.java new file mode 100644 index 0000000000..b798739218 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/createsequence/SyncCreateSequence.java @@ -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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_SequenceService_CreateSequence_sync] +import com.google.showcase.v1beta1.CreateSequenceRequest; +import com.google.showcase.v1beta1.Sequence; +import com.google.showcase.v1beta1.SequenceServiceClient; + +public class SyncCreateSequence { + + public static void main(String[] args) throws Exception { + syncCreateSequence(); + } + + public static void syncCreateSequence() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (SequenceServiceClient sequenceServiceClient = SequenceServiceClient.create()) { + CreateSequenceRequest request = + CreateSequenceRequest.newBuilder().setSequence(Sequence.newBuilder().build()).build(); + Sequence response = sequenceServiceClient.createSequence(request); + } + } +} +// [END localhost7469_v1beta1_generated_SequenceService_CreateSequence_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/createsequence/SyncCreateSequenceSequence.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/createsequence/SyncCreateSequenceSequence.java new file mode 100644 index 0000000000..857cf07c55 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/createsequence/SyncCreateSequenceSequence.java @@ -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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_SequenceService_CreateSequence_Sequence_sync] +import com.google.showcase.v1beta1.Sequence; +import com.google.showcase.v1beta1.SequenceServiceClient; + +public class SyncCreateSequenceSequence { + + public static void main(String[] args) throws Exception { + syncCreateSequenceSequence(); + } + + public static void syncCreateSequenceSequence() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (SequenceServiceClient sequenceServiceClient = SequenceServiceClient.create()) { + Sequence sequence = Sequence.newBuilder().build(); + Sequence response = sequenceServiceClient.createSequence(sequence); + } + } +} +// [END localhost7469_v1beta1_generated_SequenceService_CreateSequence_Sequence_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/getsequencereport/AsyncGetSequenceReport.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/getsequencereport/AsyncGetSequenceReport.java new file mode 100644 index 0000000000..98e96691d7 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/getsequencereport/AsyncGetSequenceReport.java @@ -0,0 +1,50 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_SequenceService_GetSequenceReport_async] +import com.google.api.core.ApiFuture; +import com.google.showcase.v1beta1.GetSequenceReportRequest; +import com.google.showcase.v1beta1.SequenceReport; +import com.google.showcase.v1beta1.SequenceReportName; +import com.google.showcase.v1beta1.SequenceServiceClient; + +public class AsyncGetSequenceReport { + + public static void main(String[] args) throws Exception { + asyncGetSequenceReport(); + } + + public static void asyncGetSequenceReport() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (SequenceServiceClient sequenceServiceClient = SequenceServiceClient.create()) { + GetSequenceReportRequest request = + GetSequenceReportRequest.newBuilder() + .setName(SequenceReportName.of("[SEQUENCE]").toString()) + .build(); + ApiFuture future = + sequenceServiceClient.getSequenceReportCallable().futureCall(request); + // Do something. + SequenceReport response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_SequenceService_GetSequenceReport_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/getsequencereport/SyncGetSequenceReport.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/getsequencereport/SyncGetSequenceReport.java new file mode 100644 index 0000000000..703ffb36fc --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/getsequencereport/SyncGetSequenceReport.java @@ -0,0 +1,46 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_SequenceService_GetSequenceReport_sync] +import com.google.showcase.v1beta1.GetSequenceReportRequest; +import com.google.showcase.v1beta1.SequenceReport; +import com.google.showcase.v1beta1.SequenceReportName; +import com.google.showcase.v1beta1.SequenceServiceClient; + +public class SyncGetSequenceReport { + + public static void main(String[] args) throws Exception { + syncGetSequenceReport(); + } + + public static void syncGetSequenceReport() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (SequenceServiceClient sequenceServiceClient = SequenceServiceClient.create()) { + GetSequenceReportRequest request = + GetSequenceReportRequest.newBuilder() + .setName(SequenceReportName.of("[SEQUENCE]").toString()) + .build(); + SequenceReport response = sequenceServiceClient.getSequenceReport(request); + } + } +} +// [END localhost7469_v1beta1_generated_SequenceService_GetSequenceReport_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/getsequencereport/SyncGetSequenceReportSequencereportname.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/getsequencereport/SyncGetSequenceReportSequencereportname.java new file mode 100644 index 0000000000..d40653efc3 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/getsequencereport/SyncGetSequenceReportSequencereportname.java @@ -0,0 +1,42 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_SequenceService_GetSequenceReport_Sequencereportname_sync] +import com.google.showcase.v1beta1.SequenceReport; +import com.google.showcase.v1beta1.SequenceReportName; +import com.google.showcase.v1beta1.SequenceServiceClient; + +public class SyncGetSequenceReportSequencereportname { + + public static void main(String[] args) throws Exception { + syncGetSequenceReportSequencereportname(); + } + + public static void syncGetSequenceReportSequencereportname() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (SequenceServiceClient sequenceServiceClient = SequenceServiceClient.create()) { + SequenceReportName name = SequenceReportName.of("[SEQUENCE]"); + SequenceReport response = sequenceServiceClient.getSequenceReport(name); + } + } +} +// [END localhost7469_v1beta1_generated_SequenceService_GetSequenceReport_Sequencereportname_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/getsequencereport/SyncGetSequenceReportString.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/getsequencereport/SyncGetSequenceReportString.java new file mode 100644 index 0000000000..f0ac090a1f --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservice/getsequencereport/SyncGetSequenceReportString.java @@ -0,0 +1,42 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_SequenceService_GetSequenceReport_String_sync] +import com.google.showcase.v1beta1.SequenceReport; +import com.google.showcase.v1beta1.SequenceReportName; +import com.google.showcase.v1beta1.SequenceServiceClient; + +public class SyncGetSequenceReportString { + + public static void main(String[] args) throws Exception { + syncGetSequenceReportString(); + } + + public static void syncGetSequenceReportString() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (SequenceServiceClient sequenceServiceClient = SequenceServiceClient.create()) { + String name = SequenceReportName.of("[SEQUENCE]").toString(); + SequenceReport response = sequenceServiceClient.getSequenceReport(name); + } + } +} +// [END localhost7469_v1beta1_generated_SequenceService_GetSequenceReport_String_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservicesettings/createsequence/SyncCreateSequence.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservicesettings/createsequence/SyncCreateSequence.java new file mode 100644 index 0000000000..d225414159 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/sequenceservicesettings/createsequence/SyncCreateSequence.java @@ -0,0 +1,49 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_SequenceServiceSettings_CreateSequence_sync] +import com.google.showcase.v1beta1.SequenceServiceSettings; +import java.time.Duration; + +public class SyncCreateSequence { + + public static void main(String[] args) throws Exception { + syncCreateSequence(); + } + + public static void syncCreateSequence() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + SequenceServiceSettings.Builder sequenceServiceSettingsBuilder = + SequenceServiceSettings.newBuilder(); + sequenceServiceSettingsBuilder + .createSequenceSettings() + .setRetrySettings( + sequenceServiceSettingsBuilder + .createSequenceSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + SequenceServiceSettings sequenceServiceSettings = sequenceServiceSettingsBuilder.build(); + } +} +// [END localhost7469_v1beta1_generated_SequenceServiceSettings_CreateSequence_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/stub/compliancestubsettings/repeatdatabody/SyncRepeatDataBody.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/stub/compliancestubsettings/repeatdatabody/SyncRepeatDataBody.java new file mode 100644 index 0000000000..c0b9e53a5b --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/stub/compliancestubsettings/repeatdatabody/SyncRepeatDataBody.java @@ -0,0 +1,48 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub.samples; + +// [START localhost7469_v1beta1_generated_ComplianceStubSettings_RepeatDataBody_sync] +import com.google.showcase.v1beta1.stub.ComplianceStubSettings; +import java.time.Duration; + +public class SyncRepeatDataBody { + + public static void main(String[] args) throws Exception { + syncRepeatDataBody(); + } + + public static void syncRepeatDataBody() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + ComplianceStubSettings.Builder complianceSettingsBuilder = ComplianceStubSettings.newBuilder(); + complianceSettingsBuilder + .repeatDataBodySettings() + .setRetrySettings( + complianceSettingsBuilder + .repeatDataBodySettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + ComplianceStubSettings complianceSettings = complianceSettingsBuilder.build(); + } +} +// [END localhost7469_v1beta1_generated_ComplianceStubSettings_RepeatDataBody_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/stub/echostubsettings/echo/SyncEcho.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/stub/echostubsettings/echo/SyncEcho.java new file mode 100644 index 0000000000..a7a18faf48 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/stub/echostubsettings/echo/SyncEcho.java @@ -0,0 +1,48 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub.samples; + +// [START localhost7469_v1beta1_generated_EchoStubSettings_Echo_sync] +import com.google.showcase.v1beta1.stub.EchoStubSettings; +import java.time.Duration; + +public class SyncEcho { + + public static void main(String[] args) throws Exception { + syncEcho(); + } + + public static void syncEcho() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + EchoStubSettings.Builder echoSettingsBuilder = EchoStubSettings.newBuilder(); + echoSettingsBuilder + .echoSettings() + .setRetrySettings( + echoSettingsBuilder + .echoSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + EchoStubSettings echoSettings = echoSettingsBuilder.build(); + } +} +// [END localhost7469_v1beta1_generated_EchoStubSettings_Echo_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/stub/identitystubsettings/createuser/SyncCreateUser.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/stub/identitystubsettings/createuser/SyncCreateUser.java new file mode 100644 index 0000000000..0413eb47cd --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/stub/identitystubsettings/createuser/SyncCreateUser.java @@ -0,0 +1,48 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub.samples; + +// [START localhost7469_v1beta1_generated_IdentityStubSettings_CreateUser_sync] +import com.google.showcase.v1beta1.stub.IdentityStubSettings; +import java.time.Duration; + +public class SyncCreateUser { + + public static void main(String[] args) throws Exception { + syncCreateUser(); + } + + public static void syncCreateUser() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + IdentityStubSettings.Builder identitySettingsBuilder = IdentityStubSettings.newBuilder(); + identitySettingsBuilder + .createUserSettings() + .setRetrySettings( + identitySettingsBuilder + .createUserSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + IdentityStubSettings identitySettings = identitySettingsBuilder.build(); + } +} +// [END localhost7469_v1beta1_generated_IdentityStubSettings_CreateUser_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/stub/messagingstubsettings/createroom/SyncCreateRoom.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/stub/messagingstubsettings/createroom/SyncCreateRoom.java new file mode 100644 index 0000000000..deffa23fc2 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/stub/messagingstubsettings/createroom/SyncCreateRoom.java @@ -0,0 +1,48 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub.samples; + +// [START localhost7469_v1beta1_generated_MessagingStubSettings_CreateRoom_sync] +import com.google.showcase.v1beta1.stub.MessagingStubSettings; +import java.time.Duration; + +public class SyncCreateRoom { + + public static void main(String[] args) throws Exception { + syncCreateRoom(); + } + + public static void syncCreateRoom() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + MessagingStubSettings.Builder messagingSettingsBuilder = MessagingStubSettings.newBuilder(); + messagingSettingsBuilder + .createRoomSettings() + .setRetrySettings( + messagingSettingsBuilder + .createRoomSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + MessagingStubSettings messagingSettings = messagingSettingsBuilder.build(); + } +} +// [END localhost7469_v1beta1_generated_MessagingStubSettings_CreateRoom_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/stub/sequenceservicestubsettings/createsequence/SyncCreateSequence.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/stub/sequenceservicestubsettings/createsequence/SyncCreateSequence.java new file mode 100644 index 0000000000..c34917c717 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/stub/sequenceservicestubsettings/createsequence/SyncCreateSequence.java @@ -0,0 +1,49 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub.samples; + +// [START localhost7469_v1beta1_generated_SequenceServiceStubSettings_CreateSequence_sync] +import com.google.showcase.v1beta1.stub.SequenceServiceStubSettings; +import java.time.Duration; + +public class SyncCreateSequence { + + public static void main(String[] args) throws Exception { + syncCreateSequence(); + } + + public static void syncCreateSequence() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + SequenceServiceStubSettings.Builder sequenceServiceSettingsBuilder = + SequenceServiceStubSettings.newBuilder(); + sequenceServiceSettingsBuilder + .createSequenceSettings() + .setRetrySettings( + sequenceServiceSettingsBuilder + .createSequenceSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + SequenceServiceStubSettings sequenceServiceSettings = sequenceServiceSettingsBuilder.build(); + } +} +// [END localhost7469_v1beta1_generated_SequenceServiceStubSettings_CreateSequence_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/stub/testingstubsettings/createsession/SyncCreateSession.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/stub/testingstubsettings/createsession/SyncCreateSession.java new file mode 100644 index 0000000000..0bac2ef097 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/stub/testingstubsettings/createsession/SyncCreateSession.java @@ -0,0 +1,48 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub.samples; + +// [START localhost7469_v1beta1_generated_TestingStubSettings_CreateSession_sync] +import com.google.showcase.v1beta1.stub.TestingStubSettings; +import java.time.Duration; + +public class SyncCreateSession { + + public static void main(String[] args) throws Exception { + syncCreateSession(); + } + + public static void syncCreateSession() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + TestingStubSettings.Builder testingSettingsBuilder = TestingStubSettings.newBuilder(); + testingSettingsBuilder + .createSessionSettings() + .setRetrySettings( + testingSettingsBuilder + .createSessionSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + TestingStubSettings testingSettings = testingSettingsBuilder.build(); + } +} +// [END localhost7469_v1beta1_generated_TestingStubSettings_CreateSession_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/create/SyncCreateSetCredentialsProvider.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/create/SyncCreateSetCredentialsProvider.java new file mode 100644 index 0000000000..54e8f745b6 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/create/SyncCreateSetCredentialsProvider.java @@ -0,0 +1,44 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Testing_Create_SetCredentialsProvider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.showcase.v1beta1.TestingClient; +import com.google.showcase.v1beta1.TestingSettings; +import com.google.showcase.v1beta1.myCredentials; + +public class SyncCreateSetCredentialsProvider { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider(); + } + + public static void syncCreateSetCredentialsProvider() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + TestingSettings testingSettings = + TestingSettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + TestingClient testingClient = TestingClient.create(testingSettings); + } +} +// [END localhost7469_v1beta1_generated_Testing_Create_SetCredentialsProvider_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/create/SyncCreateSetCredentialsProvider1.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 0000000000..98fb47f1f2 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/create/SyncCreateSetCredentialsProvider1.java @@ -0,0 +1,39 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Testing_Create_SetCredentialsProvider1_sync] +import com.google.showcase.v1beta1.TestingClient; +import com.google.showcase.v1beta1.TestingSettings; + +public class SyncCreateSetCredentialsProvider1 { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider1(); + } + + public static void syncCreateSetCredentialsProvider1() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + TestingSettings testingSettings = TestingSettings.newHttpJsonBuilder().build(); + TestingClient testingClient = TestingClient.create(testingSettings); + } +} +// [END localhost7469_v1beta1_generated_Testing_Create_SetCredentialsProvider1_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/create/SyncCreateSetEndpoint.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/create/SyncCreateSetEndpoint.java new file mode 100644 index 0000000000..31d2c2a00c --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/create/SyncCreateSetEndpoint.java @@ -0,0 +1,40 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Testing_Create_SetEndpoint_sync] +import com.google.showcase.v1beta1.TestingClient; +import com.google.showcase.v1beta1.TestingSettings; +import com.google.showcase.v1beta1.myEndpoint; + +public class SyncCreateSetEndpoint { + + public static void main(String[] args) throws Exception { + syncCreateSetEndpoint(); + } + + public static void syncCreateSetEndpoint() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + TestingSettings testingSettings = TestingSettings.newBuilder().setEndpoint(myEndpoint).build(); + TestingClient testingClient = TestingClient.create(testingSettings); + } +} +// [END localhost7469_v1beta1_generated_Testing_Create_SetEndpoint_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/createsession/AsyncCreateSession.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/createsession/AsyncCreateSession.java new file mode 100644 index 0000000000..6706d5fbbf --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/createsession/AsyncCreateSession.java @@ -0,0 +1,46 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Testing_CreateSession_async] +import com.google.api.core.ApiFuture; +import com.google.showcase.v1beta1.CreateSessionRequest; +import com.google.showcase.v1beta1.Session; +import com.google.showcase.v1beta1.TestingClient; + +public class AsyncCreateSession { + + public static void main(String[] args) throws Exception { + asyncCreateSession(); + } + + public static void asyncCreateSession() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (TestingClient testingClient = TestingClient.create()) { + CreateSessionRequest request = + CreateSessionRequest.newBuilder().setSession(Session.newBuilder().build()).build(); + ApiFuture future = testingClient.createSessionCallable().futureCall(request); + // Do something. + Session response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Testing_CreateSession_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/createsession/SyncCreateSession.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/createsession/SyncCreateSession.java new file mode 100644 index 0000000000..1e155623d0 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/createsession/SyncCreateSession.java @@ -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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Testing_CreateSession_sync] +import com.google.showcase.v1beta1.CreateSessionRequest; +import com.google.showcase.v1beta1.Session; +import com.google.showcase.v1beta1.TestingClient; + +public class SyncCreateSession { + + public static void main(String[] args) throws Exception { + syncCreateSession(); + } + + public static void syncCreateSession() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (TestingClient testingClient = TestingClient.create()) { + CreateSessionRequest request = + CreateSessionRequest.newBuilder().setSession(Session.newBuilder().build()).build(); + Session response = testingClient.createSession(request); + } + } +} +// [END localhost7469_v1beta1_generated_Testing_CreateSession_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/deletesession/AsyncDeleteSession.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/deletesession/AsyncDeleteSession.java new file mode 100644 index 0000000000..38d1dff284 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/deletesession/AsyncDeleteSession.java @@ -0,0 +1,47 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Testing_DeleteSession_async] +import com.google.api.core.ApiFuture; +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.DeleteSessionRequest; +import com.google.showcase.v1beta1.SessionName; +import com.google.showcase.v1beta1.TestingClient; + +public class AsyncDeleteSession { + + public static void main(String[] args) throws Exception { + asyncDeleteSession(); + } + + public static void asyncDeleteSession() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (TestingClient testingClient = TestingClient.create()) { + DeleteSessionRequest request = + DeleteSessionRequest.newBuilder().setName(SessionName.of("[SESSION]").toString()).build(); + ApiFuture future = testingClient.deleteSessionCallable().futureCall(request); + // Do something. + future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Testing_DeleteSession_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/deletesession/SyncDeleteSession.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/deletesession/SyncDeleteSession.java new file mode 100644 index 0000000000..d8e1cfcefb --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/deletesession/SyncDeleteSession.java @@ -0,0 +1,44 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Testing_DeleteSession_sync] +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.DeleteSessionRequest; +import com.google.showcase.v1beta1.SessionName; +import com.google.showcase.v1beta1.TestingClient; + +public class SyncDeleteSession { + + public static void main(String[] args) throws Exception { + syncDeleteSession(); + } + + public static void syncDeleteSession() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (TestingClient testingClient = TestingClient.create()) { + DeleteSessionRequest request = + DeleteSessionRequest.newBuilder().setName(SessionName.of("[SESSION]").toString()).build(); + testingClient.deleteSession(request); + } + } +} +// [END localhost7469_v1beta1_generated_Testing_DeleteSession_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/deletetest/AsyncDeleteTest.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/deletetest/AsyncDeleteTest.java new file mode 100644 index 0000000000..bbe7e7edc2 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/deletetest/AsyncDeleteTest.java @@ -0,0 +1,49 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Testing_DeleteTest_async] +import com.google.api.core.ApiFuture; +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.DeleteTestRequest; +import com.google.showcase.v1beta1.TestName; +import com.google.showcase.v1beta1.TestingClient; + +public class AsyncDeleteTest { + + public static void main(String[] args) throws Exception { + asyncDeleteTest(); + } + + public static void asyncDeleteTest() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (TestingClient testingClient = TestingClient.create()) { + DeleteTestRequest request = + DeleteTestRequest.newBuilder() + .setName(TestName.of("[SESSION]", "[TEST]").toString()) + .build(); + ApiFuture future = testingClient.deleteTestCallable().futureCall(request); + // Do something. + future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Testing_DeleteTest_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/deletetest/SyncDeleteTest.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/deletetest/SyncDeleteTest.java new file mode 100644 index 0000000000..aa2ad11d74 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/deletetest/SyncDeleteTest.java @@ -0,0 +1,46 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Testing_DeleteTest_sync] +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.DeleteTestRequest; +import com.google.showcase.v1beta1.TestName; +import com.google.showcase.v1beta1.TestingClient; + +public class SyncDeleteTest { + + public static void main(String[] args) throws Exception { + syncDeleteTest(); + } + + public static void syncDeleteTest() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (TestingClient testingClient = TestingClient.create()) { + DeleteTestRequest request = + DeleteTestRequest.newBuilder() + .setName(TestName.of("[SESSION]", "[TEST]").toString()) + .build(); + testingClient.deleteTest(request); + } + } +} +// [END localhost7469_v1beta1_generated_Testing_DeleteTest_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/getsession/AsyncGetSession.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/getsession/AsyncGetSession.java new file mode 100644 index 0000000000..f00a7a974b --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/getsession/AsyncGetSession.java @@ -0,0 +1,47 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Testing_GetSession_async] +import com.google.api.core.ApiFuture; +import com.google.showcase.v1beta1.GetSessionRequest; +import com.google.showcase.v1beta1.Session; +import com.google.showcase.v1beta1.SessionName; +import com.google.showcase.v1beta1.TestingClient; + +public class AsyncGetSession { + + public static void main(String[] args) throws Exception { + asyncGetSession(); + } + + public static void asyncGetSession() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (TestingClient testingClient = TestingClient.create()) { + GetSessionRequest request = + GetSessionRequest.newBuilder().setName(SessionName.of("[SESSION]").toString()).build(); + ApiFuture future = testingClient.getSessionCallable().futureCall(request); + // Do something. + Session response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Testing_GetSession_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/getsession/SyncGetSession.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/getsession/SyncGetSession.java new file mode 100644 index 0000000000..3ed0205286 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/getsession/SyncGetSession.java @@ -0,0 +1,44 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Testing_GetSession_sync] +import com.google.showcase.v1beta1.GetSessionRequest; +import com.google.showcase.v1beta1.Session; +import com.google.showcase.v1beta1.SessionName; +import com.google.showcase.v1beta1.TestingClient; + +public class SyncGetSession { + + public static void main(String[] args) throws Exception { + syncGetSession(); + } + + public static void syncGetSession() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (TestingClient testingClient = TestingClient.create()) { + GetSessionRequest request = + GetSessionRequest.newBuilder().setName(SessionName.of("[SESSION]").toString()).build(); + Session response = testingClient.getSession(request); + } + } +} +// [END localhost7469_v1beta1_generated_Testing_GetSession_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/listsessions/AsyncListSessions.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/listsessions/AsyncListSessions.java new file mode 100644 index 0000000000..416101c8d7 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/listsessions/AsyncListSessions.java @@ -0,0 +1,51 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Testing_ListSessions_async] +import com.google.api.core.ApiFuture; +import com.google.showcase.v1beta1.ListSessionsRequest; +import com.google.showcase.v1beta1.Session; +import com.google.showcase.v1beta1.TestingClient; + +public class AsyncListSessions { + + public static void main(String[] args) throws Exception { + asyncListSessions(); + } + + public static void asyncListSessions() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (TestingClient testingClient = TestingClient.create()) { + ListSessionsRequest request = + ListSessionsRequest.newBuilder() + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + ApiFuture future = testingClient.listSessionsPagedCallable().futureCall(request); + // Do something. + for (Session element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END localhost7469_v1beta1_generated_Testing_ListSessions_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/listsessions/AsyncListSessionsPaged.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/listsessions/AsyncListSessionsPaged.java new file mode 100644 index 0000000000..afc3931922 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/listsessions/AsyncListSessionsPaged.java @@ -0,0 +1,59 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Testing_ListSessions_Paged_async] +import com.google.common.base.Strings; +import com.google.showcase.v1beta1.ListSessionsRequest; +import com.google.showcase.v1beta1.ListSessionsResponse; +import com.google.showcase.v1beta1.Session; +import com.google.showcase.v1beta1.TestingClient; + +public class AsyncListSessionsPaged { + + public static void main(String[] args) throws Exception { + asyncListSessionsPaged(); + } + + public static void asyncListSessionsPaged() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (TestingClient testingClient = TestingClient.create()) { + ListSessionsRequest request = + ListSessionsRequest.newBuilder() + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + while (true) { + ListSessionsResponse response = testingClient.listSessionsCallable().call(request); + for (Session element : response.getSessionsList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END localhost7469_v1beta1_generated_Testing_ListSessions_Paged_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/listsessions/SyncListSessions.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/listsessions/SyncListSessions.java new file mode 100644 index 0000000000..af3db7796e --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/listsessions/SyncListSessions.java @@ -0,0 +1,48 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Testing_ListSessions_sync] +import com.google.showcase.v1beta1.ListSessionsRequest; +import com.google.showcase.v1beta1.Session; +import com.google.showcase.v1beta1.TestingClient; + +public class SyncListSessions { + + public static void main(String[] args) throws Exception { + syncListSessions(); + } + + public static void syncListSessions() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (TestingClient testingClient = TestingClient.create()) { + ListSessionsRequest request = + ListSessionsRequest.newBuilder() + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + for (Session element : testingClient.listSessions(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END localhost7469_v1beta1_generated_Testing_ListSessions_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/listtests/AsyncListTests.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/listtests/AsyncListTests.java new file mode 100644 index 0000000000..b32136cb50 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/listtests/AsyncListTests.java @@ -0,0 +1,53 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Testing_ListTests_async] +import com.google.api.core.ApiFuture; +import com.google.showcase.v1beta1.ListTestsRequest; +import com.google.showcase.v1beta1.SessionName; +import com.google.showcase.v1beta1.Test; +import com.google.showcase.v1beta1.TestingClient; + +public class AsyncListTests { + + public static void main(String[] args) throws Exception { + asyncListTests(); + } + + public static void asyncListTests() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (TestingClient testingClient = TestingClient.create()) { + ListTestsRequest request = + ListTestsRequest.newBuilder() + .setParent(SessionName.of("[SESSION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + ApiFuture future = testingClient.listTestsPagedCallable().futureCall(request); + // Do something. + for (Test element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END localhost7469_v1beta1_generated_Testing_ListTests_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/listtests/AsyncListTestsPaged.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/listtests/AsyncListTestsPaged.java new file mode 100644 index 0000000000..41692c2cdc --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/listtests/AsyncListTestsPaged.java @@ -0,0 +1,61 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Testing_ListTests_Paged_async] +import com.google.common.base.Strings; +import com.google.showcase.v1beta1.ListTestsRequest; +import com.google.showcase.v1beta1.ListTestsResponse; +import com.google.showcase.v1beta1.SessionName; +import com.google.showcase.v1beta1.Test; +import com.google.showcase.v1beta1.TestingClient; + +public class AsyncListTestsPaged { + + public static void main(String[] args) throws Exception { + asyncListTestsPaged(); + } + + public static void asyncListTestsPaged() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (TestingClient testingClient = TestingClient.create()) { + ListTestsRequest request = + ListTestsRequest.newBuilder() + .setParent(SessionName.of("[SESSION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + while (true) { + ListTestsResponse response = testingClient.listTestsCallable().call(request); + for (Test element : response.getTestsList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END localhost7469_v1beta1_generated_Testing_ListTests_Paged_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/listtests/SyncListTests.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/listtests/SyncListTests.java new file mode 100644 index 0000000000..09e918bcbf --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/listtests/SyncListTests.java @@ -0,0 +1,50 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Testing_ListTests_sync] +import com.google.showcase.v1beta1.ListTestsRequest; +import com.google.showcase.v1beta1.SessionName; +import com.google.showcase.v1beta1.Test; +import com.google.showcase.v1beta1.TestingClient; + +public class SyncListTests { + + public static void main(String[] args) throws Exception { + syncListTests(); + } + + public static void syncListTests() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (TestingClient testingClient = TestingClient.create()) { + ListTestsRequest request = + ListTestsRequest.newBuilder() + .setParent(SessionName.of("[SESSION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + for (Test element : testingClient.listTests(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END localhost7469_v1beta1_generated_Testing_ListTests_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/reportsession/AsyncReportSession.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/reportsession/AsyncReportSession.java new file mode 100644 index 0000000000..b049d290f1 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/reportsession/AsyncReportSession.java @@ -0,0 +1,48 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Testing_ReportSession_async] +import com.google.api.core.ApiFuture; +import com.google.showcase.v1beta1.ReportSessionRequest; +import com.google.showcase.v1beta1.ReportSessionResponse; +import com.google.showcase.v1beta1.SessionName; +import com.google.showcase.v1beta1.TestingClient; + +public class AsyncReportSession { + + public static void main(String[] args) throws Exception { + asyncReportSession(); + } + + public static void asyncReportSession() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (TestingClient testingClient = TestingClient.create()) { + ReportSessionRequest request = + ReportSessionRequest.newBuilder().setName(SessionName.of("[SESSION]").toString()).build(); + ApiFuture future = + testingClient.reportSessionCallable().futureCall(request); + // Do something. + ReportSessionResponse response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Testing_ReportSession_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/reportsession/SyncReportSession.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/reportsession/SyncReportSession.java new file mode 100644 index 0000000000..1420b6a569 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/reportsession/SyncReportSession.java @@ -0,0 +1,44 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Testing_ReportSession_sync] +import com.google.showcase.v1beta1.ReportSessionRequest; +import com.google.showcase.v1beta1.ReportSessionResponse; +import com.google.showcase.v1beta1.SessionName; +import com.google.showcase.v1beta1.TestingClient; + +public class SyncReportSession { + + public static void main(String[] args) throws Exception { + syncReportSession(); + } + + public static void syncReportSession() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (TestingClient testingClient = TestingClient.create()) { + ReportSessionRequest request = + ReportSessionRequest.newBuilder().setName(SessionName.of("[SESSION]").toString()).build(); + ReportSessionResponse response = testingClient.reportSession(request); + } + } +} +// [END localhost7469_v1beta1_generated_Testing_ReportSession_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/verifytest/AsyncVerifyTest.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/verifytest/AsyncVerifyTest.java new file mode 100644 index 0000000000..1c6216b9ba --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/verifytest/AsyncVerifyTest.java @@ -0,0 +1,53 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Testing_VerifyTest_async] +import com.google.api.core.ApiFuture; +import com.google.protobuf.ByteString; +import com.google.showcase.v1beta1.TestName; +import com.google.showcase.v1beta1.TestingClient; +import com.google.showcase.v1beta1.VerifyTestRequest; +import com.google.showcase.v1beta1.VerifyTestResponse; +import java.util.ArrayList; + +public class AsyncVerifyTest { + + public static void main(String[] args) throws Exception { + asyncVerifyTest(); + } + + public static void asyncVerifyTest() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (TestingClient testingClient = TestingClient.create()) { + VerifyTestRequest request = + VerifyTestRequest.newBuilder() + .setName(TestName.of("[SESSION]", "[TEST]").toString()) + .setAnswer(ByteString.EMPTY) + .addAllAnswers(new ArrayList()) + .build(); + ApiFuture future = testingClient.verifyTestCallable().futureCall(request); + // Do something. + VerifyTestResponse response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Testing_VerifyTest_async] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/verifytest/SyncVerifyTest.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/verifytest/SyncVerifyTest.java new file mode 100644 index 0000000000..26ed7c7d1a --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testing/verifytest/SyncVerifyTest.java @@ -0,0 +1,50 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Testing_VerifyTest_sync] +import com.google.protobuf.ByteString; +import com.google.showcase.v1beta1.TestName; +import com.google.showcase.v1beta1.TestingClient; +import com.google.showcase.v1beta1.VerifyTestRequest; +import com.google.showcase.v1beta1.VerifyTestResponse; +import java.util.ArrayList; + +public class SyncVerifyTest { + + public static void main(String[] args) throws Exception { + syncVerifyTest(); + } + + public static void syncVerifyTest() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (TestingClient testingClient = TestingClient.create()) { + VerifyTestRequest request = + VerifyTestRequest.newBuilder() + .setName(TestName.of("[SESSION]", "[TEST]").toString()) + .setAnswer(ByteString.EMPTY) + .addAllAnswers(new ArrayList()) + .build(); + VerifyTestResponse response = testingClient.verifyTest(request); + } + } +} +// [END localhost7469_v1beta1_generated_Testing_VerifyTest_sync] diff --git a/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testingsettings/createsession/SyncCreateSession.java b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testingsettings/createsession/SyncCreateSession.java new file mode 100644 index 0000000000..9fd60bceb9 --- /dev/null +++ b/test/integration/goldens/showcase/samples/snippets/generated/main/java/com/google/showcase/v1beta1/testingsettings/createsession/SyncCreateSession.java @@ -0,0 +1,48 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_TestingSettings_CreateSession_sync] +import com.google.showcase.v1beta1.TestingSettings; +import java.time.Duration; + +public class SyncCreateSession { + + public static void main(String[] args) throws Exception { + syncCreateSession(); + } + + public static void syncCreateSession() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + TestingSettings.Builder testingSettingsBuilder = TestingSettings.newBuilder(); + testingSettingsBuilder + .createSessionSettings() + .setRetrySettings( + testingSettingsBuilder + .createSessionSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + TestingSettings testingSettings = testingSettingsBuilder.build(); + } +} +// [END localhost7469_v1beta1_generated_TestingSettings_CreateSession_sync] diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/BlurbName.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/BlurbName.java new file mode 100644 index 0000000000..32f3ed2380 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/BlurbName.java @@ -0,0 +1,473 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import com.google.api.core.BetaApi; +import com.google.api.pathtemplate.PathTemplate; +import com.google.api.pathtemplate.ValidationException; +import com.google.api.resourcenames.ResourceName; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableMap; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +@Generated("by gapic-generator-java") +public class BlurbName implements ResourceName { + private static final PathTemplate USER_LEGACY_USER_BLURB = + PathTemplate.createWithoutUrlEncoding( + "users/{user}/profile/blurbs/legacy/{legacy_user}~{blurb}"); + private static final PathTemplate USER_BLURB = + PathTemplate.createWithoutUrlEncoding("users/{user}/profile/blurbs/{blurb}"); + private static final PathTemplate ROOM_BLURB = + PathTemplate.createWithoutUrlEncoding("rooms/{room}/blurbs/{blurb}"); + private static final PathTemplate ROOM_LEGACY_ROOM_BLURB = + PathTemplate.createWithoutUrlEncoding("rooms/{room}/blurbs/legacy/{legacy_room}.{blurb}"); + private volatile Map fieldValuesMap; + private PathTemplate pathTemplate; + private String fixedValue; + private final String user; + private final String legacyUser; + private final String blurb; + private final String room; + private final String legacyRoom; + + @Deprecated + protected BlurbName() { + user = null; + legacyUser = null; + blurb = null; + room = null; + legacyRoom = null; + } + + private BlurbName(Builder builder) { + user = Preconditions.checkNotNull(builder.getUser()); + legacyUser = Preconditions.checkNotNull(builder.getLegacyUser()); + blurb = Preconditions.checkNotNull(builder.getBlurb()); + room = null; + legacyRoom = null; + pathTemplate = USER_LEGACY_USER_BLURB; + } + + private BlurbName(UserBlurbBuilder builder) { + user = Preconditions.checkNotNull(builder.getUser()); + blurb = Preconditions.checkNotNull(builder.getBlurb()); + legacyUser = null; + room = null; + legacyRoom = null; + pathTemplate = USER_BLURB; + } + + private BlurbName(RoomBlurbBuilder builder) { + room = Preconditions.checkNotNull(builder.getRoom()); + blurb = Preconditions.checkNotNull(builder.getBlurb()); + user = null; + legacyUser = null; + legacyRoom = null; + pathTemplate = ROOM_BLURB; + } + + private BlurbName(RoomLegacyRoomBlurbBuilder builder) { + room = Preconditions.checkNotNull(builder.getRoom()); + legacyRoom = Preconditions.checkNotNull(builder.getLegacyRoom()); + blurb = Preconditions.checkNotNull(builder.getBlurb()); + user = null; + legacyUser = null; + pathTemplate = ROOM_LEGACY_ROOM_BLURB; + } + + public String getUser() { + return user; + } + + public String getLegacyUser() { + return legacyUser; + } + + public String getBlurb() { + return blurb; + } + + public String getRoom() { + return room; + } + + public String getLegacyRoom() { + return legacyRoom; + } + + public static Builder newBuilder() { + return new Builder(); + } + + @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") + public static Builder newUserLegacyUserBlurbBuilder() { + return new Builder(); + } + + @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") + public static UserBlurbBuilder newUserBlurbBuilder() { + return new UserBlurbBuilder(); + } + + @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") + public static RoomBlurbBuilder newRoomBlurbBuilder() { + return new RoomBlurbBuilder(); + } + + @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") + public static RoomLegacyRoomBlurbBuilder newRoomLegacyRoomBlurbBuilder() { + return new RoomLegacyRoomBlurbBuilder(); + } + + public Builder toBuilder() { + return new Builder(this); + } + + public static BlurbName of(String user, String legacyUser, String blurb) { + return newBuilder().setUser(user).setLegacyUser(legacyUser).setBlurb(blurb).build(); + } + + @BetaApi("The static create methods are not stable yet and may be changed in the future.") + public static BlurbName ofUserLegacyUserBlurbName(String user, String legacyUser, String blurb) { + return newBuilder().setUser(user).setLegacyUser(legacyUser).setBlurb(blurb).build(); + } + + @BetaApi("The static create methods are not stable yet and may be changed in the future.") + public static BlurbName ofUserBlurbName(String user, String blurb) { + return newUserBlurbBuilder().setUser(user).setBlurb(blurb).build(); + } + + @BetaApi("The static create methods are not stable yet and may be changed in the future.") + public static BlurbName ofRoomBlurbName(String room, String blurb) { + return newRoomBlurbBuilder().setRoom(room).setBlurb(blurb).build(); + } + + @BetaApi("The static create methods are not stable yet and may be changed in the future.") + public static BlurbName ofRoomLegacyRoomBlurbName(String room, String legacyRoom, String blurb) { + return newRoomLegacyRoomBlurbBuilder() + .setRoom(room) + .setLegacyRoom(legacyRoom) + .setBlurb(blurb) + .build(); + } + + public static String format(String user, String legacyUser, String blurb) { + return newBuilder().setUser(user).setLegacyUser(legacyUser).setBlurb(blurb).build().toString(); + } + + @BetaApi("The static format methods are not stable yet and may be changed in the future.") + public static String formatUserLegacyUserBlurbName(String user, String legacyUser, String blurb) { + return newBuilder().setUser(user).setLegacyUser(legacyUser).setBlurb(blurb).build().toString(); + } + + @BetaApi("The static format methods are not stable yet and may be changed in the future.") + public static String formatUserBlurbName(String user, String blurb) { + return newUserBlurbBuilder().setUser(user).setBlurb(blurb).build().toString(); + } + + @BetaApi("The static format methods are not stable yet and may be changed in the future.") + public static String formatRoomBlurbName(String room, String blurb) { + return newRoomBlurbBuilder().setRoom(room).setBlurb(blurb).build().toString(); + } + + @BetaApi("The static format methods are not stable yet and may be changed in the future.") + public static String formatRoomLegacyRoomBlurbName(String room, String legacyRoom, String blurb) { + return newRoomLegacyRoomBlurbBuilder() + .setRoom(room) + .setLegacyRoom(legacyRoom) + .setBlurb(blurb) + .build() + .toString(); + } + + public static BlurbName parse(String formattedString) { + if (formattedString.isEmpty()) { + return null; + } + if (USER_LEGACY_USER_BLURB.matches(formattedString)) { + Map matchMap = USER_LEGACY_USER_BLURB.match(formattedString); + return ofUserLegacyUserBlurbName( + matchMap.get("user"), matchMap.get("legacy_user"), matchMap.get("blurb")); + } else if (USER_BLURB.matches(formattedString)) { + Map matchMap = USER_BLURB.match(formattedString); + return ofUserBlurbName(matchMap.get("user"), matchMap.get("blurb")); + } else if (ROOM_BLURB.matches(formattedString)) { + Map matchMap = ROOM_BLURB.match(formattedString); + return ofRoomBlurbName(matchMap.get("room"), matchMap.get("blurb")); + } else if (ROOM_LEGACY_ROOM_BLURB.matches(formattedString)) { + Map matchMap = ROOM_LEGACY_ROOM_BLURB.match(formattedString); + return ofRoomLegacyRoomBlurbName( + matchMap.get("room"), matchMap.get("legacy_room"), matchMap.get("blurb")); + } + throw new ValidationException("BlurbName.parse: formattedString not in valid format"); + } + + public static List parseList(List formattedStrings) { + List list = new ArrayList<>(formattedStrings.size()); + for (String formattedString : formattedStrings) { + list.add(parse(formattedString)); + } + return list; + } + + public static List toStringList(List values) { + List list = new ArrayList<>(values.size()); + for (BlurbName value : values) { + if (value == null) { + list.add(""); + } else { + list.add(value.toString()); + } + } + return list; + } + + public static boolean isParsableFrom(String formattedString) { + return USER_LEGACY_USER_BLURB.matches(formattedString) + || USER_BLURB.matches(formattedString) + || ROOM_BLURB.matches(formattedString) + || ROOM_LEGACY_ROOM_BLURB.matches(formattedString); + } + + @Override + public Map getFieldValuesMap() { + if (fieldValuesMap == null) { + synchronized (this) { + if (fieldValuesMap == null) { + ImmutableMap.Builder fieldMapBuilder = ImmutableMap.builder(); + if (user != null) { + fieldMapBuilder.put("user", user); + } + if (legacyUser != null) { + fieldMapBuilder.put("legacy_user", legacyUser); + } + if (blurb != null) { + fieldMapBuilder.put("blurb", blurb); + } + if (room != null) { + fieldMapBuilder.put("room", room); + } + if (legacyRoom != null) { + fieldMapBuilder.put("legacy_room", legacyRoom); + } + fieldValuesMap = fieldMapBuilder.build(); + } + } + } + return fieldValuesMap; + } + + public String getFieldValue(String fieldName) { + return getFieldValuesMap().get(fieldName); + } + + @Override + public String toString() { + return fixedValue != null ? fixedValue : pathTemplate.instantiate(getFieldValuesMap()); + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o != null || getClass() == o.getClass()) { + BlurbName that = ((BlurbName) o); + return Objects.equals(this.user, that.user) + && Objects.equals(this.legacyUser, that.legacyUser) + && Objects.equals(this.blurb, that.blurb) + && Objects.equals(this.room, that.room) + && Objects.equals(this.legacyRoom, that.legacyRoom); + } + return false; + } + + @Override + public int hashCode() { + int h = 1; + h *= 1000003; + h ^= Objects.hashCode(fixedValue); + h *= 1000003; + h ^= Objects.hashCode(user); + h *= 1000003; + h ^= Objects.hashCode(legacyUser); + h *= 1000003; + h ^= Objects.hashCode(blurb); + h *= 1000003; + h ^= Objects.hashCode(room); + h *= 1000003; + h ^= Objects.hashCode(legacyRoom); + return h; + } + + /** Builder for users/{user}/profile/blurbs/legacy/{legacy_user}~{blurb}. */ + public static class Builder { + private String user; + private String legacyUser; + private String blurb; + + protected Builder() {} + + public String getUser() { + return user; + } + + public String getLegacyUser() { + return legacyUser; + } + + public String getBlurb() { + return blurb; + } + + public Builder setUser(String user) { + this.user = user; + return this; + } + + public Builder setLegacyUser(String legacyUser) { + this.legacyUser = legacyUser; + return this; + } + + public Builder setBlurb(String blurb) { + this.blurb = blurb; + return this; + } + + private Builder(BlurbName blurbName) { + Preconditions.checkArgument( + Objects.equals(blurbName.pathTemplate, USER_LEGACY_USER_BLURB), + "toBuilder is only supported when BlurbName has the pattern of users/{user}/profile/blurbs/legacy/{legacy_user}~{blurb}"); + this.user = blurbName.user; + this.legacyUser = blurbName.legacyUser; + this.blurb = blurbName.blurb; + } + + public BlurbName build() { + return new BlurbName(this); + } + } + + /** Builder for users/{user}/profile/blurbs/{blurb}. */ + @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") + public static class UserBlurbBuilder { + private String user; + private String blurb; + + protected UserBlurbBuilder() {} + + public String getUser() { + return user; + } + + public String getBlurb() { + return blurb; + } + + public UserBlurbBuilder setUser(String user) { + this.user = user; + return this; + } + + public UserBlurbBuilder setBlurb(String blurb) { + this.blurb = blurb; + return this; + } + + public BlurbName build() { + return new BlurbName(this); + } + } + + /** Builder for rooms/{room}/blurbs/{blurb}. */ + @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") + public static class RoomBlurbBuilder { + private String room; + private String blurb; + + protected RoomBlurbBuilder() {} + + public String getRoom() { + return room; + } + + public String getBlurb() { + return blurb; + } + + public RoomBlurbBuilder setRoom(String room) { + this.room = room; + return this; + } + + public RoomBlurbBuilder setBlurb(String blurb) { + this.blurb = blurb; + return this; + } + + public BlurbName build() { + return new BlurbName(this); + } + } + + /** Builder for rooms/{room}/blurbs/legacy/{legacy_room}.{blurb}. */ + @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") + public static class RoomLegacyRoomBlurbBuilder { + private String room; + private String legacyRoom; + private String blurb; + + protected RoomLegacyRoomBlurbBuilder() {} + + public String getRoom() { + return room; + } + + public String getLegacyRoom() { + return legacyRoom; + } + + public String getBlurb() { + return blurb; + } + + public RoomLegacyRoomBlurbBuilder setRoom(String room) { + this.room = room; + return this; + } + + public RoomLegacyRoomBlurbBuilder setLegacyRoom(String legacyRoom) { + this.legacyRoom = legacyRoom; + return this; + } + + public RoomLegacyRoomBlurbBuilder setBlurb(String blurb) { + this.blurb = blurb; + return this; + } + + public BlurbName build() { + return new BlurbName(this); + } + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/ComplianceClient.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/ComplianceClient.java new file mode 100644 index 0000000000..266f562e23 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/ComplianceClient.java @@ -0,0 +1,946 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import com.google.api.core.BetaApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.showcase.v1beta1.stub.ComplianceStub; +import com.google.showcase.v1beta1.stub.ComplianceStubSettings; +import java.io.IOException; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * Service Description: This service is used to test that GAPICs implement various REST-related + * features correctly. This mostly means transcoding proto3 requests to REST format correctly for + * various types of HTTP annotations, but it also includes verifying that unknown (numeric) enums + * received by clients can be round-tripped correctly. + * + *

This class provides the ability to make remote calls to the backing service through method + * calls that map to API methods. Sample code to get started: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (ComplianceClient complianceClient = ComplianceClient.create()) {
+ *   RepeatRequest request =
+ *       RepeatRequest.newBuilder()
+ *           .setName("name3373707")
+ *           .setInfo(ComplianceData.newBuilder().build())
+ *           .setServerVerify(true)
+ *           .setIntendedBindingUri("intendedBindingUri780142386")
+ *           .setFInt32(-1143775883)
+ *           .setFInt64(-1143775788)
+ *           .setFDouble(-1239459382)
+ *           .setPInt32(-858673665)
+ *           .setPInt64(-858673570)
+ *           .setPDouble(-991225216)
+ *           .build();
+ *   RepeatResponse response = complianceClient.repeatDataBody(request);
+ * }
+ * }
+ * + *

Note: close() needs to be called on the ComplianceClient object to clean up resources such as + * threads. In the example above, try-with-resources is used, which automatically calls close(). + * + *

The surface of this class includes several types of Java methods for each of the API's + * methods: + * + *

    + *
  1. A "flattened" method. With this type of method, the fields of the request type have been + * converted into function parameters. It may be the case that not all fields are available as + * parameters, and not every API method will have a flattened method entry point. + *
  2. A "request object" method. This type of method only takes one parameter, a request object, + * which must be constructed before the call. Not every API method will have a request object + * method. + *
  3. A "callable" method. This type of method takes no parameters and returns an immutable API + * callable object, which can be used to initiate calls to the service. + *
+ * + *

See the individual methods for example code. + * + *

Many parameters require resource names to be formatted in a particular way. To assist with + * these names, this class includes a format method for each type of name, and additionally a parse + * method to extract the individual identifiers contained within names that are returned. + * + *

This class can be customized by passing in a custom instance of ComplianceSettings to + * create(). For example: + * + *

To customize credentials: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * ComplianceSettings complianceSettings =
+ *     ComplianceSettings.newBuilder()
+ *         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
+ *         .build();
+ * ComplianceClient complianceClient = ComplianceClient.create(complianceSettings);
+ * }
+ * + *

To customize the endpoint: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * ComplianceSettings complianceSettings =
+ *     ComplianceSettings.newBuilder().setEndpoint(myEndpoint).build();
+ * ComplianceClient complianceClient = ComplianceClient.create(complianceSettings);
+ * }
+ * + *

To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over + * the wire: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * ComplianceSettings complianceSettings = ComplianceSettings.newHttpJsonBuilder().build();
+ * ComplianceClient complianceClient = ComplianceClient.create(complianceSettings);
+ * }
+ * + *

Please refer to the GitHub repository's samples for more quickstart code snippets. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class ComplianceClient implements BackgroundResource { + private final ComplianceSettings settings; + private final ComplianceStub stub; + + /** Constructs an instance of ComplianceClient with default settings. */ + public static final ComplianceClient create() throws IOException { + return create(ComplianceSettings.newBuilder().build()); + } + + /** + * Constructs an instance of ComplianceClient, using the given settings. The channels are created + * based on the settings passed in, or defaults for any settings that are not set. + */ + public static final ComplianceClient create(ComplianceSettings settings) throws IOException { + return new ComplianceClient(settings); + } + + /** + * Constructs an instance of ComplianceClient, using the given stub for making calls. This is for + * advanced usage - prefer using create(ComplianceSettings). + */ + public static final ComplianceClient create(ComplianceStub stub) { + return new ComplianceClient(stub); + } + + /** + * Constructs an instance of ComplianceClient, using the given settings. This is protected so that + * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. + */ + protected ComplianceClient(ComplianceSettings settings) throws IOException { + this.settings = settings; + this.stub = ((ComplianceStubSettings) settings.getStubSettings()).createStub(); + } + + protected ComplianceClient(ComplianceStub stub) { + this.settings = null; + this.stub = stub; + } + + public final ComplianceSettings getSettings() { + return settings; + } + + public ComplianceStub getStub() { + return stub; + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This method echoes the ComplianceData request. This method exercises sending the entire request + * object in the REST body. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (ComplianceClient complianceClient = ComplianceClient.create()) {
+   *   RepeatRequest request =
+   *       RepeatRequest.newBuilder()
+   *           .setName("name3373707")
+   *           .setInfo(ComplianceData.newBuilder().build())
+   *           .setServerVerify(true)
+   *           .setIntendedBindingUri("intendedBindingUri780142386")
+   *           .setFInt32(-1143775883)
+   *           .setFInt64(-1143775788)
+   *           .setFDouble(-1239459382)
+   *           .setPInt32(-858673665)
+   *           .setPInt64(-858673570)
+   *           .setPDouble(-991225216)
+   *           .build();
+   *   RepeatResponse response = complianceClient.repeatDataBody(request);
+   * }
+   * }
+ * + * @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 + */ + public final RepeatResponse repeatDataBody(RepeatRequest request) { + return repeatDataBodyCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This method echoes the ComplianceData request. This method exercises sending the entire request + * object in the REST body. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (ComplianceClient complianceClient = ComplianceClient.create()) {
+   *   RepeatRequest request =
+   *       RepeatRequest.newBuilder()
+   *           .setName("name3373707")
+   *           .setInfo(ComplianceData.newBuilder().build())
+   *           .setServerVerify(true)
+   *           .setIntendedBindingUri("intendedBindingUri780142386")
+   *           .setFInt32(-1143775883)
+   *           .setFInt64(-1143775788)
+   *           .setFDouble(-1239459382)
+   *           .setPInt32(-858673665)
+   *           .setPInt64(-858673570)
+   *           .setPDouble(-991225216)
+   *           .build();
+   *   ApiFuture future =
+   *       complianceClient.repeatDataBodyCallable().futureCall(request);
+   *   // Do something.
+   *   RepeatResponse response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable repeatDataBodyCallable() { + return stub.repeatDataBodyCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This method echoes the ComplianceData request. This method exercises sending the a message-type + * field in the REST body. Per AIP-127, only top-level, non-repeated fields can be sent this way. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (ComplianceClient complianceClient = ComplianceClient.create()) {
+   *   RepeatRequest request =
+   *       RepeatRequest.newBuilder()
+   *           .setName("name3373707")
+   *           .setInfo(ComplianceData.newBuilder().build())
+   *           .setServerVerify(true)
+   *           .setIntendedBindingUri("intendedBindingUri780142386")
+   *           .setFInt32(-1143775883)
+   *           .setFInt64(-1143775788)
+   *           .setFDouble(-1239459382)
+   *           .setPInt32(-858673665)
+   *           .setPInt64(-858673570)
+   *           .setPDouble(-991225216)
+   *           .build();
+   *   RepeatResponse response = complianceClient.repeatDataBodyInfo(request);
+   * }
+   * }
+ * + * @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 + */ + public final RepeatResponse repeatDataBodyInfo(RepeatRequest request) { + return repeatDataBodyInfoCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This method echoes the ComplianceData request. This method exercises sending the a message-type + * field in the REST body. Per AIP-127, only top-level, non-repeated fields can be sent this way. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (ComplianceClient complianceClient = ComplianceClient.create()) {
+   *   RepeatRequest request =
+   *       RepeatRequest.newBuilder()
+   *           .setName("name3373707")
+   *           .setInfo(ComplianceData.newBuilder().build())
+   *           .setServerVerify(true)
+   *           .setIntendedBindingUri("intendedBindingUri780142386")
+   *           .setFInt32(-1143775883)
+   *           .setFInt64(-1143775788)
+   *           .setFDouble(-1239459382)
+   *           .setPInt32(-858673665)
+   *           .setPInt64(-858673570)
+   *           .setPDouble(-991225216)
+   *           .build();
+   *   ApiFuture future =
+   *       complianceClient.repeatDataBodyInfoCallable().futureCall(request);
+   *   // Do something.
+   *   RepeatResponse response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable repeatDataBodyInfoCallable() { + return stub.repeatDataBodyInfoCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This method echoes the ComplianceData request. This method exercises sending all request fields + * as query parameters. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (ComplianceClient complianceClient = ComplianceClient.create()) {
+   *   RepeatRequest request =
+   *       RepeatRequest.newBuilder()
+   *           .setName("name3373707")
+   *           .setInfo(ComplianceData.newBuilder().build())
+   *           .setServerVerify(true)
+   *           .setIntendedBindingUri("intendedBindingUri780142386")
+   *           .setFInt32(-1143775883)
+   *           .setFInt64(-1143775788)
+   *           .setFDouble(-1239459382)
+   *           .setPInt32(-858673665)
+   *           .setPInt64(-858673570)
+   *           .setPDouble(-991225216)
+   *           .build();
+   *   RepeatResponse response = complianceClient.repeatDataQuery(request);
+   * }
+   * }
+ * + * @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 + */ + public final RepeatResponse repeatDataQuery(RepeatRequest request) { + return repeatDataQueryCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This method echoes the ComplianceData request. This method exercises sending all request fields + * as query parameters. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (ComplianceClient complianceClient = ComplianceClient.create()) {
+   *   RepeatRequest request =
+   *       RepeatRequest.newBuilder()
+   *           .setName("name3373707")
+   *           .setInfo(ComplianceData.newBuilder().build())
+   *           .setServerVerify(true)
+   *           .setIntendedBindingUri("intendedBindingUri780142386")
+   *           .setFInt32(-1143775883)
+   *           .setFInt64(-1143775788)
+   *           .setFDouble(-1239459382)
+   *           .setPInt32(-858673665)
+   *           .setPInt64(-858673570)
+   *           .setPDouble(-991225216)
+   *           .build();
+   *   ApiFuture future =
+   *       complianceClient.repeatDataQueryCallable().futureCall(request);
+   *   // Do something.
+   *   RepeatResponse response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable repeatDataQueryCallable() { + return stub.repeatDataQueryCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This method echoes the ComplianceData request. This method exercises sending some parameters as + * "simple" path variables (i.e., of the form "/bar/{foo}" rather than "/{foo=bar/*}"), and + * the rest as query parameters. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (ComplianceClient complianceClient = ComplianceClient.create()) {
+   *   RepeatRequest request =
+   *       RepeatRequest.newBuilder()
+   *           .setName("name3373707")
+   *           .setInfo(ComplianceData.newBuilder().build())
+   *           .setServerVerify(true)
+   *           .setIntendedBindingUri("intendedBindingUri780142386")
+   *           .setFInt32(-1143775883)
+   *           .setFInt64(-1143775788)
+   *           .setFDouble(-1239459382)
+   *           .setPInt32(-858673665)
+   *           .setPInt64(-858673570)
+   *           .setPDouble(-991225216)
+   *           .build();
+   *   RepeatResponse response = complianceClient.repeatDataSimplePath(request);
+   * }
+   * }
+ * + * @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 + */ + public final RepeatResponse repeatDataSimplePath(RepeatRequest request) { + return repeatDataSimplePathCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This method echoes the ComplianceData request. This method exercises sending some parameters as + * "simple" path variables (i.e., of the form "/bar/{foo}" rather than "/{foo=bar/*}"), and + * the rest as query parameters. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (ComplianceClient complianceClient = ComplianceClient.create()) {
+   *   RepeatRequest request =
+   *       RepeatRequest.newBuilder()
+   *           .setName("name3373707")
+   *           .setInfo(ComplianceData.newBuilder().build())
+   *           .setServerVerify(true)
+   *           .setIntendedBindingUri("intendedBindingUri780142386")
+   *           .setFInt32(-1143775883)
+   *           .setFInt64(-1143775788)
+   *           .setFDouble(-1239459382)
+   *           .setPInt32(-858673665)
+   *           .setPInt64(-858673570)
+   *           .setPDouble(-991225216)
+   *           .build();
+   *   ApiFuture future =
+   *       complianceClient.repeatDataSimplePathCallable().futureCall(request);
+   *   // Do something.
+   *   RepeatResponse response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable repeatDataSimplePathCallable() { + return stub.repeatDataSimplePathCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Same as RepeatDataSimplePath, but with a path resource. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (ComplianceClient complianceClient = ComplianceClient.create()) {
+   *   RepeatRequest request =
+   *       RepeatRequest.newBuilder()
+   *           .setName("name3373707")
+   *           .setInfo(ComplianceData.newBuilder().build())
+   *           .setServerVerify(true)
+   *           .setIntendedBindingUri("intendedBindingUri780142386")
+   *           .setFInt32(-1143775883)
+   *           .setFInt64(-1143775788)
+   *           .setFDouble(-1239459382)
+   *           .setPInt32(-858673665)
+   *           .setPInt64(-858673570)
+   *           .setPDouble(-991225216)
+   *           .build();
+   *   RepeatResponse response = complianceClient.repeatDataPathResource(request);
+   * }
+   * }
+ * + * @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 + */ + public final RepeatResponse repeatDataPathResource(RepeatRequest request) { + return repeatDataPathResourceCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Same as RepeatDataSimplePath, but with a path resource. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (ComplianceClient complianceClient = ComplianceClient.create()) {
+   *   RepeatRequest request =
+   *       RepeatRequest.newBuilder()
+   *           .setName("name3373707")
+   *           .setInfo(ComplianceData.newBuilder().build())
+   *           .setServerVerify(true)
+   *           .setIntendedBindingUri("intendedBindingUri780142386")
+   *           .setFInt32(-1143775883)
+   *           .setFInt64(-1143775788)
+   *           .setFDouble(-1239459382)
+   *           .setPInt32(-858673665)
+   *           .setPInt64(-858673570)
+   *           .setPDouble(-991225216)
+   *           .build();
+   *   ApiFuture future =
+   *       complianceClient.repeatDataPathResourceCallable().futureCall(request);
+   *   // Do something.
+   *   RepeatResponse response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable repeatDataPathResourceCallable() { + return stub.repeatDataPathResourceCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Same as RepeatDataSimplePath, but with a trailing resource. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (ComplianceClient complianceClient = ComplianceClient.create()) {
+   *   RepeatRequest request =
+   *       RepeatRequest.newBuilder()
+   *           .setName("name3373707")
+   *           .setInfo(ComplianceData.newBuilder().build())
+   *           .setServerVerify(true)
+   *           .setIntendedBindingUri("intendedBindingUri780142386")
+   *           .setFInt32(-1143775883)
+   *           .setFInt64(-1143775788)
+   *           .setFDouble(-1239459382)
+   *           .setPInt32(-858673665)
+   *           .setPInt64(-858673570)
+   *           .setPDouble(-991225216)
+   *           .build();
+   *   RepeatResponse response = complianceClient.repeatDataPathTrailingResource(request);
+   * }
+   * }
+ * + * @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 + */ + public final RepeatResponse repeatDataPathTrailingResource(RepeatRequest request) { + return repeatDataPathTrailingResourceCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Same as RepeatDataSimplePath, but with a trailing resource. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (ComplianceClient complianceClient = ComplianceClient.create()) {
+   *   RepeatRequest request =
+   *       RepeatRequest.newBuilder()
+   *           .setName("name3373707")
+   *           .setInfo(ComplianceData.newBuilder().build())
+   *           .setServerVerify(true)
+   *           .setIntendedBindingUri("intendedBindingUri780142386")
+   *           .setFInt32(-1143775883)
+   *           .setFInt64(-1143775788)
+   *           .setFDouble(-1239459382)
+   *           .setPInt32(-858673665)
+   *           .setPInt64(-858673570)
+   *           .setPDouble(-991225216)
+   *           .build();
+   *   ApiFuture future =
+   *       complianceClient.repeatDataPathTrailingResourceCallable().futureCall(request);
+   *   // Do something.
+   *   RepeatResponse response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable + repeatDataPathTrailingResourceCallable() { + return stub.repeatDataPathTrailingResourceCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This method echoes the ComplianceData request, using the HTTP PUT method. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (ComplianceClient complianceClient = ComplianceClient.create()) {
+   *   RepeatRequest request =
+   *       RepeatRequest.newBuilder()
+   *           .setName("name3373707")
+   *           .setInfo(ComplianceData.newBuilder().build())
+   *           .setServerVerify(true)
+   *           .setIntendedBindingUri("intendedBindingUri780142386")
+   *           .setFInt32(-1143775883)
+   *           .setFInt64(-1143775788)
+   *           .setFDouble(-1239459382)
+   *           .setPInt32(-858673665)
+   *           .setPInt64(-858673570)
+   *           .setPDouble(-991225216)
+   *           .build();
+   *   RepeatResponse response = complianceClient.repeatDataBodyPut(request);
+   * }
+   * }
+ * + * @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 + */ + public final RepeatResponse repeatDataBodyPut(RepeatRequest request) { + return repeatDataBodyPutCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This method echoes the ComplianceData request, using the HTTP PUT method. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (ComplianceClient complianceClient = ComplianceClient.create()) {
+   *   RepeatRequest request =
+   *       RepeatRequest.newBuilder()
+   *           .setName("name3373707")
+   *           .setInfo(ComplianceData.newBuilder().build())
+   *           .setServerVerify(true)
+   *           .setIntendedBindingUri("intendedBindingUri780142386")
+   *           .setFInt32(-1143775883)
+   *           .setFInt64(-1143775788)
+   *           .setFDouble(-1239459382)
+   *           .setPInt32(-858673665)
+   *           .setPInt64(-858673570)
+   *           .setPDouble(-991225216)
+   *           .build();
+   *   ApiFuture future =
+   *       complianceClient.repeatDataBodyPutCallable().futureCall(request);
+   *   // Do something.
+   *   RepeatResponse response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable repeatDataBodyPutCallable() { + return stub.repeatDataBodyPutCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This method echoes the ComplianceData request, using the HTTP PATCH method. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (ComplianceClient complianceClient = ComplianceClient.create()) {
+   *   RepeatRequest request =
+   *       RepeatRequest.newBuilder()
+   *           .setName("name3373707")
+   *           .setInfo(ComplianceData.newBuilder().build())
+   *           .setServerVerify(true)
+   *           .setIntendedBindingUri("intendedBindingUri780142386")
+   *           .setFInt32(-1143775883)
+   *           .setFInt64(-1143775788)
+   *           .setFDouble(-1239459382)
+   *           .setPInt32(-858673665)
+   *           .setPInt64(-858673570)
+   *           .setPDouble(-991225216)
+   *           .build();
+   *   RepeatResponse response = complianceClient.repeatDataBodyPatch(request);
+   * }
+   * }
+ * + * @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 + */ + public final RepeatResponse repeatDataBodyPatch(RepeatRequest request) { + return repeatDataBodyPatchCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This method echoes the ComplianceData request, using the HTTP PATCH method. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (ComplianceClient complianceClient = ComplianceClient.create()) {
+   *   RepeatRequest request =
+   *       RepeatRequest.newBuilder()
+   *           .setName("name3373707")
+   *           .setInfo(ComplianceData.newBuilder().build())
+   *           .setServerVerify(true)
+   *           .setIntendedBindingUri("intendedBindingUri780142386")
+   *           .setFInt32(-1143775883)
+   *           .setFInt64(-1143775788)
+   *           .setFDouble(-1239459382)
+   *           .setPInt32(-858673665)
+   *           .setPInt64(-858673570)
+   *           .setPDouble(-991225216)
+   *           .build();
+   *   ApiFuture future =
+   *       complianceClient.repeatDataBodyPatchCallable().futureCall(request);
+   *   // Do something.
+   *   RepeatResponse response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable repeatDataBodyPatchCallable() { + return stub.repeatDataBodyPatchCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This method requests an enum value from the server. Depending on the contents of EnumRequest, + * the enum value returned will be a known enum declared in the .proto file, or a made-up enum + * value the is unknown to the client. To verify that clients can round-trip unknown enum vaues + * they receive, use the response from this RPC as the request to VerifyEnum() + * + *

The values of enums sent by the server when a known or unknown value is requested will be + * the same within a single Showcase server run (this is needed for VerifyEnum() to work) but are + * not guaranteed to be the same across separate Showcase server runs. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (ComplianceClient complianceClient = ComplianceClient.create()) {
+   *   EnumRequest request = EnumRequest.newBuilder().setUnknownEnum(true).build();
+   *   EnumResponse response = complianceClient.getEnum(request);
+   * }
+   * }
+ * + * @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 + */ + public final EnumResponse getEnum(EnumRequest request) { + return getEnumCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This method requests an enum value from the server. Depending on the contents of EnumRequest, + * the enum value returned will be a known enum declared in the .proto file, or a made-up enum + * value the is unknown to the client. To verify that clients can round-trip unknown enum vaues + * they receive, use the response from this RPC as the request to VerifyEnum() + * + *

The values of enums sent by the server when a known or unknown value is requested will be + * the same within a single Showcase server run (this is needed for VerifyEnum() to work) but are + * not guaranteed to be the same across separate Showcase server runs. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (ComplianceClient complianceClient = ComplianceClient.create()) {
+   *   EnumRequest request = EnumRequest.newBuilder().setUnknownEnum(true).build();
+   *   ApiFuture future = complianceClient.getEnumCallable().futureCall(request);
+   *   // Do something.
+   *   EnumResponse response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable getEnumCallable() { + return stub.getEnumCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This method is used to verify that clients can round-trip enum values, which is particularly + * important for unknown enum values over REST. VerifyEnum() verifies that its request, which is + * presumably the response that the client previously got to a GetEnum(), contains the correct + * data. If so, it responds with the same EnumResponse; otherwise, the RPC errors. + * + *

This works because the values of enums sent by the server when a known or unknown value is + * requested will be the same within a single Showcase server run, although they are not + * guaranteed to be the same across separate Showcase server runs. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (ComplianceClient complianceClient = ComplianceClient.create()) {
+   *   EnumResponse request =
+   *       EnumResponse.newBuilder()
+   *           .setRequest(EnumRequest.newBuilder().build())
+   *           .setContinent(Continent.forNumber(0))
+   *           .build();
+   *   EnumResponse response = complianceClient.verifyEnum(request);
+   * }
+   * }
+ * + * @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 + */ + public final EnumResponse verifyEnum(EnumResponse request) { + return verifyEnumCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This method is used to verify that clients can round-trip enum values, which is particularly + * important for unknown enum values over REST. VerifyEnum() verifies that its request, which is + * presumably the response that the client previously got to a GetEnum(), contains the correct + * data. If so, it responds with the same EnumResponse; otherwise, the RPC errors. + * + *

This works because the values of enums sent by the server when a known or unknown value is + * requested will be the same within a single Showcase server run, although they are not + * guaranteed to be the same across separate Showcase server runs. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (ComplianceClient complianceClient = ComplianceClient.create()) {
+   *   EnumResponse request =
+   *       EnumResponse.newBuilder()
+   *           .setRequest(EnumRequest.newBuilder().build())
+   *           .setContinent(Continent.forNumber(0))
+   *           .build();
+   *   ApiFuture future = complianceClient.verifyEnumCallable().futureCall(request);
+   *   // Do something.
+   *   EnumResponse response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable verifyEnumCallable() { + return stub.verifyEnumCallable(); + } + + @Override + public final void close() { + stub.close(); + } + + @Override + public void shutdown() { + stub.shutdown(); + } + + @Override + public boolean isShutdown() { + return stub.isShutdown(); + } + + @Override + public boolean isTerminated() { + return stub.isTerminated(); + } + + @Override + public void shutdownNow() { + stub.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return stub.awaitTermination(duration, unit); + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/ComplianceClientHttpJsonTest.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/ComplianceClientHttpJsonTest.java new file mode 100644 index 0000000000..e2498246af --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/ComplianceClientHttpJsonTest.java @@ -0,0 +1,917 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.testing.MockHttpService; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ApiException; +import com.google.api.gax.rpc.ApiExceptionFactory; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.testing.FakeStatusCode; +import com.google.protobuf.ByteString; +import com.google.showcase.v1beta1.stub.HttpJsonComplianceStub; +import java.io.IOException; +import java.util.List; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class ComplianceClientHttpJsonTest { + private static MockHttpService mockService; + private static ComplianceClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonComplianceStub.getMethodDescriptors(), ComplianceSettings.getDefaultEndpoint()); + ComplianceSettings settings = + ComplianceSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + ComplianceSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = ComplianceClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void repeatDataBodyTest() throws Exception { + RepeatResponse expectedResponse = + RepeatResponse.newBuilder() + .setRequest(RepeatRequest.newBuilder().build()) + .setBindingUri("bindingUri1514820775") + .build(); + mockService.addResponse(expectedResponse); + + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + + RepeatResponse actualResponse = client.repeatDataBody(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void repeatDataBodyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + client.repeatDataBody(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void repeatDataBodyInfoTest() throws Exception { + RepeatResponse expectedResponse = + RepeatResponse.newBuilder() + .setRequest(RepeatRequest.newBuilder().build()) + .setBindingUri("bindingUri1514820775") + .build(); + mockService.addResponse(expectedResponse); + + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + + RepeatResponse actualResponse = client.repeatDataBodyInfo(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void repeatDataBodyInfoExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + client.repeatDataBodyInfo(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void repeatDataQueryTest() throws Exception { + RepeatResponse expectedResponse = + RepeatResponse.newBuilder() + .setRequest(RepeatRequest.newBuilder().build()) + .setBindingUri("bindingUri1514820775") + .build(); + mockService.addResponse(expectedResponse); + + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + + RepeatResponse actualResponse = client.repeatDataQuery(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void repeatDataQueryExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + client.repeatDataQuery(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void repeatDataSimplePathTest() throws Exception { + RepeatResponse expectedResponse = + RepeatResponse.newBuilder() + .setRequest(RepeatRequest.newBuilder().build()) + .setBindingUri("bindingUri1514820775") + .build(); + mockService.addResponse(expectedResponse); + + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo( + ComplianceData.newBuilder() + .setFString("fString-9139") + .setFInt32(-1143775883) + .setFSint32(-815756300) + .setFSfixed32(-763212615) + .setFUint32(-758497998) + .setFFixed32(1837548026) + .setFInt64(-1143775788) + .setFSint64(-815756205) + .setFSfixed64(-763212520) + .setFUint64(-758497903) + .setFFixed64(1837548121) + .setFDouble(-1239459382) + .setFFloat(-1146609341) + .setFBool(true) + .setFBytes(ByteString.EMPTY) + .setFChild(ComplianceDataChild.newBuilder().build()) + .setPString("pString-1191954271") + .setPInt32(-858673665) + .setPDouble(-991225216) + .setPBool(true) + .setPChild(ComplianceDataChild.newBuilder().build()) + .build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + + RepeatResponse actualResponse = client.repeatDataSimplePath(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void repeatDataSimplePathExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo( + ComplianceData.newBuilder() + .setFString("fString-9139") + .setFInt32(-1143775883) + .setFSint32(-815756300) + .setFSfixed32(-763212615) + .setFUint32(-758497998) + .setFFixed32(1837548026) + .setFInt64(-1143775788) + .setFSint64(-815756205) + .setFSfixed64(-763212520) + .setFUint64(-758497903) + .setFFixed64(1837548121) + .setFDouble(-1239459382) + .setFFloat(-1146609341) + .setFBool(true) + .setFBytes(ByteString.EMPTY) + .setFChild(ComplianceDataChild.newBuilder().build()) + .setPString("pString-1191954271") + .setPInt32(-858673665) + .setPDouble(-991225216) + .setPBool(true) + .setPChild(ComplianceDataChild.newBuilder().build()) + .build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + client.repeatDataSimplePath(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void repeatDataPathResourceTest() throws Exception { + RepeatResponse expectedResponse = + RepeatResponse.newBuilder() + .setRequest(RepeatRequest.newBuilder().build()) + .setBindingUri("bindingUri1514820775") + .build(); + mockService.addResponse(expectedResponse); + + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo( + ComplianceData.newBuilder() + .setFString("first/firs-9148") + .setFInt32(-1143775883) + .setFSint32(-815756300) + .setFSfixed32(-763212615) + .setFUint32(-758497998) + .setFFixed32(1837548026) + .setFInt64(-1143775788) + .setFSint64(-815756205) + .setFSfixed64(-763212520) + .setFUint64(-758497903) + .setFFixed64(1837548121) + .setFDouble(-1239459382) + .setFFloat(-1146609341) + .setFBool(true) + .setFBytes(ByteString.EMPTY) + .setFChild( + ComplianceDataChild.newBuilder() + .setFString("second/secon-5446") + .setFFloat(-1146609341) + .setFDouble(-1239459382) + .setFBool(true) + .setFContinent(Continent.forNumber(0)) + .setFChild(ComplianceDataGrandchild.newBuilder().build()) + .setPString("pString-1191954271") + .setPFloat(-861507123) + .setPDouble(-991225216) + .setPBool(true) + .setPContinent(Continent.forNumber(0)) + .setPChild(ComplianceDataGrandchild.newBuilder().build()) + .build()) + .setPString("pString-1191954271") + .setPInt32(-858673665) + .setPDouble(-991225216) + .setPBool(true) + .setPChild(ComplianceDataChild.newBuilder().build()) + .build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + + RepeatResponse actualResponse = client.repeatDataPathResource(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void repeatDataPathResourceExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo( + ComplianceData.newBuilder() + .setFString("first/firs-9148") + .setFInt32(-1143775883) + .setFSint32(-815756300) + .setFSfixed32(-763212615) + .setFUint32(-758497998) + .setFFixed32(1837548026) + .setFInt64(-1143775788) + .setFSint64(-815756205) + .setFSfixed64(-763212520) + .setFUint64(-758497903) + .setFFixed64(1837548121) + .setFDouble(-1239459382) + .setFFloat(-1146609341) + .setFBool(true) + .setFBytes(ByteString.EMPTY) + .setFChild( + ComplianceDataChild.newBuilder() + .setFString("second/secon-5446") + .setFFloat(-1146609341) + .setFDouble(-1239459382) + .setFBool(true) + .setFContinent(Continent.forNumber(0)) + .setFChild(ComplianceDataGrandchild.newBuilder().build()) + .setPString("pString-1191954271") + .setPFloat(-861507123) + .setPDouble(-991225216) + .setPBool(true) + .setPContinent(Continent.forNumber(0)) + .setPChild(ComplianceDataGrandchild.newBuilder().build()) + .build()) + .setPString("pString-1191954271") + .setPInt32(-858673665) + .setPDouble(-991225216) + .setPBool(true) + .setPChild(ComplianceDataChild.newBuilder().build()) + .build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + client.repeatDataPathResource(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void repeatDataPathTrailingResourceTest() throws Exception { + RepeatResponse expectedResponse = + RepeatResponse.newBuilder() + .setRequest(RepeatRequest.newBuilder().build()) + .setBindingUri("bindingUri1514820775") + .build(); + mockService.addResponse(expectedResponse); + + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo( + ComplianceData.newBuilder() + .setFString("first/firs-9148") + .setFInt32(-1143775883) + .setFSint32(-815756300) + .setFSfixed32(-763212615) + .setFUint32(-758497998) + .setFFixed32(1837548026) + .setFInt64(-1143775788) + .setFSint64(-815756205) + .setFSfixed64(-763212520) + .setFUint64(-758497903) + .setFFixed64(1837548121) + .setFDouble(-1239459382) + .setFFloat(-1146609341) + .setFBool(true) + .setFBytes(ByteString.EMPTY) + .setFChild( + ComplianceDataChild.newBuilder() + .setFString("second/secon-3276") + .setFFloat(-1146609341) + .setFDouble(-1239459382) + .setFBool(true) + .setFContinent(Continent.forNumber(0)) + .setFChild(ComplianceDataGrandchild.newBuilder().build()) + .setPString("pString-1191954271") + .setPFloat(-861507123) + .setPDouble(-991225216) + .setPBool(true) + .setPContinent(Continent.forNumber(0)) + .setPChild(ComplianceDataGrandchild.newBuilder().build()) + .build()) + .setPString("pString-1191954271") + .setPInt32(-858673665) + .setPDouble(-991225216) + .setPBool(true) + .setPChild(ComplianceDataChild.newBuilder().build()) + .build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + + RepeatResponse actualResponse = client.repeatDataPathTrailingResource(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void repeatDataPathTrailingResourceExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo( + ComplianceData.newBuilder() + .setFString("first/firs-9148") + .setFInt32(-1143775883) + .setFSint32(-815756300) + .setFSfixed32(-763212615) + .setFUint32(-758497998) + .setFFixed32(1837548026) + .setFInt64(-1143775788) + .setFSint64(-815756205) + .setFSfixed64(-763212520) + .setFUint64(-758497903) + .setFFixed64(1837548121) + .setFDouble(-1239459382) + .setFFloat(-1146609341) + .setFBool(true) + .setFBytes(ByteString.EMPTY) + .setFChild( + ComplianceDataChild.newBuilder() + .setFString("second/secon-3276") + .setFFloat(-1146609341) + .setFDouble(-1239459382) + .setFBool(true) + .setFContinent(Continent.forNumber(0)) + .setFChild(ComplianceDataGrandchild.newBuilder().build()) + .setPString("pString-1191954271") + .setPFloat(-861507123) + .setPDouble(-991225216) + .setPBool(true) + .setPContinent(Continent.forNumber(0)) + .setPChild(ComplianceDataGrandchild.newBuilder().build()) + .build()) + .setPString("pString-1191954271") + .setPInt32(-858673665) + .setPDouble(-991225216) + .setPBool(true) + .setPChild(ComplianceDataChild.newBuilder().build()) + .build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + client.repeatDataPathTrailingResource(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void repeatDataBodyPutTest() throws Exception { + RepeatResponse expectedResponse = + RepeatResponse.newBuilder() + .setRequest(RepeatRequest.newBuilder().build()) + .setBindingUri("bindingUri1514820775") + .build(); + mockService.addResponse(expectedResponse); + + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + + RepeatResponse actualResponse = client.repeatDataBodyPut(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void repeatDataBodyPutExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + client.repeatDataBodyPut(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void repeatDataBodyPatchTest() throws Exception { + RepeatResponse expectedResponse = + RepeatResponse.newBuilder() + .setRequest(RepeatRequest.newBuilder().build()) + .setBindingUri("bindingUri1514820775") + .build(); + mockService.addResponse(expectedResponse); + + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + + RepeatResponse actualResponse = client.repeatDataBodyPatch(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void repeatDataBodyPatchExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + client.repeatDataBodyPatch(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getEnumTest() throws Exception { + EnumResponse expectedResponse = + EnumResponse.newBuilder() + .setRequest(EnumRequest.newBuilder().build()) + .setContinent(Continent.forNumber(0)) + .build(); + mockService.addResponse(expectedResponse); + + EnumRequest request = EnumRequest.newBuilder().setUnknownEnum(true).build(); + + EnumResponse actualResponse = client.getEnum(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getEnumExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + EnumRequest request = EnumRequest.newBuilder().setUnknownEnum(true).build(); + client.getEnum(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void verifyEnumTest() throws Exception { + EnumResponse expectedResponse = + EnumResponse.newBuilder() + .setRequest(EnumRequest.newBuilder().build()) + .setContinent(Continent.forNumber(0)) + .build(); + mockService.addResponse(expectedResponse); + + EnumResponse request = + EnumResponse.newBuilder() + .setRequest(EnumRequest.newBuilder().build()) + .setContinent(Continent.forNumber(0)) + .build(); + + EnumResponse actualResponse = client.verifyEnum(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void verifyEnumExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + EnumResponse request = + EnumResponse.newBuilder() + .setRequest(EnumRequest.newBuilder().build()) + .setContinent(Continent.forNumber(0)) + .build(); + client.verifyEnum(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/ComplianceClientTest.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/ComplianceClientTest.java new file mode 100644 index 0000000000..219b1c3712 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/ComplianceClientTest.java @@ -0,0 +1,740 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.grpc.GaxGrpcProperties; +import com.google.api.gax.grpc.testing.LocalChannelProvider; +import com.google.api.gax.grpc.testing.MockGrpcService; +import com.google.api.gax.grpc.testing.MockServiceHelper; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.protobuf.AbstractMessage; +import io.grpc.StatusRuntimeException; +import java.io.IOException; +import java.util.Arrays; +import java.util.List; +import java.util.UUID; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class ComplianceClientTest { + private static MockCompliance mockCompliance; + private static MockServiceHelper mockServiceHelper; + private LocalChannelProvider channelProvider; + private ComplianceClient client; + + @BeforeClass + public static void startStaticServer() { + mockCompliance = new MockCompliance(); + mockServiceHelper = + new MockServiceHelper( + UUID.randomUUID().toString(), Arrays.asList(mockCompliance)); + mockServiceHelper.start(); + } + + @AfterClass + public static void stopServer() { + mockServiceHelper.stop(); + } + + @Before + public void setUp() throws IOException { + mockServiceHelper.reset(); + channelProvider = mockServiceHelper.createChannelProvider(); + ComplianceSettings settings = + ComplianceSettings.newBuilder() + .setTransportChannelProvider(channelProvider) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = ComplianceClient.create(settings); + } + + @After + public void tearDown() throws Exception { + client.close(); + } + + @Test + public void repeatDataBodyTest() throws Exception { + RepeatResponse expectedResponse = + RepeatResponse.newBuilder() + .setRequest(RepeatRequest.newBuilder().build()) + .setBindingUri("bindingUri1514820775") + .build(); + mockCompliance.addResponse(expectedResponse); + + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + + RepeatResponse actualResponse = client.repeatDataBody(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockCompliance.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + RepeatRequest actualRequest = ((RepeatRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getName(), actualRequest.getName()); + Assert.assertEquals(request.getInfo(), actualRequest.getInfo()); + Assert.assertEquals(request.getServerVerify(), actualRequest.getServerVerify()); + Assert.assertEquals(request.getIntendedBindingUri(), actualRequest.getIntendedBindingUri()); + Assert.assertEquals(request.getFInt32(), actualRequest.getFInt32()); + Assert.assertEquals(request.getFInt64(), actualRequest.getFInt64()); + Assert.assertEquals(request.getFDouble(), actualRequest.getFDouble(), 0.0001); + Assert.assertEquals(request.getPInt32(), actualRequest.getPInt32()); + Assert.assertEquals(request.getPInt64(), actualRequest.getPInt64()); + Assert.assertEquals(request.getPDouble(), actualRequest.getPDouble(), 0.0001); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void repeatDataBodyExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockCompliance.addException(exception); + + try { + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + client.repeatDataBody(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void repeatDataBodyInfoTest() throws Exception { + RepeatResponse expectedResponse = + RepeatResponse.newBuilder() + .setRequest(RepeatRequest.newBuilder().build()) + .setBindingUri("bindingUri1514820775") + .build(); + mockCompliance.addResponse(expectedResponse); + + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + + RepeatResponse actualResponse = client.repeatDataBodyInfo(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockCompliance.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + RepeatRequest actualRequest = ((RepeatRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getName(), actualRequest.getName()); + Assert.assertEquals(request.getInfo(), actualRequest.getInfo()); + Assert.assertEquals(request.getServerVerify(), actualRequest.getServerVerify()); + Assert.assertEquals(request.getIntendedBindingUri(), actualRequest.getIntendedBindingUri()); + Assert.assertEquals(request.getFInt32(), actualRequest.getFInt32()); + Assert.assertEquals(request.getFInt64(), actualRequest.getFInt64()); + Assert.assertEquals(request.getFDouble(), actualRequest.getFDouble(), 0.0001); + Assert.assertEquals(request.getPInt32(), actualRequest.getPInt32()); + Assert.assertEquals(request.getPInt64(), actualRequest.getPInt64()); + Assert.assertEquals(request.getPDouble(), actualRequest.getPDouble(), 0.0001); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void repeatDataBodyInfoExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockCompliance.addException(exception); + + try { + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + client.repeatDataBodyInfo(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void repeatDataQueryTest() throws Exception { + RepeatResponse expectedResponse = + RepeatResponse.newBuilder() + .setRequest(RepeatRequest.newBuilder().build()) + .setBindingUri("bindingUri1514820775") + .build(); + mockCompliance.addResponse(expectedResponse); + + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + + RepeatResponse actualResponse = client.repeatDataQuery(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockCompliance.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + RepeatRequest actualRequest = ((RepeatRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getName(), actualRequest.getName()); + Assert.assertEquals(request.getInfo(), actualRequest.getInfo()); + Assert.assertEquals(request.getServerVerify(), actualRequest.getServerVerify()); + Assert.assertEquals(request.getIntendedBindingUri(), actualRequest.getIntendedBindingUri()); + Assert.assertEquals(request.getFInt32(), actualRequest.getFInt32()); + Assert.assertEquals(request.getFInt64(), actualRequest.getFInt64()); + Assert.assertEquals(request.getFDouble(), actualRequest.getFDouble(), 0.0001); + Assert.assertEquals(request.getPInt32(), actualRequest.getPInt32()); + Assert.assertEquals(request.getPInt64(), actualRequest.getPInt64()); + Assert.assertEquals(request.getPDouble(), actualRequest.getPDouble(), 0.0001); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void repeatDataQueryExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockCompliance.addException(exception); + + try { + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + client.repeatDataQuery(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void repeatDataSimplePathTest() throws Exception { + RepeatResponse expectedResponse = + RepeatResponse.newBuilder() + .setRequest(RepeatRequest.newBuilder().build()) + .setBindingUri("bindingUri1514820775") + .build(); + mockCompliance.addResponse(expectedResponse); + + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + + RepeatResponse actualResponse = client.repeatDataSimplePath(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockCompliance.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + RepeatRequest actualRequest = ((RepeatRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getName(), actualRequest.getName()); + Assert.assertEquals(request.getInfo(), actualRequest.getInfo()); + Assert.assertEquals(request.getServerVerify(), actualRequest.getServerVerify()); + Assert.assertEquals(request.getIntendedBindingUri(), actualRequest.getIntendedBindingUri()); + Assert.assertEquals(request.getFInt32(), actualRequest.getFInt32()); + Assert.assertEquals(request.getFInt64(), actualRequest.getFInt64()); + Assert.assertEquals(request.getFDouble(), actualRequest.getFDouble(), 0.0001); + Assert.assertEquals(request.getPInt32(), actualRequest.getPInt32()); + Assert.assertEquals(request.getPInt64(), actualRequest.getPInt64()); + Assert.assertEquals(request.getPDouble(), actualRequest.getPDouble(), 0.0001); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void repeatDataSimplePathExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockCompliance.addException(exception); + + try { + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + client.repeatDataSimplePath(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void repeatDataPathResourceTest() throws Exception { + RepeatResponse expectedResponse = + RepeatResponse.newBuilder() + .setRequest(RepeatRequest.newBuilder().build()) + .setBindingUri("bindingUri1514820775") + .build(); + mockCompliance.addResponse(expectedResponse); + + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + + RepeatResponse actualResponse = client.repeatDataPathResource(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockCompliance.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + RepeatRequest actualRequest = ((RepeatRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getName(), actualRequest.getName()); + Assert.assertEquals(request.getInfo(), actualRequest.getInfo()); + Assert.assertEquals(request.getServerVerify(), actualRequest.getServerVerify()); + Assert.assertEquals(request.getIntendedBindingUri(), actualRequest.getIntendedBindingUri()); + Assert.assertEquals(request.getFInt32(), actualRequest.getFInt32()); + Assert.assertEquals(request.getFInt64(), actualRequest.getFInt64()); + Assert.assertEquals(request.getFDouble(), actualRequest.getFDouble(), 0.0001); + Assert.assertEquals(request.getPInt32(), actualRequest.getPInt32()); + Assert.assertEquals(request.getPInt64(), actualRequest.getPInt64()); + Assert.assertEquals(request.getPDouble(), actualRequest.getPDouble(), 0.0001); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void repeatDataPathResourceExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockCompliance.addException(exception); + + try { + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + client.repeatDataPathResource(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void repeatDataPathTrailingResourceTest() throws Exception { + RepeatResponse expectedResponse = + RepeatResponse.newBuilder() + .setRequest(RepeatRequest.newBuilder().build()) + .setBindingUri("bindingUri1514820775") + .build(); + mockCompliance.addResponse(expectedResponse); + + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + + RepeatResponse actualResponse = client.repeatDataPathTrailingResource(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockCompliance.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + RepeatRequest actualRequest = ((RepeatRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getName(), actualRequest.getName()); + Assert.assertEquals(request.getInfo(), actualRequest.getInfo()); + Assert.assertEquals(request.getServerVerify(), actualRequest.getServerVerify()); + Assert.assertEquals(request.getIntendedBindingUri(), actualRequest.getIntendedBindingUri()); + Assert.assertEquals(request.getFInt32(), actualRequest.getFInt32()); + Assert.assertEquals(request.getFInt64(), actualRequest.getFInt64()); + Assert.assertEquals(request.getFDouble(), actualRequest.getFDouble(), 0.0001); + Assert.assertEquals(request.getPInt32(), actualRequest.getPInt32()); + Assert.assertEquals(request.getPInt64(), actualRequest.getPInt64()); + Assert.assertEquals(request.getPDouble(), actualRequest.getPDouble(), 0.0001); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void repeatDataPathTrailingResourceExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockCompliance.addException(exception); + + try { + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + client.repeatDataPathTrailingResource(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void repeatDataBodyPutTest() throws Exception { + RepeatResponse expectedResponse = + RepeatResponse.newBuilder() + .setRequest(RepeatRequest.newBuilder().build()) + .setBindingUri("bindingUri1514820775") + .build(); + mockCompliance.addResponse(expectedResponse); + + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + + RepeatResponse actualResponse = client.repeatDataBodyPut(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockCompliance.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + RepeatRequest actualRequest = ((RepeatRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getName(), actualRequest.getName()); + Assert.assertEquals(request.getInfo(), actualRequest.getInfo()); + Assert.assertEquals(request.getServerVerify(), actualRequest.getServerVerify()); + Assert.assertEquals(request.getIntendedBindingUri(), actualRequest.getIntendedBindingUri()); + Assert.assertEquals(request.getFInt32(), actualRequest.getFInt32()); + Assert.assertEquals(request.getFInt64(), actualRequest.getFInt64()); + Assert.assertEquals(request.getFDouble(), actualRequest.getFDouble(), 0.0001); + Assert.assertEquals(request.getPInt32(), actualRequest.getPInt32()); + Assert.assertEquals(request.getPInt64(), actualRequest.getPInt64()); + Assert.assertEquals(request.getPDouble(), actualRequest.getPDouble(), 0.0001); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void repeatDataBodyPutExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockCompliance.addException(exception); + + try { + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + client.repeatDataBodyPut(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void repeatDataBodyPatchTest() throws Exception { + RepeatResponse expectedResponse = + RepeatResponse.newBuilder() + .setRequest(RepeatRequest.newBuilder().build()) + .setBindingUri("bindingUri1514820775") + .build(); + mockCompliance.addResponse(expectedResponse); + + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + + RepeatResponse actualResponse = client.repeatDataBodyPatch(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockCompliance.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + RepeatRequest actualRequest = ((RepeatRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getName(), actualRequest.getName()); + Assert.assertEquals(request.getInfo(), actualRequest.getInfo()); + Assert.assertEquals(request.getServerVerify(), actualRequest.getServerVerify()); + Assert.assertEquals(request.getIntendedBindingUri(), actualRequest.getIntendedBindingUri()); + Assert.assertEquals(request.getFInt32(), actualRequest.getFInt32()); + Assert.assertEquals(request.getFInt64(), actualRequest.getFInt64()); + Assert.assertEquals(request.getFDouble(), actualRequest.getFDouble(), 0.0001); + Assert.assertEquals(request.getPInt32(), actualRequest.getPInt32()); + Assert.assertEquals(request.getPInt64(), actualRequest.getPInt64()); + Assert.assertEquals(request.getPDouble(), actualRequest.getPDouble(), 0.0001); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void repeatDataBodyPatchExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockCompliance.addException(exception); + + try { + RepeatRequest request = + RepeatRequest.newBuilder() + .setName("name3373707") + .setInfo(ComplianceData.newBuilder().build()) + .setServerVerify(true) + .setIntendedBindingUri("intendedBindingUri780142386") + .setFInt32(-1143775883) + .setFInt64(-1143775788) + .setFDouble(-1239459382) + .setPInt32(-858673665) + .setPInt64(-858673570) + .setPDouble(-991225216) + .build(); + client.repeatDataBodyPatch(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getEnumTest() throws Exception { + EnumResponse expectedResponse = + EnumResponse.newBuilder() + .setRequest(EnumRequest.newBuilder().build()) + .setContinent(Continent.forNumber(0)) + .build(); + mockCompliance.addResponse(expectedResponse); + + EnumRequest request = EnumRequest.newBuilder().setUnknownEnum(true).build(); + + EnumResponse actualResponse = client.getEnum(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockCompliance.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + EnumRequest actualRequest = ((EnumRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getUnknownEnum(), actualRequest.getUnknownEnum()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void getEnumExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockCompliance.addException(exception); + + try { + EnumRequest request = EnumRequest.newBuilder().setUnknownEnum(true).build(); + client.getEnum(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void verifyEnumTest() throws Exception { + EnumResponse expectedResponse = + EnumResponse.newBuilder() + .setRequest(EnumRequest.newBuilder().build()) + .setContinent(Continent.forNumber(0)) + .build(); + mockCompliance.addResponse(expectedResponse); + + EnumResponse request = + EnumResponse.newBuilder() + .setRequest(EnumRequest.newBuilder().build()) + .setContinent(Continent.forNumber(0)) + .build(); + + EnumResponse actualResponse = client.verifyEnum(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockCompliance.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + EnumResponse actualRequest = ((EnumResponse) actualRequests.get(0)); + + Assert.assertEquals(request.getRequest(), actualRequest.getRequest()); + Assert.assertEquals(request.getContinent(), actualRequest.getContinent()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void verifyEnumExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockCompliance.addException(exception); + + try { + EnumResponse request = + EnumResponse.newBuilder() + .setRequest(EnumRequest.newBuilder().build()) + .setContinent(Continent.forNumber(0)) + .build(); + client.verifyEnum(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/ComplianceSettings.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/ComplianceSettings.java new file mode 100644 index 0000000000..8b562e3999 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/ComplianceSettings.java @@ -0,0 +1,297 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import com.google.api.core.ApiFunction; +import com.google.api.core.BetaApi; +import com.google.api.gax.core.GoogleCredentialsProvider; +import com.google.api.gax.core.InstantiatingExecutorProvider; +import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientSettings; +import com.google.api.gax.rpc.StubSettings; +import com.google.api.gax.rpc.TransportChannelProvider; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.showcase.v1beta1.stub.ComplianceStubSettings; +import java.io.IOException; +import java.util.List; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * Settings class to configure an instance of {@link ComplianceClient}. + * + *

The default instance has everything set to sensible defaults: + * + *

    + *
  • The default service address (localhost) and default port (7469) are used. + *
  • Credentials are acquired automatically through Application Default Credentials. + *
  • Retries are configured for idempotent methods but not for non-idempotent methods. + *
+ * + *

The builder of this class is recursive, so contained classes are themselves builders. When + * build() is called, the tree of builders is called to create the complete settings object. + * + *

For example, to set the total timeout of repeatDataBody to 30 seconds: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * ComplianceSettings.Builder complianceSettingsBuilder = ComplianceSettings.newBuilder();
+ * complianceSettingsBuilder
+ *     .repeatDataBodySettings()
+ *     .setRetrySettings(
+ *         complianceSettingsBuilder
+ *             .repeatDataBodySettings()
+ *             .getRetrySettings()
+ *             .toBuilder()
+ *             .setTotalTimeout(Duration.ofSeconds(30))
+ *             .build());
+ * ComplianceSettings complianceSettings = complianceSettingsBuilder.build();
+ * }
+ */ +@BetaApi +@Generated("by gapic-generator-java") +public class ComplianceSettings extends ClientSettings { + + /** Returns the object with the settings used for calls to repeatDataBody. */ + public UnaryCallSettings repeatDataBodySettings() { + return ((ComplianceStubSettings) getStubSettings()).repeatDataBodySettings(); + } + + /** Returns the object with the settings used for calls to repeatDataBodyInfo. */ + public UnaryCallSettings repeatDataBodyInfoSettings() { + return ((ComplianceStubSettings) getStubSettings()).repeatDataBodyInfoSettings(); + } + + /** Returns the object with the settings used for calls to repeatDataQuery. */ + public UnaryCallSettings repeatDataQuerySettings() { + return ((ComplianceStubSettings) getStubSettings()).repeatDataQuerySettings(); + } + + /** Returns the object with the settings used for calls to repeatDataSimplePath. */ + public UnaryCallSettings repeatDataSimplePathSettings() { + return ((ComplianceStubSettings) getStubSettings()).repeatDataSimplePathSettings(); + } + + /** Returns the object with the settings used for calls to repeatDataPathResource. */ + public UnaryCallSettings repeatDataPathResourceSettings() { + return ((ComplianceStubSettings) getStubSettings()).repeatDataPathResourceSettings(); + } + + /** Returns the object with the settings used for calls to repeatDataPathTrailingResource. */ + public UnaryCallSettings repeatDataPathTrailingResourceSettings() { + return ((ComplianceStubSettings) getStubSettings()).repeatDataPathTrailingResourceSettings(); + } + + /** Returns the object with the settings used for calls to repeatDataBodyPut. */ + public UnaryCallSettings repeatDataBodyPutSettings() { + return ((ComplianceStubSettings) getStubSettings()).repeatDataBodyPutSettings(); + } + + /** Returns the object with the settings used for calls to repeatDataBodyPatch. */ + public UnaryCallSettings repeatDataBodyPatchSettings() { + return ((ComplianceStubSettings) getStubSettings()).repeatDataBodyPatchSettings(); + } + + /** Returns the object with the settings used for calls to getEnum. */ + public UnaryCallSettings getEnumSettings() { + return ((ComplianceStubSettings) getStubSettings()).getEnumSettings(); + } + + /** Returns the object with the settings used for calls to verifyEnum. */ + public UnaryCallSettings verifyEnumSettings() { + return ((ComplianceStubSettings) getStubSettings()).verifyEnumSettings(); + } + + public static final ComplianceSettings create(ComplianceStubSettings stub) throws IOException { + return new ComplianceSettings.Builder(stub.toBuilder()).build(); + } + + /** Returns a builder for the default ExecutorProvider for this service. */ + public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { + return ComplianceStubSettings.defaultExecutorProviderBuilder(); + } + + /** Returns the default service endpoint. */ + public static String getDefaultEndpoint() { + return ComplianceStubSettings.getDefaultEndpoint(); + } + + /** Returns the default service scopes. */ + public static List getDefaultServiceScopes() { + return ComplianceStubSettings.getDefaultServiceScopes(); + } + + /** Returns a builder for the default credentials for this service. */ + public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { + return ComplianceStubSettings.defaultCredentialsProviderBuilder(); + } + + /** Returns a builder for the default gRPC ChannelProvider for this service. */ + public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { + return ComplianceStubSettings.defaultGrpcTransportProviderBuilder(); + } + + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return ComplianceStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + + public static TransportChannelProvider defaultTransportChannelProvider() { + return ComplianceStubSettings.defaultTransportChannelProvider(); + } + + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return ComplianceStubSettings.defaultApiClientHeaderProviderBuilder(); + } + + /** Returns a new gRPC builder for this class. */ + public static Builder newBuilder() { + return Builder.createDefault(); + } + + /** Returns a new REST builder for this class. */ + @BetaApi + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder(ClientContext clientContext) { + return new Builder(clientContext); + } + + /** Returns a builder containing all the values of this settings class. */ + public Builder toBuilder() { + return new Builder(this); + } + + protected ComplianceSettings(Builder settingsBuilder) throws IOException { + super(settingsBuilder); + } + + /** Builder for ComplianceSettings. */ + public static class Builder extends ClientSettings.Builder { + + protected Builder() throws IOException { + this(((ClientContext) null)); + } + + protected Builder(ClientContext clientContext) { + super(ComplianceStubSettings.newBuilder(clientContext)); + } + + protected Builder(ComplianceSettings settings) { + super(settings.getStubSettings().toBuilder()); + } + + protected Builder(ComplianceStubSettings.Builder stubSettings) { + super(stubSettings); + } + + private static Builder createDefault() { + return new Builder(ComplianceStubSettings.newBuilder()); + } + + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(ComplianceStubSettings.newHttpJsonBuilder()); + } + + public ComplianceStubSettings.Builder getStubSettingsBuilder() { + return ((ComplianceStubSettings.Builder) getStubSettings()); + } + + /** + * Applies the given settings updater function to all of the unary API methods in this service. + * + *

Note: This method does not support applying settings to streaming methods. + */ + public Builder applyToAllUnaryMethods( + ApiFunction, Void> settingsUpdater) { + super.applyToAllUnaryMethods( + getStubSettingsBuilder().unaryMethodSettingsBuilders(), settingsUpdater); + return this; + } + + /** Returns the builder for the settings used for calls to repeatDataBody. */ + public UnaryCallSettings.Builder repeatDataBodySettings() { + return getStubSettingsBuilder().repeatDataBodySettings(); + } + + /** Returns the builder for the settings used for calls to repeatDataBodyInfo. */ + public UnaryCallSettings.Builder repeatDataBodyInfoSettings() { + return getStubSettingsBuilder().repeatDataBodyInfoSettings(); + } + + /** Returns the builder for the settings used for calls to repeatDataQuery. */ + public UnaryCallSettings.Builder repeatDataQuerySettings() { + return getStubSettingsBuilder().repeatDataQuerySettings(); + } + + /** Returns the builder for the settings used for calls to repeatDataSimplePath. */ + public UnaryCallSettings.Builder repeatDataSimplePathSettings() { + return getStubSettingsBuilder().repeatDataSimplePathSettings(); + } + + /** Returns the builder for the settings used for calls to repeatDataPathResource. */ + public UnaryCallSettings.Builder + repeatDataPathResourceSettings() { + return getStubSettingsBuilder().repeatDataPathResourceSettings(); + } + + /** Returns the builder for the settings used for calls to repeatDataPathTrailingResource. */ + public UnaryCallSettings.Builder + repeatDataPathTrailingResourceSettings() { + return getStubSettingsBuilder().repeatDataPathTrailingResourceSettings(); + } + + /** Returns the builder for the settings used for calls to repeatDataBodyPut. */ + public UnaryCallSettings.Builder repeatDataBodyPutSettings() { + return getStubSettingsBuilder().repeatDataBodyPutSettings(); + } + + /** Returns the builder for the settings used for calls to repeatDataBodyPatch. */ + public UnaryCallSettings.Builder repeatDataBodyPatchSettings() { + return getStubSettingsBuilder().repeatDataBodyPatchSettings(); + } + + /** Returns the builder for the settings used for calls to getEnum. */ + public UnaryCallSettings.Builder getEnumSettings() { + return getStubSettingsBuilder().getEnumSettings(); + } + + /** Returns the builder for the settings used for calls to verifyEnum. */ + public UnaryCallSettings.Builder verifyEnumSettings() { + return getStubSettingsBuilder().verifyEnumSettings(); + } + + @Override + public ComplianceSettings build() throws IOException { + return new ComplianceSettings(this); + } + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/EchoClient.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/EchoClient.java new file mode 100644 index 0000000000..43d886930d --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/EchoClient.java @@ -0,0 +1,999 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import com.google.api.core.ApiFuture; +import com.google.api.core.ApiFutures; +import com.google.api.core.BetaApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.httpjson.longrunning.OperationsClient; +import com.google.api.gax.longrunning.OperationFuture; +import com.google.api.gax.paging.AbstractFixedSizeCollection; +import com.google.api.gax.paging.AbstractPage; +import com.google.api.gax.paging.AbstractPagedListResponse; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PageContext; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.common.util.concurrent.MoreExecutors; +import com.google.longrunning.Operation; +import com.google.showcase.v1beta1.stub.EchoStub; +import com.google.showcase.v1beta1.stub.EchoStubSettings; +import java.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * Service Description: This service is used showcase the four main types of rpcs - unary, server + * side streaming, client side streaming, and bidirectional streaming. This service also exposes + * methods that explicitly implement server delay, and paginated calls. Set the 'showcase-trailer' + * metadata key on any method to have the values echoed in the response trailers. Set the + * 'x-goog-request-params' metadata key on any method to have the values echoed in the response + * headers. + * + *

This class provides the ability to make remote calls to the backing service through method + * calls that map to API methods. Sample code to get started: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (EchoClient echoClient = EchoClient.create()) {
+ *   EchoRequest request =
+ *       EchoRequest.newBuilder()
+ *           .setSeverity(Severity.forNumber(0))
+ *           .setHeader("header-1221270899")
+ *           .setOtherHeader("otherHeader-2026585667")
+ *           .build();
+ *   EchoResponse response = echoClient.echo(request);
+ * }
+ * }
+ * + *

Note: close() needs to be called on the EchoClient object to clean up resources such as + * threads. In the example above, try-with-resources is used, which automatically calls close(). + * + *

The surface of this class includes several types of Java methods for each of the API's + * methods: + * + *

    + *
  1. A "flattened" method. With this type of method, the fields of the request type have been + * converted into function parameters. It may be the case that not all fields are available as + * parameters, and not every API method will have a flattened method entry point. + *
  2. A "request object" method. This type of method only takes one parameter, a request object, + * which must be constructed before the call. Not every API method will have a request object + * method. + *
  3. A "callable" method. This type of method takes no parameters and returns an immutable API + * callable object, which can be used to initiate calls to the service. + *
+ * + *

See the individual methods for example code. + * + *

Many parameters require resource names to be formatted in a particular way. To assist with + * these names, this class includes a format method for each type of name, and additionally a parse + * method to extract the individual identifiers contained within names that are returned. + * + *

This class can be customized by passing in a custom instance of EchoSettings to create(). For + * example: + * + *

To customize credentials: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * EchoSettings echoSettings =
+ *     EchoSettings.newBuilder()
+ *         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
+ *         .build();
+ * EchoClient echoClient = EchoClient.create(echoSettings);
+ * }
+ * + *

To customize the endpoint: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * EchoSettings echoSettings = EchoSettings.newBuilder().setEndpoint(myEndpoint).build();
+ * EchoClient echoClient = EchoClient.create(echoSettings);
+ * }
+ * + *

To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over + * the wire: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * EchoSettings echoSettings = EchoSettings.newHttpJsonBuilder().build();
+ * EchoClient echoClient = EchoClient.create(echoSettings);
+ * }
+ * + *

Please refer to the GitHub repository's samples for more quickstart code snippets. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class EchoClient implements BackgroundResource { + private final EchoSettings settings; + private final EchoStub stub; + private final OperationsClient httpJsonOperationsClient; + private final com.google.longrunning.OperationsClient operationsClient; + + /** Constructs an instance of EchoClient with default settings. */ + public static final EchoClient create() throws IOException { + return create(EchoSettings.newBuilder().build()); + } + + /** + * Constructs an instance of EchoClient, using the given settings. The channels are created based + * on the settings passed in, or defaults for any settings that are not set. + */ + public static final EchoClient create(EchoSettings settings) throws IOException { + return new EchoClient(settings); + } + + /** + * Constructs an instance of EchoClient, using the given stub for making calls. This is for + * advanced usage - prefer using create(EchoSettings). + */ + public static final EchoClient create(EchoStub stub) { + return new EchoClient(stub); + } + + /** + * Constructs an instance of EchoClient, using the given settings. This is protected so that it is + * easy to make a subclass, but otherwise, the static factory methods should be preferred. + */ + protected EchoClient(EchoSettings settings) throws IOException { + this.settings = settings; + this.stub = ((EchoStubSettings) settings.getStubSettings()).createStub(); + this.operationsClient = + com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); + this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); + } + + protected EchoClient(EchoStub stub) { + this.settings = null; + this.stub = stub; + this.operationsClient = + com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); + this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); + } + + public final EchoSettings getSettings() { + return settings; + } + + public EchoStub getStub() { + return stub; + } + + /** + * Returns the OperationsClient that can be used to query the status of a long-running operation + * returned by another API method call. + */ + public final com.google.longrunning.OperationsClient getOperationsClient() { + return operationsClient; + } + + /** + * Returns the OperationsClient that can be used to query the status of a long-running operation + * returned by another API method call. + */ + @BetaApi + public final OperationsClient getHttpJsonOperationsClient() { + return httpJsonOperationsClient; + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This method simply echoes the request. This method showcases unary RPCs. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (EchoClient echoClient = EchoClient.create()) {
+   *   EchoRequest request =
+   *       EchoRequest.newBuilder()
+   *           .setSeverity(Severity.forNumber(0))
+   *           .setHeader("header-1221270899")
+   *           .setOtherHeader("otherHeader-2026585667")
+   *           .build();
+   *   EchoResponse response = echoClient.echo(request);
+   * }
+   * }
+ * + * @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 + */ + public final EchoResponse echo(EchoRequest request) { + return echoCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This method simply echoes the request. This method showcases unary RPCs. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (EchoClient echoClient = EchoClient.create()) {
+   *   EchoRequest request =
+   *       EchoRequest.newBuilder()
+   *           .setSeverity(Severity.forNumber(0))
+   *           .setHeader("header-1221270899")
+   *           .setOtherHeader("otherHeader-2026585667")
+   *           .build();
+   *   ApiFuture future = echoClient.echoCallable().futureCall(request);
+   *   // Do something.
+   *   EchoResponse response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable echoCallable() { + return stub.echoCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This method splits the given content into words and will pass each word back through the + * stream. This method showcases server-side streaming RPCs. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (EchoClient echoClient = EchoClient.create()) {
+   *   ExpandRequest request =
+   *       ExpandRequest.newBuilder()
+   *           .setContent("content951530617")
+   *           .setError(Status.newBuilder().build())
+   *           .build();
+   *   ServerStream stream = echoClient.expandCallable().call(request);
+   *   for (EchoResponse response : stream) {
+   *     // Do something when a response is received.
+   *   }
+   * }
+   * }
+ */ + public final ServerStreamingCallable expandCallable() { + return stub.expandCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This method will collect the words given to it. When the stream is closed by the client, this + * method will return the a concatenation of the strings passed to it. This method showcases + * client-side streaming RPCs. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (EchoClient echoClient = EchoClient.create()) {
+   *   ApiStreamObserver responseObserver =
+   *       new ApiStreamObserver() {
+   *         {@literal @}Override
+   *         public void onNext(EchoResponse response) {
+   *           // Do something when a response is received.
+   *         }
+   *
+   *         {@literal @}Override
+   *         public void onError(Throwable t) {
+   *           // Add error-handling
+   *         }
+   *
+   *         {@literal @}Override
+   *         public void onCompleted() {
+   *           // Do something when complete.
+   *         }
+   *       };
+   *   ApiStreamObserver requestObserver =
+   *       echoClient.collect().clientStreamingCall(responseObserver);
+   *   EchoRequest request =
+   *       EchoRequest.newBuilder()
+   *           .setSeverity(Severity.forNumber(0))
+   *           .setHeader("header-1221270899")
+   *           .setOtherHeader("otherHeader-2026585667")
+   *           .build();
+   *   requestObserver.onNext(request);
+   * }
+   * }
+ */ + public final ClientStreamingCallable collectCallable() { + return stub.collectCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This method, upon receiving a request on the stream, will pass the same content back on the + * stream. This method showcases bidirectional streaming RPCs. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (EchoClient echoClient = EchoClient.create()) {
+   *   BidiStream bidiStream = echoClient.chatCallable().call();
+   *   EchoRequest request =
+   *       EchoRequest.newBuilder()
+   *           .setSeverity(Severity.forNumber(0))
+   *           .setHeader("header-1221270899")
+   *           .setOtherHeader("otherHeader-2026585667")
+   *           .build();
+   *   bidiStream.send(request);
+   *   for (EchoResponse response : bidiStream) {
+   *     // Do something when a response is received.
+   *   }
+   * }
+   * }
+ */ + public final BidiStreamingCallable chatCallable() { + return stub.chatCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This is similar to the Expand method but instead of returning a stream of expanded words, this + * method returns a paged list of expanded words. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (EchoClient echoClient = EchoClient.create()) {
+   *   PagedExpandRequest request =
+   *       PagedExpandRequest.newBuilder()
+   *           .setContent("content951530617")
+   *           .setPageSize(883849137)
+   *           .setPageToken("pageToken873572522")
+   *           .build();
+   *   for (EchoResponse element : echoClient.pagedExpand(request).iterateAll()) {
+   *     // doThingsWith(element);
+   *   }
+   * }
+   * }
+ * + * @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 + */ + public final PagedExpandPagedResponse pagedExpand(PagedExpandRequest request) { + return pagedExpandPagedCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This is similar to the Expand method but instead of returning a stream of expanded words, this + * method returns a paged list of expanded words. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (EchoClient echoClient = EchoClient.create()) {
+   *   PagedExpandRequest request =
+   *       PagedExpandRequest.newBuilder()
+   *           .setContent("content951530617")
+   *           .setPageSize(883849137)
+   *           .setPageToken("pageToken873572522")
+   *           .build();
+   *   ApiFuture future = echoClient.pagedExpandPagedCallable().futureCall(request);
+   *   // Do something.
+   *   for (EchoResponse element : future.get().iterateAll()) {
+   *     // doThingsWith(element);
+   *   }
+   * }
+   * }
+ */ + public final UnaryCallable + pagedExpandPagedCallable() { + return stub.pagedExpandPagedCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This is similar to the Expand method but instead of returning a stream of expanded words, this + * method returns a paged list of expanded words. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (EchoClient echoClient = EchoClient.create()) {
+   *   PagedExpandRequest request =
+   *       PagedExpandRequest.newBuilder()
+   *           .setContent("content951530617")
+   *           .setPageSize(883849137)
+   *           .setPageToken("pageToken873572522")
+   *           .build();
+   *   while (true) {
+   *     PagedExpandResponse response = echoClient.pagedExpandCallable().call(request);
+   *     for (EchoResponse element : response.getResponsesList()) {
+   *       // doThingsWith(element);
+   *     }
+   *     String nextPageToken = response.getNextPageToken();
+   *     if (!Strings.isNullOrEmpty(nextPageToken)) {
+   *       request = request.toBuilder().setPageToken(nextPageToken).build();
+   *     } else {
+   *       break;
+   *     }
+   *   }
+   * }
+   * }
+ */ + public final UnaryCallable pagedExpandCallable() { + return stub.pagedExpandCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This is similar to the PagedExpand except that it uses max_results instead of page_size, as + * some legacy APIs still do. New APIs should NOT use this pattern. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (EchoClient echoClient = EchoClient.create()) {
+   *   PagedExpandLegacyRequest request =
+   *       PagedExpandLegacyRequest.newBuilder()
+   *           .setContent("content951530617")
+   *           .setMaxResults(1128457243)
+   *           .setPageToken("pageToken873572522")
+   *           .build();
+   *   PagedExpandResponse response = echoClient.pagedExpandLegacy(request);
+   * }
+   * }
+ * + * @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 + */ + public final PagedExpandResponse pagedExpandLegacy(PagedExpandLegacyRequest request) { + return pagedExpandLegacyCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This is similar to the PagedExpand except that it uses max_results instead of page_size, as + * some legacy APIs still do. New APIs should NOT use this pattern. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (EchoClient echoClient = EchoClient.create()) {
+   *   PagedExpandLegacyRequest request =
+   *       PagedExpandLegacyRequest.newBuilder()
+   *           .setContent("content951530617")
+   *           .setMaxResults(1128457243)
+   *           .setPageToken("pageToken873572522")
+   *           .build();
+   *   ApiFuture future =
+   *       echoClient.pagedExpandLegacyCallable().futureCall(request);
+   *   // Do something.
+   *   PagedExpandResponse response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable + pagedExpandLegacyCallable() { + return stub.pagedExpandLegacyCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This method returns a map containing lists of words that appear in the input, keyed by their + * initial character. The only words returned are the ones included in the current page, as + * determined by page_token and page_size, which both refer to the word indices in the input. This + * paging result consisting of a map of lists is a pattern used by some legacy APIs. New APIs + * should NOT use this pattern. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (EchoClient echoClient = EchoClient.create()) {
+   *   PagedExpandRequest request =
+   *       PagedExpandRequest.newBuilder()
+   *           .setContent("content951530617")
+   *           .setPageSize(883849137)
+   *           .setPageToken("pageToken873572522")
+   *           .build();
+   *   for (Map.Entry element :
+   *       echoClient.pagedExpandLegacyMapped(request).iterateAll()) {
+   *     // doThingsWith(element);
+   *   }
+   * }
+   * }
+ * + * @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 + */ + public final PagedExpandLegacyMappedPagedResponse pagedExpandLegacyMapped( + PagedExpandRequest request) { + return pagedExpandLegacyMappedPagedCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This method returns a map containing lists of words that appear in the input, keyed by their + * initial character. The only words returned are the ones included in the current page, as + * determined by page_token and page_size, which both refer to the word indices in the input. This + * paging result consisting of a map of lists is a pattern used by some legacy APIs. New APIs + * should NOT use this pattern. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (EchoClient echoClient = EchoClient.create()) {
+   *   PagedExpandRequest request =
+   *       PagedExpandRequest.newBuilder()
+   *           .setContent("content951530617")
+   *           .setPageSize(883849137)
+   *           .setPageToken("pageToken873572522")
+   *           .build();
+   *   ApiFuture> future =
+   *       echoClient.pagedExpandLegacyMappedPagedCallable().futureCall(request);
+   *   // Do something.
+   *   for (Map.Entry element : future.get().iterateAll()) {
+   *     // doThingsWith(element);
+   *   }
+   * }
+   * }
+ */ + public final UnaryCallable + pagedExpandLegacyMappedPagedCallable() { + return stub.pagedExpandLegacyMappedPagedCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This method returns a map containing lists of words that appear in the input, keyed by their + * initial character. The only words returned are the ones included in the current page, as + * determined by page_token and page_size, which both refer to the word indices in the input. This + * paging result consisting of a map of lists is a pattern used by some legacy APIs. New APIs + * should NOT use this pattern. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (EchoClient echoClient = EchoClient.create()) {
+   *   PagedExpandRequest request =
+   *       PagedExpandRequest.newBuilder()
+   *           .setContent("content951530617")
+   *           .setPageSize(883849137)
+   *           .setPageToken("pageToken873572522")
+   *           .build();
+   *   while (true) {
+   *     PagedExpandLegacyMappedResponse response =
+   *         echoClient.pagedExpandLegacyMappedCallable().call(request);
+   *     for (Map.Entry element : response.getAlphabetizedList()) {
+   *       // doThingsWith(element);
+   *     }
+   *     String nextPageToken = response.getNextPageToken();
+   *     if (!Strings.isNullOrEmpty(nextPageToken)) {
+   *       request = request.toBuilder().setPageToken(nextPageToken).build();
+   *     } else {
+   *       break;
+   *     }
+   *   }
+   * }
+   * }
+ */ + public final UnaryCallable + pagedExpandLegacyMappedCallable() { + return stub.pagedExpandLegacyMappedCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This method will wait for the requested amount of time and then return. This method showcases + * how a client handles a request timeout. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (EchoClient echoClient = EchoClient.create()) {
+   *   WaitRequest request = WaitRequest.newBuilder().build();
+   *   WaitResponse response = echoClient.waitAsync(request).get();
+   * }
+   * }
+ * + * @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 + */ + public final OperationFuture waitAsync(WaitRequest request) { + return waitOperationCallable().futureCall(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This method will wait for the requested amount of time and then return. This method showcases + * how a client handles a request timeout. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (EchoClient echoClient = EchoClient.create()) {
+   *   WaitRequest request = WaitRequest.newBuilder().build();
+   *   OperationFuture future =
+   *       echoClient.waitOperationCallable().futureCall(request);
+   *   // Do something.
+   *   WaitResponse response = future.get();
+   * }
+   * }
+ */ + public final OperationCallable waitOperationCallable() { + return stub.waitOperationCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This method will wait for the requested amount of time and then return. This method showcases + * how a client handles a request timeout. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (EchoClient echoClient = EchoClient.create()) {
+   *   WaitRequest request = WaitRequest.newBuilder().build();
+   *   ApiFuture future = echoClient.waitCallable().futureCall(request);
+   *   // Do something.
+   *   Operation response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable waitCallable() { + return stub.waitCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This method will block (wait) for the requested amount of time and then return the response or + * error. This method showcases how a client handles delays or retries. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (EchoClient echoClient = EchoClient.create()) {
+   *   BlockRequest request =
+   *       BlockRequest.newBuilder().setResponseDelay(Duration.newBuilder().build()).build();
+   *   BlockResponse response = echoClient.block(request);
+   * }
+   * }
+ * + * @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 + */ + public final BlockResponse block(BlockRequest request) { + return blockCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This method will block (wait) for the requested amount of time and then return the response or + * error. This method showcases how a client handles delays or retries. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (EchoClient echoClient = EchoClient.create()) {
+   *   BlockRequest request =
+   *       BlockRequest.newBuilder().setResponseDelay(Duration.newBuilder().build()).build();
+   *   ApiFuture future = echoClient.blockCallable().futureCall(request);
+   *   // Do something.
+   *   BlockResponse response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable blockCallable() { + return stub.blockCallable(); + } + + @Override + public final void close() { + stub.close(); + } + + @Override + public void shutdown() { + stub.shutdown(); + } + + @Override + public boolean isShutdown() { + return stub.isShutdown(); + } + + @Override + public boolean isTerminated() { + return stub.isTerminated(); + } + + @Override + public void shutdownNow() { + stub.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return stub.awaitTermination(duration, unit); + } + + public static class PagedExpandPagedResponse + extends AbstractPagedListResponse< + PagedExpandRequest, + PagedExpandResponse, + EchoResponse, + PagedExpandPage, + PagedExpandFixedSizeCollection> { + + public static ApiFuture createAsync( + PageContext context, + ApiFuture futureResponse) { + ApiFuture futurePage = + PagedExpandPage.createEmptyPage().createPageAsync(context, futureResponse); + return ApiFutures.transform( + futurePage, input -> new PagedExpandPagedResponse(input), MoreExecutors.directExecutor()); + } + + private PagedExpandPagedResponse(PagedExpandPage page) { + super(page, PagedExpandFixedSizeCollection.createEmptyCollection()); + } + } + + public static class PagedExpandPage + extends AbstractPage { + + private PagedExpandPage( + PageContext context, + PagedExpandResponse response) { + super(context, response); + } + + private static PagedExpandPage createEmptyPage() { + return new PagedExpandPage(null, null); + } + + @Override + protected PagedExpandPage createPage( + PageContext context, + PagedExpandResponse response) { + return new PagedExpandPage(context, response); + } + + @Override + public ApiFuture createPageAsync( + PageContext context, + ApiFuture futureResponse) { + return super.createPageAsync(context, futureResponse); + } + } + + public static class PagedExpandFixedSizeCollection + extends AbstractFixedSizeCollection< + PagedExpandRequest, + PagedExpandResponse, + EchoResponse, + PagedExpandPage, + PagedExpandFixedSizeCollection> { + + private PagedExpandFixedSizeCollection(List pages, int collectionSize) { + super(pages, collectionSize); + } + + private static PagedExpandFixedSizeCollection createEmptyCollection() { + return new PagedExpandFixedSizeCollection(null, 0); + } + + @Override + protected PagedExpandFixedSizeCollection createCollection( + List pages, int collectionSize) { + return new PagedExpandFixedSizeCollection(pages, collectionSize); + } + } + + public static class PagedExpandLegacyMappedPagedResponse + extends AbstractPagedListResponse< + PagedExpandRequest, + PagedExpandLegacyMappedResponse, + Map.Entry, + PagedExpandLegacyMappedPage, + PagedExpandLegacyMappedFixedSizeCollection> { + + public static ApiFuture createAsync( + PageContext< + PagedExpandRequest, + PagedExpandLegacyMappedResponse, + Map.Entry> + context, + ApiFuture futureResponse) { + ApiFuture futurePage = + PagedExpandLegacyMappedPage.createEmptyPage().createPageAsync(context, futureResponse); + return ApiFutures.transform( + futurePage, + input -> new PagedExpandLegacyMappedPagedResponse(input), + MoreExecutors.directExecutor()); + } + + private PagedExpandLegacyMappedPagedResponse(PagedExpandLegacyMappedPage page) { + super(page, PagedExpandLegacyMappedFixedSizeCollection.createEmptyCollection()); + } + } + + public static class PagedExpandLegacyMappedPage + extends AbstractPage< + PagedExpandRequest, + PagedExpandLegacyMappedResponse, + Map.Entry, + PagedExpandLegacyMappedPage> { + + private PagedExpandLegacyMappedPage( + PageContext< + PagedExpandRequest, + PagedExpandLegacyMappedResponse, + Map.Entry> + context, + PagedExpandLegacyMappedResponse response) { + super(context, response); + } + + private static PagedExpandLegacyMappedPage createEmptyPage() { + return new PagedExpandLegacyMappedPage(null, null); + } + + @Override + protected PagedExpandLegacyMappedPage createPage( + PageContext< + PagedExpandRequest, + PagedExpandLegacyMappedResponse, + Map.Entry> + context, + PagedExpandLegacyMappedResponse response) { + return new PagedExpandLegacyMappedPage(context, response); + } + + @Override + public ApiFuture createPageAsync( + PageContext< + PagedExpandRequest, + PagedExpandLegacyMappedResponse, + Map.Entry> + context, + ApiFuture futureResponse) { + return super.createPageAsync(context, futureResponse); + } + } + + public static class PagedExpandLegacyMappedFixedSizeCollection + extends AbstractFixedSizeCollection< + PagedExpandRequest, + PagedExpandLegacyMappedResponse, + Map.Entry, + PagedExpandLegacyMappedPage, + PagedExpandLegacyMappedFixedSizeCollection> { + + private PagedExpandLegacyMappedFixedSizeCollection( + List pages, int collectionSize) { + super(pages, collectionSize); + } + + private static PagedExpandLegacyMappedFixedSizeCollection createEmptyCollection() { + return new PagedExpandLegacyMappedFixedSizeCollection(null, 0); + } + + @Override + protected PagedExpandLegacyMappedFixedSizeCollection createCollection( + List pages, int collectionSize) { + return new PagedExpandLegacyMappedFixedSizeCollection(pages, collectionSize); + } + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/EchoClientHttpJsonTest.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/EchoClientHttpJsonTest.java new file mode 100644 index 0000000000..c3084bda5f --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/EchoClientHttpJsonTest.java @@ -0,0 +1,431 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import static com.google.showcase.v1beta1.EchoClient.PagedExpandLegacyMappedPagedResponse; +import static com.google.showcase.v1beta1.EchoClient.PagedExpandPagedResponse; + +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.testing.MockHttpService; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ApiException; +import com.google.api.gax.rpc.ApiExceptionFactory; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.testing.FakeStatusCode; +import com.google.common.collect.Lists; +import com.google.longrunning.Operation; +import com.google.protobuf.Any; +import com.google.protobuf.Duration; +import com.google.showcase.v1beta1.stub.HttpJsonEchoStub; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ExecutionException; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class EchoClientHttpJsonTest { + private static MockHttpService mockService; + private static EchoClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonEchoStub.getMethodDescriptors(), EchoSettings.getDefaultEndpoint()); + EchoSettings settings = + EchoSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + EchoSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = EchoClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void echoTest() throws Exception { + EchoResponse expectedResponse = + EchoResponse.newBuilder() + .setContent("content951530617") + .setSeverity(Severity.forNumber(0)) + .build(); + mockService.addResponse(expectedResponse); + + EchoRequest request = + EchoRequest.newBuilder() + .setSeverity(Severity.forNumber(0)) + .setHeader("header-1221270899") + .setOtherHeader("otherHeader-2026585667") + .build(); + + EchoResponse actualResponse = client.echo(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void echoExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + EchoRequest request = + EchoRequest.newBuilder() + .setSeverity(Severity.forNumber(0)) + .setHeader("header-1221270899") + .setOtherHeader("otherHeader-2026585667") + .build(); + client.echo(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void expandTest() throws Exception {} + + @Test + public void expandExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + } + + @Test + public void collectUnsupportedMethodTest() throws Exception { + // The collect() method is not supported in REST transport. + // This empty test is generated for technical reasons. + } + + @Test + public void chatUnsupportedMethodTest() throws Exception { + // The chat() method is not supported in REST transport. + // This empty test is generated for technical reasons. + } + + @Test + public void pagedExpandTest() throws Exception { + EchoResponse responsesElement = EchoResponse.newBuilder().build(); + PagedExpandResponse expectedResponse = + PagedExpandResponse.newBuilder() + .setNextPageToken("") + .addAllResponses(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + PagedExpandRequest request = + PagedExpandRequest.newBuilder() + .setContent("content951530617") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + + PagedExpandPagedResponse pagedListResponse = client.pagedExpand(request); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getResponsesList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void pagedExpandExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + PagedExpandRequest request = + PagedExpandRequest.newBuilder() + .setContent("content951530617") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + client.pagedExpand(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void pagedExpandLegacyTest() throws Exception { + PagedExpandResponse expectedResponse = + PagedExpandResponse.newBuilder() + .addAllResponses(new ArrayList()) + .setNextPageToken("nextPageToken-1386094857") + .build(); + mockService.addResponse(expectedResponse); + + PagedExpandLegacyRequest request = + PagedExpandLegacyRequest.newBuilder() + .setContent("content951530617") + .setMaxResults(1128457243) + .setPageToken("pageToken873572522") + .build(); + + PagedExpandResponse actualResponse = client.pagedExpandLegacy(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void pagedExpandLegacyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + PagedExpandLegacyRequest request = + PagedExpandLegacyRequest.newBuilder() + .setContent("content951530617") + .setMaxResults(1128457243) + .setPageToken("pageToken873572522") + .build(); + client.pagedExpandLegacy(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void pagedExpandLegacyMappedTest() throws Exception { + PagedExpandResponseList responsesElement = PagedExpandResponseList.newBuilder().build(); + PagedExpandLegacyMappedResponse expectedResponse = + PagedExpandLegacyMappedResponse.newBuilder() + .setNextPageToken("") + .putAllAlphabetized(Collections.singletonMap("alphabetized", responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + PagedExpandRequest request = + PagedExpandRequest.newBuilder() + .setContent("content951530617") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + + PagedExpandLegacyMappedPagedResponse pagedListResponse = + client.pagedExpandLegacyMapped(request); + + List> resources = + Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals( + expectedResponse.getAlphabetizedMap().entrySet().iterator().next(), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void pagedExpandLegacyMappedExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + PagedExpandRequest request = + PagedExpandRequest.newBuilder() + .setContent("content951530617") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + client.pagedExpandLegacyMapped(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void waitTest() throws Exception { + WaitResponse expectedResponse = + WaitResponse.newBuilder().setContent("content951530617").build(); + Operation resultOperation = + Operation.newBuilder() + .setName("waitTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + WaitRequest request = WaitRequest.newBuilder().build(); + + WaitResponse actualResponse = client.waitAsync(request).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void waitExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + WaitRequest request = WaitRequest.newBuilder().build(); + client.waitAsync(request).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void blockTest() throws Exception { + BlockResponse expectedResponse = + BlockResponse.newBuilder().setContent("content951530617").build(); + mockService.addResponse(expectedResponse); + + BlockRequest request = + BlockRequest.newBuilder().setResponseDelay(Duration.newBuilder().build()).build(); + + BlockResponse actualResponse = client.block(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void blockExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + BlockRequest request = + BlockRequest.newBuilder().setResponseDelay(Duration.newBuilder().build()).build(); + client.block(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/EchoClientTest.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/EchoClientTest.java new file mode 100644 index 0000000000..9f6f7f128c --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/EchoClientTest.java @@ -0,0 +1,562 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import static com.google.showcase.v1beta1.EchoClient.PagedExpandLegacyMappedPagedResponse; +import static com.google.showcase.v1beta1.EchoClient.PagedExpandPagedResponse; + +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.grpc.GaxGrpcProperties; +import com.google.api.gax.grpc.testing.LocalChannelProvider; +import com.google.api.gax.grpc.testing.MockGrpcService; +import com.google.api.gax.grpc.testing.MockServiceHelper; +import com.google.api.gax.grpc.testing.MockStreamObserver; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ApiStreamObserver; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StatusCode; +import com.google.common.collect.Lists; +import com.google.longrunning.Operation; +import com.google.protobuf.AbstractMessage; +import com.google.protobuf.Any; +import com.google.protobuf.Duration; +import com.google.rpc.Status; +import io.grpc.StatusRuntimeException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.ExecutionException; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class EchoClientTest { + private static MockEcho mockEcho; + private static MockServiceHelper mockServiceHelper; + private LocalChannelProvider channelProvider; + private EchoClient client; + + @BeforeClass + public static void startStaticServer() { + mockEcho = new MockEcho(); + mockServiceHelper = + new MockServiceHelper( + UUID.randomUUID().toString(), Arrays.asList(mockEcho)); + mockServiceHelper.start(); + } + + @AfterClass + public static void stopServer() { + mockServiceHelper.stop(); + } + + @Before + public void setUp() throws IOException { + mockServiceHelper.reset(); + channelProvider = mockServiceHelper.createChannelProvider(); + EchoSettings settings = + EchoSettings.newBuilder() + .setTransportChannelProvider(channelProvider) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = EchoClient.create(settings); + } + + @After + public void tearDown() throws Exception { + client.close(); + } + + @Test + public void echoTest() throws Exception { + EchoResponse expectedResponse = + EchoResponse.newBuilder() + .setContent("content951530617") + .setSeverity(Severity.forNumber(0)) + .build(); + mockEcho.addResponse(expectedResponse); + + EchoRequest request = + EchoRequest.newBuilder() + .setSeverity(Severity.forNumber(0)) + .setHeader("header-1221270899") + .setOtherHeader("otherHeader-2026585667") + .build(); + + EchoResponse actualResponse = client.echo(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockEcho.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + EchoRequest actualRequest = ((EchoRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getContent(), actualRequest.getContent()); + Assert.assertEquals(request.getError(), actualRequest.getError()); + Assert.assertEquals(request.getSeverity(), actualRequest.getSeverity()); + Assert.assertEquals(request.getHeader(), actualRequest.getHeader()); + Assert.assertEquals(request.getOtherHeader(), actualRequest.getOtherHeader()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void echoExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockEcho.addException(exception); + + try { + EchoRequest request = + EchoRequest.newBuilder() + .setSeverity(Severity.forNumber(0)) + .setHeader("header-1221270899") + .setOtherHeader("otherHeader-2026585667") + .build(); + client.echo(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void expandTest() throws Exception { + EchoResponse expectedResponse = + EchoResponse.newBuilder() + .setContent("content951530617") + .setSeverity(Severity.forNumber(0)) + .build(); + mockEcho.addResponse(expectedResponse); + ExpandRequest request = + ExpandRequest.newBuilder() + .setContent("content951530617") + .setError(Status.newBuilder().build()) + .build(); + + MockStreamObserver responseObserver = new MockStreamObserver<>(); + + ServerStreamingCallable callable = client.expandCallable(); + callable.serverStreamingCall(request, responseObserver); + + List actualResponses = responseObserver.future().get(); + Assert.assertEquals(1, actualResponses.size()); + Assert.assertEquals(expectedResponse, actualResponses.get(0)); + } + + @Test + public void expandExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockEcho.addException(exception); + ExpandRequest request = + ExpandRequest.newBuilder() + .setContent("content951530617") + .setError(Status.newBuilder().build()) + .build(); + + MockStreamObserver responseObserver = new MockStreamObserver<>(); + + ServerStreamingCallable callable = client.expandCallable(); + callable.serverStreamingCall(request, responseObserver); + + try { + List actualResponses = responseObserver.future().get(); + Assert.fail("No exception thrown"); + } catch (ExecutionException e) { + Assert.assertTrue(e.getCause() instanceof InvalidArgumentException); + InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); + Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); + } + } + + @Test + public void collectTest() throws Exception { + EchoResponse expectedResponse = + EchoResponse.newBuilder() + .setContent("content951530617") + .setSeverity(Severity.forNumber(0)) + .build(); + mockEcho.addResponse(expectedResponse); + EchoRequest request = + EchoRequest.newBuilder() + .setSeverity(Severity.forNumber(0)) + .setHeader("header-1221270899") + .setOtherHeader("otherHeader-2026585667") + .build(); + + MockStreamObserver responseObserver = new MockStreamObserver<>(); + + ClientStreamingCallable callable = client.collectCallable(); + ApiStreamObserver requestObserver = callable.clientStreamingCall(responseObserver); + + requestObserver.onNext(request); + requestObserver.onCompleted(); + + List actualResponses = responseObserver.future().get(); + Assert.assertEquals(1, actualResponses.size()); + Assert.assertEquals(expectedResponse, actualResponses.get(0)); + } + + @Test + public void collectExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockEcho.addException(exception); + EchoRequest request = + EchoRequest.newBuilder() + .setSeverity(Severity.forNumber(0)) + .setHeader("header-1221270899") + .setOtherHeader("otherHeader-2026585667") + .build(); + + MockStreamObserver responseObserver = new MockStreamObserver<>(); + + ClientStreamingCallable callable = client.collectCallable(); + ApiStreamObserver requestObserver = callable.clientStreamingCall(responseObserver); + + requestObserver.onNext(request); + + try { + List actualResponses = responseObserver.future().get(); + Assert.fail("No exception thrown"); + } catch (ExecutionException e) { + Assert.assertTrue(e.getCause() instanceof InvalidArgumentException); + InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); + Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); + } + } + + @Test + public void chatTest() throws Exception { + EchoResponse expectedResponse = + EchoResponse.newBuilder() + .setContent("content951530617") + .setSeverity(Severity.forNumber(0)) + .build(); + mockEcho.addResponse(expectedResponse); + EchoRequest request = + EchoRequest.newBuilder() + .setSeverity(Severity.forNumber(0)) + .setHeader("header-1221270899") + .setOtherHeader("otherHeader-2026585667") + .build(); + + MockStreamObserver responseObserver = new MockStreamObserver<>(); + + BidiStreamingCallable callable = client.chatCallable(); + ApiStreamObserver requestObserver = callable.bidiStreamingCall(responseObserver); + + requestObserver.onNext(request); + requestObserver.onCompleted(); + + List actualResponses = responseObserver.future().get(); + Assert.assertEquals(1, actualResponses.size()); + Assert.assertEquals(expectedResponse, actualResponses.get(0)); + } + + @Test + public void chatExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockEcho.addException(exception); + EchoRequest request = + EchoRequest.newBuilder() + .setSeverity(Severity.forNumber(0)) + .setHeader("header-1221270899") + .setOtherHeader("otherHeader-2026585667") + .build(); + + MockStreamObserver responseObserver = new MockStreamObserver<>(); + + BidiStreamingCallable callable = client.chatCallable(); + ApiStreamObserver requestObserver = callable.bidiStreamingCall(responseObserver); + + requestObserver.onNext(request); + + try { + List actualResponses = responseObserver.future().get(); + Assert.fail("No exception thrown"); + } catch (ExecutionException e) { + Assert.assertTrue(e.getCause() instanceof InvalidArgumentException); + InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); + Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); + } + } + + @Test + public void pagedExpandTest() throws Exception { + EchoResponse responsesElement = EchoResponse.newBuilder().build(); + PagedExpandResponse expectedResponse = + PagedExpandResponse.newBuilder() + .setNextPageToken("") + .addAllResponses(Arrays.asList(responsesElement)) + .build(); + mockEcho.addResponse(expectedResponse); + + PagedExpandRequest request = + PagedExpandRequest.newBuilder() + .setContent("content951530617") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + + PagedExpandPagedResponse pagedListResponse = client.pagedExpand(request); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getResponsesList().get(0), resources.get(0)); + + List actualRequests = mockEcho.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + PagedExpandRequest actualRequest = ((PagedExpandRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getContent(), actualRequest.getContent()); + Assert.assertEquals(request.getPageSize(), actualRequest.getPageSize()); + Assert.assertEquals(request.getPageToken(), actualRequest.getPageToken()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void pagedExpandExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockEcho.addException(exception); + + try { + PagedExpandRequest request = + PagedExpandRequest.newBuilder() + .setContent("content951530617") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + client.pagedExpand(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void pagedExpandLegacyTest() throws Exception { + PagedExpandResponse expectedResponse = + PagedExpandResponse.newBuilder() + .addAllResponses(new ArrayList()) + .setNextPageToken("nextPageToken-1386094857") + .build(); + mockEcho.addResponse(expectedResponse); + + PagedExpandLegacyRequest request = + PagedExpandLegacyRequest.newBuilder() + .setContent("content951530617") + .setMaxResults(1128457243) + .setPageToken("pageToken873572522") + .build(); + + PagedExpandResponse actualResponse = client.pagedExpandLegacy(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockEcho.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + PagedExpandLegacyRequest actualRequest = ((PagedExpandLegacyRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getContent(), actualRequest.getContent()); + Assert.assertEquals(request.getMaxResults(), actualRequest.getMaxResults()); + Assert.assertEquals(request.getPageToken(), actualRequest.getPageToken()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void pagedExpandLegacyExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockEcho.addException(exception); + + try { + PagedExpandLegacyRequest request = + PagedExpandLegacyRequest.newBuilder() + .setContent("content951530617") + .setMaxResults(1128457243) + .setPageToken("pageToken873572522") + .build(); + client.pagedExpandLegacy(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void pagedExpandLegacyMappedTest() throws Exception { + PagedExpandResponseList responsesElement = PagedExpandResponseList.newBuilder().build(); + PagedExpandLegacyMappedResponse expectedResponse = + PagedExpandLegacyMappedResponse.newBuilder() + .setNextPageToken("") + .putAllAlphabetized(Collections.singletonMap("alphabetized", responsesElement)) + .build(); + mockEcho.addResponse(expectedResponse); + + PagedExpandRequest request = + PagedExpandRequest.newBuilder() + .setContent("content951530617") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + + PagedExpandLegacyMappedPagedResponse pagedListResponse = + client.pagedExpandLegacyMapped(request); + + List> resources = + Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals( + expectedResponse.getAlphabetizedMap().entrySet().iterator().next(), resources.get(0)); + + List actualRequests = mockEcho.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + PagedExpandRequest actualRequest = ((PagedExpandRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getContent(), actualRequest.getContent()); + Assert.assertEquals(request.getPageSize(), actualRequest.getPageSize()); + Assert.assertEquals(request.getPageToken(), actualRequest.getPageToken()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void pagedExpandLegacyMappedExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockEcho.addException(exception); + + try { + PagedExpandRequest request = + PagedExpandRequest.newBuilder() + .setContent("content951530617") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + client.pagedExpandLegacyMapped(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void waitTest() throws Exception { + WaitResponse expectedResponse = + WaitResponse.newBuilder().setContent("content951530617").build(); + Operation resultOperation = + Operation.newBuilder() + .setName("waitTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockEcho.addResponse(resultOperation); + + WaitRequest request = WaitRequest.newBuilder().build(); + + WaitResponse actualResponse = client.waitAsync(request).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockEcho.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + WaitRequest actualRequest = ((WaitRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getEndTime(), actualRequest.getEndTime()); + Assert.assertEquals(request.getTtl(), actualRequest.getTtl()); + Assert.assertEquals(request.getError(), actualRequest.getError()); + Assert.assertEquals(request.getSuccess(), actualRequest.getSuccess()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void waitExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockEcho.addException(exception); + + try { + WaitRequest request = WaitRequest.newBuilder().build(); + client.waitAsync(request).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); + InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); + Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); + } + } + + @Test + public void blockTest() throws Exception { + BlockResponse expectedResponse = + BlockResponse.newBuilder().setContent("content951530617").build(); + mockEcho.addResponse(expectedResponse); + + BlockRequest request = + BlockRequest.newBuilder().setResponseDelay(Duration.newBuilder().build()).build(); + + BlockResponse actualResponse = client.block(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockEcho.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + BlockRequest actualRequest = ((BlockRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getResponseDelay(), actualRequest.getResponseDelay()); + Assert.assertEquals(request.getError(), actualRequest.getError()); + Assert.assertEquals(request.getSuccess(), actualRequest.getSuccess()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void blockExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockEcho.addException(exception); + + try { + BlockRequest request = + BlockRequest.newBuilder().setResponseDelay(Duration.newBuilder().build()).build(); + client.block(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/EchoSettings.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/EchoSettings.java new file mode 100644 index 0000000000..b8c1785ef0 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/EchoSettings.java @@ -0,0 +1,315 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import static com.google.showcase.v1beta1.EchoClient.PagedExpandLegacyMappedPagedResponse; +import static com.google.showcase.v1beta1.EchoClient.PagedExpandPagedResponse; + +import com.google.api.core.ApiFunction; +import com.google.api.core.BetaApi; +import com.google.api.gax.core.GoogleCredentialsProvider; +import com.google.api.gax.core.InstantiatingExecutorProvider; +import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientSettings; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.StubSettings; +import com.google.api.gax.rpc.TransportChannelProvider; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.longrunning.Operation; +import com.google.showcase.v1beta1.stub.EchoStubSettings; +import java.io.IOException; +import java.util.List; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * Settings class to configure an instance of {@link EchoClient}. + * + *

The default instance has everything set to sensible defaults: + * + *

    + *
  • The default service address (localhost) and default port (7469) are used. + *
  • Credentials are acquired automatically through Application Default Credentials. + *
  • Retries are configured for idempotent methods but not for non-idempotent methods. + *
+ * + *

The builder of this class is recursive, so contained classes are themselves builders. When + * build() is called, the tree of builders is called to create the complete settings object. + * + *

For example, to set the total timeout of echo to 30 seconds: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * EchoSettings.Builder echoSettingsBuilder = EchoSettings.newBuilder();
+ * echoSettingsBuilder
+ *     .echoSettings()
+ *     .setRetrySettings(
+ *         echoSettingsBuilder
+ *             .echoSettings()
+ *             .getRetrySettings()
+ *             .toBuilder()
+ *             .setTotalTimeout(Duration.ofSeconds(30))
+ *             .build());
+ * EchoSettings echoSettings = echoSettingsBuilder.build();
+ * }
+ */ +@BetaApi +@Generated("by gapic-generator-java") +public class EchoSettings extends ClientSettings { + + /** Returns the object with the settings used for calls to echo. */ + public UnaryCallSettings echoSettings() { + return ((EchoStubSettings) getStubSettings()).echoSettings(); + } + + /** Returns the object with the settings used for calls to expand. */ + public ServerStreamingCallSettings expandSettings() { + return ((EchoStubSettings) getStubSettings()).expandSettings(); + } + + /** Returns the object with the settings used for calls to collect. */ + public StreamingCallSettings collectSettings() { + return ((EchoStubSettings) getStubSettings()).collectSettings(); + } + + /** Returns the object with the settings used for calls to chat. */ + public StreamingCallSettings chatSettings() { + return ((EchoStubSettings) getStubSettings()).chatSettings(); + } + + /** Returns the object with the settings used for calls to pagedExpand. */ + public PagedCallSettings + pagedExpandSettings() { + return ((EchoStubSettings) getStubSettings()).pagedExpandSettings(); + } + + /** Returns the object with the settings used for calls to pagedExpandLegacy. */ + public UnaryCallSettings + pagedExpandLegacySettings() { + return ((EchoStubSettings) getStubSettings()).pagedExpandLegacySettings(); + } + + /** Returns the object with the settings used for calls to pagedExpandLegacyMapped. */ + public PagedCallSettings< + PagedExpandRequest, PagedExpandLegacyMappedResponse, PagedExpandLegacyMappedPagedResponse> + pagedExpandLegacyMappedSettings() { + return ((EchoStubSettings) getStubSettings()).pagedExpandLegacyMappedSettings(); + } + + /** Returns the object with the settings used for calls to wait. */ + public UnaryCallSettings waitSettings() { + return ((EchoStubSettings) getStubSettings()).waitSettings(); + } + + /** Returns the object with the settings used for calls to wait. */ + public OperationCallSettings waitOperationSettings() { + return ((EchoStubSettings) getStubSettings()).waitOperationSettings(); + } + + /** Returns the object with the settings used for calls to block. */ + public UnaryCallSettings blockSettings() { + return ((EchoStubSettings) getStubSettings()).blockSettings(); + } + + public static final EchoSettings create(EchoStubSettings stub) throws IOException { + return new EchoSettings.Builder(stub.toBuilder()).build(); + } + + /** Returns a builder for the default ExecutorProvider for this service. */ + public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { + return EchoStubSettings.defaultExecutorProviderBuilder(); + } + + /** Returns the default service endpoint. */ + public static String getDefaultEndpoint() { + return EchoStubSettings.getDefaultEndpoint(); + } + + /** Returns the default service scopes. */ + public static List getDefaultServiceScopes() { + return EchoStubSettings.getDefaultServiceScopes(); + } + + /** Returns a builder for the default credentials for this service. */ + public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { + return EchoStubSettings.defaultCredentialsProviderBuilder(); + } + + /** Returns a builder for the default gRPC ChannelProvider for this service. */ + public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { + return EchoStubSettings.defaultGrpcTransportProviderBuilder(); + } + + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return EchoStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + + public static TransportChannelProvider defaultTransportChannelProvider() { + return EchoStubSettings.defaultTransportChannelProvider(); + } + + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return EchoStubSettings.defaultApiClientHeaderProviderBuilder(); + } + + /** Returns a new gRPC builder for this class. */ + public static Builder newBuilder() { + return Builder.createDefault(); + } + + /** Returns a new REST builder for this class. */ + @BetaApi + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder(ClientContext clientContext) { + return new Builder(clientContext); + } + + /** Returns a builder containing all the values of this settings class. */ + public Builder toBuilder() { + return new Builder(this); + } + + protected EchoSettings(Builder settingsBuilder) throws IOException { + super(settingsBuilder); + } + + /** Builder for EchoSettings. */ + public static class Builder extends ClientSettings.Builder { + + protected Builder() throws IOException { + this(((ClientContext) null)); + } + + protected Builder(ClientContext clientContext) { + super(EchoStubSettings.newBuilder(clientContext)); + } + + protected Builder(EchoSettings settings) { + super(settings.getStubSettings().toBuilder()); + } + + protected Builder(EchoStubSettings.Builder stubSettings) { + super(stubSettings); + } + + private static Builder createDefault() { + return new Builder(EchoStubSettings.newBuilder()); + } + + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(EchoStubSettings.newHttpJsonBuilder()); + } + + public EchoStubSettings.Builder getStubSettingsBuilder() { + return ((EchoStubSettings.Builder) getStubSettings()); + } + + /** + * Applies the given settings updater function to all of the unary API methods in this service. + * + *

Note: This method does not support applying settings to streaming methods. + */ + public Builder applyToAllUnaryMethods( + ApiFunction, Void> settingsUpdater) { + super.applyToAllUnaryMethods( + getStubSettingsBuilder().unaryMethodSettingsBuilders(), settingsUpdater); + return this; + } + + /** Returns the builder for the settings used for calls to echo. */ + public UnaryCallSettings.Builder echoSettings() { + return getStubSettingsBuilder().echoSettings(); + } + + /** Returns the builder for the settings used for calls to expand. */ + public ServerStreamingCallSettings.Builder expandSettings() { + return getStubSettingsBuilder().expandSettings(); + } + + /** Returns the builder for the settings used for calls to collect. */ + public StreamingCallSettings.Builder collectSettings() { + return getStubSettingsBuilder().collectSettings(); + } + + /** Returns the builder for the settings used for calls to chat. */ + public StreamingCallSettings.Builder chatSettings() { + return getStubSettingsBuilder().chatSettings(); + } + + /** Returns the builder for the settings used for calls to pagedExpand. */ + public PagedCallSettings.Builder< + PagedExpandRequest, PagedExpandResponse, PagedExpandPagedResponse> + pagedExpandSettings() { + return getStubSettingsBuilder().pagedExpandSettings(); + } + + /** Returns the builder for the settings used for calls to pagedExpandLegacy. */ + public UnaryCallSettings.Builder + pagedExpandLegacySettings() { + return getStubSettingsBuilder().pagedExpandLegacySettings(); + } + + /** Returns the builder for the settings used for calls to pagedExpandLegacyMapped. */ + public PagedCallSettings.Builder< + PagedExpandRequest, + PagedExpandLegacyMappedResponse, + PagedExpandLegacyMappedPagedResponse> + pagedExpandLegacyMappedSettings() { + return getStubSettingsBuilder().pagedExpandLegacyMappedSettings(); + } + + /** Returns the builder for the settings used for calls to wait. */ + public UnaryCallSettings.Builder waitSettings() { + return getStubSettingsBuilder().waitSettings(); + } + + /** Returns the builder for the settings used for calls to wait. */ + public OperationCallSettings.Builder + waitOperationSettings() { + return getStubSettingsBuilder().waitOperationSettings(); + } + + /** Returns the builder for the settings used for calls to block. */ + public UnaryCallSettings.Builder blockSettings() { + return getStubSettingsBuilder().blockSettings(); + } + + @Override + public EchoSettings build() throws IOException { + return new EchoSettings(this); + } + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/IdentityClient.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/IdentityClient.java new file mode 100644 index 0000000000..b50159d6fc --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/IdentityClient.java @@ -0,0 +1,774 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import com.google.api.core.ApiFuture; +import com.google.api.core.ApiFutures; +import com.google.api.core.BetaApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.paging.AbstractFixedSizeCollection; +import com.google.api.gax.paging.AbstractPage; +import com.google.api.gax.paging.AbstractPagedListResponse; +import com.google.api.gax.rpc.PageContext; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.common.util.concurrent.MoreExecutors; +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.stub.IdentityStub; +import com.google.showcase.v1beta1.stub.IdentityStubSettings; +import java.io.IOException; +import java.util.List; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * Service Description: A simple identity service. + * + *

This class provides the ability to make remote calls to the backing service through method + * calls that map to API methods. Sample code to get started: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (IdentityClient identityClient = IdentityClient.create()) {
+ *   String displayName = "displayName1714148973";
+ *   String email = "email96619420";
+ *   User response = identityClient.createUser(displayName, email);
+ * }
+ * }
+ * + *

Note: close() needs to be called on the IdentityClient object to clean up resources such as + * threads. In the example above, try-with-resources is used, which automatically calls close(). + * + *

The surface of this class includes several types of Java methods for each of the API's + * methods: + * + *

    + *
  1. A "flattened" method. With this type of method, the fields of the request type have been + * converted into function parameters. It may be the case that not all fields are available as + * parameters, and not every API method will have a flattened method entry point. + *
  2. A "request object" method. This type of method only takes one parameter, a request object, + * which must be constructed before the call. Not every API method will have a request object + * method. + *
  3. A "callable" method. This type of method takes no parameters and returns an immutable API + * callable object, which can be used to initiate calls to the service. + *
+ * + *

See the individual methods for example code. + * + *

Many parameters require resource names to be formatted in a particular way. To assist with + * these names, this class includes a format method for each type of name, and additionally a parse + * method to extract the individual identifiers contained within names that are returned. + * + *

This class can be customized by passing in a custom instance of IdentitySettings to create(). + * For example: + * + *

To customize credentials: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * IdentitySettings identitySettings =
+ *     IdentitySettings.newBuilder()
+ *         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
+ *         .build();
+ * IdentityClient identityClient = IdentityClient.create(identitySettings);
+ * }
+ * + *

To customize the endpoint: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * IdentitySettings identitySettings =
+ *     IdentitySettings.newBuilder().setEndpoint(myEndpoint).build();
+ * IdentityClient identityClient = IdentityClient.create(identitySettings);
+ * }
+ * + *

To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over + * the wire: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * IdentitySettings identitySettings = IdentitySettings.newHttpJsonBuilder().build();
+ * IdentityClient identityClient = IdentityClient.create(identitySettings);
+ * }
+ * + *

Please refer to the GitHub repository's samples for more quickstart code snippets. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class IdentityClient implements BackgroundResource { + private final IdentitySettings settings; + private final IdentityStub stub; + + /** Constructs an instance of IdentityClient with default settings. */ + public static final IdentityClient create() throws IOException { + return create(IdentitySettings.newBuilder().build()); + } + + /** + * Constructs an instance of IdentityClient, using the given settings. The channels are created + * based on the settings passed in, or defaults for any settings that are not set. + */ + public static final IdentityClient create(IdentitySettings settings) throws IOException { + return new IdentityClient(settings); + } + + /** + * Constructs an instance of IdentityClient, using the given stub for making calls. This is for + * advanced usage - prefer using create(IdentitySettings). + */ + public static final IdentityClient create(IdentityStub stub) { + return new IdentityClient(stub); + } + + /** + * Constructs an instance of IdentityClient, using the given settings. This is protected so that + * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. + */ + protected IdentityClient(IdentitySettings settings) throws IOException { + this.settings = settings; + this.stub = ((IdentityStubSettings) settings.getStubSettings()).createStub(); + } + + protected IdentityClient(IdentityStub stub) { + this.settings = null; + this.stub = stub; + } + + public final IdentitySettings getSettings() { + return settings; + } + + public IdentityStub getStub() { + return stub; + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates a user. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (IdentityClient identityClient = IdentityClient.create()) {
+   *   String displayName = "displayName1714148973";
+   *   String email = "email96619420";
+   *   User response = identityClient.createUser(displayName, email);
+   * }
+   * }
+ * + * @param displayName The display_name of the user. + * @param email The email address of the user. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final User createUser(String displayName, String email) { + CreateUserRequest request = + CreateUserRequest.newBuilder() + .setUser(User.newBuilder().setDisplayName(displayName).setEmail(email).build()) + .build(); + return createUser(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates a user. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (IdentityClient identityClient = IdentityClient.create()) {
+   *   String displayName = "displayName1714148973";
+   *   String email = "email96619420";
+   *   int age = 96511;
+   *   String nickname = "nickname70690926";
+   *   boolean enableNotifications = true;
+   *   double heightFeet = -1032737338;
+   *   User response =
+   *       identityClient.createUser(
+   *           displayName, email, age, nickname, enableNotifications, heightFeet);
+   * }
+   * }
+ * + * @param displayName The display_name of the user. + * @param email The email address of the user. + * @param age The age of the user in years. + * @param nickname The nickname of the user. + *

(-- aip.dev/not-precedent: An empty string is a valid nickname. Ordinarily, + * proto3_optional should not be used on a `string` field. --) + * @param enableNotifications Enables the receiving of notifications. The default is true if + * unset. + *

(-- aip.dev/not-precedent: The default for the feature is true. Ordinarily, the default + * for a `bool` field should be false. --) + * @param heightFeet The height of the user in feet. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final User createUser( + String displayName, + String email, + int age, + String nickname, + boolean enableNotifications, + double heightFeet) { + CreateUserRequest request = + CreateUserRequest.newBuilder() + .setUser( + User.newBuilder() + .setDisplayName(displayName) + .setEmail(email) + .setAge(age) + .setNickname(nickname) + .setEnableNotifications(enableNotifications) + .setHeightFeet(heightFeet) + .build()) + .build(); + return createUser(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates a user. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (IdentityClient identityClient = IdentityClient.create()) {
+   *   CreateUserRequest request =
+   *       CreateUserRequest.newBuilder().setUser(User.newBuilder().build()).build();
+   *   User response = identityClient.createUser(request);
+   * }
+   * }
+ * + * @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 + */ + public final User createUser(CreateUserRequest request) { + return createUserCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates a user. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (IdentityClient identityClient = IdentityClient.create()) {
+   *   CreateUserRequest request =
+   *       CreateUserRequest.newBuilder().setUser(User.newBuilder().build()).build();
+   *   ApiFuture future = identityClient.createUserCallable().futureCall(request);
+   *   // Do something.
+   *   User response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable createUserCallable() { + return stub.createUserCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Retrieves the User with the given uri. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (IdentityClient identityClient = IdentityClient.create()) {
+   *   UserName name = UserName.of("[USER]");
+   *   User response = identityClient.getUser(name);
+   * }
+   * }
+ * + * @param name The resource name of the requested user. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final User getUser(UserName name) { + GetUserRequest request = + GetUserRequest.newBuilder().setName(name == null ? null : name.toString()).build(); + return getUser(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Retrieves the User with the given uri. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (IdentityClient identityClient = IdentityClient.create()) {
+   *   String name = UserName.of("[USER]").toString();
+   *   User response = identityClient.getUser(name);
+   * }
+   * }
+ * + * @param name The resource name of the requested user. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final User getUser(String name) { + GetUserRequest request = GetUserRequest.newBuilder().setName(name).build(); + return getUser(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Retrieves the User with the given uri. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (IdentityClient identityClient = IdentityClient.create()) {
+   *   GetUserRequest request =
+   *       GetUserRequest.newBuilder().setName(UserName.of("[USER]").toString()).build();
+   *   User response = identityClient.getUser(request);
+   * }
+   * }
+ * + * @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 + */ + public final User getUser(GetUserRequest request) { + return getUserCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Retrieves the User with the given uri. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (IdentityClient identityClient = IdentityClient.create()) {
+   *   GetUserRequest request =
+   *       GetUserRequest.newBuilder().setName(UserName.of("[USER]").toString()).build();
+   *   ApiFuture future = identityClient.getUserCallable().futureCall(request);
+   *   // Do something.
+   *   User response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable getUserCallable() { + return stub.getUserCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Updates a user. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (IdentityClient identityClient = IdentityClient.create()) {
+   *   UpdateUserRequest request =
+   *       UpdateUserRequest.newBuilder()
+   *           .setUser(User.newBuilder().build())
+   *           .setUpdateMask(FieldMask.newBuilder().build())
+   *           .build();
+   *   User response = identityClient.updateUser(request);
+   * }
+   * }
+ * + * @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 + */ + public final User updateUser(UpdateUserRequest request) { + return updateUserCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Updates a user. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (IdentityClient identityClient = IdentityClient.create()) {
+   *   UpdateUserRequest request =
+   *       UpdateUserRequest.newBuilder()
+   *           .setUser(User.newBuilder().build())
+   *           .setUpdateMask(FieldMask.newBuilder().build())
+   *           .build();
+   *   ApiFuture future = identityClient.updateUserCallable().futureCall(request);
+   *   // Do something.
+   *   User response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable updateUserCallable() { + return stub.updateUserCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Deletes a user, their profile, and all of their authored messages. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (IdentityClient identityClient = IdentityClient.create()) {
+   *   UserName name = UserName.of("[USER]");
+   *   identityClient.deleteUser(name);
+   * }
+   * }
+ * + * @param name The resource name of the user to delete. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final void deleteUser(UserName name) { + DeleteUserRequest request = + DeleteUserRequest.newBuilder().setName(name == null ? null : name.toString()).build(); + deleteUser(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Deletes a user, their profile, and all of their authored messages. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (IdentityClient identityClient = IdentityClient.create()) {
+   *   String name = UserName.of("[USER]").toString();
+   *   identityClient.deleteUser(name);
+   * }
+   * }
+ * + * @param name The resource name of the user to delete. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final void deleteUser(String name) { + DeleteUserRequest request = DeleteUserRequest.newBuilder().setName(name).build(); + deleteUser(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Deletes a user, their profile, and all of their authored messages. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (IdentityClient identityClient = IdentityClient.create()) {
+   *   DeleteUserRequest request =
+   *       DeleteUserRequest.newBuilder().setName(UserName.of("[USER]").toString()).build();
+   *   identityClient.deleteUser(request);
+   * }
+   * }
+ * + * @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 + */ + public final void deleteUser(DeleteUserRequest request) { + deleteUserCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Deletes a user, their profile, and all of their authored messages. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (IdentityClient identityClient = IdentityClient.create()) {
+   *   DeleteUserRequest request =
+   *       DeleteUserRequest.newBuilder().setName(UserName.of("[USER]").toString()).build();
+   *   ApiFuture future = identityClient.deleteUserCallable().futureCall(request);
+   *   // Do something.
+   *   future.get();
+   * }
+   * }
+ */ + public final UnaryCallable deleteUserCallable() { + return stub.deleteUserCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Lists all users. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (IdentityClient identityClient = IdentityClient.create()) {
+   *   ListUsersRequest request =
+   *       ListUsersRequest.newBuilder()
+   *           .setPageSize(883849137)
+   *           .setPageToken("pageToken873572522")
+   *           .build();
+   *   for (User element : identityClient.listUsers(request).iterateAll()) {
+   *     // doThingsWith(element);
+   *   }
+   * }
+   * }
+ * + * @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 + */ + public final ListUsersPagedResponse listUsers(ListUsersRequest request) { + return listUsersPagedCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Lists all users. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (IdentityClient identityClient = IdentityClient.create()) {
+   *   ListUsersRequest request =
+   *       ListUsersRequest.newBuilder()
+   *           .setPageSize(883849137)
+   *           .setPageToken("pageToken873572522")
+   *           .build();
+   *   ApiFuture future = identityClient.listUsersPagedCallable().futureCall(request);
+   *   // Do something.
+   *   for (User element : future.get().iterateAll()) {
+   *     // doThingsWith(element);
+   *   }
+   * }
+   * }
+ */ + public final UnaryCallable listUsersPagedCallable() { + return stub.listUsersPagedCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Lists all users. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (IdentityClient identityClient = IdentityClient.create()) {
+   *   ListUsersRequest request =
+   *       ListUsersRequest.newBuilder()
+   *           .setPageSize(883849137)
+   *           .setPageToken("pageToken873572522")
+   *           .build();
+   *   while (true) {
+   *     ListUsersResponse response = identityClient.listUsersCallable().call(request);
+   *     for (User element : response.getUsersList()) {
+   *       // doThingsWith(element);
+   *     }
+   *     String nextPageToken = response.getNextPageToken();
+   *     if (!Strings.isNullOrEmpty(nextPageToken)) {
+   *       request = request.toBuilder().setPageToken(nextPageToken).build();
+   *     } else {
+   *       break;
+   *     }
+   *   }
+   * }
+   * }
+ */ + public final UnaryCallable listUsersCallable() { + return stub.listUsersCallable(); + } + + @Override + public final void close() { + stub.close(); + } + + @Override + public void shutdown() { + stub.shutdown(); + } + + @Override + public boolean isShutdown() { + return stub.isShutdown(); + } + + @Override + public boolean isTerminated() { + return stub.isTerminated(); + } + + @Override + public void shutdownNow() { + stub.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return stub.awaitTermination(duration, unit); + } + + public static class ListUsersPagedResponse + extends AbstractPagedListResponse< + ListUsersRequest, ListUsersResponse, User, ListUsersPage, ListUsersFixedSizeCollection> { + + public static ApiFuture createAsync( + PageContext context, + ApiFuture futureResponse) { + ApiFuture futurePage = + ListUsersPage.createEmptyPage().createPageAsync(context, futureResponse); + return ApiFutures.transform( + futurePage, input -> new ListUsersPagedResponse(input), MoreExecutors.directExecutor()); + } + + private ListUsersPagedResponse(ListUsersPage page) { + super(page, ListUsersFixedSizeCollection.createEmptyCollection()); + } + } + + public static class ListUsersPage + extends AbstractPage { + + private ListUsersPage( + PageContext context, + ListUsersResponse response) { + super(context, response); + } + + private static ListUsersPage createEmptyPage() { + return new ListUsersPage(null, null); + } + + @Override + protected ListUsersPage createPage( + PageContext context, + ListUsersResponse response) { + return new ListUsersPage(context, response); + } + + @Override + public ApiFuture createPageAsync( + PageContext context, + ApiFuture futureResponse) { + return super.createPageAsync(context, futureResponse); + } + } + + public static class ListUsersFixedSizeCollection + extends AbstractFixedSizeCollection< + ListUsersRequest, ListUsersResponse, User, ListUsersPage, ListUsersFixedSizeCollection> { + + private ListUsersFixedSizeCollection(List pages, int collectionSize) { + super(pages, collectionSize); + } + + private static ListUsersFixedSizeCollection createEmptyCollection() { + return new ListUsersFixedSizeCollection(null, 0); + } + + @Override + protected ListUsersFixedSizeCollection createCollection( + List pages, int collectionSize) { + return new ListUsersFixedSizeCollection(pages, collectionSize); + } + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/IdentityClientHttpJsonTest.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/IdentityClientHttpJsonTest.java new file mode 100644 index 0000000000..8928792040 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/IdentityClientHttpJsonTest.java @@ -0,0 +1,520 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import static com.google.showcase.v1beta1.IdentityClient.ListUsersPagedResponse; + +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.testing.MockHttpService; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ApiException; +import com.google.api.gax.rpc.ApiExceptionFactory; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.testing.FakeStatusCode; +import com.google.common.collect.Lists; +import com.google.protobuf.Empty; +import com.google.protobuf.FieldMask; +import com.google.protobuf.Timestamp; +import com.google.showcase.v1beta1.stub.HttpJsonIdentityStub; +import java.io.IOException; +import java.util.Arrays; +import java.util.List; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class IdentityClientHttpJsonTest { + private static MockHttpService mockService; + private static IdentityClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonIdentityStub.getMethodDescriptors(), IdentitySettings.getDefaultEndpoint()); + IdentitySettings settings = + IdentitySettings.newHttpJsonBuilder() + .setTransportChannelProvider( + IdentitySettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = IdentityClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void createUserTest() throws Exception { + User expectedResponse = + User.newBuilder() + .setName(UserName.of("[USER]").toString()) + .setDisplayName("displayName1714148973") + .setEmail("email96619420") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setAge(96511) + .setHeightFeet(-1032737338) + .setNickname("nickname70690926") + .setEnableNotifications(true) + .build(); + mockService.addResponse(expectedResponse); + + String displayName = "displayName1714148973"; + String email = "email96619420"; + + User actualResponse = client.createUser(displayName, email); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createUserExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String displayName = "displayName1714148973"; + String email = "email96619420"; + client.createUser(displayName, email); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createUserTest2() throws Exception { + User expectedResponse = + User.newBuilder() + .setName(UserName.of("[USER]").toString()) + .setDisplayName("displayName1714148973") + .setEmail("email96619420") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setAge(96511) + .setHeightFeet(-1032737338) + .setNickname("nickname70690926") + .setEnableNotifications(true) + .build(); + mockService.addResponse(expectedResponse); + + String displayName = "displayName1714148973"; + String email = "email96619420"; + int age = 96511; + String nickname = "nickname70690926"; + boolean enableNotifications = true; + double heightFeet = -1032737338; + + User actualResponse = + client.createUser(displayName, email, age, nickname, enableNotifications, heightFeet); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createUserExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String displayName = "displayName1714148973"; + String email = "email96619420"; + int age = 96511; + String nickname = "nickname70690926"; + boolean enableNotifications = true; + double heightFeet = -1032737338; + client.createUser(displayName, email, age, nickname, enableNotifications, heightFeet); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getUserTest() throws Exception { + User expectedResponse = + User.newBuilder() + .setName(UserName.of("[USER]").toString()) + .setDisplayName("displayName1714148973") + .setEmail("email96619420") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setAge(96511) + .setHeightFeet(-1032737338) + .setNickname("nickname70690926") + .setEnableNotifications(true) + .build(); + mockService.addResponse(expectedResponse); + + UserName name = UserName.of("[USER]"); + + User actualResponse = client.getUser(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getUserExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + UserName name = UserName.of("[USER]"); + client.getUser(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getUserTest2() throws Exception { + User expectedResponse = + User.newBuilder() + .setName(UserName.of("[USER]").toString()) + .setDisplayName("displayName1714148973") + .setEmail("email96619420") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setAge(96511) + .setHeightFeet(-1032737338) + .setNickname("nickname70690926") + .setEnableNotifications(true) + .build(); + mockService.addResponse(expectedResponse); + + String name = "users/user-6376"; + + User actualResponse = client.getUser(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getUserExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "users/user-6376"; + client.getUser(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateUserTest() throws Exception { + User expectedResponse = + User.newBuilder() + .setName(UserName.of("[USER]").toString()) + .setDisplayName("displayName1714148973") + .setEmail("email96619420") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setAge(96511) + .setHeightFeet(-1032737338) + .setNickname("nickname70690926") + .setEnableNotifications(true) + .build(); + mockService.addResponse(expectedResponse); + + UpdateUserRequest request = + UpdateUserRequest.newBuilder() + .setUser( + User.newBuilder() + .setName(UserName.of("[USER]").toString()) + .setDisplayName("displayName1714148973") + .setEmail("email96619420") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setAge(96511) + .setHeightFeet(-1032737338) + .setNickname("nickname70690926") + .setEnableNotifications(true) + .build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + + User actualResponse = client.updateUser(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void updateUserExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + UpdateUserRequest request = + UpdateUserRequest.newBuilder() + .setUser( + User.newBuilder() + .setName(UserName.of("[USER]").toString()) + .setDisplayName("displayName1714148973") + .setEmail("email96619420") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setAge(96511) + .setHeightFeet(-1032737338) + .setNickname("nickname70690926") + .setEnableNotifications(true) + .build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + client.updateUser(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteUserTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + UserName name = UserName.of("[USER]"); + + client.deleteUser(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteUserExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + UserName name = UserName.of("[USER]"); + client.deleteUser(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteUserTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + String name = "users/user-6376"; + + client.deleteUser(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteUserExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "users/user-6376"; + client.deleteUser(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listUsersTest() throws Exception { + User responsesElement = User.newBuilder().build(); + ListUsersResponse expectedResponse = + ListUsersResponse.newBuilder() + .setNextPageToken("") + .addAllUsers(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + ListUsersRequest request = + ListUsersRequest.newBuilder() + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + + ListUsersPagedResponse pagedListResponse = client.listUsers(request); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getUsersList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listUsersExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ListUsersRequest request = + ListUsersRequest.newBuilder() + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + client.listUsers(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/IdentityClientTest.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/IdentityClientTest.java new file mode 100644 index 0000000000..acbfbedb75 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/IdentityClientTest.java @@ -0,0 +1,462 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import static com.google.showcase.v1beta1.IdentityClient.ListUsersPagedResponse; + +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.grpc.GaxGrpcProperties; +import com.google.api.gax.grpc.testing.LocalChannelProvider; +import com.google.api.gax.grpc.testing.MockGrpcService; +import com.google.api.gax.grpc.testing.MockServiceHelper; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.common.collect.Lists; +import com.google.protobuf.AbstractMessage; +import com.google.protobuf.Empty; +import com.google.protobuf.FieldMask; +import com.google.protobuf.Timestamp; +import io.grpc.StatusRuntimeException; +import java.io.IOException; +import java.util.Arrays; +import java.util.List; +import java.util.UUID; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class IdentityClientTest { + private static MockIdentity mockIdentity; + private static MockServiceHelper mockServiceHelper; + private LocalChannelProvider channelProvider; + private IdentityClient client; + + @BeforeClass + public static void startStaticServer() { + mockIdentity = new MockIdentity(); + mockServiceHelper = + new MockServiceHelper( + UUID.randomUUID().toString(), Arrays.asList(mockIdentity)); + mockServiceHelper.start(); + } + + @AfterClass + public static void stopServer() { + mockServiceHelper.stop(); + } + + @Before + public void setUp() throws IOException { + mockServiceHelper.reset(); + channelProvider = mockServiceHelper.createChannelProvider(); + IdentitySettings settings = + IdentitySettings.newBuilder() + .setTransportChannelProvider(channelProvider) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = IdentityClient.create(settings); + } + + @After + public void tearDown() throws Exception { + client.close(); + } + + @Test + public void createUserTest() throws Exception { + User expectedResponse = + User.newBuilder() + .setName(UserName.of("[USER]").toString()) + .setDisplayName("displayName1714148973") + .setEmail("email96619420") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setAge(96511) + .setHeightFeet(-1032737338) + .setNickname("nickname70690926") + .setEnableNotifications(true) + .build(); + mockIdentity.addResponse(expectedResponse); + + String displayName = "displayName1714148973"; + String email = "email96619420"; + + User actualResponse = client.createUser(displayName, email); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockIdentity.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CreateUserRequest actualRequest = ((CreateUserRequest) actualRequests.get(0)); + + Assert.assertEquals(displayName, actualRequest.getUser().getDisplayName()); + Assert.assertEquals(email, actualRequest.getUser().getEmail()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void createUserExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockIdentity.addException(exception); + + try { + String displayName = "displayName1714148973"; + String email = "email96619420"; + client.createUser(displayName, email); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createUserTest2() throws Exception { + User expectedResponse = + User.newBuilder() + .setName(UserName.of("[USER]").toString()) + .setDisplayName("displayName1714148973") + .setEmail("email96619420") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setAge(96511) + .setHeightFeet(-1032737338) + .setNickname("nickname70690926") + .setEnableNotifications(true) + .build(); + mockIdentity.addResponse(expectedResponse); + + String displayName = "displayName1714148973"; + String email = "email96619420"; + int age = 96511; + String nickname = "nickname70690926"; + boolean enableNotifications = true; + double heightFeet = -1032737338; + + User actualResponse = + client.createUser(displayName, email, age, nickname, enableNotifications, heightFeet); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockIdentity.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CreateUserRequest actualRequest = ((CreateUserRequest) actualRequests.get(0)); + + Assert.assertEquals(displayName, actualRequest.getUser().getDisplayName()); + Assert.assertEquals(email, actualRequest.getUser().getEmail()); + Assert.assertEquals(age, actualRequest.getUser().getAge()); + Assert.assertEquals(nickname, actualRequest.getUser().getNickname()); + Assert.assertEquals(enableNotifications, actualRequest.getUser().getEnableNotifications()); + Assert.assertEquals(heightFeet, actualRequest.getUser().getHeightFeet(), 0.0001); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void createUserExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockIdentity.addException(exception); + + try { + String displayName = "displayName1714148973"; + String email = "email96619420"; + int age = 96511; + String nickname = "nickname70690926"; + boolean enableNotifications = true; + double heightFeet = -1032737338; + client.createUser(displayName, email, age, nickname, enableNotifications, heightFeet); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getUserTest() throws Exception { + User expectedResponse = + User.newBuilder() + .setName(UserName.of("[USER]").toString()) + .setDisplayName("displayName1714148973") + .setEmail("email96619420") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setAge(96511) + .setHeightFeet(-1032737338) + .setNickname("nickname70690926") + .setEnableNotifications(true) + .build(); + mockIdentity.addResponse(expectedResponse); + + UserName name = UserName.of("[USER]"); + + User actualResponse = client.getUser(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockIdentity.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + GetUserRequest actualRequest = ((GetUserRequest) actualRequests.get(0)); + + Assert.assertEquals(name.toString(), actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void getUserExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockIdentity.addException(exception); + + try { + UserName name = UserName.of("[USER]"); + client.getUser(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getUserTest2() throws Exception { + User expectedResponse = + User.newBuilder() + .setName(UserName.of("[USER]").toString()) + .setDisplayName("displayName1714148973") + .setEmail("email96619420") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setAge(96511) + .setHeightFeet(-1032737338) + .setNickname("nickname70690926") + .setEnableNotifications(true) + .build(); + mockIdentity.addResponse(expectedResponse); + + String name = "name3373707"; + + User actualResponse = client.getUser(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockIdentity.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + GetUserRequest actualRequest = ((GetUserRequest) actualRequests.get(0)); + + Assert.assertEquals(name, actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void getUserExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockIdentity.addException(exception); + + try { + String name = "name3373707"; + client.getUser(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateUserTest() throws Exception { + User expectedResponse = + User.newBuilder() + .setName(UserName.of("[USER]").toString()) + .setDisplayName("displayName1714148973") + .setEmail("email96619420") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setAge(96511) + .setHeightFeet(-1032737338) + .setNickname("nickname70690926") + .setEnableNotifications(true) + .build(); + mockIdentity.addResponse(expectedResponse); + + UpdateUserRequest request = + UpdateUserRequest.newBuilder() + .setUser(User.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + + User actualResponse = client.updateUser(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockIdentity.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + UpdateUserRequest actualRequest = ((UpdateUserRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getUser(), actualRequest.getUser()); + Assert.assertEquals(request.getUpdateMask(), actualRequest.getUpdateMask()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void updateUserExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockIdentity.addException(exception); + + try { + UpdateUserRequest request = + UpdateUserRequest.newBuilder() + .setUser(User.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + client.updateUser(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteUserTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockIdentity.addResponse(expectedResponse); + + UserName name = UserName.of("[USER]"); + + client.deleteUser(name); + + List actualRequests = mockIdentity.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + DeleteUserRequest actualRequest = ((DeleteUserRequest) actualRequests.get(0)); + + Assert.assertEquals(name.toString(), actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void deleteUserExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockIdentity.addException(exception); + + try { + UserName name = UserName.of("[USER]"); + client.deleteUser(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteUserTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockIdentity.addResponse(expectedResponse); + + String name = "name3373707"; + + client.deleteUser(name); + + List actualRequests = mockIdentity.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + DeleteUserRequest actualRequest = ((DeleteUserRequest) actualRequests.get(0)); + + Assert.assertEquals(name, actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void deleteUserExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockIdentity.addException(exception); + + try { + String name = "name3373707"; + client.deleteUser(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listUsersTest() throws Exception { + User responsesElement = User.newBuilder().build(); + ListUsersResponse expectedResponse = + ListUsersResponse.newBuilder() + .setNextPageToken("") + .addAllUsers(Arrays.asList(responsesElement)) + .build(); + mockIdentity.addResponse(expectedResponse); + + ListUsersRequest request = + ListUsersRequest.newBuilder() + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + + ListUsersPagedResponse pagedListResponse = client.listUsers(request); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getUsersList().get(0), resources.get(0)); + + List actualRequests = mockIdentity.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListUsersRequest actualRequest = ((ListUsersRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getPageSize(), actualRequest.getPageSize()); + Assert.assertEquals(request.getPageToken(), actualRequest.getPageToken()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void listUsersExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockIdentity.addException(exception); + + try { + ListUsersRequest request = + ListUsersRequest.newBuilder() + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + client.listUsers(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/IdentitySettings.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/IdentitySettings.java new file mode 100644 index 0000000000..f4db5be8a8 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/IdentitySettings.java @@ -0,0 +1,251 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import static com.google.showcase.v1beta1.IdentityClient.ListUsersPagedResponse; + +import com.google.api.core.ApiFunction; +import com.google.api.core.BetaApi; +import com.google.api.gax.core.GoogleCredentialsProvider; +import com.google.api.gax.core.InstantiatingExecutorProvider; +import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientSettings; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.StubSettings; +import com.google.api.gax.rpc.TransportChannelProvider; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.stub.IdentityStubSettings; +import java.io.IOException; +import java.util.List; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * Settings class to configure an instance of {@link IdentityClient}. + * + *

The default instance has everything set to sensible defaults: + * + *

    + *
  • The default service address (localhost) and default port (7469) are used. + *
  • Credentials are acquired automatically through Application Default Credentials. + *
  • Retries are configured for idempotent methods but not for non-idempotent methods. + *
+ * + *

The builder of this class is recursive, so contained classes are themselves builders. When + * build() is called, the tree of builders is called to create the complete settings object. + * + *

For example, to set the total timeout of createUser to 30 seconds: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * IdentitySettings.Builder identitySettingsBuilder = IdentitySettings.newBuilder();
+ * identitySettingsBuilder
+ *     .createUserSettings()
+ *     .setRetrySettings(
+ *         identitySettingsBuilder
+ *             .createUserSettings()
+ *             .getRetrySettings()
+ *             .toBuilder()
+ *             .setTotalTimeout(Duration.ofSeconds(30))
+ *             .build());
+ * IdentitySettings identitySettings = identitySettingsBuilder.build();
+ * }
+ */ +@BetaApi +@Generated("by gapic-generator-java") +public class IdentitySettings extends ClientSettings { + + /** Returns the object with the settings used for calls to createUser. */ + public UnaryCallSettings createUserSettings() { + return ((IdentityStubSettings) getStubSettings()).createUserSettings(); + } + + /** Returns the object with the settings used for calls to getUser. */ + public UnaryCallSettings getUserSettings() { + return ((IdentityStubSettings) getStubSettings()).getUserSettings(); + } + + /** Returns the object with the settings used for calls to updateUser. */ + public UnaryCallSettings updateUserSettings() { + return ((IdentityStubSettings) getStubSettings()).updateUserSettings(); + } + + /** Returns the object with the settings used for calls to deleteUser. */ + public UnaryCallSettings deleteUserSettings() { + return ((IdentityStubSettings) getStubSettings()).deleteUserSettings(); + } + + /** Returns the object with the settings used for calls to listUsers. */ + public PagedCallSettings + listUsersSettings() { + return ((IdentityStubSettings) getStubSettings()).listUsersSettings(); + } + + public static final IdentitySettings create(IdentityStubSettings stub) throws IOException { + return new IdentitySettings.Builder(stub.toBuilder()).build(); + } + + /** Returns a builder for the default ExecutorProvider for this service. */ + public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { + return IdentityStubSettings.defaultExecutorProviderBuilder(); + } + + /** Returns the default service endpoint. */ + public static String getDefaultEndpoint() { + return IdentityStubSettings.getDefaultEndpoint(); + } + + /** Returns the default service scopes. */ + public static List getDefaultServiceScopes() { + return IdentityStubSettings.getDefaultServiceScopes(); + } + + /** Returns a builder for the default credentials for this service. */ + public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { + return IdentityStubSettings.defaultCredentialsProviderBuilder(); + } + + /** Returns a builder for the default gRPC ChannelProvider for this service. */ + public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { + return IdentityStubSettings.defaultGrpcTransportProviderBuilder(); + } + + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return IdentityStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + + public static TransportChannelProvider defaultTransportChannelProvider() { + return IdentityStubSettings.defaultTransportChannelProvider(); + } + + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return IdentityStubSettings.defaultApiClientHeaderProviderBuilder(); + } + + /** Returns a new gRPC builder for this class. */ + public static Builder newBuilder() { + return Builder.createDefault(); + } + + /** Returns a new REST builder for this class. */ + @BetaApi + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder(ClientContext clientContext) { + return new Builder(clientContext); + } + + /** Returns a builder containing all the values of this settings class. */ + public Builder toBuilder() { + return new Builder(this); + } + + protected IdentitySettings(Builder settingsBuilder) throws IOException { + super(settingsBuilder); + } + + /** Builder for IdentitySettings. */ + public static class Builder extends ClientSettings.Builder { + + protected Builder() throws IOException { + this(((ClientContext) null)); + } + + protected Builder(ClientContext clientContext) { + super(IdentityStubSettings.newBuilder(clientContext)); + } + + protected Builder(IdentitySettings settings) { + super(settings.getStubSettings().toBuilder()); + } + + protected Builder(IdentityStubSettings.Builder stubSettings) { + super(stubSettings); + } + + private static Builder createDefault() { + return new Builder(IdentityStubSettings.newBuilder()); + } + + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(IdentityStubSettings.newHttpJsonBuilder()); + } + + public IdentityStubSettings.Builder getStubSettingsBuilder() { + return ((IdentityStubSettings.Builder) getStubSettings()); + } + + /** + * Applies the given settings updater function to all of the unary API methods in this service. + * + *

Note: This method does not support applying settings to streaming methods. + */ + public Builder applyToAllUnaryMethods( + ApiFunction, Void> settingsUpdater) { + super.applyToAllUnaryMethods( + getStubSettingsBuilder().unaryMethodSettingsBuilders(), settingsUpdater); + return this; + } + + /** Returns the builder for the settings used for calls to createUser. */ + public UnaryCallSettings.Builder createUserSettings() { + return getStubSettingsBuilder().createUserSettings(); + } + + /** Returns the builder for the settings used for calls to getUser. */ + public UnaryCallSettings.Builder getUserSettings() { + return getStubSettingsBuilder().getUserSettings(); + } + + /** Returns the builder for the settings used for calls to updateUser. */ + public UnaryCallSettings.Builder updateUserSettings() { + return getStubSettingsBuilder().updateUserSettings(); + } + + /** Returns the builder for the settings used for calls to deleteUser. */ + public UnaryCallSettings.Builder deleteUserSettings() { + return getStubSettingsBuilder().deleteUserSettings(); + } + + /** Returns the builder for the settings used for calls to listUsers. */ + public PagedCallSettings.Builder + listUsersSettings() { + return getStubSettingsBuilder().listUsersSettings(); + } + + @Override + public IdentitySettings build() throws IOException { + return new IdentitySettings(this); + } + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MessagingClient.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MessagingClient.java new file mode 100644 index 0000000000..e19a62a25b --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MessagingClient.java @@ -0,0 +1,2117 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import com.google.api.core.ApiFuture; +import com.google.api.core.ApiFutures; +import com.google.api.core.BetaApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.httpjson.longrunning.OperationsClient; +import com.google.api.gax.longrunning.OperationFuture; +import com.google.api.gax.paging.AbstractFixedSizeCollection; +import com.google.api.gax.paging.AbstractPage; +import com.google.api.gax.paging.AbstractPagedListResponse; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PageContext; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.common.util.concurrent.MoreExecutors; +import com.google.longrunning.Operation; +import com.google.protobuf.ByteString; +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.stub.MessagingStub; +import com.google.showcase.v1beta1.stub.MessagingStubSettings; +import java.io.IOException; +import java.util.List; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * Service Description: A simple messaging service that implements chat rooms and profile posts. + * + *

This messaging service showcases the features that API clients generated by gapic-generators + * implement. + * + *

This class provides the ability to make remote calls to the backing service through method + * calls that map to API methods. Sample code to get started: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (MessagingClient messagingClient = MessagingClient.create()) {
+ *   String displayName = "displayName1714148973";
+ *   String description = "description-1724546052";
+ *   Room response = messagingClient.createRoom(displayName, description);
+ * }
+ * }
+ * + *

Note: close() needs to be called on the MessagingClient object to clean up resources such as + * threads. In the example above, try-with-resources is used, which automatically calls close(). + * + *

The surface of this class includes several types of Java methods for each of the API's + * methods: + * + *

    + *
  1. A "flattened" method. With this type of method, the fields of the request type have been + * converted into function parameters. It may be the case that not all fields are available as + * parameters, and not every API method will have a flattened method entry point. + *
  2. A "request object" method. This type of method only takes one parameter, a request object, + * which must be constructed before the call. Not every API method will have a request object + * method. + *
  3. A "callable" method. This type of method takes no parameters and returns an immutable API + * callable object, which can be used to initiate calls to the service. + *
+ * + *

See the individual methods for example code. + * + *

Many parameters require resource names to be formatted in a particular way. To assist with + * these names, this class includes a format method for each type of name, and additionally a parse + * method to extract the individual identifiers contained within names that are returned. + * + *

This class can be customized by passing in a custom instance of MessagingSettings to create(). + * For example: + * + *

To customize credentials: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * MessagingSettings messagingSettings =
+ *     MessagingSettings.newBuilder()
+ *         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
+ *         .build();
+ * MessagingClient messagingClient = MessagingClient.create(messagingSettings);
+ * }
+ * + *

To customize the endpoint: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * MessagingSettings messagingSettings =
+ *     MessagingSettings.newBuilder().setEndpoint(myEndpoint).build();
+ * MessagingClient messagingClient = MessagingClient.create(messagingSettings);
+ * }
+ * + *

To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over + * the wire: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * MessagingSettings messagingSettings = MessagingSettings.newHttpJsonBuilder().build();
+ * MessagingClient messagingClient = MessagingClient.create(messagingSettings);
+ * }
+ * + *

Please refer to the GitHub repository's samples for more quickstart code snippets. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class MessagingClient implements BackgroundResource { + private final MessagingSettings settings; + private final MessagingStub stub; + private final OperationsClient httpJsonOperationsClient; + private final com.google.longrunning.OperationsClient operationsClient; + + /** Constructs an instance of MessagingClient with default settings. */ + public static final MessagingClient create() throws IOException { + return create(MessagingSettings.newBuilder().build()); + } + + /** + * Constructs an instance of MessagingClient, using the given settings. The channels are created + * based on the settings passed in, or defaults for any settings that are not set. + */ + public static final MessagingClient create(MessagingSettings settings) throws IOException { + return new MessagingClient(settings); + } + + /** + * Constructs an instance of MessagingClient, using the given stub for making calls. This is for + * advanced usage - prefer using create(MessagingSettings). + */ + public static final MessagingClient create(MessagingStub stub) { + return new MessagingClient(stub); + } + + /** + * Constructs an instance of MessagingClient, using the given settings. This is protected so that + * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. + */ + protected MessagingClient(MessagingSettings settings) throws IOException { + this.settings = settings; + this.stub = ((MessagingStubSettings) settings.getStubSettings()).createStub(); + this.operationsClient = + com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); + this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); + } + + protected MessagingClient(MessagingStub stub) { + this.settings = null; + this.stub = stub; + this.operationsClient = + com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); + this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); + } + + public final MessagingSettings getSettings() { + return settings; + } + + public MessagingStub getStub() { + return stub; + } + + /** + * Returns the OperationsClient that can be used to query the status of a long-running operation + * returned by another API method call. + */ + public final com.google.longrunning.OperationsClient getOperationsClient() { + return operationsClient; + } + + /** + * Returns the OperationsClient that can be used to query the status of a long-running operation + * returned by another API method call. + */ + @BetaApi + public final OperationsClient getHttpJsonOperationsClient() { + return httpJsonOperationsClient; + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates a room. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   String displayName = "displayName1714148973";
+   *   String description = "description-1724546052";
+   *   Room response = messagingClient.createRoom(displayName, description);
+   * }
+   * }
+ * + * @param displayName The human readable name of the chat room. + * @param description The description of the chat room. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final Room createRoom(String displayName, String description) { + CreateRoomRequest request = + CreateRoomRequest.newBuilder() + .setRoom( + Room.newBuilder().setDisplayName(displayName).setDescription(description).build()) + .build(); + return createRoom(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates a room. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   CreateRoomRequest request =
+   *       CreateRoomRequest.newBuilder().setRoom(Room.newBuilder().build()).build();
+   *   Room response = messagingClient.createRoom(request);
+   * }
+   * }
+ * + * @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 + */ + public final Room createRoom(CreateRoomRequest request) { + return createRoomCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates a room. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   CreateRoomRequest request =
+   *       CreateRoomRequest.newBuilder().setRoom(Room.newBuilder().build()).build();
+   *   ApiFuture future = messagingClient.createRoomCallable().futureCall(request);
+   *   // Do something.
+   *   Room response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable createRoomCallable() { + return stub.createRoomCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Retrieves the Room with the given resource name. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   RoomName name = RoomName.of("[ROOM]");
+   *   Room response = messagingClient.getRoom(name);
+   * }
+   * }
+ * + * @param name The resource name of the requested room. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final Room getRoom(RoomName name) { + GetRoomRequest request = + GetRoomRequest.newBuilder().setName(name == null ? null : name.toString()).build(); + return getRoom(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Retrieves the Room with the given resource name. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   String name = RoomName.of("[ROOM]").toString();
+   *   Room response = messagingClient.getRoom(name);
+   * }
+   * }
+ * + * @param name The resource name of the requested room. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final Room getRoom(String name) { + GetRoomRequest request = GetRoomRequest.newBuilder().setName(name).build(); + return getRoom(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Retrieves the Room with the given resource name. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   GetRoomRequest request =
+   *       GetRoomRequest.newBuilder().setName(RoomName.of("[ROOM]").toString()).build();
+   *   Room response = messagingClient.getRoom(request);
+   * }
+   * }
+ * + * @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 + */ + public final Room getRoom(GetRoomRequest request) { + return getRoomCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Retrieves the Room with the given resource name. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   GetRoomRequest request =
+   *       GetRoomRequest.newBuilder().setName(RoomName.of("[ROOM]").toString()).build();
+   *   ApiFuture future = messagingClient.getRoomCallable().futureCall(request);
+   *   // Do something.
+   *   Room response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable getRoomCallable() { + return stub.getRoomCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Updates a room. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   UpdateRoomRequest request =
+   *       UpdateRoomRequest.newBuilder()
+   *           .setRoom(Room.newBuilder().build())
+   *           .setUpdateMask(FieldMask.newBuilder().build())
+   *           .build();
+   *   Room response = messagingClient.updateRoom(request);
+   * }
+   * }
+ * + * @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 + */ + public final Room updateRoom(UpdateRoomRequest request) { + return updateRoomCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Updates a room. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   UpdateRoomRequest request =
+   *       UpdateRoomRequest.newBuilder()
+   *           .setRoom(Room.newBuilder().build())
+   *           .setUpdateMask(FieldMask.newBuilder().build())
+   *           .build();
+   *   ApiFuture future = messagingClient.updateRoomCallable().futureCall(request);
+   *   // Do something.
+   *   Room response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable updateRoomCallable() { + return stub.updateRoomCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Deletes a room and all of its blurbs. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   RoomName name = RoomName.of("[ROOM]");
+   *   messagingClient.deleteRoom(name);
+   * }
+   * }
+ * + * @param name The resource name of the requested room. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final void deleteRoom(RoomName name) { + DeleteRoomRequest request = + DeleteRoomRequest.newBuilder().setName(name == null ? null : name.toString()).build(); + deleteRoom(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Deletes a room and all of its blurbs. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   String name = RoomName.of("[ROOM]").toString();
+   *   messagingClient.deleteRoom(name);
+   * }
+   * }
+ * + * @param name The resource name of the requested room. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final void deleteRoom(String name) { + DeleteRoomRequest request = DeleteRoomRequest.newBuilder().setName(name).build(); + deleteRoom(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Deletes a room and all of its blurbs. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   DeleteRoomRequest request =
+   *       DeleteRoomRequest.newBuilder().setName(RoomName.of("[ROOM]").toString()).build();
+   *   messagingClient.deleteRoom(request);
+   * }
+   * }
+ * + * @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 + */ + public final void deleteRoom(DeleteRoomRequest request) { + deleteRoomCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Deletes a room and all of its blurbs. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   DeleteRoomRequest request =
+   *       DeleteRoomRequest.newBuilder().setName(RoomName.of("[ROOM]").toString()).build();
+   *   ApiFuture future = messagingClient.deleteRoomCallable().futureCall(request);
+   *   // Do something.
+   *   future.get();
+   * }
+   * }
+ */ + public final UnaryCallable deleteRoomCallable() { + return stub.deleteRoomCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Lists all chat rooms. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   ListRoomsRequest request =
+   *       ListRoomsRequest.newBuilder()
+   *           .setPageSize(883849137)
+   *           .setPageToken("pageToken873572522")
+   *           .build();
+   *   for (Room element : messagingClient.listRooms(request).iterateAll()) {
+   *     // doThingsWith(element);
+   *   }
+   * }
+   * }
+ * + * @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 + */ + public final ListRoomsPagedResponse listRooms(ListRoomsRequest request) { + return listRoomsPagedCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Lists all chat rooms. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   ListRoomsRequest request =
+   *       ListRoomsRequest.newBuilder()
+   *           .setPageSize(883849137)
+   *           .setPageToken("pageToken873572522")
+   *           .build();
+   *   ApiFuture future = messagingClient.listRoomsPagedCallable().futureCall(request);
+   *   // Do something.
+   *   for (Room element : future.get().iterateAll()) {
+   *     // doThingsWith(element);
+   *   }
+   * }
+   * }
+ */ + public final UnaryCallable listRoomsPagedCallable() { + return stub.listRoomsPagedCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Lists all chat rooms. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   ListRoomsRequest request =
+   *       ListRoomsRequest.newBuilder()
+   *           .setPageSize(883849137)
+   *           .setPageToken("pageToken873572522")
+   *           .build();
+   *   while (true) {
+   *     ListRoomsResponse response = messagingClient.listRoomsCallable().call(request);
+   *     for (Room element : response.getRoomsList()) {
+   *       // doThingsWith(element);
+   *     }
+   *     String nextPageToken = response.getNextPageToken();
+   *     if (!Strings.isNullOrEmpty(nextPageToken)) {
+   *       request = request.toBuilder().setPageToken(nextPageToken).build();
+   *     } else {
+   *       break;
+   *     }
+   *   }
+   * }
+   * }
+ */ + public final UnaryCallable listRoomsCallable() { + return stub.listRoomsCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates a blurb. If the parent is a room, the blurb is understood to be a message in that room. + * If the parent is a profile, the blurb is understood to be a post on the profile. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   ProfileName parent = ProfileName.of("[USER]");
+   *   UserName user = UserName.of("[USER]");
+   *   ByteString image = ByteString.EMPTY;
+   *   Blurb response = messagingClient.createBlurb(parent, user, image);
+   * }
+   * }
+ * + * @param parent The resource name of the chat room or user profile that this blurb will be tied + * to. + * @param user The resource name of the blurb's author. + * @param image The image content of this blurb. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final Blurb createBlurb(ProfileName parent, UserName user, ByteString image) { + CreateBlurbRequest request = + CreateBlurbRequest.newBuilder() + .setParent(parent == null ? null : parent.toString()) + .setBlurb( + Blurb.newBuilder() + .setUser(user == null ? null : user.toString()) + .setImage(image) + .build()) + .build(); + return createBlurb(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates a blurb. If the parent is a room, the blurb is understood to be a message in that room. + * If the parent is a profile, the blurb is understood to be a post on the profile. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   ProfileName parent = ProfileName.of("[USER]");
+   *   UserName user = UserName.of("[USER]");
+   *   String text = "text3556653";
+   *   Blurb response = messagingClient.createBlurb(parent, user, text);
+   * }
+   * }
+ * + * @param parent The resource name of the chat room or user profile that this blurb will be tied + * to. + * @param user The resource name of the blurb's author. + * @param text The textual content of this blurb. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final Blurb createBlurb(ProfileName parent, UserName user, String text) { + CreateBlurbRequest request = + CreateBlurbRequest.newBuilder() + .setParent(parent == null ? null : parent.toString()) + .setBlurb( + Blurb.newBuilder() + .setUser(user == null ? null : user.toString()) + .setText(text) + .build()) + .build(); + return createBlurb(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates a blurb. If the parent is a room, the blurb is understood to be a message in that room. + * If the parent is a profile, the blurb is understood to be a post on the profile. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   ProfileName parent = ProfileName.of("[USER]");
+   *   String user = UserName.of("[USER]").toString();
+   *   ByteString image = ByteString.EMPTY;
+   *   Blurb response = messagingClient.createBlurb(parent, user, image);
+   * }
+   * }
+ * + * @param parent The resource name of the chat room or user profile that this blurb will be tied + * to. + * @param user The resource name of the blurb's author. + * @param image The image content of this blurb. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final Blurb createBlurb(ProfileName parent, String user, ByteString image) { + CreateBlurbRequest request = + CreateBlurbRequest.newBuilder() + .setParent(parent == null ? null : parent.toString()) + .setBlurb(Blurb.newBuilder().setUser(user).setImage(image).build()) + .build(); + return createBlurb(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates a blurb. If the parent is a room, the blurb is understood to be a message in that room. + * If the parent is a profile, the blurb is understood to be a post on the profile. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   ProfileName parent = ProfileName.of("[USER]");
+   *   String user = UserName.of("[USER]").toString();
+   *   String text = "text3556653";
+   *   Blurb response = messagingClient.createBlurb(parent, user, text);
+   * }
+   * }
+ * + * @param parent The resource name of the chat room or user profile that this blurb will be tied + * to. + * @param user The resource name of the blurb's author. + * @param text The textual content of this blurb. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final Blurb createBlurb(ProfileName parent, String user, String text) { + CreateBlurbRequest request = + CreateBlurbRequest.newBuilder() + .setParent(parent == null ? null : parent.toString()) + .setBlurb(Blurb.newBuilder().setUser(user).setText(text).build()) + .build(); + return createBlurb(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates a blurb. If the parent is a room, the blurb is understood to be a message in that room. + * If the parent is a profile, the blurb is understood to be a post on the profile. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   RoomName parent = RoomName.of("[ROOM]");
+   *   UserName user = UserName.of("[USER]");
+   *   ByteString image = ByteString.EMPTY;
+   *   Blurb response = messagingClient.createBlurb(parent, user, image);
+   * }
+   * }
+ * + * @param parent The resource name of the chat room or user profile that this blurb will be tied + * to. + * @param user The resource name of the blurb's author. + * @param image The image content of this blurb. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final Blurb createBlurb(RoomName parent, UserName user, ByteString image) { + CreateBlurbRequest request = + CreateBlurbRequest.newBuilder() + .setParent(parent == null ? null : parent.toString()) + .setBlurb( + Blurb.newBuilder() + .setUser(user == null ? null : user.toString()) + .setImage(image) + .build()) + .build(); + return createBlurb(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates a blurb. If the parent is a room, the blurb is understood to be a message in that room. + * If the parent is a profile, the blurb is understood to be a post on the profile. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   RoomName parent = RoomName.of("[ROOM]");
+   *   UserName user = UserName.of("[USER]");
+   *   String text = "text3556653";
+   *   Blurb response = messagingClient.createBlurb(parent, user, text);
+   * }
+   * }
+ * + * @param parent The resource name of the chat room or user profile that this blurb will be tied + * to. + * @param user The resource name of the blurb's author. + * @param text The textual content of this blurb. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final Blurb createBlurb(RoomName parent, UserName user, String text) { + CreateBlurbRequest request = + CreateBlurbRequest.newBuilder() + .setParent(parent == null ? null : parent.toString()) + .setBlurb( + Blurb.newBuilder() + .setUser(user == null ? null : user.toString()) + .setText(text) + .build()) + .build(); + return createBlurb(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates a blurb. If the parent is a room, the blurb is understood to be a message in that room. + * If the parent is a profile, the blurb is understood to be a post on the profile. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   RoomName parent = RoomName.of("[ROOM]");
+   *   String user = UserName.of("[USER]").toString();
+   *   ByteString image = ByteString.EMPTY;
+   *   Blurb response = messagingClient.createBlurb(parent, user, image);
+   * }
+   * }
+ * + * @param parent The resource name of the chat room or user profile that this blurb will be tied + * to. + * @param user The resource name of the blurb's author. + * @param image The image content of this blurb. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final Blurb createBlurb(RoomName parent, String user, ByteString image) { + CreateBlurbRequest request = + CreateBlurbRequest.newBuilder() + .setParent(parent == null ? null : parent.toString()) + .setBlurb(Blurb.newBuilder().setUser(user).setImage(image).build()) + .build(); + return createBlurb(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates a blurb. If the parent is a room, the blurb is understood to be a message in that room. + * If the parent is a profile, the blurb is understood to be a post on the profile. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   RoomName parent = RoomName.of("[ROOM]");
+   *   String user = UserName.of("[USER]").toString();
+   *   String text = "text3556653";
+   *   Blurb response = messagingClient.createBlurb(parent, user, text);
+   * }
+   * }
+ * + * @param parent The resource name of the chat room or user profile that this blurb will be tied + * to. + * @param user The resource name of the blurb's author. + * @param text The textual content of this blurb. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final Blurb createBlurb(RoomName parent, String user, String text) { + CreateBlurbRequest request = + CreateBlurbRequest.newBuilder() + .setParent(parent == null ? null : parent.toString()) + .setBlurb(Blurb.newBuilder().setUser(user).setText(text).build()) + .build(); + return createBlurb(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates a blurb. If the parent is a room, the blurb is understood to be a message in that room. + * If the parent is a profile, the blurb is understood to be a post on the profile. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   String parent = ProfileName.of("[USER]").toString();
+   *   UserName user = UserName.of("[USER]");
+   *   ByteString image = ByteString.EMPTY;
+   *   Blurb response = messagingClient.createBlurb(parent, user, image);
+   * }
+   * }
+ * + * @param parent The resource name of the chat room or user profile that this blurb will be tied + * to. + * @param user The resource name of the blurb's author. + * @param image The image content of this blurb. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final Blurb createBlurb(String parent, UserName user, ByteString image) { + CreateBlurbRequest request = + CreateBlurbRequest.newBuilder() + .setParent(parent) + .setBlurb( + Blurb.newBuilder() + .setUser(user == null ? null : user.toString()) + .setImage(image) + .build()) + .build(); + return createBlurb(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates a blurb. If the parent is a room, the blurb is understood to be a message in that room. + * If the parent is a profile, the blurb is understood to be a post on the profile. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   String parent = ProfileName.of("[USER]").toString();
+   *   UserName user = UserName.of("[USER]");
+   *   String text = "text3556653";
+   *   Blurb response = messagingClient.createBlurb(parent, user, text);
+   * }
+   * }
+ * + * @param parent The resource name of the chat room or user profile that this blurb will be tied + * to. + * @param user The resource name of the blurb's author. + * @param text The textual content of this blurb. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final Blurb createBlurb(String parent, UserName user, String text) { + CreateBlurbRequest request = + CreateBlurbRequest.newBuilder() + .setParent(parent) + .setBlurb( + Blurb.newBuilder() + .setUser(user == null ? null : user.toString()) + .setText(text) + .build()) + .build(); + return createBlurb(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates a blurb. If the parent is a room, the blurb is understood to be a message in that room. + * If the parent is a profile, the blurb is understood to be a post on the profile. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   String parent = ProfileName.of("[USER]").toString();
+   *   String user = UserName.of("[USER]").toString();
+   *   ByteString image = ByteString.EMPTY;
+   *   Blurb response = messagingClient.createBlurb(parent, user, image);
+   * }
+   * }
+ * + * @param parent The resource name of the chat room or user profile that this blurb will be tied + * to. + * @param user The resource name of the blurb's author. + * @param image The image content of this blurb. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final Blurb createBlurb(String parent, String user, ByteString image) { + CreateBlurbRequest request = + CreateBlurbRequest.newBuilder() + .setParent(parent) + .setBlurb(Blurb.newBuilder().setUser(user).setImage(image).build()) + .build(); + return createBlurb(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates a blurb. If the parent is a room, the blurb is understood to be a message in that room. + * If the parent is a profile, the blurb is understood to be a post on the profile. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   String parent = ProfileName.of("[USER]").toString();
+   *   String user = UserName.of("[USER]").toString();
+   *   String text = "text3556653";
+   *   Blurb response = messagingClient.createBlurb(parent, user, text);
+   * }
+   * }
+ * + * @param parent The resource name of the chat room or user profile that this blurb will be tied + * to. + * @param user The resource name of the blurb's author. + * @param text The textual content of this blurb. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final Blurb createBlurb(String parent, String user, String text) { + CreateBlurbRequest request = + CreateBlurbRequest.newBuilder() + .setParent(parent) + .setBlurb(Blurb.newBuilder().setUser(user).setText(text).build()) + .build(); + return createBlurb(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates a blurb. If the parent is a room, the blurb is understood to be a message in that room. + * If the parent is a profile, the blurb is understood to be a post on the profile. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   CreateBlurbRequest request =
+   *       CreateBlurbRequest.newBuilder()
+   *           .setParent(ProfileName.of("[USER]").toString())
+   *           .setBlurb(Blurb.newBuilder().build())
+   *           .build();
+   *   Blurb response = messagingClient.createBlurb(request);
+   * }
+   * }
+ * + * @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 + */ + public final Blurb createBlurb(CreateBlurbRequest request) { + return createBlurbCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates a blurb. If the parent is a room, the blurb is understood to be a message in that room. + * If the parent is a profile, the blurb is understood to be a post on the profile. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   CreateBlurbRequest request =
+   *       CreateBlurbRequest.newBuilder()
+   *           .setParent(ProfileName.of("[USER]").toString())
+   *           .setBlurb(Blurb.newBuilder().build())
+   *           .build();
+   *   ApiFuture future = messagingClient.createBlurbCallable().futureCall(request);
+   *   // Do something.
+   *   Blurb response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable createBlurbCallable() { + return stub.createBlurbCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Retrieves the Blurb with the given resource name. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   BlurbName name = BlurbName.ofRoomBlurbName("[ROOM]", "[BLURB]");
+   *   Blurb response = messagingClient.getBlurb(name);
+   * }
+   * }
+ * + * @param name The resource name of the requested blurb. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final Blurb getBlurb(BlurbName name) { + GetBlurbRequest request = + GetBlurbRequest.newBuilder().setName(name == null ? null : name.toString()).build(); + return getBlurb(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Retrieves the Blurb with the given resource name. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   String name =
+   *       BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]").toString();
+   *   Blurb response = messagingClient.getBlurb(name);
+   * }
+   * }
+ * + * @param name The resource name of the requested blurb. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final Blurb getBlurb(String name) { + GetBlurbRequest request = GetBlurbRequest.newBuilder().setName(name).build(); + return getBlurb(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Retrieves the Blurb with the given resource name. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   GetBlurbRequest request =
+   *       GetBlurbRequest.newBuilder()
+   *           .setName(BlurbName.ofRoomBlurbName("[ROOM]", "[BLURB]").toString())
+   *           .build();
+   *   Blurb response = messagingClient.getBlurb(request);
+   * }
+   * }
+ * + * @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 + */ + public final Blurb getBlurb(GetBlurbRequest request) { + return getBlurbCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Retrieves the Blurb with the given resource name. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   GetBlurbRequest request =
+   *       GetBlurbRequest.newBuilder()
+   *           .setName(BlurbName.ofRoomBlurbName("[ROOM]", "[BLURB]").toString())
+   *           .build();
+   *   ApiFuture future = messagingClient.getBlurbCallable().futureCall(request);
+   *   // Do something.
+   *   Blurb response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable getBlurbCallable() { + return stub.getBlurbCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Updates a blurb. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   UpdateBlurbRequest request =
+   *       UpdateBlurbRequest.newBuilder()
+   *           .setBlurb(Blurb.newBuilder().build())
+   *           .setUpdateMask(FieldMask.newBuilder().build())
+   *           .build();
+   *   Blurb response = messagingClient.updateBlurb(request);
+   * }
+   * }
+ * + * @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 + */ + public final Blurb updateBlurb(UpdateBlurbRequest request) { + return updateBlurbCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Updates a blurb. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   UpdateBlurbRequest request =
+   *       UpdateBlurbRequest.newBuilder()
+   *           .setBlurb(Blurb.newBuilder().build())
+   *           .setUpdateMask(FieldMask.newBuilder().build())
+   *           .build();
+   *   ApiFuture future = messagingClient.updateBlurbCallable().futureCall(request);
+   *   // Do something.
+   *   Blurb response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable updateBlurbCallable() { + return stub.updateBlurbCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Deletes a blurb. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   BlurbName name = BlurbName.ofRoomBlurbName("[ROOM]", "[BLURB]");
+   *   messagingClient.deleteBlurb(name);
+   * }
+   * }
+ * + * @param name The resource name of the requested blurb. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final void deleteBlurb(BlurbName name) { + DeleteBlurbRequest request = + DeleteBlurbRequest.newBuilder().setName(name == null ? null : name.toString()).build(); + deleteBlurb(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Deletes a blurb. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   String name =
+   *       BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]").toString();
+   *   messagingClient.deleteBlurb(name);
+   * }
+   * }
+ * + * @param name The resource name of the requested blurb. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final void deleteBlurb(String name) { + DeleteBlurbRequest request = DeleteBlurbRequest.newBuilder().setName(name).build(); + deleteBlurb(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Deletes a blurb. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   DeleteBlurbRequest request =
+   *       DeleteBlurbRequest.newBuilder()
+   *           .setName(BlurbName.ofRoomBlurbName("[ROOM]", "[BLURB]").toString())
+   *           .build();
+   *   messagingClient.deleteBlurb(request);
+   * }
+   * }
+ * + * @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 + */ + public final void deleteBlurb(DeleteBlurbRequest request) { + deleteBlurbCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Deletes a blurb. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   DeleteBlurbRequest request =
+   *       DeleteBlurbRequest.newBuilder()
+   *           .setName(BlurbName.ofRoomBlurbName("[ROOM]", "[BLURB]").toString())
+   *           .build();
+   *   ApiFuture future = messagingClient.deleteBlurbCallable().futureCall(request);
+   *   // Do something.
+   *   future.get();
+   * }
+   * }
+ */ + public final UnaryCallable deleteBlurbCallable() { + return stub.deleteBlurbCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Lists blurbs for a specific chat room or user profile depending on the parent resource name. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   ProfileName parent = ProfileName.of("[USER]");
+   *   for (Blurb element : messagingClient.listBlurbs(parent).iterateAll()) {
+   *     // doThingsWith(element);
+   *   }
+   * }
+   * }
+ * + * @param parent The resource name of the requested room or profile whos blurbs to list. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final ListBlurbsPagedResponse listBlurbs(ProfileName parent) { + ListBlurbsRequest request = + ListBlurbsRequest.newBuilder().setParent(parent == null ? null : parent.toString()).build(); + return listBlurbs(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Lists blurbs for a specific chat room or user profile depending on the parent resource name. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   RoomName parent = RoomName.of("[ROOM]");
+   *   for (Blurb element : messagingClient.listBlurbs(parent).iterateAll()) {
+   *     // doThingsWith(element);
+   *   }
+   * }
+   * }
+ * + * @param parent The resource name of the requested room or profile whos blurbs to list. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final ListBlurbsPagedResponse listBlurbs(RoomName parent) { + ListBlurbsRequest request = + ListBlurbsRequest.newBuilder().setParent(parent == null ? null : parent.toString()).build(); + return listBlurbs(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Lists blurbs for a specific chat room or user profile depending on the parent resource name. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   String parent = ProfileName.of("[USER]").toString();
+   *   for (Blurb element : messagingClient.listBlurbs(parent).iterateAll()) {
+   *     // doThingsWith(element);
+   *   }
+   * }
+   * }
+ * + * @param parent The resource name of the requested room or profile whos blurbs to list. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final ListBlurbsPagedResponse listBlurbs(String parent) { + ListBlurbsRequest request = ListBlurbsRequest.newBuilder().setParent(parent).build(); + return listBlurbs(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Lists blurbs for a specific chat room or user profile depending on the parent resource name. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   ListBlurbsRequest request =
+   *       ListBlurbsRequest.newBuilder()
+   *           .setParent(ProfileName.of("[USER]").toString())
+   *           .setPageSize(883849137)
+   *           .setPageToken("pageToken873572522")
+   *           .build();
+   *   for (Blurb element : messagingClient.listBlurbs(request).iterateAll()) {
+   *     // doThingsWith(element);
+   *   }
+   * }
+   * }
+ * + * @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 + */ + public final ListBlurbsPagedResponse listBlurbs(ListBlurbsRequest request) { + return listBlurbsPagedCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Lists blurbs for a specific chat room or user profile depending on the parent resource name. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   ListBlurbsRequest request =
+   *       ListBlurbsRequest.newBuilder()
+   *           .setParent(ProfileName.of("[USER]").toString())
+   *           .setPageSize(883849137)
+   *           .setPageToken("pageToken873572522")
+   *           .build();
+   *   ApiFuture future = messagingClient.listBlurbsPagedCallable().futureCall(request);
+   *   // Do something.
+   *   for (Blurb element : future.get().iterateAll()) {
+   *     // doThingsWith(element);
+   *   }
+   * }
+   * }
+ */ + public final UnaryCallable listBlurbsPagedCallable() { + return stub.listBlurbsPagedCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Lists blurbs for a specific chat room or user profile depending on the parent resource name. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   ListBlurbsRequest request =
+   *       ListBlurbsRequest.newBuilder()
+   *           .setParent(ProfileName.of("[USER]").toString())
+   *           .setPageSize(883849137)
+   *           .setPageToken("pageToken873572522")
+   *           .build();
+   *   while (true) {
+   *     ListBlurbsResponse response = messagingClient.listBlurbsCallable().call(request);
+   *     for (Blurb element : response.getBlurbsList()) {
+   *       // doThingsWith(element);
+   *     }
+   *     String nextPageToken = response.getNextPageToken();
+   *     if (!Strings.isNullOrEmpty(nextPageToken)) {
+   *       request = request.toBuilder().setPageToken(nextPageToken).build();
+   *     } else {
+   *       break;
+   *     }
+   *   }
+   * }
+   * }
+ */ + public final UnaryCallable listBlurbsCallable() { + return stub.listBlurbsCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This method searches through all blurbs across all rooms and profiles for blurbs containing to + * words found in the query. Only posts that contain an exact match of a queried word will be + * returned. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   ProfileName parent = ProfileName.of("[USER]");
+   *   String query = "query107944136";
+   *   SearchBlurbsResponse response = messagingClient.searchBlurbsAsync(parent, query).get();
+   * }
+   * }
+ * + * @param parent The rooms or profiles to search. If unset, `SearchBlurbs` will search all rooms + * and all profiles. + * @param query The query used to search for blurbs containing to words of this string. Only posts + * that contain an exact match of a queried word will be returned. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final OperationFuture searchBlurbsAsync( + ProfileName parent, String query) { + SearchBlurbsRequest request = + SearchBlurbsRequest.newBuilder() + .setParent(parent == null ? null : parent.toString()) + .setQuery(query) + .build(); + return searchBlurbsAsync(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This method searches through all blurbs across all rooms and profiles for blurbs containing to + * words found in the query. Only posts that contain an exact match of a queried word will be + * returned. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   RoomName parent = RoomName.of("[ROOM]");
+   *   String query = "query107944136";
+   *   SearchBlurbsResponse response = messagingClient.searchBlurbsAsync(parent, query).get();
+   * }
+   * }
+ * + * @param parent The rooms or profiles to search. If unset, `SearchBlurbs` will search all rooms + * and all profiles. + * @param query The query used to search for blurbs containing to words of this string. Only posts + * that contain an exact match of a queried word will be returned. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final OperationFuture searchBlurbsAsync( + RoomName parent, String query) { + SearchBlurbsRequest request = + SearchBlurbsRequest.newBuilder() + .setParent(parent == null ? null : parent.toString()) + .setQuery(query) + .build(); + return searchBlurbsAsync(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This method searches through all blurbs across all rooms and profiles for blurbs containing to + * words found in the query. Only posts that contain an exact match of a queried word will be + * returned. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   String parent = ProfileName.of("[USER]").toString();
+   *   String query = "query107944136";
+   *   SearchBlurbsResponse response = messagingClient.searchBlurbsAsync(parent, query).get();
+   * }
+   * }
+ * + * @param parent The rooms or profiles to search. If unset, `SearchBlurbs` will search all rooms + * and all profiles. + * @param query The query used to search for blurbs containing to words of this string. Only posts + * that contain an exact match of a queried word will be returned. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final OperationFuture searchBlurbsAsync( + String parent, String query) { + SearchBlurbsRequest request = + SearchBlurbsRequest.newBuilder().setParent(parent).setQuery(query).build(); + return searchBlurbsAsync(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This method searches through all blurbs across all rooms and profiles for blurbs containing to + * words found in the query. Only posts that contain an exact match of a queried word will be + * returned. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   SearchBlurbsRequest request =
+   *       SearchBlurbsRequest.newBuilder()
+   *           .setQuery("query107944136")
+   *           .setParent(ProfileName.of("[USER]").toString())
+   *           .setPageSize(883849137)
+   *           .setPageToken("pageToken873572522")
+   *           .build();
+   *   SearchBlurbsResponse response = messagingClient.searchBlurbsAsync(request).get();
+   * }
+   * }
+ * + * @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 + */ + public final OperationFuture searchBlurbsAsync( + SearchBlurbsRequest request) { + return searchBlurbsOperationCallable().futureCall(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This method searches through all blurbs across all rooms and profiles for blurbs containing to + * words found in the query. Only posts that contain an exact match of a queried word will be + * returned. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   SearchBlurbsRequest request =
+   *       SearchBlurbsRequest.newBuilder()
+   *           .setQuery("query107944136")
+   *           .setParent(ProfileName.of("[USER]").toString())
+   *           .setPageSize(883849137)
+   *           .setPageToken("pageToken873572522")
+   *           .build();
+   *   OperationFuture future =
+   *       messagingClient.searchBlurbsOperationCallable().futureCall(request);
+   *   // Do something.
+   *   SearchBlurbsResponse response = future.get();
+   * }
+   * }
+ */ + public final OperationCallable + searchBlurbsOperationCallable() { + return stub.searchBlurbsOperationCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This method searches through all blurbs across all rooms and profiles for blurbs containing to + * words found in the query. Only posts that contain an exact match of a queried word will be + * returned. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   SearchBlurbsRequest request =
+   *       SearchBlurbsRequest.newBuilder()
+   *           .setQuery("query107944136")
+   *           .setParent(ProfileName.of("[USER]").toString())
+   *           .setPageSize(883849137)
+   *           .setPageToken("pageToken873572522")
+   *           .build();
+   *   ApiFuture future = messagingClient.searchBlurbsCallable().futureCall(request);
+   *   // Do something.
+   *   Operation response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable searchBlurbsCallable() { + return stub.searchBlurbsCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This returns a stream that emits the blurbs that are created for a particular chat room or user + * profile. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   StreamBlurbsRequest request =
+   *       StreamBlurbsRequest.newBuilder()
+   *           .setName(ProfileName.of("[USER]").toString())
+   *           .setExpireTime(Timestamp.newBuilder().build())
+   *           .build();
+   *   ServerStream stream =
+   *       messagingClient.streamBlurbsCallable().call(request);
+   *   for (StreamBlurbsResponse response : stream) {
+   *     // Do something when a response is received.
+   *   }
+   * }
+   * }
+ */ + public final ServerStreamingCallable + streamBlurbsCallable() { + return stub.streamBlurbsCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This is a stream to create multiple blurbs. If an invalid blurb is requested to be created, the + * stream will close with an error. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   ApiStreamObserver responseObserver =
+   *       new ApiStreamObserver() {
+   *         {@literal @}Override
+   *         public void onNext(SendBlurbsResponse response) {
+   *           // Do something when a response is received.
+   *         }
+   *
+   *         {@literal @}Override
+   *         public void onError(Throwable t) {
+   *           // Add error-handling
+   *         }
+   *
+   *         {@literal @}Override
+   *         public void onCompleted() {
+   *           // Do something when complete.
+   *         }
+   *       };
+   *   ApiStreamObserver requestObserver =
+   *       messagingClient.sendBlurbs().clientStreamingCall(responseObserver);
+   *   CreateBlurbRequest request =
+   *       CreateBlurbRequest.newBuilder()
+   *           .setParent(ProfileName.of("[USER]").toString())
+   *           .setBlurb(Blurb.newBuilder().build())
+   *           .build();
+   *   requestObserver.onNext(request);
+   * }
+   * }
+ */ + public final ClientStreamingCallable + sendBlurbsCallable() { + return stub.sendBlurbsCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * This method starts a bidirectional stream that receives all blurbs that are being created after + * the stream has started and sends requests to create blurbs. If an invalid blurb is requested to + * be created, the stream will close with an error. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   BidiStream bidiStream =
+   *       messagingClient.connectCallable().call();
+   *   ConnectRequest request = ConnectRequest.newBuilder().build();
+   *   bidiStream.send(request);
+   *   for (StreamBlurbsResponse response : bidiStream) {
+   *     // Do something when a response is received.
+   *   }
+   * }
+   * }
+ */ + public final BidiStreamingCallable connectCallable() { + return stub.connectCallable(); + } + + @Override + public final void close() { + stub.close(); + } + + @Override + public void shutdown() { + stub.shutdown(); + } + + @Override + public boolean isShutdown() { + return stub.isShutdown(); + } + + @Override + public boolean isTerminated() { + return stub.isTerminated(); + } + + @Override + public void shutdownNow() { + stub.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return stub.awaitTermination(duration, unit); + } + + public static class ListRoomsPagedResponse + extends AbstractPagedListResponse< + ListRoomsRequest, ListRoomsResponse, Room, ListRoomsPage, ListRoomsFixedSizeCollection> { + + public static ApiFuture createAsync( + PageContext context, + ApiFuture futureResponse) { + ApiFuture futurePage = + ListRoomsPage.createEmptyPage().createPageAsync(context, futureResponse); + return ApiFutures.transform( + futurePage, input -> new ListRoomsPagedResponse(input), MoreExecutors.directExecutor()); + } + + private ListRoomsPagedResponse(ListRoomsPage page) { + super(page, ListRoomsFixedSizeCollection.createEmptyCollection()); + } + } + + public static class ListRoomsPage + extends AbstractPage { + + private ListRoomsPage( + PageContext context, + ListRoomsResponse response) { + super(context, response); + } + + private static ListRoomsPage createEmptyPage() { + return new ListRoomsPage(null, null); + } + + @Override + protected ListRoomsPage createPage( + PageContext context, + ListRoomsResponse response) { + return new ListRoomsPage(context, response); + } + + @Override + public ApiFuture createPageAsync( + PageContext context, + ApiFuture futureResponse) { + return super.createPageAsync(context, futureResponse); + } + } + + public static class ListRoomsFixedSizeCollection + extends AbstractFixedSizeCollection< + ListRoomsRequest, ListRoomsResponse, Room, ListRoomsPage, ListRoomsFixedSizeCollection> { + + private ListRoomsFixedSizeCollection(List pages, int collectionSize) { + super(pages, collectionSize); + } + + private static ListRoomsFixedSizeCollection createEmptyCollection() { + return new ListRoomsFixedSizeCollection(null, 0); + } + + @Override + protected ListRoomsFixedSizeCollection createCollection( + List pages, int collectionSize) { + return new ListRoomsFixedSizeCollection(pages, collectionSize); + } + } + + public static class ListBlurbsPagedResponse + extends AbstractPagedListResponse< + ListBlurbsRequest, + ListBlurbsResponse, + Blurb, + ListBlurbsPage, + ListBlurbsFixedSizeCollection> { + + public static ApiFuture createAsync( + PageContext context, + ApiFuture futureResponse) { + ApiFuture futurePage = + ListBlurbsPage.createEmptyPage().createPageAsync(context, futureResponse); + return ApiFutures.transform( + futurePage, input -> new ListBlurbsPagedResponse(input), MoreExecutors.directExecutor()); + } + + private ListBlurbsPagedResponse(ListBlurbsPage page) { + super(page, ListBlurbsFixedSizeCollection.createEmptyCollection()); + } + } + + public static class ListBlurbsPage + extends AbstractPage { + + private ListBlurbsPage( + PageContext context, + ListBlurbsResponse response) { + super(context, response); + } + + private static ListBlurbsPage createEmptyPage() { + return new ListBlurbsPage(null, null); + } + + @Override + protected ListBlurbsPage createPage( + PageContext context, + ListBlurbsResponse response) { + return new ListBlurbsPage(context, response); + } + + @Override + public ApiFuture createPageAsync( + PageContext context, + ApiFuture futureResponse) { + return super.createPageAsync(context, futureResponse); + } + } + + public static class ListBlurbsFixedSizeCollection + extends AbstractFixedSizeCollection< + ListBlurbsRequest, + ListBlurbsResponse, + Blurb, + ListBlurbsPage, + ListBlurbsFixedSizeCollection> { + + private ListBlurbsFixedSizeCollection(List pages, int collectionSize) { + super(pages, collectionSize); + } + + private static ListBlurbsFixedSizeCollection createEmptyCollection() { + return new ListBlurbsFixedSizeCollection(null, 0); + } + + @Override + protected ListBlurbsFixedSizeCollection createCollection( + List pages, int collectionSize) { + return new ListBlurbsFixedSizeCollection(pages, collectionSize); + } + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MessagingClientHttpJsonTest.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MessagingClientHttpJsonTest.java new file mode 100644 index 0000000000..de062e07f3 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MessagingClientHttpJsonTest.java @@ -0,0 +1,1649 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import static com.google.showcase.v1beta1.MessagingClient.ListBlurbsPagedResponse; +import static com.google.showcase.v1beta1.MessagingClient.ListRoomsPagedResponse; + +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.testing.MockHttpService; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ApiException; +import com.google.api.gax.rpc.ApiExceptionFactory; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.testing.FakeStatusCode; +import com.google.common.collect.Lists; +import com.google.longrunning.Operation; +import com.google.protobuf.Any; +import com.google.protobuf.ByteString; +import com.google.protobuf.Empty; +import com.google.protobuf.FieldMask; +import com.google.protobuf.Timestamp; +import com.google.showcase.v1beta1.stub.HttpJsonMessagingStub; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.ExecutionException; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class MessagingClientHttpJsonTest { + private static MockHttpService mockService; + private static MessagingClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonMessagingStub.getMethodDescriptors(), MessagingSettings.getDefaultEndpoint()); + MessagingSettings settings = + MessagingSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + MessagingSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = MessagingClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void createRoomTest() throws Exception { + Room expectedResponse = + Room.newBuilder() + .setName(RoomName.of("[ROOM]").toString()) + .setDisplayName("displayName1714148973") + .setDescription("description-1724546052") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String displayName = "displayName1714148973"; + String description = "description-1724546052"; + + Room actualResponse = client.createRoom(displayName, description); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createRoomExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String displayName = "displayName1714148973"; + String description = "description-1724546052"; + client.createRoom(displayName, description); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getRoomTest() throws Exception { + Room expectedResponse = + Room.newBuilder() + .setName(RoomName.of("[ROOM]").toString()) + .setDisplayName("displayName1714148973") + .setDescription("description-1724546052") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + RoomName name = RoomName.of("[ROOM]"); + + Room actualResponse = client.getRoom(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getRoomExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + RoomName name = RoomName.of("[ROOM]"); + client.getRoom(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getRoomTest2() throws Exception { + Room expectedResponse = + Room.newBuilder() + .setName(RoomName.of("[ROOM]").toString()) + .setDisplayName("displayName1714148973") + .setDescription("description-1724546052") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "rooms/room-472"; + + Room actualResponse = client.getRoom(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getRoomExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "rooms/room-472"; + client.getRoom(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateRoomTest() throws Exception { + Room expectedResponse = + Room.newBuilder() + .setName(RoomName.of("[ROOM]").toString()) + .setDisplayName("displayName1714148973") + .setDescription("description-1724546052") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + UpdateRoomRequest request = + UpdateRoomRequest.newBuilder() + .setRoom( + Room.newBuilder() + .setName(RoomName.of("[ROOM]").toString()) + .setDisplayName("displayName1714148973") + .setDescription("description-1724546052") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + + Room actualResponse = client.updateRoom(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void updateRoomExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + UpdateRoomRequest request = + UpdateRoomRequest.newBuilder() + .setRoom( + Room.newBuilder() + .setName(RoomName.of("[ROOM]").toString()) + .setDisplayName("displayName1714148973") + .setDescription("description-1724546052") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + client.updateRoom(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteRoomTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + RoomName name = RoomName.of("[ROOM]"); + + client.deleteRoom(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteRoomExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + RoomName name = RoomName.of("[ROOM]"); + client.deleteRoom(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteRoomTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + String name = "rooms/room-472"; + + client.deleteRoom(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteRoomExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "rooms/room-472"; + client.deleteRoom(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listRoomsTest() throws Exception { + Room responsesElement = Room.newBuilder().build(); + ListRoomsResponse expectedResponse = + ListRoomsResponse.newBuilder() + .setNextPageToken("") + .addAllRooms(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + ListRoomsRequest request = + ListRoomsRequest.newBuilder() + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + + ListRoomsPagedResponse pagedListResponse = client.listRooms(request); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getRoomsList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listRoomsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ListRoomsRequest request = + ListRoomsRequest.newBuilder() + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + client.listRooms(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createBlurbTest() throws Exception { + Blurb expectedResponse = + Blurb.newBuilder() + .setName( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setUser(UserName.of("[USER]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + ProfileName parent = ProfileName.of("[USER]"); + UserName user = UserName.of("[USER]"); + ByteString image = ByteString.EMPTY; + + Blurb actualResponse = client.createBlurb(parent, user, image); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createBlurbExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ProfileName parent = ProfileName.of("[USER]"); + UserName user = UserName.of("[USER]"); + ByteString image = ByteString.EMPTY; + client.createBlurb(parent, user, image); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createBlurbTest2() throws Exception { + Blurb expectedResponse = + Blurb.newBuilder() + .setName( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setUser(UserName.of("[USER]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + ProfileName parent = ProfileName.of("[USER]"); + UserName user = UserName.of("[USER]"); + String text = "text3556653"; + + Blurb actualResponse = client.createBlurb(parent, user, text); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createBlurbExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ProfileName parent = ProfileName.of("[USER]"); + UserName user = UserName.of("[USER]"); + String text = "text3556653"; + client.createBlurb(parent, user, text); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createBlurbTest3() throws Exception { + Blurb expectedResponse = + Blurb.newBuilder() + .setName( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setUser(UserName.of("[USER]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + ProfileName parent = ProfileName.of("[USER]"); + String user = "user3599307"; + ByteString image = ByteString.EMPTY; + + Blurb actualResponse = client.createBlurb(parent, user, image); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createBlurbExceptionTest3() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ProfileName parent = ProfileName.of("[USER]"); + String user = "user3599307"; + ByteString image = ByteString.EMPTY; + client.createBlurb(parent, user, image); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createBlurbTest4() throws Exception { + Blurb expectedResponse = + Blurb.newBuilder() + .setName( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setUser(UserName.of("[USER]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + ProfileName parent = ProfileName.of("[USER]"); + String user = "user3599307"; + String text = "text3556653"; + + Blurb actualResponse = client.createBlurb(parent, user, text); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createBlurbExceptionTest4() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ProfileName parent = ProfileName.of("[USER]"); + String user = "user3599307"; + String text = "text3556653"; + client.createBlurb(parent, user, text); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createBlurbTest5() throws Exception { + Blurb expectedResponse = + Blurb.newBuilder() + .setName( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setUser(UserName.of("[USER]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + RoomName parent = RoomName.of("[ROOM]"); + UserName user = UserName.of("[USER]"); + ByteString image = ByteString.EMPTY; + + Blurb actualResponse = client.createBlurb(parent, user, image); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createBlurbExceptionTest5() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + RoomName parent = RoomName.of("[ROOM]"); + UserName user = UserName.of("[USER]"); + ByteString image = ByteString.EMPTY; + client.createBlurb(parent, user, image); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createBlurbTest6() throws Exception { + Blurb expectedResponse = + Blurb.newBuilder() + .setName( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setUser(UserName.of("[USER]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + RoomName parent = RoomName.of("[ROOM]"); + UserName user = UserName.of("[USER]"); + String text = "text3556653"; + + Blurb actualResponse = client.createBlurb(parent, user, text); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createBlurbExceptionTest6() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + RoomName parent = RoomName.of("[ROOM]"); + UserName user = UserName.of("[USER]"); + String text = "text3556653"; + client.createBlurb(parent, user, text); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createBlurbTest7() throws Exception { + Blurb expectedResponse = + Blurb.newBuilder() + .setName( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setUser(UserName.of("[USER]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + RoomName parent = RoomName.of("[ROOM]"); + String user = "user3599307"; + ByteString image = ByteString.EMPTY; + + Blurb actualResponse = client.createBlurb(parent, user, image); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createBlurbExceptionTest7() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + RoomName parent = RoomName.of("[ROOM]"); + String user = "user3599307"; + ByteString image = ByteString.EMPTY; + client.createBlurb(parent, user, image); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createBlurbTest8() throws Exception { + Blurb expectedResponse = + Blurb.newBuilder() + .setName( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setUser(UserName.of("[USER]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + RoomName parent = RoomName.of("[ROOM]"); + String user = "user3599307"; + String text = "text3556653"; + + Blurb actualResponse = client.createBlurb(parent, user, text); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createBlurbExceptionTest8() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + RoomName parent = RoomName.of("[ROOM]"); + String user = "user3599307"; + String text = "text3556653"; + client.createBlurb(parent, user, text); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createBlurbTest9() throws Exception { + Blurb expectedResponse = + Blurb.newBuilder() + .setName( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setUser(UserName.of("[USER]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "rooms/room-4889"; + UserName user = UserName.of("[USER]"); + ByteString image = ByteString.EMPTY; + + Blurb actualResponse = client.createBlurb(parent, user, image); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createBlurbExceptionTest9() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "rooms/room-4889"; + UserName user = UserName.of("[USER]"); + ByteString image = ByteString.EMPTY; + client.createBlurb(parent, user, image); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createBlurbTest10() throws Exception { + Blurb expectedResponse = + Blurb.newBuilder() + .setName( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setUser(UserName.of("[USER]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "rooms/room-4889"; + UserName user = UserName.of("[USER]"); + String text = "text3556653"; + + Blurb actualResponse = client.createBlurb(parent, user, text); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createBlurbExceptionTest10() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "rooms/room-4889"; + UserName user = UserName.of("[USER]"); + String text = "text3556653"; + client.createBlurb(parent, user, text); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createBlurbTest11() throws Exception { + Blurb expectedResponse = + Blurb.newBuilder() + .setName( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setUser(UserName.of("[USER]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "rooms/room-4889"; + String user = "user3599307"; + ByteString image = ByteString.EMPTY; + + Blurb actualResponse = client.createBlurb(parent, user, image); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createBlurbExceptionTest11() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "rooms/room-4889"; + String user = "user3599307"; + ByteString image = ByteString.EMPTY; + client.createBlurb(parent, user, image); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createBlurbTest12() throws Exception { + Blurb expectedResponse = + Blurb.newBuilder() + .setName( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setUser(UserName.of("[USER]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "rooms/room-4889"; + String user = "user3599307"; + String text = "text3556653"; + + Blurb actualResponse = client.createBlurb(parent, user, text); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createBlurbExceptionTest12() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "rooms/room-4889"; + String user = "user3599307"; + String text = "text3556653"; + client.createBlurb(parent, user, text); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getBlurbTest() throws Exception { + Blurb expectedResponse = + Blurb.newBuilder() + .setName(BlurbName.ofRoomBlurbName("[ROOM]", "[BLURB]").toString()) + .setUser(UserName.of("[USER]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + BlurbName name = BlurbName.ofRoomBlurbName("[ROOM]", "[BLURB]"); + + Blurb actualResponse = client.getBlurb(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getBlurbExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + BlurbName name = BlurbName.ofRoomBlurbName("[ROOM]", "[BLURB]"); + client.getBlurb(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getBlurbTest2() throws Exception { + Blurb expectedResponse = + Blurb.newBuilder() + .setName(BlurbName.ofRoomBlurbName("[ROOM]", "[BLURB]").toString()) + .setUser(UserName.of("[USER]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "rooms/room-9094/blurbs/blurb-9094"; + + Blurb actualResponse = client.getBlurb(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getBlurbExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "rooms/room-9094/blurbs/blurb-9094"; + client.getBlurb(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateBlurbTest() throws Exception { + Blurb expectedResponse = + Blurb.newBuilder() + .setName(BlurbName.ofRoomBlurbName("[ROOM]", "[BLURB]").toString()) + .setUser(UserName.of("[USER]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + UpdateBlurbRequest request = + UpdateBlurbRequest.newBuilder() + .setBlurb( + Blurb.newBuilder() + .setName( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setUser(UserName.of("[USER]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + + Blurb actualResponse = client.updateBlurb(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void updateBlurbExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + UpdateBlurbRequest request = + UpdateBlurbRequest.newBuilder() + .setBlurb( + Blurb.newBuilder() + .setName( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setUser(UserName.of("[USER]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + client.updateBlurb(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteBlurbTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + BlurbName name = BlurbName.ofRoomBlurbName("[ROOM]", "[BLURB]"); + + client.deleteBlurb(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteBlurbExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + BlurbName name = BlurbName.ofRoomBlurbName("[ROOM]", "[BLURB]"); + client.deleteBlurb(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteBlurbTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + String name = "rooms/room-9094/blurbs/blurb-9094"; + + client.deleteBlurb(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteBlurbExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "rooms/room-9094/blurbs/blurb-9094"; + client.deleteBlurb(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listBlurbsTest() throws Exception { + Blurb responsesElement = Blurb.newBuilder().build(); + ListBlurbsResponse expectedResponse = + ListBlurbsResponse.newBuilder() + .setNextPageToken("") + .addAllBlurbs(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + ProfileName parent = ProfileName.of("[USER]"); + + ListBlurbsPagedResponse pagedListResponse = client.listBlurbs(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getBlurbsList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listBlurbsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ProfileName parent = ProfileName.of("[USER]"); + client.listBlurbs(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listBlurbsTest2() throws Exception { + Blurb responsesElement = Blurb.newBuilder().build(); + ListBlurbsResponse expectedResponse = + ListBlurbsResponse.newBuilder() + .setNextPageToken("") + .addAllBlurbs(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + RoomName parent = RoomName.of("[ROOM]"); + + ListBlurbsPagedResponse pagedListResponse = client.listBlurbs(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getBlurbsList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listBlurbsExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + RoomName parent = RoomName.of("[ROOM]"); + client.listBlurbs(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listBlurbsTest3() throws Exception { + Blurb responsesElement = Blurb.newBuilder().build(); + ListBlurbsResponse expectedResponse = + ListBlurbsResponse.newBuilder() + .setNextPageToken("") + .addAllBlurbs(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "rooms/room-4889"; + + ListBlurbsPagedResponse pagedListResponse = client.listBlurbs(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getBlurbsList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listBlurbsExceptionTest3() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "rooms/room-4889"; + client.listBlurbs(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void searchBlurbsTest() throws Exception { + SearchBlurbsResponse expectedResponse = + SearchBlurbsResponse.newBuilder() + .addAllBlurbs(new ArrayList()) + .setNextPageToken("nextPageToken-1386094857") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("searchBlurbsTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + ProfileName parent = ProfileName.of("[USER]"); + String query = "query107944136"; + + SearchBlurbsResponse actualResponse = client.searchBlurbsAsync(parent, query).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void searchBlurbsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ProfileName parent = ProfileName.of("[USER]"); + String query = "query107944136"; + client.searchBlurbsAsync(parent, query).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void searchBlurbsTest2() throws Exception { + SearchBlurbsResponse expectedResponse = + SearchBlurbsResponse.newBuilder() + .addAllBlurbs(new ArrayList()) + .setNextPageToken("nextPageToken-1386094857") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("searchBlurbsTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + RoomName parent = RoomName.of("[ROOM]"); + String query = "query107944136"; + + SearchBlurbsResponse actualResponse = client.searchBlurbsAsync(parent, query).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void searchBlurbsExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + RoomName parent = RoomName.of("[ROOM]"); + String query = "query107944136"; + client.searchBlurbsAsync(parent, query).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void searchBlurbsTest3() throws Exception { + SearchBlurbsResponse expectedResponse = + SearchBlurbsResponse.newBuilder() + .addAllBlurbs(new ArrayList()) + .setNextPageToken("nextPageToken-1386094857") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("searchBlurbsTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String parent = "rooms/room-4889"; + String query = "query107944136"; + + SearchBlurbsResponse actualResponse = client.searchBlurbsAsync(parent, query).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void searchBlurbsExceptionTest3() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "rooms/room-4889"; + String query = "query107944136"; + client.searchBlurbsAsync(parent, query).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void streamBlurbsTest() throws Exception {} + + @Test + public void streamBlurbsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + } + + @Test + public void sendBlurbsUnsupportedMethodTest() throws Exception { + // The sendBlurbs() method is not supported in REST transport. + // This empty test is generated for technical reasons. + } + + @Test + public void connectUnsupportedMethodTest() throws Exception { + // The connect() method is not supported in REST transport. + // This empty test is generated for technical reasons. + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MessagingClientTest.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MessagingClientTest.java new file mode 100644 index 0000000000..0f4e531141 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MessagingClientTest.java @@ -0,0 +1,1614 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import static com.google.showcase.v1beta1.MessagingClient.ListBlurbsPagedResponse; +import static com.google.showcase.v1beta1.MessagingClient.ListRoomsPagedResponse; + +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.grpc.GaxGrpcProperties; +import com.google.api.gax.grpc.testing.LocalChannelProvider; +import com.google.api.gax.grpc.testing.MockGrpcService; +import com.google.api.gax.grpc.testing.MockServiceHelper; +import com.google.api.gax.grpc.testing.MockStreamObserver; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ApiStreamObserver; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StatusCode; +import com.google.common.collect.Lists; +import com.google.longrunning.Operation; +import com.google.protobuf.AbstractMessage; +import com.google.protobuf.Any; +import com.google.protobuf.ByteString; +import com.google.protobuf.Empty; +import com.google.protobuf.FieldMask; +import com.google.protobuf.Timestamp; +import io.grpc.StatusRuntimeException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.ExecutionException; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class MessagingClientTest { + private static MockMessaging mockMessaging; + private static MockServiceHelper mockServiceHelper; + private LocalChannelProvider channelProvider; + private MessagingClient client; + + @BeforeClass + public static void startStaticServer() { + mockMessaging = new MockMessaging(); + mockServiceHelper = + new MockServiceHelper( + UUID.randomUUID().toString(), Arrays.asList(mockMessaging)); + mockServiceHelper.start(); + } + + @AfterClass + public static void stopServer() { + mockServiceHelper.stop(); + } + + @Before + public void setUp() throws IOException { + mockServiceHelper.reset(); + channelProvider = mockServiceHelper.createChannelProvider(); + MessagingSettings settings = + MessagingSettings.newBuilder() + .setTransportChannelProvider(channelProvider) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = MessagingClient.create(settings); + } + + @After + public void tearDown() throws Exception { + client.close(); + } + + @Test + public void createRoomTest() throws Exception { + Room expectedResponse = + Room.newBuilder() + .setName(RoomName.of("[ROOM]").toString()) + .setDisplayName("displayName1714148973") + .setDescription("description-1724546052") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockMessaging.addResponse(expectedResponse); + + String displayName = "displayName1714148973"; + String description = "description-1724546052"; + + Room actualResponse = client.createRoom(displayName, description); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockMessaging.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CreateRoomRequest actualRequest = ((CreateRoomRequest) actualRequests.get(0)); + + Assert.assertEquals(displayName, actualRequest.getRoom().getDisplayName()); + Assert.assertEquals(description, actualRequest.getRoom().getDescription()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void createRoomExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMessaging.addException(exception); + + try { + String displayName = "displayName1714148973"; + String description = "description-1724546052"; + client.createRoom(displayName, description); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getRoomTest() throws Exception { + Room expectedResponse = + Room.newBuilder() + .setName(RoomName.of("[ROOM]").toString()) + .setDisplayName("displayName1714148973") + .setDescription("description-1724546052") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockMessaging.addResponse(expectedResponse); + + RoomName name = RoomName.of("[ROOM]"); + + Room actualResponse = client.getRoom(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockMessaging.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + GetRoomRequest actualRequest = ((GetRoomRequest) actualRequests.get(0)); + + Assert.assertEquals(name.toString(), actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void getRoomExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMessaging.addException(exception); + + try { + RoomName name = RoomName.of("[ROOM]"); + client.getRoom(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getRoomTest2() throws Exception { + Room expectedResponse = + Room.newBuilder() + .setName(RoomName.of("[ROOM]").toString()) + .setDisplayName("displayName1714148973") + .setDescription("description-1724546052") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockMessaging.addResponse(expectedResponse); + + String name = "name3373707"; + + Room actualResponse = client.getRoom(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockMessaging.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + GetRoomRequest actualRequest = ((GetRoomRequest) actualRequests.get(0)); + + Assert.assertEquals(name, actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void getRoomExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMessaging.addException(exception); + + try { + String name = "name3373707"; + client.getRoom(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateRoomTest() throws Exception { + Room expectedResponse = + Room.newBuilder() + .setName(RoomName.of("[ROOM]").toString()) + .setDisplayName("displayName1714148973") + .setDescription("description-1724546052") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockMessaging.addResponse(expectedResponse); + + UpdateRoomRequest request = + UpdateRoomRequest.newBuilder() + .setRoom(Room.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + + Room actualResponse = client.updateRoom(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockMessaging.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + UpdateRoomRequest actualRequest = ((UpdateRoomRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getRoom(), actualRequest.getRoom()); + Assert.assertEquals(request.getUpdateMask(), actualRequest.getUpdateMask()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void updateRoomExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMessaging.addException(exception); + + try { + UpdateRoomRequest request = + UpdateRoomRequest.newBuilder() + .setRoom(Room.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + client.updateRoom(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteRoomTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockMessaging.addResponse(expectedResponse); + + RoomName name = RoomName.of("[ROOM]"); + + client.deleteRoom(name); + + List actualRequests = mockMessaging.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + DeleteRoomRequest actualRequest = ((DeleteRoomRequest) actualRequests.get(0)); + + Assert.assertEquals(name.toString(), actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void deleteRoomExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMessaging.addException(exception); + + try { + RoomName name = RoomName.of("[ROOM]"); + client.deleteRoom(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteRoomTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockMessaging.addResponse(expectedResponse); + + String name = "name3373707"; + + client.deleteRoom(name); + + List actualRequests = mockMessaging.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + DeleteRoomRequest actualRequest = ((DeleteRoomRequest) actualRequests.get(0)); + + Assert.assertEquals(name, actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void deleteRoomExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMessaging.addException(exception); + + try { + String name = "name3373707"; + client.deleteRoom(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listRoomsTest() throws Exception { + Room responsesElement = Room.newBuilder().build(); + ListRoomsResponse expectedResponse = + ListRoomsResponse.newBuilder() + .setNextPageToken("") + .addAllRooms(Arrays.asList(responsesElement)) + .build(); + mockMessaging.addResponse(expectedResponse); + + ListRoomsRequest request = + ListRoomsRequest.newBuilder() + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + + ListRoomsPagedResponse pagedListResponse = client.listRooms(request); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getRoomsList().get(0), resources.get(0)); + + List actualRequests = mockMessaging.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListRoomsRequest actualRequest = ((ListRoomsRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getPageSize(), actualRequest.getPageSize()); + Assert.assertEquals(request.getPageToken(), actualRequest.getPageToken()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void listRoomsExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMessaging.addException(exception); + + try { + ListRoomsRequest request = + ListRoomsRequest.newBuilder() + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + client.listRooms(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createBlurbTest() throws Exception { + Blurb expectedResponse = + Blurb.newBuilder() + .setName( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setUser(UserName.of("[USER]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockMessaging.addResponse(expectedResponse); + + ProfileName parent = ProfileName.of("[USER]"); + UserName user = UserName.of("[USER]"); + ByteString image = ByteString.EMPTY; + + Blurb actualResponse = client.createBlurb(parent, user, image); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockMessaging.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CreateBlurbRequest actualRequest = ((CreateBlurbRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertEquals(user.toString(), actualRequest.getBlurb().getUser()); + Assert.assertEquals(image, actualRequest.getBlurb().getImage()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void createBlurbExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMessaging.addException(exception); + + try { + ProfileName parent = ProfileName.of("[USER]"); + UserName user = UserName.of("[USER]"); + ByteString image = ByteString.EMPTY; + client.createBlurb(parent, user, image); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createBlurbTest2() throws Exception { + Blurb expectedResponse = + Blurb.newBuilder() + .setName( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setUser(UserName.of("[USER]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockMessaging.addResponse(expectedResponse); + + ProfileName parent = ProfileName.of("[USER]"); + UserName user = UserName.of("[USER]"); + String text = "text3556653"; + + Blurb actualResponse = client.createBlurb(parent, user, text); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockMessaging.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CreateBlurbRequest actualRequest = ((CreateBlurbRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertEquals(user.toString(), actualRequest.getBlurb().getUser()); + Assert.assertEquals(text, actualRequest.getBlurb().getText()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void createBlurbExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMessaging.addException(exception); + + try { + ProfileName parent = ProfileName.of("[USER]"); + UserName user = UserName.of("[USER]"); + String text = "text3556653"; + client.createBlurb(parent, user, text); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createBlurbTest3() throws Exception { + Blurb expectedResponse = + Blurb.newBuilder() + .setName( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setUser(UserName.of("[USER]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockMessaging.addResponse(expectedResponse); + + ProfileName parent = ProfileName.of("[USER]"); + String user = "user3599307"; + ByteString image = ByteString.EMPTY; + + Blurb actualResponse = client.createBlurb(parent, user, image); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockMessaging.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CreateBlurbRequest actualRequest = ((CreateBlurbRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertEquals(user, actualRequest.getBlurb().getUser()); + Assert.assertEquals(image, actualRequest.getBlurb().getImage()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void createBlurbExceptionTest3() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMessaging.addException(exception); + + try { + ProfileName parent = ProfileName.of("[USER]"); + String user = "user3599307"; + ByteString image = ByteString.EMPTY; + client.createBlurb(parent, user, image); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createBlurbTest4() throws Exception { + Blurb expectedResponse = + Blurb.newBuilder() + .setName( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setUser(UserName.of("[USER]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockMessaging.addResponse(expectedResponse); + + ProfileName parent = ProfileName.of("[USER]"); + String user = "user3599307"; + String text = "text3556653"; + + Blurb actualResponse = client.createBlurb(parent, user, text); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockMessaging.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CreateBlurbRequest actualRequest = ((CreateBlurbRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertEquals(user, actualRequest.getBlurb().getUser()); + Assert.assertEquals(text, actualRequest.getBlurb().getText()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void createBlurbExceptionTest4() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMessaging.addException(exception); + + try { + ProfileName parent = ProfileName.of("[USER]"); + String user = "user3599307"; + String text = "text3556653"; + client.createBlurb(parent, user, text); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createBlurbTest5() throws Exception { + Blurb expectedResponse = + Blurb.newBuilder() + .setName( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setUser(UserName.of("[USER]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockMessaging.addResponse(expectedResponse); + + RoomName parent = RoomName.of("[ROOM]"); + UserName user = UserName.of("[USER]"); + ByteString image = ByteString.EMPTY; + + Blurb actualResponse = client.createBlurb(parent, user, image); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockMessaging.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CreateBlurbRequest actualRequest = ((CreateBlurbRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertEquals(user.toString(), actualRequest.getBlurb().getUser()); + Assert.assertEquals(image, actualRequest.getBlurb().getImage()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void createBlurbExceptionTest5() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMessaging.addException(exception); + + try { + RoomName parent = RoomName.of("[ROOM]"); + UserName user = UserName.of("[USER]"); + ByteString image = ByteString.EMPTY; + client.createBlurb(parent, user, image); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createBlurbTest6() throws Exception { + Blurb expectedResponse = + Blurb.newBuilder() + .setName( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setUser(UserName.of("[USER]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockMessaging.addResponse(expectedResponse); + + RoomName parent = RoomName.of("[ROOM]"); + UserName user = UserName.of("[USER]"); + String text = "text3556653"; + + Blurb actualResponse = client.createBlurb(parent, user, text); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockMessaging.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CreateBlurbRequest actualRequest = ((CreateBlurbRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertEquals(user.toString(), actualRequest.getBlurb().getUser()); + Assert.assertEquals(text, actualRequest.getBlurb().getText()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void createBlurbExceptionTest6() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMessaging.addException(exception); + + try { + RoomName parent = RoomName.of("[ROOM]"); + UserName user = UserName.of("[USER]"); + String text = "text3556653"; + client.createBlurb(parent, user, text); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createBlurbTest7() throws Exception { + Blurb expectedResponse = + Blurb.newBuilder() + .setName( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setUser(UserName.of("[USER]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockMessaging.addResponse(expectedResponse); + + RoomName parent = RoomName.of("[ROOM]"); + String user = "user3599307"; + ByteString image = ByteString.EMPTY; + + Blurb actualResponse = client.createBlurb(parent, user, image); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockMessaging.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CreateBlurbRequest actualRequest = ((CreateBlurbRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertEquals(user, actualRequest.getBlurb().getUser()); + Assert.assertEquals(image, actualRequest.getBlurb().getImage()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void createBlurbExceptionTest7() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMessaging.addException(exception); + + try { + RoomName parent = RoomName.of("[ROOM]"); + String user = "user3599307"; + ByteString image = ByteString.EMPTY; + client.createBlurb(parent, user, image); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createBlurbTest8() throws Exception { + Blurb expectedResponse = + Blurb.newBuilder() + .setName( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setUser(UserName.of("[USER]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockMessaging.addResponse(expectedResponse); + + RoomName parent = RoomName.of("[ROOM]"); + String user = "user3599307"; + String text = "text3556653"; + + Blurb actualResponse = client.createBlurb(parent, user, text); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockMessaging.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CreateBlurbRequest actualRequest = ((CreateBlurbRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertEquals(user, actualRequest.getBlurb().getUser()); + Assert.assertEquals(text, actualRequest.getBlurb().getText()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void createBlurbExceptionTest8() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMessaging.addException(exception); + + try { + RoomName parent = RoomName.of("[ROOM]"); + String user = "user3599307"; + String text = "text3556653"; + client.createBlurb(parent, user, text); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createBlurbTest9() throws Exception { + Blurb expectedResponse = + Blurb.newBuilder() + .setName( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setUser(UserName.of("[USER]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockMessaging.addResponse(expectedResponse); + + String parent = "parent-995424086"; + UserName user = UserName.of("[USER]"); + ByteString image = ByteString.EMPTY; + + Blurb actualResponse = client.createBlurb(parent, user, image); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockMessaging.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CreateBlurbRequest actualRequest = ((CreateBlurbRequest) actualRequests.get(0)); + + Assert.assertEquals(parent, actualRequest.getParent()); + Assert.assertEquals(user.toString(), actualRequest.getBlurb().getUser()); + Assert.assertEquals(image, actualRequest.getBlurb().getImage()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void createBlurbExceptionTest9() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMessaging.addException(exception); + + try { + String parent = "parent-995424086"; + UserName user = UserName.of("[USER]"); + ByteString image = ByteString.EMPTY; + client.createBlurb(parent, user, image); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createBlurbTest10() throws Exception { + Blurb expectedResponse = + Blurb.newBuilder() + .setName( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setUser(UserName.of("[USER]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockMessaging.addResponse(expectedResponse); + + String parent = "parent-995424086"; + UserName user = UserName.of("[USER]"); + String text = "text3556653"; + + Blurb actualResponse = client.createBlurb(parent, user, text); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockMessaging.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CreateBlurbRequest actualRequest = ((CreateBlurbRequest) actualRequests.get(0)); + + Assert.assertEquals(parent, actualRequest.getParent()); + Assert.assertEquals(user.toString(), actualRequest.getBlurb().getUser()); + Assert.assertEquals(text, actualRequest.getBlurb().getText()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void createBlurbExceptionTest10() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMessaging.addException(exception); + + try { + String parent = "parent-995424086"; + UserName user = UserName.of("[USER]"); + String text = "text3556653"; + client.createBlurb(parent, user, text); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createBlurbTest11() throws Exception { + Blurb expectedResponse = + Blurb.newBuilder() + .setName( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setUser(UserName.of("[USER]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockMessaging.addResponse(expectedResponse); + + String parent = "parent-995424086"; + String user = "user3599307"; + ByteString image = ByteString.EMPTY; + + Blurb actualResponse = client.createBlurb(parent, user, image); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockMessaging.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CreateBlurbRequest actualRequest = ((CreateBlurbRequest) actualRequests.get(0)); + + Assert.assertEquals(parent, actualRequest.getParent()); + Assert.assertEquals(user, actualRequest.getBlurb().getUser()); + Assert.assertEquals(image, actualRequest.getBlurb().getImage()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void createBlurbExceptionTest11() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMessaging.addException(exception); + + try { + String parent = "parent-995424086"; + String user = "user3599307"; + ByteString image = ByteString.EMPTY; + client.createBlurb(parent, user, image); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createBlurbTest12() throws Exception { + Blurb expectedResponse = + Blurb.newBuilder() + .setName( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setUser(UserName.of("[USER]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockMessaging.addResponse(expectedResponse); + + String parent = "parent-995424086"; + String user = "user3599307"; + String text = "text3556653"; + + Blurb actualResponse = client.createBlurb(parent, user, text); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockMessaging.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CreateBlurbRequest actualRequest = ((CreateBlurbRequest) actualRequests.get(0)); + + Assert.assertEquals(parent, actualRequest.getParent()); + Assert.assertEquals(user, actualRequest.getBlurb().getUser()); + Assert.assertEquals(text, actualRequest.getBlurb().getText()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void createBlurbExceptionTest12() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMessaging.addException(exception); + + try { + String parent = "parent-995424086"; + String user = "user3599307"; + String text = "text3556653"; + client.createBlurb(parent, user, text); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getBlurbTest() throws Exception { + Blurb expectedResponse = + Blurb.newBuilder() + .setName(BlurbName.ofRoomBlurbName("[ROOM]", "[BLURB]").toString()) + .setUser(UserName.of("[USER]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockMessaging.addResponse(expectedResponse); + + BlurbName name = BlurbName.ofRoomBlurbName("[ROOM]", "[BLURB]"); + + Blurb actualResponse = client.getBlurb(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockMessaging.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + GetBlurbRequest actualRequest = ((GetBlurbRequest) actualRequests.get(0)); + + Assert.assertEquals(name.toString(), actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void getBlurbExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMessaging.addException(exception); + + try { + BlurbName name = BlurbName.ofRoomBlurbName("[ROOM]", "[BLURB]"); + client.getBlurb(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getBlurbTest2() throws Exception { + Blurb expectedResponse = + Blurb.newBuilder() + .setName(BlurbName.ofRoomBlurbName("[ROOM]", "[BLURB]").toString()) + .setUser(UserName.of("[USER]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockMessaging.addResponse(expectedResponse); + + String name = "name3373707"; + + Blurb actualResponse = client.getBlurb(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockMessaging.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + GetBlurbRequest actualRequest = ((GetBlurbRequest) actualRequests.get(0)); + + Assert.assertEquals(name, actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void getBlurbExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMessaging.addException(exception); + + try { + String name = "name3373707"; + client.getBlurb(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateBlurbTest() throws Exception { + Blurb expectedResponse = + Blurb.newBuilder() + .setName(BlurbName.ofRoomBlurbName("[ROOM]", "[BLURB]").toString()) + .setUser(UserName.of("[USER]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockMessaging.addResponse(expectedResponse); + + UpdateBlurbRequest request = + UpdateBlurbRequest.newBuilder() + .setBlurb(Blurb.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + + Blurb actualResponse = client.updateBlurb(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockMessaging.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + UpdateBlurbRequest actualRequest = ((UpdateBlurbRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getBlurb(), actualRequest.getBlurb()); + Assert.assertEquals(request.getUpdateMask(), actualRequest.getUpdateMask()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void updateBlurbExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMessaging.addException(exception); + + try { + UpdateBlurbRequest request = + UpdateBlurbRequest.newBuilder() + .setBlurb(Blurb.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + client.updateBlurb(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteBlurbTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockMessaging.addResponse(expectedResponse); + + BlurbName name = BlurbName.ofRoomBlurbName("[ROOM]", "[BLURB]"); + + client.deleteBlurb(name); + + List actualRequests = mockMessaging.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + DeleteBlurbRequest actualRequest = ((DeleteBlurbRequest) actualRequests.get(0)); + + Assert.assertEquals(name.toString(), actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void deleteBlurbExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMessaging.addException(exception); + + try { + BlurbName name = BlurbName.ofRoomBlurbName("[ROOM]", "[BLURB]"); + client.deleteBlurb(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteBlurbTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockMessaging.addResponse(expectedResponse); + + String name = "name3373707"; + + client.deleteBlurb(name); + + List actualRequests = mockMessaging.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + DeleteBlurbRequest actualRequest = ((DeleteBlurbRequest) actualRequests.get(0)); + + Assert.assertEquals(name, actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void deleteBlurbExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMessaging.addException(exception); + + try { + String name = "name3373707"; + client.deleteBlurb(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listBlurbsTest() throws Exception { + Blurb responsesElement = Blurb.newBuilder().build(); + ListBlurbsResponse expectedResponse = + ListBlurbsResponse.newBuilder() + .setNextPageToken("") + .addAllBlurbs(Arrays.asList(responsesElement)) + .build(); + mockMessaging.addResponse(expectedResponse); + + ProfileName parent = ProfileName.of("[USER]"); + + ListBlurbsPagedResponse pagedListResponse = client.listBlurbs(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getBlurbsList().get(0), resources.get(0)); + + List actualRequests = mockMessaging.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListBlurbsRequest actualRequest = ((ListBlurbsRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void listBlurbsExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMessaging.addException(exception); + + try { + ProfileName parent = ProfileName.of("[USER]"); + client.listBlurbs(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listBlurbsTest2() throws Exception { + Blurb responsesElement = Blurb.newBuilder().build(); + ListBlurbsResponse expectedResponse = + ListBlurbsResponse.newBuilder() + .setNextPageToken("") + .addAllBlurbs(Arrays.asList(responsesElement)) + .build(); + mockMessaging.addResponse(expectedResponse); + + RoomName parent = RoomName.of("[ROOM]"); + + ListBlurbsPagedResponse pagedListResponse = client.listBlurbs(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getBlurbsList().get(0), resources.get(0)); + + List actualRequests = mockMessaging.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListBlurbsRequest actualRequest = ((ListBlurbsRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void listBlurbsExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMessaging.addException(exception); + + try { + RoomName parent = RoomName.of("[ROOM]"); + client.listBlurbs(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listBlurbsTest3() throws Exception { + Blurb responsesElement = Blurb.newBuilder().build(); + ListBlurbsResponse expectedResponse = + ListBlurbsResponse.newBuilder() + .setNextPageToken("") + .addAllBlurbs(Arrays.asList(responsesElement)) + .build(); + mockMessaging.addResponse(expectedResponse); + + String parent = "parent-995424086"; + + ListBlurbsPagedResponse pagedListResponse = client.listBlurbs(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getBlurbsList().get(0), resources.get(0)); + + List actualRequests = mockMessaging.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListBlurbsRequest actualRequest = ((ListBlurbsRequest) actualRequests.get(0)); + + Assert.assertEquals(parent, actualRequest.getParent()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void listBlurbsExceptionTest3() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMessaging.addException(exception); + + try { + String parent = "parent-995424086"; + client.listBlurbs(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void searchBlurbsTest() throws Exception { + SearchBlurbsResponse expectedResponse = + SearchBlurbsResponse.newBuilder() + .addAllBlurbs(new ArrayList()) + .setNextPageToken("nextPageToken-1386094857") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("searchBlurbsTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockMessaging.addResponse(resultOperation); + + ProfileName parent = ProfileName.of("[USER]"); + String query = "query107944136"; + + SearchBlurbsResponse actualResponse = client.searchBlurbsAsync(parent, query).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockMessaging.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + SearchBlurbsRequest actualRequest = ((SearchBlurbsRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertEquals(query, actualRequest.getQuery()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void searchBlurbsExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMessaging.addException(exception); + + try { + ProfileName parent = ProfileName.of("[USER]"); + String query = "query107944136"; + client.searchBlurbsAsync(parent, query).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); + InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); + Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); + } + } + + @Test + public void searchBlurbsTest2() throws Exception { + SearchBlurbsResponse expectedResponse = + SearchBlurbsResponse.newBuilder() + .addAllBlurbs(new ArrayList()) + .setNextPageToken("nextPageToken-1386094857") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("searchBlurbsTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockMessaging.addResponse(resultOperation); + + RoomName parent = RoomName.of("[ROOM]"); + String query = "query107944136"; + + SearchBlurbsResponse actualResponse = client.searchBlurbsAsync(parent, query).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockMessaging.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + SearchBlurbsRequest actualRequest = ((SearchBlurbsRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertEquals(query, actualRequest.getQuery()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void searchBlurbsExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMessaging.addException(exception); + + try { + RoomName parent = RoomName.of("[ROOM]"); + String query = "query107944136"; + client.searchBlurbsAsync(parent, query).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); + InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); + Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); + } + } + + @Test + public void searchBlurbsTest3() throws Exception { + SearchBlurbsResponse expectedResponse = + SearchBlurbsResponse.newBuilder() + .addAllBlurbs(new ArrayList()) + .setNextPageToken("nextPageToken-1386094857") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("searchBlurbsTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockMessaging.addResponse(resultOperation); + + String parent = "parent-995424086"; + String query = "query107944136"; + + SearchBlurbsResponse actualResponse = client.searchBlurbsAsync(parent, query).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockMessaging.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + SearchBlurbsRequest actualRequest = ((SearchBlurbsRequest) actualRequests.get(0)); + + Assert.assertEquals(parent, actualRequest.getParent()); + Assert.assertEquals(query, actualRequest.getQuery()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void searchBlurbsExceptionTest3() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMessaging.addException(exception); + + try { + String parent = "parent-995424086"; + String query = "query107944136"; + client.searchBlurbsAsync(parent, query).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); + InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); + Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); + } + } + + @Test + public void streamBlurbsTest() throws Exception { + StreamBlurbsResponse expectedResponse = + StreamBlurbsResponse.newBuilder().setBlurb(Blurb.newBuilder().build()).build(); + mockMessaging.addResponse(expectedResponse); + StreamBlurbsRequest request = + StreamBlurbsRequest.newBuilder() + .setName(ProfileName.of("[USER]").toString()) + .setExpireTime(Timestamp.newBuilder().build()) + .build(); + + MockStreamObserver responseObserver = new MockStreamObserver<>(); + + ServerStreamingCallable callable = + client.streamBlurbsCallable(); + callable.serverStreamingCall(request, responseObserver); + + List actualResponses = responseObserver.future().get(); + Assert.assertEquals(1, actualResponses.size()); + Assert.assertEquals(expectedResponse, actualResponses.get(0)); + } + + @Test + public void streamBlurbsExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMessaging.addException(exception); + StreamBlurbsRequest request = + StreamBlurbsRequest.newBuilder() + .setName(ProfileName.of("[USER]").toString()) + .setExpireTime(Timestamp.newBuilder().build()) + .build(); + + MockStreamObserver responseObserver = new MockStreamObserver<>(); + + ServerStreamingCallable callable = + client.streamBlurbsCallable(); + callable.serverStreamingCall(request, responseObserver); + + try { + List actualResponses = responseObserver.future().get(); + Assert.fail("No exception thrown"); + } catch (ExecutionException e) { + Assert.assertTrue(e.getCause() instanceof InvalidArgumentException); + InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); + Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); + } + } + + @Test + public void sendBlurbsTest() throws Exception { + SendBlurbsResponse expectedResponse = + SendBlurbsResponse.newBuilder().addAllNames(new ArrayList()).build(); + mockMessaging.addResponse(expectedResponse); + CreateBlurbRequest request = + CreateBlurbRequest.newBuilder() + .setParent(ProfileName.of("[USER]").toString()) + .setBlurb(Blurb.newBuilder().build()) + .build(); + + MockStreamObserver responseObserver = new MockStreamObserver<>(); + + ClientStreamingCallable callable = + client.sendBlurbsCallable(); + ApiStreamObserver requestObserver = + callable.clientStreamingCall(responseObserver); + + requestObserver.onNext(request); + requestObserver.onCompleted(); + + List actualResponses = responseObserver.future().get(); + Assert.assertEquals(1, actualResponses.size()); + Assert.assertEquals(expectedResponse, actualResponses.get(0)); + } + + @Test + public void sendBlurbsExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMessaging.addException(exception); + CreateBlurbRequest request = + CreateBlurbRequest.newBuilder() + .setParent(ProfileName.of("[USER]").toString()) + .setBlurb(Blurb.newBuilder().build()) + .build(); + + MockStreamObserver responseObserver = new MockStreamObserver<>(); + + ClientStreamingCallable callable = + client.sendBlurbsCallable(); + ApiStreamObserver requestObserver = + callable.clientStreamingCall(responseObserver); + + requestObserver.onNext(request); + + try { + List actualResponses = responseObserver.future().get(); + Assert.fail("No exception thrown"); + } catch (ExecutionException e) { + Assert.assertTrue(e.getCause() instanceof InvalidArgumentException); + InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); + Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); + } + } + + @Test + public void connectTest() throws Exception { + StreamBlurbsResponse expectedResponse = + StreamBlurbsResponse.newBuilder().setBlurb(Blurb.newBuilder().build()).build(); + mockMessaging.addResponse(expectedResponse); + ConnectRequest request = ConnectRequest.newBuilder().build(); + + MockStreamObserver responseObserver = new MockStreamObserver<>(); + + BidiStreamingCallable callable = client.connectCallable(); + ApiStreamObserver requestObserver = + callable.bidiStreamingCall(responseObserver); + + requestObserver.onNext(request); + requestObserver.onCompleted(); + + List actualResponses = responseObserver.future().get(); + Assert.assertEquals(1, actualResponses.size()); + Assert.assertEquals(expectedResponse, actualResponses.get(0)); + } + + @Test + public void connectExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMessaging.addException(exception); + ConnectRequest request = ConnectRequest.newBuilder().build(); + + MockStreamObserver responseObserver = new MockStreamObserver<>(); + + BidiStreamingCallable callable = client.connectCallable(); + ApiStreamObserver requestObserver = + callable.bidiStreamingCall(responseObserver); + + requestObserver.onNext(request); + + try { + List actualResponses = responseObserver.future().get(); + Assert.fail("No exception thrown"); + } catch (ExecutionException e) { + Assert.assertTrue(e.getCause() instanceof InvalidArgumentException); + InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); + Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); + } + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MessagingSettings.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MessagingSettings.java new file mode 100644 index 0000000000..2196181ea3 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MessagingSettings.java @@ -0,0 +1,364 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import static com.google.showcase.v1beta1.MessagingClient.ListBlurbsPagedResponse; +import static com.google.showcase.v1beta1.MessagingClient.ListRoomsPagedResponse; + +import com.google.api.core.ApiFunction; +import com.google.api.core.BetaApi; +import com.google.api.gax.core.GoogleCredentialsProvider; +import com.google.api.gax.core.InstantiatingExecutorProvider; +import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientSettings; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.StubSettings; +import com.google.api.gax.rpc.TransportChannelProvider; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.longrunning.Operation; +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.stub.MessagingStubSettings; +import java.io.IOException; +import java.util.List; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * Settings class to configure an instance of {@link MessagingClient}. + * + *

The default instance has everything set to sensible defaults: + * + *

    + *
  • The default service address (localhost) and default port (7469) are used. + *
  • Credentials are acquired automatically through Application Default Credentials. + *
  • Retries are configured for idempotent methods but not for non-idempotent methods. + *
+ * + *

The builder of this class is recursive, so contained classes are themselves builders. When + * build() is called, the tree of builders is called to create the complete settings object. + * + *

For example, to set the total timeout of createRoom to 30 seconds: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * MessagingSettings.Builder messagingSettingsBuilder = MessagingSettings.newBuilder();
+ * messagingSettingsBuilder
+ *     .createRoomSettings()
+ *     .setRetrySettings(
+ *         messagingSettingsBuilder
+ *             .createRoomSettings()
+ *             .getRetrySettings()
+ *             .toBuilder()
+ *             .setTotalTimeout(Duration.ofSeconds(30))
+ *             .build());
+ * MessagingSettings messagingSettings = messagingSettingsBuilder.build();
+ * }
+ */ +@BetaApi +@Generated("by gapic-generator-java") +public class MessagingSettings extends ClientSettings { + + /** Returns the object with the settings used for calls to createRoom. */ + public UnaryCallSettings createRoomSettings() { + return ((MessagingStubSettings) getStubSettings()).createRoomSettings(); + } + + /** Returns the object with the settings used for calls to getRoom. */ + public UnaryCallSettings getRoomSettings() { + return ((MessagingStubSettings) getStubSettings()).getRoomSettings(); + } + + /** Returns the object with the settings used for calls to updateRoom. */ + public UnaryCallSettings updateRoomSettings() { + return ((MessagingStubSettings) getStubSettings()).updateRoomSettings(); + } + + /** Returns the object with the settings used for calls to deleteRoom. */ + public UnaryCallSettings deleteRoomSettings() { + return ((MessagingStubSettings) getStubSettings()).deleteRoomSettings(); + } + + /** Returns the object with the settings used for calls to listRooms. */ + public PagedCallSettings + listRoomsSettings() { + return ((MessagingStubSettings) getStubSettings()).listRoomsSettings(); + } + + /** Returns the object with the settings used for calls to createBlurb. */ + public UnaryCallSettings createBlurbSettings() { + return ((MessagingStubSettings) getStubSettings()).createBlurbSettings(); + } + + /** Returns the object with the settings used for calls to getBlurb. */ + public UnaryCallSettings getBlurbSettings() { + return ((MessagingStubSettings) getStubSettings()).getBlurbSettings(); + } + + /** Returns the object with the settings used for calls to updateBlurb. */ + public UnaryCallSettings updateBlurbSettings() { + return ((MessagingStubSettings) getStubSettings()).updateBlurbSettings(); + } + + /** Returns the object with the settings used for calls to deleteBlurb. */ + public UnaryCallSettings deleteBlurbSettings() { + return ((MessagingStubSettings) getStubSettings()).deleteBlurbSettings(); + } + + /** Returns the object with the settings used for calls to listBlurbs. */ + public PagedCallSettings + listBlurbsSettings() { + return ((MessagingStubSettings) getStubSettings()).listBlurbsSettings(); + } + + /** Returns the object with the settings used for calls to searchBlurbs. */ + public UnaryCallSettings searchBlurbsSettings() { + return ((MessagingStubSettings) getStubSettings()).searchBlurbsSettings(); + } + + /** Returns the object with the settings used for calls to searchBlurbs. */ + public OperationCallSettings + searchBlurbsOperationSettings() { + return ((MessagingStubSettings) getStubSettings()).searchBlurbsOperationSettings(); + } + + /** Returns the object with the settings used for calls to streamBlurbs. */ + public ServerStreamingCallSettings + streamBlurbsSettings() { + return ((MessagingStubSettings) getStubSettings()).streamBlurbsSettings(); + } + + /** Returns the object with the settings used for calls to sendBlurbs. */ + public StreamingCallSettings sendBlurbsSettings() { + return ((MessagingStubSettings) getStubSettings()).sendBlurbsSettings(); + } + + /** Returns the object with the settings used for calls to connect. */ + public StreamingCallSettings connectSettings() { + return ((MessagingStubSettings) getStubSettings()).connectSettings(); + } + + public static final MessagingSettings create(MessagingStubSettings stub) throws IOException { + return new MessagingSettings.Builder(stub.toBuilder()).build(); + } + + /** Returns a builder for the default ExecutorProvider for this service. */ + public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { + return MessagingStubSettings.defaultExecutorProviderBuilder(); + } + + /** Returns the default service endpoint. */ + public static String getDefaultEndpoint() { + return MessagingStubSettings.getDefaultEndpoint(); + } + + /** Returns the default service scopes. */ + public static List getDefaultServiceScopes() { + return MessagingStubSettings.getDefaultServiceScopes(); + } + + /** Returns a builder for the default credentials for this service. */ + public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { + return MessagingStubSettings.defaultCredentialsProviderBuilder(); + } + + /** Returns a builder for the default gRPC ChannelProvider for this service. */ + public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { + return MessagingStubSettings.defaultGrpcTransportProviderBuilder(); + } + + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return MessagingStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + + public static TransportChannelProvider defaultTransportChannelProvider() { + return MessagingStubSettings.defaultTransportChannelProvider(); + } + + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return MessagingStubSettings.defaultApiClientHeaderProviderBuilder(); + } + + /** Returns a new gRPC builder for this class. */ + public static Builder newBuilder() { + return Builder.createDefault(); + } + + /** Returns a new REST builder for this class. */ + @BetaApi + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder(ClientContext clientContext) { + return new Builder(clientContext); + } + + /** Returns a builder containing all the values of this settings class. */ + public Builder toBuilder() { + return new Builder(this); + } + + protected MessagingSettings(Builder settingsBuilder) throws IOException { + super(settingsBuilder); + } + + /** Builder for MessagingSettings. */ + public static class Builder extends ClientSettings.Builder { + + protected Builder() throws IOException { + this(((ClientContext) null)); + } + + protected Builder(ClientContext clientContext) { + super(MessagingStubSettings.newBuilder(clientContext)); + } + + protected Builder(MessagingSettings settings) { + super(settings.getStubSettings().toBuilder()); + } + + protected Builder(MessagingStubSettings.Builder stubSettings) { + super(stubSettings); + } + + private static Builder createDefault() { + return new Builder(MessagingStubSettings.newBuilder()); + } + + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(MessagingStubSettings.newHttpJsonBuilder()); + } + + public MessagingStubSettings.Builder getStubSettingsBuilder() { + return ((MessagingStubSettings.Builder) getStubSettings()); + } + + /** + * Applies the given settings updater function to all of the unary API methods in this service. + * + *

Note: This method does not support applying settings to streaming methods. + */ + public Builder applyToAllUnaryMethods( + ApiFunction, Void> settingsUpdater) { + super.applyToAllUnaryMethods( + getStubSettingsBuilder().unaryMethodSettingsBuilders(), settingsUpdater); + return this; + } + + /** Returns the builder for the settings used for calls to createRoom. */ + public UnaryCallSettings.Builder createRoomSettings() { + return getStubSettingsBuilder().createRoomSettings(); + } + + /** Returns the builder for the settings used for calls to getRoom. */ + public UnaryCallSettings.Builder getRoomSettings() { + return getStubSettingsBuilder().getRoomSettings(); + } + + /** Returns the builder for the settings used for calls to updateRoom. */ + public UnaryCallSettings.Builder updateRoomSettings() { + return getStubSettingsBuilder().updateRoomSettings(); + } + + /** Returns the builder for the settings used for calls to deleteRoom. */ + public UnaryCallSettings.Builder deleteRoomSettings() { + return getStubSettingsBuilder().deleteRoomSettings(); + } + + /** Returns the builder for the settings used for calls to listRooms. */ + public PagedCallSettings.Builder + listRoomsSettings() { + return getStubSettingsBuilder().listRoomsSettings(); + } + + /** Returns the builder for the settings used for calls to createBlurb. */ + public UnaryCallSettings.Builder createBlurbSettings() { + return getStubSettingsBuilder().createBlurbSettings(); + } + + /** Returns the builder for the settings used for calls to getBlurb. */ + public UnaryCallSettings.Builder getBlurbSettings() { + return getStubSettingsBuilder().getBlurbSettings(); + } + + /** Returns the builder for the settings used for calls to updateBlurb. */ + public UnaryCallSettings.Builder updateBlurbSettings() { + return getStubSettingsBuilder().updateBlurbSettings(); + } + + /** Returns the builder for the settings used for calls to deleteBlurb. */ + public UnaryCallSettings.Builder deleteBlurbSettings() { + return getStubSettingsBuilder().deleteBlurbSettings(); + } + + /** Returns the builder for the settings used for calls to listBlurbs. */ + public PagedCallSettings.Builder + listBlurbsSettings() { + return getStubSettingsBuilder().listBlurbsSettings(); + } + + /** Returns the builder for the settings used for calls to searchBlurbs. */ + public UnaryCallSettings.Builder searchBlurbsSettings() { + return getStubSettingsBuilder().searchBlurbsSettings(); + } + + /** Returns the builder for the settings used for calls to searchBlurbs. */ + public OperationCallSettings.Builder< + SearchBlurbsRequest, SearchBlurbsResponse, SearchBlurbsMetadata> + searchBlurbsOperationSettings() { + return getStubSettingsBuilder().searchBlurbsOperationSettings(); + } + + /** Returns the builder for the settings used for calls to streamBlurbs. */ + public ServerStreamingCallSettings.Builder + streamBlurbsSettings() { + return getStubSettingsBuilder().streamBlurbsSettings(); + } + + /** Returns the builder for the settings used for calls to sendBlurbs. */ + public StreamingCallSettings.Builder + sendBlurbsSettings() { + return getStubSettingsBuilder().sendBlurbsSettings(); + } + + /** Returns the builder for the settings used for calls to connect. */ + public StreamingCallSettings.Builder connectSettings() { + return getStubSettingsBuilder().connectSettings(); + } + + @Override + public MessagingSettings build() throws IOException { + return new MessagingSettings(this); + } + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MockCompliance.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MockCompliance.java new file mode 100644 index 0000000000..5c86c23a02 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MockCompliance.java @@ -0,0 +1,59 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.testing.MockGrpcService; +import com.google.protobuf.AbstractMessage; +import io.grpc.ServerServiceDefinition; +import java.util.List; +import javax.annotation.Generated; + +@BetaApi +@Generated("by gapic-generator-java") +public class MockCompliance implements MockGrpcService { + private final MockComplianceImpl serviceImpl; + + public MockCompliance() { + serviceImpl = new MockComplianceImpl(); + } + + @Override + public List getRequests() { + return serviceImpl.getRequests(); + } + + @Override + public void addResponse(AbstractMessage response) { + serviceImpl.addResponse(response); + } + + @Override + public void addException(Exception exception) { + serviceImpl.addException(exception); + } + + @Override + public ServerServiceDefinition getServiceDefinition() { + return serviceImpl.bindService(); + } + + @Override + public void reset() { + serviceImpl.reset(); + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MockComplianceImpl.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MockComplianceImpl.java new file mode 100644 index 0000000000..5d27cb09c2 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MockComplianceImpl.java @@ -0,0 +1,268 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import com.google.api.core.BetaApi; +import com.google.protobuf.AbstractMessage; +import com.google.showcase.v1beta1.ComplianceGrpc.ComplianceImplBase; +import io.grpc.stub.StreamObserver; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; +import javax.annotation.Generated; + +@BetaApi +@Generated("by gapic-generator-java") +public class MockComplianceImpl extends ComplianceImplBase { + private List requests; + private Queue responses; + + public MockComplianceImpl() { + requests = new ArrayList<>(); + responses = new LinkedList<>(); + } + + public List getRequests() { + return requests; + } + + public void addResponse(AbstractMessage response) { + responses.add(response); + } + + public void setResponses(List responses) { + this.responses = new LinkedList(responses); + } + + public void addException(Exception exception) { + responses.add(exception); + } + + public void reset() { + requests = new ArrayList<>(); + responses = new LinkedList<>(); + } + + @Override + public void repeatDataBody( + RepeatRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof RepeatResponse) { + requests.add(request); + responseObserver.onNext(((RepeatResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method RepeatDataBody, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + RepeatResponse.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void repeatDataBodyInfo( + RepeatRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof RepeatResponse) { + requests.add(request); + responseObserver.onNext(((RepeatResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method RepeatDataBodyInfo, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + RepeatResponse.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void repeatDataQuery( + RepeatRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof RepeatResponse) { + requests.add(request); + responseObserver.onNext(((RepeatResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method RepeatDataQuery, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + RepeatResponse.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void repeatDataSimplePath( + RepeatRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof RepeatResponse) { + requests.add(request); + responseObserver.onNext(((RepeatResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method RepeatDataSimplePath, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + RepeatResponse.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void repeatDataPathResource( + RepeatRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof RepeatResponse) { + requests.add(request); + responseObserver.onNext(((RepeatResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method RepeatDataPathResource, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + RepeatResponse.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void repeatDataPathTrailingResource( + RepeatRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof RepeatResponse) { + requests.add(request); + responseObserver.onNext(((RepeatResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method RepeatDataPathTrailingResource, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + RepeatResponse.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void repeatDataBodyPut( + RepeatRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof RepeatResponse) { + requests.add(request); + responseObserver.onNext(((RepeatResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method RepeatDataBodyPut, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + RepeatResponse.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void repeatDataBodyPatch( + RepeatRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof RepeatResponse) { + requests.add(request); + responseObserver.onNext(((RepeatResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method RepeatDataBodyPatch, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + RepeatResponse.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void getEnum(EnumRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof EnumResponse) { + requests.add(request); + responseObserver.onNext(((EnumResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method GetEnum, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + EnumResponse.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void verifyEnum(EnumResponse request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof EnumResponse) { + requests.add(request); + responseObserver.onNext(((EnumResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method VerifyEnum, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + EnumResponse.class.getName(), + Exception.class.getName()))); + } + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MockEcho.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MockEcho.java new file mode 100644 index 0000000000..713524d540 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MockEcho.java @@ -0,0 +1,59 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.testing.MockGrpcService; +import com.google.protobuf.AbstractMessage; +import io.grpc.ServerServiceDefinition; +import java.util.List; +import javax.annotation.Generated; + +@BetaApi +@Generated("by gapic-generator-java") +public class MockEcho implements MockGrpcService { + private final MockEchoImpl serviceImpl; + + public MockEcho() { + serviceImpl = new MockEchoImpl(); + } + + @Override + public List getRequests() { + return serviceImpl.getRequests(); + } + + @Override + public void addResponse(AbstractMessage response) { + serviceImpl.addResponse(response); + } + + @Override + public void addException(Exception exception) { + serviceImpl.addException(exception); + } + + @Override + public ServerServiceDefinition getServiceDefinition() { + return serviceImpl.bindService(); + } + + @Override + public void reset() { + serviceImpl.reset(); + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MockEchoImpl.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MockEchoImpl.java new file mode 100644 index 0000000000..ebb4bab00d --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MockEchoImpl.java @@ -0,0 +1,277 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import com.google.api.core.BetaApi; +import com.google.longrunning.Operation; +import com.google.protobuf.AbstractMessage; +import com.google.showcase.v1beta1.EchoGrpc.EchoImplBase; +import io.grpc.stub.StreamObserver; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; +import javax.annotation.Generated; + +@BetaApi +@Generated("by gapic-generator-java") +public class MockEchoImpl extends EchoImplBase { + private List requests; + private Queue responses; + + public MockEchoImpl() { + requests = new ArrayList<>(); + responses = new LinkedList<>(); + } + + public List getRequests() { + return requests; + } + + public void addResponse(AbstractMessage response) { + responses.add(response); + } + + public void setResponses(List responses) { + this.responses = new LinkedList(responses); + } + + public void addException(Exception exception) { + responses.add(exception); + } + + public void reset() { + requests = new ArrayList<>(); + responses = new LinkedList<>(); + } + + @Override + public void echo(EchoRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof EchoResponse) { + requests.add(request); + responseObserver.onNext(((EchoResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method Echo, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + EchoResponse.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void expand(ExpandRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof EchoResponse) { + requests.add(request); + responseObserver.onNext(((EchoResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method Expand, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + EchoResponse.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public StreamObserver collect(final StreamObserver responseObserver) { + StreamObserver requestObserver = + new StreamObserver() { + @Override + public void onNext(EchoRequest value) { + requests.add(value); + final Object response = responses.remove(); + if (response instanceof EchoResponse) { + responseObserver.onNext(((EchoResponse) response)); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method Collect, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + EchoResponse.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void onError(Throwable t) { + responseObserver.onError(t); + } + + @Override + public void onCompleted() { + responseObserver.onCompleted(); + } + }; + return requestObserver; + } + + @Override + public StreamObserver chat(final StreamObserver responseObserver) { + StreamObserver requestObserver = + new StreamObserver() { + @Override + public void onNext(EchoRequest value) { + requests.add(value); + final Object response = responses.remove(); + if (response instanceof EchoResponse) { + responseObserver.onNext(((EchoResponse) response)); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method Chat, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + EchoResponse.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void onError(Throwable t) { + responseObserver.onError(t); + } + + @Override + public void onCompleted() { + responseObserver.onCompleted(); + } + }; + return requestObserver; + } + + @Override + public void pagedExpand( + PagedExpandRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof PagedExpandResponse) { + requests.add(request); + responseObserver.onNext(((PagedExpandResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method PagedExpand, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + PagedExpandResponse.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void pagedExpandLegacy( + PagedExpandLegacyRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof PagedExpandResponse) { + requests.add(request); + responseObserver.onNext(((PagedExpandResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method PagedExpandLegacy, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + PagedExpandResponse.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void pagedExpandLegacyMapped( + PagedExpandRequest request, + StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof PagedExpandLegacyMappedResponse) { + requests.add(request); + responseObserver.onNext(((PagedExpandLegacyMappedResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method PagedExpandLegacyMapped, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + PagedExpandLegacyMappedResponse.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void wait(WaitRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof Operation) { + requests.add(request); + responseObserver.onNext(((Operation) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method Wait, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + Operation.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void block(BlockRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof BlockResponse) { + requests.add(request); + responseObserver.onNext(((BlockResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method Block, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + BlockResponse.class.getName(), + Exception.class.getName()))); + } + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MockIdentity.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MockIdentity.java new file mode 100644 index 0000000000..c1fa686113 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MockIdentity.java @@ -0,0 +1,59 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.testing.MockGrpcService; +import com.google.protobuf.AbstractMessage; +import io.grpc.ServerServiceDefinition; +import java.util.List; +import javax.annotation.Generated; + +@BetaApi +@Generated("by gapic-generator-java") +public class MockIdentity implements MockGrpcService { + private final MockIdentityImpl serviceImpl; + + public MockIdentity() { + serviceImpl = new MockIdentityImpl(); + } + + @Override + public List getRequests() { + return serviceImpl.getRequests(); + } + + @Override + public void addResponse(AbstractMessage response) { + serviceImpl.addResponse(response); + } + + @Override + public void addException(Exception exception) { + serviceImpl.addException(exception); + } + + @Override + public ServerServiceDefinition getServiceDefinition() { + return serviceImpl.bindService(); + } + + @Override + public void reset() { + serviceImpl.reset(); + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MockIdentityImpl.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MockIdentityImpl.java new file mode 100644 index 0000000000..508e333af6 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MockIdentityImpl.java @@ -0,0 +1,162 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import com.google.api.core.BetaApi; +import com.google.protobuf.AbstractMessage; +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.IdentityGrpc.IdentityImplBase; +import io.grpc.stub.StreamObserver; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; +import javax.annotation.Generated; + +@BetaApi +@Generated("by gapic-generator-java") +public class MockIdentityImpl extends IdentityImplBase { + private List requests; + private Queue responses; + + public MockIdentityImpl() { + requests = new ArrayList<>(); + responses = new LinkedList<>(); + } + + public List getRequests() { + return requests; + } + + public void addResponse(AbstractMessage response) { + responses.add(response); + } + + public void setResponses(List responses) { + this.responses = new LinkedList(responses); + } + + public void addException(Exception exception) { + responses.add(exception); + } + + public void reset() { + requests = new ArrayList<>(); + responses = new LinkedList<>(); + } + + @Override + public void createUser(CreateUserRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof User) { + requests.add(request); + responseObserver.onNext(((User) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method CreateUser, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + User.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void getUser(GetUserRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof User) { + requests.add(request); + responseObserver.onNext(((User) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method GetUser, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + User.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void updateUser(UpdateUserRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof User) { + requests.add(request); + responseObserver.onNext(((User) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method UpdateUser, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + User.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void deleteUser(DeleteUserRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof Empty) { + requests.add(request); + responseObserver.onNext(((Empty) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method DeleteUser, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + Empty.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void listUsers( + ListUsersRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof ListUsersResponse) { + requests.add(request); + responseObserver.onNext(((ListUsersResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method ListUsers, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + ListUsersResponse.class.getName(), + Exception.class.getName()))); + } + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MockMessaging.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MockMessaging.java new file mode 100644 index 0000000000..213a8982b8 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MockMessaging.java @@ -0,0 +1,59 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.testing.MockGrpcService; +import com.google.protobuf.AbstractMessage; +import io.grpc.ServerServiceDefinition; +import java.util.List; +import javax.annotation.Generated; + +@BetaApi +@Generated("by gapic-generator-java") +public class MockMessaging implements MockGrpcService { + private final MockMessagingImpl serviceImpl; + + public MockMessaging() { + serviceImpl = new MockMessagingImpl(); + } + + @Override + public List getRequests() { + return serviceImpl.getRequests(); + } + + @Override + public void addResponse(AbstractMessage response) { + serviceImpl.addResponse(response); + } + + @Override + public void addException(Exception exception) { + serviceImpl.addException(exception); + } + + @Override + public ServerServiceDefinition getServiceDefinition() { + return serviceImpl.bindService(); + } + + @Override + public void reset() { + serviceImpl.reset(); + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MockMessagingImpl.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MockMessagingImpl.java new file mode 100644 index 0000000000..f14386051c --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MockMessagingImpl.java @@ -0,0 +1,380 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import com.google.api.core.BetaApi; +import com.google.longrunning.Operation; +import com.google.protobuf.AbstractMessage; +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.MessagingGrpc.MessagingImplBase; +import io.grpc.stub.StreamObserver; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; +import javax.annotation.Generated; + +@BetaApi +@Generated("by gapic-generator-java") +public class MockMessagingImpl extends MessagingImplBase { + private List requests; + private Queue responses; + + public MockMessagingImpl() { + requests = new ArrayList<>(); + responses = new LinkedList<>(); + } + + public List getRequests() { + return requests; + } + + public void addResponse(AbstractMessage response) { + responses.add(response); + } + + public void setResponses(List responses) { + this.responses = new LinkedList(responses); + } + + public void addException(Exception exception) { + responses.add(exception); + } + + public void reset() { + requests = new ArrayList<>(); + responses = new LinkedList<>(); + } + + @Override + public void createRoom(CreateRoomRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof Room) { + requests.add(request); + responseObserver.onNext(((Room) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method CreateRoom, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + Room.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void getRoom(GetRoomRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof Room) { + requests.add(request); + responseObserver.onNext(((Room) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method GetRoom, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + Room.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void updateRoom(UpdateRoomRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof Room) { + requests.add(request); + responseObserver.onNext(((Room) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method UpdateRoom, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + Room.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void deleteRoom(DeleteRoomRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof Empty) { + requests.add(request); + responseObserver.onNext(((Empty) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method DeleteRoom, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + Empty.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void listRooms( + ListRoomsRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof ListRoomsResponse) { + requests.add(request); + responseObserver.onNext(((ListRoomsResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method ListRooms, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + ListRoomsResponse.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void createBlurb(CreateBlurbRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof Blurb) { + requests.add(request); + responseObserver.onNext(((Blurb) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method CreateBlurb, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + Blurb.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void getBlurb(GetBlurbRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof Blurb) { + requests.add(request); + responseObserver.onNext(((Blurb) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method GetBlurb, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + Blurb.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void updateBlurb(UpdateBlurbRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof Blurb) { + requests.add(request); + responseObserver.onNext(((Blurb) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method UpdateBlurb, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + Blurb.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void deleteBlurb(DeleteBlurbRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof Empty) { + requests.add(request); + responseObserver.onNext(((Empty) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method DeleteBlurb, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + Empty.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void listBlurbs( + ListBlurbsRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof ListBlurbsResponse) { + requests.add(request); + responseObserver.onNext(((ListBlurbsResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method ListBlurbs, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + ListBlurbsResponse.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void searchBlurbs( + SearchBlurbsRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof Operation) { + requests.add(request); + responseObserver.onNext(((Operation) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method SearchBlurbs, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + Operation.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void streamBlurbs( + StreamBlurbsRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof StreamBlurbsResponse) { + requests.add(request); + responseObserver.onNext(((StreamBlurbsResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method StreamBlurbs, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + StreamBlurbsResponse.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public StreamObserver sendBlurbs( + final StreamObserver responseObserver) { + StreamObserver requestObserver = + new StreamObserver() { + @Override + public void onNext(CreateBlurbRequest value) { + requests.add(value); + final Object response = responses.remove(); + if (response instanceof SendBlurbsResponse) { + responseObserver.onNext(((SendBlurbsResponse) response)); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method SendBlurbs, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + SendBlurbsResponse.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void onError(Throwable t) { + responseObserver.onError(t); + } + + @Override + public void onCompleted() { + responseObserver.onCompleted(); + } + }; + return requestObserver; + } + + @Override + public StreamObserver connect( + final StreamObserver responseObserver) { + StreamObserver requestObserver = + new StreamObserver() { + @Override + public void onNext(ConnectRequest value) { + requests.add(value); + final Object response = responses.remove(); + if (response instanceof StreamBlurbsResponse) { + responseObserver.onNext(((StreamBlurbsResponse) response)); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method Connect, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + StreamBlurbsResponse.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void onError(Throwable t) { + responseObserver.onError(t); + } + + @Override + public void onCompleted() { + responseObserver.onCompleted(); + } + }; + return requestObserver; + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MockSequenceService.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MockSequenceService.java new file mode 100644 index 0000000000..6e7db409ff --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MockSequenceService.java @@ -0,0 +1,59 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.testing.MockGrpcService; +import com.google.protobuf.AbstractMessage; +import io.grpc.ServerServiceDefinition; +import java.util.List; +import javax.annotation.Generated; + +@BetaApi +@Generated("by gapic-generator-java") +public class MockSequenceService implements MockGrpcService { + private final MockSequenceServiceImpl serviceImpl; + + public MockSequenceService() { + serviceImpl = new MockSequenceServiceImpl(); + } + + @Override + public List getRequests() { + return serviceImpl.getRequests(); + } + + @Override + public void addResponse(AbstractMessage response) { + serviceImpl.addResponse(response); + } + + @Override + public void addException(Exception exception) { + serviceImpl.addException(exception); + } + + @Override + public ServerServiceDefinition getServiceDefinition() { + return serviceImpl.bindService(); + } + + @Override + public void reset() { + serviceImpl.reset(); + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MockSequenceServiceImpl.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MockSequenceServiceImpl.java new file mode 100644 index 0000000000..a529856c95 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MockSequenceServiceImpl.java @@ -0,0 +1,124 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import com.google.api.core.BetaApi; +import com.google.protobuf.AbstractMessage; +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.SequenceServiceGrpc.SequenceServiceImplBase; +import io.grpc.stub.StreamObserver; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; +import javax.annotation.Generated; + +@BetaApi +@Generated("by gapic-generator-java") +public class MockSequenceServiceImpl extends SequenceServiceImplBase { + private List requests; + private Queue responses; + + public MockSequenceServiceImpl() { + requests = new ArrayList<>(); + responses = new LinkedList<>(); + } + + public List getRequests() { + return requests; + } + + public void addResponse(AbstractMessage response) { + responses.add(response); + } + + public void setResponses(List responses) { + this.responses = new LinkedList(responses); + } + + public void addException(Exception exception) { + responses.add(exception); + } + + public void reset() { + requests = new ArrayList<>(); + responses = new LinkedList<>(); + } + + @Override + public void createSequence( + CreateSequenceRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof Sequence) { + requests.add(request); + responseObserver.onNext(((Sequence) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method CreateSequence, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + Sequence.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void getSequenceReport( + GetSequenceReportRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof SequenceReport) { + requests.add(request); + responseObserver.onNext(((SequenceReport) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method GetSequenceReport, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + SequenceReport.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void attemptSequence( + AttemptSequenceRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof Empty) { + requests.add(request); + responseObserver.onNext(((Empty) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method AttemptSequence, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + Empty.class.getName(), + Exception.class.getName()))); + } + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MockTesting.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MockTesting.java new file mode 100644 index 0000000000..07bf673623 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MockTesting.java @@ -0,0 +1,59 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.testing.MockGrpcService; +import com.google.protobuf.AbstractMessage; +import io.grpc.ServerServiceDefinition; +import java.util.List; +import javax.annotation.Generated; + +@BetaApi +@Generated("by gapic-generator-java") +public class MockTesting implements MockGrpcService { + private final MockTestingImpl serviceImpl; + + public MockTesting() { + serviceImpl = new MockTestingImpl(); + } + + @Override + public List getRequests() { + return serviceImpl.getRequests(); + } + + @Override + public void addResponse(AbstractMessage response) { + serviceImpl.addResponse(response); + } + + @Override + public void addException(Exception exception) { + serviceImpl.addException(exception); + } + + @Override + public ServerServiceDefinition getServiceDefinition() { + return serviceImpl.bindService(); + } + + @Override + public void reset() { + serviceImpl.reset(); + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MockTestingImpl.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MockTestingImpl.java new file mode 100644 index 0000000000..8bc492536e --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/MockTestingImpl.java @@ -0,0 +1,226 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import com.google.api.core.BetaApi; +import com.google.protobuf.AbstractMessage; +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.TestingGrpc.TestingImplBase; +import io.grpc.stub.StreamObserver; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; +import javax.annotation.Generated; + +@BetaApi +@Generated("by gapic-generator-java") +public class MockTestingImpl extends TestingImplBase { + private List requests; + private Queue responses; + + public MockTestingImpl() { + requests = new ArrayList<>(); + responses = new LinkedList<>(); + } + + public List getRequests() { + return requests; + } + + public void addResponse(AbstractMessage response) { + responses.add(response); + } + + public void setResponses(List responses) { + this.responses = new LinkedList(responses); + } + + public void addException(Exception exception) { + responses.add(exception); + } + + public void reset() { + requests = new ArrayList<>(); + responses = new LinkedList<>(); + } + + @Override + public void createSession( + CreateSessionRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof Session) { + requests.add(request); + responseObserver.onNext(((Session) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method CreateSession, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + Session.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void getSession(GetSessionRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof Session) { + requests.add(request); + responseObserver.onNext(((Session) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method GetSession, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + Session.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void listSessions( + ListSessionsRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof ListSessionsResponse) { + requests.add(request); + responseObserver.onNext(((ListSessionsResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method ListSessions, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + ListSessionsResponse.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void deleteSession(DeleteSessionRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof Empty) { + requests.add(request); + responseObserver.onNext(((Empty) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method DeleteSession, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + Empty.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void reportSession( + ReportSessionRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof ReportSessionResponse) { + requests.add(request); + responseObserver.onNext(((ReportSessionResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method ReportSession, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + ReportSessionResponse.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void listTests( + ListTestsRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof ListTestsResponse) { + requests.add(request); + responseObserver.onNext(((ListTestsResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method ListTests, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + ListTestsResponse.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void deleteTest(DeleteTestRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof Empty) { + requests.add(request); + responseObserver.onNext(((Empty) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method DeleteTest, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + Empty.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void verifyTest( + VerifyTestRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof VerifyTestResponse) { + requests.add(request); + responseObserver.onNext(((VerifyTestResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method VerifyTest, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + VerifyTestResponse.class.getName(), + Exception.class.getName()))); + } + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/ProfileName.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/ProfileName.java new file mode 100644 index 0000000000..b69500d0ae --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/ProfileName.java @@ -0,0 +1,168 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import com.google.api.pathtemplate.PathTemplate; +import com.google.api.resourcenames.ResourceName; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableMap; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +@Generated("by gapic-generator-java") +public class ProfileName implements ResourceName { + private static final PathTemplate USER = + PathTemplate.createWithoutUrlEncoding("users/{user}/profile/blurbs"); + private volatile Map fieldValuesMap; + private final String user; + + @Deprecated + protected ProfileName() { + user = null; + } + + private ProfileName(Builder builder) { + user = Preconditions.checkNotNull(builder.getUser()); + } + + public String getUser() { + return user; + } + + public static Builder newBuilder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder(this); + } + + public static ProfileName of(String user) { + return newBuilder().setUser(user).build(); + } + + public static String format(String user) { + return newBuilder().setUser(user).build().toString(); + } + + public static ProfileName parse(String formattedString) { + if (formattedString.isEmpty()) { + return null; + } + Map matchMap = + USER.validatedMatch( + formattedString, "ProfileName.parse: formattedString not in valid format"); + return of(matchMap.get("user")); + } + + public static List parseList(List formattedStrings) { + List list = new ArrayList<>(formattedStrings.size()); + for (String formattedString : formattedStrings) { + list.add(parse(formattedString)); + } + return list; + } + + public static List toStringList(List values) { + List list = new ArrayList<>(values.size()); + for (ProfileName value : values) { + if (value == null) { + list.add(""); + } else { + list.add(value.toString()); + } + } + return list; + } + + public static boolean isParsableFrom(String formattedString) { + return USER.matches(formattedString); + } + + @Override + public Map getFieldValuesMap() { + if (fieldValuesMap == null) { + synchronized (this) { + if (fieldValuesMap == null) { + ImmutableMap.Builder fieldMapBuilder = ImmutableMap.builder(); + if (user != null) { + fieldMapBuilder.put("user", user); + } + fieldValuesMap = fieldMapBuilder.build(); + } + } + } + return fieldValuesMap; + } + + public String getFieldValue(String fieldName) { + return getFieldValuesMap().get(fieldName); + } + + @Override + public String toString() { + return USER.instantiate("user", user); + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o != null || getClass() == o.getClass()) { + ProfileName that = ((ProfileName) o); + return Objects.equals(this.user, that.user); + } + return false; + } + + @Override + public int hashCode() { + int h = 1; + h *= 1000003; + h ^= Objects.hashCode(user); + return h; + } + + /** Builder for users/{user}/profile/blurbs. */ + public static class Builder { + private String user; + + protected Builder() {} + + public String getUser() { + return user; + } + + public Builder setUser(String user) { + this.user = user; + return this; + } + + private Builder(ProfileName profileName) { + this.user = profileName.user; + } + + public ProfileName build() { + return new ProfileName(this); + } + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/RoomName.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/RoomName.java new file mode 100644 index 0000000000..b7ebbbad5d --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/RoomName.java @@ -0,0 +1,166 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import com.google.api.pathtemplate.PathTemplate; +import com.google.api.resourcenames.ResourceName; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableMap; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +@Generated("by gapic-generator-java") +public class RoomName implements ResourceName { + private static final PathTemplate ROOM = PathTemplate.createWithoutUrlEncoding("rooms/{room}"); + private volatile Map fieldValuesMap; + private final String room; + + @Deprecated + protected RoomName() { + room = null; + } + + private RoomName(Builder builder) { + room = Preconditions.checkNotNull(builder.getRoom()); + } + + public String getRoom() { + return room; + } + + public static Builder newBuilder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder(this); + } + + public static RoomName of(String room) { + return newBuilder().setRoom(room).build(); + } + + public static String format(String room) { + return newBuilder().setRoom(room).build().toString(); + } + + public static RoomName parse(String formattedString) { + if (formattedString.isEmpty()) { + return null; + } + Map matchMap = + ROOM.validatedMatch(formattedString, "RoomName.parse: formattedString not in valid format"); + return of(matchMap.get("room")); + } + + public static List parseList(List formattedStrings) { + List list = new ArrayList<>(formattedStrings.size()); + for (String formattedString : formattedStrings) { + list.add(parse(formattedString)); + } + return list; + } + + public static List toStringList(List values) { + List list = new ArrayList<>(values.size()); + for (RoomName value : values) { + if (value == null) { + list.add(""); + } else { + list.add(value.toString()); + } + } + return list; + } + + public static boolean isParsableFrom(String formattedString) { + return ROOM.matches(formattedString); + } + + @Override + public Map getFieldValuesMap() { + if (fieldValuesMap == null) { + synchronized (this) { + if (fieldValuesMap == null) { + ImmutableMap.Builder fieldMapBuilder = ImmutableMap.builder(); + if (room != null) { + fieldMapBuilder.put("room", room); + } + fieldValuesMap = fieldMapBuilder.build(); + } + } + } + return fieldValuesMap; + } + + public String getFieldValue(String fieldName) { + return getFieldValuesMap().get(fieldName); + } + + @Override + public String toString() { + return ROOM.instantiate("room", room); + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o != null || getClass() == o.getClass()) { + RoomName that = ((RoomName) o); + return Objects.equals(this.room, that.room); + } + return false; + } + + @Override + public int hashCode() { + int h = 1; + h *= 1000003; + h ^= Objects.hashCode(room); + return h; + } + + /** Builder for rooms/{room}. */ + public static class Builder { + private String room; + + protected Builder() {} + + public String getRoom() { + return room; + } + + public Builder setRoom(String room) { + this.room = room; + return this; + } + + private Builder(RoomName roomName) { + this.room = roomName.room; + } + + public RoomName build() { + return new RoomName(this); + } + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/SequenceName.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/SequenceName.java new file mode 100644 index 0000000000..067bb15adb --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/SequenceName.java @@ -0,0 +1,168 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import com.google.api.pathtemplate.PathTemplate; +import com.google.api.resourcenames.ResourceName; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableMap; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +@Generated("by gapic-generator-java") +public class SequenceName implements ResourceName { + private static final PathTemplate SEQUENCE = + PathTemplate.createWithoutUrlEncoding("sequences/{sequence}"); + private volatile Map fieldValuesMap; + private final String sequence; + + @Deprecated + protected SequenceName() { + sequence = null; + } + + private SequenceName(Builder builder) { + sequence = Preconditions.checkNotNull(builder.getSequence()); + } + + public String getSequence() { + return sequence; + } + + public static Builder newBuilder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder(this); + } + + public static SequenceName of(String sequence) { + return newBuilder().setSequence(sequence).build(); + } + + public static String format(String sequence) { + return newBuilder().setSequence(sequence).build().toString(); + } + + public static SequenceName parse(String formattedString) { + if (formattedString.isEmpty()) { + return null; + } + Map matchMap = + SEQUENCE.validatedMatch( + formattedString, "SequenceName.parse: formattedString not in valid format"); + return of(matchMap.get("sequence")); + } + + public static List parseList(List formattedStrings) { + List list = new ArrayList<>(formattedStrings.size()); + for (String formattedString : formattedStrings) { + list.add(parse(formattedString)); + } + return list; + } + + public static List toStringList(List values) { + List list = new ArrayList<>(values.size()); + for (SequenceName value : values) { + if (value == null) { + list.add(""); + } else { + list.add(value.toString()); + } + } + return list; + } + + public static boolean isParsableFrom(String formattedString) { + return SEQUENCE.matches(formattedString); + } + + @Override + public Map getFieldValuesMap() { + if (fieldValuesMap == null) { + synchronized (this) { + if (fieldValuesMap == null) { + ImmutableMap.Builder fieldMapBuilder = ImmutableMap.builder(); + if (sequence != null) { + fieldMapBuilder.put("sequence", sequence); + } + fieldValuesMap = fieldMapBuilder.build(); + } + } + } + return fieldValuesMap; + } + + public String getFieldValue(String fieldName) { + return getFieldValuesMap().get(fieldName); + } + + @Override + public String toString() { + return SEQUENCE.instantiate("sequence", sequence); + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o != null || getClass() == o.getClass()) { + SequenceName that = ((SequenceName) o); + return Objects.equals(this.sequence, that.sequence); + } + return false; + } + + @Override + public int hashCode() { + int h = 1; + h *= 1000003; + h ^= Objects.hashCode(sequence); + return h; + } + + /** Builder for sequences/{sequence}. */ + public static class Builder { + private String sequence; + + protected Builder() {} + + public String getSequence() { + return sequence; + } + + public Builder setSequence(String sequence) { + this.sequence = sequence; + return this; + } + + private Builder(SequenceName sequenceName) { + this.sequence = sequenceName.sequence; + } + + public SequenceName build() { + return new SequenceName(this); + } + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/SequenceReportName.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/SequenceReportName.java new file mode 100644 index 0000000000..80742478a3 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/SequenceReportName.java @@ -0,0 +1,168 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import com.google.api.pathtemplate.PathTemplate; +import com.google.api.resourcenames.ResourceName; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableMap; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +@Generated("by gapic-generator-java") +public class SequenceReportName implements ResourceName { + private static final PathTemplate SEQUENCE = + PathTemplate.createWithoutUrlEncoding("sequences/{sequence}/sequenceReport"); + private volatile Map fieldValuesMap; + private final String sequence; + + @Deprecated + protected SequenceReportName() { + sequence = null; + } + + private SequenceReportName(Builder builder) { + sequence = Preconditions.checkNotNull(builder.getSequence()); + } + + public String getSequence() { + return sequence; + } + + public static Builder newBuilder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder(this); + } + + public static SequenceReportName of(String sequence) { + return newBuilder().setSequence(sequence).build(); + } + + public static String format(String sequence) { + return newBuilder().setSequence(sequence).build().toString(); + } + + public static SequenceReportName parse(String formattedString) { + if (formattedString.isEmpty()) { + return null; + } + Map matchMap = + SEQUENCE.validatedMatch( + formattedString, "SequenceReportName.parse: formattedString not in valid format"); + return of(matchMap.get("sequence")); + } + + public static List parseList(List formattedStrings) { + List list = new ArrayList<>(formattedStrings.size()); + for (String formattedString : formattedStrings) { + list.add(parse(formattedString)); + } + return list; + } + + public static List toStringList(List values) { + List list = new ArrayList<>(values.size()); + for (SequenceReportName value : values) { + if (value == null) { + list.add(""); + } else { + list.add(value.toString()); + } + } + return list; + } + + public static boolean isParsableFrom(String formattedString) { + return SEQUENCE.matches(formattedString); + } + + @Override + public Map getFieldValuesMap() { + if (fieldValuesMap == null) { + synchronized (this) { + if (fieldValuesMap == null) { + ImmutableMap.Builder fieldMapBuilder = ImmutableMap.builder(); + if (sequence != null) { + fieldMapBuilder.put("sequence", sequence); + } + fieldValuesMap = fieldMapBuilder.build(); + } + } + } + return fieldValuesMap; + } + + public String getFieldValue(String fieldName) { + return getFieldValuesMap().get(fieldName); + } + + @Override + public String toString() { + return SEQUENCE.instantiate("sequence", sequence); + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o != null || getClass() == o.getClass()) { + SequenceReportName that = ((SequenceReportName) o); + return Objects.equals(this.sequence, that.sequence); + } + return false; + } + + @Override + public int hashCode() { + int h = 1; + h *= 1000003; + h ^= Objects.hashCode(sequence); + return h; + } + + /** Builder for sequences/{sequence}/sequenceReport. */ + public static class Builder { + private String sequence; + + protected Builder() {} + + public String getSequence() { + return sequence; + } + + public Builder setSequence(String sequence) { + this.sequence = sequence; + return this; + } + + private Builder(SequenceReportName sequenceReportName) { + this.sequence = sequenceReportName.sequence; + } + + public SequenceReportName build() { + return new SequenceReportName(this); + } + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/SequenceServiceClient.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/SequenceServiceClient.java new file mode 100644 index 0000000000..3a5221b5ef --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/SequenceServiceClient.java @@ -0,0 +1,498 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import com.google.api.core.BetaApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.stub.SequenceServiceStub; +import com.google.showcase.v1beta1.stub.SequenceServiceStubSettings; +import java.io.IOException; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * This class provides the ability to make remote calls to the backing service through method calls + * that map to API methods. Sample code to get started: + * + *
{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (SequenceServiceClient sequenceServiceClient = SequenceServiceClient.create()) {
+ *   Sequence sequence = Sequence.newBuilder().build();
+ *   Sequence response = sequenceServiceClient.createSequence(sequence);
+ * }
+ * }
+ * + *

Note: close() needs to be called on the SequenceServiceClient object to clean up resources + * such as threads. In the example above, try-with-resources is used, which automatically calls + * close(). + * + *

The surface of this class includes several types of Java methods for each of the API's + * methods: + * + *

    + *
  1. A "flattened" method. With this type of method, the fields of the request type have been + * converted into function parameters. It may be the case that not all fields are available as + * parameters, and not every API method will have a flattened method entry point. + *
  2. A "request object" method. This type of method only takes one parameter, a request object, + * which must be constructed before the call. Not every API method will have a request object + * method. + *
  3. A "callable" method. This type of method takes no parameters and returns an immutable API + * callable object, which can be used to initiate calls to the service. + *
+ * + *

See the individual methods for example code. + * + *

Many parameters require resource names to be formatted in a particular way. To assist with + * these names, this class includes a format method for each type of name, and additionally a parse + * method to extract the individual identifiers contained within names that are returned. + * + *

This class can be customized by passing in a custom instance of SequenceServiceSettings to + * create(). For example: + * + *

To customize credentials: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * SequenceServiceSettings sequenceServiceSettings =
+ *     SequenceServiceSettings.newBuilder()
+ *         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
+ *         .build();
+ * SequenceServiceClient sequenceServiceClient =
+ *     SequenceServiceClient.create(sequenceServiceSettings);
+ * }
+ * + *

To customize the endpoint: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * SequenceServiceSettings sequenceServiceSettings =
+ *     SequenceServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
+ * SequenceServiceClient sequenceServiceClient =
+ *     SequenceServiceClient.create(sequenceServiceSettings);
+ * }
+ * + *

To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over + * the wire: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * SequenceServiceSettings sequenceServiceSettings =
+ *     SequenceServiceSettings.newHttpJsonBuilder().build();
+ * SequenceServiceClient sequenceServiceClient =
+ *     SequenceServiceClient.create(sequenceServiceSettings);
+ * }
+ * + *

Please refer to the GitHub repository's samples for more quickstart code snippets. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class SequenceServiceClient implements BackgroundResource { + private final SequenceServiceSettings settings; + private final SequenceServiceStub stub; + + /** Constructs an instance of SequenceServiceClient with default settings. */ + public static final SequenceServiceClient create() throws IOException { + return create(SequenceServiceSettings.newBuilder().build()); + } + + /** + * Constructs an instance of SequenceServiceClient, using the given settings. The channels are + * created based on the settings passed in, or defaults for any settings that are not set. + */ + public static final SequenceServiceClient create(SequenceServiceSettings settings) + throws IOException { + return new SequenceServiceClient(settings); + } + + /** + * Constructs an instance of SequenceServiceClient, using the given stub for making calls. This is + * for advanced usage - prefer using create(SequenceServiceSettings). + */ + public static final SequenceServiceClient create(SequenceServiceStub stub) { + return new SequenceServiceClient(stub); + } + + /** + * Constructs an instance of SequenceServiceClient, using the given settings. This is protected so + * that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected SequenceServiceClient(SequenceServiceSettings settings) throws IOException { + this.settings = settings; + this.stub = ((SequenceServiceStubSettings) settings.getStubSettings()).createStub(); + } + + protected SequenceServiceClient(SequenceServiceStub stub) { + this.settings = null; + this.stub = stub; + } + + public final SequenceServiceSettings getSettings() { + return settings; + } + + public SequenceServiceStub getStub() { + return stub; + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates a sequence. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (SequenceServiceClient sequenceServiceClient = SequenceServiceClient.create()) {
+   *   Sequence sequence = Sequence.newBuilder().build();
+   *   Sequence response = sequenceServiceClient.createSequence(sequence);
+   * }
+   * }
+ * + * @param sequence + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final Sequence createSequence(Sequence sequence) { + CreateSequenceRequest request = + CreateSequenceRequest.newBuilder().setSequence(sequence).build(); + return createSequence(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates a sequence. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (SequenceServiceClient sequenceServiceClient = SequenceServiceClient.create()) {
+   *   CreateSequenceRequest request =
+   *       CreateSequenceRequest.newBuilder().setSequence(Sequence.newBuilder().build()).build();
+   *   Sequence response = sequenceServiceClient.createSequence(request);
+   * }
+   * }
+ * + * @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 + */ + public final Sequence createSequence(CreateSequenceRequest request) { + return createSequenceCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates a sequence. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (SequenceServiceClient sequenceServiceClient = SequenceServiceClient.create()) {
+   *   CreateSequenceRequest request =
+   *       CreateSequenceRequest.newBuilder().setSequence(Sequence.newBuilder().build()).build();
+   *   ApiFuture future =
+   *       sequenceServiceClient.createSequenceCallable().futureCall(request);
+   *   // Do something.
+   *   Sequence response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable createSequenceCallable() { + return stub.createSequenceCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Retrieves a sequence. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (SequenceServiceClient sequenceServiceClient = SequenceServiceClient.create()) {
+   *   SequenceReportName name = SequenceReportName.of("[SEQUENCE]");
+   *   SequenceReport response = sequenceServiceClient.getSequenceReport(name);
+   * }
+   * }
+ * + * @param name + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final SequenceReport getSequenceReport(SequenceReportName name) { + GetSequenceReportRequest request = + GetSequenceReportRequest.newBuilder() + .setName(name == null ? null : name.toString()) + .build(); + return getSequenceReport(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Retrieves a sequence. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (SequenceServiceClient sequenceServiceClient = SequenceServiceClient.create()) {
+   *   String name = SequenceReportName.of("[SEQUENCE]").toString();
+   *   SequenceReport response = sequenceServiceClient.getSequenceReport(name);
+   * }
+   * }
+ * + * @param name + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final SequenceReport getSequenceReport(String name) { + GetSequenceReportRequest request = GetSequenceReportRequest.newBuilder().setName(name).build(); + return getSequenceReport(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Retrieves a sequence. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (SequenceServiceClient sequenceServiceClient = SequenceServiceClient.create()) {
+   *   GetSequenceReportRequest request =
+   *       GetSequenceReportRequest.newBuilder()
+   *           .setName(SequenceReportName.of("[SEQUENCE]").toString())
+   *           .build();
+   *   SequenceReport response = sequenceServiceClient.getSequenceReport(request);
+   * }
+   * }
+ * + * @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 + */ + public final SequenceReport getSequenceReport(GetSequenceReportRequest request) { + return getSequenceReportCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Retrieves a sequence. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (SequenceServiceClient sequenceServiceClient = SequenceServiceClient.create()) {
+   *   GetSequenceReportRequest request =
+   *       GetSequenceReportRequest.newBuilder()
+   *           .setName(SequenceReportName.of("[SEQUENCE]").toString())
+   *           .build();
+   *   ApiFuture future =
+   *       sequenceServiceClient.getSequenceReportCallable().futureCall(request);
+   *   // Do something.
+   *   SequenceReport response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable getSequenceReportCallable() { + return stub.getSequenceReportCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Attempts a sequence. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (SequenceServiceClient sequenceServiceClient = SequenceServiceClient.create()) {
+   *   SequenceName name = SequenceName.of("[SEQUENCE]");
+   *   sequenceServiceClient.attemptSequence(name);
+   * }
+   * }
+ * + * @param name + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final void attemptSequence(SequenceName name) { + AttemptSequenceRequest request = + AttemptSequenceRequest.newBuilder().setName(name == null ? null : name.toString()).build(); + attemptSequence(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Attempts a sequence. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (SequenceServiceClient sequenceServiceClient = SequenceServiceClient.create()) {
+   *   String name = SequenceName.of("[SEQUENCE]").toString();
+   *   sequenceServiceClient.attemptSequence(name);
+   * }
+   * }
+ * + * @param name + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final void attemptSequence(String name) { + AttemptSequenceRequest request = AttemptSequenceRequest.newBuilder().setName(name).build(); + attemptSequence(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Attempts a sequence. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (SequenceServiceClient sequenceServiceClient = SequenceServiceClient.create()) {
+   *   AttemptSequenceRequest request =
+   *       AttemptSequenceRequest.newBuilder()
+   *           .setName(SequenceName.of("[SEQUENCE]").toString())
+   *           .build();
+   *   sequenceServiceClient.attemptSequence(request);
+   * }
+   * }
+ * + * @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 + */ + public final void attemptSequence(AttemptSequenceRequest request) { + attemptSequenceCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Attempts a sequence. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (SequenceServiceClient sequenceServiceClient = SequenceServiceClient.create()) {
+   *   AttemptSequenceRequest request =
+   *       AttemptSequenceRequest.newBuilder()
+   *           .setName(SequenceName.of("[SEQUENCE]").toString())
+   *           .build();
+   *   ApiFuture future = sequenceServiceClient.attemptSequenceCallable().futureCall(request);
+   *   // Do something.
+   *   future.get();
+   * }
+   * }
+ */ + public final UnaryCallable attemptSequenceCallable() { + return stub.attemptSequenceCallable(); + } + + @Override + public final void close() { + stub.close(); + } + + @Override + public void shutdown() { + stub.shutdown(); + } + + @Override + public boolean isShutdown() { + return stub.isShutdown(); + } + + @Override + public boolean isTerminated() { + return stub.isTerminated(); + } + + @Override + public void shutdownNow() { + stub.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return stub.awaitTermination(duration, unit); + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/SequenceServiceClientHttpJsonTest.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/SequenceServiceClientHttpJsonTest.java new file mode 100644 index 0000000000..167002e8f2 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/SequenceServiceClientHttpJsonTest.java @@ -0,0 +1,290 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.testing.MockHttpService; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ApiException; +import com.google.api.gax.rpc.ApiExceptionFactory; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.testing.FakeStatusCode; +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.stub.HttpJsonSequenceServiceStub; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class SequenceServiceClientHttpJsonTest { + private static MockHttpService mockService; + private static SequenceServiceClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonSequenceServiceStub.getMethodDescriptors(), + SequenceServiceSettings.getDefaultEndpoint()); + SequenceServiceSettings settings = + SequenceServiceSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + SequenceServiceSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = SequenceServiceClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void createSequenceTest() throws Exception { + Sequence expectedResponse = + Sequence.newBuilder() + .setName(SequenceName.of("[SEQUENCE]").toString()) + .addAllResponses(new ArrayList()) + .build(); + mockService.addResponse(expectedResponse); + + Sequence sequence = Sequence.newBuilder().build(); + + Sequence actualResponse = client.createSequence(sequence); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createSequenceExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + Sequence sequence = Sequence.newBuilder().build(); + client.createSequence(sequence); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getSequenceReportTest() throws Exception { + SequenceReport expectedResponse = + SequenceReport.newBuilder() + .setName(SequenceReportName.of("[SEQUENCE]").toString()) + .addAllAttempts(new ArrayList()) + .build(); + mockService.addResponse(expectedResponse); + + SequenceReportName name = SequenceReportName.of("[SEQUENCE]"); + + SequenceReport actualResponse = client.getSequenceReport(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getSequenceReportExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + SequenceReportName name = SequenceReportName.of("[SEQUENCE]"); + client.getSequenceReport(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getSequenceReportTest2() throws Exception { + SequenceReport expectedResponse = + SequenceReport.newBuilder() + .setName(SequenceReportName.of("[SEQUENCE]").toString()) + .addAllAttempts(new ArrayList()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "sequences/sequence-5566/sequenceReport"; + + SequenceReport actualResponse = client.getSequenceReport(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getSequenceReportExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "sequences/sequence-5566/sequenceReport"; + client.getSequenceReport(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void attemptSequenceTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + SequenceName name = SequenceName.of("[SEQUENCE]"); + + client.attemptSequence(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void attemptSequenceExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + SequenceName name = SequenceName.of("[SEQUENCE]"); + client.attemptSequence(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void attemptSequenceTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + String name = "sequences/sequence-9950"; + + client.attemptSequence(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void attemptSequenceExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "sequences/sequence-9950"; + client.attemptSequence(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/SequenceServiceClientTest.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/SequenceServiceClientTest.java new file mode 100644 index 0000000000..4b6f722827 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/SequenceServiceClientTest.java @@ -0,0 +1,264 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.grpc.GaxGrpcProperties; +import com.google.api.gax.grpc.testing.LocalChannelProvider; +import com.google.api.gax.grpc.testing.MockGrpcService; +import com.google.api.gax.grpc.testing.MockServiceHelper; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.protobuf.AbstractMessage; +import com.google.protobuf.Empty; +import io.grpc.StatusRuntimeException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.UUID; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class SequenceServiceClientTest { + private static MockSequenceService mockSequenceService; + private static MockServiceHelper mockServiceHelper; + private LocalChannelProvider channelProvider; + private SequenceServiceClient client; + + @BeforeClass + public static void startStaticServer() { + mockSequenceService = new MockSequenceService(); + mockServiceHelper = + new MockServiceHelper( + UUID.randomUUID().toString(), Arrays.asList(mockSequenceService)); + mockServiceHelper.start(); + } + + @AfterClass + public static void stopServer() { + mockServiceHelper.stop(); + } + + @Before + public void setUp() throws IOException { + mockServiceHelper.reset(); + channelProvider = mockServiceHelper.createChannelProvider(); + SequenceServiceSettings settings = + SequenceServiceSettings.newBuilder() + .setTransportChannelProvider(channelProvider) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = SequenceServiceClient.create(settings); + } + + @After + public void tearDown() throws Exception { + client.close(); + } + + @Test + public void createSequenceTest() throws Exception { + Sequence expectedResponse = + Sequence.newBuilder() + .setName(SequenceName.of("[SEQUENCE]").toString()) + .addAllResponses(new ArrayList()) + .build(); + mockSequenceService.addResponse(expectedResponse); + + Sequence sequence = Sequence.newBuilder().build(); + + Sequence actualResponse = client.createSequence(sequence); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockSequenceService.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CreateSequenceRequest actualRequest = ((CreateSequenceRequest) actualRequests.get(0)); + + Assert.assertEquals(sequence, actualRequest.getSequence()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void createSequenceExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockSequenceService.addException(exception); + + try { + Sequence sequence = Sequence.newBuilder().build(); + client.createSequence(sequence); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getSequenceReportTest() throws Exception { + SequenceReport expectedResponse = + SequenceReport.newBuilder() + .setName(SequenceReportName.of("[SEQUENCE]").toString()) + .addAllAttempts(new ArrayList()) + .build(); + mockSequenceService.addResponse(expectedResponse); + + SequenceReportName name = SequenceReportName.of("[SEQUENCE]"); + + SequenceReport actualResponse = client.getSequenceReport(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockSequenceService.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + GetSequenceReportRequest actualRequest = ((GetSequenceReportRequest) actualRequests.get(0)); + + Assert.assertEquals(name.toString(), actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void getSequenceReportExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockSequenceService.addException(exception); + + try { + SequenceReportName name = SequenceReportName.of("[SEQUENCE]"); + client.getSequenceReport(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getSequenceReportTest2() throws Exception { + SequenceReport expectedResponse = + SequenceReport.newBuilder() + .setName(SequenceReportName.of("[SEQUENCE]").toString()) + .addAllAttempts(new ArrayList()) + .build(); + mockSequenceService.addResponse(expectedResponse); + + String name = "name3373707"; + + SequenceReport actualResponse = client.getSequenceReport(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockSequenceService.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + GetSequenceReportRequest actualRequest = ((GetSequenceReportRequest) actualRequests.get(0)); + + Assert.assertEquals(name, actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void getSequenceReportExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockSequenceService.addException(exception); + + try { + String name = "name3373707"; + client.getSequenceReport(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void attemptSequenceTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockSequenceService.addResponse(expectedResponse); + + SequenceName name = SequenceName.of("[SEQUENCE]"); + + client.attemptSequence(name); + + List actualRequests = mockSequenceService.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + AttemptSequenceRequest actualRequest = ((AttemptSequenceRequest) actualRequests.get(0)); + + Assert.assertEquals(name.toString(), actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void attemptSequenceExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockSequenceService.addException(exception); + + try { + SequenceName name = SequenceName.of("[SEQUENCE]"); + client.attemptSequence(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void attemptSequenceTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockSequenceService.addResponse(expectedResponse); + + String name = "name3373707"; + + client.attemptSequence(name); + + List actualRequests = mockSequenceService.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + AttemptSequenceRequest actualRequest = ((AttemptSequenceRequest) actualRequests.get(0)); + + Assert.assertEquals(name, actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void attemptSequenceExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockSequenceService.addException(exception); + + try { + String name = "name3373707"; + client.attemptSequence(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/SequenceServiceSettings.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/SequenceServiceSettings.java new file mode 100644 index 0000000000..7b6225a1ee --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/SequenceServiceSettings.java @@ -0,0 +1,229 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import com.google.api.core.ApiFunction; +import com.google.api.core.BetaApi; +import com.google.api.gax.core.GoogleCredentialsProvider; +import com.google.api.gax.core.InstantiatingExecutorProvider; +import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientSettings; +import com.google.api.gax.rpc.StubSettings; +import com.google.api.gax.rpc.TransportChannelProvider; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.stub.SequenceServiceStubSettings; +import java.io.IOException; +import java.util.List; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * Settings class to configure an instance of {@link SequenceServiceClient}. + * + *

The default instance has everything set to sensible defaults: + * + *

    + *
  • The default service address (localhost) and default port (7469) are used. + *
  • Credentials are acquired automatically through Application Default Credentials. + *
  • Retries are configured for idempotent methods but not for non-idempotent methods. + *
+ * + *

The builder of this class is recursive, so contained classes are themselves builders. When + * build() is called, the tree of builders is called to create the complete settings object. + * + *

For example, to set the total timeout of createSequence to 30 seconds: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * SequenceServiceSettings.Builder sequenceServiceSettingsBuilder =
+ *     SequenceServiceSettings.newBuilder();
+ * sequenceServiceSettingsBuilder
+ *     .createSequenceSettings()
+ *     .setRetrySettings(
+ *         sequenceServiceSettingsBuilder
+ *             .createSequenceSettings()
+ *             .getRetrySettings()
+ *             .toBuilder()
+ *             .setTotalTimeout(Duration.ofSeconds(30))
+ *             .build());
+ * SequenceServiceSettings sequenceServiceSettings = sequenceServiceSettingsBuilder.build();
+ * }
+ */ +@BetaApi +@Generated("by gapic-generator-java") +public class SequenceServiceSettings extends ClientSettings { + + /** Returns the object with the settings used for calls to createSequence. */ + public UnaryCallSettings createSequenceSettings() { + return ((SequenceServiceStubSettings) getStubSettings()).createSequenceSettings(); + } + + /** Returns the object with the settings used for calls to getSequenceReport. */ + public UnaryCallSettings getSequenceReportSettings() { + return ((SequenceServiceStubSettings) getStubSettings()).getSequenceReportSettings(); + } + + /** Returns the object with the settings used for calls to attemptSequence. */ + public UnaryCallSettings attemptSequenceSettings() { + return ((SequenceServiceStubSettings) getStubSettings()).attemptSequenceSettings(); + } + + public static final SequenceServiceSettings create(SequenceServiceStubSettings stub) + throws IOException { + return new SequenceServiceSettings.Builder(stub.toBuilder()).build(); + } + + /** Returns a builder for the default ExecutorProvider for this service. */ + public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { + return SequenceServiceStubSettings.defaultExecutorProviderBuilder(); + } + + /** Returns the default service endpoint. */ + public static String getDefaultEndpoint() { + return SequenceServiceStubSettings.getDefaultEndpoint(); + } + + /** Returns the default service scopes. */ + public static List getDefaultServiceScopes() { + return SequenceServiceStubSettings.getDefaultServiceScopes(); + } + + /** Returns a builder for the default credentials for this service. */ + public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { + return SequenceServiceStubSettings.defaultCredentialsProviderBuilder(); + } + + /** Returns a builder for the default gRPC ChannelProvider for this service. */ + public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { + return SequenceServiceStubSettings.defaultGrpcTransportProviderBuilder(); + } + + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return SequenceServiceStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + + public static TransportChannelProvider defaultTransportChannelProvider() { + return SequenceServiceStubSettings.defaultTransportChannelProvider(); + } + + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return SequenceServiceStubSettings.defaultApiClientHeaderProviderBuilder(); + } + + /** Returns a new gRPC builder for this class. */ + public static Builder newBuilder() { + return Builder.createDefault(); + } + + /** Returns a new REST builder for this class. */ + @BetaApi + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder(ClientContext clientContext) { + return new Builder(clientContext); + } + + /** Returns a builder containing all the values of this settings class. */ + public Builder toBuilder() { + return new Builder(this); + } + + protected SequenceServiceSettings(Builder settingsBuilder) throws IOException { + super(settingsBuilder); + } + + /** Builder for SequenceServiceSettings. */ + public static class Builder extends ClientSettings.Builder { + + protected Builder() throws IOException { + this(((ClientContext) null)); + } + + protected Builder(ClientContext clientContext) { + super(SequenceServiceStubSettings.newBuilder(clientContext)); + } + + protected Builder(SequenceServiceSettings settings) { + super(settings.getStubSettings().toBuilder()); + } + + protected Builder(SequenceServiceStubSettings.Builder stubSettings) { + super(stubSettings); + } + + private static Builder createDefault() { + return new Builder(SequenceServiceStubSettings.newBuilder()); + } + + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(SequenceServiceStubSettings.newHttpJsonBuilder()); + } + + public SequenceServiceStubSettings.Builder getStubSettingsBuilder() { + return ((SequenceServiceStubSettings.Builder) getStubSettings()); + } + + /** + * Applies the given settings updater function to all of the unary API methods in this service. + * + *

Note: This method does not support applying settings to streaming methods. + */ + public Builder applyToAllUnaryMethods( + ApiFunction, Void> settingsUpdater) { + super.applyToAllUnaryMethods( + getStubSettingsBuilder().unaryMethodSettingsBuilders(), settingsUpdater); + return this; + } + + /** Returns the builder for the settings used for calls to createSequence. */ + public UnaryCallSettings.Builder createSequenceSettings() { + return getStubSettingsBuilder().createSequenceSettings(); + } + + /** Returns the builder for the settings used for calls to getSequenceReport. */ + public UnaryCallSettings.Builder + getSequenceReportSettings() { + return getStubSettingsBuilder().getSequenceReportSettings(); + } + + /** Returns the builder for the settings used for calls to attemptSequence. */ + public UnaryCallSettings.Builder attemptSequenceSettings() { + return getStubSettingsBuilder().attemptSequenceSettings(); + } + + @Override + public SequenceServiceSettings build() throws IOException { + return new SequenceServiceSettings(this); + } + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/SessionName.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/SessionName.java new file mode 100644 index 0000000000..a205c1272d --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/SessionName.java @@ -0,0 +1,168 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import com.google.api.pathtemplate.PathTemplate; +import com.google.api.resourcenames.ResourceName; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableMap; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +@Generated("by gapic-generator-java") +public class SessionName implements ResourceName { + private static final PathTemplate SESSION = + PathTemplate.createWithoutUrlEncoding("sessions/{session}"); + private volatile Map fieldValuesMap; + private final String session; + + @Deprecated + protected SessionName() { + session = null; + } + + private SessionName(Builder builder) { + session = Preconditions.checkNotNull(builder.getSession()); + } + + public String getSession() { + return session; + } + + public static Builder newBuilder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder(this); + } + + public static SessionName of(String session) { + return newBuilder().setSession(session).build(); + } + + public static String format(String session) { + return newBuilder().setSession(session).build().toString(); + } + + public static SessionName parse(String formattedString) { + if (formattedString.isEmpty()) { + return null; + } + Map matchMap = + SESSION.validatedMatch( + formattedString, "SessionName.parse: formattedString not in valid format"); + return of(matchMap.get("session")); + } + + public static List parseList(List formattedStrings) { + List list = new ArrayList<>(formattedStrings.size()); + for (String formattedString : formattedStrings) { + list.add(parse(formattedString)); + } + return list; + } + + public static List toStringList(List values) { + List list = new ArrayList<>(values.size()); + for (SessionName value : values) { + if (value == null) { + list.add(""); + } else { + list.add(value.toString()); + } + } + return list; + } + + public static boolean isParsableFrom(String formattedString) { + return SESSION.matches(formattedString); + } + + @Override + public Map getFieldValuesMap() { + if (fieldValuesMap == null) { + synchronized (this) { + if (fieldValuesMap == null) { + ImmutableMap.Builder fieldMapBuilder = ImmutableMap.builder(); + if (session != null) { + fieldMapBuilder.put("session", session); + } + fieldValuesMap = fieldMapBuilder.build(); + } + } + } + return fieldValuesMap; + } + + public String getFieldValue(String fieldName) { + return getFieldValuesMap().get(fieldName); + } + + @Override + public String toString() { + return SESSION.instantiate("session", session); + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o != null || getClass() == o.getClass()) { + SessionName that = ((SessionName) o); + return Objects.equals(this.session, that.session); + } + return false; + } + + @Override + public int hashCode() { + int h = 1; + h *= 1000003; + h ^= Objects.hashCode(session); + return h; + } + + /** Builder for sessions/{session}. */ + public static class Builder { + private String session; + + protected Builder() {} + + public String getSession() { + return session; + } + + public Builder setSession(String session) { + this.session = session; + return this; + } + + private Builder(SessionName sessionName) { + this.session = sessionName.session; + } + + public SessionName build() { + return new SessionName(this); + } + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/TestName.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/TestName.java new file mode 100644 index 0000000000..fb2855113a --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/TestName.java @@ -0,0 +1,191 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import com.google.api.pathtemplate.PathTemplate; +import com.google.api.resourcenames.ResourceName; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableMap; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +@Generated("by gapic-generator-java") +public class TestName implements ResourceName { + private static final PathTemplate SESSION_TEST = + PathTemplate.createWithoutUrlEncoding("sessions/{session}/tests/{test}"); + private volatile Map fieldValuesMap; + private final String session; + private final String test; + + @Deprecated + protected TestName() { + session = null; + test = null; + } + + private TestName(Builder builder) { + session = Preconditions.checkNotNull(builder.getSession()); + test = Preconditions.checkNotNull(builder.getTest()); + } + + public String getSession() { + return session; + } + + public String getTest() { + return test; + } + + public static Builder newBuilder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder(this); + } + + public static TestName of(String session, String test) { + return newBuilder().setSession(session).setTest(test).build(); + } + + public static String format(String session, String test) { + return newBuilder().setSession(session).setTest(test).build().toString(); + } + + public static TestName parse(String formattedString) { + if (formattedString.isEmpty()) { + return null; + } + Map matchMap = + SESSION_TEST.validatedMatch( + formattedString, "TestName.parse: formattedString not in valid format"); + return of(matchMap.get("session"), matchMap.get("test")); + } + + public static List parseList(List formattedStrings) { + List list = new ArrayList<>(formattedStrings.size()); + for (String formattedString : formattedStrings) { + list.add(parse(formattedString)); + } + return list; + } + + public static List toStringList(List values) { + List list = new ArrayList<>(values.size()); + for (TestName value : values) { + if (value == null) { + list.add(""); + } else { + list.add(value.toString()); + } + } + return list; + } + + public static boolean isParsableFrom(String formattedString) { + return SESSION_TEST.matches(formattedString); + } + + @Override + public Map getFieldValuesMap() { + if (fieldValuesMap == null) { + synchronized (this) { + if (fieldValuesMap == null) { + ImmutableMap.Builder fieldMapBuilder = ImmutableMap.builder(); + if (session != null) { + fieldMapBuilder.put("session", session); + } + if (test != null) { + fieldMapBuilder.put("test", test); + } + fieldValuesMap = fieldMapBuilder.build(); + } + } + } + return fieldValuesMap; + } + + public String getFieldValue(String fieldName) { + return getFieldValuesMap().get(fieldName); + } + + @Override + public String toString() { + return SESSION_TEST.instantiate("session", session, "test", test); + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o != null || getClass() == o.getClass()) { + TestName that = ((TestName) o); + return Objects.equals(this.session, that.session) && Objects.equals(this.test, that.test); + } + return false; + } + + @Override + public int hashCode() { + int h = 1; + h *= 1000003; + h ^= Objects.hashCode(session); + h *= 1000003; + h ^= Objects.hashCode(test); + return h; + } + + /** Builder for sessions/{session}/tests/{test}. */ + public static class Builder { + private String session; + private String test; + + protected Builder() {} + + public String getSession() { + return session; + } + + public String getTest() { + return test; + } + + public Builder setSession(String session) { + this.session = session; + return this; + } + + public Builder setTest(String test) { + this.test = test; + return this; + } + + private Builder(TestName testName) { + this.session = testName.session; + this.test = testName.test; + } + + public TestName build() { + return new TestName(this); + } + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/TestingClient.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/TestingClient.java new file mode 100644 index 0000000000..9cf8b16a13 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/TestingClient.java @@ -0,0 +1,880 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import com.google.api.core.ApiFuture; +import com.google.api.core.ApiFutures; +import com.google.api.core.BetaApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.paging.AbstractFixedSizeCollection; +import com.google.api.gax.paging.AbstractPage; +import com.google.api.gax.paging.AbstractPagedListResponse; +import com.google.api.gax.rpc.PageContext; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.common.util.concurrent.MoreExecutors; +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.stub.TestingStub; +import com.google.showcase.v1beta1.stub.TestingStubSettings; +import java.io.IOException; +import java.util.List; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * Service Description: A service to facilitate running discrete sets of tests against Showcase. + * + *

This class provides the ability to make remote calls to the backing service through method + * calls that map to API methods. Sample code to get started: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (TestingClient testingClient = TestingClient.create()) {
+ *   CreateSessionRequest request =
+ *       CreateSessionRequest.newBuilder().setSession(Session.newBuilder().build()).build();
+ *   Session response = testingClient.createSession(request);
+ * }
+ * }
+ * + *

Note: close() needs to be called on the TestingClient object to clean up resources such as + * threads. In the example above, try-with-resources is used, which automatically calls close(). + * + *

The surface of this class includes several types of Java methods for each of the API's + * methods: + * + *

    + *
  1. A "flattened" method. With this type of method, the fields of the request type have been + * converted into function parameters. It may be the case that not all fields are available as + * parameters, and not every API method will have a flattened method entry point. + *
  2. A "request object" method. This type of method only takes one parameter, a request object, + * which must be constructed before the call. Not every API method will have a request object + * method. + *
  3. A "callable" method. This type of method takes no parameters and returns an immutable API + * callable object, which can be used to initiate calls to the service. + *
+ * + *

See the individual methods for example code. + * + *

Many parameters require resource names to be formatted in a particular way. To assist with + * these names, this class includes a format method for each type of name, and additionally a parse + * method to extract the individual identifiers contained within names that are returned. + * + *

This class can be customized by passing in a custom instance of TestingSettings to create(). + * For example: + * + *

To customize credentials: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * TestingSettings testingSettings =
+ *     TestingSettings.newBuilder()
+ *         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
+ *         .build();
+ * TestingClient testingClient = TestingClient.create(testingSettings);
+ * }
+ * + *

To customize the endpoint: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * TestingSettings testingSettings = TestingSettings.newBuilder().setEndpoint(myEndpoint).build();
+ * TestingClient testingClient = TestingClient.create(testingSettings);
+ * }
+ * + *

To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over + * the wire: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * TestingSettings testingSettings = TestingSettings.newHttpJsonBuilder().build();
+ * TestingClient testingClient = TestingClient.create(testingSettings);
+ * }
+ * + *

Please refer to the GitHub repository's samples for more quickstart code snippets. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class TestingClient implements BackgroundResource { + private final TestingSettings settings; + private final TestingStub stub; + + /** Constructs an instance of TestingClient with default settings. */ + public static final TestingClient create() throws IOException { + return create(TestingSettings.newBuilder().build()); + } + + /** + * Constructs an instance of TestingClient, using the given settings. The channels are created + * based on the settings passed in, or defaults for any settings that are not set. + */ + public static final TestingClient create(TestingSettings settings) throws IOException { + return new TestingClient(settings); + } + + /** + * Constructs an instance of TestingClient, using the given stub for making calls. This is for + * advanced usage - prefer using create(TestingSettings). + */ + public static final TestingClient create(TestingStub stub) { + return new TestingClient(stub); + } + + /** + * Constructs an instance of TestingClient, using the given settings. This is protected so that it + * is easy to make a subclass, but otherwise, the static factory methods should be preferred. + */ + protected TestingClient(TestingSettings settings) throws IOException { + this.settings = settings; + this.stub = ((TestingStubSettings) settings.getStubSettings()).createStub(); + } + + protected TestingClient(TestingStub stub) { + this.settings = null; + this.stub = stub; + } + + public final TestingSettings getSettings() { + return settings; + } + + public TestingStub getStub() { + return stub; + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates a new testing session. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (TestingClient testingClient = TestingClient.create()) {
+   *   CreateSessionRequest request =
+   *       CreateSessionRequest.newBuilder().setSession(Session.newBuilder().build()).build();
+   *   Session response = testingClient.createSession(request);
+   * }
+   * }
+ * + * @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 + */ + public final Session createSession(CreateSessionRequest request) { + return createSessionCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates a new testing session. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (TestingClient testingClient = TestingClient.create()) {
+   *   CreateSessionRequest request =
+   *       CreateSessionRequest.newBuilder().setSession(Session.newBuilder().build()).build();
+   *   ApiFuture future = testingClient.createSessionCallable().futureCall(request);
+   *   // Do something.
+   *   Session response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable createSessionCallable() { + return stub.createSessionCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Gets a testing session. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (TestingClient testingClient = TestingClient.create()) {
+   *   GetSessionRequest request =
+   *       GetSessionRequest.newBuilder().setName(SessionName.of("[SESSION]").toString()).build();
+   *   Session response = testingClient.getSession(request);
+   * }
+   * }
+ * + * @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 + */ + public final Session getSession(GetSessionRequest request) { + return getSessionCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Gets a testing session. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (TestingClient testingClient = TestingClient.create()) {
+   *   GetSessionRequest request =
+   *       GetSessionRequest.newBuilder().setName(SessionName.of("[SESSION]").toString()).build();
+   *   ApiFuture future = testingClient.getSessionCallable().futureCall(request);
+   *   // Do something.
+   *   Session response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable getSessionCallable() { + return stub.getSessionCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Lists the current test sessions. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (TestingClient testingClient = TestingClient.create()) {
+   *   ListSessionsRequest request =
+   *       ListSessionsRequest.newBuilder()
+   *           .setPageSize(883849137)
+   *           .setPageToken("pageToken873572522")
+   *           .build();
+   *   for (Session element : testingClient.listSessions(request).iterateAll()) {
+   *     // doThingsWith(element);
+   *   }
+   * }
+   * }
+ * + * @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 + */ + public final ListSessionsPagedResponse listSessions(ListSessionsRequest request) { + return listSessionsPagedCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Lists the current test sessions. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (TestingClient testingClient = TestingClient.create()) {
+   *   ListSessionsRequest request =
+   *       ListSessionsRequest.newBuilder()
+   *           .setPageSize(883849137)
+   *           .setPageToken("pageToken873572522")
+   *           .build();
+   *   ApiFuture future = testingClient.listSessionsPagedCallable().futureCall(request);
+   *   // Do something.
+   *   for (Session element : future.get().iterateAll()) {
+   *     // doThingsWith(element);
+   *   }
+   * }
+   * }
+ */ + public final UnaryCallable + listSessionsPagedCallable() { + return stub.listSessionsPagedCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Lists the current test sessions. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (TestingClient testingClient = TestingClient.create()) {
+   *   ListSessionsRequest request =
+   *       ListSessionsRequest.newBuilder()
+   *           .setPageSize(883849137)
+   *           .setPageToken("pageToken873572522")
+   *           .build();
+   *   while (true) {
+   *     ListSessionsResponse response = testingClient.listSessionsCallable().call(request);
+   *     for (Session element : response.getSessionsList()) {
+   *       // doThingsWith(element);
+   *     }
+   *     String nextPageToken = response.getNextPageToken();
+   *     if (!Strings.isNullOrEmpty(nextPageToken)) {
+   *       request = request.toBuilder().setPageToken(nextPageToken).build();
+   *     } else {
+   *       break;
+   *     }
+   *   }
+   * }
+   * }
+ */ + public final UnaryCallable listSessionsCallable() { + return stub.listSessionsCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Delete a test session. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (TestingClient testingClient = TestingClient.create()) {
+   *   DeleteSessionRequest request =
+   *       DeleteSessionRequest.newBuilder().setName(SessionName.of("[SESSION]").toString()).build();
+   *   testingClient.deleteSession(request);
+   * }
+   * }
+ * + * @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 + */ + public final void deleteSession(DeleteSessionRequest request) { + deleteSessionCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Delete a test session. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (TestingClient testingClient = TestingClient.create()) {
+   *   DeleteSessionRequest request =
+   *       DeleteSessionRequest.newBuilder().setName(SessionName.of("[SESSION]").toString()).build();
+   *   ApiFuture future = testingClient.deleteSessionCallable().futureCall(request);
+   *   // Do something.
+   *   future.get();
+   * }
+   * }
+ */ + public final UnaryCallable deleteSessionCallable() { + return stub.deleteSessionCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Report on the status of a session. This generates a report detailing which tests have been + * completed, and an overall rollup. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (TestingClient testingClient = TestingClient.create()) {
+   *   ReportSessionRequest request =
+   *       ReportSessionRequest.newBuilder().setName(SessionName.of("[SESSION]").toString()).build();
+   *   ReportSessionResponse response = testingClient.reportSession(request);
+   * }
+   * }
+ * + * @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 + */ + public final ReportSessionResponse reportSession(ReportSessionRequest request) { + return reportSessionCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Report on the status of a session. This generates a report detailing which tests have been + * completed, and an overall rollup. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (TestingClient testingClient = TestingClient.create()) {
+   *   ReportSessionRequest request =
+   *       ReportSessionRequest.newBuilder().setName(SessionName.of("[SESSION]").toString()).build();
+   *   ApiFuture future =
+   *       testingClient.reportSessionCallable().futureCall(request);
+   *   // Do something.
+   *   ReportSessionResponse response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable reportSessionCallable() { + return stub.reportSessionCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * List the tests of a sessesion. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (TestingClient testingClient = TestingClient.create()) {
+   *   ListTestsRequest request =
+   *       ListTestsRequest.newBuilder()
+   *           .setParent(SessionName.of("[SESSION]").toString())
+   *           .setPageSize(883849137)
+   *           .setPageToken("pageToken873572522")
+   *           .build();
+   *   for (Test element : testingClient.listTests(request).iterateAll()) {
+   *     // doThingsWith(element);
+   *   }
+   * }
+   * }
+ * + * @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 + */ + public final ListTestsPagedResponse listTests(ListTestsRequest request) { + return listTestsPagedCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * List the tests of a sessesion. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (TestingClient testingClient = TestingClient.create()) {
+   *   ListTestsRequest request =
+   *       ListTestsRequest.newBuilder()
+   *           .setParent(SessionName.of("[SESSION]").toString())
+   *           .setPageSize(883849137)
+   *           .setPageToken("pageToken873572522")
+   *           .build();
+   *   ApiFuture future = testingClient.listTestsPagedCallable().futureCall(request);
+   *   // Do something.
+   *   for (Test element : future.get().iterateAll()) {
+   *     // doThingsWith(element);
+   *   }
+   * }
+   * }
+ */ + public final UnaryCallable listTestsPagedCallable() { + return stub.listTestsPagedCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * List the tests of a sessesion. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (TestingClient testingClient = TestingClient.create()) {
+   *   ListTestsRequest request =
+   *       ListTestsRequest.newBuilder()
+   *           .setParent(SessionName.of("[SESSION]").toString())
+   *           .setPageSize(883849137)
+   *           .setPageToken("pageToken873572522")
+   *           .build();
+   *   while (true) {
+   *     ListTestsResponse response = testingClient.listTestsCallable().call(request);
+   *     for (Test element : response.getTestsList()) {
+   *       // doThingsWith(element);
+   *     }
+   *     String nextPageToken = response.getNextPageToken();
+   *     if (!Strings.isNullOrEmpty(nextPageToken)) {
+   *       request = request.toBuilder().setPageToken(nextPageToken).build();
+   *     } else {
+   *       break;
+   *     }
+   *   }
+   * }
+   * }
+ */ + public final UnaryCallable listTestsCallable() { + return stub.listTestsCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Explicitly decline to implement a test. + * + *

This removes the test from subsequent `ListTests` calls, and attempting to do the test will + * error. + * + *

This method will error if attempting to delete a required test. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (TestingClient testingClient = TestingClient.create()) {
+   *   DeleteTestRequest request =
+   *       DeleteTestRequest.newBuilder()
+   *           .setName(TestName.of("[SESSION]", "[TEST]").toString())
+   *           .build();
+   *   testingClient.deleteTest(request);
+   * }
+   * }
+ * + * @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 + */ + public final void deleteTest(DeleteTestRequest request) { + deleteTestCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Explicitly decline to implement a test. + * + *

This removes the test from subsequent `ListTests` calls, and attempting to do the test will + * error. + * + *

This method will error if attempting to delete a required test. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (TestingClient testingClient = TestingClient.create()) {
+   *   DeleteTestRequest request =
+   *       DeleteTestRequest.newBuilder()
+   *           .setName(TestName.of("[SESSION]", "[TEST]").toString())
+   *           .build();
+   *   ApiFuture future = testingClient.deleteTestCallable().futureCall(request);
+   *   // Do something.
+   *   future.get();
+   * }
+   * }
+ */ + public final UnaryCallable deleteTestCallable() { + return stub.deleteTestCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Register a response to a test. + * + *

In cases where a test involves registering a final answer at the end of the test, this + * method provides the means to do so. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (TestingClient testingClient = TestingClient.create()) {
+   *   VerifyTestRequest request =
+   *       VerifyTestRequest.newBuilder()
+   *           .setName(TestName.of("[SESSION]", "[TEST]").toString())
+   *           .setAnswer(ByteString.EMPTY)
+   *           .addAllAnswers(new ArrayList())
+   *           .build();
+   *   VerifyTestResponse response = testingClient.verifyTest(request);
+   * }
+   * }
+ * + * @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 + */ + public final VerifyTestResponse verifyTest(VerifyTestRequest request) { + return verifyTestCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Register a response to a test. + * + *

In cases where a test involves registering a final answer at the end of the test, this + * method provides the means to do so. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (TestingClient testingClient = TestingClient.create()) {
+   *   VerifyTestRequest request =
+   *       VerifyTestRequest.newBuilder()
+   *           .setName(TestName.of("[SESSION]", "[TEST]").toString())
+   *           .setAnswer(ByteString.EMPTY)
+   *           .addAllAnswers(new ArrayList())
+   *           .build();
+   *   ApiFuture future = testingClient.verifyTestCallable().futureCall(request);
+   *   // Do something.
+   *   VerifyTestResponse response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable verifyTestCallable() { + return stub.verifyTestCallable(); + } + + @Override + public final void close() { + stub.close(); + } + + @Override + public void shutdown() { + stub.shutdown(); + } + + @Override + public boolean isShutdown() { + return stub.isShutdown(); + } + + @Override + public boolean isTerminated() { + return stub.isTerminated(); + } + + @Override + public void shutdownNow() { + stub.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return stub.awaitTermination(duration, unit); + } + + public static class ListSessionsPagedResponse + extends AbstractPagedListResponse< + ListSessionsRequest, + ListSessionsResponse, + Session, + ListSessionsPage, + ListSessionsFixedSizeCollection> { + + public static ApiFuture createAsync( + PageContext context, + ApiFuture futureResponse) { + ApiFuture futurePage = + ListSessionsPage.createEmptyPage().createPageAsync(context, futureResponse); + return ApiFutures.transform( + futurePage, + input -> new ListSessionsPagedResponse(input), + MoreExecutors.directExecutor()); + } + + private ListSessionsPagedResponse(ListSessionsPage page) { + super(page, ListSessionsFixedSizeCollection.createEmptyCollection()); + } + } + + public static class ListSessionsPage + extends AbstractPage { + + private ListSessionsPage( + PageContext context, + ListSessionsResponse response) { + super(context, response); + } + + private static ListSessionsPage createEmptyPage() { + return new ListSessionsPage(null, null); + } + + @Override + protected ListSessionsPage createPage( + PageContext context, + ListSessionsResponse response) { + return new ListSessionsPage(context, response); + } + + @Override + public ApiFuture createPageAsync( + PageContext context, + ApiFuture futureResponse) { + return super.createPageAsync(context, futureResponse); + } + } + + public static class ListSessionsFixedSizeCollection + extends AbstractFixedSizeCollection< + ListSessionsRequest, + ListSessionsResponse, + Session, + ListSessionsPage, + ListSessionsFixedSizeCollection> { + + private ListSessionsFixedSizeCollection(List pages, int collectionSize) { + super(pages, collectionSize); + } + + private static ListSessionsFixedSizeCollection createEmptyCollection() { + return new ListSessionsFixedSizeCollection(null, 0); + } + + @Override + protected ListSessionsFixedSizeCollection createCollection( + List pages, int collectionSize) { + return new ListSessionsFixedSizeCollection(pages, collectionSize); + } + } + + public static class ListTestsPagedResponse + extends AbstractPagedListResponse< + ListTestsRequest, ListTestsResponse, Test, ListTestsPage, ListTestsFixedSizeCollection> { + + public static ApiFuture createAsync( + PageContext context, + ApiFuture futureResponse) { + ApiFuture futurePage = + ListTestsPage.createEmptyPage().createPageAsync(context, futureResponse); + return ApiFutures.transform( + futurePage, input -> new ListTestsPagedResponse(input), MoreExecutors.directExecutor()); + } + + private ListTestsPagedResponse(ListTestsPage page) { + super(page, ListTestsFixedSizeCollection.createEmptyCollection()); + } + } + + public static class ListTestsPage + extends AbstractPage { + + private ListTestsPage( + PageContext context, + ListTestsResponse response) { + super(context, response); + } + + private static ListTestsPage createEmptyPage() { + return new ListTestsPage(null, null); + } + + @Override + protected ListTestsPage createPage( + PageContext context, + ListTestsResponse response) { + return new ListTestsPage(context, response); + } + + @Override + public ApiFuture createPageAsync( + PageContext context, + ApiFuture futureResponse) { + return super.createPageAsync(context, futureResponse); + } + } + + public static class ListTestsFixedSizeCollection + extends AbstractFixedSizeCollection< + ListTestsRequest, ListTestsResponse, Test, ListTestsPage, ListTestsFixedSizeCollection> { + + private ListTestsFixedSizeCollection(List pages, int collectionSize) { + super(pages, collectionSize); + } + + private static ListTestsFixedSizeCollection createEmptyCollection() { + return new ListTestsFixedSizeCollection(null, 0); + } + + @Override + protected ListTestsFixedSizeCollection createCollection( + List pages, int collectionSize) { + return new ListTestsFixedSizeCollection(pages, collectionSize); + } + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/TestingClientHttpJsonTest.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/TestingClientHttpJsonTest.java new file mode 100644 index 0000000000..b16824b565 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/TestingClientHttpJsonTest.java @@ -0,0 +1,472 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import static com.google.showcase.v1beta1.TestingClient.ListSessionsPagedResponse; +import static com.google.showcase.v1beta1.TestingClient.ListTestsPagedResponse; + +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.testing.MockHttpService; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ApiException; +import com.google.api.gax.rpc.ApiExceptionFactory; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.testing.FakeStatusCode; +import com.google.common.collect.Lists; +import com.google.protobuf.ByteString; +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.stub.HttpJsonTestingStub; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class TestingClientHttpJsonTest { + private static MockHttpService mockService; + private static TestingClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonTestingStub.getMethodDescriptors(), TestingSettings.getDefaultEndpoint()); + TestingSettings settings = + TestingSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + TestingSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = TestingClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void createSessionTest() throws Exception { + Session expectedResponse = + Session.newBuilder().setName(SessionName.of("[SESSION]").toString()).build(); + mockService.addResponse(expectedResponse); + + CreateSessionRequest request = + CreateSessionRequest.newBuilder().setSession(Session.newBuilder().build()).build(); + + Session actualResponse = client.createSession(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createSessionExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + CreateSessionRequest request = + CreateSessionRequest.newBuilder().setSession(Session.newBuilder().build()).build(); + client.createSession(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getSessionTest() throws Exception { + Session expectedResponse = + Session.newBuilder().setName(SessionName.of("[SESSION]").toString()).build(); + mockService.addResponse(expectedResponse); + + GetSessionRequest request = + GetSessionRequest.newBuilder().setName(SessionName.of("[SESSION]").toString()).build(); + + Session actualResponse = client.getSession(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getSessionExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GetSessionRequest request = + GetSessionRequest.newBuilder().setName(SessionName.of("[SESSION]").toString()).build(); + client.getSession(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listSessionsTest() throws Exception { + Session responsesElement = Session.newBuilder().build(); + ListSessionsResponse expectedResponse = + ListSessionsResponse.newBuilder() + .setNextPageToken("") + .addAllSessions(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + ListSessionsRequest request = + ListSessionsRequest.newBuilder() + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + + ListSessionsPagedResponse pagedListResponse = client.listSessions(request); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getSessionsList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listSessionsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ListSessionsRequest request = + ListSessionsRequest.newBuilder() + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + client.listSessions(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteSessionTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + DeleteSessionRequest request = + DeleteSessionRequest.newBuilder().setName(SessionName.of("[SESSION]").toString()).build(); + + client.deleteSession(request); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteSessionExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + DeleteSessionRequest request = + DeleteSessionRequest.newBuilder().setName(SessionName.of("[SESSION]").toString()).build(); + client.deleteSession(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void reportSessionTest() throws Exception { + ReportSessionResponse expectedResponse = + ReportSessionResponse.newBuilder().addAllTestRuns(new ArrayList()).build(); + mockService.addResponse(expectedResponse); + + ReportSessionRequest request = + ReportSessionRequest.newBuilder().setName(SessionName.of("[SESSION]").toString()).build(); + + ReportSessionResponse actualResponse = client.reportSession(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void reportSessionExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ReportSessionRequest request = + ReportSessionRequest.newBuilder().setName(SessionName.of("[SESSION]").toString()).build(); + client.reportSession(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listTestsTest() throws Exception { + com.google.showcase.v1beta1.Test responsesElement = + com.google.showcase.v1beta1.Test.newBuilder().build(); + ListTestsResponse expectedResponse = + ListTestsResponse.newBuilder() + .setNextPageToken("") + .addAllTests(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + ListTestsRequest request = + ListTestsRequest.newBuilder() + .setParent(SessionName.of("[SESSION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + + ListTestsPagedResponse pagedListResponse = client.listTests(request); + + List resources = + Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getTestsList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listTestsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ListTestsRequest request = + ListTestsRequest.newBuilder() + .setParent(SessionName.of("[SESSION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + client.listTests(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteTestTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + DeleteTestRequest request = + DeleteTestRequest.newBuilder() + .setName(TestName.of("[SESSION]", "[TEST]").toString()) + .build(); + + client.deleteTest(request); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteTestExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + DeleteTestRequest request = + DeleteTestRequest.newBuilder() + .setName(TestName.of("[SESSION]", "[TEST]").toString()) + .build(); + client.deleteTest(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void verifyTestTest() throws Exception { + VerifyTestResponse expectedResponse = + VerifyTestResponse.newBuilder().setIssue(Issue.newBuilder().build()).build(); + mockService.addResponse(expectedResponse); + + VerifyTestRequest request = + VerifyTestRequest.newBuilder() + .setName(TestName.of("[SESSION]", "[TEST]").toString()) + .setAnswer(ByteString.EMPTY) + .addAllAnswers(new ArrayList()) + .build(); + + VerifyTestResponse actualResponse = client.verifyTest(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void verifyTestExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + VerifyTestRequest request = + VerifyTestRequest.newBuilder() + .setName(TestName.of("[SESSION]", "[TEST]").toString()) + .setAnswer(ByteString.EMPTY) + .addAllAnswers(new ArrayList()) + .build(); + client.verifyTest(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/TestingClientTest.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/TestingClientTest.java new file mode 100644 index 0000000000..27ac6b9632 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/TestingClientTest.java @@ -0,0 +1,433 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import static com.google.showcase.v1beta1.TestingClient.ListSessionsPagedResponse; +import static com.google.showcase.v1beta1.TestingClient.ListTestsPagedResponse; + +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.grpc.GaxGrpcProperties; +import com.google.api.gax.grpc.testing.LocalChannelProvider; +import com.google.api.gax.grpc.testing.MockGrpcService; +import com.google.api.gax.grpc.testing.MockServiceHelper; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.common.collect.Lists; +import com.google.protobuf.AbstractMessage; +import com.google.protobuf.ByteString; +import com.google.protobuf.Empty; +import io.grpc.StatusRuntimeException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.UUID; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class TestingClientTest { + private static MockServiceHelper mockServiceHelper; + private static MockTesting mockTesting; + private LocalChannelProvider channelProvider; + private TestingClient client; + + @BeforeClass + public static void startStaticServer() { + mockTesting = new MockTesting(); + mockServiceHelper = + new MockServiceHelper( + UUID.randomUUID().toString(), Arrays.asList(mockTesting)); + mockServiceHelper.start(); + } + + @AfterClass + public static void stopServer() { + mockServiceHelper.stop(); + } + + @Before + public void setUp() throws IOException { + mockServiceHelper.reset(); + channelProvider = mockServiceHelper.createChannelProvider(); + TestingSettings settings = + TestingSettings.newBuilder() + .setTransportChannelProvider(channelProvider) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = TestingClient.create(settings); + } + + @After + public void tearDown() throws Exception { + client.close(); + } + + @Test + public void createSessionTest() throws Exception { + Session expectedResponse = + Session.newBuilder().setName(SessionName.of("[SESSION]").toString()).build(); + mockTesting.addResponse(expectedResponse); + + CreateSessionRequest request = + CreateSessionRequest.newBuilder().setSession(Session.newBuilder().build()).build(); + + Session actualResponse = client.createSession(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockTesting.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CreateSessionRequest actualRequest = ((CreateSessionRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getSession(), actualRequest.getSession()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void createSessionExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockTesting.addException(exception); + + try { + CreateSessionRequest request = + CreateSessionRequest.newBuilder().setSession(Session.newBuilder().build()).build(); + client.createSession(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getSessionTest() throws Exception { + Session expectedResponse = + Session.newBuilder().setName(SessionName.of("[SESSION]").toString()).build(); + mockTesting.addResponse(expectedResponse); + + GetSessionRequest request = + GetSessionRequest.newBuilder().setName(SessionName.of("[SESSION]").toString()).build(); + + Session actualResponse = client.getSession(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockTesting.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + GetSessionRequest actualRequest = ((GetSessionRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getName(), actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void getSessionExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockTesting.addException(exception); + + try { + GetSessionRequest request = + GetSessionRequest.newBuilder().setName(SessionName.of("[SESSION]").toString()).build(); + client.getSession(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listSessionsTest() throws Exception { + Session responsesElement = Session.newBuilder().build(); + ListSessionsResponse expectedResponse = + ListSessionsResponse.newBuilder() + .setNextPageToken("") + .addAllSessions(Arrays.asList(responsesElement)) + .build(); + mockTesting.addResponse(expectedResponse); + + ListSessionsRequest request = + ListSessionsRequest.newBuilder() + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + + ListSessionsPagedResponse pagedListResponse = client.listSessions(request); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getSessionsList().get(0), resources.get(0)); + + List actualRequests = mockTesting.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListSessionsRequest actualRequest = ((ListSessionsRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getPageSize(), actualRequest.getPageSize()); + Assert.assertEquals(request.getPageToken(), actualRequest.getPageToken()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void listSessionsExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockTesting.addException(exception); + + try { + ListSessionsRequest request = + ListSessionsRequest.newBuilder() + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + client.listSessions(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteSessionTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockTesting.addResponse(expectedResponse); + + DeleteSessionRequest request = + DeleteSessionRequest.newBuilder().setName(SessionName.of("[SESSION]").toString()).build(); + + client.deleteSession(request); + + List actualRequests = mockTesting.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + DeleteSessionRequest actualRequest = ((DeleteSessionRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getName(), actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void deleteSessionExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockTesting.addException(exception); + + try { + DeleteSessionRequest request = + DeleteSessionRequest.newBuilder().setName(SessionName.of("[SESSION]").toString()).build(); + client.deleteSession(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void reportSessionTest() throws Exception { + ReportSessionResponse expectedResponse = + ReportSessionResponse.newBuilder().addAllTestRuns(new ArrayList()).build(); + mockTesting.addResponse(expectedResponse); + + ReportSessionRequest request = + ReportSessionRequest.newBuilder().setName(SessionName.of("[SESSION]").toString()).build(); + + ReportSessionResponse actualResponse = client.reportSession(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockTesting.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ReportSessionRequest actualRequest = ((ReportSessionRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getName(), actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void reportSessionExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockTesting.addException(exception); + + try { + ReportSessionRequest request = + ReportSessionRequest.newBuilder().setName(SessionName.of("[SESSION]").toString()).build(); + client.reportSession(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listTestsTest() throws Exception { + com.google.showcase.v1beta1.Test responsesElement = + com.google.showcase.v1beta1.Test.newBuilder().build(); + ListTestsResponse expectedResponse = + ListTestsResponse.newBuilder() + .setNextPageToken("") + .addAllTests(Arrays.asList(responsesElement)) + .build(); + mockTesting.addResponse(expectedResponse); + + ListTestsRequest request = + ListTestsRequest.newBuilder() + .setParent(SessionName.of("[SESSION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + + ListTestsPagedResponse pagedListResponse = client.listTests(request); + + List resources = + Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getTestsList().get(0), resources.get(0)); + + List actualRequests = mockTesting.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListTestsRequest actualRequest = ((ListTestsRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getParent(), actualRequest.getParent()); + Assert.assertEquals(request.getPageSize(), actualRequest.getPageSize()); + Assert.assertEquals(request.getPageToken(), actualRequest.getPageToken()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void listTestsExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockTesting.addException(exception); + + try { + ListTestsRequest request = + ListTestsRequest.newBuilder() + .setParent(SessionName.of("[SESSION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + client.listTests(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteTestTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockTesting.addResponse(expectedResponse); + + DeleteTestRequest request = + DeleteTestRequest.newBuilder() + .setName(TestName.of("[SESSION]", "[TEST]").toString()) + .build(); + + client.deleteTest(request); + + List actualRequests = mockTesting.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + DeleteTestRequest actualRequest = ((DeleteTestRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getName(), actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void deleteTestExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockTesting.addException(exception); + + try { + DeleteTestRequest request = + DeleteTestRequest.newBuilder() + .setName(TestName.of("[SESSION]", "[TEST]").toString()) + .build(); + client.deleteTest(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void verifyTestTest() throws Exception { + VerifyTestResponse expectedResponse = + VerifyTestResponse.newBuilder().setIssue(Issue.newBuilder().build()).build(); + mockTesting.addResponse(expectedResponse); + + VerifyTestRequest request = + VerifyTestRequest.newBuilder() + .setName(TestName.of("[SESSION]", "[TEST]").toString()) + .setAnswer(ByteString.EMPTY) + .addAllAnswers(new ArrayList()) + .build(); + + VerifyTestResponse actualResponse = client.verifyTest(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockTesting.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + VerifyTestRequest actualRequest = ((VerifyTestRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getName(), actualRequest.getName()); + Assert.assertEquals(request.getAnswer(), actualRequest.getAnswer()); + Assert.assertEquals(request.getAnswersList(), actualRequest.getAnswersList()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void verifyTestExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockTesting.addException(exception); + + try { + VerifyTestRequest request = + VerifyTestRequest.newBuilder() + .setName(TestName.of("[SESSION]", "[TEST]").toString()) + .setAnswer(ByteString.EMPTY) + .addAllAnswers(new ArrayList()) + .build(); + client.verifyTest(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/TestingSettings.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/TestingSettings.java new file mode 100644 index 0000000000..0a59e67a92 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/TestingSettings.java @@ -0,0 +1,286 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import static com.google.showcase.v1beta1.TestingClient.ListSessionsPagedResponse; +import static com.google.showcase.v1beta1.TestingClient.ListTestsPagedResponse; + +import com.google.api.core.ApiFunction; +import com.google.api.core.BetaApi; +import com.google.api.gax.core.GoogleCredentialsProvider; +import com.google.api.gax.core.InstantiatingExecutorProvider; +import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientSettings; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.StubSettings; +import com.google.api.gax.rpc.TransportChannelProvider; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.stub.TestingStubSettings; +import java.io.IOException; +import java.util.List; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * Settings class to configure an instance of {@link TestingClient}. + * + *

The default instance has everything set to sensible defaults: + * + *

    + *
  • The default service address (localhost) and default port (7469) are used. + *
  • Credentials are acquired automatically through Application Default Credentials. + *
  • Retries are configured for idempotent methods but not for non-idempotent methods. + *
+ * + *

The builder of this class is recursive, so contained classes are themselves builders. When + * build() is called, the tree of builders is called to create the complete settings object. + * + *

For example, to set the total timeout of createSession to 30 seconds: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * TestingSettings.Builder testingSettingsBuilder = TestingSettings.newBuilder();
+ * testingSettingsBuilder
+ *     .createSessionSettings()
+ *     .setRetrySettings(
+ *         testingSettingsBuilder
+ *             .createSessionSettings()
+ *             .getRetrySettings()
+ *             .toBuilder()
+ *             .setTotalTimeout(Duration.ofSeconds(30))
+ *             .build());
+ * TestingSettings testingSettings = testingSettingsBuilder.build();
+ * }
+ */ +@BetaApi +@Generated("by gapic-generator-java") +public class TestingSettings extends ClientSettings { + + /** Returns the object with the settings used for calls to createSession. */ + public UnaryCallSettings createSessionSettings() { + return ((TestingStubSettings) getStubSettings()).createSessionSettings(); + } + + /** Returns the object with the settings used for calls to getSession. */ + public UnaryCallSettings getSessionSettings() { + return ((TestingStubSettings) getStubSettings()).getSessionSettings(); + } + + /** Returns the object with the settings used for calls to listSessions. */ + public PagedCallSettings + listSessionsSettings() { + return ((TestingStubSettings) getStubSettings()).listSessionsSettings(); + } + + /** Returns the object with the settings used for calls to deleteSession. */ + public UnaryCallSettings deleteSessionSettings() { + return ((TestingStubSettings) getStubSettings()).deleteSessionSettings(); + } + + /** Returns the object with the settings used for calls to reportSession. */ + public UnaryCallSettings reportSessionSettings() { + return ((TestingStubSettings) getStubSettings()).reportSessionSettings(); + } + + /** Returns the object with the settings used for calls to listTests. */ + public PagedCallSettings + listTestsSettings() { + return ((TestingStubSettings) getStubSettings()).listTestsSettings(); + } + + /** Returns the object with the settings used for calls to deleteTest. */ + public UnaryCallSettings deleteTestSettings() { + return ((TestingStubSettings) getStubSettings()).deleteTestSettings(); + } + + /** Returns the object with the settings used for calls to verifyTest. */ + public UnaryCallSettings verifyTestSettings() { + return ((TestingStubSettings) getStubSettings()).verifyTestSettings(); + } + + public static final TestingSettings create(TestingStubSettings stub) throws IOException { + return new TestingSettings.Builder(stub.toBuilder()).build(); + } + + /** Returns a builder for the default ExecutorProvider for this service. */ + public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { + return TestingStubSettings.defaultExecutorProviderBuilder(); + } + + /** Returns the default service endpoint. */ + public static String getDefaultEndpoint() { + return TestingStubSettings.getDefaultEndpoint(); + } + + /** Returns the default service scopes. */ + public static List getDefaultServiceScopes() { + return TestingStubSettings.getDefaultServiceScopes(); + } + + /** Returns a builder for the default credentials for this service. */ + public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { + return TestingStubSettings.defaultCredentialsProviderBuilder(); + } + + /** Returns a builder for the default gRPC ChannelProvider for this service. */ + public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { + return TestingStubSettings.defaultGrpcTransportProviderBuilder(); + } + + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return TestingStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + + public static TransportChannelProvider defaultTransportChannelProvider() { + return TestingStubSettings.defaultTransportChannelProvider(); + } + + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return TestingStubSettings.defaultApiClientHeaderProviderBuilder(); + } + + /** Returns a new gRPC builder for this class. */ + public static Builder newBuilder() { + return Builder.createDefault(); + } + + /** Returns a new REST builder for this class. */ + @BetaApi + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder(ClientContext clientContext) { + return new Builder(clientContext); + } + + /** Returns a builder containing all the values of this settings class. */ + public Builder toBuilder() { + return new Builder(this); + } + + protected TestingSettings(Builder settingsBuilder) throws IOException { + super(settingsBuilder); + } + + /** Builder for TestingSettings. */ + public static class Builder extends ClientSettings.Builder { + + protected Builder() throws IOException { + this(((ClientContext) null)); + } + + protected Builder(ClientContext clientContext) { + super(TestingStubSettings.newBuilder(clientContext)); + } + + protected Builder(TestingSettings settings) { + super(settings.getStubSettings().toBuilder()); + } + + protected Builder(TestingStubSettings.Builder stubSettings) { + super(stubSettings); + } + + private static Builder createDefault() { + return new Builder(TestingStubSettings.newBuilder()); + } + + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(TestingStubSettings.newHttpJsonBuilder()); + } + + public TestingStubSettings.Builder getStubSettingsBuilder() { + return ((TestingStubSettings.Builder) getStubSettings()); + } + + /** + * Applies the given settings updater function to all of the unary API methods in this service. + * + *

Note: This method does not support applying settings to streaming methods. + */ + public Builder applyToAllUnaryMethods( + ApiFunction, Void> settingsUpdater) { + super.applyToAllUnaryMethods( + getStubSettingsBuilder().unaryMethodSettingsBuilders(), settingsUpdater); + return this; + } + + /** Returns the builder for the settings used for calls to createSession. */ + public UnaryCallSettings.Builder createSessionSettings() { + return getStubSettingsBuilder().createSessionSettings(); + } + + /** Returns the builder for the settings used for calls to getSession. */ + public UnaryCallSettings.Builder getSessionSettings() { + return getStubSettingsBuilder().getSessionSettings(); + } + + /** Returns the builder for the settings used for calls to listSessions. */ + public PagedCallSettings.Builder< + ListSessionsRequest, ListSessionsResponse, ListSessionsPagedResponse> + listSessionsSettings() { + return getStubSettingsBuilder().listSessionsSettings(); + } + + /** Returns the builder for the settings used for calls to deleteSession. */ + public UnaryCallSettings.Builder deleteSessionSettings() { + return getStubSettingsBuilder().deleteSessionSettings(); + } + + /** Returns the builder for the settings used for calls to reportSession. */ + public UnaryCallSettings.Builder + reportSessionSettings() { + return getStubSettingsBuilder().reportSessionSettings(); + } + + /** Returns the builder for the settings used for calls to listTests. */ + public PagedCallSettings.Builder + listTestsSettings() { + return getStubSettingsBuilder().listTestsSettings(); + } + + /** Returns the builder for the settings used for calls to deleteTest. */ + public UnaryCallSettings.Builder deleteTestSettings() { + return getStubSettingsBuilder().deleteTestSettings(); + } + + /** Returns the builder for the settings used for calls to verifyTest. */ + public UnaryCallSettings.Builder verifyTestSettings() { + return getStubSettingsBuilder().verifyTestSettings(); + } + + @Override + public TestingSettings build() throws IOException { + return new TestingSettings(this); + } + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/UserName.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/UserName.java new file mode 100644 index 0000000000..df5a3618b7 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/UserName.java @@ -0,0 +1,166 @@ +/* + * 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 + * + * https://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.showcase.v1beta1; + +import com.google.api.pathtemplate.PathTemplate; +import com.google.api.resourcenames.ResourceName; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableMap; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +@Generated("by gapic-generator-java") +public class UserName implements ResourceName { + private static final PathTemplate USER = PathTemplate.createWithoutUrlEncoding("users/{user}"); + private volatile Map fieldValuesMap; + private final String user; + + @Deprecated + protected UserName() { + user = null; + } + + private UserName(Builder builder) { + user = Preconditions.checkNotNull(builder.getUser()); + } + + public String getUser() { + return user; + } + + public static Builder newBuilder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder(this); + } + + public static UserName of(String user) { + return newBuilder().setUser(user).build(); + } + + public static String format(String user) { + return newBuilder().setUser(user).build().toString(); + } + + public static UserName parse(String formattedString) { + if (formattedString.isEmpty()) { + return null; + } + Map matchMap = + USER.validatedMatch(formattedString, "UserName.parse: formattedString not in valid format"); + return of(matchMap.get("user")); + } + + public static List parseList(List formattedStrings) { + List list = new ArrayList<>(formattedStrings.size()); + for (String formattedString : formattedStrings) { + list.add(parse(formattedString)); + } + return list; + } + + public static List toStringList(List values) { + List list = new ArrayList<>(values.size()); + for (UserName value : values) { + if (value == null) { + list.add(""); + } else { + list.add(value.toString()); + } + } + return list; + } + + public static boolean isParsableFrom(String formattedString) { + return USER.matches(formattedString); + } + + @Override + public Map getFieldValuesMap() { + if (fieldValuesMap == null) { + synchronized (this) { + if (fieldValuesMap == null) { + ImmutableMap.Builder fieldMapBuilder = ImmutableMap.builder(); + if (user != null) { + fieldMapBuilder.put("user", user); + } + fieldValuesMap = fieldMapBuilder.build(); + } + } + } + return fieldValuesMap; + } + + public String getFieldValue(String fieldName) { + return getFieldValuesMap().get(fieldName); + } + + @Override + public String toString() { + return USER.instantiate("user", user); + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o != null || getClass() == o.getClass()) { + UserName that = ((UserName) o); + return Objects.equals(this.user, that.user); + } + return false; + } + + @Override + public int hashCode() { + int h = 1; + h *= 1000003; + h ^= Objects.hashCode(user); + return h; + } + + /** Builder for users/{user}. */ + public static class Builder { + private String user; + + protected Builder() {} + + public String getUser() { + return user; + } + + public Builder setUser(String user) { + this.user = user; + return this; + } + + private Builder(UserName userName) { + this.user = userName.user; + } + + public UserName build() { + return new UserName(this); + } + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/gapic_metadata.json b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/gapic_metadata.json new file mode 100644 index 0000000000..31f51f17ef --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/gapic_metadata.json @@ -0,0 +1,210 @@ +{ + "schema": "1.0", + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "java", + "protoPackage": "google.showcase.v1beta1", + "libraryPackage": "com.google.showcase.v1beta1", + "services": { + "Compliance": { + "clients": { + "grpc": { + "libraryClient": "ComplianceClient", + "rpcs": { + "GetEnum": { + "methods": ["getEnum", "getEnumCallable"] + }, + "RepeatDataBody": { + "methods": ["repeatDataBody", "repeatDataBodyCallable"] + }, + "RepeatDataBodyInfo": { + "methods": ["repeatDataBodyInfo", "repeatDataBodyInfoCallable"] + }, + "RepeatDataBodyPatch": { + "methods": ["repeatDataBodyPatch", "repeatDataBodyPatchCallable"] + }, + "RepeatDataBodyPut": { + "methods": ["repeatDataBodyPut", "repeatDataBodyPutCallable"] + }, + "RepeatDataPathResource": { + "methods": ["repeatDataPathResource", "repeatDataPathResourceCallable"] + }, + "RepeatDataPathTrailingResource": { + "methods": ["repeatDataPathTrailingResource", "repeatDataPathTrailingResourceCallable"] + }, + "RepeatDataQuery": { + "methods": ["repeatDataQuery", "repeatDataQueryCallable"] + }, + "RepeatDataSimplePath": { + "methods": ["repeatDataSimplePath", "repeatDataSimplePathCallable"] + }, + "VerifyEnum": { + "methods": ["verifyEnum", "verifyEnumCallable"] + } + } + } + } + }, + "Echo": { + "clients": { + "grpc": { + "libraryClient": "EchoClient", + "rpcs": { + "Block": { + "methods": ["block", "blockCallable"] + }, + "Chat": { + "methods": ["chatCallable"] + }, + "Collect": { + "methods": ["collectCallable"] + }, + "Echo": { + "methods": ["echo", "echoCallable"] + }, + "Expand": { + "methods": ["expandCallable"] + }, + "PagedExpand": { + "methods": ["pagedExpand", "pagedExpandPagedCallable", "pagedExpandCallable"] + }, + "PagedExpandLegacy": { + "methods": ["pagedExpandLegacy", "pagedExpandLegacyCallable"] + }, + "PagedExpandLegacyMapped": { + "methods": ["pagedExpandLegacyMapped", "pagedExpandLegacyMappedPagedCallable", "pagedExpandLegacyMappedCallable"] + }, + "Wait": { + "methods": ["waitAsync", "waitOperationCallable", "waitCallable"] + } + } + } + } + }, + "Identity": { + "clients": { + "grpc": { + "libraryClient": "IdentityClient", + "rpcs": { + "CreateUser": { + "methods": ["createUser", "createUser", "createUser", "createUserCallable"] + }, + "DeleteUser": { + "methods": ["deleteUser", "deleteUser", "deleteUser", "deleteUserCallable"] + }, + "GetUser": { + "methods": ["getUser", "getUser", "getUser", "getUserCallable"] + }, + "ListUsers": { + "methods": ["listUsers", "listUsersPagedCallable", "listUsersCallable"] + }, + "UpdateUser": { + "methods": ["updateUser", "updateUserCallable"] + } + } + } + } + }, + "Messaging": { + "clients": { + "grpc": { + "libraryClient": "MessagingClient", + "rpcs": { + "Connect": { + "methods": ["connectCallable"] + }, + "CreateBlurb": { + "methods": ["createBlurb", "createBlurb", "createBlurb", "createBlurb", "createBlurb", "createBlurb", "createBlurb", "createBlurb", "createBlurb", "createBlurb", "createBlurb", "createBlurb", "createBlurb", "createBlurbCallable"] + }, + "CreateRoom": { + "methods": ["createRoom", "createRoom", "createRoomCallable"] + }, + "DeleteBlurb": { + "methods": ["deleteBlurb", "deleteBlurb", "deleteBlurb", "deleteBlurbCallable"] + }, + "DeleteRoom": { + "methods": ["deleteRoom", "deleteRoom", "deleteRoom", "deleteRoomCallable"] + }, + "GetBlurb": { + "methods": ["getBlurb", "getBlurb", "getBlurb", "getBlurbCallable"] + }, + "GetRoom": { + "methods": ["getRoom", "getRoom", "getRoom", "getRoomCallable"] + }, + "ListBlurbs": { + "methods": ["listBlurbs", "listBlurbs", "listBlurbs", "listBlurbs", "listBlurbsPagedCallable", "listBlurbsCallable"] + }, + "ListRooms": { + "methods": ["listRooms", "listRoomsPagedCallable", "listRoomsCallable"] + }, + "SearchBlurbs": { + "methods": ["searchBlurbsAsync", "searchBlurbsAsync", "searchBlurbsAsync", "searchBlurbsAsync", "searchBlurbsOperationCallable", "searchBlurbsCallable"] + }, + "SendBlurbs": { + "methods": ["sendBlurbsCallable"] + }, + "StreamBlurbs": { + "methods": ["streamBlurbsCallable"] + }, + "UpdateBlurb": { + "methods": ["updateBlurb", "updateBlurbCallable"] + }, + "UpdateRoom": { + "methods": ["updateRoom", "updateRoomCallable"] + } + } + } + } + }, + "SequenceService": { + "clients": { + "grpc": { + "libraryClient": "SequenceServiceClient", + "rpcs": { + "AttemptSequence": { + "methods": ["attemptSequence", "attemptSequence", "attemptSequence", "attemptSequenceCallable"] + }, + "CreateSequence": { + "methods": ["createSequence", "createSequence", "createSequenceCallable"] + }, + "GetSequenceReport": { + "methods": ["getSequenceReport", "getSequenceReport", "getSequenceReport", "getSequenceReportCallable"] + } + } + } + } + }, + "Testing": { + "clients": { + "grpc": { + "libraryClient": "TestingClient", + "rpcs": { + "CreateSession": { + "methods": ["createSession", "createSessionCallable"] + }, + "DeleteSession": { + "methods": ["deleteSession", "deleteSessionCallable"] + }, + "DeleteTest": { + "methods": ["deleteTest", "deleteTestCallable"] + }, + "GetSession": { + "methods": ["getSession", "getSessionCallable"] + }, + "ListSessions": { + "methods": ["listSessions", "listSessionsPagedCallable", "listSessionsCallable"] + }, + "ListTests": { + "methods": ["listTests", "listTestsPagedCallable", "listTestsCallable"] + }, + "ReportSession": { + "methods": ["reportSession", "reportSessionCallable"] + }, + "VerifyTest": { + "methods": ["verifyTest", "verifyTestCallable"] + } + } + } + } + } + } +} \ No newline at end of file diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/package-info.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/package-info.java new file mode 100644 index 0000000000..be1926a090 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/package-info.java @@ -0,0 +1,162 @@ +/* + * 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 + * + * https://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. + */ + +/** + * A client to Client Libraries Showcase API + * + *

The interfaces provided are listed below, along with usage samples. + * + *

======================= ComplianceClient ======================= + * + *

Service Description: This service is used to test that GAPICs implement various REST-related + * features correctly. This mostly means transcoding proto3 requests to REST format correctly for + * various types of HTTP annotations, but it also includes verifying that unknown (numeric) enums + * received by clients can be round-tripped correctly. + * + *

Sample for ComplianceClient: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (ComplianceClient complianceClient = ComplianceClient.create()) {
+ *   RepeatRequest request =
+ *       RepeatRequest.newBuilder()
+ *           .setName("name3373707")
+ *           .setInfo(ComplianceData.newBuilder().build())
+ *           .setServerVerify(true)
+ *           .setIntendedBindingUri("intendedBindingUri780142386")
+ *           .setFInt32(-1143775883)
+ *           .setFInt64(-1143775788)
+ *           .setFDouble(-1239459382)
+ *           .setPInt32(-858673665)
+ *           .setPInt64(-858673570)
+ *           .setPDouble(-991225216)
+ *           .build();
+ *   RepeatResponse response = complianceClient.repeatDataBody(request);
+ * }
+ * }
+ * + *

======================= EchoClient ======================= + * + *

Service Description: This service is used showcase the four main types of rpcs - unary, server + * side streaming, client side streaming, and bidirectional streaming. This service also exposes + * methods that explicitly implement server delay, and paginated calls. Set the 'showcase-trailer' + * metadata key on any method to have the values echoed in the response trailers. Set the + * 'x-goog-request-params' metadata key on any method to have the values echoed in the response + * headers. + * + *

Sample for EchoClient: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (EchoClient echoClient = EchoClient.create()) {
+ *   EchoRequest request =
+ *       EchoRequest.newBuilder()
+ *           .setSeverity(Severity.forNumber(0))
+ *           .setHeader("header-1221270899")
+ *           .setOtherHeader("otherHeader-2026585667")
+ *           .build();
+ *   EchoResponse response = echoClient.echo(request);
+ * }
+ * }
+ * + *

======================= IdentityClient ======================= + * + *

Service Description: A simple identity service. + * + *

Sample for IdentityClient: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (IdentityClient identityClient = IdentityClient.create()) {
+ *   String displayName = "displayName1714148973";
+ *   String email = "email96619420";
+ *   User response = identityClient.createUser(displayName, email);
+ * }
+ * }
+ * + *

======================= MessagingClient ======================= + * + *

Service Description: A simple messaging service that implements chat rooms and profile posts. + * + *

This messaging service showcases the features that API clients generated by gapic-generators + * implement. + * + *

Sample for MessagingClient: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (MessagingClient messagingClient = MessagingClient.create()) {
+ *   String displayName = "displayName1714148973";
+ *   String description = "description-1724546052";
+ *   Room response = messagingClient.createRoom(displayName, description);
+ * }
+ * }
+ * + *

======================= SequenceServiceClient ======================= + * + *

Sample for SequenceServiceClient: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (SequenceServiceClient sequenceServiceClient = SequenceServiceClient.create()) {
+ *   Sequence sequence = Sequence.newBuilder().build();
+ *   Sequence response = sequenceServiceClient.createSequence(sequence);
+ * }
+ * }
+ * + *

======================= TestingClient ======================= + * + *

Service Description: A service to facilitate running discrete sets of tests against Showcase. + * + *

Sample for TestingClient: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (TestingClient testingClient = TestingClient.create()) {
+ *   CreateSessionRequest request =
+ *       CreateSessionRequest.newBuilder().setSession(Session.newBuilder().build()).build();
+ *   Session response = testingClient.createSession(request);
+ * }
+ * }
+ */ +@Generated("by gapic-generator-java") +package com.google.showcase.v1beta1; + +import javax.annotation.Generated; diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/ComplianceStub.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/ComplianceStub.java new file mode 100644 index 0000000000..c4f54eb557 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/ComplianceStub.java @@ -0,0 +1,81 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.showcase.v1beta1.EnumRequest; +import com.google.showcase.v1beta1.EnumResponse; +import com.google.showcase.v1beta1.RepeatRequest; +import com.google.showcase.v1beta1.RepeatResponse; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * Base stub class for the Compliance service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public abstract class ComplianceStub implements BackgroundResource { + + public UnaryCallable repeatDataBodyCallable() { + throw new UnsupportedOperationException("Not implemented: repeatDataBodyCallable()"); + } + + public UnaryCallable repeatDataBodyInfoCallable() { + throw new UnsupportedOperationException("Not implemented: repeatDataBodyInfoCallable()"); + } + + public UnaryCallable repeatDataQueryCallable() { + throw new UnsupportedOperationException("Not implemented: repeatDataQueryCallable()"); + } + + public UnaryCallable repeatDataSimplePathCallable() { + throw new UnsupportedOperationException("Not implemented: repeatDataSimplePathCallable()"); + } + + public UnaryCallable repeatDataPathResourceCallable() { + throw new UnsupportedOperationException("Not implemented: repeatDataPathResourceCallable()"); + } + + public UnaryCallable repeatDataPathTrailingResourceCallable() { + throw new UnsupportedOperationException( + "Not implemented: repeatDataPathTrailingResourceCallable()"); + } + + public UnaryCallable repeatDataBodyPutCallable() { + throw new UnsupportedOperationException("Not implemented: repeatDataBodyPutCallable()"); + } + + public UnaryCallable repeatDataBodyPatchCallable() { + throw new UnsupportedOperationException("Not implemented: repeatDataBodyPatchCallable()"); + } + + public UnaryCallable getEnumCallable() { + throw new UnsupportedOperationException("Not implemented: getEnumCallable()"); + } + + public UnaryCallable verifyEnumCallable() { + throw new UnsupportedOperationException("Not implemented: verifyEnumCallable()"); + } + + @Override + public abstract void close(); +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/ComplianceStubSettings.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/ComplianceStubSettings.java new file mode 100644 index 0000000000..67b16b6fac --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/ComplianceStubSettings.java @@ -0,0 +1,526 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub; + +import com.google.api.core.ApiFunction; +import com.google.api.core.BetaApi; +import com.google.api.gax.core.GaxProperties; +import com.google.api.gax.core.GoogleCredentialsProvider; +import com.google.api.gax.core.InstantiatingExecutorProvider; +import com.google.api.gax.grpc.GaxGrpcProperties; +import com.google.api.gax.grpc.GrpcTransportChannel; +import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.HttpJsonTransportChannel; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; +import com.google.api.gax.retrying.RetrySettings; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.StubSettings; +import com.google.api.gax.rpc.TransportChannelProvider; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Lists; +import com.google.showcase.v1beta1.EnumRequest; +import com.google.showcase.v1beta1.EnumResponse; +import com.google.showcase.v1beta1.RepeatRequest; +import com.google.showcase.v1beta1.RepeatResponse; +import java.io.IOException; +import java.util.List; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * Settings class to configure an instance of {@link ComplianceStub}. + * + *

The default instance has everything set to sensible defaults: + * + *

    + *
  • The default service address (localhost) and default port (7469) are used. + *
  • Credentials are acquired automatically through Application Default Credentials. + *
  • Retries are configured for idempotent methods but not for non-idempotent methods. + *
+ * + *

The builder of this class is recursive, so contained classes are themselves builders. When + * build() is called, the tree of builders is called to create the complete settings object. + * + *

For example, to set the total timeout of repeatDataBody to 30 seconds: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * ComplianceStubSettings.Builder complianceSettingsBuilder = ComplianceStubSettings.newBuilder();
+ * complianceSettingsBuilder
+ *     .repeatDataBodySettings()
+ *     .setRetrySettings(
+ *         complianceSettingsBuilder
+ *             .repeatDataBodySettings()
+ *             .getRetrySettings()
+ *             .toBuilder()
+ *             .setTotalTimeout(Duration.ofSeconds(30))
+ *             .build());
+ * ComplianceStubSettings complianceSettings = complianceSettingsBuilder.build();
+ * }
+ */ +@BetaApi +@Generated("by gapic-generator-java") +public class ComplianceStubSettings extends StubSettings { + /** The default scopes of the service. */ + private static final ImmutableList DEFAULT_SERVICE_SCOPES = + ImmutableList.builder().build(); + + private final UnaryCallSettings repeatDataBodySettings; + private final UnaryCallSettings repeatDataBodyInfoSettings; + private final UnaryCallSettings repeatDataQuerySettings; + private final UnaryCallSettings repeatDataSimplePathSettings; + private final UnaryCallSettings repeatDataPathResourceSettings; + private final UnaryCallSettings + repeatDataPathTrailingResourceSettings; + private final UnaryCallSettings repeatDataBodyPutSettings; + private final UnaryCallSettings repeatDataBodyPatchSettings; + private final UnaryCallSettings getEnumSettings; + private final UnaryCallSettings verifyEnumSettings; + + /** Returns the object with the settings used for calls to repeatDataBody. */ + public UnaryCallSettings repeatDataBodySettings() { + return repeatDataBodySettings; + } + + /** Returns the object with the settings used for calls to repeatDataBodyInfo. */ + public UnaryCallSettings repeatDataBodyInfoSettings() { + return repeatDataBodyInfoSettings; + } + + /** Returns the object with the settings used for calls to repeatDataQuery. */ + public UnaryCallSettings repeatDataQuerySettings() { + return repeatDataQuerySettings; + } + + /** Returns the object with the settings used for calls to repeatDataSimplePath. */ + public UnaryCallSettings repeatDataSimplePathSettings() { + return repeatDataSimplePathSettings; + } + + /** Returns the object with the settings used for calls to repeatDataPathResource. */ + public UnaryCallSettings repeatDataPathResourceSettings() { + return repeatDataPathResourceSettings; + } + + /** Returns the object with the settings used for calls to repeatDataPathTrailingResource. */ + public UnaryCallSettings repeatDataPathTrailingResourceSettings() { + return repeatDataPathTrailingResourceSettings; + } + + /** Returns the object with the settings used for calls to repeatDataBodyPut. */ + public UnaryCallSettings repeatDataBodyPutSettings() { + return repeatDataBodyPutSettings; + } + + /** Returns the object with the settings used for calls to repeatDataBodyPatch. */ + public UnaryCallSettings repeatDataBodyPatchSettings() { + return repeatDataBodyPatchSettings; + } + + /** Returns the object with the settings used for calls to getEnum. */ + public UnaryCallSettings getEnumSettings() { + return getEnumSettings; + } + + /** Returns the object with the settings used for calls to verifyEnum. */ + public UnaryCallSettings verifyEnumSettings() { + return verifyEnumSettings; + } + + public ComplianceStub createStub() throws IOException { + if (getTransportChannelProvider() + .getTransportName() + .equals(GrpcTransportChannel.getGrpcTransportName())) { + return GrpcComplianceStub.create(this); + } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonComplianceStub.create(this); + } + throw new UnsupportedOperationException( + String.format( + "Transport not supported: %s", getTransportChannelProvider().getTransportName())); + } + + /** Returns a builder for the default ExecutorProvider for this service. */ + public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { + return InstantiatingExecutorProvider.newBuilder(); + } + + /** Returns the default service endpoint. */ + public static String getDefaultEndpoint() { + return "localhost:7469"; + } + + /** Returns the default mTLS service endpoint. */ + public static String getDefaultMtlsEndpoint() { + return "localhost:7469"; + } + + /** Returns the default service scopes. */ + public static List getDefaultServiceScopes() { + return DEFAULT_SERVICE_SCOPES; + } + + /** Returns a builder for the default credentials for this service. */ + public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { + return GoogleCredentialsProvider.newBuilder() + .setScopesToApply(DEFAULT_SERVICE_SCOPES) + .setUseJwtAccessWithScope(true); + } + + /** Returns a builder for the default gRPC ChannelProvider for this service. */ + public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { + return InstantiatingGrpcChannelProvider.newBuilder() + .setMaxInboundMessageSize(Integer.MAX_VALUE); + } + + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return InstantiatingHttpJsonChannelProvider.newBuilder(); + } + + public static TransportChannelProvider defaultTransportChannelProvider() { + return defaultGrpcTransportProviderBuilder().build(); + } + + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken( + "gapic", GaxProperties.getLibraryVersion(ComplianceStubSettings.class)) + .setTransportToken( + GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); + } + + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken( + "gapic", GaxProperties.getLibraryVersion(ComplianceStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return ComplianceStubSettings.defaultGrpcApiClientHeaderProviderBuilder(); + } + + /** Returns a new gRPC builder for this class. */ + public static Builder newBuilder() { + return Builder.createDefault(); + } + + /** Returns a new REST builder for this class. */ + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder(ClientContext clientContext) { + return new Builder(clientContext); + } + + /** Returns a builder containing all the values of this settings class. */ + public Builder toBuilder() { + return new Builder(this); + } + + protected ComplianceStubSettings(Builder settingsBuilder) throws IOException { + super(settingsBuilder); + + repeatDataBodySettings = settingsBuilder.repeatDataBodySettings().build(); + repeatDataBodyInfoSettings = settingsBuilder.repeatDataBodyInfoSettings().build(); + repeatDataQuerySettings = settingsBuilder.repeatDataQuerySettings().build(); + repeatDataSimplePathSettings = settingsBuilder.repeatDataSimplePathSettings().build(); + repeatDataPathResourceSettings = settingsBuilder.repeatDataPathResourceSettings().build(); + repeatDataPathTrailingResourceSettings = + settingsBuilder.repeatDataPathTrailingResourceSettings().build(); + repeatDataBodyPutSettings = settingsBuilder.repeatDataBodyPutSettings().build(); + repeatDataBodyPatchSettings = settingsBuilder.repeatDataBodyPatchSettings().build(); + getEnumSettings = settingsBuilder.getEnumSettings().build(); + verifyEnumSettings = settingsBuilder.verifyEnumSettings().build(); + } + + /** Builder for ComplianceStubSettings. */ + public static class Builder extends StubSettings.Builder { + private final ImmutableList> unaryMethodSettingsBuilders; + private final UnaryCallSettings.Builder repeatDataBodySettings; + private final UnaryCallSettings.Builder + repeatDataBodyInfoSettings; + private final UnaryCallSettings.Builder repeatDataQuerySettings; + private final UnaryCallSettings.Builder + repeatDataSimplePathSettings; + private final UnaryCallSettings.Builder + repeatDataPathResourceSettings; + private final UnaryCallSettings.Builder + repeatDataPathTrailingResourceSettings; + private final UnaryCallSettings.Builder + repeatDataBodyPutSettings; + private final UnaryCallSettings.Builder + repeatDataBodyPatchSettings; + private final UnaryCallSettings.Builder getEnumSettings; + private final UnaryCallSettings.Builder verifyEnumSettings; + private static final ImmutableMap> + RETRYABLE_CODE_DEFINITIONS; + + static { + ImmutableMap.Builder> definitions = + ImmutableMap.builder(); + definitions.put("no_retry_codes", ImmutableSet.copyOf(Lists.newArrayList())); + RETRYABLE_CODE_DEFINITIONS = definitions.build(); + } + + private static final ImmutableMap RETRY_PARAM_DEFINITIONS; + + static { + ImmutableMap.Builder definitions = ImmutableMap.builder(); + RetrySettings settings = null; + settings = RetrySettings.newBuilder().setRpcTimeoutMultiplier(1.0).build(); + definitions.put("no_retry_params", settings); + RETRY_PARAM_DEFINITIONS = definitions.build(); + } + + protected Builder() { + this(((ClientContext) null)); + } + + protected Builder(ClientContext clientContext) { + super(clientContext); + + repeatDataBodySettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + repeatDataBodyInfoSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + repeatDataQuerySettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + repeatDataSimplePathSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + repeatDataPathResourceSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + repeatDataPathTrailingResourceSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + repeatDataBodyPutSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + repeatDataBodyPatchSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + getEnumSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + verifyEnumSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of( + repeatDataBodySettings, + repeatDataBodyInfoSettings, + repeatDataQuerySettings, + repeatDataSimplePathSettings, + repeatDataPathResourceSettings, + repeatDataPathTrailingResourceSettings, + repeatDataBodyPutSettings, + repeatDataBodyPatchSettings, + getEnumSettings, + verifyEnumSettings); + initDefaults(this); + } + + protected Builder(ComplianceStubSettings settings) { + super(settings); + + repeatDataBodySettings = settings.repeatDataBodySettings.toBuilder(); + repeatDataBodyInfoSettings = settings.repeatDataBodyInfoSettings.toBuilder(); + repeatDataQuerySettings = settings.repeatDataQuerySettings.toBuilder(); + repeatDataSimplePathSettings = settings.repeatDataSimplePathSettings.toBuilder(); + repeatDataPathResourceSettings = settings.repeatDataPathResourceSettings.toBuilder(); + repeatDataPathTrailingResourceSettings = + settings.repeatDataPathTrailingResourceSettings.toBuilder(); + repeatDataBodyPutSettings = settings.repeatDataBodyPutSettings.toBuilder(); + repeatDataBodyPatchSettings = settings.repeatDataBodyPatchSettings.toBuilder(); + getEnumSettings = settings.getEnumSettings.toBuilder(); + verifyEnumSettings = settings.verifyEnumSettings.toBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of( + repeatDataBodySettings, + repeatDataBodyInfoSettings, + repeatDataQuerySettings, + repeatDataSimplePathSettings, + repeatDataPathResourceSettings, + repeatDataPathTrailingResourceSettings, + repeatDataBodyPutSettings, + repeatDataBodyPatchSettings, + getEnumSettings, + verifyEnumSettings); + } + + private static Builder createDefault() { + Builder builder = new Builder(((ClientContext) null)); + + builder.setTransportChannelProvider(defaultTransportChannelProvider()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultApiClientHeaderProviderBuilder().build()); + builder.setEndpoint(getDefaultEndpoint()); + builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); + builder.setSwitchToMtlsEndpointAllowed(true); + + return initDefaults(builder); + } + + private static Builder createHttpJsonDefault() { + Builder builder = new Builder(((ClientContext) null)); + + builder.setTransportChannelProvider(defaultHttpJsonTransportProviderBuilder().build()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultHttpJsonApiClientHeaderProviderBuilder().build()); + builder.setEndpoint(getDefaultEndpoint()); + builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); + builder.setSwitchToMtlsEndpointAllowed(true); + + return initDefaults(builder); + } + + private static Builder initDefaults(Builder builder) { + builder + .repeatDataBodySettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .repeatDataBodyInfoSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .repeatDataQuerySettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .repeatDataSimplePathSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .repeatDataPathResourceSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .repeatDataPathTrailingResourceSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .repeatDataBodyPutSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .repeatDataBodyPatchSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .getEnumSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .verifyEnumSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + return builder; + } + + /** + * Applies the given settings updater function to all of the unary API methods in this service. + * + *

Note: This method does not support applying settings to streaming methods. + */ + public Builder applyToAllUnaryMethods( + ApiFunction, Void> settingsUpdater) { + super.applyToAllUnaryMethods(unaryMethodSettingsBuilders, settingsUpdater); + return this; + } + + public ImmutableList> unaryMethodSettingsBuilders() { + return unaryMethodSettingsBuilders; + } + + /** Returns the builder for the settings used for calls to repeatDataBody. */ + public UnaryCallSettings.Builder repeatDataBodySettings() { + return repeatDataBodySettings; + } + + /** Returns the builder for the settings used for calls to repeatDataBodyInfo. */ + public UnaryCallSettings.Builder repeatDataBodyInfoSettings() { + return repeatDataBodyInfoSettings; + } + + /** Returns the builder for the settings used for calls to repeatDataQuery. */ + public UnaryCallSettings.Builder repeatDataQuerySettings() { + return repeatDataQuerySettings; + } + + /** Returns the builder for the settings used for calls to repeatDataSimplePath. */ + public UnaryCallSettings.Builder repeatDataSimplePathSettings() { + return repeatDataSimplePathSettings; + } + + /** Returns the builder for the settings used for calls to repeatDataPathResource. */ + public UnaryCallSettings.Builder + repeatDataPathResourceSettings() { + return repeatDataPathResourceSettings; + } + + /** Returns the builder for the settings used for calls to repeatDataPathTrailingResource. */ + public UnaryCallSettings.Builder + repeatDataPathTrailingResourceSettings() { + return repeatDataPathTrailingResourceSettings; + } + + /** Returns the builder for the settings used for calls to repeatDataBodyPut. */ + public UnaryCallSettings.Builder repeatDataBodyPutSettings() { + return repeatDataBodyPutSettings; + } + + /** Returns the builder for the settings used for calls to repeatDataBodyPatch. */ + public UnaryCallSettings.Builder repeatDataBodyPatchSettings() { + return repeatDataBodyPatchSettings; + } + + /** Returns the builder for the settings used for calls to getEnum. */ + public UnaryCallSettings.Builder getEnumSettings() { + return getEnumSettings; + } + + /** Returns the builder for the settings used for calls to verifyEnum. */ + public UnaryCallSettings.Builder verifyEnumSettings() { + return verifyEnumSettings; + } + + @Override + public ComplianceStubSettings build() throws IOException { + return new ComplianceStubSettings(this); + } + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/EchoStub.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/EchoStub.java new file mode 100644 index 0000000000..be6b33ec95 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/EchoStub.java @@ -0,0 +1,116 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub; + +import static com.google.showcase.v1beta1.EchoClient.PagedExpandLegacyMappedPagedResponse; +import static com.google.showcase.v1beta1.EchoClient.PagedExpandPagedResponse; + +import com.google.api.core.BetaApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import com.google.showcase.v1beta1.BlockRequest; +import com.google.showcase.v1beta1.BlockResponse; +import com.google.showcase.v1beta1.EchoRequest; +import com.google.showcase.v1beta1.EchoResponse; +import com.google.showcase.v1beta1.ExpandRequest; +import com.google.showcase.v1beta1.PagedExpandLegacyMappedResponse; +import com.google.showcase.v1beta1.PagedExpandLegacyRequest; +import com.google.showcase.v1beta1.PagedExpandRequest; +import com.google.showcase.v1beta1.PagedExpandResponse; +import com.google.showcase.v1beta1.WaitMetadata; +import com.google.showcase.v1beta1.WaitRequest; +import com.google.showcase.v1beta1.WaitResponse; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * Base stub class for the Echo service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public abstract class EchoStub implements BackgroundResource { + + public OperationsStub getOperationsStub() { + return null; + } + + public com.google.api.gax.httpjson.longrunning.stub.OperationsStub getHttpJsonOperationsStub() { + return null; + } + + public UnaryCallable echoCallable() { + throw new UnsupportedOperationException("Not implemented: echoCallable()"); + } + + public ServerStreamingCallable expandCallable() { + throw new UnsupportedOperationException("Not implemented: expandCallable()"); + } + + public ClientStreamingCallable collectCallable() { + throw new UnsupportedOperationException("Not implemented: collectCallable()"); + } + + public BidiStreamingCallable chatCallable() { + throw new UnsupportedOperationException("Not implemented: chatCallable()"); + } + + public UnaryCallable pagedExpandPagedCallable() { + throw new UnsupportedOperationException("Not implemented: pagedExpandPagedCallable()"); + } + + public UnaryCallable pagedExpandCallable() { + throw new UnsupportedOperationException("Not implemented: pagedExpandCallable()"); + } + + public UnaryCallable pagedExpandLegacyCallable() { + throw new UnsupportedOperationException("Not implemented: pagedExpandLegacyCallable()"); + } + + public UnaryCallable + pagedExpandLegacyMappedPagedCallable() { + throw new UnsupportedOperationException( + "Not implemented: pagedExpandLegacyMappedPagedCallable()"); + } + + public UnaryCallable + pagedExpandLegacyMappedCallable() { + throw new UnsupportedOperationException("Not implemented: pagedExpandLegacyMappedCallable()"); + } + + public OperationCallable waitOperationCallable() { + throw new UnsupportedOperationException("Not implemented: waitOperationCallable()"); + } + + public UnaryCallable waitCallable() { + throw new UnsupportedOperationException("Not implemented: waitCallable()"); + } + + public UnaryCallable blockCallable() { + throw new UnsupportedOperationException("Not implemented: blockCallable()"); + } + + @Override + public abstract void close(); +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/EchoStubSettings.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/EchoStubSettings.java new file mode 100644 index 0000000000..d4d038ddd4 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/EchoStubSettings.java @@ -0,0 +1,713 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub; + +import static com.google.showcase.v1beta1.EchoClient.PagedExpandLegacyMappedPagedResponse; +import static com.google.showcase.v1beta1.EchoClient.PagedExpandPagedResponse; + +import com.google.api.core.ApiFunction; +import com.google.api.core.ApiFuture; +import com.google.api.core.BetaApi; +import com.google.api.gax.core.GaxProperties; +import com.google.api.gax.core.GoogleCredentialsProvider; +import com.google.api.gax.core.InstantiatingExecutorProvider; +import com.google.api.gax.grpc.GaxGrpcProperties; +import com.google.api.gax.grpc.GrpcTransportChannel; +import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.grpc.ProtoOperationTransformers; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.HttpJsonTransportChannel; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; +import com.google.api.gax.longrunning.OperationSnapshot; +import com.google.api.gax.longrunning.OperationTimedPollAlgorithm; +import com.google.api.gax.retrying.RetrySettings; +import com.google.api.gax.rpc.ApiCallContext; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.PageContext; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.PagedListDescriptor; +import com.google.api.gax.rpc.PagedListResponseFactory; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.StubSettings; +import com.google.api.gax.rpc.TransportChannelProvider; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Lists; +import com.google.longrunning.Operation; +import com.google.showcase.v1beta1.BlockRequest; +import com.google.showcase.v1beta1.BlockResponse; +import com.google.showcase.v1beta1.EchoRequest; +import com.google.showcase.v1beta1.EchoResponse; +import com.google.showcase.v1beta1.ExpandRequest; +import com.google.showcase.v1beta1.PagedExpandLegacyMappedResponse; +import com.google.showcase.v1beta1.PagedExpandLegacyRequest; +import com.google.showcase.v1beta1.PagedExpandRequest; +import com.google.showcase.v1beta1.PagedExpandResponse; +import com.google.showcase.v1beta1.PagedExpandResponseList; +import com.google.showcase.v1beta1.WaitMetadata; +import com.google.showcase.v1beta1.WaitRequest; +import com.google.showcase.v1beta1.WaitResponse; +import java.io.IOException; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import javax.annotation.Generated; +import org.threeten.bp.Duration; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * Settings class to configure an instance of {@link EchoStub}. + * + *

The default instance has everything set to sensible defaults: + * + *

    + *
  • The default service address (localhost) and default port (7469) are used. + *
  • Credentials are acquired automatically through Application Default Credentials. + *
  • Retries are configured for idempotent methods but not for non-idempotent methods. + *
+ * + *

The builder of this class is recursive, so contained classes are themselves builders. When + * build() is called, the tree of builders is called to create the complete settings object. + * + *

For example, to set the total timeout of echo to 30 seconds: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * EchoStubSettings.Builder echoSettingsBuilder = EchoStubSettings.newBuilder();
+ * echoSettingsBuilder
+ *     .echoSettings()
+ *     .setRetrySettings(
+ *         echoSettingsBuilder
+ *             .echoSettings()
+ *             .getRetrySettings()
+ *             .toBuilder()
+ *             .setTotalTimeout(Duration.ofSeconds(30))
+ *             .build());
+ * EchoStubSettings echoSettings = echoSettingsBuilder.build();
+ * }
+ */ +@BetaApi +@Generated("by gapic-generator-java") +public class EchoStubSettings extends StubSettings { + /** The default scopes of the service. */ + private static final ImmutableList DEFAULT_SERVICE_SCOPES = + ImmutableList.builder().build(); + + private final UnaryCallSettings echoSettings; + private final ServerStreamingCallSettings expandSettings; + private final StreamingCallSettings collectSettings; + private final StreamingCallSettings chatSettings; + private final PagedCallSettings + pagedExpandSettings; + private final UnaryCallSettings + pagedExpandLegacySettings; + private final PagedCallSettings< + PagedExpandRequest, PagedExpandLegacyMappedResponse, PagedExpandLegacyMappedPagedResponse> + pagedExpandLegacyMappedSettings; + private final UnaryCallSettings waitSettings; + private final OperationCallSettings + waitOperationSettings; + private final UnaryCallSettings blockSettings; + + private static final PagedListDescriptor + PAGED_EXPAND_PAGE_STR_DESC = + new PagedListDescriptor() { + @Override + public String emptyToken() { + return ""; + } + + @Override + public PagedExpandRequest injectToken(PagedExpandRequest payload, String token) { + return PagedExpandRequest.newBuilder(payload).setPageToken(token).build(); + } + + @Override + public PagedExpandRequest injectPageSize(PagedExpandRequest payload, int pageSize) { + return PagedExpandRequest.newBuilder(payload).setPageSize(pageSize).build(); + } + + @Override + public Integer extractPageSize(PagedExpandRequest payload) { + return payload.getPageSize(); + } + + @Override + public String extractNextToken(PagedExpandResponse payload) { + return payload.getNextPageToken(); + } + + @Override + public Iterable extractResources(PagedExpandResponse payload) { + return payload.getResponsesList() == null + ? ImmutableList.of() + : payload.getResponsesList(); + } + }; + + private static final PagedListDescriptor< + PagedExpandRequest, + PagedExpandLegacyMappedResponse, + Map.Entry> + PAGED_EXPAND_LEGACY_MAPPED_PAGE_STR_DESC = + new PagedListDescriptor< + PagedExpandRequest, + PagedExpandLegacyMappedResponse, + Map.Entry>() { + @Override + public String emptyToken() { + return ""; + } + + @Override + public PagedExpandRequest injectToken(PagedExpandRequest payload, String token) { + return PagedExpandRequest.newBuilder(payload).setPageToken(token).build(); + } + + @Override + public PagedExpandRequest injectPageSize(PagedExpandRequest payload, int pageSize) { + return PagedExpandRequest.newBuilder(payload).setPageSize(pageSize).build(); + } + + @Override + public Integer extractPageSize(PagedExpandRequest payload) { + return payload.getPageSize(); + } + + @Override + public String extractNextToken(PagedExpandLegacyMappedResponse payload) { + return payload.getNextPageToken(); + } + + @Override + public Iterable> extractResources( + PagedExpandLegacyMappedResponse payload) { + return payload.getAlphabetizedMap() == null + ? Collections.>emptySet() + : payload.getAlphabetizedMap().entrySet(); + } + }; + + private static final PagedListResponseFactory< + PagedExpandRequest, PagedExpandResponse, PagedExpandPagedResponse> + PAGED_EXPAND_PAGE_STR_FACT = + new PagedListResponseFactory< + PagedExpandRequest, PagedExpandResponse, PagedExpandPagedResponse>() { + @Override + public ApiFuture getFuturePagedResponse( + UnaryCallable callable, + PagedExpandRequest request, + ApiCallContext context, + ApiFuture futureResponse) { + PageContext pageContext = + PageContext.create(callable, PAGED_EXPAND_PAGE_STR_DESC, request, context); + return PagedExpandPagedResponse.createAsync(pageContext, futureResponse); + } + }; + + private static final PagedListResponseFactory< + PagedExpandRequest, PagedExpandLegacyMappedResponse, PagedExpandLegacyMappedPagedResponse> + PAGED_EXPAND_LEGACY_MAPPED_PAGE_STR_FACT = + new PagedListResponseFactory< + PagedExpandRequest, + PagedExpandLegacyMappedResponse, + PagedExpandLegacyMappedPagedResponse>() { + @Override + public ApiFuture getFuturePagedResponse( + UnaryCallable callable, + PagedExpandRequest request, + ApiCallContext context, + ApiFuture futureResponse) { + PageContext< + PagedExpandRequest, + PagedExpandLegacyMappedResponse, + Map.Entry> + pageContext = + PageContext.create( + callable, PAGED_EXPAND_LEGACY_MAPPED_PAGE_STR_DESC, request, context); + return PagedExpandLegacyMappedPagedResponse.createAsync(pageContext, futureResponse); + } + }; + + /** Returns the object with the settings used for calls to echo. */ + public UnaryCallSettings echoSettings() { + return echoSettings; + } + + /** Returns the object with the settings used for calls to expand. */ + public ServerStreamingCallSettings expandSettings() { + return expandSettings; + } + + /** Returns the object with the settings used for calls to collect. */ + public StreamingCallSettings collectSettings() { + return collectSettings; + } + + /** Returns the object with the settings used for calls to chat. */ + public StreamingCallSettings chatSettings() { + return chatSettings; + } + + /** Returns the object with the settings used for calls to pagedExpand. */ + public PagedCallSettings + pagedExpandSettings() { + return pagedExpandSettings; + } + + /** Returns the object with the settings used for calls to pagedExpandLegacy. */ + public UnaryCallSettings + pagedExpandLegacySettings() { + return pagedExpandLegacySettings; + } + + /** Returns the object with the settings used for calls to pagedExpandLegacyMapped. */ + public PagedCallSettings< + PagedExpandRequest, PagedExpandLegacyMappedResponse, PagedExpandLegacyMappedPagedResponse> + pagedExpandLegacyMappedSettings() { + return pagedExpandLegacyMappedSettings; + } + + /** Returns the object with the settings used for calls to wait. */ + public UnaryCallSettings waitSettings() { + return waitSettings; + } + + /** Returns the object with the settings used for calls to wait. */ + public OperationCallSettings waitOperationSettings() { + return waitOperationSettings; + } + + /** Returns the object with the settings used for calls to block. */ + public UnaryCallSettings blockSettings() { + return blockSettings; + } + + public EchoStub createStub() throws IOException { + if (getTransportChannelProvider() + .getTransportName() + .equals(GrpcTransportChannel.getGrpcTransportName())) { + return GrpcEchoStub.create(this); + } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonEchoStub.create(this); + } + throw new UnsupportedOperationException( + String.format( + "Transport not supported: %s", getTransportChannelProvider().getTransportName())); + } + + /** Returns a builder for the default ExecutorProvider for this service. */ + public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { + return InstantiatingExecutorProvider.newBuilder(); + } + + /** Returns the default service endpoint. */ + public static String getDefaultEndpoint() { + return "localhost:7469"; + } + + /** Returns the default mTLS service endpoint. */ + public static String getDefaultMtlsEndpoint() { + return "localhost:7469"; + } + + /** Returns the default service scopes. */ + public static List getDefaultServiceScopes() { + return DEFAULT_SERVICE_SCOPES; + } + + /** Returns a builder for the default credentials for this service. */ + public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { + return GoogleCredentialsProvider.newBuilder() + .setScopesToApply(DEFAULT_SERVICE_SCOPES) + .setUseJwtAccessWithScope(true); + } + + /** Returns a builder for the default gRPC ChannelProvider for this service. */ + public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { + return InstantiatingGrpcChannelProvider.newBuilder() + .setMaxInboundMessageSize(Integer.MAX_VALUE); + } + + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return InstantiatingHttpJsonChannelProvider.newBuilder(); + } + + public static TransportChannelProvider defaultTransportChannelProvider() { + return defaultGrpcTransportProviderBuilder().build(); + } + + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken("gapic", GaxProperties.getLibraryVersion(EchoStubSettings.class)) + .setTransportToken( + GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); + } + + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken("gapic", GaxProperties.getLibraryVersion(EchoStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return EchoStubSettings.defaultGrpcApiClientHeaderProviderBuilder(); + } + + /** Returns a new gRPC builder for this class. */ + public static Builder newBuilder() { + return Builder.createDefault(); + } + + /** Returns a new REST builder for this class. */ + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder(ClientContext clientContext) { + return new Builder(clientContext); + } + + /** Returns a builder containing all the values of this settings class. */ + public Builder toBuilder() { + return new Builder(this); + } + + protected EchoStubSettings(Builder settingsBuilder) throws IOException { + super(settingsBuilder); + + echoSettings = settingsBuilder.echoSettings().build(); + expandSettings = settingsBuilder.expandSettings().build(); + collectSettings = settingsBuilder.collectSettings().build(); + chatSettings = settingsBuilder.chatSettings().build(); + pagedExpandSettings = settingsBuilder.pagedExpandSettings().build(); + pagedExpandLegacySettings = settingsBuilder.pagedExpandLegacySettings().build(); + pagedExpandLegacyMappedSettings = settingsBuilder.pagedExpandLegacyMappedSettings().build(); + waitSettings = settingsBuilder.waitSettings().build(); + waitOperationSettings = settingsBuilder.waitOperationSettings().build(); + blockSettings = settingsBuilder.blockSettings().build(); + } + + /** Builder for EchoStubSettings. */ + public static class Builder extends StubSettings.Builder { + private final ImmutableList> unaryMethodSettingsBuilders; + private final UnaryCallSettings.Builder echoSettings; + private final ServerStreamingCallSettings.Builder expandSettings; + private final StreamingCallSettings.Builder collectSettings; + private final StreamingCallSettings.Builder chatSettings; + private final PagedCallSettings.Builder< + PagedExpandRequest, PagedExpandResponse, PagedExpandPagedResponse> + pagedExpandSettings; + private final UnaryCallSettings.Builder + pagedExpandLegacySettings; + private final PagedCallSettings.Builder< + PagedExpandRequest, + PagedExpandLegacyMappedResponse, + PagedExpandLegacyMappedPagedResponse> + pagedExpandLegacyMappedSettings; + private final UnaryCallSettings.Builder waitSettings; + private final OperationCallSettings.Builder + waitOperationSettings; + private final UnaryCallSettings.Builder blockSettings; + private static final ImmutableMap> + RETRYABLE_CODE_DEFINITIONS; + + static { + ImmutableMap.Builder> definitions = + ImmutableMap.builder(); + definitions.put( + "retry_policy_1_codes", + ImmutableSet.copyOf( + Lists.newArrayList( + StatusCode.Code.UNAVAILABLE, StatusCode.Code.UNKNOWN))); + definitions.put( + "no_retry_0_codes", ImmutableSet.copyOf(Lists.newArrayList())); + RETRYABLE_CODE_DEFINITIONS = definitions.build(); + } + + private static final ImmutableMap RETRY_PARAM_DEFINITIONS; + + static { + ImmutableMap.Builder definitions = ImmutableMap.builder(); + RetrySettings settings = null; + settings = + RetrySettings.newBuilder() + .setInitialRetryDelay(Duration.ofMillis(100L)) + .setRetryDelayMultiplier(2.0) + .setMaxRetryDelay(Duration.ofMillis(3000L)) + .setInitialRpcTimeout(Duration.ofMillis(10000L)) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ofMillis(10000L)) + .setTotalTimeout(Duration.ofMillis(10000L)) + .build(); + definitions.put("retry_policy_1_params", settings); + settings = + RetrySettings.newBuilder() + .setInitialRpcTimeout(Duration.ofMillis(5000L)) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ofMillis(5000L)) + .setTotalTimeout(Duration.ofMillis(5000L)) + .build(); + definitions.put("no_retry_0_params", settings); + RETRY_PARAM_DEFINITIONS = definitions.build(); + } + + protected Builder() { + this(((ClientContext) null)); + } + + protected Builder(ClientContext clientContext) { + super(clientContext); + + echoSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + expandSettings = ServerStreamingCallSettings.newBuilder(); + collectSettings = StreamingCallSettings.newBuilder(); + chatSettings = StreamingCallSettings.newBuilder(); + pagedExpandSettings = PagedCallSettings.newBuilder(PAGED_EXPAND_PAGE_STR_FACT); + pagedExpandLegacySettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + pagedExpandLegacyMappedSettings = + PagedCallSettings.newBuilder(PAGED_EXPAND_LEGACY_MAPPED_PAGE_STR_FACT); + waitSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + waitOperationSettings = OperationCallSettings.newBuilder(); + blockSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of( + echoSettings, + pagedExpandSettings, + pagedExpandLegacySettings, + pagedExpandLegacyMappedSettings, + waitSettings, + blockSettings); + initDefaults(this); + } + + protected Builder(EchoStubSettings settings) { + super(settings); + + echoSettings = settings.echoSettings.toBuilder(); + expandSettings = settings.expandSettings.toBuilder(); + collectSettings = settings.collectSettings.toBuilder(); + chatSettings = settings.chatSettings.toBuilder(); + pagedExpandSettings = settings.pagedExpandSettings.toBuilder(); + pagedExpandLegacySettings = settings.pagedExpandLegacySettings.toBuilder(); + pagedExpandLegacyMappedSettings = settings.pagedExpandLegacyMappedSettings.toBuilder(); + waitSettings = settings.waitSettings.toBuilder(); + waitOperationSettings = settings.waitOperationSettings.toBuilder(); + blockSettings = settings.blockSettings.toBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of( + echoSettings, + pagedExpandSettings, + pagedExpandLegacySettings, + pagedExpandLegacyMappedSettings, + waitSettings, + blockSettings); + } + + private static Builder createDefault() { + Builder builder = new Builder(((ClientContext) null)); + + builder.setTransportChannelProvider(defaultTransportChannelProvider()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultApiClientHeaderProviderBuilder().build()); + builder.setEndpoint(getDefaultEndpoint()); + builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); + builder.setSwitchToMtlsEndpointAllowed(true); + + return initDefaults(builder); + } + + private static Builder createHttpJsonDefault() { + Builder builder = new Builder(((ClientContext) null)); + + builder.setTransportChannelProvider(defaultHttpJsonTransportProviderBuilder().build()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultHttpJsonApiClientHeaderProviderBuilder().build()); + builder.setEndpoint(getDefaultEndpoint()); + builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); + builder.setSwitchToMtlsEndpointAllowed(true); + + return initDefaults(builder); + } + + private static Builder initDefaults(Builder builder) { + builder + .echoSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_1_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_1_params")); + + builder + .expandSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_1_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_1_params")); + + builder + .pagedExpandSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_1_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_1_params")); + + builder + .pagedExpandLegacySettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); + + builder + .pagedExpandLegacyMappedSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); + + builder + .waitSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); + + builder + .blockSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); + + builder + .waitOperationSettings() + .setInitialCallSettings( + UnaryCallSettings.newUnaryCallSettingsBuilder() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")) + .build()) + .setResponseTransformer( + ProtoOperationTransformers.ResponseTransformer.create(WaitResponse.class)) + .setMetadataTransformer( + ProtoOperationTransformers.MetadataTransformer.create(WaitMetadata.class)) + .setPollingAlgorithm( + OperationTimedPollAlgorithm.create( + RetrySettings.newBuilder() + .setInitialRetryDelay(Duration.ofMillis(5000L)) + .setRetryDelayMultiplier(1.5) + .setMaxRetryDelay(Duration.ofMillis(45000L)) + .setInitialRpcTimeout(Duration.ZERO) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ZERO) + .setTotalTimeout(Duration.ofMillis(300000L)) + .build())); + + return builder; + } + + /** + * Applies the given settings updater function to all of the unary API methods in this service. + * + *

Note: This method does not support applying settings to streaming methods. + */ + public Builder applyToAllUnaryMethods( + ApiFunction, Void> settingsUpdater) { + super.applyToAllUnaryMethods(unaryMethodSettingsBuilders, settingsUpdater); + return this; + } + + public ImmutableList> unaryMethodSettingsBuilders() { + return unaryMethodSettingsBuilders; + } + + /** Returns the builder for the settings used for calls to echo. */ + public UnaryCallSettings.Builder echoSettings() { + return echoSettings; + } + + /** Returns the builder for the settings used for calls to expand. */ + public ServerStreamingCallSettings.Builder expandSettings() { + return expandSettings; + } + + /** Returns the builder for the settings used for calls to collect. */ + public StreamingCallSettings.Builder collectSettings() { + return collectSettings; + } + + /** Returns the builder for the settings used for calls to chat. */ + public StreamingCallSettings.Builder chatSettings() { + return chatSettings; + } + + /** Returns the builder for the settings used for calls to pagedExpand. */ + public PagedCallSettings.Builder< + PagedExpandRequest, PagedExpandResponse, PagedExpandPagedResponse> + pagedExpandSettings() { + return pagedExpandSettings; + } + + /** Returns the builder for the settings used for calls to pagedExpandLegacy. */ + public UnaryCallSettings.Builder + pagedExpandLegacySettings() { + return pagedExpandLegacySettings; + } + + /** Returns the builder for the settings used for calls to pagedExpandLegacyMapped. */ + public PagedCallSettings.Builder< + PagedExpandRequest, + PagedExpandLegacyMappedResponse, + PagedExpandLegacyMappedPagedResponse> + pagedExpandLegacyMappedSettings() { + return pagedExpandLegacyMappedSettings; + } + + /** Returns the builder for the settings used for calls to wait. */ + public UnaryCallSettings.Builder waitSettings() { + return waitSettings; + } + + /** Returns the builder for the settings used for calls to wait. */ + @BetaApi( + "The surface for use by generated code is not stable yet and may change in the future.") + public OperationCallSettings.Builder + waitOperationSettings() { + return waitOperationSettings; + } + + /** Returns the builder for the settings used for calls to block. */ + public UnaryCallSettings.Builder blockSettings() { + return blockSettings; + } + + @Override + public EchoStubSettings build() throws IOException { + return new EchoStubSettings(this); + } + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/GrpcComplianceCallableFactory.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/GrpcComplianceCallableFactory.java new file mode 100644 index 0000000000..953ca5555b --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/GrpcComplianceCallableFactory.java @@ -0,0 +1,115 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * gRPC callable factory implementation for the Compliance service API. + * + *

This class is for advanced usage. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class GrpcComplianceCallableFactory implements GrpcStubCallableFactory { + + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, callSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, callSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, callSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, callSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, callSettings, clientContext); + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/GrpcComplianceStub.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/GrpcComplianceStub.java new file mode 100644 index 0000000000..116d0fa5cb --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/GrpcComplianceStub.java @@ -0,0 +1,397 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.core.BackgroundResourceAggregation; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.common.collect.ImmutableMap; +import com.google.longrunning.stub.GrpcOperationsStub; +import com.google.showcase.v1beta1.EnumRequest; +import com.google.showcase.v1beta1.EnumResponse; +import com.google.showcase.v1beta1.RepeatRequest; +import com.google.showcase.v1beta1.RepeatResponse; +import io.grpc.MethodDescriptor; +import io.grpc.protobuf.ProtoUtils; +import java.io.IOException; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * gRPC stub implementation for the Compliance service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class GrpcComplianceStub extends ComplianceStub { + private static final MethodDescriptor + repeatDataBodyMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.Compliance/RepeatDataBody") + .setRequestMarshaller(ProtoUtils.marshaller(RepeatRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(RepeatResponse.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + repeatDataBodyInfoMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.Compliance/RepeatDataBodyInfo") + .setRequestMarshaller(ProtoUtils.marshaller(RepeatRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(RepeatResponse.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + repeatDataQueryMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.Compliance/RepeatDataQuery") + .setRequestMarshaller(ProtoUtils.marshaller(RepeatRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(RepeatResponse.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + repeatDataSimplePathMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.Compliance/RepeatDataSimplePath") + .setRequestMarshaller(ProtoUtils.marshaller(RepeatRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(RepeatResponse.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + repeatDataPathResourceMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.Compliance/RepeatDataPathResource") + .setRequestMarshaller(ProtoUtils.marshaller(RepeatRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(RepeatResponse.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + repeatDataPathTrailingResourceMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName( + "google.showcase.v1beta1.Compliance/RepeatDataPathTrailingResource") + .setRequestMarshaller(ProtoUtils.marshaller(RepeatRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(RepeatResponse.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + repeatDataBodyPutMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.Compliance/RepeatDataBodyPut") + .setRequestMarshaller(ProtoUtils.marshaller(RepeatRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(RepeatResponse.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + repeatDataBodyPatchMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.Compliance/RepeatDataBodyPatch") + .setRequestMarshaller(ProtoUtils.marshaller(RepeatRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(RepeatResponse.getDefaultInstance())) + .build(); + + private static final MethodDescriptor getEnumMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.Compliance/GetEnum") + .setRequestMarshaller(ProtoUtils.marshaller(EnumRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(EnumResponse.getDefaultInstance())) + .build(); + + private static final MethodDescriptor verifyEnumMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.Compliance/VerifyEnum") + .setRequestMarshaller(ProtoUtils.marshaller(EnumResponse.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(EnumResponse.getDefaultInstance())) + .build(); + + private final UnaryCallable repeatDataBodyCallable; + private final UnaryCallable repeatDataBodyInfoCallable; + private final UnaryCallable repeatDataQueryCallable; + private final UnaryCallable repeatDataSimplePathCallable; + private final UnaryCallable repeatDataPathResourceCallable; + private final UnaryCallable repeatDataPathTrailingResourceCallable; + private final UnaryCallable repeatDataBodyPutCallable; + private final UnaryCallable repeatDataBodyPatchCallable; + private final UnaryCallable getEnumCallable; + private final UnaryCallable verifyEnumCallable; + + private final BackgroundResource backgroundResources; + private final GrpcOperationsStub operationsStub; + private final GrpcStubCallableFactory callableFactory; + + public static final GrpcComplianceStub create(ComplianceStubSettings settings) + throws IOException { + return new GrpcComplianceStub(settings, ClientContext.create(settings)); + } + + public static final GrpcComplianceStub create(ClientContext clientContext) throws IOException { + return new GrpcComplianceStub(ComplianceStubSettings.newBuilder().build(), clientContext); + } + + public static final GrpcComplianceStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcComplianceStub( + ComplianceStubSettings.newBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of GrpcComplianceStub, using the given settings. This is protected so + * that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected GrpcComplianceStub(ComplianceStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new GrpcComplianceCallableFactory()); + } + + /** + * Constructs an instance of GrpcComplianceStub, using the given settings. This is protected so + * that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected GrpcComplianceStub( + ComplianceStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory); + + GrpcCallSettings repeatDataBodyTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(repeatDataBodyMethodDescriptor) + .build(); + GrpcCallSettings repeatDataBodyInfoTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(repeatDataBodyInfoMethodDescriptor) + .build(); + GrpcCallSettings repeatDataQueryTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(repeatDataQueryMethodDescriptor) + .build(); + GrpcCallSettings repeatDataSimplePathTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(repeatDataSimplePathMethodDescriptor) + .setParamsExtractor( + request -> { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("info.f_bool", String.valueOf(request.getInfo().getFBool())); + params.put("info.f_double", String.valueOf(request.getInfo().getFDouble())); + params.put("info.f_int32", String.valueOf(request.getInfo().getFInt32())); + params.put("info.f_kingdom", String.valueOf(request.getInfo().getFKingdom())); + params.put("info.f_string", String.valueOf(request.getInfo().getFString())); + return params.build(); + }) + .build(); + GrpcCallSettings repeatDataPathResourceTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(repeatDataPathResourceMethodDescriptor) + .setParamsExtractor( + request -> { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("info.f_bool", String.valueOf(request.getInfo().getFBool())); + params.put( + "info.f_child.f_string", + String.valueOf(request.getInfo().getFChild().getFString())); + params.put("info.f_string", String.valueOf(request.getInfo().getFString())); + return params.build(); + }) + .build(); + GrpcCallSettings + repeatDataPathTrailingResourceTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(repeatDataPathTrailingResourceMethodDescriptor) + .setParamsExtractor( + request -> { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put( + "info.f_child.f_string", + String.valueOf(request.getInfo().getFChild().getFString())); + params.put("info.f_string", String.valueOf(request.getInfo().getFString())); + return params.build(); + }) + .build(); + GrpcCallSettings repeatDataBodyPutTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(repeatDataBodyPutMethodDescriptor) + .build(); + GrpcCallSettings repeatDataBodyPatchTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(repeatDataBodyPatchMethodDescriptor) + .build(); + GrpcCallSettings getEnumTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(getEnumMethodDescriptor) + .build(); + GrpcCallSettings verifyEnumTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(verifyEnumMethodDescriptor) + .build(); + + this.repeatDataBodyCallable = + callableFactory.createUnaryCallable( + repeatDataBodyTransportSettings, settings.repeatDataBodySettings(), clientContext); + this.repeatDataBodyInfoCallable = + callableFactory.createUnaryCallable( + repeatDataBodyInfoTransportSettings, + settings.repeatDataBodyInfoSettings(), + clientContext); + this.repeatDataQueryCallable = + callableFactory.createUnaryCallable( + repeatDataQueryTransportSettings, settings.repeatDataQuerySettings(), clientContext); + this.repeatDataSimplePathCallable = + callableFactory.createUnaryCallable( + repeatDataSimplePathTransportSettings, + settings.repeatDataSimplePathSettings(), + clientContext); + this.repeatDataPathResourceCallable = + callableFactory.createUnaryCallable( + repeatDataPathResourceTransportSettings, + settings.repeatDataPathResourceSettings(), + clientContext); + this.repeatDataPathTrailingResourceCallable = + callableFactory.createUnaryCallable( + repeatDataPathTrailingResourceTransportSettings, + settings.repeatDataPathTrailingResourceSettings(), + clientContext); + this.repeatDataBodyPutCallable = + callableFactory.createUnaryCallable( + repeatDataBodyPutTransportSettings, + settings.repeatDataBodyPutSettings(), + clientContext); + this.repeatDataBodyPatchCallable = + callableFactory.createUnaryCallable( + repeatDataBodyPatchTransportSettings, + settings.repeatDataBodyPatchSettings(), + clientContext); + this.getEnumCallable = + callableFactory.createUnaryCallable( + getEnumTransportSettings, settings.getEnumSettings(), clientContext); + this.verifyEnumCallable = + callableFactory.createUnaryCallable( + verifyEnumTransportSettings, settings.verifyEnumSettings(), clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + public GrpcOperationsStub getOperationsStub() { + return operationsStub; + } + + @Override + public UnaryCallable repeatDataBodyCallable() { + return repeatDataBodyCallable; + } + + @Override + public UnaryCallable repeatDataBodyInfoCallable() { + return repeatDataBodyInfoCallable; + } + + @Override + public UnaryCallable repeatDataQueryCallable() { + return repeatDataQueryCallable; + } + + @Override + public UnaryCallable repeatDataSimplePathCallable() { + return repeatDataSimplePathCallable; + } + + @Override + public UnaryCallable repeatDataPathResourceCallable() { + return repeatDataPathResourceCallable; + } + + @Override + public UnaryCallable repeatDataPathTrailingResourceCallable() { + return repeatDataPathTrailingResourceCallable; + } + + @Override + public UnaryCallable repeatDataBodyPutCallable() { + return repeatDataBodyPutCallable; + } + + @Override + public UnaryCallable repeatDataBodyPatchCallable() { + return repeatDataBodyPatchCallable; + } + + @Override + public UnaryCallable getEnumCallable() { + return getEnumCallable; + } + + @Override + public UnaryCallable verifyEnumCallable() { + return verifyEnumCallable; + } + + @Override + public final void close() { + try { + backgroundResources.close(); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new IllegalStateException("Failed to close resource", e); + } + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/GrpcEchoCallableFactory.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/GrpcEchoCallableFactory.java new file mode 100644 index 0000000000..3306812933 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/GrpcEchoCallableFactory.java @@ -0,0 +1,115 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * gRPC callable factory implementation for the Echo service API. + * + *

This class is for advanced usage. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class GrpcEchoCallableFactory implements GrpcStubCallableFactory { + + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, callSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, callSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, callSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, callSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, callSettings, clientContext); + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/GrpcEchoStub.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/GrpcEchoStub.java new file mode 100644 index 0000000000..3e8a99d5b2 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/GrpcEchoStub.java @@ -0,0 +1,413 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub; + +import static com.google.showcase.v1beta1.EchoClient.PagedExpandLegacyMappedPagedResponse; +import static com.google.showcase.v1beta1.EchoClient.PagedExpandPagedResponse; + +import com.google.api.core.BetaApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.core.BackgroundResourceAggregation; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.RequestParamsBuilder; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.api.pathtemplate.PathTemplate; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.GrpcOperationsStub; +import com.google.showcase.v1beta1.BlockRequest; +import com.google.showcase.v1beta1.BlockResponse; +import com.google.showcase.v1beta1.EchoRequest; +import com.google.showcase.v1beta1.EchoResponse; +import com.google.showcase.v1beta1.ExpandRequest; +import com.google.showcase.v1beta1.PagedExpandLegacyMappedResponse; +import com.google.showcase.v1beta1.PagedExpandLegacyRequest; +import com.google.showcase.v1beta1.PagedExpandRequest; +import com.google.showcase.v1beta1.PagedExpandResponse; +import com.google.showcase.v1beta1.WaitMetadata; +import com.google.showcase.v1beta1.WaitRequest; +import com.google.showcase.v1beta1.WaitResponse; +import io.grpc.MethodDescriptor; +import io.grpc.protobuf.ProtoUtils; +import java.io.IOException; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * gRPC stub implementation for the Echo service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class GrpcEchoStub extends EchoStub { + private static final MethodDescriptor echoMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.Echo/Echo") + .setRequestMarshaller(ProtoUtils.marshaller(EchoRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(EchoResponse.getDefaultInstance())) + .build(); + + private static final MethodDescriptor expandMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.SERVER_STREAMING) + .setFullMethodName("google.showcase.v1beta1.Echo/Expand") + .setRequestMarshaller(ProtoUtils.marshaller(ExpandRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(EchoResponse.getDefaultInstance())) + .build(); + + private static final MethodDescriptor collectMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.CLIENT_STREAMING) + .setFullMethodName("google.showcase.v1beta1.Echo/Collect") + .setRequestMarshaller(ProtoUtils.marshaller(EchoRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(EchoResponse.getDefaultInstance())) + .build(); + + private static final MethodDescriptor chatMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.BIDI_STREAMING) + .setFullMethodName("google.showcase.v1beta1.Echo/Chat") + .setRequestMarshaller(ProtoUtils.marshaller(EchoRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(EchoResponse.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + pagedExpandMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.Echo/PagedExpand") + .setRequestMarshaller(ProtoUtils.marshaller(PagedExpandRequest.getDefaultInstance())) + .setResponseMarshaller( + ProtoUtils.marshaller(PagedExpandResponse.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + pagedExpandLegacyMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.Echo/PagedExpandLegacy") + .setRequestMarshaller( + ProtoUtils.marshaller(PagedExpandLegacyRequest.getDefaultInstance())) + .setResponseMarshaller( + ProtoUtils.marshaller(PagedExpandResponse.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + pagedExpandLegacyMappedMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.Echo/PagedExpandLegacyMapped") + .setRequestMarshaller(ProtoUtils.marshaller(PagedExpandRequest.getDefaultInstance())) + .setResponseMarshaller( + ProtoUtils.marshaller(PagedExpandLegacyMappedResponse.getDefaultInstance())) + .build(); + + private static final MethodDescriptor waitMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.Echo/Wait") + .setRequestMarshaller(ProtoUtils.marshaller(WaitRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance())) + .build(); + + private static final MethodDescriptor blockMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.Echo/Block") + .setRequestMarshaller(ProtoUtils.marshaller(BlockRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(BlockResponse.getDefaultInstance())) + .build(); + + private final UnaryCallable echoCallable; + private final ServerStreamingCallable expandCallable; + private final ClientStreamingCallable collectCallable; + private final BidiStreamingCallable chatCallable; + private final UnaryCallable pagedExpandCallable; + private final UnaryCallable + pagedExpandPagedCallable; + private final UnaryCallable + pagedExpandLegacyCallable; + private final UnaryCallable + pagedExpandLegacyMappedCallable; + private final UnaryCallable + pagedExpandLegacyMappedPagedCallable; + private final UnaryCallable waitCallable; + private final OperationCallable waitOperationCallable; + private final UnaryCallable blockCallable; + + private final BackgroundResource backgroundResources; + private final GrpcOperationsStub operationsStub; + private final GrpcStubCallableFactory callableFactory; + + private static final PathTemplate ECHO_0_PATH_TEMPLATE = PathTemplate.create("{header=**}"); + private static final PathTemplate ECHO_1_PATH_TEMPLATE = PathTemplate.create("{routing_id=**}"); + private static final PathTemplate ECHO_2_PATH_TEMPLATE = + PathTemplate.create("{table_name=regions/*/zones/*/**}"); + private static final PathTemplate ECHO_3_PATH_TEMPLATE = + PathTemplate.create("{super_id=projects/*}/**"); + private static final PathTemplate ECHO_4_PATH_TEMPLATE = + PathTemplate.create("{table_name=projects/*/instances/*/**}"); + private static final PathTemplate ECHO_5_PATH_TEMPLATE = + PathTemplate.create("projects/*/{instance_id=instances/*}/**"); + private static final PathTemplate ECHO_6_PATH_TEMPLATE = PathTemplate.create("{baz=**}"); + private static final PathTemplate ECHO_7_PATH_TEMPLATE = + PathTemplate.create("{qux=projects/*}/**"); + + public static final GrpcEchoStub create(EchoStubSettings settings) throws IOException { + return new GrpcEchoStub(settings, ClientContext.create(settings)); + } + + public static final GrpcEchoStub create(ClientContext clientContext) throws IOException { + return new GrpcEchoStub(EchoStubSettings.newBuilder().build(), clientContext); + } + + public static final GrpcEchoStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcEchoStub(EchoStubSettings.newBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of GrpcEchoStub, using the given settings. This is protected so that it + * is easy to make a subclass, but otherwise, the static factory methods should be preferred. + */ + protected GrpcEchoStub(EchoStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new GrpcEchoCallableFactory()); + } + + /** + * Constructs an instance of GrpcEchoStub, using the given settings. This is protected so that it + * is easy to make a subclass, but otherwise, the static factory methods should be preferred. + */ + protected GrpcEchoStub( + EchoStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory); + + GrpcCallSettings echoTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(echoMethodDescriptor) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add(request.getHeader(), "header", ECHO_0_PATH_TEMPLATE); + builder.add(request.getHeader(), "routing_id", ECHO_1_PATH_TEMPLATE); + builder.add(request.getHeader(), "table_name", ECHO_2_PATH_TEMPLATE); + builder.add(request.getHeader(), "super_id", ECHO_3_PATH_TEMPLATE); + builder.add(request.getHeader(), "table_name", ECHO_4_PATH_TEMPLATE); + builder.add(request.getHeader(), "instance_id", ECHO_5_PATH_TEMPLATE); + builder.add(request.getOtherHeader(), "baz", ECHO_6_PATH_TEMPLATE); + builder.add(request.getOtherHeader(), "qux", ECHO_7_PATH_TEMPLATE); + return builder.build(); + }) + .build(); + GrpcCallSettings expandTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(expandMethodDescriptor) + .build(); + GrpcCallSettings collectTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(collectMethodDescriptor) + .build(); + GrpcCallSettings chatTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(chatMethodDescriptor) + .build(); + GrpcCallSettings pagedExpandTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(pagedExpandMethodDescriptor) + .build(); + GrpcCallSettings + pagedExpandLegacyTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(pagedExpandLegacyMethodDescriptor) + .build(); + GrpcCallSettings + pagedExpandLegacyMappedTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(pagedExpandLegacyMappedMethodDescriptor) + .build(); + GrpcCallSettings waitTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(waitMethodDescriptor) + .build(); + GrpcCallSettings blockTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(blockMethodDescriptor) + .build(); + + this.echoCallable = + callableFactory.createUnaryCallable( + echoTransportSettings, settings.echoSettings(), clientContext); + this.expandCallable = + callableFactory.createServerStreamingCallable( + expandTransportSettings, settings.expandSettings(), clientContext); + this.collectCallable = + callableFactory.createClientStreamingCallable( + collectTransportSettings, settings.collectSettings(), clientContext); + this.chatCallable = + callableFactory.createBidiStreamingCallable( + chatTransportSettings, settings.chatSettings(), clientContext); + this.pagedExpandCallable = + callableFactory.createUnaryCallable( + pagedExpandTransportSettings, settings.pagedExpandSettings(), clientContext); + this.pagedExpandPagedCallable = + callableFactory.createPagedCallable( + pagedExpandTransportSettings, settings.pagedExpandSettings(), clientContext); + this.pagedExpandLegacyCallable = + callableFactory.createUnaryCallable( + pagedExpandLegacyTransportSettings, + settings.pagedExpandLegacySettings(), + clientContext); + this.pagedExpandLegacyMappedCallable = + callableFactory.createUnaryCallable( + pagedExpandLegacyMappedTransportSettings, + settings.pagedExpandLegacyMappedSettings(), + clientContext); + this.pagedExpandLegacyMappedPagedCallable = + callableFactory.createPagedCallable( + pagedExpandLegacyMappedTransportSettings, + settings.pagedExpandLegacyMappedSettings(), + clientContext); + this.waitCallable = + callableFactory.createUnaryCallable( + waitTransportSettings, settings.waitSettings(), clientContext); + this.waitOperationCallable = + callableFactory.createOperationCallable( + waitTransportSettings, settings.waitOperationSettings(), clientContext, operationsStub); + this.blockCallable = + callableFactory.createUnaryCallable( + blockTransportSettings, settings.blockSettings(), clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + public GrpcOperationsStub getOperationsStub() { + return operationsStub; + } + + @Override + public UnaryCallable echoCallable() { + return echoCallable; + } + + @Override + public ServerStreamingCallable expandCallable() { + return expandCallable; + } + + @Override + public ClientStreamingCallable collectCallable() { + return collectCallable; + } + + @Override + public BidiStreamingCallable chatCallable() { + return chatCallable; + } + + @Override + public UnaryCallable pagedExpandCallable() { + return pagedExpandCallable; + } + + @Override + public UnaryCallable pagedExpandPagedCallable() { + return pagedExpandPagedCallable; + } + + @Override + public UnaryCallable pagedExpandLegacyCallable() { + return pagedExpandLegacyCallable; + } + + @Override + public UnaryCallable + pagedExpandLegacyMappedCallable() { + return pagedExpandLegacyMappedCallable; + } + + @Override + public UnaryCallable + pagedExpandLegacyMappedPagedCallable() { + return pagedExpandLegacyMappedPagedCallable; + } + + @Override + public UnaryCallable waitCallable() { + return waitCallable; + } + + @Override + public OperationCallable waitOperationCallable() { + return waitOperationCallable; + } + + @Override + public UnaryCallable blockCallable() { + return blockCallable; + } + + @Override + public final void close() { + try { + backgroundResources.close(); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new IllegalStateException("Failed to close resource", e); + } + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/GrpcIdentityCallableFactory.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/GrpcIdentityCallableFactory.java new file mode 100644 index 0000000000..313391c0ee --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/GrpcIdentityCallableFactory.java @@ -0,0 +1,115 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * gRPC callable factory implementation for the Identity service API. + * + *

This class is for advanced usage. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class GrpcIdentityCallableFactory implements GrpcStubCallableFactory { + + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, callSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, callSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, callSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, callSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, callSettings, clientContext); + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/GrpcIdentityStub.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/GrpcIdentityStub.java new file mode 100644 index 0000000000..516fe97b2b --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/GrpcIdentityStub.java @@ -0,0 +1,272 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub; + +import static com.google.showcase.v1beta1.IdentityClient.ListUsersPagedResponse; + +import com.google.api.core.BetaApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.core.BackgroundResourceAggregation; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.common.collect.ImmutableMap; +import com.google.longrunning.stub.GrpcOperationsStub; +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.CreateUserRequest; +import com.google.showcase.v1beta1.DeleteUserRequest; +import com.google.showcase.v1beta1.GetUserRequest; +import com.google.showcase.v1beta1.ListUsersRequest; +import com.google.showcase.v1beta1.ListUsersResponse; +import com.google.showcase.v1beta1.UpdateUserRequest; +import com.google.showcase.v1beta1.User; +import io.grpc.MethodDescriptor; +import io.grpc.protobuf.ProtoUtils; +import java.io.IOException; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * gRPC stub implementation for the Identity service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class GrpcIdentityStub extends IdentityStub { + private static final MethodDescriptor createUserMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.Identity/CreateUser") + .setRequestMarshaller(ProtoUtils.marshaller(CreateUserRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(User.getDefaultInstance())) + .build(); + + private static final MethodDescriptor getUserMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.Identity/GetUser") + .setRequestMarshaller(ProtoUtils.marshaller(GetUserRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(User.getDefaultInstance())) + .build(); + + private static final MethodDescriptor updateUserMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.Identity/UpdateUser") + .setRequestMarshaller(ProtoUtils.marshaller(UpdateUserRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(User.getDefaultInstance())) + .build(); + + private static final MethodDescriptor deleteUserMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.Identity/DeleteUser") + .setRequestMarshaller(ProtoUtils.marshaller(DeleteUserRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + listUsersMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.Identity/ListUsers") + .setRequestMarshaller(ProtoUtils.marshaller(ListUsersRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(ListUsersResponse.getDefaultInstance())) + .build(); + + private final UnaryCallable createUserCallable; + private final UnaryCallable getUserCallable; + private final UnaryCallable updateUserCallable; + private final UnaryCallable deleteUserCallable; + private final UnaryCallable listUsersCallable; + private final UnaryCallable listUsersPagedCallable; + + private final BackgroundResource backgroundResources; + private final GrpcOperationsStub operationsStub; + private final GrpcStubCallableFactory callableFactory; + + public static final GrpcIdentityStub create(IdentityStubSettings settings) throws IOException { + return new GrpcIdentityStub(settings, ClientContext.create(settings)); + } + + public static final GrpcIdentityStub create(ClientContext clientContext) throws IOException { + return new GrpcIdentityStub(IdentityStubSettings.newBuilder().build(), clientContext); + } + + public static final GrpcIdentityStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcIdentityStub( + IdentityStubSettings.newBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of GrpcIdentityStub, using the given settings. This is protected so that + * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. + */ + protected GrpcIdentityStub(IdentityStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new GrpcIdentityCallableFactory()); + } + + /** + * Constructs an instance of GrpcIdentityStub, using the given settings. This is protected so that + * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. + */ + protected GrpcIdentityStub( + IdentityStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory); + + GrpcCallSettings createUserTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(createUserMethodDescriptor) + .build(); + GrpcCallSettings getUserTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(getUserMethodDescriptor) + .setParamsExtractor( + request -> { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + }) + .build(); + GrpcCallSettings updateUserTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(updateUserMethodDescriptor) + .setParamsExtractor( + request -> { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("user.name", String.valueOf(request.getUser().getName())); + return params.build(); + }) + .build(); + GrpcCallSettings deleteUserTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(deleteUserMethodDescriptor) + .setParamsExtractor( + request -> { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + }) + .build(); + GrpcCallSettings listUsersTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(listUsersMethodDescriptor) + .build(); + + this.createUserCallable = + callableFactory.createUnaryCallable( + createUserTransportSettings, settings.createUserSettings(), clientContext); + this.getUserCallable = + callableFactory.createUnaryCallable( + getUserTransportSettings, settings.getUserSettings(), clientContext); + this.updateUserCallable = + callableFactory.createUnaryCallable( + updateUserTransportSettings, settings.updateUserSettings(), clientContext); + this.deleteUserCallable = + callableFactory.createUnaryCallable( + deleteUserTransportSettings, settings.deleteUserSettings(), clientContext); + this.listUsersCallable = + callableFactory.createUnaryCallable( + listUsersTransportSettings, settings.listUsersSettings(), clientContext); + this.listUsersPagedCallable = + callableFactory.createPagedCallable( + listUsersTransportSettings, settings.listUsersSettings(), clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + public GrpcOperationsStub getOperationsStub() { + return operationsStub; + } + + @Override + public UnaryCallable createUserCallable() { + return createUserCallable; + } + + @Override + public UnaryCallable getUserCallable() { + return getUserCallable; + } + + @Override + public UnaryCallable updateUserCallable() { + return updateUserCallable; + } + + @Override + public UnaryCallable deleteUserCallable() { + return deleteUserCallable; + } + + @Override + public UnaryCallable listUsersCallable() { + return listUsersCallable; + } + + @Override + public UnaryCallable listUsersPagedCallable() { + return listUsersPagedCallable; + } + + @Override + public final void close() { + try { + backgroundResources.close(); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new IllegalStateException("Failed to close resource", e); + } + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/GrpcMessagingCallableFactory.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/GrpcMessagingCallableFactory.java new file mode 100644 index 0000000000..82e36cdcdf --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/GrpcMessagingCallableFactory.java @@ -0,0 +1,115 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * gRPC callable factory implementation for the Messaging service API. + * + *

This class is for advanced usage. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class GrpcMessagingCallableFactory implements GrpcStubCallableFactory { + + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, callSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, callSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, callSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, callSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, callSettings, clientContext); + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/GrpcMessagingStub.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/GrpcMessagingStub.java new file mode 100644 index 0000000000..91be592df1 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/GrpcMessagingStub.java @@ -0,0 +1,562 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub; + +import static com.google.showcase.v1beta1.MessagingClient.ListBlurbsPagedResponse; +import static com.google.showcase.v1beta1.MessagingClient.ListRoomsPagedResponse; + +import com.google.api.core.BetaApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.core.BackgroundResourceAggregation; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.common.collect.ImmutableMap; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.GrpcOperationsStub; +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.Blurb; +import com.google.showcase.v1beta1.ConnectRequest; +import com.google.showcase.v1beta1.CreateBlurbRequest; +import com.google.showcase.v1beta1.CreateRoomRequest; +import com.google.showcase.v1beta1.DeleteBlurbRequest; +import com.google.showcase.v1beta1.DeleteRoomRequest; +import com.google.showcase.v1beta1.GetBlurbRequest; +import com.google.showcase.v1beta1.GetRoomRequest; +import com.google.showcase.v1beta1.ListBlurbsRequest; +import com.google.showcase.v1beta1.ListBlurbsResponse; +import com.google.showcase.v1beta1.ListRoomsRequest; +import com.google.showcase.v1beta1.ListRoomsResponse; +import com.google.showcase.v1beta1.Room; +import com.google.showcase.v1beta1.SearchBlurbsMetadata; +import com.google.showcase.v1beta1.SearchBlurbsRequest; +import com.google.showcase.v1beta1.SearchBlurbsResponse; +import com.google.showcase.v1beta1.SendBlurbsResponse; +import com.google.showcase.v1beta1.StreamBlurbsRequest; +import com.google.showcase.v1beta1.StreamBlurbsResponse; +import com.google.showcase.v1beta1.UpdateBlurbRequest; +import com.google.showcase.v1beta1.UpdateRoomRequest; +import io.grpc.MethodDescriptor; +import io.grpc.protobuf.ProtoUtils; +import java.io.IOException; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * gRPC stub implementation for the Messaging service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class GrpcMessagingStub extends MessagingStub { + private static final MethodDescriptor createRoomMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.Messaging/CreateRoom") + .setRequestMarshaller(ProtoUtils.marshaller(CreateRoomRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Room.getDefaultInstance())) + .build(); + + private static final MethodDescriptor getRoomMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.Messaging/GetRoom") + .setRequestMarshaller(ProtoUtils.marshaller(GetRoomRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Room.getDefaultInstance())) + .build(); + + private static final MethodDescriptor updateRoomMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.Messaging/UpdateRoom") + .setRequestMarshaller(ProtoUtils.marshaller(UpdateRoomRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Room.getDefaultInstance())) + .build(); + + private static final MethodDescriptor deleteRoomMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.Messaging/DeleteRoom") + .setRequestMarshaller(ProtoUtils.marshaller(DeleteRoomRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + listRoomsMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.Messaging/ListRooms") + .setRequestMarshaller(ProtoUtils.marshaller(ListRoomsRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(ListRoomsResponse.getDefaultInstance())) + .build(); + + private static final MethodDescriptor createBlurbMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.Messaging/CreateBlurb") + .setRequestMarshaller(ProtoUtils.marshaller(CreateBlurbRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Blurb.getDefaultInstance())) + .build(); + + private static final MethodDescriptor getBlurbMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.Messaging/GetBlurb") + .setRequestMarshaller(ProtoUtils.marshaller(GetBlurbRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Blurb.getDefaultInstance())) + .build(); + + private static final MethodDescriptor updateBlurbMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.Messaging/UpdateBlurb") + .setRequestMarshaller(ProtoUtils.marshaller(UpdateBlurbRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Blurb.getDefaultInstance())) + .build(); + + private static final MethodDescriptor deleteBlurbMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.Messaging/DeleteBlurb") + .setRequestMarshaller(ProtoUtils.marshaller(DeleteBlurbRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + listBlurbsMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.Messaging/ListBlurbs") + .setRequestMarshaller(ProtoUtils.marshaller(ListBlurbsRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(ListBlurbsResponse.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + searchBlurbsMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.Messaging/SearchBlurbs") + .setRequestMarshaller(ProtoUtils.marshaller(SearchBlurbsRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + streamBlurbsMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.SERVER_STREAMING) + .setFullMethodName("google.showcase.v1beta1.Messaging/StreamBlurbs") + .setRequestMarshaller(ProtoUtils.marshaller(StreamBlurbsRequest.getDefaultInstance())) + .setResponseMarshaller( + ProtoUtils.marshaller(StreamBlurbsResponse.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + sendBlurbsMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.CLIENT_STREAMING) + .setFullMethodName("google.showcase.v1beta1.Messaging/SendBlurbs") + .setRequestMarshaller(ProtoUtils.marshaller(CreateBlurbRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(SendBlurbsResponse.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + connectMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.BIDI_STREAMING) + .setFullMethodName("google.showcase.v1beta1.Messaging/Connect") + .setRequestMarshaller(ProtoUtils.marshaller(ConnectRequest.getDefaultInstance())) + .setResponseMarshaller( + ProtoUtils.marshaller(StreamBlurbsResponse.getDefaultInstance())) + .build(); + + private final UnaryCallable createRoomCallable; + private final UnaryCallable getRoomCallable; + private final UnaryCallable updateRoomCallable; + private final UnaryCallable deleteRoomCallable; + private final UnaryCallable listRoomsCallable; + private final UnaryCallable listRoomsPagedCallable; + private final UnaryCallable createBlurbCallable; + private final UnaryCallable getBlurbCallable; + private final UnaryCallable updateBlurbCallable; + private final UnaryCallable deleteBlurbCallable; + private final UnaryCallable listBlurbsCallable; + private final UnaryCallable listBlurbsPagedCallable; + private final UnaryCallable searchBlurbsCallable; + private final OperationCallable + searchBlurbsOperationCallable; + private final ServerStreamingCallable + streamBlurbsCallable; + private final ClientStreamingCallable sendBlurbsCallable; + private final BidiStreamingCallable connectCallable; + + private final BackgroundResource backgroundResources; + private final GrpcOperationsStub operationsStub; + private final GrpcStubCallableFactory callableFactory; + + public static final GrpcMessagingStub create(MessagingStubSettings settings) throws IOException { + return new GrpcMessagingStub(settings, ClientContext.create(settings)); + } + + public static final GrpcMessagingStub create(ClientContext clientContext) throws IOException { + return new GrpcMessagingStub(MessagingStubSettings.newBuilder().build(), clientContext); + } + + public static final GrpcMessagingStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcMessagingStub( + MessagingStubSettings.newBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of GrpcMessagingStub, using the given settings. This is protected so + * that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected GrpcMessagingStub(MessagingStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new GrpcMessagingCallableFactory()); + } + + /** + * Constructs an instance of GrpcMessagingStub, using the given settings. This is protected so + * that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected GrpcMessagingStub( + MessagingStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory); + + GrpcCallSettings createRoomTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(createRoomMethodDescriptor) + .build(); + GrpcCallSettings getRoomTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(getRoomMethodDescriptor) + .setParamsExtractor( + request -> { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + }) + .build(); + GrpcCallSettings updateRoomTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(updateRoomMethodDescriptor) + .setParamsExtractor( + request -> { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("room.name", String.valueOf(request.getRoom().getName())); + return params.build(); + }) + .build(); + GrpcCallSettings deleteRoomTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(deleteRoomMethodDescriptor) + .setParamsExtractor( + request -> { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + }) + .build(); + GrpcCallSettings listRoomsTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(listRoomsMethodDescriptor) + .build(); + GrpcCallSettings createBlurbTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(createBlurbMethodDescriptor) + .setParamsExtractor( + request -> { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("parent", String.valueOf(request.getParent())); + return params.build(); + }) + .build(); + GrpcCallSettings getBlurbTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(getBlurbMethodDescriptor) + .setParamsExtractor( + request -> { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + }) + .build(); + GrpcCallSettings updateBlurbTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(updateBlurbMethodDescriptor) + .setParamsExtractor( + request -> { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("blurb.name", String.valueOf(request.getBlurb().getName())); + return params.build(); + }) + .build(); + GrpcCallSettings deleteBlurbTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(deleteBlurbMethodDescriptor) + .setParamsExtractor( + request -> { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + }) + .build(); + GrpcCallSettings listBlurbsTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(listBlurbsMethodDescriptor) + .setParamsExtractor( + request -> { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("parent", String.valueOf(request.getParent())); + return params.build(); + }) + .build(); + GrpcCallSettings searchBlurbsTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(searchBlurbsMethodDescriptor) + .setParamsExtractor( + request -> { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("parent", String.valueOf(request.getParent())); + return params.build(); + }) + .build(); + GrpcCallSettings streamBlurbsTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(streamBlurbsMethodDescriptor) + .setParamsExtractor( + request -> { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + }) + .build(); + GrpcCallSettings sendBlurbsTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(sendBlurbsMethodDescriptor) + .setParamsExtractor( + request -> { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("parent", String.valueOf(request.getParent())); + return params.build(); + }) + .build(); + GrpcCallSettings connectTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(connectMethodDescriptor) + .build(); + + this.createRoomCallable = + callableFactory.createUnaryCallable( + createRoomTransportSettings, settings.createRoomSettings(), clientContext); + this.getRoomCallable = + callableFactory.createUnaryCallable( + getRoomTransportSettings, settings.getRoomSettings(), clientContext); + this.updateRoomCallable = + callableFactory.createUnaryCallable( + updateRoomTransportSettings, settings.updateRoomSettings(), clientContext); + this.deleteRoomCallable = + callableFactory.createUnaryCallable( + deleteRoomTransportSettings, settings.deleteRoomSettings(), clientContext); + this.listRoomsCallable = + callableFactory.createUnaryCallable( + listRoomsTransportSettings, settings.listRoomsSettings(), clientContext); + this.listRoomsPagedCallable = + callableFactory.createPagedCallable( + listRoomsTransportSettings, settings.listRoomsSettings(), clientContext); + this.createBlurbCallable = + callableFactory.createUnaryCallable( + createBlurbTransportSettings, settings.createBlurbSettings(), clientContext); + this.getBlurbCallable = + callableFactory.createUnaryCallable( + getBlurbTransportSettings, settings.getBlurbSettings(), clientContext); + this.updateBlurbCallable = + callableFactory.createUnaryCallable( + updateBlurbTransportSettings, settings.updateBlurbSettings(), clientContext); + this.deleteBlurbCallable = + callableFactory.createUnaryCallable( + deleteBlurbTransportSettings, settings.deleteBlurbSettings(), clientContext); + this.listBlurbsCallable = + callableFactory.createUnaryCallable( + listBlurbsTransportSettings, settings.listBlurbsSettings(), clientContext); + this.listBlurbsPagedCallable = + callableFactory.createPagedCallable( + listBlurbsTransportSettings, settings.listBlurbsSettings(), clientContext); + this.searchBlurbsCallable = + callableFactory.createUnaryCallable( + searchBlurbsTransportSettings, settings.searchBlurbsSettings(), clientContext); + this.searchBlurbsOperationCallable = + callableFactory.createOperationCallable( + searchBlurbsTransportSettings, + settings.searchBlurbsOperationSettings(), + clientContext, + operationsStub); + this.streamBlurbsCallable = + callableFactory.createServerStreamingCallable( + streamBlurbsTransportSettings, settings.streamBlurbsSettings(), clientContext); + this.sendBlurbsCallable = + callableFactory.createClientStreamingCallable( + sendBlurbsTransportSettings, settings.sendBlurbsSettings(), clientContext); + this.connectCallable = + callableFactory.createBidiStreamingCallable( + connectTransportSettings, settings.connectSettings(), clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + public GrpcOperationsStub getOperationsStub() { + return operationsStub; + } + + @Override + public UnaryCallable createRoomCallable() { + return createRoomCallable; + } + + @Override + public UnaryCallable getRoomCallable() { + return getRoomCallable; + } + + @Override + public UnaryCallable updateRoomCallable() { + return updateRoomCallable; + } + + @Override + public UnaryCallable deleteRoomCallable() { + return deleteRoomCallable; + } + + @Override + public UnaryCallable listRoomsCallable() { + return listRoomsCallable; + } + + @Override + public UnaryCallable listRoomsPagedCallable() { + return listRoomsPagedCallable; + } + + @Override + public UnaryCallable createBlurbCallable() { + return createBlurbCallable; + } + + @Override + public UnaryCallable getBlurbCallable() { + return getBlurbCallable; + } + + @Override + public UnaryCallable updateBlurbCallable() { + return updateBlurbCallable; + } + + @Override + public UnaryCallable deleteBlurbCallable() { + return deleteBlurbCallable; + } + + @Override + public UnaryCallable listBlurbsCallable() { + return listBlurbsCallable; + } + + @Override + public UnaryCallable listBlurbsPagedCallable() { + return listBlurbsPagedCallable; + } + + @Override + public UnaryCallable searchBlurbsCallable() { + return searchBlurbsCallable; + } + + @Override + public OperationCallable + searchBlurbsOperationCallable() { + return searchBlurbsOperationCallable; + } + + @Override + public ServerStreamingCallable streamBlurbsCallable() { + return streamBlurbsCallable; + } + + @Override + public ClientStreamingCallable sendBlurbsCallable() { + return sendBlurbsCallable; + } + + @Override + public BidiStreamingCallable connectCallable() { + return connectCallable; + } + + @Override + public final void close() { + try { + backgroundResources.close(); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new IllegalStateException("Failed to close resource", e); + } + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/GrpcSequenceServiceCallableFactory.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/GrpcSequenceServiceCallableFactory.java new file mode 100644 index 0000000000..b7ed163bf7 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/GrpcSequenceServiceCallableFactory.java @@ -0,0 +1,115 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * gRPC callable factory implementation for the SequenceService service API. + * + *

This class is for advanced usage. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class GrpcSequenceServiceCallableFactory implements GrpcStubCallableFactory { + + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, callSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, callSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, callSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, callSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, callSettings, clientContext); + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/GrpcSequenceServiceStub.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/GrpcSequenceServiceStub.java new file mode 100644 index 0000000000..9f34118467 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/GrpcSequenceServiceStub.java @@ -0,0 +1,223 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.core.BackgroundResourceAggregation; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.common.collect.ImmutableMap; +import com.google.longrunning.stub.GrpcOperationsStub; +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.AttemptSequenceRequest; +import com.google.showcase.v1beta1.CreateSequenceRequest; +import com.google.showcase.v1beta1.GetSequenceReportRequest; +import com.google.showcase.v1beta1.Sequence; +import com.google.showcase.v1beta1.SequenceReport; +import io.grpc.MethodDescriptor; +import io.grpc.protobuf.ProtoUtils; +import java.io.IOException; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * gRPC stub implementation for the SequenceService service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class GrpcSequenceServiceStub extends SequenceServiceStub { + private static final MethodDescriptor + createSequenceMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.SequenceService/CreateSequence") + .setRequestMarshaller( + ProtoUtils.marshaller(CreateSequenceRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Sequence.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + getSequenceReportMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.SequenceService/GetSequenceReport") + .setRequestMarshaller( + ProtoUtils.marshaller(GetSequenceReportRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(SequenceReport.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + attemptSequenceMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.SequenceService/AttemptSequence") + .setRequestMarshaller( + ProtoUtils.marshaller(AttemptSequenceRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance())) + .build(); + + private final UnaryCallable createSequenceCallable; + private final UnaryCallable getSequenceReportCallable; + private final UnaryCallable attemptSequenceCallable; + + private final BackgroundResource backgroundResources; + private final GrpcOperationsStub operationsStub; + private final GrpcStubCallableFactory callableFactory; + + public static final GrpcSequenceServiceStub create(SequenceServiceStubSettings settings) + throws IOException { + return new GrpcSequenceServiceStub(settings, ClientContext.create(settings)); + } + + public static final GrpcSequenceServiceStub create(ClientContext clientContext) + throws IOException { + return new GrpcSequenceServiceStub( + SequenceServiceStubSettings.newBuilder().build(), clientContext); + } + + public static final GrpcSequenceServiceStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcSequenceServiceStub( + SequenceServiceStubSettings.newBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of GrpcSequenceServiceStub, using the given settings. This is protected + * so that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected GrpcSequenceServiceStub( + SequenceServiceStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new GrpcSequenceServiceCallableFactory()); + } + + /** + * Constructs an instance of GrpcSequenceServiceStub, using the given settings. This is protected + * so that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected GrpcSequenceServiceStub( + SequenceServiceStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory); + + GrpcCallSettings createSequenceTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(createSequenceMethodDescriptor) + .build(); + GrpcCallSettings getSequenceReportTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(getSequenceReportMethodDescriptor) + .setParamsExtractor( + request -> { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + }) + .build(); + GrpcCallSettings attemptSequenceTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(attemptSequenceMethodDescriptor) + .setParamsExtractor( + request -> { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + }) + .build(); + + this.createSequenceCallable = + callableFactory.createUnaryCallable( + createSequenceTransportSettings, settings.createSequenceSettings(), clientContext); + this.getSequenceReportCallable = + callableFactory.createUnaryCallable( + getSequenceReportTransportSettings, + settings.getSequenceReportSettings(), + clientContext); + this.attemptSequenceCallable = + callableFactory.createUnaryCallable( + attemptSequenceTransportSettings, settings.attemptSequenceSettings(), clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + public GrpcOperationsStub getOperationsStub() { + return operationsStub; + } + + @Override + public UnaryCallable createSequenceCallable() { + return createSequenceCallable; + } + + @Override + public UnaryCallable getSequenceReportCallable() { + return getSequenceReportCallable; + } + + @Override + public UnaryCallable attemptSequenceCallable() { + return attemptSequenceCallable; + } + + @Override + public final void close() { + try { + backgroundResources.close(); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new IllegalStateException("Failed to close resource", e); + } + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/GrpcTestingCallableFactory.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/GrpcTestingCallableFactory.java new file mode 100644 index 0000000000..d117701765 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/GrpcTestingCallableFactory.java @@ -0,0 +1,115 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * gRPC callable factory implementation for the Testing service API. + * + *

This class is for advanced usage. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class GrpcTestingCallableFactory implements GrpcStubCallableFactory { + + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, callSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, callSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, callSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, callSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, callSettings, clientContext); + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/GrpcTestingStub.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/GrpcTestingStub.java new file mode 100644 index 0000000000..0787a31179 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/GrpcTestingStub.java @@ -0,0 +1,378 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub; + +import static com.google.showcase.v1beta1.TestingClient.ListSessionsPagedResponse; +import static com.google.showcase.v1beta1.TestingClient.ListTestsPagedResponse; + +import com.google.api.core.BetaApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.core.BackgroundResourceAggregation; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.common.collect.ImmutableMap; +import com.google.longrunning.stub.GrpcOperationsStub; +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.CreateSessionRequest; +import com.google.showcase.v1beta1.DeleteSessionRequest; +import com.google.showcase.v1beta1.DeleteTestRequest; +import com.google.showcase.v1beta1.GetSessionRequest; +import com.google.showcase.v1beta1.ListSessionsRequest; +import com.google.showcase.v1beta1.ListSessionsResponse; +import com.google.showcase.v1beta1.ListTestsRequest; +import com.google.showcase.v1beta1.ListTestsResponse; +import com.google.showcase.v1beta1.ReportSessionRequest; +import com.google.showcase.v1beta1.ReportSessionResponse; +import com.google.showcase.v1beta1.Session; +import com.google.showcase.v1beta1.VerifyTestRequest; +import com.google.showcase.v1beta1.VerifyTestResponse; +import io.grpc.MethodDescriptor; +import io.grpc.protobuf.ProtoUtils; +import java.io.IOException; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * gRPC stub implementation for the Testing service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class GrpcTestingStub extends TestingStub { + private static final MethodDescriptor + createSessionMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.Testing/CreateSession") + .setRequestMarshaller( + ProtoUtils.marshaller(CreateSessionRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Session.getDefaultInstance())) + .build(); + + private static final MethodDescriptor getSessionMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.Testing/GetSession") + .setRequestMarshaller(ProtoUtils.marshaller(GetSessionRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Session.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + listSessionsMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.Testing/ListSessions") + .setRequestMarshaller(ProtoUtils.marshaller(ListSessionsRequest.getDefaultInstance())) + .setResponseMarshaller( + ProtoUtils.marshaller(ListSessionsResponse.getDefaultInstance())) + .build(); + + private static final MethodDescriptor deleteSessionMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.Testing/DeleteSession") + .setRequestMarshaller(ProtoUtils.marshaller(DeleteSessionRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + reportSessionMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.Testing/ReportSession") + .setRequestMarshaller( + ProtoUtils.marshaller(ReportSessionRequest.getDefaultInstance())) + .setResponseMarshaller( + ProtoUtils.marshaller(ReportSessionResponse.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + listTestsMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.Testing/ListTests") + .setRequestMarshaller(ProtoUtils.marshaller(ListTestsRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(ListTestsResponse.getDefaultInstance())) + .build(); + + private static final MethodDescriptor deleteTestMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.Testing/DeleteTest") + .setRequestMarshaller(ProtoUtils.marshaller(DeleteTestRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + verifyTestMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.showcase.v1beta1.Testing/VerifyTest") + .setRequestMarshaller(ProtoUtils.marshaller(VerifyTestRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(VerifyTestResponse.getDefaultInstance())) + .build(); + + private final UnaryCallable createSessionCallable; + private final UnaryCallable getSessionCallable; + private final UnaryCallable listSessionsCallable; + private final UnaryCallable + listSessionsPagedCallable; + private final UnaryCallable deleteSessionCallable; + private final UnaryCallable reportSessionCallable; + private final UnaryCallable listTestsCallable; + private final UnaryCallable listTestsPagedCallable; + private final UnaryCallable deleteTestCallable; + private final UnaryCallable verifyTestCallable; + + private final BackgroundResource backgroundResources; + private final GrpcOperationsStub operationsStub; + private final GrpcStubCallableFactory callableFactory; + + public static final GrpcTestingStub create(TestingStubSettings settings) throws IOException { + return new GrpcTestingStub(settings, ClientContext.create(settings)); + } + + public static final GrpcTestingStub create(ClientContext clientContext) throws IOException { + return new GrpcTestingStub(TestingStubSettings.newBuilder().build(), clientContext); + } + + public static final GrpcTestingStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcTestingStub( + TestingStubSettings.newBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of GrpcTestingStub, using the given settings. This is protected so that + * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. + */ + protected GrpcTestingStub(TestingStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new GrpcTestingCallableFactory()); + } + + /** + * Constructs an instance of GrpcTestingStub, using the given settings. This is protected so that + * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. + */ + protected GrpcTestingStub( + TestingStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory); + + GrpcCallSettings createSessionTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(createSessionMethodDescriptor) + .build(); + GrpcCallSettings getSessionTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(getSessionMethodDescriptor) + .setParamsExtractor( + request -> { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + }) + .build(); + GrpcCallSettings listSessionsTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(listSessionsMethodDescriptor) + .build(); + GrpcCallSettings deleteSessionTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(deleteSessionMethodDescriptor) + .setParamsExtractor( + request -> { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + }) + .build(); + GrpcCallSettings reportSessionTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(reportSessionMethodDescriptor) + .setParamsExtractor( + request -> { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + }) + .build(); + GrpcCallSettings listTestsTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(listTestsMethodDescriptor) + .setParamsExtractor( + request -> { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("parent", String.valueOf(request.getParent())); + return params.build(); + }) + .build(); + GrpcCallSettings deleteTestTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(deleteTestMethodDescriptor) + .setParamsExtractor( + request -> { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + }) + .build(); + GrpcCallSettings verifyTestTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(verifyTestMethodDescriptor) + .setParamsExtractor( + request -> { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + }) + .build(); + + this.createSessionCallable = + callableFactory.createUnaryCallable( + createSessionTransportSettings, settings.createSessionSettings(), clientContext); + this.getSessionCallable = + callableFactory.createUnaryCallable( + getSessionTransportSettings, settings.getSessionSettings(), clientContext); + this.listSessionsCallable = + callableFactory.createUnaryCallable( + listSessionsTransportSettings, settings.listSessionsSettings(), clientContext); + this.listSessionsPagedCallable = + callableFactory.createPagedCallable( + listSessionsTransportSettings, settings.listSessionsSettings(), clientContext); + this.deleteSessionCallable = + callableFactory.createUnaryCallable( + deleteSessionTransportSettings, settings.deleteSessionSettings(), clientContext); + this.reportSessionCallable = + callableFactory.createUnaryCallable( + reportSessionTransportSettings, settings.reportSessionSettings(), clientContext); + this.listTestsCallable = + callableFactory.createUnaryCallable( + listTestsTransportSettings, settings.listTestsSettings(), clientContext); + this.listTestsPagedCallable = + callableFactory.createPagedCallable( + listTestsTransportSettings, settings.listTestsSettings(), clientContext); + this.deleteTestCallable = + callableFactory.createUnaryCallable( + deleteTestTransportSettings, settings.deleteTestSettings(), clientContext); + this.verifyTestCallable = + callableFactory.createUnaryCallable( + verifyTestTransportSettings, settings.verifyTestSettings(), clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + public GrpcOperationsStub getOperationsStub() { + return operationsStub; + } + + @Override + public UnaryCallable createSessionCallable() { + return createSessionCallable; + } + + @Override + public UnaryCallable getSessionCallable() { + return getSessionCallable; + } + + @Override + public UnaryCallable listSessionsCallable() { + return listSessionsCallable; + } + + @Override + public UnaryCallable listSessionsPagedCallable() { + return listSessionsPagedCallable; + } + + @Override + public UnaryCallable deleteSessionCallable() { + return deleteSessionCallable; + } + + @Override + public UnaryCallable reportSessionCallable() { + return reportSessionCallable; + } + + @Override + public UnaryCallable listTestsCallable() { + return listTestsCallable; + } + + @Override + public UnaryCallable listTestsPagedCallable() { + return listTestsPagedCallable; + } + + @Override + public UnaryCallable deleteTestCallable() { + return deleteTestCallable; + } + + @Override + public UnaryCallable verifyTestCallable() { + return verifyTestCallable; + } + + @Override + public final void close() { + try { + backgroundResources.close(); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new IllegalStateException("Failed to close resource", e); + } + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/HttpJsonComplianceCallableFactory.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/HttpJsonComplianceCallableFactory.java new file mode 100644 index 0000000000..ae83f1e131 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/HttpJsonComplianceCallableFactory.java @@ -0,0 +1,105 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonCallableFactory; +import com.google.api.gax.httpjson.HttpJsonOperationSnapshotCallable; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.longrunning.stub.OperationsStub; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST callable factory implementation for the Compliance service API. + * + *

This class is for advanced usage. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonComplianceCallableFactory + implements HttpJsonStubCallableFactory { + + @Override + public UnaryCallable createUnaryCallable( + HttpJsonCallSettings httpJsonCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createUnaryCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + HttpJsonCallSettings httpJsonCallSettings, + PagedCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createPagedCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + HttpJsonCallSettings httpJsonCallSettings, + BatchingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createBatchingCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + @Override + public + OperationCallable createOperationCallable( + HttpJsonCallSettings httpJsonCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + UnaryCallable innerCallable = + HttpJsonCallableFactory.createBaseUnaryCallable( + httpJsonCallSettings, callSettings.getInitialCallSettings(), clientContext); + HttpJsonOperationSnapshotCallable initialCallable = + new HttpJsonOperationSnapshotCallable( + innerCallable, + httpJsonCallSettings.getMethodDescriptor().getOperationSnapshotFactory()); + return HttpJsonCallableFactory.createOperationCallable( + callSettings, clientContext, operationsStub.longRunningClient(), initialCallable); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + HttpJsonCallSettings httpJsonCallSettings, + ServerStreamingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createServerStreamingCallable( + httpJsonCallSettings, callSettings, clientContext); + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/HttpJsonComplianceStub.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/HttpJsonComplianceStub.java new file mode 100644 index 0000000000..5fd2556f89 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/HttpJsonComplianceStub.java @@ -0,0 +1,772 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.core.BackgroundResourceAggregation; +import com.google.api.gax.httpjson.ApiMethodDescriptor; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.ProtoMessageRequestFormatter; +import com.google.api.gax.httpjson.ProtoMessageResponseParser; +import com.google.api.gax.httpjson.ProtoRestSerializer; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.protobuf.TypeRegistry; +import com.google.showcase.v1beta1.EnumRequest; +import com.google.showcase.v1beta1.EnumResponse; +import com.google.showcase.v1beta1.RepeatRequest; +import com.google.showcase.v1beta1.RepeatResponse; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST stub implementation for the Compliance service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonComplianceStub extends ComplianceStub { + private static final TypeRegistry typeRegistry = TypeRegistry.newBuilder().build(); + + private static final ApiMethodDescriptor + repeatDataBodyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.Compliance/RepeatDataBody") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/repeat:body", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().build(), true)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(RepeatResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + repeatDataBodyInfoMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.Compliance/RepeatDataBodyInfo") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/repeat:bodyinfo", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "fDouble", request.getFDouble()); + serializer.putQueryParam(fields, "fInt32", request.getFInt32()); + serializer.putQueryParam(fields, "fInt64", request.getFInt64()); + if (request.hasIntendedBindingUri()) { + serializer.putQueryParam( + fields, "intendedBindingUri", request.getIntendedBindingUri()); + } + serializer.putQueryParam(fields, "name", request.getName()); + if (request.hasPDouble()) { + serializer.putQueryParam(fields, "pDouble", request.getPDouble()); + } + if (request.hasPInt32()) { + serializer.putQueryParam(fields, "pInt32", request.getPInt32()); + } + if (request.hasPInt64()) { + serializer.putQueryParam(fields, "pInt64", request.getPInt64()); + } + serializer.putQueryParam( + fields, "serverVerify", request.getServerVerify()); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create().toBody("info", request.getInfo(), true)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(RepeatResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + repeatDataQueryMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.Compliance/RepeatDataQuery") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/repeat:query", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "fDouble", request.getFDouble()); + serializer.putQueryParam(fields, "fInt32", request.getFInt32()); + serializer.putQueryParam(fields, "fInt64", request.getFInt64()); + serializer.putQueryParam(fields, "info", request.getInfo()); + if (request.hasIntendedBindingUri()) { + serializer.putQueryParam( + fields, "intendedBindingUri", request.getIntendedBindingUri()); + } + serializer.putQueryParam(fields, "name", request.getName()); + if (request.hasPDouble()) { + serializer.putQueryParam(fields, "pDouble", request.getPDouble()); + } + if (request.hasPInt32()) { + serializer.putQueryParam(fields, "pInt32", request.getPInt32()); + } + if (request.hasPInt64()) { + serializer.putQueryParam(fields, "pInt64", request.getPInt64()); + } + serializer.putQueryParam( + fields, "serverVerify", request.getServerVerify()); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(RepeatResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + repeatDataSimplePathMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.Compliance/RepeatDataSimplePath") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/repeat/{info.fString}/{info.fInt32}/{info.fDouble}/{info.fBool}/{info.fKingdom}:simplepath", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam( + fields, "info.fBool", request.getInfo().getFBool()); + serializer.putPathParam( + fields, "info.fDouble", request.getInfo().getFDouble()); + serializer.putPathParam( + fields, "info.fInt32", request.getInfo().getFInt32()); + serializer.putPathParam( + fields, "info.fKingdom", request.getInfo().getFKingdomValue()); + serializer.putPathParam( + fields, "info.fString", request.getInfo().getFString()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "fDouble", request.getFDouble()); + serializer.putQueryParam(fields, "fInt32", request.getFInt32()); + serializer.putQueryParam(fields, "fInt64", request.getFInt64()); + serializer.putQueryParam(fields, "info", request.getInfo()); + if (request.hasIntendedBindingUri()) { + serializer.putQueryParam( + fields, "intendedBindingUri", request.getIntendedBindingUri()); + } + serializer.putQueryParam(fields, "name", request.getName()); + if (request.hasPDouble()) { + serializer.putQueryParam(fields, "pDouble", request.getPDouble()); + } + if (request.hasPInt32()) { + serializer.putQueryParam(fields, "pInt32", request.getPInt32()); + } + if (request.hasPInt64()) { + serializer.putQueryParam(fields, "pInt64", request.getPInt64()); + } + serializer.putQueryParam( + fields, "serverVerify", request.getServerVerify()); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(RepeatResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + repeatDataPathResourceMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.Compliance/RepeatDataPathResource") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/repeat/{info.fString=first/*}/{info.fChild.fString=second/*}/bool/{info.fBool}:pathresource", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam( + fields, "info.fBool", request.getInfo().getFBool()); + serializer.putPathParam( + fields, + "info.fChild.fString", + request.getInfo().getFChild().getFString()); + serializer.putPathParam( + fields, "info.fString", request.getInfo().getFString()); + return fields; + }) + .setAdditionalPaths( + "/v1beta1/repeat/{info.fChild.fString=first/*}/{info.fString=second/*}/bool/{info.fBool}:childfirstpathresource") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "fDouble", request.getFDouble()); + serializer.putQueryParam(fields, "fInt32", request.getFInt32()); + serializer.putQueryParam(fields, "fInt64", request.getFInt64()); + serializer.putQueryParam(fields, "info", request.getInfo()); + if (request.hasIntendedBindingUri()) { + serializer.putQueryParam( + fields, "intendedBindingUri", request.getIntendedBindingUri()); + } + serializer.putQueryParam(fields, "name", request.getName()); + if (request.hasPDouble()) { + serializer.putQueryParam(fields, "pDouble", request.getPDouble()); + } + if (request.hasPInt32()) { + serializer.putQueryParam(fields, "pInt32", request.getPInt32()); + } + if (request.hasPInt64()) { + serializer.putQueryParam(fields, "pInt64", request.getPInt64()); + } + serializer.putQueryParam( + fields, "serverVerify", request.getServerVerify()); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(RepeatResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + repeatDataPathTrailingResourceMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.showcase.v1beta1.Compliance/RepeatDataPathTrailingResource") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/repeat/{info.fString=first/*}/{info.fChild.fString=second/**}:pathtrailingresource", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam( + fields, + "info.fChild.fString", + request.getInfo().getFChild().getFString()); + serializer.putPathParam( + fields, "info.fString", request.getInfo().getFString()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "fDouble", request.getFDouble()); + serializer.putQueryParam(fields, "fInt32", request.getFInt32()); + serializer.putQueryParam(fields, "fInt64", request.getFInt64()); + serializer.putQueryParam(fields, "info", request.getInfo()); + if (request.hasIntendedBindingUri()) { + serializer.putQueryParam( + fields, "intendedBindingUri", request.getIntendedBindingUri()); + } + serializer.putQueryParam(fields, "name", request.getName()); + if (request.hasPDouble()) { + serializer.putQueryParam(fields, "pDouble", request.getPDouble()); + } + if (request.hasPInt32()) { + serializer.putQueryParam(fields, "pInt32", request.getPInt32()); + } + if (request.hasPInt64()) { + serializer.putQueryParam(fields, "pInt64", request.getPInt64()); + } + serializer.putQueryParam( + fields, "serverVerify", request.getServerVerify()); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(RepeatResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + repeatDataBodyPutMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.Compliance/RepeatDataBodyPut") + .setHttpMethod("PUT") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/repeat:bodyput", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().build(), true)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(RepeatResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + repeatDataBodyPatchMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.Compliance/RepeatDataBodyPatch") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/repeat:bodypatch", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().build(), true)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(RepeatResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor getEnumMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.Compliance/GetEnum") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/compliance/enum", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = ProtoRestSerializer.create(); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "unknownEnum", request.getUnknownEnum()); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(EnumResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor verifyEnumMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.Compliance/VerifyEnum") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/compliance/enum", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = ProtoRestSerializer.create(); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "continent", request.getContinentValue()); + serializer.putQueryParam(fields, "request", request.getRequest()); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(EnumResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private final UnaryCallable repeatDataBodyCallable; + private final UnaryCallable repeatDataBodyInfoCallable; + private final UnaryCallable repeatDataQueryCallable; + private final UnaryCallable repeatDataSimplePathCallable; + private final UnaryCallable repeatDataPathResourceCallable; + private final UnaryCallable repeatDataPathTrailingResourceCallable; + private final UnaryCallable repeatDataBodyPutCallable; + private final UnaryCallable repeatDataBodyPatchCallable; + private final UnaryCallable getEnumCallable; + private final UnaryCallable verifyEnumCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonComplianceStub create(ComplianceStubSettings settings) + throws IOException { + return new HttpJsonComplianceStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonComplianceStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonComplianceStub( + ComplianceStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonComplianceStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonComplianceStub( + ComplianceStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonComplianceStub, using the given settings. This is protected + * so that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected HttpJsonComplianceStub(ComplianceStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new HttpJsonComplianceCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonComplianceStub, using the given settings. This is protected + * so that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected HttpJsonComplianceStub( + ComplianceStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + + HttpJsonCallSettings repeatDataBodyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(repeatDataBodyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings repeatDataBodyInfoTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(repeatDataBodyInfoMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings repeatDataQueryTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(repeatDataQueryMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings repeatDataSimplePathTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(repeatDataSimplePathMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings repeatDataPathResourceTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(repeatDataPathResourceMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + repeatDataPathTrailingResourceTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(repeatDataPathTrailingResourceMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings repeatDataBodyPutTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(repeatDataBodyPutMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings repeatDataBodyPatchTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(repeatDataBodyPatchMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getEnumTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getEnumMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings verifyEnumTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(verifyEnumMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.repeatDataBodyCallable = + callableFactory.createUnaryCallable( + repeatDataBodyTransportSettings, settings.repeatDataBodySettings(), clientContext); + this.repeatDataBodyInfoCallable = + callableFactory.createUnaryCallable( + repeatDataBodyInfoTransportSettings, + settings.repeatDataBodyInfoSettings(), + clientContext); + this.repeatDataQueryCallable = + callableFactory.createUnaryCallable( + repeatDataQueryTransportSettings, settings.repeatDataQuerySettings(), clientContext); + this.repeatDataSimplePathCallable = + callableFactory.createUnaryCallable( + repeatDataSimplePathTransportSettings, + settings.repeatDataSimplePathSettings(), + clientContext); + this.repeatDataPathResourceCallable = + callableFactory.createUnaryCallable( + repeatDataPathResourceTransportSettings, + settings.repeatDataPathResourceSettings(), + clientContext); + this.repeatDataPathTrailingResourceCallable = + callableFactory.createUnaryCallable( + repeatDataPathTrailingResourceTransportSettings, + settings.repeatDataPathTrailingResourceSettings(), + clientContext); + this.repeatDataBodyPutCallable = + callableFactory.createUnaryCallable( + repeatDataBodyPutTransportSettings, + settings.repeatDataBodyPutSettings(), + clientContext); + this.repeatDataBodyPatchCallable = + callableFactory.createUnaryCallable( + repeatDataBodyPatchTransportSettings, + settings.repeatDataBodyPatchSettings(), + clientContext); + this.getEnumCallable = + callableFactory.createUnaryCallable( + getEnumTransportSettings, settings.getEnumSettings(), clientContext); + this.verifyEnumCallable = + callableFactory.createUnaryCallable( + verifyEnumTransportSettings, settings.verifyEnumSettings(), clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(repeatDataBodyMethodDescriptor); + methodDescriptors.add(repeatDataBodyInfoMethodDescriptor); + methodDescriptors.add(repeatDataQueryMethodDescriptor); + methodDescriptors.add(repeatDataSimplePathMethodDescriptor); + methodDescriptors.add(repeatDataPathResourceMethodDescriptor); + methodDescriptors.add(repeatDataPathTrailingResourceMethodDescriptor); + methodDescriptors.add(repeatDataBodyPutMethodDescriptor); + methodDescriptors.add(repeatDataBodyPatchMethodDescriptor); + methodDescriptors.add(getEnumMethodDescriptor); + methodDescriptors.add(verifyEnumMethodDescriptor); + return methodDescriptors; + } + + @Override + public UnaryCallable repeatDataBodyCallable() { + return repeatDataBodyCallable; + } + + @Override + public UnaryCallable repeatDataBodyInfoCallable() { + return repeatDataBodyInfoCallable; + } + + @Override + public UnaryCallable repeatDataQueryCallable() { + return repeatDataQueryCallable; + } + + @Override + public UnaryCallable repeatDataSimplePathCallable() { + return repeatDataSimplePathCallable; + } + + @Override + public UnaryCallable repeatDataPathResourceCallable() { + return repeatDataPathResourceCallable; + } + + @Override + public UnaryCallable repeatDataPathTrailingResourceCallable() { + return repeatDataPathTrailingResourceCallable; + } + + @Override + public UnaryCallable repeatDataBodyPutCallable() { + return repeatDataBodyPutCallable; + } + + @Override + public UnaryCallable repeatDataBodyPatchCallable() { + return repeatDataBodyPatchCallable; + } + + @Override + public UnaryCallable getEnumCallable() { + return getEnumCallable; + } + + @Override + public UnaryCallable verifyEnumCallable() { + return verifyEnumCallable; + } + + @Override + public final void close() { + try { + backgroundResources.close(); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new IllegalStateException("Failed to close resource", e); + } + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/HttpJsonEchoCallableFactory.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/HttpJsonEchoCallableFactory.java new file mode 100644 index 0000000000..0702689af2 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/HttpJsonEchoCallableFactory.java @@ -0,0 +1,105 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonCallableFactory; +import com.google.api.gax.httpjson.HttpJsonOperationSnapshotCallable; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.longrunning.stub.OperationsStub; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST callable factory implementation for the Echo service API. + * + *

This class is for advanced usage. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonEchoCallableFactory + implements HttpJsonStubCallableFactory { + + @Override + public UnaryCallable createUnaryCallable( + HttpJsonCallSettings httpJsonCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createUnaryCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + HttpJsonCallSettings httpJsonCallSettings, + PagedCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createPagedCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + HttpJsonCallSettings httpJsonCallSettings, + BatchingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createBatchingCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + @Override + public + OperationCallable createOperationCallable( + HttpJsonCallSettings httpJsonCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + UnaryCallable innerCallable = + HttpJsonCallableFactory.createBaseUnaryCallable( + httpJsonCallSettings, callSettings.getInitialCallSettings(), clientContext); + HttpJsonOperationSnapshotCallable initialCallable = + new HttpJsonOperationSnapshotCallable( + innerCallable, + httpJsonCallSettings.getMethodDescriptor().getOperationSnapshotFactory()); + return HttpJsonCallableFactory.createOperationCallable( + callSettings, clientContext, operationsStub.longRunningClient(), initialCallable); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + HttpJsonCallSettings httpJsonCallSettings, + ServerStreamingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createServerStreamingCallable( + httpJsonCallSettings, callSettings, clientContext); + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/HttpJsonEchoStub.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/HttpJsonEchoStub.java new file mode 100644 index 0000000000..3ddb5d3570 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/HttpJsonEchoStub.java @@ -0,0 +1,562 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub; + +import static com.google.showcase.v1beta1.EchoClient.PagedExpandLegacyMappedPagedResponse; +import static com.google.showcase.v1beta1.EchoClient.PagedExpandPagedResponse; + +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.core.BackgroundResourceAggregation; +import com.google.api.gax.httpjson.ApiMethodDescriptor; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonOperationSnapshot; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.ProtoMessageRequestFormatter; +import com.google.api.gax.httpjson.ProtoMessageResponseParser; +import com.google.api.gax.httpjson.ProtoRestSerializer; +import com.google.api.gax.httpjson.longrunning.stub.HttpJsonOperationsStub; +import com.google.api.gax.longrunning.OperationSnapshot; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.protobuf.TypeRegistry; +import com.google.showcase.v1beta1.BlockRequest; +import com.google.showcase.v1beta1.BlockResponse; +import com.google.showcase.v1beta1.EchoRequest; +import com.google.showcase.v1beta1.EchoResponse; +import com.google.showcase.v1beta1.ExpandRequest; +import com.google.showcase.v1beta1.PagedExpandLegacyMappedResponse; +import com.google.showcase.v1beta1.PagedExpandLegacyRequest; +import com.google.showcase.v1beta1.PagedExpandRequest; +import com.google.showcase.v1beta1.PagedExpandResponse; +import com.google.showcase.v1beta1.WaitMetadata; +import com.google.showcase.v1beta1.WaitRequest; +import com.google.showcase.v1beta1.WaitResponse; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST stub implementation for the Echo service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonEchoStub extends EchoStub { + private static final TypeRegistry typeRegistry = + TypeRegistry.newBuilder() + .add(WaitResponse.getDescriptor()) + .add(WaitMetadata.getDescriptor()) + .build(); + + private static final ApiMethodDescriptor echoMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.Echo/Echo") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/echo:echo", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = ProtoRestSerializer.create(); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().build(), true)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(EchoResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor expandMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.Echo/Expand") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.SERVER_STREAMING) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/echo:expand", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().build(), true)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(EchoResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + pagedExpandMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.Echo/PagedExpand") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/echo:pagedExpand", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().build(), true)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(PagedExpandResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + pagedExpandLegacyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.Echo/PagedExpandLegacy") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/echo:pagedExpandLegacy", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().build(), true)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(PagedExpandResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + pagedExpandLegacyMappedMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.Echo/PagedExpandLegacyMapped") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/echo:pagedExpandLegacyMapped", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().build(), true)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(PagedExpandLegacyMappedResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor waitMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.Echo/Wait") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/echo:wait", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = ProtoRestSerializer.create(); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().build(), true)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (WaitRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor blockMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.Echo/Block") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/echo:block", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = ProtoRestSerializer.create(); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().build(), true)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(BlockResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private final UnaryCallable echoCallable; + private final ServerStreamingCallable expandCallable; + private final UnaryCallable pagedExpandCallable; + private final UnaryCallable + pagedExpandPagedCallable; + private final UnaryCallable + pagedExpandLegacyCallable; + private final UnaryCallable + pagedExpandLegacyMappedCallable; + private final UnaryCallable + pagedExpandLegacyMappedPagedCallable; + private final UnaryCallable waitCallable; + private final OperationCallable waitOperationCallable; + private final UnaryCallable blockCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonOperationsStub httpJsonOperationsStub; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonEchoStub create(EchoStubSettings settings) throws IOException { + return new HttpJsonEchoStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonEchoStub create(ClientContext clientContext) throws IOException { + return new HttpJsonEchoStub(EchoStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonEchoStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonEchoStub( + EchoStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonEchoStub, using the given settings. This is protected so that + * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. + */ + protected HttpJsonEchoStub(EchoStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new HttpJsonEchoCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonEchoStub, using the given settings. This is protected so that + * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. + */ + protected HttpJsonEchoStub( + EchoStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.httpJsonOperationsStub = + HttpJsonOperationsStub.create(clientContext, callableFactory, typeRegistry); + + HttpJsonCallSettings echoTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(echoMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings expandTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(expandMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings pagedExpandTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(pagedExpandMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + pagedExpandLegacyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(pagedExpandLegacyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + pagedExpandLegacyMappedTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(pagedExpandLegacyMappedMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings waitTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(waitMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings blockTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(blockMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.echoCallable = + callableFactory.createUnaryCallable( + echoTransportSettings, settings.echoSettings(), clientContext); + this.expandCallable = + callableFactory.createServerStreamingCallable( + expandTransportSettings, settings.expandSettings(), clientContext); + this.pagedExpandCallable = + callableFactory.createUnaryCallable( + pagedExpandTransportSettings, settings.pagedExpandSettings(), clientContext); + this.pagedExpandPagedCallable = + callableFactory.createPagedCallable( + pagedExpandTransportSettings, settings.pagedExpandSettings(), clientContext); + this.pagedExpandLegacyCallable = + callableFactory.createUnaryCallable( + pagedExpandLegacyTransportSettings, + settings.pagedExpandLegacySettings(), + clientContext); + this.pagedExpandLegacyMappedCallable = + callableFactory.createUnaryCallable( + pagedExpandLegacyMappedTransportSettings, + settings.pagedExpandLegacyMappedSettings(), + clientContext); + this.pagedExpandLegacyMappedPagedCallable = + callableFactory.createPagedCallable( + pagedExpandLegacyMappedTransportSettings, + settings.pagedExpandLegacyMappedSettings(), + clientContext); + this.waitCallable = + callableFactory.createUnaryCallable( + waitTransportSettings, settings.waitSettings(), clientContext); + this.waitOperationCallable = + callableFactory.createOperationCallable( + waitTransportSettings, + settings.waitOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.blockCallable = + callableFactory.createUnaryCallable( + blockTransportSettings, settings.blockSettings(), clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(echoMethodDescriptor); + methodDescriptors.add(expandMethodDescriptor); + methodDescriptors.add(pagedExpandMethodDescriptor); + methodDescriptors.add(pagedExpandLegacyMethodDescriptor); + methodDescriptors.add(pagedExpandLegacyMappedMethodDescriptor); + methodDescriptors.add(waitMethodDescriptor); + methodDescriptors.add(blockMethodDescriptor); + return methodDescriptors; + } + + public HttpJsonOperationsStub getHttpJsonOperationsStub() { + return httpJsonOperationsStub; + } + + @Override + public UnaryCallable echoCallable() { + return echoCallable; + } + + @Override + public ServerStreamingCallable expandCallable() { + return expandCallable; + } + + @Override + public UnaryCallable pagedExpandCallable() { + return pagedExpandCallable; + } + + @Override + public UnaryCallable pagedExpandPagedCallable() { + return pagedExpandPagedCallable; + } + + @Override + public UnaryCallable pagedExpandLegacyCallable() { + return pagedExpandLegacyCallable; + } + + @Override + public UnaryCallable + pagedExpandLegacyMappedCallable() { + return pagedExpandLegacyMappedCallable; + } + + @Override + public UnaryCallable + pagedExpandLegacyMappedPagedCallable() { + return pagedExpandLegacyMappedPagedCallable; + } + + @Override + public UnaryCallable waitCallable() { + return waitCallable; + } + + @Override + public OperationCallable waitOperationCallable() { + return waitOperationCallable; + } + + @Override + public UnaryCallable blockCallable() { + return blockCallable; + } + + @Override + public final void close() { + try { + backgroundResources.close(); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new IllegalStateException("Failed to close resource", e); + } + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/HttpJsonIdentityCallableFactory.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/HttpJsonIdentityCallableFactory.java new file mode 100644 index 0000000000..b8766ddbcd --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/HttpJsonIdentityCallableFactory.java @@ -0,0 +1,105 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonCallableFactory; +import com.google.api.gax.httpjson.HttpJsonOperationSnapshotCallable; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.longrunning.stub.OperationsStub; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST callable factory implementation for the Identity service API. + * + *

This class is for advanced usage. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonIdentityCallableFactory + implements HttpJsonStubCallableFactory { + + @Override + public UnaryCallable createUnaryCallable( + HttpJsonCallSettings httpJsonCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createUnaryCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + HttpJsonCallSettings httpJsonCallSettings, + PagedCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createPagedCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + HttpJsonCallSettings httpJsonCallSettings, + BatchingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createBatchingCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + @Override + public + OperationCallable createOperationCallable( + HttpJsonCallSettings httpJsonCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + UnaryCallable innerCallable = + HttpJsonCallableFactory.createBaseUnaryCallable( + httpJsonCallSettings, callSettings.getInitialCallSettings(), clientContext); + HttpJsonOperationSnapshotCallable initialCallable = + new HttpJsonOperationSnapshotCallable( + innerCallable, + httpJsonCallSettings.getMethodDescriptor().getOperationSnapshotFactory()); + return HttpJsonCallableFactory.createOperationCallable( + callSettings, clientContext, operationsStub.longRunningClient(), initialCallable); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + HttpJsonCallSettings httpJsonCallSettings, + ServerStreamingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createServerStreamingCallable( + httpJsonCallSettings, callSettings, clientContext); + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/HttpJsonIdentityStub.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/HttpJsonIdentityStub.java new file mode 100644 index 0000000000..528858e711 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/HttpJsonIdentityStub.java @@ -0,0 +1,406 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub; + +import static com.google.showcase.v1beta1.IdentityClient.ListUsersPagedResponse; + +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.core.BackgroundResourceAggregation; +import com.google.api.gax.httpjson.ApiMethodDescriptor; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.ProtoMessageRequestFormatter; +import com.google.api.gax.httpjson.ProtoMessageResponseParser; +import com.google.api.gax.httpjson.ProtoRestSerializer; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.protobuf.Empty; +import com.google.protobuf.TypeRegistry; +import com.google.showcase.v1beta1.CreateUserRequest; +import com.google.showcase.v1beta1.DeleteUserRequest; +import com.google.showcase.v1beta1.GetUserRequest; +import com.google.showcase.v1beta1.ListUsersRequest; +import com.google.showcase.v1beta1.ListUsersResponse; +import com.google.showcase.v1beta1.UpdateUserRequest; +import com.google.showcase.v1beta1.User; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST stub implementation for the Identity service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonIdentityStub extends IdentityStub { + private static final TypeRegistry typeRegistry = TypeRegistry.newBuilder().build(); + + private static final ApiMethodDescriptor createUserMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.Identity/CreateUser") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/users", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().build(), true)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(User.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor getUserMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.Identity/GetUser") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{name=users/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(User.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor updateUserMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.Identity/UpdateUser") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{user.name=users/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "user.name", request.getUser().getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create().toBody("user", request.getUser(), true)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(User.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor deleteUserMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.Identity/DeleteUser") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{name=users/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Empty.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + listUsersMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.Identity/ListUsers") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/users", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListUsersResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private final UnaryCallable createUserCallable; + private final UnaryCallable getUserCallable; + private final UnaryCallable updateUserCallable; + private final UnaryCallable deleteUserCallable; + private final UnaryCallable listUsersCallable; + private final UnaryCallable listUsersPagedCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonIdentityStub create(IdentityStubSettings settings) + throws IOException { + return new HttpJsonIdentityStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonIdentityStub create(ClientContext clientContext) throws IOException { + return new HttpJsonIdentityStub( + IdentityStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonIdentityStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonIdentityStub( + IdentityStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonIdentityStub, using the given settings. This is protected so + * that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected HttpJsonIdentityStub(IdentityStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new HttpJsonIdentityCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonIdentityStub, using the given settings. This is protected so + * that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected HttpJsonIdentityStub( + IdentityStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + + HttpJsonCallSettings createUserTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createUserMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getUserTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getUserMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings updateUserTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateUserMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deleteUserTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteUserMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings listUsersTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listUsersMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.createUserCallable = + callableFactory.createUnaryCallable( + createUserTransportSettings, settings.createUserSettings(), clientContext); + this.getUserCallable = + callableFactory.createUnaryCallable( + getUserTransportSettings, settings.getUserSettings(), clientContext); + this.updateUserCallable = + callableFactory.createUnaryCallable( + updateUserTransportSettings, settings.updateUserSettings(), clientContext); + this.deleteUserCallable = + callableFactory.createUnaryCallable( + deleteUserTransportSettings, settings.deleteUserSettings(), clientContext); + this.listUsersCallable = + callableFactory.createUnaryCallable( + listUsersTransportSettings, settings.listUsersSettings(), clientContext); + this.listUsersPagedCallable = + callableFactory.createPagedCallable( + listUsersTransportSettings, settings.listUsersSettings(), clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(createUserMethodDescriptor); + methodDescriptors.add(getUserMethodDescriptor); + methodDescriptors.add(updateUserMethodDescriptor); + methodDescriptors.add(deleteUserMethodDescriptor); + methodDescriptors.add(listUsersMethodDescriptor); + return methodDescriptors; + } + + @Override + public UnaryCallable createUserCallable() { + return createUserCallable; + } + + @Override + public UnaryCallable getUserCallable() { + return getUserCallable; + } + + @Override + public UnaryCallable updateUserCallable() { + return updateUserCallable; + } + + @Override + public UnaryCallable deleteUserCallable() { + return deleteUserCallable; + } + + @Override + public UnaryCallable listUsersCallable() { + return listUsersCallable; + } + + @Override + public UnaryCallable listUsersPagedCallable() { + return listUsersPagedCallable; + } + + @Override + public final void close() { + try { + backgroundResources.close(); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new IllegalStateException("Failed to close resource", e); + } + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/HttpJsonMessagingCallableFactory.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/HttpJsonMessagingCallableFactory.java new file mode 100644 index 0000000000..f56157bdd4 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/HttpJsonMessagingCallableFactory.java @@ -0,0 +1,105 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonCallableFactory; +import com.google.api.gax.httpjson.HttpJsonOperationSnapshotCallable; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.longrunning.stub.OperationsStub; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST callable factory implementation for the Messaging service API. + * + *

This class is for advanced usage. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonMessagingCallableFactory + implements HttpJsonStubCallableFactory { + + @Override + public UnaryCallable createUnaryCallable( + HttpJsonCallSettings httpJsonCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createUnaryCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + HttpJsonCallSettings httpJsonCallSettings, + PagedCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createPagedCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + HttpJsonCallSettings httpJsonCallSettings, + BatchingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createBatchingCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + @Override + public + OperationCallable createOperationCallable( + HttpJsonCallSettings httpJsonCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + UnaryCallable innerCallable = + HttpJsonCallableFactory.createBaseUnaryCallable( + httpJsonCallSettings, callSettings.getInitialCallSettings(), clientContext); + HttpJsonOperationSnapshotCallable initialCallable = + new HttpJsonOperationSnapshotCallable( + innerCallable, + httpJsonCallSettings.getMethodDescriptor().getOperationSnapshotFactory()); + return HttpJsonCallableFactory.createOperationCallable( + callSettings, clientContext, operationsStub.longRunningClient(), initialCallable); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + HttpJsonCallSettings httpJsonCallSettings, + ServerStreamingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createServerStreamingCallable( + httpJsonCallSettings, callSettings, clientContext); + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/HttpJsonMessagingStub.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/HttpJsonMessagingStub.java new file mode 100644 index 0000000000..41ac603817 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/HttpJsonMessagingStub.java @@ -0,0 +1,823 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub; + +import static com.google.showcase.v1beta1.MessagingClient.ListBlurbsPagedResponse; +import static com.google.showcase.v1beta1.MessagingClient.ListRoomsPagedResponse; + +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.core.BackgroundResourceAggregation; +import com.google.api.gax.httpjson.ApiMethodDescriptor; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonOperationSnapshot; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.ProtoMessageRequestFormatter; +import com.google.api.gax.httpjson.ProtoMessageResponseParser; +import com.google.api.gax.httpjson.ProtoRestSerializer; +import com.google.api.gax.httpjson.longrunning.stub.HttpJsonOperationsStub; +import com.google.api.gax.longrunning.OperationSnapshot; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.protobuf.Empty; +import com.google.protobuf.TypeRegistry; +import com.google.showcase.v1beta1.Blurb; +import com.google.showcase.v1beta1.CreateBlurbRequest; +import com.google.showcase.v1beta1.CreateRoomRequest; +import com.google.showcase.v1beta1.DeleteBlurbRequest; +import com.google.showcase.v1beta1.DeleteRoomRequest; +import com.google.showcase.v1beta1.GetBlurbRequest; +import com.google.showcase.v1beta1.GetRoomRequest; +import com.google.showcase.v1beta1.ListBlurbsRequest; +import com.google.showcase.v1beta1.ListBlurbsResponse; +import com.google.showcase.v1beta1.ListRoomsRequest; +import com.google.showcase.v1beta1.ListRoomsResponse; +import com.google.showcase.v1beta1.Room; +import com.google.showcase.v1beta1.SearchBlurbsMetadata; +import com.google.showcase.v1beta1.SearchBlurbsRequest; +import com.google.showcase.v1beta1.SearchBlurbsResponse; +import com.google.showcase.v1beta1.StreamBlurbsRequest; +import com.google.showcase.v1beta1.StreamBlurbsResponse; +import com.google.showcase.v1beta1.UpdateBlurbRequest; +import com.google.showcase.v1beta1.UpdateRoomRequest; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST stub implementation for the Messaging service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonMessagingStub extends MessagingStub { + private static final TypeRegistry typeRegistry = + TypeRegistry.newBuilder() + .add(SearchBlurbsResponse.getDescriptor()) + .add(SearchBlurbsMetadata.getDescriptor()) + .build(); + + private static final ApiMethodDescriptor createRoomMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.Messaging/CreateRoom") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/rooms", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().build(), true)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Room.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor getRoomMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.Messaging/GetRoom") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{name=rooms/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Room.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor updateRoomMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.Messaging/UpdateRoom") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{room.name=rooms/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "room.name", request.getRoom().getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create().toBody("room", request.getRoom(), true)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Room.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor deleteRoomMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.Messaging/DeleteRoom") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{name=rooms/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Empty.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + listRoomsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.Messaging/ListRooms") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/rooms", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListRoomsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor createBlurbMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.Messaging/CreateBlurb") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{parent=rooms/*}/blurbs", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setAdditionalPaths("/v1beta1/{parent=users/*/profile}/blurbs") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearParent().build(), true)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Blurb.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor getBlurbMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.Messaging/GetBlurb") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{name=rooms/*/blurbs/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setAdditionalPaths("/v1beta1/{name=users/*/profile/blurbs/*}") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Blurb.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor updateBlurbMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.Messaging/UpdateBlurb") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{blurb.name=rooms/*/blurbs/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "blurb.name", request.getBlurb().getName()); + return fields; + }) + .setAdditionalPaths("/v1beta1/{blurb.name=users/*/profile/blurbs/*}") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create().toBody("blurb", request.getBlurb(), true)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Blurb.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor deleteBlurbMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.Messaging/DeleteBlurb") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{name=rooms/*/blurbs/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setAdditionalPaths("/v1beta1/{name=users/*/profile/blurbs/*}") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Empty.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + listBlurbsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.Messaging/ListBlurbs") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{parent=rooms/*}/blurbs", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setAdditionalPaths("/v1beta1/{parent=users/*/profile}/blurbs") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListBlurbsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + searchBlurbsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.Messaging/SearchBlurbs") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{parent=rooms/*}/blurbs:search", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setAdditionalPaths("/v1beta1/{parent=users/*/profile}/blurbs:search") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearParent().build(), true)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (SearchBlurbsRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + streamBlurbsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.Messaging/StreamBlurbs") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.SERVER_STREAMING) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{name=rooms/*}/blurbs:stream", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setAdditionalPaths("/v1beta1/{name=users/*/profile}/blurbs:stream") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearName().build(), true)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(StreamBlurbsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private final UnaryCallable createRoomCallable; + private final UnaryCallable getRoomCallable; + private final UnaryCallable updateRoomCallable; + private final UnaryCallable deleteRoomCallable; + private final UnaryCallable listRoomsCallable; + private final UnaryCallable listRoomsPagedCallable; + private final UnaryCallable createBlurbCallable; + private final UnaryCallable getBlurbCallable; + private final UnaryCallable updateBlurbCallable; + private final UnaryCallable deleteBlurbCallable; + private final UnaryCallable listBlurbsCallable; + private final UnaryCallable listBlurbsPagedCallable; + private final UnaryCallable searchBlurbsCallable; + private final OperationCallable + searchBlurbsOperationCallable; + private final ServerStreamingCallable + streamBlurbsCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonOperationsStub httpJsonOperationsStub; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonMessagingStub create(MessagingStubSettings settings) + throws IOException { + return new HttpJsonMessagingStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonMessagingStub create(ClientContext clientContext) throws IOException { + return new HttpJsonMessagingStub( + MessagingStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonMessagingStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonMessagingStub( + MessagingStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonMessagingStub, using the given settings. This is protected so + * that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected HttpJsonMessagingStub(MessagingStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new HttpJsonMessagingCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonMessagingStub, using the given settings. This is protected so + * that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected HttpJsonMessagingStub( + MessagingStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.httpJsonOperationsStub = + HttpJsonOperationsStub.create(clientContext, callableFactory, typeRegistry); + + HttpJsonCallSettings createRoomTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createRoomMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getRoomTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getRoomMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings updateRoomTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateRoomMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deleteRoomTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteRoomMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings listRoomsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listRoomsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings createBlurbTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createBlurbMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getBlurbTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getBlurbMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings updateBlurbTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateBlurbMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deleteBlurbTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteBlurbMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings listBlurbsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listBlurbsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings searchBlurbsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(searchBlurbsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings streamBlurbsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(streamBlurbsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.createRoomCallable = + callableFactory.createUnaryCallable( + createRoomTransportSettings, settings.createRoomSettings(), clientContext); + this.getRoomCallable = + callableFactory.createUnaryCallable( + getRoomTransportSettings, settings.getRoomSettings(), clientContext); + this.updateRoomCallable = + callableFactory.createUnaryCallable( + updateRoomTransportSettings, settings.updateRoomSettings(), clientContext); + this.deleteRoomCallable = + callableFactory.createUnaryCallable( + deleteRoomTransportSettings, settings.deleteRoomSettings(), clientContext); + this.listRoomsCallable = + callableFactory.createUnaryCallable( + listRoomsTransportSettings, settings.listRoomsSettings(), clientContext); + this.listRoomsPagedCallable = + callableFactory.createPagedCallable( + listRoomsTransportSettings, settings.listRoomsSettings(), clientContext); + this.createBlurbCallable = + callableFactory.createUnaryCallable( + createBlurbTransportSettings, settings.createBlurbSettings(), clientContext); + this.getBlurbCallable = + callableFactory.createUnaryCallable( + getBlurbTransportSettings, settings.getBlurbSettings(), clientContext); + this.updateBlurbCallable = + callableFactory.createUnaryCallable( + updateBlurbTransportSettings, settings.updateBlurbSettings(), clientContext); + this.deleteBlurbCallable = + callableFactory.createUnaryCallable( + deleteBlurbTransportSettings, settings.deleteBlurbSettings(), clientContext); + this.listBlurbsCallable = + callableFactory.createUnaryCallable( + listBlurbsTransportSettings, settings.listBlurbsSettings(), clientContext); + this.listBlurbsPagedCallable = + callableFactory.createPagedCallable( + listBlurbsTransportSettings, settings.listBlurbsSettings(), clientContext); + this.searchBlurbsCallable = + callableFactory.createUnaryCallable( + searchBlurbsTransportSettings, settings.searchBlurbsSettings(), clientContext); + this.searchBlurbsOperationCallable = + callableFactory.createOperationCallable( + searchBlurbsTransportSettings, + settings.searchBlurbsOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.streamBlurbsCallable = + callableFactory.createServerStreamingCallable( + streamBlurbsTransportSettings, settings.streamBlurbsSettings(), clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(createRoomMethodDescriptor); + methodDescriptors.add(getRoomMethodDescriptor); + methodDescriptors.add(updateRoomMethodDescriptor); + methodDescriptors.add(deleteRoomMethodDescriptor); + methodDescriptors.add(listRoomsMethodDescriptor); + methodDescriptors.add(createBlurbMethodDescriptor); + methodDescriptors.add(getBlurbMethodDescriptor); + methodDescriptors.add(updateBlurbMethodDescriptor); + methodDescriptors.add(deleteBlurbMethodDescriptor); + methodDescriptors.add(listBlurbsMethodDescriptor); + methodDescriptors.add(searchBlurbsMethodDescriptor); + methodDescriptors.add(streamBlurbsMethodDescriptor); + return methodDescriptors; + } + + public HttpJsonOperationsStub getHttpJsonOperationsStub() { + return httpJsonOperationsStub; + } + + @Override + public UnaryCallable createRoomCallable() { + return createRoomCallable; + } + + @Override + public UnaryCallable getRoomCallable() { + return getRoomCallable; + } + + @Override + public UnaryCallable updateRoomCallable() { + return updateRoomCallable; + } + + @Override + public UnaryCallable deleteRoomCallable() { + return deleteRoomCallable; + } + + @Override + public UnaryCallable listRoomsCallable() { + return listRoomsCallable; + } + + @Override + public UnaryCallable listRoomsPagedCallable() { + return listRoomsPagedCallable; + } + + @Override + public UnaryCallable createBlurbCallable() { + return createBlurbCallable; + } + + @Override + public UnaryCallable getBlurbCallable() { + return getBlurbCallable; + } + + @Override + public UnaryCallable updateBlurbCallable() { + return updateBlurbCallable; + } + + @Override + public UnaryCallable deleteBlurbCallable() { + return deleteBlurbCallable; + } + + @Override + public UnaryCallable listBlurbsCallable() { + return listBlurbsCallable; + } + + @Override + public UnaryCallable listBlurbsPagedCallable() { + return listBlurbsPagedCallable; + } + + @Override + public UnaryCallable searchBlurbsCallable() { + return searchBlurbsCallable; + } + + @Override + public OperationCallable + searchBlurbsOperationCallable() { + return searchBlurbsOperationCallable; + } + + @Override + public ServerStreamingCallable streamBlurbsCallable() { + return streamBlurbsCallable; + } + + @Override + public final void close() { + try { + backgroundResources.close(); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new IllegalStateException("Failed to close resource", e); + } + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/HttpJsonSequenceServiceCallableFactory.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/HttpJsonSequenceServiceCallableFactory.java new file mode 100644 index 0000000000..dc37c46e8a --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/HttpJsonSequenceServiceCallableFactory.java @@ -0,0 +1,105 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonCallableFactory; +import com.google.api.gax.httpjson.HttpJsonOperationSnapshotCallable; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.longrunning.stub.OperationsStub; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST callable factory implementation for the SequenceService service API. + * + *

This class is for advanced usage. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonSequenceServiceCallableFactory + implements HttpJsonStubCallableFactory { + + @Override + public UnaryCallable createUnaryCallable( + HttpJsonCallSettings httpJsonCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createUnaryCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + HttpJsonCallSettings httpJsonCallSettings, + PagedCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createPagedCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + HttpJsonCallSettings httpJsonCallSettings, + BatchingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createBatchingCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + @Override + public + OperationCallable createOperationCallable( + HttpJsonCallSettings httpJsonCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + UnaryCallable innerCallable = + HttpJsonCallableFactory.createBaseUnaryCallable( + httpJsonCallSettings, callSettings.getInitialCallSettings(), clientContext); + HttpJsonOperationSnapshotCallable initialCallable = + new HttpJsonOperationSnapshotCallable( + innerCallable, + httpJsonCallSettings.getMethodDescriptor().getOperationSnapshotFactory()); + return HttpJsonCallableFactory.createOperationCallable( + callSettings, clientContext, operationsStub.longRunningClient(), initialCallable); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + HttpJsonCallSettings httpJsonCallSettings, + ServerStreamingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createServerStreamingCallable( + httpJsonCallSettings, callSettings, clientContext); + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/HttpJsonSequenceServiceStub.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/HttpJsonSequenceServiceStub.java new file mode 100644 index 0000000000..c2522b9648 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/HttpJsonSequenceServiceStub.java @@ -0,0 +1,302 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.core.BackgroundResourceAggregation; +import com.google.api.gax.httpjson.ApiMethodDescriptor; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.ProtoMessageRequestFormatter; +import com.google.api.gax.httpjson.ProtoMessageResponseParser; +import com.google.api.gax.httpjson.ProtoRestSerializer; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.protobuf.Empty; +import com.google.protobuf.TypeRegistry; +import com.google.showcase.v1beta1.AttemptSequenceRequest; +import com.google.showcase.v1beta1.CreateSequenceRequest; +import com.google.showcase.v1beta1.GetSequenceReportRequest; +import com.google.showcase.v1beta1.Sequence; +import com.google.showcase.v1beta1.SequenceReport; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST stub implementation for the SequenceService service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonSequenceServiceStub extends SequenceServiceStub { + private static final TypeRegistry typeRegistry = TypeRegistry.newBuilder().build(); + + private static final ApiMethodDescriptor + createSequenceMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.SequenceService/CreateSequence") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/sequences", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("sequence", request.getSequence(), true)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Sequence.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getSequenceReportMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.SequenceService/GetSequenceReport") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{name=sequences/*/sequenceReport}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(SequenceReport.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + attemptSequenceMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.SequenceService/AttemptSequence") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{name=sequences/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearName().build(), true)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Empty.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private final UnaryCallable createSequenceCallable; + private final UnaryCallable getSequenceReportCallable; + private final UnaryCallable attemptSequenceCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonSequenceServiceStub create(SequenceServiceStubSettings settings) + throws IOException { + return new HttpJsonSequenceServiceStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonSequenceServiceStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonSequenceServiceStub( + SequenceServiceStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonSequenceServiceStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonSequenceServiceStub( + SequenceServiceStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonSequenceServiceStub, using the given settings. This is + * protected so that it is easy to make a subclass, but otherwise, the static factory methods + * should be preferred. + */ + protected HttpJsonSequenceServiceStub( + SequenceServiceStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new HttpJsonSequenceServiceCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonSequenceServiceStub, using the given settings. This is + * protected so that it is easy to make a subclass, but otherwise, the static factory methods + * should be preferred. + */ + protected HttpJsonSequenceServiceStub( + SequenceServiceStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + + HttpJsonCallSettings createSequenceTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createSequenceMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + getSequenceReportTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getSequenceReportMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings attemptSequenceTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(attemptSequenceMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.createSequenceCallable = + callableFactory.createUnaryCallable( + createSequenceTransportSettings, settings.createSequenceSettings(), clientContext); + this.getSequenceReportCallable = + callableFactory.createUnaryCallable( + getSequenceReportTransportSettings, + settings.getSequenceReportSettings(), + clientContext); + this.attemptSequenceCallable = + callableFactory.createUnaryCallable( + attemptSequenceTransportSettings, settings.attemptSequenceSettings(), clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(createSequenceMethodDescriptor); + methodDescriptors.add(getSequenceReportMethodDescriptor); + methodDescriptors.add(attemptSequenceMethodDescriptor); + return methodDescriptors; + } + + @Override + public UnaryCallable createSequenceCallable() { + return createSequenceCallable; + } + + @Override + public UnaryCallable getSequenceReportCallable() { + return getSequenceReportCallable; + } + + @Override + public UnaryCallable attemptSequenceCallable() { + return attemptSequenceCallable; + } + + @Override + public final void close() { + try { + backgroundResources.close(); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new IllegalStateException("Failed to close resource", e); + } + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/HttpJsonTestingCallableFactory.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/HttpJsonTestingCallableFactory.java new file mode 100644 index 0000000000..c33422c6ae --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/HttpJsonTestingCallableFactory.java @@ -0,0 +1,105 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonCallableFactory; +import com.google.api.gax.httpjson.HttpJsonOperationSnapshotCallable; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.longrunning.stub.OperationsStub; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST callable factory implementation for the Testing service API. + * + *

This class is for advanced usage. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonTestingCallableFactory + implements HttpJsonStubCallableFactory { + + @Override + public UnaryCallable createUnaryCallable( + HttpJsonCallSettings httpJsonCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createUnaryCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + HttpJsonCallSettings httpJsonCallSettings, + PagedCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createPagedCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + HttpJsonCallSettings httpJsonCallSettings, + BatchingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createBatchingCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + @Override + public + OperationCallable createOperationCallable( + HttpJsonCallSettings httpJsonCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + UnaryCallable innerCallable = + HttpJsonCallableFactory.createBaseUnaryCallable( + httpJsonCallSettings, callSettings.getInitialCallSettings(), clientContext); + HttpJsonOperationSnapshotCallable initialCallable = + new HttpJsonOperationSnapshotCallable( + innerCallable, + httpJsonCallSettings.getMethodDescriptor().getOperationSnapshotFactory()); + return HttpJsonCallableFactory.createOperationCallable( + callSettings, clientContext, operationsStub.longRunningClient(), initialCallable); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + HttpJsonCallSettings httpJsonCallSettings, + ServerStreamingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createServerStreamingCallable( + httpJsonCallSettings, callSettings, clientContext); + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/HttpJsonTestingStub.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/HttpJsonTestingStub.java new file mode 100644 index 0000000000..eb1a664bb0 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/HttpJsonTestingStub.java @@ -0,0 +1,572 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub; + +import static com.google.showcase.v1beta1.TestingClient.ListSessionsPagedResponse; +import static com.google.showcase.v1beta1.TestingClient.ListTestsPagedResponse; + +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.core.BackgroundResourceAggregation; +import com.google.api.gax.httpjson.ApiMethodDescriptor; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.ProtoMessageRequestFormatter; +import com.google.api.gax.httpjson.ProtoMessageResponseParser; +import com.google.api.gax.httpjson.ProtoRestSerializer; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.protobuf.Empty; +import com.google.protobuf.TypeRegistry; +import com.google.showcase.v1beta1.CreateSessionRequest; +import com.google.showcase.v1beta1.DeleteSessionRequest; +import com.google.showcase.v1beta1.DeleteTestRequest; +import com.google.showcase.v1beta1.GetSessionRequest; +import com.google.showcase.v1beta1.ListSessionsRequest; +import com.google.showcase.v1beta1.ListSessionsResponse; +import com.google.showcase.v1beta1.ListTestsRequest; +import com.google.showcase.v1beta1.ListTestsResponse; +import com.google.showcase.v1beta1.ReportSessionRequest; +import com.google.showcase.v1beta1.ReportSessionResponse; +import com.google.showcase.v1beta1.Session; +import com.google.showcase.v1beta1.VerifyTestRequest; +import com.google.showcase.v1beta1.VerifyTestResponse; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST stub implementation for the Testing service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonTestingStub extends TestingStub { + private static final TypeRegistry typeRegistry = TypeRegistry.newBuilder().build(); + + private static final ApiMethodDescriptor + createSessionMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.Testing/CreateSession") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/sessions", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("session", request.getSession(), true)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Session.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor getSessionMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.Testing/GetSession") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{name=sessions/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Session.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + listSessionsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.Testing/ListSessions") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/sessions", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListSessionsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + deleteSessionMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.Testing/DeleteSession") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{name=sessions/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Empty.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + reportSessionMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.Testing/ReportSession") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{name=sessions/*}:report", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ReportSessionResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + listTestsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.Testing/ListTests") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{parent=sessions/*}/tests", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListTestsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor deleteTestMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.Testing/DeleteTest") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{name=sessions/*/tests/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Empty.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + verifyTestMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.showcase.v1beta1.Testing/VerifyTest") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{name=sessions/*/tests/*}:check", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "answer", request.getAnswer()); + serializer.putQueryParam(fields, "answers", request.getAnswersList()); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(VerifyTestResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private final UnaryCallable createSessionCallable; + private final UnaryCallable getSessionCallable; + private final UnaryCallable listSessionsCallable; + private final UnaryCallable + listSessionsPagedCallable; + private final UnaryCallable deleteSessionCallable; + private final UnaryCallable reportSessionCallable; + private final UnaryCallable listTestsCallable; + private final UnaryCallable listTestsPagedCallable; + private final UnaryCallable deleteTestCallable; + private final UnaryCallable verifyTestCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonTestingStub create(TestingStubSettings settings) throws IOException { + return new HttpJsonTestingStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonTestingStub create(ClientContext clientContext) throws IOException { + return new HttpJsonTestingStub(TestingStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonTestingStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonTestingStub( + TestingStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonTestingStub, using the given settings. This is protected so + * that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected HttpJsonTestingStub(TestingStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new HttpJsonTestingCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonTestingStub, using the given settings. This is protected so + * that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected HttpJsonTestingStub( + TestingStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + + HttpJsonCallSettings createSessionTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createSessionMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getSessionTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getSessionMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings listSessionsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listSessionsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deleteSessionTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteSessionMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + reportSessionTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(reportSessionMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings listTestsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listTestsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deleteTestTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteTestMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings verifyTestTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(verifyTestMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.createSessionCallable = + callableFactory.createUnaryCallable( + createSessionTransportSettings, settings.createSessionSettings(), clientContext); + this.getSessionCallable = + callableFactory.createUnaryCallable( + getSessionTransportSettings, settings.getSessionSettings(), clientContext); + this.listSessionsCallable = + callableFactory.createUnaryCallable( + listSessionsTransportSettings, settings.listSessionsSettings(), clientContext); + this.listSessionsPagedCallable = + callableFactory.createPagedCallable( + listSessionsTransportSettings, settings.listSessionsSettings(), clientContext); + this.deleteSessionCallable = + callableFactory.createUnaryCallable( + deleteSessionTransportSettings, settings.deleteSessionSettings(), clientContext); + this.reportSessionCallable = + callableFactory.createUnaryCallable( + reportSessionTransportSettings, settings.reportSessionSettings(), clientContext); + this.listTestsCallable = + callableFactory.createUnaryCallable( + listTestsTransportSettings, settings.listTestsSettings(), clientContext); + this.listTestsPagedCallable = + callableFactory.createPagedCallable( + listTestsTransportSettings, settings.listTestsSettings(), clientContext); + this.deleteTestCallable = + callableFactory.createUnaryCallable( + deleteTestTransportSettings, settings.deleteTestSettings(), clientContext); + this.verifyTestCallable = + callableFactory.createUnaryCallable( + verifyTestTransportSettings, settings.verifyTestSettings(), clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(createSessionMethodDescriptor); + methodDescriptors.add(getSessionMethodDescriptor); + methodDescriptors.add(listSessionsMethodDescriptor); + methodDescriptors.add(deleteSessionMethodDescriptor); + methodDescriptors.add(reportSessionMethodDescriptor); + methodDescriptors.add(listTestsMethodDescriptor); + methodDescriptors.add(deleteTestMethodDescriptor); + methodDescriptors.add(verifyTestMethodDescriptor); + return methodDescriptors; + } + + @Override + public UnaryCallable createSessionCallable() { + return createSessionCallable; + } + + @Override + public UnaryCallable getSessionCallable() { + return getSessionCallable; + } + + @Override + public UnaryCallable listSessionsCallable() { + return listSessionsCallable; + } + + @Override + public UnaryCallable listSessionsPagedCallable() { + return listSessionsPagedCallable; + } + + @Override + public UnaryCallable deleteSessionCallable() { + return deleteSessionCallable; + } + + @Override + public UnaryCallable reportSessionCallable() { + return reportSessionCallable; + } + + @Override + public UnaryCallable listTestsCallable() { + return listTestsCallable; + } + + @Override + public UnaryCallable listTestsPagedCallable() { + return listTestsPagedCallable; + } + + @Override + public UnaryCallable deleteTestCallable() { + return deleteTestCallable; + } + + @Override + public UnaryCallable verifyTestCallable() { + return verifyTestCallable; + } + + @Override + public final void close() { + try { + backgroundResources.close(); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new IllegalStateException("Failed to close resource", e); + } + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/IdentityStub.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/IdentityStub.java new file mode 100644 index 0000000000..b09d5c635e --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/IdentityStub.java @@ -0,0 +1,70 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub; + +import static com.google.showcase.v1beta1.IdentityClient.ListUsersPagedResponse; + +import com.google.api.core.BetaApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.CreateUserRequest; +import com.google.showcase.v1beta1.DeleteUserRequest; +import com.google.showcase.v1beta1.GetUserRequest; +import com.google.showcase.v1beta1.ListUsersRequest; +import com.google.showcase.v1beta1.ListUsersResponse; +import com.google.showcase.v1beta1.UpdateUserRequest; +import com.google.showcase.v1beta1.User; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * Base stub class for the Identity service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public abstract class IdentityStub implements BackgroundResource { + + public UnaryCallable createUserCallable() { + throw new UnsupportedOperationException("Not implemented: createUserCallable()"); + } + + public UnaryCallable getUserCallable() { + throw new UnsupportedOperationException("Not implemented: getUserCallable()"); + } + + public UnaryCallable updateUserCallable() { + throw new UnsupportedOperationException("Not implemented: updateUserCallable()"); + } + + public UnaryCallable deleteUserCallable() { + throw new UnsupportedOperationException("Not implemented: deleteUserCallable()"); + } + + public UnaryCallable listUsersPagedCallable() { + throw new UnsupportedOperationException("Not implemented: listUsersPagedCallable()"); + } + + public UnaryCallable listUsersCallable() { + throw new UnsupportedOperationException("Not implemented: listUsersCallable()"); + } + + @Override + public abstract void close(); +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/IdentityStubSettings.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/IdentityStubSettings.java new file mode 100644 index 0000000000..92aaa1133d --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/IdentityStubSettings.java @@ -0,0 +1,491 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub; + +import static com.google.showcase.v1beta1.IdentityClient.ListUsersPagedResponse; + +import com.google.api.core.ApiFunction; +import com.google.api.core.ApiFuture; +import com.google.api.core.BetaApi; +import com.google.api.gax.core.GaxProperties; +import com.google.api.gax.core.GoogleCredentialsProvider; +import com.google.api.gax.core.InstantiatingExecutorProvider; +import com.google.api.gax.grpc.GaxGrpcProperties; +import com.google.api.gax.grpc.GrpcTransportChannel; +import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.HttpJsonTransportChannel; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; +import com.google.api.gax.retrying.RetrySettings; +import com.google.api.gax.rpc.ApiCallContext; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.PageContext; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.PagedListDescriptor; +import com.google.api.gax.rpc.PagedListResponseFactory; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.StubSettings; +import com.google.api.gax.rpc.TransportChannelProvider; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Lists; +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.CreateUserRequest; +import com.google.showcase.v1beta1.DeleteUserRequest; +import com.google.showcase.v1beta1.GetUserRequest; +import com.google.showcase.v1beta1.ListUsersRequest; +import com.google.showcase.v1beta1.ListUsersResponse; +import com.google.showcase.v1beta1.UpdateUserRequest; +import com.google.showcase.v1beta1.User; +import java.io.IOException; +import java.util.List; +import javax.annotation.Generated; +import org.threeten.bp.Duration; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * Settings class to configure an instance of {@link IdentityStub}. + * + *

The default instance has everything set to sensible defaults: + * + *

    + *
  • The default service address (localhost) and default port (7469) are used. + *
  • Credentials are acquired automatically through Application Default Credentials. + *
  • Retries are configured for idempotent methods but not for non-idempotent methods. + *
+ * + *

The builder of this class is recursive, so contained classes are themselves builders. When + * build() is called, the tree of builders is called to create the complete settings object. + * + *

For example, to set the total timeout of createUser to 30 seconds: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * IdentityStubSettings.Builder identitySettingsBuilder = IdentityStubSettings.newBuilder();
+ * identitySettingsBuilder
+ *     .createUserSettings()
+ *     .setRetrySettings(
+ *         identitySettingsBuilder
+ *             .createUserSettings()
+ *             .getRetrySettings()
+ *             .toBuilder()
+ *             .setTotalTimeout(Duration.ofSeconds(30))
+ *             .build());
+ * IdentityStubSettings identitySettings = identitySettingsBuilder.build();
+ * }
+ */ +@BetaApi +@Generated("by gapic-generator-java") +public class IdentityStubSettings extends StubSettings { + /** The default scopes of the service. */ + private static final ImmutableList DEFAULT_SERVICE_SCOPES = + ImmutableList.builder().build(); + + private final UnaryCallSettings createUserSettings; + private final UnaryCallSettings getUserSettings; + private final UnaryCallSettings updateUserSettings; + private final UnaryCallSettings deleteUserSettings; + private final PagedCallSettings + listUsersSettings; + + private static final PagedListDescriptor + LIST_USERS_PAGE_STR_DESC = + new PagedListDescriptor() { + @Override + public String emptyToken() { + return ""; + } + + @Override + public ListUsersRequest injectToken(ListUsersRequest payload, String token) { + return ListUsersRequest.newBuilder(payload).setPageToken(token).build(); + } + + @Override + public ListUsersRequest injectPageSize(ListUsersRequest payload, int pageSize) { + return ListUsersRequest.newBuilder(payload).setPageSize(pageSize).build(); + } + + @Override + public Integer extractPageSize(ListUsersRequest payload) { + return payload.getPageSize(); + } + + @Override + public String extractNextToken(ListUsersResponse payload) { + return payload.getNextPageToken(); + } + + @Override + public Iterable extractResources(ListUsersResponse payload) { + return payload.getUsersList() == null + ? ImmutableList.of() + : payload.getUsersList(); + } + }; + + private static final PagedListResponseFactory< + ListUsersRequest, ListUsersResponse, ListUsersPagedResponse> + LIST_USERS_PAGE_STR_FACT = + new PagedListResponseFactory< + ListUsersRequest, ListUsersResponse, ListUsersPagedResponse>() { + @Override + public ApiFuture getFuturePagedResponse( + UnaryCallable callable, + ListUsersRequest request, + ApiCallContext context, + ApiFuture futureResponse) { + PageContext pageContext = + PageContext.create(callable, LIST_USERS_PAGE_STR_DESC, request, context); + return ListUsersPagedResponse.createAsync(pageContext, futureResponse); + } + }; + + /** Returns the object with the settings used for calls to createUser. */ + public UnaryCallSettings createUserSettings() { + return createUserSettings; + } + + /** Returns the object with the settings used for calls to getUser. */ + public UnaryCallSettings getUserSettings() { + return getUserSettings; + } + + /** Returns the object with the settings used for calls to updateUser. */ + public UnaryCallSettings updateUserSettings() { + return updateUserSettings; + } + + /** Returns the object with the settings used for calls to deleteUser. */ + public UnaryCallSettings deleteUserSettings() { + return deleteUserSettings; + } + + /** Returns the object with the settings used for calls to listUsers. */ + public PagedCallSettings + listUsersSettings() { + return listUsersSettings; + } + + public IdentityStub createStub() throws IOException { + if (getTransportChannelProvider() + .getTransportName() + .equals(GrpcTransportChannel.getGrpcTransportName())) { + return GrpcIdentityStub.create(this); + } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonIdentityStub.create(this); + } + throw new UnsupportedOperationException( + String.format( + "Transport not supported: %s", getTransportChannelProvider().getTransportName())); + } + + /** Returns a builder for the default ExecutorProvider for this service. */ + public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { + return InstantiatingExecutorProvider.newBuilder(); + } + + /** Returns the default service endpoint. */ + public static String getDefaultEndpoint() { + return "localhost:7469"; + } + + /** Returns the default mTLS service endpoint. */ + public static String getDefaultMtlsEndpoint() { + return "localhost:7469"; + } + + /** Returns the default service scopes. */ + public static List getDefaultServiceScopes() { + return DEFAULT_SERVICE_SCOPES; + } + + /** Returns a builder for the default credentials for this service. */ + public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { + return GoogleCredentialsProvider.newBuilder() + .setScopesToApply(DEFAULT_SERVICE_SCOPES) + .setUseJwtAccessWithScope(true); + } + + /** Returns a builder for the default gRPC ChannelProvider for this service. */ + public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { + return InstantiatingGrpcChannelProvider.newBuilder() + .setMaxInboundMessageSize(Integer.MAX_VALUE); + } + + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return InstantiatingHttpJsonChannelProvider.newBuilder(); + } + + public static TransportChannelProvider defaultTransportChannelProvider() { + return defaultGrpcTransportProviderBuilder().build(); + } + + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken("gapic", GaxProperties.getLibraryVersion(IdentityStubSettings.class)) + .setTransportToken( + GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); + } + + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken("gapic", GaxProperties.getLibraryVersion(IdentityStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return IdentityStubSettings.defaultGrpcApiClientHeaderProviderBuilder(); + } + + /** Returns a new gRPC builder for this class. */ + public static Builder newBuilder() { + return Builder.createDefault(); + } + + /** Returns a new REST builder for this class. */ + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder(ClientContext clientContext) { + return new Builder(clientContext); + } + + /** Returns a builder containing all the values of this settings class. */ + public Builder toBuilder() { + return new Builder(this); + } + + protected IdentityStubSettings(Builder settingsBuilder) throws IOException { + super(settingsBuilder); + + createUserSettings = settingsBuilder.createUserSettings().build(); + getUserSettings = settingsBuilder.getUserSettings().build(); + updateUserSettings = settingsBuilder.updateUserSettings().build(); + deleteUserSettings = settingsBuilder.deleteUserSettings().build(); + listUsersSettings = settingsBuilder.listUsersSettings().build(); + } + + /** Builder for IdentityStubSettings. */ + public static class Builder extends StubSettings.Builder { + private final ImmutableList> unaryMethodSettingsBuilders; + private final UnaryCallSettings.Builder createUserSettings; + private final UnaryCallSettings.Builder getUserSettings; + private final UnaryCallSettings.Builder updateUserSettings; + private final UnaryCallSettings.Builder deleteUserSettings; + private final PagedCallSettings.Builder< + ListUsersRequest, ListUsersResponse, ListUsersPagedResponse> + listUsersSettings; + private static final ImmutableMap> + RETRYABLE_CODE_DEFINITIONS; + + static { + ImmutableMap.Builder> definitions = + ImmutableMap.builder(); + definitions.put("no_retry_codes", ImmutableSet.copyOf(Lists.newArrayList())); + definitions.put( + "retry_policy_2_codes", + ImmutableSet.copyOf( + Lists.newArrayList( + StatusCode.Code.UNAVAILABLE, StatusCode.Code.UNKNOWN))); + RETRYABLE_CODE_DEFINITIONS = definitions.build(); + } + + private static final ImmutableMap RETRY_PARAM_DEFINITIONS; + + static { + ImmutableMap.Builder definitions = ImmutableMap.builder(); + RetrySettings settings = null; + settings = RetrySettings.newBuilder().setRpcTimeoutMultiplier(1.0).build(); + definitions.put("no_retry_params", settings); + settings = + RetrySettings.newBuilder() + .setInitialRetryDelay(Duration.ofMillis(200L)) + .setRetryDelayMultiplier(2.0) + .setMaxRetryDelay(Duration.ofMillis(3000L)) + .setInitialRpcTimeout(Duration.ofMillis(5000L)) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ofMillis(5000L)) + .setTotalTimeout(Duration.ofMillis(5000L)) + .build(); + definitions.put("retry_policy_2_params", settings); + RETRY_PARAM_DEFINITIONS = definitions.build(); + } + + protected Builder() { + this(((ClientContext) null)); + } + + protected Builder(ClientContext clientContext) { + super(clientContext); + + createUserSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + getUserSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + updateUserSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + deleteUserSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + listUsersSettings = PagedCallSettings.newBuilder(LIST_USERS_PAGE_STR_FACT); + + unaryMethodSettingsBuilders = + ImmutableList.>of( + createUserSettings, + getUserSettings, + updateUserSettings, + deleteUserSettings, + listUsersSettings); + initDefaults(this); + } + + protected Builder(IdentityStubSettings settings) { + super(settings); + + createUserSettings = settings.createUserSettings.toBuilder(); + getUserSettings = settings.getUserSettings.toBuilder(); + updateUserSettings = settings.updateUserSettings.toBuilder(); + deleteUserSettings = settings.deleteUserSettings.toBuilder(); + listUsersSettings = settings.listUsersSettings.toBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of( + createUserSettings, + getUserSettings, + updateUserSettings, + deleteUserSettings, + listUsersSettings); + } + + private static Builder createDefault() { + Builder builder = new Builder(((ClientContext) null)); + + builder.setTransportChannelProvider(defaultTransportChannelProvider()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultApiClientHeaderProviderBuilder().build()); + builder.setEndpoint(getDefaultEndpoint()); + builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); + builder.setSwitchToMtlsEndpointAllowed(true); + + return initDefaults(builder); + } + + private static Builder createHttpJsonDefault() { + Builder builder = new Builder(((ClientContext) null)); + + builder.setTransportChannelProvider(defaultHttpJsonTransportProviderBuilder().build()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultHttpJsonApiClientHeaderProviderBuilder().build()); + builder.setEndpoint(getDefaultEndpoint()); + builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); + builder.setSwitchToMtlsEndpointAllowed(true); + + return initDefaults(builder); + } + + private static Builder initDefaults(Builder builder) { + builder + .createUserSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .getUserSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_2_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_2_params")); + + builder + .updateUserSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .deleteUserSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .listUsersSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_2_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_2_params")); + + return builder; + } + + /** + * Applies the given settings updater function to all of the unary API methods in this service. + * + *

Note: This method does not support applying settings to streaming methods. + */ + public Builder applyToAllUnaryMethods( + ApiFunction, Void> settingsUpdater) { + super.applyToAllUnaryMethods(unaryMethodSettingsBuilders, settingsUpdater); + return this; + } + + public ImmutableList> unaryMethodSettingsBuilders() { + return unaryMethodSettingsBuilders; + } + + /** Returns the builder for the settings used for calls to createUser. */ + public UnaryCallSettings.Builder createUserSettings() { + return createUserSettings; + } + + /** Returns the builder for the settings used for calls to getUser. */ + public UnaryCallSettings.Builder getUserSettings() { + return getUserSettings; + } + + /** Returns the builder for the settings used for calls to updateUser. */ + public UnaryCallSettings.Builder updateUserSettings() { + return updateUserSettings; + } + + /** Returns the builder for the settings used for calls to deleteUser. */ + public UnaryCallSettings.Builder deleteUserSettings() { + return deleteUserSettings; + } + + /** Returns the builder for the settings used for calls to listUsers. */ + public PagedCallSettings.Builder + listUsersSettings() { + return listUsersSettings; + } + + @Override + public IdentityStubSettings build() throws IOException { + return new IdentityStubSettings(this); + } + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/MessagingStub.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/MessagingStub.java new file mode 100644 index 0000000000..50372c599b --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/MessagingStub.java @@ -0,0 +1,144 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub; + +import static com.google.showcase.v1beta1.MessagingClient.ListBlurbsPagedResponse; +import static com.google.showcase.v1beta1.MessagingClient.ListRoomsPagedResponse; + +import com.google.api.core.BetaApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.Blurb; +import com.google.showcase.v1beta1.ConnectRequest; +import com.google.showcase.v1beta1.CreateBlurbRequest; +import com.google.showcase.v1beta1.CreateRoomRequest; +import com.google.showcase.v1beta1.DeleteBlurbRequest; +import com.google.showcase.v1beta1.DeleteRoomRequest; +import com.google.showcase.v1beta1.GetBlurbRequest; +import com.google.showcase.v1beta1.GetRoomRequest; +import com.google.showcase.v1beta1.ListBlurbsRequest; +import com.google.showcase.v1beta1.ListBlurbsResponse; +import com.google.showcase.v1beta1.ListRoomsRequest; +import com.google.showcase.v1beta1.ListRoomsResponse; +import com.google.showcase.v1beta1.Room; +import com.google.showcase.v1beta1.SearchBlurbsMetadata; +import com.google.showcase.v1beta1.SearchBlurbsRequest; +import com.google.showcase.v1beta1.SearchBlurbsResponse; +import com.google.showcase.v1beta1.SendBlurbsResponse; +import com.google.showcase.v1beta1.StreamBlurbsRequest; +import com.google.showcase.v1beta1.StreamBlurbsResponse; +import com.google.showcase.v1beta1.UpdateBlurbRequest; +import com.google.showcase.v1beta1.UpdateRoomRequest; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * Base stub class for the Messaging service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public abstract class MessagingStub implements BackgroundResource { + + public OperationsStub getOperationsStub() { + return null; + } + + public com.google.api.gax.httpjson.longrunning.stub.OperationsStub getHttpJsonOperationsStub() { + return null; + } + + public UnaryCallable createRoomCallable() { + throw new UnsupportedOperationException("Not implemented: createRoomCallable()"); + } + + public UnaryCallable getRoomCallable() { + throw new UnsupportedOperationException("Not implemented: getRoomCallable()"); + } + + public UnaryCallable updateRoomCallable() { + throw new UnsupportedOperationException("Not implemented: updateRoomCallable()"); + } + + public UnaryCallable deleteRoomCallable() { + throw new UnsupportedOperationException("Not implemented: deleteRoomCallable()"); + } + + public UnaryCallable listRoomsPagedCallable() { + throw new UnsupportedOperationException("Not implemented: listRoomsPagedCallable()"); + } + + public UnaryCallable listRoomsCallable() { + throw new UnsupportedOperationException("Not implemented: listRoomsCallable()"); + } + + public UnaryCallable createBlurbCallable() { + throw new UnsupportedOperationException("Not implemented: createBlurbCallable()"); + } + + public UnaryCallable getBlurbCallable() { + throw new UnsupportedOperationException("Not implemented: getBlurbCallable()"); + } + + public UnaryCallable updateBlurbCallable() { + throw new UnsupportedOperationException("Not implemented: updateBlurbCallable()"); + } + + public UnaryCallable deleteBlurbCallable() { + throw new UnsupportedOperationException("Not implemented: deleteBlurbCallable()"); + } + + public UnaryCallable listBlurbsPagedCallable() { + throw new UnsupportedOperationException("Not implemented: listBlurbsPagedCallable()"); + } + + public UnaryCallable listBlurbsCallable() { + throw new UnsupportedOperationException("Not implemented: listBlurbsCallable()"); + } + + public OperationCallable + searchBlurbsOperationCallable() { + throw new UnsupportedOperationException("Not implemented: searchBlurbsOperationCallable()"); + } + + public UnaryCallable searchBlurbsCallable() { + throw new UnsupportedOperationException("Not implemented: searchBlurbsCallable()"); + } + + public ServerStreamingCallable streamBlurbsCallable() { + throw new UnsupportedOperationException("Not implemented: streamBlurbsCallable()"); + } + + public ClientStreamingCallable sendBlurbsCallable() { + throw new UnsupportedOperationException("Not implemented: sendBlurbsCallable()"); + } + + public BidiStreamingCallable connectCallable() { + throw new UnsupportedOperationException("Not implemented: connectCallable()"); + } + + @Override + public abstract void close(); +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/MessagingStubSettings.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/MessagingStubSettings.java new file mode 100644 index 0000000000..326883942f --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/MessagingStubSettings.java @@ -0,0 +1,815 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub; + +import static com.google.showcase.v1beta1.MessagingClient.ListBlurbsPagedResponse; +import static com.google.showcase.v1beta1.MessagingClient.ListRoomsPagedResponse; + +import com.google.api.core.ApiFunction; +import com.google.api.core.ApiFuture; +import com.google.api.core.BetaApi; +import com.google.api.gax.core.GaxProperties; +import com.google.api.gax.core.GoogleCredentialsProvider; +import com.google.api.gax.core.InstantiatingExecutorProvider; +import com.google.api.gax.grpc.GaxGrpcProperties; +import com.google.api.gax.grpc.GrpcTransportChannel; +import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.grpc.ProtoOperationTransformers; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.HttpJsonTransportChannel; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; +import com.google.api.gax.longrunning.OperationSnapshot; +import com.google.api.gax.longrunning.OperationTimedPollAlgorithm; +import com.google.api.gax.retrying.RetrySettings; +import com.google.api.gax.rpc.ApiCallContext; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.PageContext; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.PagedListDescriptor; +import com.google.api.gax.rpc.PagedListResponseFactory; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.StubSettings; +import com.google.api.gax.rpc.TransportChannelProvider; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Lists; +import com.google.longrunning.Operation; +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.Blurb; +import com.google.showcase.v1beta1.ConnectRequest; +import com.google.showcase.v1beta1.CreateBlurbRequest; +import com.google.showcase.v1beta1.CreateRoomRequest; +import com.google.showcase.v1beta1.DeleteBlurbRequest; +import com.google.showcase.v1beta1.DeleteRoomRequest; +import com.google.showcase.v1beta1.GetBlurbRequest; +import com.google.showcase.v1beta1.GetRoomRequest; +import com.google.showcase.v1beta1.ListBlurbsRequest; +import com.google.showcase.v1beta1.ListBlurbsResponse; +import com.google.showcase.v1beta1.ListRoomsRequest; +import com.google.showcase.v1beta1.ListRoomsResponse; +import com.google.showcase.v1beta1.Room; +import com.google.showcase.v1beta1.SearchBlurbsMetadata; +import com.google.showcase.v1beta1.SearchBlurbsRequest; +import com.google.showcase.v1beta1.SearchBlurbsResponse; +import com.google.showcase.v1beta1.SendBlurbsResponse; +import com.google.showcase.v1beta1.StreamBlurbsRequest; +import com.google.showcase.v1beta1.StreamBlurbsResponse; +import com.google.showcase.v1beta1.UpdateBlurbRequest; +import com.google.showcase.v1beta1.UpdateRoomRequest; +import java.io.IOException; +import java.util.List; +import javax.annotation.Generated; +import org.threeten.bp.Duration; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * Settings class to configure an instance of {@link MessagingStub}. + * + *

The default instance has everything set to sensible defaults: + * + *

    + *
  • The default service address (localhost) and default port (7469) are used. + *
  • Credentials are acquired automatically through Application Default Credentials. + *
  • Retries are configured for idempotent methods but not for non-idempotent methods. + *
+ * + *

The builder of this class is recursive, so contained classes are themselves builders. When + * build() is called, the tree of builders is called to create the complete settings object. + * + *

For example, to set the total timeout of createRoom to 30 seconds: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * MessagingStubSettings.Builder messagingSettingsBuilder = MessagingStubSettings.newBuilder();
+ * messagingSettingsBuilder
+ *     .createRoomSettings()
+ *     .setRetrySettings(
+ *         messagingSettingsBuilder
+ *             .createRoomSettings()
+ *             .getRetrySettings()
+ *             .toBuilder()
+ *             .setTotalTimeout(Duration.ofSeconds(30))
+ *             .build());
+ * MessagingStubSettings messagingSettings = messagingSettingsBuilder.build();
+ * }
+ */ +@BetaApi +@Generated("by gapic-generator-java") +public class MessagingStubSettings extends StubSettings { + /** The default scopes of the service. */ + private static final ImmutableList DEFAULT_SERVICE_SCOPES = + ImmutableList.builder().build(); + + private final UnaryCallSettings createRoomSettings; + private final UnaryCallSettings getRoomSettings; + private final UnaryCallSettings updateRoomSettings; + private final UnaryCallSettings deleteRoomSettings; + private final PagedCallSettings + listRoomsSettings; + private final UnaryCallSettings createBlurbSettings; + private final UnaryCallSettings getBlurbSettings; + private final UnaryCallSettings updateBlurbSettings; + private final UnaryCallSettings deleteBlurbSettings; + private final PagedCallSettings + listBlurbsSettings; + private final UnaryCallSettings searchBlurbsSettings; + private final OperationCallSettings< + SearchBlurbsRequest, SearchBlurbsResponse, SearchBlurbsMetadata> + searchBlurbsOperationSettings; + private final ServerStreamingCallSettings + streamBlurbsSettings; + private final StreamingCallSettings sendBlurbsSettings; + private final StreamingCallSettings connectSettings; + + private static final PagedListDescriptor + LIST_ROOMS_PAGE_STR_DESC = + new PagedListDescriptor() { + @Override + public String emptyToken() { + return ""; + } + + @Override + public ListRoomsRequest injectToken(ListRoomsRequest payload, String token) { + return ListRoomsRequest.newBuilder(payload).setPageToken(token).build(); + } + + @Override + public ListRoomsRequest injectPageSize(ListRoomsRequest payload, int pageSize) { + return ListRoomsRequest.newBuilder(payload).setPageSize(pageSize).build(); + } + + @Override + public Integer extractPageSize(ListRoomsRequest payload) { + return payload.getPageSize(); + } + + @Override + public String extractNextToken(ListRoomsResponse payload) { + return payload.getNextPageToken(); + } + + @Override + public Iterable extractResources(ListRoomsResponse payload) { + return payload.getRoomsList() == null + ? ImmutableList.of() + : payload.getRoomsList(); + } + }; + + private static final PagedListDescriptor + LIST_BLURBS_PAGE_STR_DESC = + new PagedListDescriptor() { + @Override + public String emptyToken() { + return ""; + } + + @Override + public ListBlurbsRequest injectToken(ListBlurbsRequest payload, String token) { + return ListBlurbsRequest.newBuilder(payload).setPageToken(token).build(); + } + + @Override + public ListBlurbsRequest injectPageSize(ListBlurbsRequest payload, int pageSize) { + return ListBlurbsRequest.newBuilder(payload).setPageSize(pageSize).build(); + } + + @Override + public Integer extractPageSize(ListBlurbsRequest payload) { + return payload.getPageSize(); + } + + @Override + public String extractNextToken(ListBlurbsResponse payload) { + return payload.getNextPageToken(); + } + + @Override + public Iterable extractResources(ListBlurbsResponse payload) { + return payload.getBlurbsList() == null + ? ImmutableList.of() + : payload.getBlurbsList(); + } + }; + + private static final PagedListResponseFactory< + ListRoomsRequest, ListRoomsResponse, ListRoomsPagedResponse> + LIST_ROOMS_PAGE_STR_FACT = + new PagedListResponseFactory< + ListRoomsRequest, ListRoomsResponse, ListRoomsPagedResponse>() { + @Override + public ApiFuture getFuturePagedResponse( + UnaryCallable callable, + ListRoomsRequest request, + ApiCallContext context, + ApiFuture futureResponse) { + PageContext pageContext = + PageContext.create(callable, LIST_ROOMS_PAGE_STR_DESC, request, context); + return ListRoomsPagedResponse.createAsync(pageContext, futureResponse); + } + }; + + private static final PagedListResponseFactory< + ListBlurbsRequest, ListBlurbsResponse, ListBlurbsPagedResponse> + LIST_BLURBS_PAGE_STR_FACT = + new PagedListResponseFactory< + ListBlurbsRequest, ListBlurbsResponse, ListBlurbsPagedResponse>() { + @Override + public ApiFuture getFuturePagedResponse( + UnaryCallable callable, + ListBlurbsRequest request, + ApiCallContext context, + ApiFuture futureResponse) { + PageContext pageContext = + PageContext.create(callable, LIST_BLURBS_PAGE_STR_DESC, request, context); + return ListBlurbsPagedResponse.createAsync(pageContext, futureResponse); + } + }; + + /** Returns the object with the settings used for calls to createRoom. */ + public UnaryCallSettings createRoomSettings() { + return createRoomSettings; + } + + /** Returns the object with the settings used for calls to getRoom. */ + public UnaryCallSettings getRoomSettings() { + return getRoomSettings; + } + + /** Returns the object with the settings used for calls to updateRoom. */ + public UnaryCallSettings updateRoomSettings() { + return updateRoomSettings; + } + + /** Returns the object with the settings used for calls to deleteRoom. */ + public UnaryCallSettings deleteRoomSettings() { + return deleteRoomSettings; + } + + /** Returns the object with the settings used for calls to listRooms. */ + public PagedCallSettings + listRoomsSettings() { + return listRoomsSettings; + } + + /** Returns the object with the settings used for calls to createBlurb. */ + public UnaryCallSettings createBlurbSettings() { + return createBlurbSettings; + } + + /** Returns the object with the settings used for calls to getBlurb. */ + public UnaryCallSettings getBlurbSettings() { + return getBlurbSettings; + } + + /** Returns the object with the settings used for calls to updateBlurb. */ + public UnaryCallSettings updateBlurbSettings() { + return updateBlurbSettings; + } + + /** Returns the object with the settings used for calls to deleteBlurb. */ + public UnaryCallSettings deleteBlurbSettings() { + return deleteBlurbSettings; + } + + /** Returns the object with the settings used for calls to listBlurbs. */ + public PagedCallSettings + listBlurbsSettings() { + return listBlurbsSettings; + } + + /** Returns the object with the settings used for calls to searchBlurbs. */ + public UnaryCallSettings searchBlurbsSettings() { + return searchBlurbsSettings; + } + + /** Returns the object with the settings used for calls to searchBlurbs. */ + public OperationCallSettings + searchBlurbsOperationSettings() { + return searchBlurbsOperationSettings; + } + + /** Returns the object with the settings used for calls to streamBlurbs. */ + public ServerStreamingCallSettings + streamBlurbsSettings() { + return streamBlurbsSettings; + } + + /** Returns the object with the settings used for calls to sendBlurbs. */ + public StreamingCallSettings sendBlurbsSettings() { + return sendBlurbsSettings; + } + + /** Returns the object with the settings used for calls to connect. */ + public StreamingCallSettings connectSettings() { + return connectSettings; + } + + public MessagingStub createStub() throws IOException { + if (getTransportChannelProvider() + .getTransportName() + .equals(GrpcTransportChannel.getGrpcTransportName())) { + return GrpcMessagingStub.create(this); + } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonMessagingStub.create(this); + } + throw new UnsupportedOperationException( + String.format( + "Transport not supported: %s", getTransportChannelProvider().getTransportName())); + } + + /** Returns a builder for the default ExecutorProvider for this service. */ + public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { + return InstantiatingExecutorProvider.newBuilder(); + } + + /** Returns the default service endpoint. */ + public static String getDefaultEndpoint() { + return "localhost:7469"; + } + + /** Returns the default mTLS service endpoint. */ + public static String getDefaultMtlsEndpoint() { + return "localhost:7469"; + } + + /** Returns the default service scopes. */ + public static List getDefaultServiceScopes() { + return DEFAULT_SERVICE_SCOPES; + } + + /** Returns a builder for the default credentials for this service. */ + public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { + return GoogleCredentialsProvider.newBuilder() + .setScopesToApply(DEFAULT_SERVICE_SCOPES) + .setUseJwtAccessWithScope(true); + } + + /** Returns a builder for the default gRPC ChannelProvider for this service. */ + public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { + return InstantiatingGrpcChannelProvider.newBuilder() + .setMaxInboundMessageSize(Integer.MAX_VALUE); + } + + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return InstantiatingHttpJsonChannelProvider.newBuilder(); + } + + public static TransportChannelProvider defaultTransportChannelProvider() { + return defaultGrpcTransportProviderBuilder().build(); + } + + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken("gapic", GaxProperties.getLibraryVersion(MessagingStubSettings.class)) + .setTransportToken( + GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); + } + + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken("gapic", GaxProperties.getLibraryVersion(MessagingStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return MessagingStubSettings.defaultGrpcApiClientHeaderProviderBuilder(); + } + + /** Returns a new gRPC builder for this class. */ + public static Builder newBuilder() { + return Builder.createDefault(); + } + + /** Returns a new REST builder for this class. */ + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder(ClientContext clientContext) { + return new Builder(clientContext); + } + + /** Returns a builder containing all the values of this settings class. */ + public Builder toBuilder() { + return new Builder(this); + } + + protected MessagingStubSettings(Builder settingsBuilder) throws IOException { + super(settingsBuilder); + + createRoomSettings = settingsBuilder.createRoomSettings().build(); + getRoomSettings = settingsBuilder.getRoomSettings().build(); + updateRoomSettings = settingsBuilder.updateRoomSettings().build(); + deleteRoomSettings = settingsBuilder.deleteRoomSettings().build(); + listRoomsSettings = settingsBuilder.listRoomsSettings().build(); + createBlurbSettings = settingsBuilder.createBlurbSettings().build(); + getBlurbSettings = settingsBuilder.getBlurbSettings().build(); + updateBlurbSettings = settingsBuilder.updateBlurbSettings().build(); + deleteBlurbSettings = settingsBuilder.deleteBlurbSettings().build(); + listBlurbsSettings = settingsBuilder.listBlurbsSettings().build(); + searchBlurbsSettings = settingsBuilder.searchBlurbsSettings().build(); + searchBlurbsOperationSettings = settingsBuilder.searchBlurbsOperationSettings().build(); + streamBlurbsSettings = settingsBuilder.streamBlurbsSettings().build(); + sendBlurbsSettings = settingsBuilder.sendBlurbsSettings().build(); + connectSettings = settingsBuilder.connectSettings().build(); + } + + /** Builder for MessagingStubSettings. */ + public static class Builder extends StubSettings.Builder { + private final ImmutableList> unaryMethodSettingsBuilders; + private final UnaryCallSettings.Builder createRoomSettings; + private final UnaryCallSettings.Builder getRoomSettings; + private final UnaryCallSettings.Builder updateRoomSettings; + private final UnaryCallSettings.Builder deleteRoomSettings; + private final PagedCallSettings.Builder< + ListRoomsRequest, ListRoomsResponse, ListRoomsPagedResponse> + listRoomsSettings; + private final UnaryCallSettings.Builder createBlurbSettings; + private final UnaryCallSettings.Builder getBlurbSettings; + private final UnaryCallSettings.Builder updateBlurbSettings; + private final UnaryCallSettings.Builder deleteBlurbSettings; + private final PagedCallSettings.Builder< + ListBlurbsRequest, ListBlurbsResponse, ListBlurbsPagedResponse> + listBlurbsSettings; + private final UnaryCallSettings.Builder searchBlurbsSettings; + private final OperationCallSettings.Builder< + SearchBlurbsRequest, SearchBlurbsResponse, SearchBlurbsMetadata> + searchBlurbsOperationSettings; + private final ServerStreamingCallSettings.Builder + streamBlurbsSettings; + private final StreamingCallSettings.Builder + sendBlurbsSettings; + private final StreamingCallSettings.Builder + connectSettings; + private static final ImmutableMap> + RETRYABLE_CODE_DEFINITIONS; + + static { + ImmutableMap.Builder> definitions = + ImmutableMap.builder(); + definitions.put( + "no_retry_0_codes", ImmutableSet.copyOf(Lists.newArrayList())); + definitions.put( + "retry_policy_1_codes", + ImmutableSet.copyOf( + Lists.newArrayList( + StatusCode.Code.UNAVAILABLE, StatusCode.Code.UNKNOWN))); + RETRYABLE_CODE_DEFINITIONS = definitions.build(); + } + + private static final ImmutableMap RETRY_PARAM_DEFINITIONS; + + static { + ImmutableMap.Builder definitions = ImmutableMap.builder(); + RetrySettings settings = null; + settings = + RetrySettings.newBuilder() + .setInitialRpcTimeout(Duration.ofMillis(5000L)) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ofMillis(5000L)) + .setTotalTimeout(Duration.ofMillis(5000L)) + .build(); + definitions.put("no_retry_0_params", settings); + settings = + RetrySettings.newBuilder() + .setInitialRetryDelay(Duration.ofMillis(100L)) + .setRetryDelayMultiplier(2.0) + .setMaxRetryDelay(Duration.ofMillis(3000L)) + .setInitialRpcTimeout(Duration.ofMillis(10000L)) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ofMillis(10000L)) + .setTotalTimeout(Duration.ofMillis(10000L)) + .build(); + definitions.put("retry_policy_1_params", settings); + RETRY_PARAM_DEFINITIONS = definitions.build(); + } + + protected Builder() { + this(((ClientContext) null)); + } + + protected Builder(ClientContext clientContext) { + super(clientContext); + + createRoomSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + getRoomSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + updateRoomSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + deleteRoomSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + listRoomsSettings = PagedCallSettings.newBuilder(LIST_ROOMS_PAGE_STR_FACT); + createBlurbSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + getBlurbSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + updateBlurbSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + deleteBlurbSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + listBlurbsSettings = PagedCallSettings.newBuilder(LIST_BLURBS_PAGE_STR_FACT); + searchBlurbsSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + searchBlurbsOperationSettings = OperationCallSettings.newBuilder(); + streamBlurbsSettings = ServerStreamingCallSettings.newBuilder(); + sendBlurbsSettings = StreamingCallSettings.newBuilder(); + connectSettings = StreamingCallSettings.newBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of( + createRoomSettings, + getRoomSettings, + updateRoomSettings, + deleteRoomSettings, + listRoomsSettings, + createBlurbSettings, + getBlurbSettings, + updateBlurbSettings, + deleteBlurbSettings, + listBlurbsSettings, + searchBlurbsSettings); + initDefaults(this); + } + + protected Builder(MessagingStubSettings settings) { + super(settings); + + createRoomSettings = settings.createRoomSettings.toBuilder(); + getRoomSettings = settings.getRoomSettings.toBuilder(); + updateRoomSettings = settings.updateRoomSettings.toBuilder(); + deleteRoomSettings = settings.deleteRoomSettings.toBuilder(); + listRoomsSettings = settings.listRoomsSettings.toBuilder(); + createBlurbSettings = settings.createBlurbSettings.toBuilder(); + getBlurbSettings = settings.getBlurbSettings.toBuilder(); + updateBlurbSettings = settings.updateBlurbSettings.toBuilder(); + deleteBlurbSettings = settings.deleteBlurbSettings.toBuilder(); + listBlurbsSettings = settings.listBlurbsSettings.toBuilder(); + searchBlurbsSettings = settings.searchBlurbsSettings.toBuilder(); + searchBlurbsOperationSettings = settings.searchBlurbsOperationSettings.toBuilder(); + streamBlurbsSettings = settings.streamBlurbsSettings.toBuilder(); + sendBlurbsSettings = settings.sendBlurbsSettings.toBuilder(); + connectSettings = settings.connectSettings.toBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of( + createRoomSettings, + getRoomSettings, + updateRoomSettings, + deleteRoomSettings, + listRoomsSettings, + createBlurbSettings, + getBlurbSettings, + updateBlurbSettings, + deleteBlurbSettings, + listBlurbsSettings, + searchBlurbsSettings); + } + + private static Builder createDefault() { + Builder builder = new Builder(((ClientContext) null)); + + builder.setTransportChannelProvider(defaultTransportChannelProvider()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultApiClientHeaderProviderBuilder().build()); + builder.setEndpoint(getDefaultEndpoint()); + builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); + builder.setSwitchToMtlsEndpointAllowed(true); + + return initDefaults(builder); + } + + private static Builder createHttpJsonDefault() { + Builder builder = new Builder(((ClientContext) null)); + + builder.setTransportChannelProvider(defaultHttpJsonTransportProviderBuilder().build()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultHttpJsonApiClientHeaderProviderBuilder().build()); + builder.setEndpoint(getDefaultEndpoint()); + builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); + builder.setSwitchToMtlsEndpointAllowed(true); + + return initDefaults(builder); + } + + private static Builder initDefaults(Builder builder) { + builder + .createRoomSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); + + builder + .getRoomSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_1_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_1_params")); + + builder + .updateRoomSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); + + builder + .deleteRoomSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); + + builder + .listRoomsSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_1_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_1_params")); + + builder + .createBlurbSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); + + builder + .getBlurbSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_1_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_1_params")); + + builder + .updateBlurbSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); + + builder + .deleteBlurbSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); + + builder + .listBlurbsSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_1_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_1_params")); + + builder + .searchBlurbsSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_1_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_1_params")); + + builder + .streamBlurbsSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); + + builder + .searchBlurbsOperationSettings() + .setInitialCallSettings( + UnaryCallSettings + .newUnaryCallSettingsBuilder() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_1_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_1_params")) + .build()) + .setResponseTransformer( + ProtoOperationTransformers.ResponseTransformer.create(SearchBlurbsResponse.class)) + .setMetadataTransformer( + ProtoOperationTransformers.MetadataTransformer.create(SearchBlurbsMetadata.class)) + .setPollingAlgorithm( + OperationTimedPollAlgorithm.create( + RetrySettings.newBuilder() + .setInitialRetryDelay(Duration.ofMillis(5000L)) + .setRetryDelayMultiplier(1.5) + .setMaxRetryDelay(Duration.ofMillis(45000L)) + .setInitialRpcTimeout(Duration.ZERO) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ZERO) + .setTotalTimeout(Duration.ofMillis(300000L)) + .build())); + + return builder; + } + + /** + * Applies the given settings updater function to all of the unary API methods in this service. + * + *

Note: This method does not support applying settings to streaming methods. + */ + public Builder applyToAllUnaryMethods( + ApiFunction, Void> settingsUpdater) { + super.applyToAllUnaryMethods(unaryMethodSettingsBuilders, settingsUpdater); + return this; + } + + public ImmutableList> unaryMethodSettingsBuilders() { + return unaryMethodSettingsBuilders; + } + + /** Returns the builder for the settings used for calls to createRoom. */ + public UnaryCallSettings.Builder createRoomSettings() { + return createRoomSettings; + } + + /** Returns the builder for the settings used for calls to getRoom. */ + public UnaryCallSettings.Builder getRoomSettings() { + return getRoomSettings; + } + + /** Returns the builder for the settings used for calls to updateRoom. */ + public UnaryCallSettings.Builder updateRoomSettings() { + return updateRoomSettings; + } + + /** Returns the builder for the settings used for calls to deleteRoom. */ + public UnaryCallSettings.Builder deleteRoomSettings() { + return deleteRoomSettings; + } + + /** Returns the builder for the settings used for calls to listRooms. */ + public PagedCallSettings.Builder + listRoomsSettings() { + return listRoomsSettings; + } + + /** Returns the builder for the settings used for calls to createBlurb. */ + public UnaryCallSettings.Builder createBlurbSettings() { + return createBlurbSettings; + } + + /** Returns the builder for the settings used for calls to getBlurb. */ + public UnaryCallSettings.Builder getBlurbSettings() { + return getBlurbSettings; + } + + /** Returns the builder for the settings used for calls to updateBlurb. */ + public UnaryCallSettings.Builder updateBlurbSettings() { + return updateBlurbSettings; + } + + /** Returns the builder for the settings used for calls to deleteBlurb. */ + public UnaryCallSettings.Builder deleteBlurbSettings() { + return deleteBlurbSettings; + } + + /** Returns the builder for the settings used for calls to listBlurbs. */ + public PagedCallSettings.Builder + listBlurbsSettings() { + return listBlurbsSettings; + } + + /** Returns the builder for the settings used for calls to searchBlurbs. */ + public UnaryCallSettings.Builder searchBlurbsSettings() { + return searchBlurbsSettings; + } + + /** Returns the builder for the settings used for calls to searchBlurbs. */ + @BetaApi( + "The surface for use by generated code is not stable yet and may change in the future.") + public OperationCallSettings.Builder< + SearchBlurbsRequest, SearchBlurbsResponse, SearchBlurbsMetadata> + searchBlurbsOperationSettings() { + return searchBlurbsOperationSettings; + } + + /** Returns the builder for the settings used for calls to streamBlurbs. */ + public ServerStreamingCallSettings.Builder + streamBlurbsSettings() { + return streamBlurbsSettings; + } + + /** Returns the builder for the settings used for calls to sendBlurbs. */ + public StreamingCallSettings.Builder + sendBlurbsSettings() { + return sendBlurbsSettings; + } + + /** Returns the builder for the settings used for calls to connect. */ + public StreamingCallSettings.Builder connectSettings() { + return connectSettings; + } + + @Override + public MessagingStubSettings build() throws IOException { + return new MessagingStubSettings(this); + } + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/SequenceServiceStub.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/SequenceServiceStub.java new file mode 100644 index 0000000000..7b2f12a463 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/SequenceServiceStub.java @@ -0,0 +1,54 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.AttemptSequenceRequest; +import com.google.showcase.v1beta1.CreateSequenceRequest; +import com.google.showcase.v1beta1.GetSequenceReportRequest; +import com.google.showcase.v1beta1.Sequence; +import com.google.showcase.v1beta1.SequenceReport; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * Base stub class for the SequenceService service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public abstract class SequenceServiceStub implements BackgroundResource { + + public UnaryCallable createSequenceCallable() { + throw new UnsupportedOperationException("Not implemented: createSequenceCallable()"); + } + + public UnaryCallable getSequenceReportCallable() { + throw new UnsupportedOperationException("Not implemented: getSequenceReportCallable()"); + } + + public UnaryCallable attemptSequenceCallable() { + throw new UnsupportedOperationException("Not implemented: attemptSequenceCallable()"); + } + + @Override + public abstract void close(); +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/SequenceServiceStubSettings.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/SequenceServiceStubSettings.java new file mode 100644 index 0000000000..8a4e8b0151 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/SequenceServiceStubSettings.java @@ -0,0 +1,387 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub; + +import com.google.api.core.ApiFunction; +import com.google.api.core.BetaApi; +import com.google.api.gax.core.GaxProperties; +import com.google.api.gax.core.GoogleCredentialsProvider; +import com.google.api.gax.core.InstantiatingExecutorProvider; +import com.google.api.gax.grpc.GaxGrpcProperties; +import com.google.api.gax.grpc.GrpcTransportChannel; +import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.HttpJsonTransportChannel; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; +import com.google.api.gax.retrying.RetrySettings; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.StubSettings; +import com.google.api.gax.rpc.TransportChannelProvider; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Lists; +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.AttemptSequenceRequest; +import com.google.showcase.v1beta1.CreateSequenceRequest; +import com.google.showcase.v1beta1.GetSequenceReportRequest; +import com.google.showcase.v1beta1.Sequence; +import com.google.showcase.v1beta1.SequenceReport; +import java.io.IOException; +import java.util.List; +import javax.annotation.Generated; +import org.threeten.bp.Duration; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * Settings class to configure an instance of {@link SequenceServiceStub}. + * + *

The default instance has everything set to sensible defaults: + * + *

    + *
  • The default service address (localhost) and default port (7469) are used. + *
  • Credentials are acquired automatically through Application Default Credentials. + *
  • Retries are configured for idempotent methods but not for non-idempotent methods. + *
+ * + *

The builder of this class is recursive, so contained classes are themselves builders. When + * build() is called, the tree of builders is called to create the complete settings object. + * + *

For example, to set the total timeout of createSequence to 30 seconds: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * SequenceServiceStubSettings.Builder sequenceServiceSettingsBuilder =
+ *     SequenceServiceStubSettings.newBuilder();
+ * sequenceServiceSettingsBuilder
+ *     .createSequenceSettings()
+ *     .setRetrySettings(
+ *         sequenceServiceSettingsBuilder
+ *             .createSequenceSettings()
+ *             .getRetrySettings()
+ *             .toBuilder()
+ *             .setTotalTimeout(Duration.ofSeconds(30))
+ *             .build());
+ * SequenceServiceStubSettings sequenceServiceSettings = sequenceServiceSettingsBuilder.build();
+ * }
+ */ +@BetaApi +@Generated("by gapic-generator-java") +public class SequenceServiceStubSettings extends StubSettings { + /** The default scopes of the service. */ + private static final ImmutableList DEFAULT_SERVICE_SCOPES = + ImmutableList.builder().build(); + + private final UnaryCallSettings createSequenceSettings; + private final UnaryCallSettings + getSequenceReportSettings; + private final UnaryCallSettings attemptSequenceSettings; + + /** Returns the object with the settings used for calls to createSequence. */ + public UnaryCallSettings createSequenceSettings() { + return createSequenceSettings; + } + + /** Returns the object with the settings used for calls to getSequenceReport. */ + public UnaryCallSettings getSequenceReportSettings() { + return getSequenceReportSettings; + } + + /** Returns the object with the settings used for calls to attemptSequence. */ + public UnaryCallSettings attemptSequenceSettings() { + return attemptSequenceSettings; + } + + public SequenceServiceStub createStub() throws IOException { + if (getTransportChannelProvider() + .getTransportName() + .equals(GrpcTransportChannel.getGrpcTransportName())) { + return GrpcSequenceServiceStub.create(this); + } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonSequenceServiceStub.create(this); + } + throw new UnsupportedOperationException( + String.format( + "Transport not supported: %s", getTransportChannelProvider().getTransportName())); + } + + /** Returns a builder for the default ExecutorProvider for this service. */ + public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { + return InstantiatingExecutorProvider.newBuilder(); + } + + /** Returns the default service endpoint. */ + public static String getDefaultEndpoint() { + return "localhost:7469"; + } + + /** Returns the default mTLS service endpoint. */ + public static String getDefaultMtlsEndpoint() { + return "localhost:7469"; + } + + /** Returns the default service scopes. */ + public static List getDefaultServiceScopes() { + return DEFAULT_SERVICE_SCOPES; + } + + /** Returns a builder for the default credentials for this service. */ + public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { + return GoogleCredentialsProvider.newBuilder() + .setScopesToApply(DEFAULT_SERVICE_SCOPES) + .setUseJwtAccessWithScope(true); + } + + /** Returns a builder for the default gRPC ChannelProvider for this service. */ + public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { + return InstantiatingGrpcChannelProvider.newBuilder() + .setMaxInboundMessageSize(Integer.MAX_VALUE); + } + + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return InstantiatingHttpJsonChannelProvider.newBuilder(); + } + + public static TransportChannelProvider defaultTransportChannelProvider() { + return defaultGrpcTransportProviderBuilder().build(); + } + + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken( + "gapic", GaxProperties.getLibraryVersion(SequenceServiceStubSettings.class)) + .setTransportToken( + GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); + } + + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken( + "gapic", GaxProperties.getLibraryVersion(SequenceServiceStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return SequenceServiceStubSettings.defaultGrpcApiClientHeaderProviderBuilder(); + } + + /** Returns a new gRPC builder for this class. */ + public static Builder newBuilder() { + return Builder.createDefault(); + } + + /** Returns a new REST builder for this class. */ + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder(ClientContext clientContext) { + return new Builder(clientContext); + } + + /** Returns a builder containing all the values of this settings class. */ + public Builder toBuilder() { + return new Builder(this); + } + + protected SequenceServiceStubSettings(Builder settingsBuilder) throws IOException { + super(settingsBuilder); + + createSequenceSettings = settingsBuilder.createSequenceSettings().build(); + getSequenceReportSettings = settingsBuilder.getSequenceReportSettings().build(); + attemptSequenceSettings = settingsBuilder.attemptSequenceSettings().build(); + } + + /** Builder for SequenceServiceStubSettings. */ + public static class Builder extends StubSettings.Builder { + private final ImmutableList> unaryMethodSettingsBuilders; + private final UnaryCallSettings.Builder createSequenceSettings; + private final UnaryCallSettings.Builder + getSequenceReportSettings; + private final UnaryCallSettings.Builder attemptSequenceSettings; + private static final ImmutableMap> + RETRYABLE_CODE_DEFINITIONS; + + static { + ImmutableMap.Builder> definitions = + ImmutableMap.builder(); + definitions.put( + "no_retry_0_codes", ImmutableSet.copyOf(Lists.newArrayList())); + definitions.put( + "retry_policy_1_codes", + ImmutableSet.copyOf( + Lists.newArrayList( + StatusCode.Code.UNAVAILABLE, StatusCode.Code.UNKNOWN))); + RETRYABLE_CODE_DEFINITIONS = definitions.build(); + } + + private static final ImmutableMap RETRY_PARAM_DEFINITIONS; + + static { + ImmutableMap.Builder definitions = ImmutableMap.builder(); + RetrySettings settings = null; + settings = + RetrySettings.newBuilder() + .setInitialRpcTimeout(Duration.ofMillis(5000L)) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ofMillis(5000L)) + .setTotalTimeout(Duration.ofMillis(5000L)) + .build(); + definitions.put("no_retry_0_params", settings); + settings = + RetrySettings.newBuilder() + .setInitialRetryDelay(Duration.ofMillis(100L)) + .setRetryDelayMultiplier(2.0) + .setMaxRetryDelay(Duration.ofMillis(3000L)) + .setInitialRpcTimeout(Duration.ofMillis(10000L)) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ofMillis(10000L)) + .setTotalTimeout(Duration.ofMillis(10000L)) + .build(); + definitions.put("retry_policy_1_params", settings); + RETRY_PARAM_DEFINITIONS = definitions.build(); + } + + protected Builder() { + this(((ClientContext) null)); + } + + protected Builder(ClientContext clientContext) { + super(clientContext); + + createSequenceSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + getSequenceReportSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + attemptSequenceSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of( + createSequenceSettings, getSequenceReportSettings, attemptSequenceSettings); + initDefaults(this); + } + + protected Builder(SequenceServiceStubSettings settings) { + super(settings); + + createSequenceSettings = settings.createSequenceSettings.toBuilder(); + getSequenceReportSettings = settings.getSequenceReportSettings.toBuilder(); + attemptSequenceSettings = settings.attemptSequenceSettings.toBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of( + createSequenceSettings, getSequenceReportSettings, attemptSequenceSettings); + } + + private static Builder createDefault() { + Builder builder = new Builder(((ClientContext) null)); + + builder.setTransportChannelProvider(defaultTransportChannelProvider()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultApiClientHeaderProviderBuilder().build()); + builder.setEndpoint(getDefaultEndpoint()); + builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); + builder.setSwitchToMtlsEndpointAllowed(true); + + return initDefaults(builder); + } + + private static Builder createHttpJsonDefault() { + Builder builder = new Builder(((ClientContext) null)); + + builder.setTransportChannelProvider(defaultHttpJsonTransportProviderBuilder().build()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultHttpJsonApiClientHeaderProviderBuilder().build()); + builder.setEndpoint(getDefaultEndpoint()); + builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); + builder.setSwitchToMtlsEndpointAllowed(true); + + return initDefaults(builder); + } + + private static Builder initDefaults(Builder builder) { + builder + .createSequenceSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); + + builder + .getSequenceReportSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); + + builder + .attemptSequenceSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_1_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_1_params")); + + return builder; + } + + /** + * Applies the given settings updater function to all of the unary API methods in this service. + * + *

Note: This method does not support applying settings to streaming methods. + */ + public Builder applyToAllUnaryMethods( + ApiFunction, Void> settingsUpdater) { + super.applyToAllUnaryMethods(unaryMethodSettingsBuilders, settingsUpdater); + return this; + } + + public ImmutableList> unaryMethodSettingsBuilders() { + return unaryMethodSettingsBuilders; + } + + /** Returns the builder for the settings used for calls to createSequence. */ + public UnaryCallSettings.Builder createSequenceSettings() { + return createSequenceSettings; + } + + /** Returns the builder for the settings used for calls to getSequenceReport. */ + public UnaryCallSettings.Builder + getSequenceReportSettings() { + return getSequenceReportSettings; + } + + /** Returns the builder for the settings used for calls to attemptSequence. */ + public UnaryCallSettings.Builder attemptSequenceSettings() { + return attemptSequenceSettings; + } + + @Override + public SequenceServiceStubSettings build() throws IOException { + return new SequenceServiceStubSettings(this); + } + } +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/TestingStub.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/TestingStub.java new file mode 100644 index 0000000000..5a79303508 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/TestingStub.java @@ -0,0 +1,93 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub; + +import static com.google.showcase.v1beta1.TestingClient.ListSessionsPagedResponse; +import static com.google.showcase.v1beta1.TestingClient.ListTestsPagedResponse; + +import com.google.api.core.BetaApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.CreateSessionRequest; +import com.google.showcase.v1beta1.DeleteSessionRequest; +import com.google.showcase.v1beta1.DeleteTestRequest; +import com.google.showcase.v1beta1.GetSessionRequest; +import com.google.showcase.v1beta1.ListSessionsRequest; +import com.google.showcase.v1beta1.ListSessionsResponse; +import com.google.showcase.v1beta1.ListTestsRequest; +import com.google.showcase.v1beta1.ListTestsResponse; +import com.google.showcase.v1beta1.ReportSessionRequest; +import com.google.showcase.v1beta1.ReportSessionResponse; +import com.google.showcase.v1beta1.Session; +import com.google.showcase.v1beta1.VerifyTestRequest; +import com.google.showcase.v1beta1.VerifyTestResponse; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * Base stub class for the Testing service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public abstract class TestingStub implements BackgroundResource { + + public UnaryCallable createSessionCallable() { + throw new UnsupportedOperationException("Not implemented: createSessionCallable()"); + } + + public UnaryCallable getSessionCallable() { + throw new UnsupportedOperationException("Not implemented: getSessionCallable()"); + } + + public UnaryCallable listSessionsPagedCallable() { + throw new UnsupportedOperationException("Not implemented: listSessionsPagedCallable()"); + } + + public UnaryCallable listSessionsCallable() { + throw new UnsupportedOperationException("Not implemented: listSessionsCallable()"); + } + + public UnaryCallable deleteSessionCallable() { + throw new UnsupportedOperationException("Not implemented: deleteSessionCallable()"); + } + + public UnaryCallable reportSessionCallable() { + throw new UnsupportedOperationException("Not implemented: reportSessionCallable()"); + } + + public UnaryCallable listTestsPagedCallable() { + throw new UnsupportedOperationException("Not implemented: listTestsPagedCallable()"); + } + + public UnaryCallable listTestsCallable() { + throw new UnsupportedOperationException("Not implemented: listTestsCallable()"); + } + + public UnaryCallable deleteTestCallable() { + throw new UnsupportedOperationException("Not implemented: deleteTestCallable()"); + } + + public UnaryCallable verifyTestCallable() { + throw new UnsupportedOperationException("Not implemented: verifyTestCallable()"); + } + + @Override + public abstract void close(); +} diff --git a/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/TestingStubSettings.java b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/TestingStubSettings.java new file mode 100644 index 0000000000..9c22b1ce81 --- /dev/null +++ b/test/integration/goldens/showcase/src/com/google/showcase/v1beta1/stub/TestingStubSettings.java @@ -0,0 +1,612 @@ +/* + * 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 + * + * https://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.showcase.v1beta1.stub; + +import static com.google.showcase.v1beta1.TestingClient.ListSessionsPagedResponse; +import static com.google.showcase.v1beta1.TestingClient.ListTestsPagedResponse; + +import com.google.api.core.ApiFunction; +import com.google.api.core.ApiFuture; +import com.google.api.core.BetaApi; +import com.google.api.gax.core.GaxProperties; +import com.google.api.gax.core.GoogleCredentialsProvider; +import com.google.api.gax.core.InstantiatingExecutorProvider; +import com.google.api.gax.grpc.GaxGrpcProperties; +import com.google.api.gax.grpc.GrpcTransportChannel; +import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.HttpJsonTransportChannel; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; +import com.google.api.gax.retrying.RetrySettings; +import com.google.api.gax.rpc.ApiCallContext; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.PageContext; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.PagedListDescriptor; +import com.google.api.gax.rpc.PagedListResponseFactory; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.StubSettings; +import com.google.api.gax.rpc.TransportChannelProvider; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Lists; +import com.google.protobuf.Empty; +import com.google.showcase.v1beta1.CreateSessionRequest; +import com.google.showcase.v1beta1.DeleteSessionRequest; +import com.google.showcase.v1beta1.DeleteTestRequest; +import com.google.showcase.v1beta1.GetSessionRequest; +import com.google.showcase.v1beta1.ListSessionsRequest; +import com.google.showcase.v1beta1.ListSessionsResponse; +import com.google.showcase.v1beta1.ListTestsRequest; +import com.google.showcase.v1beta1.ListTestsResponse; +import com.google.showcase.v1beta1.ReportSessionRequest; +import com.google.showcase.v1beta1.ReportSessionResponse; +import com.google.showcase.v1beta1.Session; +import com.google.showcase.v1beta1.Test; +import com.google.showcase.v1beta1.VerifyTestRequest; +import com.google.showcase.v1beta1.VerifyTestResponse; +import java.io.IOException; +import java.util.List; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * Settings class to configure an instance of {@link TestingStub}. + * + *

The default instance has everything set to sensible defaults: + * + *

    + *
  • The default service address (localhost) and default port (7469) are used. + *
  • Credentials are acquired automatically through Application Default Credentials. + *
  • Retries are configured for idempotent methods but not for non-idempotent methods. + *
+ * + *

The builder of this class is recursive, so contained classes are themselves builders. When + * build() is called, the tree of builders is called to create the complete settings object. + * + *

For example, to set the total timeout of createSession to 30 seconds: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * TestingStubSettings.Builder testingSettingsBuilder = TestingStubSettings.newBuilder();
+ * testingSettingsBuilder
+ *     .createSessionSettings()
+ *     .setRetrySettings(
+ *         testingSettingsBuilder
+ *             .createSessionSettings()
+ *             .getRetrySettings()
+ *             .toBuilder()
+ *             .setTotalTimeout(Duration.ofSeconds(30))
+ *             .build());
+ * TestingStubSettings testingSettings = testingSettingsBuilder.build();
+ * }
+ */ +@BetaApi +@Generated("by gapic-generator-java") +public class TestingStubSettings extends StubSettings { + /** The default scopes of the service. */ + private static final ImmutableList DEFAULT_SERVICE_SCOPES = + ImmutableList.builder().build(); + + private final UnaryCallSettings createSessionSettings; + private final UnaryCallSettings getSessionSettings; + private final PagedCallSettings< + ListSessionsRequest, ListSessionsResponse, ListSessionsPagedResponse> + listSessionsSettings; + private final UnaryCallSettings deleteSessionSettings; + private final UnaryCallSettings + reportSessionSettings; + private final PagedCallSettings + listTestsSettings; + private final UnaryCallSettings deleteTestSettings; + private final UnaryCallSettings verifyTestSettings; + + private static final PagedListDescriptor + LIST_SESSIONS_PAGE_STR_DESC = + new PagedListDescriptor() { + @Override + public String emptyToken() { + return ""; + } + + @Override + public ListSessionsRequest injectToken(ListSessionsRequest payload, String token) { + return ListSessionsRequest.newBuilder(payload).setPageToken(token).build(); + } + + @Override + public ListSessionsRequest injectPageSize(ListSessionsRequest payload, int pageSize) { + return ListSessionsRequest.newBuilder(payload).setPageSize(pageSize).build(); + } + + @Override + public Integer extractPageSize(ListSessionsRequest payload) { + return payload.getPageSize(); + } + + @Override + public String extractNextToken(ListSessionsResponse payload) { + return payload.getNextPageToken(); + } + + @Override + public Iterable extractResources(ListSessionsResponse payload) { + return payload.getSessionsList() == null + ? ImmutableList.of() + : payload.getSessionsList(); + } + }; + + private static final PagedListDescriptor + LIST_TESTS_PAGE_STR_DESC = + new PagedListDescriptor() { + @Override + public String emptyToken() { + return ""; + } + + @Override + public ListTestsRequest injectToken(ListTestsRequest payload, String token) { + return ListTestsRequest.newBuilder(payload).setPageToken(token).build(); + } + + @Override + public ListTestsRequest injectPageSize(ListTestsRequest payload, int pageSize) { + return ListTestsRequest.newBuilder(payload).setPageSize(pageSize).build(); + } + + @Override + public Integer extractPageSize(ListTestsRequest payload) { + return payload.getPageSize(); + } + + @Override + public String extractNextToken(ListTestsResponse payload) { + return payload.getNextPageToken(); + } + + @Override + public Iterable extractResources(ListTestsResponse payload) { + return payload.getTestsList() == null + ? ImmutableList.of() + : payload.getTestsList(); + } + }; + + private static final PagedListResponseFactory< + ListSessionsRequest, ListSessionsResponse, ListSessionsPagedResponse> + LIST_SESSIONS_PAGE_STR_FACT = + new PagedListResponseFactory< + ListSessionsRequest, ListSessionsResponse, ListSessionsPagedResponse>() { + @Override + public ApiFuture getFuturePagedResponse( + UnaryCallable callable, + ListSessionsRequest request, + ApiCallContext context, + ApiFuture futureResponse) { + PageContext pageContext = + PageContext.create(callable, LIST_SESSIONS_PAGE_STR_DESC, request, context); + return ListSessionsPagedResponse.createAsync(pageContext, futureResponse); + } + }; + + private static final PagedListResponseFactory< + ListTestsRequest, ListTestsResponse, ListTestsPagedResponse> + LIST_TESTS_PAGE_STR_FACT = + new PagedListResponseFactory< + ListTestsRequest, ListTestsResponse, ListTestsPagedResponse>() { + @Override + public ApiFuture getFuturePagedResponse( + UnaryCallable callable, + ListTestsRequest request, + ApiCallContext context, + ApiFuture futureResponse) { + PageContext pageContext = + PageContext.create(callable, LIST_TESTS_PAGE_STR_DESC, request, context); + return ListTestsPagedResponse.createAsync(pageContext, futureResponse); + } + }; + + /** Returns the object with the settings used for calls to createSession. */ + public UnaryCallSettings createSessionSettings() { + return createSessionSettings; + } + + /** Returns the object with the settings used for calls to getSession. */ + public UnaryCallSettings getSessionSettings() { + return getSessionSettings; + } + + /** Returns the object with the settings used for calls to listSessions. */ + public PagedCallSettings + listSessionsSettings() { + return listSessionsSettings; + } + + /** Returns the object with the settings used for calls to deleteSession. */ + public UnaryCallSettings deleteSessionSettings() { + return deleteSessionSettings; + } + + /** Returns the object with the settings used for calls to reportSession. */ + public UnaryCallSettings reportSessionSettings() { + return reportSessionSettings; + } + + /** Returns the object with the settings used for calls to listTests. */ + public PagedCallSettings + listTestsSettings() { + return listTestsSettings; + } + + /** Returns the object with the settings used for calls to deleteTest. */ + public UnaryCallSettings deleteTestSettings() { + return deleteTestSettings; + } + + /** Returns the object with the settings used for calls to verifyTest. */ + public UnaryCallSettings verifyTestSettings() { + return verifyTestSettings; + } + + public TestingStub createStub() throws IOException { + if (getTransportChannelProvider() + .getTransportName() + .equals(GrpcTransportChannel.getGrpcTransportName())) { + return GrpcTestingStub.create(this); + } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonTestingStub.create(this); + } + throw new UnsupportedOperationException( + String.format( + "Transport not supported: %s", getTransportChannelProvider().getTransportName())); + } + + /** Returns a builder for the default ExecutorProvider for this service. */ + public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { + return InstantiatingExecutorProvider.newBuilder(); + } + + /** Returns the default service endpoint. */ + public static String getDefaultEndpoint() { + return "localhost:7469"; + } + + /** Returns the default mTLS service endpoint. */ + public static String getDefaultMtlsEndpoint() { + return "localhost:7469"; + } + + /** Returns the default service scopes. */ + public static List getDefaultServiceScopes() { + return DEFAULT_SERVICE_SCOPES; + } + + /** Returns a builder for the default credentials for this service. */ + public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { + return GoogleCredentialsProvider.newBuilder() + .setScopesToApply(DEFAULT_SERVICE_SCOPES) + .setUseJwtAccessWithScope(true); + } + + /** Returns a builder for the default gRPC ChannelProvider for this service. */ + public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { + return InstantiatingGrpcChannelProvider.newBuilder() + .setMaxInboundMessageSize(Integer.MAX_VALUE); + } + + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return InstantiatingHttpJsonChannelProvider.newBuilder(); + } + + public static TransportChannelProvider defaultTransportChannelProvider() { + return defaultGrpcTransportProviderBuilder().build(); + } + + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken("gapic", GaxProperties.getLibraryVersion(TestingStubSettings.class)) + .setTransportToken( + GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); + } + + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken("gapic", GaxProperties.getLibraryVersion(TestingStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return TestingStubSettings.defaultGrpcApiClientHeaderProviderBuilder(); + } + + /** Returns a new gRPC builder for this class. */ + public static Builder newBuilder() { + return Builder.createDefault(); + } + + /** Returns a new REST builder for this class. */ + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder(ClientContext clientContext) { + return new Builder(clientContext); + } + + /** Returns a builder containing all the values of this settings class. */ + public Builder toBuilder() { + return new Builder(this); + } + + protected TestingStubSettings(Builder settingsBuilder) throws IOException { + super(settingsBuilder); + + createSessionSettings = settingsBuilder.createSessionSettings().build(); + getSessionSettings = settingsBuilder.getSessionSettings().build(); + listSessionsSettings = settingsBuilder.listSessionsSettings().build(); + deleteSessionSettings = settingsBuilder.deleteSessionSettings().build(); + reportSessionSettings = settingsBuilder.reportSessionSettings().build(); + listTestsSettings = settingsBuilder.listTestsSettings().build(); + deleteTestSettings = settingsBuilder.deleteTestSettings().build(); + verifyTestSettings = settingsBuilder.verifyTestSettings().build(); + } + + /** Builder for TestingStubSettings. */ + public static class Builder extends StubSettings.Builder { + private final ImmutableList> unaryMethodSettingsBuilders; + private final UnaryCallSettings.Builder createSessionSettings; + private final UnaryCallSettings.Builder getSessionSettings; + private final PagedCallSettings.Builder< + ListSessionsRequest, ListSessionsResponse, ListSessionsPagedResponse> + listSessionsSettings; + private final UnaryCallSettings.Builder deleteSessionSettings; + private final UnaryCallSettings.Builder + reportSessionSettings; + private final PagedCallSettings.Builder< + ListTestsRequest, ListTestsResponse, ListTestsPagedResponse> + listTestsSettings; + private final UnaryCallSettings.Builder deleteTestSettings; + private final UnaryCallSettings.Builder + verifyTestSettings; + private static final ImmutableMap> + RETRYABLE_CODE_DEFINITIONS; + + static { + ImmutableMap.Builder> definitions = + ImmutableMap.builder(); + definitions.put("no_retry_codes", ImmutableSet.copyOf(Lists.newArrayList())); + RETRYABLE_CODE_DEFINITIONS = definitions.build(); + } + + private static final ImmutableMap RETRY_PARAM_DEFINITIONS; + + static { + ImmutableMap.Builder definitions = ImmutableMap.builder(); + RetrySettings settings = null; + settings = RetrySettings.newBuilder().setRpcTimeoutMultiplier(1.0).build(); + definitions.put("no_retry_params", settings); + RETRY_PARAM_DEFINITIONS = definitions.build(); + } + + protected Builder() { + this(((ClientContext) null)); + } + + protected Builder(ClientContext clientContext) { + super(clientContext); + + createSessionSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + getSessionSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + listSessionsSettings = PagedCallSettings.newBuilder(LIST_SESSIONS_PAGE_STR_FACT); + deleteSessionSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + reportSessionSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + listTestsSettings = PagedCallSettings.newBuilder(LIST_TESTS_PAGE_STR_FACT); + deleteTestSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + verifyTestSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of( + createSessionSettings, + getSessionSettings, + listSessionsSettings, + deleteSessionSettings, + reportSessionSettings, + listTestsSettings, + deleteTestSettings, + verifyTestSettings); + initDefaults(this); + } + + protected Builder(TestingStubSettings settings) { + super(settings); + + createSessionSettings = settings.createSessionSettings.toBuilder(); + getSessionSettings = settings.getSessionSettings.toBuilder(); + listSessionsSettings = settings.listSessionsSettings.toBuilder(); + deleteSessionSettings = settings.deleteSessionSettings.toBuilder(); + reportSessionSettings = settings.reportSessionSettings.toBuilder(); + listTestsSettings = settings.listTestsSettings.toBuilder(); + deleteTestSettings = settings.deleteTestSettings.toBuilder(); + verifyTestSettings = settings.verifyTestSettings.toBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of( + createSessionSettings, + getSessionSettings, + listSessionsSettings, + deleteSessionSettings, + reportSessionSettings, + listTestsSettings, + deleteTestSettings, + verifyTestSettings); + } + + private static Builder createDefault() { + Builder builder = new Builder(((ClientContext) null)); + + builder.setTransportChannelProvider(defaultTransportChannelProvider()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultApiClientHeaderProviderBuilder().build()); + builder.setEndpoint(getDefaultEndpoint()); + builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); + builder.setSwitchToMtlsEndpointAllowed(true); + + return initDefaults(builder); + } + + private static Builder createHttpJsonDefault() { + Builder builder = new Builder(((ClientContext) null)); + + builder.setTransportChannelProvider(defaultHttpJsonTransportProviderBuilder().build()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultHttpJsonApiClientHeaderProviderBuilder().build()); + builder.setEndpoint(getDefaultEndpoint()); + builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); + builder.setSwitchToMtlsEndpointAllowed(true); + + return initDefaults(builder); + } + + private static Builder initDefaults(Builder builder) { + builder + .createSessionSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .getSessionSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .listSessionsSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .deleteSessionSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .reportSessionSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .listTestsSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .deleteTestSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .verifyTestSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + return builder; + } + + /** + * Applies the given settings updater function to all of the unary API methods in this service. + * + *

Note: This method does not support applying settings to streaming methods. + */ + public Builder applyToAllUnaryMethods( + ApiFunction, Void> settingsUpdater) { + super.applyToAllUnaryMethods(unaryMethodSettingsBuilders, settingsUpdater); + return this; + } + + public ImmutableList> unaryMethodSettingsBuilders() { + return unaryMethodSettingsBuilders; + } + + /** Returns the builder for the settings used for calls to createSession. */ + public UnaryCallSettings.Builder createSessionSettings() { + return createSessionSettings; + } + + /** Returns the builder for the settings used for calls to getSession. */ + public UnaryCallSettings.Builder getSessionSettings() { + return getSessionSettings; + } + + /** Returns the builder for the settings used for calls to listSessions. */ + public PagedCallSettings.Builder< + ListSessionsRequest, ListSessionsResponse, ListSessionsPagedResponse> + listSessionsSettings() { + return listSessionsSettings; + } + + /** Returns the builder for the settings used for calls to deleteSession. */ + public UnaryCallSettings.Builder deleteSessionSettings() { + return deleteSessionSettings; + } + + /** Returns the builder for the settings used for calls to reportSession. */ + public UnaryCallSettings.Builder + reportSessionSettings() { + return reportSessionSettings; + } + + /** Returns the builder for the settings used for calls to listTests. */ + public PagedCallSettings.Builder + listTestsSettings() { + return listTestsSettings; + } + + /** Returns the builder for the settings used for calls to deleteTest. */ + public UnaryCallSettings.Builder deleteTestSettings() { + return deleteTestSettings; + } + + /** Returns the builder for the settings used for calls to verifyTest. */ + public UnaryCallSettings.Builder verifyTestSettings() { + return verifyTestSettings; + } + + @Override + public TestingStubSettings build() throws IOException { + return new TestingStubSettings(this); + } + } +} diff --git a/test/showcase/BUILD.bazel b/test/showcase/BUILD.bazel new file mode 100644 index 0000000000..d4563af02a --- /dev/null +++ b/test/showcase/BUILD.bazel @@ -0,0 +1,59 @@ +load( + "//rules_java_gapic:java_gapic.bzl", + "java_gapic_library", + "java_gapic_test", +) +load("@io_grpc_grpc_java//:java_grpc_library.bzl", "java_grpc_library") +load("@rules_gapic//:gapic.bzl", "proto_library_with_info") +load("@rules_proto//proto:defs.bzl", "proto_library") +load("//rules_java_gapic:java_gapic_pkg.bzl", "java_gapic_assembly_gradle_pkg") + +package(default_visibility = ["//visibility:public"]) + +proto_library_with_info( + name = "showcase_proto_with_info", + deps = [ + "@com_google_gapic_showcase//schema/google/showcase/v1beta1:showcase_proto", + "@com_google_googleapis//google/cloud:common_resources_proto", + ], +) + +java_proto_library( + name = "showcase_java_proto", + deps = ["@com_google_gapic_showcase//schema/google/showcase/v1beta1:showcase_proto"], +) + +java_grpc_library( + name = "showcase_java_grpc", + srcs = ["@com_google_gapic_showcase//schema/google/showcase/v1beta1:showcase_proto"], + deps = [":showcase_java_proto"], +) + +java_gapic_library( + name = "showcase_java_gapic", + srcs = [":showcase_proto_with_info"], + gapic_yaml = None, + grpc_service_config = "@com_google_gapic_showcase//schema/google/showcase/v1beta1:showcase_grpc_service_config.json", + rest_numeric_enums = True, + service_yaml = "@com_google_gapic_showcase//schema/google/showcase/v1beta1:showcase_v1beta1.yaml", + test_deps = [ + ":showcase_java_grpc", + ], + transport = "grpc+rest", + deps = [ + ":showcase_java_proto", + "@com_google_googleapis//google/api:api_java_proto", + ], +) + +# Open Source Packages +java_gapic_assembly_gradle_pkg( + name = "google-cloud-showcase-v1beta1-java", + transport = "grpc+rest", + deps = [ + ":showcase_java_gapic", + ":showcase_java_grpc", + ":showcase_java_proto", + "@com_google_gapic_showcase//schema/google/showcase/v1beta1:showcase_proto", + ], +) diff --git a/version.txt b/version.txt index 5f4f65c859..46b81d815a 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -2.10.3 +2.11.0