diff --git a/src/test/java/com/google/api/generator/gapic/composer/ServiceClientClassComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/ServiceClientClassComposerTest.java
index 0f210ac1a5..f0c0d70102 100644
--- a/src/test/java/com/google/api/generator/gapic/composer/ServiceClientClassComposerTest.java
+++ b/src/test/java/com/google/api/generator/gapic/composer/ServiceClientClassComposerTest.java
@@ -14,6 +14,7 @@
package com.google.api.generator.gapic.composer;
+import static com.google.api.generator.test.framework.Assert.assertCodeEquals;
import static junit.framework.Assert.assertEquals;
import com.google.api.generator.engine.writer.JavaWriterVisitor;
@@ -22,9 +23,12 @@
import com.google.api.generator.gapic.model.ResourceName;
import com.google.api.generator.gapic.model.Service;
import com.google.api.generator.gapic.protoparser.Parser;
+import com.google.api.generator.test.framework.Utils;
import com.google.protobuf.Descriptors.FileDescriptor;
import com.google.protobuf.Descriptors.ServiceDescriptor;
import com.google.showcase.v1beta1.EchoOuterClass;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -57,507 +61,8 @@ public void generateServiceClasses() {
JavaWriterVisitor visitor = new JavaWriterVisitor();
clazz.classDefinition().accept(visitor);
- assertEquals(EXPECTED_CLASS_STRING, visitor.write());
+ Utils.saveCodegenToFile(this.getClass(), "EchoClient.golden", visitor.write());
+ Path goldenFilePath = Paths.get(ComposerConstants.GOLDENFILES_DIRECTORY, "EchoClient.golden");
+ assertCodeEquals(goldenFilePath, visitor.write());
}
-
- // TODO(miraleung): Update this when a file-diffing test mechanism is in place.
- private static final String EXPECTED_CLASS_STRING =
- "package com.google.showcase.v1beta1;\n"
- + "\n"
- + "import com.google.api.core.ApiFunction;\n"
- + "import com.google.api.core.ApiFuture;\n"
- + "import com.google.api.core.ApiFutures;\n"
- + "import com.google.api.core.BetaApi;\n"
- + "import com.google.api.gax.core.BackgroundResource;\n"
- + "import com.google.api.gax.longrunning.OperationFuture;\n"
- + "import com.google.api.gax.paging.AbstractFixedSizeCollection;\n"
- + "import com.google.api.gax.paging.AbstractPage;\n"
- + "import com.google.api.gax.paging.AbstractPagedListResponse;\n"
- + "import com.google.api.gax.rpc.BidiStreamingCallable;\n"
- + "import com.google.api.gax.rpc.ClientStreamingCallable;\n"
- + "import com.google.api.gax.rpc.OperationCallable;\n"
- + "import com.google.api.gax.rpc.PageContext;\n"
- + "import com.google.api.gax.rpc.ServerStreamingCallable;\n"
- + "import com.google.api.gax.rpc.UnaryCallable;\n"
- + "import com.google.api.resourcenames.ResourceName;\n"
- + "import com.google.common.util.concurrent.MoreExecutors;\n"
- + "import com.google.longrunning.Operation;\n"
- + "import com.google.longrunning.OperationsClient;\n"
- + "import com.google.protobuf.Duration;\n"
- + "import com.google.protobuf.Timestamp;\n"
- + "import com.google.rpc.Status;\n"
- + "import com.google.showcase.v1beta1.stub.EchoStub;\n"
- + "import com.google.showcase.v1beta1.stub.EchoStubSettings;\n"
- + "import java.io.IOException;\n"
- + "import java.util.List;\n"
- + "import java.util.Objects;\n"
- + "import java.util.concurrent.TimeUnit;\n"
- + "import javax.annotation.Generated;\n"
- + "\n"
- + "// AUTO-GENERATED DOCUMENTATION AND CLASS.\n"
- + "/**\n"
- + " * This class provides the ability to make remote calls to the backing service"
- + " through method calls\n"
- + " * that map to API methods. Sample code to get started:\n"
- + " *\n"
- + " *
Note: close() needs to be called on the echoClient object to clean up resources"
- + " such as\n"
- + " * threads. In the example above, try-with-resources is used, which automatically"
- + " calls close().\n"
- + " *\n"
- + " *
The surface of this class includes several types of Java methods for each of"
- + " the API's\n"
- + " * methods:\n"
- + " *\n"
- + " *
\n"
- + " * - A \"flattened\" method. With this type of method, the fields of the request"
- + " type have been\n"
- + " * converted into function parameters. It may be the case that not all fields"
- + " are available as\n"
- + " * parameters, and not every API method will have a flattened method entry"
- + " point.\n"
- + " *
- A \"request object\" method. This type of method only takes one parameter, a"
- + " request object,\n"
- + " * which must be constructed before the call. Not every API method will have a"
- + " request object\n"
- + " * method.\n"
- + " *
- A \"callable\" method. This type of method takes no parameters and returns"
- + " an immutable API\n"
- + " * callable object, which can be used to initiate calls to the service.\n"
- + " *
\n"
- + " *\n"
- + " * See the individual methods for example code.\n"
- + " *\n"
- + " *
Many parameters require resource names to be formatted in a particular way. To"
- + " assist with\n"
- + " * these names, this class includes a format method for each type of name, and"
- + " additionally a parse\n"
- + " * method to extract the individual identifiers contained within names that are"
- + " returned.\n"
- + " *\n"
- + " *
This class can be customized by passing in a custom instance of EchoSettings to"
- + " create(). For\n"
- + " * example:\n"
- + " *\n"
- + " *
To customize credentials:\n"
- + " *\n"
- + " *
To customize the endpoint:\n"
- + " */\n"
- + "@BetaApi\n"
- + "@Generated(\"by gapic-generator\")\n"
- + "public class EchoClient implements BackgroundResource {\n"
- + " private final EchoSettings settings;\n"
- + " private final EchoStub stub;\n"
- + " private final OperationsClient operationsClient;\n"
- + "\n"
- + " /** Constructs an instance of EchoClient with default settings. */\n"
- + " public static final EchoClient create() throws IOException {\n"
- + " return create(EchoSettings.newBuilder().build());\n"
- + " }\n"
- + "\n"
- + " /**\n"
- + " * Constructs an instance of EchoClient, using the given settings. The channels are"
- + " created based\n"
- + " * on the settings passed in, or defaults for any settings that are not set.\n"
- + " */\n"
- + " public static final EchoClient create(EchoSettings settings) throws IOException {\n"
- + " return new EchoClient(settings);\n"
- + " }\n"
- + "\n"
- + " /**\n"
- + " * Constructs an instance of EchoClient, using the given stub for making calls."
- + " This is for\n"
- + " * advanced usage - prefer using create(EchoSettings).\n"
- + " */\n"
- + " @BetaApi(\"A restructuring of stub classes is planned, so this may break in the"
- + " future\")\n"
- + " public static final EchoClient create(EchoStub stub) {\n"
- + " return new EchoClient(stub);\n"
- + " }\n"
- + "\n"
- + " /**\n"
- + " * Constructs an instance of EchoClient, using the given settings. This is"
- + " protected so that it is\n"
- + " * easy to make a subclass, but otherwise, the static factory methods should be"
- + " preferred.\n"
- + " */\n"
- + " protected EchoClient(EchoSettings settings) throws IOException {\n"
- + " this.settings = settings;\n"
- + " this.stub = ((EchoStubSettings) settings.getStubSettings()).createStub();\n"
- + " this.operationsClient = OperationsClient.create(this.stub.getOperationsStub());\n"
- + " }\n"
- + "\n"
- + " @BetaApi(\"A restructuring of stub classes is planned, so this may break in the"
- + " future\")\n"
- + " protected EchoClient(EchoStub stub) {\n"
- + " this.settings = null;\n"
- + " this.stub = stub;\n"
- + " this.operationsClient = OperationsClient.create(this.stub.getOperationsStub());\n"
- + " }\n"
- + "\n"
- + " public final EchoSettings getSettings() {\n"
- + " return settings;\n"
- + " }\n"
- + "\n"
- + " @BetaApi(\"A restructuring of stub classes is planned, so this may break in the"
- + " future\")\n"
- + " public EchoStub getStub() {\n"
- + " return stub;\n"
- + " }\n"
- + "\n"
- + " /**\n"
- + " * Returns the OperationsClient that can be used to query the status of a"
- + " long-running operation\n"
- + " * returned by another API method call.\n"
- + " */\n"
- + " public final OperationsClient getOperationsClient() {\n"
- + " return operationsClient;\n"
- + " }\n"
- + "\n"
- + " // AUTO-GENERATED DOCUMENTATION AND METHOD.\n"
- + " /**\n"
- + " * Sample code:\n"
- + " *\n"
- + " * @param parent\n"
- + " * @throws com.google.api.gax.rpc.ApiException if the remote call fails\n"
- + " */\n"
- + " public final EchoResponse echo(ResourceName parent) {\n"
- + " EchoRequest request =\n"
- + " EchoRequest.newBuilder()\n"
- + " .setParent(Objects.isNull(parent) ? null : parent.toString())\n"
- + " .build();\n"
- + " return echo(request);\n"
- + " }\n"
- + "\n"
- + " // AUTO-GENERATED DOCUMENTATION AND METHOD.\n"
- + " /**\n"
- + " * Sample code:\n"
- + " *\n"
- + " * @param error\n"
- + " * @throws com.google.api.gax.rpc.ApiException if the remote call fails\n"
- + " */\n"
- + " public final EchoResponse echo(Status error) {\n"
- + " EchoRequest request = EchoRequest.newBuilder().setError(error).build();\n"
- + " return echo(request);\n"
- + " }\n"
- + "\n"
- + " // AUTO-GENERATED DOCUMENTATION AND METHOD.\n"
- + " /**\n"
- + " * Sample code:\n"
- + " *\n"
- + " * @param name\n"
- + " * @throws com.google.api.gax.rpc.ApiException if the remote call fails\n"
- + " */\n"
- + " public final EchoResponse echo(FoobarName name) {\n"
- + " EchoRequest request =\n"
- + " EchoRequest.newBuilder().setName(Objects.isNull(name) ? null :"
- + " name.toString()).build();\n"
- + " return echo(request);\n"
- + " }\n"
- + "\n"
- + " // AUTO-GENERATED DOCUMENTATION AND METHOD.\n"
- + " /**\n"
- + " * Sample code:\n"
- + " *\n"
- + " * @param content\n"
- + " * @throws com.google.api.gax.rpc.ApiException if the remote call fails\n"
- + " */\n"
- + " public final EchoResponse echo(String content) {\n"
- + " EchoRequest request = EchoRequest.newBuilder().setContent(content).build();\n"
- + " return echo(request);\n"
- + " }\n"
- + "\n"
- + " // AUTO-GENERATED DOCUMENTATION AND METHOD.\n"
- + " /**\n"
- + " * Sample code:\n"
- + " *\n"
- + " * @param name\n"
- + " * @throws com.google.api.gax.rpc.ApiException if the remote call fails\n"
- + " */\n"
- + " public final EchoResponse echo(String name) {\n"
- + " EchoRequest request = EchoRequest.newBuilder().setName(name).build();\n"
- + " return echo(request);\n"
- + " }\n"
- + "\n"
- + " // AUTO-GENERATED DOCUMENTATION AND METHOD.\n"
- + " /**\n"
- + " * Sample code:\n"
- + " *\n"
- + " * @param parent\n"
- + " * @throws com.google.api.gax.rpc.ApiException if the remote call fails\n"
- + " */\n"
- + " public final EchoResponse echo(String parent) {\n"
- + " EchoRequest request = EchoRequest.newBuilder().setParent(parent).build();\n"
- + " return echo(request);\n"
- + " }\n"
- + "\n"
- + " // AUTO-GENERATED DOCUMENTATION AND METHOD.\n"
- + " /**\n"
- + " * Sample code:\n"
- + " *\n"
- + " * @param content\n"
- + " * @param severity\n"
- + " * @throws com.google.api.gax.rpc.ApiException if the remote call fails\n"
- + " */\n"
- + " public final EchoResponse echo(String content, Severity severity) {\n"
- + " EchoRequest request =\n"
- + " EchoRequest.newBuilder().setContent(content).setSeverity(severity).build();\n"
- + " return echo(request);\n"
- + " }\n"
- + "\n"
- + " // AUTO-GENERATED DOCUMENTATION AND METHOD.\n"
- + " /**\n"
- + " * Sample code:\n"
- + " *\n"
- + " * @param request The request object containing all of the parameters for the API"
- + " call.\n"
- + " * @throws com.google.api.gax.rpc.ApiException if the remote call fails\n"
- + " */\n"
- + " public final EchoResponse echo(EchoRequest request) {\n"
- + " return echoCallable().call(request);\n"
- + " }\n"
- + "\n"
- + " // AUTO-GENERATED DOCUMENTATION AND METHOD.\n"
- + " /** Sample code: */\n"
- + " public final UnaryCallable echoCallable() {\n"
- + " return stub.echoCallable();\n"
- + " }\n"
- + "\n"
- + " // AUTO-GENERATED DOCUMENTATION AND METHOD.\n"
- + " /** Sample code: */\n"
- + " public final ServerStreamingCallable expandCallable()"
- + " {\n"
- + " return stub.expandCallable();\n"
- + " }\n"
- + "\n"
- + " // AUTO-GENERATED DOCUMENTATION AND METHOD.\n"
- + " /** Sample code: */\n"
- + " public final ClientStreamingCallable collectCallable()"
- + " {\n"
- + " return stub.collectCallable();\n"
- + " }\n"
- + "\n"
- + " // AUTO-GENERATED DOCUMENTATION AND METHOD.\n"
- + " /** Sample code: */\n"
- + " public final BidiStreamingCallable chatCallable() {\n"
- + " return stub.chatCallable();\n"
- + " }\n"
- + "\n"
- + " // AUTO-GENERATED DOCUMENTATION AND METHOD.\n"
- + " /** Sample code: */\n"
- + " public final BidiStreamingCallable chatAgainCallable()"
- + " {\n"
- + " return stub.chatAgainCallable();\n"
- + " }\n"
- + "\n"
- + " // AUTO-GENERATED DOCUMENTATION AND METHOD.\n"
- + " /**\n"
- + " * Sample code:\n"
- + " *\n"
- + " * @param request The request object containing all of the parameters for the API"
- + " call.\n"
- + " * @throws com.google.api.gax.rpc.ApiException if the remote call fails\n"
- + " */\n"
- + " public final PagedExpandPagedResponse pagedExpand(PagedExpandRequest request) {\n"
- + " return pagedExpandPagedCallable().call(request);\n"
- + " }\n"
- + "\n"
- + " // AUTO-GENERATED DOCUMENTATION AND METHOD.\n"
- + " /** Sample code: */\n"
- + " public final UnaryCallable\n"
- + " pagedExpandPagedCallable() {\n"
- + " return stub.pagedExpandPagedCallable();\n"
- + " }\n"
- + "\n"
- + " // AUTO-GENERATED DOCUMENTATION AND METHOD.\n"
- + " /** Sample code: */\n"
- + " public final UnaryCallable"
- + " pagedExpandCallable() {\n"
- + " return stub.pagedExpandCallable();\n"
- + " }\n"
- + "\n"
- + " // AUTO-GENERATED DOCUMENTATION AND METHOD.\n"
- + " /**\n"
- + " * Sample code:\n"
- + " *\n"
- + " * @param ttl\n"
- + " * @throws com.google.api.gax.rpc.ApiException if the remote call fails\n"
- + " */\n"
- + " public final OperationFuture waitAsync(Duration ttl)"
- + " {\n"
- + " WaitRequest request = WaitRequest.newBuilder().setTtl(ttl).build();\n"
- + " return waitAsync(request);\n"
- + " }\n"
- + "\n"
- + " // AUTO-GENERATED DOCUMENTATION AND METHOD.\n"
- + " /**\n"
- + " * Sample code:\n"
- + " *\n"
- + " * @param end_time\n"
- + " * @throws com.google.api.gax.rpc.ApiException if the remote call fails\n"
- + " */\n"
- + " public final OperationFuture waitAsync(Timestamp"
- + " endTime) {\n"
- + " WaitRequest request = WaitRequest.newBuilder().setEndTime(endTime).build();\n"
- + " return waitAsync(request);\n"
- + " }\n"
- + "\n"
- + " // AUTO-GENERATED DOCUMENTATION AND METHOD.\n"
- + " /**\n"
- + " * Sample code:\n"
- + " *\n"
- + " * @param request The request object containing all of the parameters for the API"
- + " call.\n"
- + " * @throws com.google.api.gax.rpc.ApiException if the remote call fails\n"
- + " */\n"
- + " public final OperationFuture waitAsync(WaitRequest"
- + " request) {\n"
- + " return waitOperationCallable().futureCall(request);\n"
- + " }\n"
- + "\n"
- + " // AUTO-GENERATED DOCUMENTATION AND METHOD.\n"
- + " /** Sample code: */\n"
- + " public final OperationCallable"
- + " waitOperationCallable() {\n"
- + " return stub.waitOperationCallable();\n"
- + " }\n"
- + "\n"
- + " // AUTO-GENERATED DOCUMENTATION AND METHOD.\n"
- + " /** Sample code: */\n"
- + " public final UnaryCallable waitCallable() {\n"
- + " return stub.waitCallable();\n"
- + " }\n"
- + "\n"
- + " // AUTO-GENERATED DOCUMENTATION AND METHOD.\n"
- + " /**\n"
- + " * Sample code:\n"
- + " *\n"
- + " * @param request The request object containing all of the parameters for the API"
- + " call.\n"
- + " * @throws com.google.api.gax.rpc.ApiException if the remote call fails\n"
- + " */\n"
- + " public final BlockResponse block(BlockRequest request) {\n"
- + " return blockCallable().call(request);\n"
- + " }\n"
- + "\n"
- + " // AUTO-GENERATED DOCUMENTATION AND METHOD.\n"
- + " /** Sample code: */\n"
- + " public final UnaryCallable blockCallable() {\n"
- + " return stub.blockCallable();\n"
- + " }\n"
- + "\n"
- + " @Override\n"
- + " public final void close() {\n"
- + " stub.close();\n"
- + " }\n"
- + "\n"
- + " @Override\n"
- + " public void shutdown() {\n"
- + " stub.shutdown();\n"
- + " }\n"
- + "\n"
- + " @Override\n"
- + " public boolean isShutdown() {\n"
- + " return stub.isShutdown();\n"
- + " }\n"
- + "\n"
- + " @Override\n"
- + " public boolean isTerminated() {\n"
- + " return stub.isTerminated();\n"
- + " }\n"
- + "\n"
- + " @Override\n"
- + " public void shutdownNow() {\n"
- + " stub.shutdownNow();\n"
- + " }\n"
- + "\n"
- + " @Override\n"
- + " public boolean awaitTermination(long duration, TimeUnit unit) throws"
- + " InterruptedException {\n"
- + " return stub.awaitTermination(duration, unit);\n"
- + " }\n"
- + "\n"
- + " public static class PagedExpandPagedResponse\n"
- + " extends AbstractPagedListResponse<\n"
- + " PagedExpandRequest,\n"
- + " PagedExpandResponse,\n"
- + " EchoResponse,\n"
- + " PagedExpandPage,\n"
- + " PagedExpandFixedSizeCollection> {\n"
- + "\n"
- + " public static ApiFuture createAsync(\n"
- + " PageContext context,\n"
- + " ApiFuture futureResponse) {\n"
- + " ApiFuture futurePage =\n"
- + " PagedExpandPage.createEmptyPage().createPageAsync(context,"
- + " futureResponse);\n"
- + " return ApiFutures.transform(\n"
- + " futurePage,\n"
- + " new ApiFunction() {\n"
- + " @Override\n"
- + " public PagedExpandPagedResponse apply(PagedExpandPage input) {\n"
- + " return new PagedExpandPagedResponse(input);\n"
- + " }\n"
- + " },\n"
- + " MoreExecutors.directExecutor());\n"
- + " }\n"
- + "\n"
- + " private PagedExpandPagedResponse(PagedExpandPage page) {\n"
- + " super(page, PagedExpandFixedSizeCollection.createEmptyCollection());\n"
- + " }\n"
- + " }\n"
- + "\n"
- + " public static class PagedExpandPage\n"
- + " extends AbstractPage {\n"
- + "\n"
- + " private PagedExpandPage(\n"
- + " PageContext context,\n"
- + " PagedExpandResponse response) {\n"
- + " super(context, response);\n"
- + " }\n"
- + "\n"
- + " private static PagedExpandPage createEmptyPage() {\n"
- + " return new PagedExpandPage(null, null);\n"
- + " }\n"
- + "\n"
- + " @Override\n"
- + " protected PagedExpandPage createPage(\n"
- + " PageContext context,\n"
- + " PagedExpandResponse response) {\n"
- + " return new PagedExpandPage(context, response);\n"
- + " }\n"
- + "\n"
- + " @Override\n"
- + " public ApiFuture createPageAsync(\n"
- + " PageContext context,\n"
- + " ApiFuture futureResponse) {\n"
- + " return super.createPageAsync(context, futureResponse);\n"
- + " }\n"
- + " }\n"
- + "\n"
- + " public static class PagedExpandFixedSizeCollection\n"
- + " extends AbstractFixedSizeCollection<\n"
- + " PagedExpandRequest,\n"
- + " PagedExpandResponse,\n"
- + " EchoResponse,\n"
- + " PagedExpandPage,\n"
- + " PagedExpandFixedSizeCollection> {\n"
- + "\n"
- + " private PagedExpandFixedSizeCollection(List pages, int"
- + " collectionSize) {\n"
- + " super(pages, collectionSize);\n"
- + " }\n"
- + "\n"
- + " private static PagedExpandFixedSizeCollection createEmptyCollection() {\n"
- + " return new PagedExpandFixedSizeCollection(null, 0);\n"
- + " }\n"
- + "\n"
- + " @Override\n"
- + " protected PagedExpandFixedSizeCollection createCollection(\n"
- + " List pages, int collectionSize) {\n"
- + " return new PagedExpandFixedSizeCollection(pages, collectionSize);\n"
- + " }\n"
- + " }\n"
- + "}\n";
}
diff --git a/src/test/java/com/google/api/generator/gapic/composer/ServiceClientTestClassComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/ServiceClientTestClassComposerTest.java
index 973ba9393c..29902de51d 100644
--- a/src/test/java/com/google/api/generator/gapic/composer/ServiceClientTestClassComposerTest.java
+++ b/src/test/java/com/google/api/generator/gapic/composer/ServiceClientTestClassComposerTest.java
@@ -14,6 +14,7 @@
package com.google.api.generator.gapic.composer;
+import static com.google.api.generator.test.framework.Assert.assertCodeEquals;
import static junit.framework.Assert.assertEquals;
import com.google.api.generator.engine.writer.JavaWriterVisitor;
@@ -22,9 +23,12 @@
import com.google.api.generator.gapic.model.ResourceName;
import com.google.api.generator.gapic.model.Service;
import com.google.api.generator.gapic.protoparser.Parser;
+import com.google.api.generator.test.framework.Utils;
import com.google.protobuf.Descriptors.FileDescriptor;
import com.google.protobuf.Descriptors.ServiceDescriptor;
import com.google.showcase.v1beta1.EchoOuterClass;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -58,693 +62,9 @@ public void generateServiceClasses() {
JavaWriterVisitor visitor = new JavaWriterVisitor();
clazz.classDefinition().accept(visitor);
- assertEquals(EXPECTED_CLASS_STRING, visitor.write());
+ Utils.saveCodegenToFile(this.getClass(), "EchoClientTest.golden", visitor.write());
+ Path goldenFilePath =
+ Paths.get(ComposerConstants.GOLDENFILES_DIRECTORY, "EchoClientTest.golden");
+ assertCodeEquals(goldenFilePath, visitor.write());
}
-
- // TODO(miraleung): Update this when a file-diffing test mechanism is in place.
- private static final String EXPECTED_CLASS_STRING =
- "package com.google.showcase.v1beta1;\n"
- + "\n"
- + "import com.google.api.gax.core.NoCredentialsProvider;\n"
- + "import com.google.api.gax.grpc.GaxGrpcProperties;\n"
- + "import com.google.api.gax.grpc.testing.LocalChannelProvider;\n"
- + "import com.google.api.gax.grpc.testing.MockGrpcService;\n"
- + "import com.google.api.gax.grpc.testing.MockServiceHelper;\n"
- + "import com.google.api.gax.grpc.testing.MockStreamObserver;\n"
- + "import com.google.api.gax.rpc.ApiClientHeaderProvider;\n"
- + "import com.google.api.gax.rpc.ApiStreamObserver;\n"
- + "import com.google.api.gax.rpc.BidiStreamingCallable;\n"
- + "import com.google.api.gax.rpc.ClientStreamingCallable;\n"
- + "import com.google.api.gax.rpc.InvalidArgumentException;\n"
- + "import com.google.api.gax.rpc.ServerStreamingCallable;\n"
- + "import com.google.api.gax.rpc.StatusCode;\n"
- + "import com.google.api.resourcenames.ResourceName;\n"
- + "import com.google.common.collect.Lists;\n"
- + "import com.google.longrunning.Operation;\n"
- + "import com.google.protobuf.AbstractMessage;\n"
- + "import com.google.protobuf.Any;\n"
- + "import com.google.protobuf.Duration;\n"
- + "import com.google.protobuf.Timestamp;\n"
- + "import com.google.rpc.Status;\n"
- + "import io.grpc.StatusRuntimeException;\n"
- + "import java.io.IOException;\n"
- + "import java.util.Arrays;\n"
- + "import java.util.List;\n"
- + "import java.util.UUID;\n"
- + "import java.util.concurrent.ExecutionException;\n"
- + "import javax.annotation.Generated;\n"
- + "import org.junit.After;\n"
- + "import org.junit.AfterClass;\n"
- + "import org.junit.Assert;\n"
- + "import org.junit.Before;\n"
- + "import org.junit.BeforeClass;\n"
- + "import org.junit.Test;\n"
- + "\n"
- + "@Generated(\"by gapic-generator-java\")\n"
- + "public class EchoClientTest {\n"
- + " public static MockServiceHelper mockServiceHelper;\n"
- + " public static MockEcho mockEcho;\n"
- + " public EchoClient client;\n"
- + " public LocalChannelProvider channelProvider;\n"
- + "\n"
- + " @BeforeClass\n"
- + " public static void startStaticServer() {\n"
- + " mockEcho = new MockEcho();\n"
- + " mockServiceHelper =\n"
- + " new MockServiceHelper(\n"
- + " UUID.randomUUID().toString(),"
- + " Arrays.asList(mockEcho));\n"
- + " mockServiceHelper.start();\n"
- + " }\n"
- + "\n"
- + " @AfterClass\n"
- + " public static void stopServer() {\n"
- + " mockServiceHelper.stop();\n"
- + " }\n"
- + "\n"
- + " @Before\n"
- + " public void setUp() throws IOException {\n"
- + " mockServiceHelper.reset();\n"
- + " channelProvider = mockServiceHelper.createChannelProvider();\n"
- + " EchoSettings settings =\n"
- + " EchoSettings.newBuilder()\n"
- + " .setTransportChannelProvider(channelProvider)\n"
- + " .setCredentialsProvider(NoCredentialsProvider.create())\n"
- + " .build();\n"
- + " client = EchoClient.create(settings);\n"
- + " }\n"
- + "\n"
- + " @After\n"
- + " public void tearDown() throws Exception {\n"
- + " client.close();\n"
- + " }\n"
- + "\n"
- + " @Test\n"
- + " public void echoTest() {\n"
- + " EchoResponse expectedResponse =\n"
- + " EchoResponse.newBuilder().setContent(\"content951530617\").build();\n"
- + " mockEcho.addResponse(expectedResponse);\n"
- + " ResourceName parent = FoobarName.ofProjectFoobarName(\"[PROJECT]\","
- + " \"[FOOBAR]\");\n"
- + " EchoResponse actualResponse = client.echo(parent);\n"
- + " Assert.assertEquals(expectedResponse, actualResponse);\n"
- + " List actualRequests = mockEcho.getRequests();\n"
- + " Assert.assertEquals(1, actualRequests.size());\n"
- + " EchoRequest actualRequest = ((EchoRequest) actualRequests.get(0));\n"
- + " Assert.assertEquals(parent.toString(), actualRequest.getParent());\n"
- + " Assert.assertTrue(\n"
- + " channelProvider.isHeaderSent(\n"
- + " ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),\n"
- + " GaxGrpcProperties.getDefaultApiClientHeaderPattern()));\n"
- + " }\n"
- + "\n"
- + " @Test\n"
- + " public void echoExceptionTest() throws Exception {\n"
- + " StatusRuntimeException exception = new"
- + " StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);\n"
- + " mockEcho.addException(exception);\n"
- + " try {\n"
- + " ResourceName parent = FoobarName.ofProjectFoobarName(\"[PROJECT]\","
- + " \"[FOOBAR]\");\n"
- + " client.echo(parent);\n"
- + " Assert.fail(\"No exception raised\");\n"
- + " } catch (InvalidArgumentException e) {\n"
- + " // Expected exception.\n"
- + " }\n"
- + " }\n"
- + "\n"
- + " @Test\n"
- + " public void echoTest2() {\n"
- + " EchoResponse expectedResponse =\n"
- + " EchoResponse.newBuilder().setContent(\"content951530617\").build();\n"
- + " mockEcho.addResponse(expectedResponse);\n"
- + " Status error = Status.newBuilder().build();\n"
- + " EchoResponse actualResponse = client.echo(error);\n"
- + " Assert.assertEquals(expectedResponse, actualResponse);\n"
- + " List actualRequests = mockEcho.getRequests();\n"
- + " Assert.assertEquals(1, actualRequests.size());\n"
- + " EchoRequest actualRequest = ((EchoRequest) actualRequests.get(0));\n"
- + " Assert.assertEquals(error, actualRequest.getError());\n"
- + " Assert.assertTrue(\n"
- + " channelProvider.isHeaderSent(\n"
- + " ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),\n"
- + " GaxGrpcProperties.getDefaultApiClientHeaderPattern()));\n"
- + " }\n"
- + "\n"
- + " @Test\n"
- + " public void echoExceptionTest2() throws Exception {\n"
- + " StatusRuntimeException exception = new"
- + " StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);\n"
- + " mockEcho.addException(exception);\n"
- + " try {\n"
- + " Status error = Status.newBuilder().build();\n"
- + " client.echo(error);\n"
- + " Assert.fail(\"No exception raised\");\n"
- + " } catch (InvalidArgumentException e) {\n"
- + " // Expected exception.\n"
- + " }\n"
- + " }\n"
- + "\n"
- + " @Test\n"
- + " public void echoTest3() {\n"
- + " EchoResponse expectedResponse =\n"
- + " EchoResponse.newBuilder().setContent(\"content951530617\").build();\n"
- + " mockEcho.addResponse(expectedResponse);\n"
- + " FoobarName name = FoobarName.ofProjectFoobarName(\"[PROJECT]\", \"[FOOBAR]\");\n"
- + " EchoResponse actualResponse = client.echo(name);\n"
- + " Assert.assertEquals(expectedResponse, actualResponse);\n"
- + " List actualRequests = mockEcho.getRequests();\n"
- + " Assert.assertEquals(1, actualRequests.size());\n"
- + " EchoRequest actualRequest = ((EchoRequest) actualRequests.get(0));\n"
- + " Assert.assertEquals(name.toString(), actualRequest.getName());\n"
- + " Assert.assertTrue(\n"
- + " channelProvider.isHeaderSent(\n"
- + " ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),\n"
- + " GaxGrpcProperties.getDefaultApiClientHeaderPattern()));\n"
- + " }\n"
- + "\n"
- + " @Test\n"
- + " public void echoExceptionTest3() throws Exception {\n"
- + " StatusRuntimeException exception = new"
- + " StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);\n"
- + " mockEcho.addException(exception);\n"
- + " try {\n"
- + " FoobarName name = FoobarName.ofProjectFoobarName(\"[PROJECT]\","
- + " \"[FOOBAR]\");\n"
- + " client.echo(name);\n"
- + " Assert.fail(\"No exception raised\");\n"
- + " } catch (InvalidArgumentException e) {\n"
- + " // Expected exception.\n"
- + " }\n"
- + " }\n"
- + "\n"
- + " @Test\n"
- + " public void echoTest4() {\n"
- + " EchoResponse expectedResponse =\n"
- + " EchoResponse.newBuilder().setContent(\"content951530617\").build();\n"
- + " mockEcho.addResponse(expectedResponse);\n"
- + " String content = \"content951530617\";\n"
- + " EchoResponse actualResponse = client.echo(content);\n"
- + " Assert.assertEquals(expectedResponse, actualResponse);\n"
- + " List actualRequests = mockEcho.getRequests();\n"
- + " Assert.assertEquals(1, actualRequests.size());\n"
- + " EchoRequest actualRequest = ((EchoRequest) actualRequests.get(0));\n"
- + " Assert.assertEquals(content, actualRequest.getContent());\n"
- + " Assert.assertTrue(\n"
- + " channelProvider.isHeaderSent(\n"
- + " ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),\n"
- + " GaxGrpcProperties.getDefaultApiClientHeaderPattern()));\n"
- + " }\n"
- + "\n"
- + " @Test\n"
- + " public void echoExceptionTest4() throws Exception {\n"
- + " StatusRuntimeException exception = new"
- + " StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);\n"
- + " mockEcho.addException(exception);\n"
- + " try {\n"
- + " String content = \"content951530617\";\n"
- + " client.echo(content);\n"
- + " Assert.fail(\"No exception raised\");\n"
- + " } catch (InvalidArgumentException e) {\n"
- + " // Expected exception.\n"
- + " }\n"
- + " }\n"
- + "\n"
- + " @Test\n"
- + " public void echoTest5() {\n"
- + " EchoResponse expectedResponse =\n"
- + " EchoResponse.newBuilder().setContent(\"content951530617\").build();\n"
- + " mockEcho.addResponse(expectedResponse);\n"
- + " String name = \"name3373707\";\n"
- + " EchoResponse actualResponse = client.echo(name);\n"
- + " Assert.assertEquals(expectedResponse, actualResponse);\n"
- + " List actualRequests = mockEcho.getRequests();\n"
- + " Assert.assertEquals(1, actualRequests.size());\n"
- + " EchoRequest actualRequest = ((EchoRequest) actualRequests.get(0));\n"
- + " Assert.assertEquals(name, actualRequest.getName());\n"
- + " Assert.assertTrue(\n"
- + " channelProvider.isHeaderSent(\n"
- + " ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),\n"
- + " GaxGrpcProperties.getDefaultApiClientHeaderPattern()));\n"
- + " }\n"
- + "\n"
- + " @Test\n"
- + " public void echoExceptionTest5() throws Exception {\n"
- + " StatusRuntimeException exception = new"
- + " StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);\n"
- + " mockEcho.addException(exception);\n"
- + " try {\n"
- + " String name = \"name3373707\";\n"
- + " client.echo(name);\n"
- + " Assert.fail(\"No exception raised\");\n"
- + " } catch (InvalidArgumentException e) {\n"
- + " // Expected exception.\n"
- + " }\n"
- + " }\n"
- + "\n"
- + " @Test\n"
- + " public void echoTest6() {\n"
- + " EchoResponse expectedResponse =\n"
- + " EchoResponse.newBuilder().setContent(\"content951530617\").build();\n"
- + " mockEcho.addResponse(expectedResponse);\n"
- + " String parent = \"parent-995424086\";\n"
- + " EchoResponse actualResponse = client.echo(parent);\n"
- + " Assert.assertEquals(expectedResponse, actualResponse);\n"
- + " List actualRequests = mockEcho.getRequests();\n"
- + " Assert.assertEquals(1, actualRequests.size());\n"
- + " EchoRequest actualRequest = ((EchoRequest) actualRequests.get(0));\n"
- + " Assert.assertEquals(parent, actualRequest.getParent());\n"
- + " Assert.assertTrue(\n"
- + " channelProvider.isHeaderSent(\n"
- + " ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),\n"
- + " GaxGrpcProperties.getDefaultApiClientHeaderPattern()));\n"
- + " }\n"
- + "\n"
- + " @Test\n"
- + " public void echoExceptionTest6() throws Exception {\n"
- + " StatusRuntimeException exception = new"
- + " StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);\n"
- + " mockEcho.addException(exception);\n"
- + " try {\n"
- + " String parent = \"parent-995424086\";\n"
- + " client.echo(parent);\n"
- + " Assert.fail(\"No exception raised\");\n"
- + " } catch (InvalidArgumentException e) {\n"
- + " // Expected exception.\n"
- + " }\n"
- + " }\n"
- + "\n"
- + " @Test\n"
- + " public void echoTest7() {\n"
- + " EchoResponse expectedResponse =\n"
- + " EchoResponse.newBuilder().setContent(\"content951530617\").build();\n"
- + " mockEcho.addResponse(expectedResponse);\n"
- + " String content = \"content951530617\";\n"
- + " Severity severity = Severity.forNumber(0);\n"
- + " EchoResponse actualResponse = client.echo(content, severity);\n"
- + " Assert.assertEquals(expectedResponse, actualResponse);\n"
- + " List actualRequests = mockEcho.getRequests();\n"
- + " Assert.assertEquals(1, actualRequests.size());\n"
- + " EchoRequest actualRequest = ((EchoRequest) actualRequests.get(0));\n"
- + " Assert.assertEquals(content, actualRequest.getContent());\n"
- + " Assert.assertEquals(severity, actualRequest.getSeverity());\n"
- + " Assert.assertTrue(\n"
- + " channelProvider.isHeaderSent(\n"
- + " ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),\n"
- + " GaxGrpcProperties.getDefaultApiClientHeaderPattern()));\n"
- + " }\n"
- + "\n"
- + " @Test\n"
- + " public void echoExceptionTest7() throws Exception {\n"
- + " StatusRuntimeException exception = new"
- + " StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);\n"
- + " mockEcho.addException(exception);\n"
- + " try {\n"
- + " String content = \"content951530617\";\n"
- + " Severity severity = Severity.forNumber(0);\n"
- + " client.echo(content, severity);\n"
- + " Assert.fail(\"No exception raised\");\n"
- + " } catch (InvalidArgumentException e) {\n"
- + " // Expected exception.\n"
- + " }\n"
- + " }\n"
- + "\n"
- + " @Test\n"
- + " public void expandTest() {\n"
- + " EchoResponse expectedResponse =\n"
- + " EchoResponse.newBuilder().setContent(\"content951530617\").build();\n"
- + " mockEcho.addResponse(expectedResponse);\n"
- + " ExpandRequest request =\n"
- + " "
- + " ExpandRequest.newBuilder().setContent(\"content951530617\").setInfo(\"info3237038\").build();\n"
- + " MockStreamObserver responseObserver = new MockStreamObserver<>();\n"
- + " ServerStreamingCallable callable ="
- + " client.expandCallable();\n"
- + " callable.serverStreamingCall(request, responseObserver);\n"
- + " List actualResponses = responseObserver.future().get();\n"
- + " Assert.assertEquals(1, actualResponses.size());\n"
- + " Assert.assertEquals(expectedResponse, actualResponses.get(0));\n"
- + " }\n"
- + "\n"
- + " @Test\n"
- + " public void expandExceptionTest() throws Exception {\n"
- + " StatusRuntimeException exception = new"
- + " StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);\n"
- + " mockEcho.addException(exception);\n"
- + " ExpandRequest request =\n"
- + " "
- + " ExpandRequest.newBuilder().setContent(\"content951530617\").setInfo(\"info3237038\").build();\n"
- + " MockStreamObserver responseObserver = new MockStreamObserver<>();\n"
- + " client.expandCallable();\n"
- + " try {\n"
- + " List actualResponses = responseObserver.future().get();\n"
- + " Assert.fail(\"No exception thrown\");\n"
- + " } catch (ExecutionException e) {\n"
- + " Assert.assertTrue(e.getCause() instanceof InvalidArgumentException);\n"
- + " InvalidArgumentException apiException = ((InvalidArgumentException)"
- + " e.getCause());\n"
- + " Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT,"
- + " apiException.getStatusCode().getCode());\n"
- + " }\n"
- + " }\n"
- + "\n"
- + " @Test\n"
- + " public void collectTest() {\n"
- + " EchoResponse expectedResponse =\n"
- + " EchoResponse.newBuilder().setContent(\"content951530617\").build();\n"
- + " mockEcho.addResponse(expectedResponse);\n"
- + " EchoRequest request =\n"
- + " EchoRequest.newBuilder()\n"
- + " .setName(FoobarName.ofProjectFoobarName(\"[PROJECT]\","
- + " \"[FOOBAR]\").toString())\n"
- + " .setParent(FoobarName.ofProjectFoobarName(\"[PROJECT]\","
- + " \"[FOOBAR]\").toString())\n"
- + " .setFoobar(Foobar.newBuilder().build())\n"
- + " .build();\n"
- + " MockStreamObserver responseObserver = new MockStreamObserver<>();\n"
- + " ClientStreamingCallable callable ="
- + " client.collectCallable();\n"
- + " ApiStreamObserver requestObserver =\n"
- + " callable.clientStreamingCall(request, responseObserver);\n"
- + " requestObserver.onNext(request);\n"
- + " requestObserver.onCompleted();\n"
- + " List actualResponses = responseObserver.future().get();\n"
- + " Assert.assertEquals(1, actualResponses.size());\n"
- + " Assert.assertEquals(expectedResponse, actualResponses.get(0));\n"
- + " }\n"
- + "\n"
- + " @Test\n"
- + " public void collectExceptionTest() throws Exception {\n"
- + " StatusRuntimeException exception = new"
- + " StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);\n"
- + " mockEcho.addException(exception);\n"
- + " EchoRequest request =\n"
- + " EchoRequest.newBuilder()\n"
- + " .setName(FoobarName.ofProjectFoobarName(\"[PROJECT]\","
- + " \"[FOOBAR]\").toString())\n"
- + " .setParent(FoobarName.ofProjectFoobarName(\"[PROJECT]\","
- + " \"[FOOBAR]\").toString())\n"
- + " .setFoobar(Foobar.newBuilder().build())\n"
- + " .build();\n"
- + " MockStreamObserver responseObserver = new MockStreamObserver<>();\n"
- + " ClientStreamingCallable callable ="
- + " client.collectCallable();\n"
- + " ApiStreamObserver requestObserver =\n"
- + " callable.clientStreamingCall(request, responseObserver);\n"
- + " requestObserver.onNext(request);\n"
- + " try {\n"
- + " List actualResponses = responseObserver.future().get();\n"
- + " Assert.fail(\"No exception thrown\");\n"
- + " } catch (ExecutionException e) {\n"
- + " Assert.assertTrue(e.getCause() instanceof InvalidArgumentException);\n"
- + " InvalidArgumentException apiException = ((InvalidArgumentException)"
- + " e.getCause());\n"
- + " Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT,"
- + " apiException.getStatusCode().getCode());\n"
- + " }\n"
- + " }\n"
- + "\n"
- + " @Test\n"
- + " public void chatTest() {\n"
- + " EchoResponse expectedResponse =\n"
- + " EchoResponse.newBuilder().setContent(\"content951530617\").build();\n"
- + " mockEcho.addResponse(expectedResponse);\n"
- + " EchoRequest request =\n"
- + " EchoRequest.newBuilder()\n"
- + " .setName(FoobarName.ofProjectFoobarName(\"[PROJECT]\","
- + " \"[FOOBAR]\").toString())\n"
- + " .setParent(FoobarName.ofProjectFoobarName(\"[PROJECT]\","
- + " \"[FOOBAR]\").toString())\n"
- + " .setFoobar(Foobar.newBuilder().build())\n"
- + " .build();\n"
- + " MockStreamObserver responseObserver = new MockStreamObserver<>();\n"
- + " BidiStreamingCallable callable ="
- + " client.chatCallable();\n"
- + " ApiStreamObserver requestObserver =\n"
- + " callable.bidiStreamingCall(request, responseObserver);\n"
- + " requestObserver.onNext(request);\n"
- + " requestObserver.onCompleted();\n"
- + " List actualResponses = responseObserver.future().get();\n"
- + " Assert.assertEquals(1, actualResponses.size());\n"
- + " Assert.assertEquals(expectedResponse, actualResponses.get(0));\n"
- + " }\n"
- + "\n"
- + " @Test\n"
- + " public void chatExceptionTest() throws Exception {\n"
- + " StatusRuntimeException exception = new"
- + " StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);\n"
- + " mockEcho.addException(exception);\n"
- + " EchoRequest request =\n"
- + " EchoRequest.newBuilder()\n"
- + " .setName(FoobarName.ofProjectFoobarName(\"[PROJECT]\","
- + " \"[FOOBAR]\").toString())\n"
- + " .setParent(FoobarName.ofProjectFoobarName(\"[PROJECT]\","
- + " \"[FOOBAR]\").toString())\n"
- + " .setFoobar(Foobar.newBuilder().build())\n"
- + " .build();\n"
- + " MockStreamObserver responseObserver = new MockStreamObserver<>();\n"
- + " BidiStreamingCallable callable ="
- + " client.chatCallable();\n"
- + " ApiStreamObserver requestObserver =\n"
- + " callable.bidiStreamingCall(request, responseObserver);\n"
- + " requestObserver.onNext(request);\n"
- + " try {\n"
- + " List actualResponses = responseObserver.future().get();\n"
- + " Assert.fail(\"No exception thrown\");\n"
- + " } catch (ExecutionException e) {\n"
- + " Assert.assertTrue(e.getCause() instanceof InvalidArgumentException);\n"
- + " InvalidArgumentException apiException = ((InvalidArgumentException)"
- + " e.getCause());\n"
- + " Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT,"
- + " apiException.getStatusCode().getCode());\n"
- + " }\n"
- + " }\n"
- + "\n"
- + " @Test\n"
- + " public void chatAgainTest() {\n"
- + " EchoResponse expectedResponse =\n"
- + " EchoResponse.newBuilder().setContent(\"content951530617\").build();\n"
- + " mockEcho.addResponse(expectedResponse);\n"
- + " EchoRequest request =\n"
- + " EchoRequest.newBuilder()\n"
- + " .setName(FoobarName.ofProjectFoobarName(\"[PROJECT]\","
- + " \"[FOOBAR]\").toString())\n"
- + " .setParent(FoobarName.ofProjectFoobarName(\"[PROJECT]\","
- + " \"[FOOBAR]\").toString())\n"
- + " .setFoobar(Foobar.newBuilder().build())\n"
- + " .build();\n"
- + " MockStreamObserver responseObserver = new MockStreamObserver<>();\n"
- + " BidiStreamingCallable callable ="
- + " client.chatAgainCallable();\n"
- + " ApiStreamObserver requestObserver =\n"
- + " callable.bidiStreamingCall(request, responseObserver);\n"
- + " requestObserver.onNext(request);\n"
- + " requestObserver.onCompleted();\n"
- + " List actualResponses = responseObserver.future().get();\n"
- + " Assert.assertEquals(1, actualResponses.size());\n"
- + " Assert.assertEquals(expectedResponse, actualResponses.get(0));\n"
- + " }\n"
- + "\n"
- + " @Test\n"
- + " public void chatAgainExceptionTest() throws Exception {\n"
- + " StatusRuntimeException exception = new"
- + " StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);\n"
- + " mockEcho.addException(exception);\n"
- + " EchoRequest request =\n"
- + " EchoRequest.newBuilder()\n"
- + " .setName(FoobarName.ofProjectFoobarName(\"[PROJECT]\","
- + " \"[FOOBAR]\").toString())\n"
- + " .setParent(FoobarName.ofProjectFoobarName(\"[PROJECT]\","
- + " \"[FOOBAR]\").toString())\n"
- + " .setFoobar(Foobar.newBuilder().build())\n"
- + " .build();\n"
- + " MockStreamObserver responseObserver = new MockStreamObserver<>();\n"
- + " BidiStreamingCallable callable ="
- + " client.chatAgainCallable();\n"
- + " ApiStreamObserver requestObserver =\n"
- + " callable.bidiStreamingCall(request, responseObserver);\n"
- + " requestObserver.onNext(request);\n"
- + " try {\n"
- + " List actualResponses = responseObserver.future().get();\n"
- + " Assert.fail(\"No exception thrown\");\n"
- + " } catch (ExecutionException e) {\n"
- + " Assert.assertTrue(e.getCause() instanceof InvalidArgumentException);\n"
- + " InvalidArgumentException apiException = ((InvalidArgumentException)"
- + " e.getCause());\n"
- + " Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT,"
- + " apiException.getStatusCode().getCode());\n"
- + " }\n"
- + " }\n"
- + "\n"
- + " @Test\n"
- + " public void pagedExpandTest() {\n"
- + " EchoResponse responsesElement = EchoResponse.newBuilder().build();\n"
- + " PagedExpandResponse expectedResponse =\n"
- + " PagedExpandResponse.newBuilder()\n"
- + " .setNextPageToken(\"\")\n"
- + " .addAllResponses(Arrays.asList(responsesElement))\n"
- + " .build();\n"
- + " mockEcho.addResponse(expectedResponse);\n"
- + " PagedExpandRequest request =\n"
- + " PagedExpandRequest.newBuilder()\n"
- + " .setContent(\"content951530617\")\n"
- + " .setPageSize(883849137)\n"
- + " .setPageToken(\"page_token1630607433\")\n"
- + " .build();\n"
- + " PagedExpandResponse pagedListResponse = client.pagedExpand(request);\n"
- + " resources = Lists.newArrayList(pagedListResponse.iterateAll());\n"
- + " Assert.assertEquals(1, resources.size());\n"
- + " Assert.assertEquals(expectedResponse.getResponsesList().get(0),"
- + " resources.get(0));\n"
- + " List actualRequests = mockEcho.getRequests();\n"
- + " Assert.assertEquals(1, actualRequests.size());\n"
- + " PagedExpandRequest actualRequest = ((PagedExpandRequest)"
- + " actualRequests.get(0));\n"
- + " Assert.assertEquals(request.getContent(), actualRequest.getContent());\n"
- + " Assert.assertEquals(request.getPageSize(), actualRequest.getPageSize());\n"
- + " Assert.assertEquals(request.getPageToken(), actualRequest.getPageToken());\n"
- + " Assert.assertTrue(\n"
- + " channelProvider.isHeaderSent(\n"
- + " ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),\n"
- + " GaxGrpcProperties.getDefaultApiClientHeaderPattern()));\n"
- + " }\n"
- + "\n"
- + " @Test\n"
- + " public void pagedExpandExceptionTest() throws Exception {\n"
- + " StatusRuntimeException exception = new"
- + " StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);\n"
- + " mockEcho.addException(exception);\n"
- + " try {\n"
- + " PagedExpandRequest request =\n"
- + " PagedExpandRequest.newBuilder()\n"
- + " .setContent(\"content951530617\")\n"
- + " .setPageSize(883849137)\n"
- + " .setPageToken(\"page_token1630607433\")\n"
- + " .build();\n"
- + " client.pagedExpand(request);\n"
- + " Assert.fail(\"No exception raised\");\n"
- + " } catch (InvalidArgumentException e) {\n"
- + " // Expected exception.\n"
- + " }\n"
- + " }\n"
- + "\n"
- + " @Test\n"
- + " public void waitTest() {\n"
- + " WaitResponse expectedResponse =\n"
- + " WaitResponse.newBuilder().setContent(\"content951530617\").build();\n"
- + " Operation resultOperation =\n"
- + " Operation.newBuilder()\n"
- + " .setName(\"waitTest\")\n"
- + " .setDone(true)\n"
- + " .setResponse(Any.pack(expectedResponse))\n"
- + " .build();\n"
- + " mockEcho.addResponse(resultOperation);\n"
- + " Duration ttl = Duration.newBuilder().build();\n"
- + " WaitResponse actualResponse = client.waitAsync(ttl).get();\n"
- + " Assert.assertEquals(expectedResponse, actualResponse);\n"
- + " List actualRequests = mockEcho.getRequests();\n"
- + " Assert.assertEquals(1, actualRequests.size());\n"
- + " WaitRequest actualRequest = ((WaitRequest) actualRequests.get(0));\n"
- + " Assert.assertEquals(ttl, actualRequest.getTtl());\n"
- + " Assert.assertTrue(\n"
- + " channelProvider.isHeaderSent(\n"
- + " ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),\n"
- + " GaxGrpcProperties.getDefaultApiClientHeaderPattern()));\n"
- + " }\n"
- + "\n"
- + " @Test\n"
- + " public void waitExceptionTest() throws Exception {\n"
- + " StatusRuntimeException exception = new"
- + " StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);\n"
- + " mockEcho.addException(exception);\n"
- + " try {\n"
- + " Duration ttl = Duration.newBuilder().build();\n"
- + " client.waitAsync(ttl).get();\n"
- + " Assert.fail(\"No exception raised\");\n"
- + " } catch (ExecutionException e) {\n"
- + " Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass());\n"
- + " InvalidArgumentException apiException = ((InvalidArgumentException)"
- + " e.getCause());\n"
- + " Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT,"
- + " apiException.getStatusCode().getCode());\n"
- + " }\n"
- + " }\n"
- + "\n"
- + " @Test\n"
- + " public void waitTest2() {\n"
- + " WaitResponse expectedResponse =\n"
- + " WaitResponse.newBuilder().setContent(\"content951530617\").build();\n"
- + " Operation resultOperation =\n"
- + " Operation.newBuilder()\n"
- + " .setName(\"waitTest\")\n"
- + " .setDone(true)\n"
- + " .setResponse(Any.pack(expectedResponse))\n"
- + " .build();\n"
- + " mockEcho.addResponse(resultOperation);\n"
- + " Timestamp endTime = Timestamp.newBuilder().build();\n"
- + " WaitResponse actualResponse = client.waitAsync(endTime).get();\n"
- + " Assert.assertEquals(expectedResponse, actualResponse);\n"
- + " List actualRequests = mockEcho.getRequests();\n"
- + " Assert.assertEquals(1, actualRequests.size());\n"
- + " WaitRequest actualRequest = ((WaitRequest) actualRequests.get(0));\n"
- + " Assert.assertEquals(endTime, actualRequest.getEndTime());\n"
- + " Assert.assertTrue(\n"
- + " channelProvider.isHeaderSent(\n"
- + " ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),\n"
- + " GaxGrpcProperties.getDefaultApiClientHeaderPattern()));\n"
- + " }\n"
- + "\n"
- + " @Test\n"
- + " public void waitExceptionTest2() throws Exception {\n"
- + " StatusRuntimeException exception = new"
- + " StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);\n"
- + " mockEcho.addException(exception);\n"
- + " try {\n"
- + " Timestamp endTime = Timestamp.newBuilder().build();\n"
- + " client.waitAsync(endTime).get();\n"
- + " Assert.fail(\"No exception raised\");\n"
- + " } catch (ExecutionException e) {\n"
- + " Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass());\n"
- + " InvalidArgumentException apiException = ((InvalidArgumentException)"
- + " e.getCause());\n"
- + " Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT,"
- + " apiException.getStatusCode().getCode());\n"
- + " }\n"
- + " }\n"
- + "\n"
- + " @Test\n"
- + " public void blockTest() {\n"
- + " BlockResponse expectedResponse =\n"
- + " BlockResponse.newBuilder().setContent(\"content951530617\").build();\n"
- + " mockEcho.addResponse(expectedResponse);\n"
- + " BlockRequest request = BlockRequest.newBuilder().build();\n"
- + " BlockResponse actualResponse = client.block(request);\n"
- + " Assert.assertEquals(expectedResponse, actualResponse);\n"
- + " List actualRequests = mockEcho.getRequests();\n"
- + " Assert.assertEquals(1, actualRequests.size());\n"
- + " BlockRequest actualRequest = ((BlockRequest) actualRequests.get(0));\n"
- + " Assert.assertEquals(request.getResponseDelay(),"
- + " actualRequest.getResponseDelay());\n"
- + " Assert.assertEquals(request.getError(), actualRequest.getError());\n"
- + " Assert.assertEquals(request.getSuccess(), actualRequest.getSuccess());\n"
- + " Assert.assertTrue(\n"
- + " channelProvider.isHeaderSent(\n"
- + " ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),\n"
- + " GaxGrpcProperties.getDefaultApiClientHeaderPattern()));\n"
- + " }\n"
- + "\n"
- + " @Test\n"
- + " public void blockExceptionTest() throws Exception {\n"
- + " StatusRuntimeException exception = new"
- + " StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);\n"
- + " mockEcho.addException(exception);\n"
- + " try {\n"
- + " BlockRequest request = BlockRequest.newBuilder().build();\n"
- + " client.block(request);\n"
- + " Assert.fail(\"No exception raised\");\n"
- + " } catch (InvalidArgumentException e) {\n"
- + " // Expected exception.\n"
- + " }\n"
- + " }\n"
- + "}\n";
}
diff --git a/src/test/java/com/google/api/generator/gapic/composer/goldens/EchoClient.golden b/src/test/java/com/google/api/generator/gapic/composer/goldens/EchoClient.golden
new file mode 100644
index 0000000000..20a193853e
--- /dev/null
+++ b/src/test/java/com/google/api/generator/gapic/composer/goldens/EchoClient.golden
@@ -0,0 +1,459 @@
+package com.google.showcase.v1beta1;
+
+import com.google.api.core.ApiFunction;
+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.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.api.resourcenames.ResourceName;
+import com.google.common.util.concurrent.MoreExecutors;
+import com.google.longrunning.Operation;
+import com.google.longrunning.OperationsClient;
+import com.google.protobuf.Duration;
+import com.google.protobuf.Timestamp;
+import com.google.rpc.Status;
+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.Objects;
+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:
+ *
+ * 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:
+ *
+ *
+ * - 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.
+ *
- 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.
+ *
- 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:
+ *
+ *
To customize the endpoint:
+ */
+@BetaApi
+@Generated("by gapic-generator")
+public class EchoClient implements BackgroundResource {
+ private final EchoSettings settings;
+ private final EchoStub stub;
+ private final 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).
+ */
+ @BetaApi("A restructuring of stub classes is planned, so this may break in the future")
+ 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 = OperationsClient.create(this.stub.getOperationsStub());
+ }
+
+ @BetaApi("A restructuring of stub classes is planned, so this may break in the future")
+ protected EchoClient(EchoStub stub) {
+ this.settings = null;
+ this.stub = stub;
+ this.operationsClient = OperationsClient.create(this.stub.getOperationsStub());
+ }
+
+ public final EchoSettings getSettings() {
+ return settings;
+ }
+
+ @BetaApi("A restructuring of stub classes is planned, so this may break in the future")
+ 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 OperationsClient getOperationsClient() {
+ return operationsClient;
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Sample code:
+ *
+ * @param parent
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final EchoResponse echo(ResourceName parent) {
+ EchoRequest request =
+ EchoRequest.newBuilder()
+ .setParent(Objects.isNull(parent) ? null : parent.toString())
+ .build();
+ return echo(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Sample code:
+ *
+ * @param error
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final EchoResponse echo(Status error) {
+ EchoRequest request = EchoRequest.newBuilder().setError(error).build();
+ return echo(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Sample code:
+ *
+ * @param name
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final EchoResponse echo(FoobarName name) {
+ EchoRequest request =
+ EchoRequest.newBuilder().setName(Objects.isNull(name) ? null : name.toString()).build();
+ return echo(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Sample code:
+ *
+ * @param content
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final EchoResponse echo(String content) {
+ EchoRequest request = EchoRequest.newBuilder().setContent(content).build();
+ return echo(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Sample code:
+ *
+ * @param name
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final EchoResponse echo(String name) {
+ EchoRequest request = EchoRequest.newBuilder().setName(name).build();
+ return echo(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Sample code:
+ *
+ * @param parent
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final EchoResponse echo(String parent) {
+ EchoRequest request = EchoRequest.newBuilder().setParent(parent).build();
+ return echo(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Sample code:
+ *
+ * @param content
+ * @param severity
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final EchoResponse echo(String content, Severity severity) {
+ EchoRequest request =
+ EchoRequest.newBuilder().setContent(content).setSeverity(severity).build();
+ return echo(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Sample code:
+ *
+ * @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.
+ /** Sample code: */
+ public final UnaryCallable echoCallable() {
+ return stub.echoCallable();
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /** Sample code: */
+ public final ServerStreamingCallable expandCallable() {
+ return stub.expandCallable();
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /** Sample code: */
+ public final ClientStreamingCallable collectCallable() {
+ return stub.collectCallable();
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /** Sample code: */
+ public final BidiStreamingCallable chatCallable() {
+ return stub.chatCallable();
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /** Sample code: */
+ public final BidiStreamingCallable chatAgainCallable() {
+ return stub.chatAgainCallable();
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Sample code:
+ *
+ * @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.
+ /** Sample code: */
+ public final UnaryCallable
+ pagedExpandPagedCallable() {
+ return stub.pagedExpandPagedCallable();
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /** Sample code: */
+ public final UnaryCallable pagedExpandCallable() {
+ return stub.pagedExpandCallable();
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Sample code:
+ *
+ * @param ttl
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final OperationFuture waitAsync(Duration ttl) {
+ WaitRequest request = WaitRequest.newBuilder().setTtl(ttl).build();
+ return waitAsync(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Sample code:
+ *
+ * @param end_time
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final OperationFuture waitAsync(Timestamp endTime) {
+ WaitRequest request = WaitRequest.newBuilder().setEndTime(endTime).build();
+ return waitAsync(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Sample code:
+ *
+ * @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.
+ /** Sample code: */
+ public final OperationCallable waitOperationCallable() {
+ return stub.waitOperationCallable();
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /** Sample code: */
+ public final UnaryCallable waitCallable() {
+ return stub.waitCallable();
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Sample code:
+ *
+ * @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.
+ /** Sample code: */
+ 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,
+ new ApiFunction() {
+ @Override
+ public PagedExpandPagedResponse apply(PagedExpandPage input) {
+ return 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);
+ }
+ }
+}
diff --git a/src/test/java/com/google/api/generator/gapic/composer/goldens/EchoClientTest.golden b/src/test/java/com/google/api/generator/gapic/composer/goldens/EchoClientTest.golden
new file mode 100644
index 0000000000..c1cf340662
--- /dev/null
+++ b/src/test/java/com/google/api/generator/gapic/composer/goldens/EchoClientTest.golden
@@ -0,0 +1,629 @@
+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.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.api.resourcenames.ResourceName;
+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.protobuf.Timestamp;
+import com.google.rpc.Status;
+import io.grpc.StatusRuntimeException;
+import java.io.IOException;
+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 EchoClientTest {
+ public static MockServiceHelper mockServiceHelper;
+ public static MockEcho mockEcho;
+ public EchoClient client;
+ public LocalChannelProvider channelProvider;
+
+ @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() {
+ EchoResponse expectedResponse =
+ EchoResponse.newBuilder().setContent("content951530617").build();
+ mockEcho.addResponse(expectedResponse);
+ ResourceName parent = FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]");
+ EchoResponse actualResponse = client.echo(parent);
+ Assert.assertEquals(expectedResponse, actualResponse);
+ List actualRequests = mockEcho.getRequests();
+ Assert.assertEquals(1, actualRequests.size());
+ EchoRequest actualRequest = ((EchoRequest) actualRequests.get(0));
+ Assert.assertEquals(parent.toString(), actualRequest.getParent());
+ 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 {
+ ResourceName parent = FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]");
+ client.echo(parent);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void echoTest2() {
+ EchoResponse expectedResponse =
+ EchoResponse.newBuilder().setContent("content951530617").build();
+ mockEcho.addResponse(expectedResponse);
+ Status error = Status.newBuilder().build();
+ EchoResponse actualResponse = client.echo(error);
+ Assert.assertEquals(expectedResponse, actualResponse);
+ List actualRequests = mockEcho.getRequests();
+ Assert.assertEquals(1, actualRequests.size());
+ EchoRequest actualRequest = ((EchoRequest) actualRequests.get(0));
+ Assert.assertEquals(error, actualRequest.getError());
+ Assert.assertTrue(
+ channelProvider.isHeaderSent(
+ ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
+ GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
+ }
+
+ @Test
+ public void echoExceptionTest2() throws Exception {
+ StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
+ mockEcho.addException(exception);
+ try {
+ Status error = Status.newBuilder().build();
+ client.echo(error);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void echoTest3() {
+ EchoResponse expectedResponse =
+ EchoResponse.newBuilder().setContent("content951530617").build();
+ mockEcho.addResponse(expectedResponse);
+ FoobarName name = FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]");
+ EchoResponse actualResponse = client.echo(name);
+ Assert.assertEquals(expectedResponse, actualResponse);
+ List actualRequests = mockEcho.getRequests();
+ Assert.assertEquals(1, actualRequests.size());
+ EchoRequest actualRequest = ((EchoRequest) actualRequests.get(0));
+ Assert.assertEquals(name.toString(), actualRequest.getName());
+ Assert.assertTrue(
+ channelProvider.isHeaderSent(
+ ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
+ GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
+ }
+
+ @Test
+ public void echoExceptionTest3() throws Exception {
+ StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
+ mockEcho.addException(exception);
+ try {
+ FoobarName name = FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]");
+ client.echo(name);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void echoTest4() {
+ EchoResponse expectedResponse =
+ EchoResponse.newBuilder().setContent("content951530617").build();
+ mockEcho.addResponse(expectedResponse);
+ String content = "content951530617";
+ EchoResponse actualResponse = client.echo(content);
+ Assert.assertEquals(expectedResponse, actualResponse);
+ List actualRequests = mockEcho.getRequests();
+ Assert.assertEquals(1, actualRequests.size());
+ EchoRequest actualRequest = ((EchoRequest) actualRequests.get(0));
+ Assert.assertEquals(content, actualRequest.getContent());
+ Assert.assertTrue(
+ channelProvider.isHeaderSent(
+ ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
+ GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
+ }
+
+ @Test
+ public void echoExceptionTest4() throws Exception {
+ StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
+ mockEcho.addException(exception);
+ try {
+ String content = "content951530617";
+ client.echo(content);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void echoTest5() {
+ EchoResponse expectedResponse =
+ EchoResponse.newBuilder().setContent("content951530617").build();
+ mockEcho.addResponse(expectedResponse);
+ String name = "name3373707";
+ EchoResponse actualResponse = client.echo(name);
+ Assert.assertEquals(expectedResponse, actualResponse);
+ List actualRequests = mockEcho.getRequests();
+ Assert.assertEquals(1, actualRequests.size());
+ EchoRequest actualRequest = ((EchoRequest) actualRequests.get(0));
+ Assert.assertEquals(name, actualRequest.getName());
+ Assert.assertTrue(
+ channelProvider.isHeaderSent(
+ ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
+ GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
+ }
+
+ @Test
+ public void echoExceptionTest5() throws Exception {
+ StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
+ mockEcho.addException(exception);
+ try {
+ String name = "name3373707";
+ client.echo(name);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void echoTest6() {
+ EchoResponse expectedResponse =
+ EchoResponse.newBuilder().setContent("content951530617").build();
+ mockEcho.addResponse(expectedResponse);
+ String parent = "parent-995424086";
+ EchoResponse actualResponse = client.echo(parent);
+ Assert.assertEquals(expectedResponse, actualResponse);
+ List actualRequests = mockEcho.getRequests();
+ Assert.assertEquals(1, actualRequests.size());
+ EchoRequest actualRequest = ((EchoRequest) actualRequests.get(0));
+ Assert.assertEquals(parent, actualRequest.getParent());
+ Assert.assertTrue(
+ channelProvider.isHeaderSent(
+ ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
+ GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
+ }
+
+ @Test
+ public void echoExceptionTest6() throws Exception {
+ StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
+ mockEcho.addException(exception);
+ try {
+ String parent = "parent-995424086";
+ client.echo(parent);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void echoTest7() {
+ EchoResponse expectedResponse =
+ EchoResponse.newBuilder().setContent("content951530617").build();
+ mockEcho.addResponse(expectedResponse);
+ String content = "content951530617";
+ Severity severity = Severity.forNumber(0);
+ EchoResponse actualResponse = client.echo(content, severity);
+ Assert.assertEquals(expectedResponse, actualResponse);
+ List actualRequests = mockEcho.getRequests();
+ Assert.assertEquals(1, actualRequests.size());
+ EchoRequest actualRequest = ((EchoRequest) actualRequests.get(0));
+ Assert.assertEquals(content, actualRequest.getContent());
+ Assert.assertEquals(severity, actualRequest.getSeverity());
+ Assert.assertTrue(
+ channelProvider.isHeaderSent(
+ ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
+ GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
+ }
+
+ @Test
+ public void echoExceptionTest7() throws Exception {
+ StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
+ mockEcho.addException(exception);
+ try {
+ String content = "content951530617";
+ Severity severity = Severity.forNumber(0);
+ client.echo(content, severity);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void expandTest() {
+ EchoResponse expectedResponse =
+ EchoResponse.newBuilder().setContent("content951530617").build();
+ mockEcho.addResponse(expectedResponse);
+ ExpandRequest request =
+ ExpandRequest.newBuilder().setContent("content951530617").setInfo("info3237038").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").setInfo("info3237038").build();
+ MockStreamObserver responseObserver = new MockStreamObserver<>();
+ client.expandCallable();
+ 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() {
+ EchoResponse expectedResponse =
+ EchoResponse.newBuilder().setContent("content951530617").build();
+ mockEcho.addResponse(expectedResponse);
+ EchoRequest request =
+ EchoRequest.newBuilder()
+ .setName(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
+ .setParent(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
+ .setFoobar(Foobar.newBuilder().build())
+ .build();
+ MockStreamObserver responseObserver = new MockStreamObserver<>();
+ ClientStreamingCallable callable = client.collectCallable();
+ ApiStreamObserver requestObserver =
+ callable.clientStreamingCall(request, 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()
+ .setName(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
+ .setParent(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
+ .setFoobar(Foobar.newBuilder().build())
+ .build();
+ MockStreamObserver responseObserver = new MockStreamObserver<>();
+ ClientStreamingCallable callable = client.collectCallable();
+ ApiStreamObserver requestObserver =
+ callable.clientStreamingCall(request, 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() {
+ EchoResponse expectedResponse =
+ EchoResponse.newBuilder().setContent("content951530617").build();
+ mockEcho.addResponse(expectedResponse);
+ EchoRequest request =
+ EchoRequest.newBuilder()
+ .setName(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
+ .setParent(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
+ .setFoobar(Foobar.newBuilder().build())
+ .build();
+ MockStreamObserver responseObserver = new MockStreamObserver<>();
+ BidiStreamingCallable callable = client.chatCallable();
+ ApiStreamObserver requestObserver =
+ callable.bidiStreamingCall(request, 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()
+ .setName(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
+ .setParent(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
+ .setFoobar(Foobar.newBuilder().build())
+ .build();
+ MockStreamObserver responseObserver = new MockStreamObserver<>();
+ BidiStreamingCallable callable = client.chatCallable();
+ ApiStreamObserver requestObserver =
+ callable.bidiStreamingCall(request, 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 chatAgainTest() {
+ EchoResponse expectedResponse =
+ EchoResponse.newBuilder().setContent("content951530617").build();
+ mockEcho.addResponse(expectedResponse);
+ EchoRequest request =
+ EchoRequest.newBuilder()
+ .setName(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
+ .setParent(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
+ .setFoobar(Foobar.newBuilder().build())
+ .build();
+ MockStreamObserver responseObserver = new MockStreamObserver<>();
+ BidiStreamingCallable callable = client.chatAgainCallable();
+ ApiStreamObserver requestObserver =
+ callable.bidiStreamingCall(request, 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 chatAgainExceptionTest() throws Exception {
+ StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
+ mockEcho.addException(exception);
+ EchoRequest request =
+ EchoRequest.newBuilder()
+ .setName(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
+ .setParent(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
+ .setFoobar(Foobar.newBuilder().build())
+ .build();
+ MockStreamObserver responseObserver = new MockStreamObserver<>();
+ BidiStreamingCallable callable = client.chatAgainCallable();
+ ApiStreamObserver requestObserver =
+ callable.bidiStreamingCall(request, 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() {
+ 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("page_token1630607433")
+ .build();
+ PagedExpandResponse pagedListResponse = client.pagedExpand(request);
+ 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("page_token1630607433")
+ .build();
+ client.pagedExpand(request);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void waitTest() {
+ WaitResponse expectedResponse =
+ WaitResponse.newBuilder().setContent("content951530617").build();
+ Operation resultOperation =
+ Operation.newBuilder()
+ .setName("waitTest")
+ .setDone(true)
+ .setResponse(Any.pack(expectedResponse))
+ .build();
+ mockEcho.addResponse(resultOperation);
+ Duration ttl = Duration.newBuilder().build();
+ WaitResponse actualResponse = client.waitAsync(ttl).get();
+ Assert.assertEquals(expectedResponse, actualResponse);
+ List actualRequests = mockEcho.getRequests();
+ Assert.assertEquals(1, actualRequests.size());
+ WaitRequest actualRequest = ((WaitRequest) actualRequests.get(0));
+ Assert.assertEquals(ttl, actualRequest.getTtl());
+ 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 {
+ Duration ttl = Duration.newBuilder().build();
+ client.waitAsync(ttl).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 waitTest2() {
+ WaitResponse expectedResponse =
+ WaitResponse.newBuilder().setContent("content951530617").build();
+ Operation resultOperation =
+ Operation.newBuilder()
+ .setName("waitTest")
+ .setDone(true)
+ .setResponse(Any.pack(expectedResponse))
+ .build();
+ mockEcho.addResponse(resultOperation);
+ Timestamp endTime = Timestamp.newBuilder().build();
+ WaitResponse actualResponse = client.waitAsync(endTime).get();
+ Assert.assertEquals(expectedResponse, actualResponse);
+ List actualRequests = mockEcho.getRequests();
+ Assert.assertEquals(1, actualRequests.size());
+ WaitRequest actualRequest = ((WaitRequest) actualRequests.get(0));
+ Assert.assertEquals(endTime, actualRequest.getEndTime());
+ Assert.assertTrue(
+ channelProvider.isHeaderSent(
+ ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
+ GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
+ }
+
+ @Test
+ public void waitExceptionTest2() throws Exception {
+ StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
+ mockEcho.addException(exception);
+ try {
+ Timestamp endTime = Timestamp.newBuilder().build();
+ client.waitAsync(endTime).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() {
+ BlockResponse expectedResponse =
+ BlockResponse.newBuilder().setContent("content951530617").build();
+ mockEcho.addResponse(expectedResponse);
+ BlockRequest request = BlockRequest.newBuilder().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().build();
+ client.block(request);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+}