diff --git a/java-game-servers/README.md b/java-game-servers/README.md index 44f509ee9d0b..ff58961ccec2 100644 --- a/java-game-servers/README.md +++ b/java-game-servers/README.md @@ -19,20 +19,20 @@ If you are using Maven, add this to your pom.xml file: com.google.cloud google-cloud-game-servers - 2.2.0 + 2.2.1 ``` If you are using Gradle without BOM, add this to your dependencies ```Groovy -implementation 'com.google.cloud:google-cloud-game-servers:2.2.0' +implementation 'com.google.cloud:google-cloud-game-servers:2.2.1' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-game-servers" % "2.2.0" +libraryDependencies += "com.google.cloud" % "google-cloud-game-servers" % "2.2.1" ``` ## Authentication diff --git a/java-game-servers/google-cloud-game-servers/pom.xml b/java-game-servers/google-cloud-game-servers/pom.xml index 807d70bd496e..23cf2646fe74 100644 --- a/java-game-servers/google-cloud-game-servers/pom.xml +++ b/java-game-servers/google-cloud-game-servers/pom.xml @@ -62,6 +62,10 @@ com.google.api gax-grpc + + com.google.api + gax-httpjson + org.threeten threetenbp @@ -90,12 +94,24 @@ test + + com.google.api + gax + testlib + test + com.google.api gax-grpc testlib test + + com.google.api + gax-httpjson + testlib + test + diff --git a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/GameServerClustersServiceClient.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/GameServerClustersServiceClient.java index aafb7909fc2d..82cccd9da7f9 100644 --- a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/GameServerClustersServiceClient.java +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/GameServerClustersServiceClient.java @@ -19,6 +19,7 @@ import com.google.api.core.ApiFuture; import com.google.api.core.ApiFutures; 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; @@ -30,7 +31,6 @@ import com.google.cloud.gaming.v1.stub.GameServerClustersServiceStubSettings; import com.google.common.util.concurrent.MoreExecutors; import com.google.longrunning.Operation; -import com.google.longrunning.OperationsClient; import com.google.protobuf.Empty; import com.google.protobuf.FieldMask; import java.io.IOException; @@ -108,13 +108,29 @@ * GameServerClustersServiceClient.create(gameServerClustersServiceSettings); * } * + *

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 for illustrative purposes only.
+ * // It may require modifications to work in your environment.
+ * GameServerClustersServiceSettings gameServerClustersServiceSettings =
+ *     GameServerClustersServiceSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             GameServerClustersServiceSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * GameServerClustersServiceClient gameServerClustersServiceClient =
+ *     GameServerClustersServiceClient.create(gameServerClustersServiceSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @Generated("by gapic-generator-java") public class GameServerClustersServiceClient implements BackgroundResource { private final GameServerClustersServiceSettings settings; private final GameServerClustersServiceStub stub; - private final OperationsClient operationsClient; + private final OperationsClient httpJsonOperationsClient; + private final com.google.longrunning.OperationsClient operationsClient; /** Constructs an instance of GameServerClustersServiceClient with default settings. */ public static final GameServerClustersServiceClient create() throws IOException { @@ -148,13 +164,17 @@ protected GameServerClustersServiceClient(GameServerClustersServiceSettings sett throws IOException { this.settings = settings; this.stub = ((GameServerClustersServiceStubSettings) settings.getStubSettings()).createStub(); - this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + this.operationsClient = + com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); + this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); } protected GameServerClustersServiceClient(GameServerClustersServiceStub stub) { this.settings = null; this.stub = stub; - this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + this.operationsClient = + com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); + this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); } public final GameServerClustersServiceSettings getSettings() { @@ -169,10 +189,18 @@ public GameServerClustersServiceStub getStub() { * 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() { + 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. + */ + public final OperationsClient getHttpJsonOperationsClient() { + return httpJsonOperationsClient; + } + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Lists game server clusters in a given project and location. diff --git a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/GameServerClustersServiceSettings.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/GameServerClustersServiceSettings.java index 6a1cf12221c5..762843cdaf0f 100644 --- a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/GameServerClustersServiceSettings.java +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/GameServerClustersServiceSettings.java @@ -23,6 +23,7 @@ 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; @@ -184,11 +185,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return GameServerClustersServiceStubSettings.defaultCredentialsProviderBuilder(); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return GameServerClustersServiceStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return GameServerClustersServiceStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return GameServerClustersServiceStubSettings.defaultTransportChannelProvider(); } @@ -198,11 +206,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return GameServerClustersServiceStubSettings.defaultApiClientHeaderProviderBuilder(); } - /** Returns a new builder for this class. */ + /** 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); @@ -241,6 +255,11 @@ private static Builder createDefault() { return new Builder(GameServerClustersServiceStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(GameServerClustersServiceStubSettings.newHttpJsonBuilder()); + } + public GameServerClustersServiceStubSettings.Builder getStubSettingsBuilder() { return ((GameServerClustersServiceStubSettings.Builder) getStubSettings()); } diff --git a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/GameServerConfigsServiceClient.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/GameServerConfigsServiceClient.java index c949043c1e48..bb451fa885ab 100644 --- a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/GameServerConfigsServiceClient.java +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/GameServerConfigsServiceClient.java @@ -19,6 +19,7 @@ import com.google.api.core.ApiFuture; import com.google.api.core.ApiFutures; 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; @@ -30,7 +31,6 @@ import com.google.cloud.gaming.v1.stub.GameServerConfigsServiceStubSettings; import com.google.common.util.concurrent.MoreExecutors; import com.google.longrunning.Operation; -import com.google.longrunning.OperationsClient; import com.google.protobuf.Empty; import java.io.IOException; import java.util.List; @@ -106,13 +106,29 @@ * GameServerConfigsServiceClient.create(gameServerConfigsServiceSettings); * } * + *

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 for illustrative purposes only.
+ * // It may require modifications to work in your environment.
+ * GameServerConfigsServiceSettings gameServerConfigsServiceSettings =
+ *     GameServerConfigsServiceSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             GameServerConfigsServiceSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * GameServerConfigsServiceClient gameServerConfigsServiceClient =
+ *     GameServerConfigsServiceClient.create(gameServerConfigsServiceSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @Generated("by gapic-generator-java") public class GameServerConfigsServiceClient implements BackgroundResource { private final GameServerConfigsServiceSettings settings; private final GameServerConfigsServiceStub stub; - private final OperationsClient operationsClient; + private final OperationsClient httpJsonOperationsClient; + private final com.google.longrunning.OperationsClient operationsClient; /** Constructs an instance of GameServerConfigsServiceClient with default settings. */ public static final GameServerConfigsServiceClient create() throws IOException { @@ -146,13 +162,17 @@ protected GameServerConfigsServiceClient(GameServerConfigsServiceSettings settin throws IOException { this.settings = settings; this.stub = ((GameServerConfigsServiceStubSettings) settings.getStubSettings()).createStub(); - this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + this.operationsClient = + com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); + this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); } protected GameServerConfigsServiceClient(GameServerConfigsServiceStub stub) { this.settings = null; this.stub = stub; - this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + this.operationsClient = + com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); + this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); } public final GameServerConfigsServiceSettings getSettings() { @@ -167,10 +187,18 @@ public GameServerConfigsServiceStub getStub() { * 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() { + 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. + */ + public final OperationsClient getHttpJsonOperationsClient() { + return httpJsonOperationsClient; + } + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Lists game server configs in a given project, location, and game server deployment. diff --git a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/GameServerConfigsServiceSettings.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/GameServerConfigsServiceSettings.java index 8a9225d0e920..d28d25984abf 100644 --- a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/GameServerConfigsServiceSettings.java +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/GameServerConfigsServiceSettings.java @@ -23,6 +23,7 @@ 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; @@ -145,11 +146,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return GameServerConfigsServiceStubSettings.defaultCredentialsProviderBuilder(); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return GameServerConfigsServiceStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return GameServerConfigsServiceStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return GameServerConfigsServiceStubSettings.defaultTransportChannelProvider(); } @@ -159,11 +167,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return GameServerConfigsServiceStubSettings.defaultApiClientHeaderProviderBuilder(); } - /** Returns a new builder for this class. */ + /** 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); @@ -202,6 +216,11 @@ private static Builder createDefault() { return new Builder(GameServerConfigsServiceStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(GameServerConfigsServiceStubSettings.newHttpJsonBuilder()); + } + public GameServerConfigsServiceStubSettings.Builder getStubSettingsBuilder() { return ((GameServerConfigsServiceStubSettings.Builder) getStubSettings()); } diff --git a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/GameServerDeploymentsServiceClient.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/GameServerDeploymentsServiceClient.java index a2a83b62edcf..7f79496e112d 100644 --- a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/GameServerDeploymentsServiceClient.java +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/GameServerDeploymentsServiceClient.java @@ -19,6 +19,7 @@ import com.google.api.core.ApiFuture; import com.google.api.core.ApiFutures; 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; @@ -30,7 +31,6 @@ import com.google.cloud.gaming.v1.stub.GameServerDeploymentsServiceStubSettings; import com.google.common.util.concurrent.MoreExecutors; import com.google.longrunning.Operation; -import com.google.longrunning.OperationsClient; import com.google.protobuf.Empty; import com.google.protobuf.FieldMask; import java.io.IOException; @@ -109,13 +109,30 @@ * GameServerDeploymentsServiceClient.create(gameServerDeploymentsServiceSettings); * } * + *

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 for illustrative purposes only.
+ * // It may require modifications to work in your environment.
+ * GameServerDeploymentsServiceSettings gameServerDeploymentsServiceSettings =
+ *     GameServerDeploymentsServiceSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             GameServerDeploymentsServiceSettings.defaultHttpJsonTransportProviderBuilder()
+ *                 .build())
+ *         .build();
+ * GameServerDeploymentsServiceClient gameServerDeploymentsServiceClient =
+ *     GameServerDeploymentsServiceClient.create(gameServerDeploymentsServiceSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @Generated("by gapic-generator-java") public class GameServerDeploymentsServiceClient implements BackgroundResource { private final GameServerDeploymentsServiceSettings settings; private final GameServerDeploymentsServiceStub stub; - private final OperationsClient operationsClient; + private final OperationsClient httpJsonOperationsClient; + private final com.google.longrunning.OperationsClient operationsClient; /** Constructs an instance of GameServerDeploymentsServiceClient with default settings. */ public static final GameServerDeploymentsServiceClient create() throws IOException { @@ -151,13 +168,17 @@ protected GameServerDeploymentsServiceClient(GameServerDeploymentsServiceSetting this.settings = settings; this.stub = ((GameServerDeploymentsServiceStubSettings) settings.getStubSettings()).createStub(); - this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + this.operationsClient = + com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); + this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); } protected GameServerDeploymentsServiceClient(GameServerDeploymentsServiceStub stub) { this.settings = null; this.stub = stub; - this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + this.operationsClient = + com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); + this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); } public final GameServerDeploymentsServiceSettings getSettings() { @@ -172,10 +193,18 @@ public GameServerDeploymentsServiceStub getStub() { * 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() { + 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. + */ + public final OperationsClient getHttpJsonOperationsClient() { + return httpJsonOperationsClient; + } + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Lists game server deployments in a given project and location. diff --git a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/GameServerDeploymentsServiceSettings.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/GameServerDeploymentsServiceSettings.java index 22bfb32c2771..aa9270e30c65 100644 --- a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/GameServerDeploymentsServiceSettings.java +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/GameServerDeploymentsServiceSettings.java @@ -23,6 +23,7 @@ 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; @@ -199,11 +200,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return GameServerDeploymentsServiceStubSettings.defaultCredentialsProviderBuilder(); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return GameServerDeploymentsServiceStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return GameServerDeploymentsServiceStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return GameServerDeploymentsServiceStubSettings.defaultTransportChannelProvider(); } @@ -213,11 +221,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return GameServerDeploymentsServiceStubSettings.defaultApiClientHeaderProviderBuilder(); } - /** Returns a new builder for this class. */ + /** 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); @@ -256,6 +270,11 @@ private static Builder createDefault() { return new Builder(GameServerDeploymentsServiceStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(GameServerDeploymentsServiceStubSettings.newHttpJsonBuilder()); + } + public GameServerDeploymentsServiceStubSettings.Builder getStubSettingsBuilder() { return ((GameServerDeploymentsServiceStubSettings.Builder) getStubSettings()); } diff --git a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/RealmsServiceClient.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/RealmsServiceClient.java index 4eee41606faa..ca6bd84b44b7 100644 --- a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/RealmsServiceClient.java +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/RealmsServiceClient.java @@ -19,6 +19,7 @@ import com.google.api.core.ApiFuture; import com.google.api.core.ApiFutures; 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; @@ -30,7 +31,6 @@ import com.google.cloud.gaming.v1.stub.RealmsServiceStubSettings; import com.google.common.util.concurrent.MoreExecutors; import com.google.longrunning.Operation; -import com.google.longrunning.OperationsClient; import com.google.protobuf.Empty; import com.google.protobuf.FieldMask; import java.io.IOException; @@ -103,13 +103,28 @@ * RealmsServiceClient realmsServiceClient = RealmsServiceClient.create(realmsServiceSettings); * } * + *

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 for illustrative purposes only.
+ * // It may require modifications to work in your environment.
+ * RealmsServiceSettings realmsServiceSettings =
+ *     RealmsServiceSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             RealmsServiceSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * RealmsServiceClient realmsServiceClient = RealmsServiceClient.create(realmsServiceSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @Generated("by gapic-generator-java") public class RealmsServiceClient implements BackgroundResource { private final RealmsServiceSettings settings; private final RealmsServiceStub stub; - private final OperationsClient operationsClient; + private final OperationsClient httpJsonOperationsClient; + private final com.google.longrunning.OperationsClient operationsClient; /** Constructs an instance of RealmsServiceClient with default settings. */ public static final RealmsServiceClient create() throws IOException { @@ -141,13 +156,17 @@ public static final RealmsServiceClient create(RealmsServiceStub stub) { protected RealmsServiceClient(RealmsServiceSettings settings) throws IOException { this.settings = settings; this.stub = ((RealmsServiceStubSettings) settings.getStubSettings()).createStub(); - this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + this.operationsClient = + com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); + this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); } protected RealmsServiceClient(RealmsServiceStub stub) { this.settings = null; this.stub = stub; - this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + this.operationsClient = + com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); + this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); } public final RealmsServiceSettings getSettings() { @@ -162,10 +181,18 @@ public RealmsServiceStub getStub() { * 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() { + 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. + */ + public final OperationsClient getHttpJsonOperationsClient() { + return httpJsonOperationsClient; + } + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Lists realms in a given project and location. diff --git a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/RealmsServiceSettings.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/RealmsServiceSettings.java index 635790a7838b..8f2642f04bc8 100644 --- a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/RealmsServiceSettings.java +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/RealmsServiceSettings.java @@ -23,6 +23,7 @@ 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; @@ -148,11 +149,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return RealmsServiceStubSettings.defaultCredentialsProviderBuilder(); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return RealmsServiceStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return RealmsServiceStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return RealmsServiceStubSettings.defaultTransportChannelProvider(); } @@ -162,11 +170,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return RealmsServiceStubSettings.defaultApiClientHeaderProviderBuilder(); } - /** Returns a new builder for this class. */ + /** 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); @@ -204,6 +218,11 @@ private static Builder createDefault() { return new Builder(RealmsServiceStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(RealmsServiceStubSettings.newHttpJsonBuilder()); + } + public RealmsServiceStubSettings.Builder getStubSettingsBuilder() { return ((RealmsServiceStubSettings.Builder) getStubSettings()); } diff --git a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/GameServerClustersServiceStub.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/GameServerClustersServiceStub.java index e0774f313464..7951508067c1 100644 --- a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/GameServerClustersServiceStub.java +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/GameServerClustersServiceStub.java @@ -50,7 +50,11 @@ public abstract class GameServerClustersServiceStub implements BackgroundResource { public OperationsStub getOperationsStub() { - throw new UnsupportedOperationException("Not implemented: getOperationsStub()"); + return null; + } + + public com.google.api.gax.httpjson.longrunning.stub.OperationsStub getHttpJsonOperationsStub() { + return null; } public UnaryCallable diff --git a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/GameServerClustersServiceStubSettings.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/GameServerClustersServiceStubSettings.java index 67d753c3cc6a..830494e2d346 100644 --- a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/GameServerClustersServiceStubSettings.java +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/GameServerClustersServiceStubSettings.java @@ -28,6 +28,9 @@ 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; @@ -290,6 +293,11 @@ public GameServerClustersServiceStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcGameServerClustersServiceStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonGameServerClustersServiceStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -322,18 +330,25 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde .setUseJwtAccessWithScope(true); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** 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 defaultApiClientHeaderProviderBuilder() { + public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() { return ApiClientHeaderProvider.newBuilder() .setGeneratedLibToken( "gapic", GaxProperties.getLibraryVersion(GameServerClustersServiceStubSettings.class)) @@ -341,11 +356,30 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); } - /** Returns a new builder for this class. */ + @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(GameServerClustersServiceStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return GameServerClustersServiceStubSettings.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); @@ -543,6 +577,19 @@ private static Builder createDefault() { 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 .listGameServerClustersSettings() diff --git a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/GameServerConfigsServiceStub.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/GameServerConfigsServiceStub.java index 4bc013035a3f..b7c979697a00 100644 --- a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/GameServerConfigsServiceStub.java +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/GameServerConfigsServiceStub.java @@ -43,7 +43,11 @@ public abstract class GameServerConfigsServiceStub implements BackgroundResource { public OperationsStub getOperationsStub() { - throw new UnsupportedOperationException("Not implemented: getOperationsStub()"); + return null; + } + + public com.google.api.gax.httpjson.longrunning.stub.OperationsStub getHttpJsonOperationsStub() { + return null; } public UnaryCallable diff --git a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/GameServerConfigsServiceStubSettings.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/GameServerConfigsServiceStubSettings.java index 85ceea98869f..851916066e1d 100644 --- a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/GameServerConfigsServiceStubSettings.java +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/GameServerConfigsServiceStubSettings.java @@ -28,6 +28,9 @@ 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; @@ -231,6 +234,11 @@ public GameServerConfigsServiceStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcGameServerConfigsServiceStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonGameServerConfigsServiceStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -263,18 +271,25 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde .setUseJwtAccessWithScope(true); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** 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 defaultApiClientHeaderProviderBuilder() { + public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() { return ApiClientHeaderProvider.newBuilder() .setGeneratedLibToken( "gapic", GaxProperties.getLibraryVersion(GameServerConfigsServiceStubSettings.class)) @@ -282,11 +297,30 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); } - /** Returns a new builder for this class. */ + @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(GameServerConfigsServiceStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return GameServerConfigsServiceStubSettings.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); @@ -429,6 +463,19 @@ private static Builder createDefault() { 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 .listGameServerConfigsSettings() diff --git a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/GameServerDeploymentsServiceStub.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/GameServerDeploymentsServiceStub.java index 486ea6f44179..e0904cf4fc7e 100644 --- a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/GameServerDeploymentsServiceStub.java +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/GameServerDeploymentsServiceStub.java @@ -51,7 +51,11 @@ public abstract class GameServerDeploymentsServiceStub implements BackgroundResource { public OperationsStub getOperationsStub() { - throw new UnsupportedOperationException("Not implemented: getOperationsStub()"); + return null; + } + + public com.google.api.gax.httpjson.longrunning.stub.OperationsStub getHttpJsonOperationsStub() { + return null; } public UnaryCallable diff --git a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/GameServerDeploymentsServiceStubSettings.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/GameServerDeploymentsServiceStubSettings.java index fd512bbc029a..1d5461cc63f0 100644 --- a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/GameServerDeploymentsServiceStubSettings.java +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/GameServerDeploymentsServiceStubSettings.java @@ -28,6 +28,9 @@ 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; @@ -313,6 +316,11 @@ public GameServerDeploymentsServiceStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcGameServerDeploymentsServiceStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonGameServerDeploymentsServiceStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -345,18 +353,25 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde .setUseJwtAccessWithScope(true); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** 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 defaultApiClientHeaderProviderBuilder() { + public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() { return ApiClientHeaderProvider.newBuilder() .setGeneratedLibToken( "gapic", @@ -365,11 +380,31 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); } - /** Returns a new builder for this class. */ + @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(GameServerDeploymentsServiceStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return GameServerDeploymentsServiceStubSettings.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); @@ -575,6 +610,19 @@ private static Builder createDefault() { 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 .listGameServerDeploymentsSettings() diff --git a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/HttpJsonGameServerClustersServiceCallableFactory.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/HttpJsonGameServerClustersServiceCallableFactory.java new file mode 100644 index 000000000000..2d57c3c99414 --- /dev/null +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/HttpJsonGameServerClustersServiceCallableFactory.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.cloud.gaming.v1.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 GameServerClustersService service API. + * + *

This class is for advanced usage. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonGameServerClustersServiceCallableFactory + 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/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/HttpJsonGameServerClustersServiceStub.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/HttpJsonGameServerClustersServiceStub.java new file mode 100644 index 000000000000..d1ae48f5c365 --- /dev/null +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/HttpJsonGameServerClustersServiceStub.java @@ -0,0 +1,742 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.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.cloud.gaming.v1.stub; + +import static com.google.cloud.gaming.v1.GameServerClustersServiceClient.ListGameServerClustersPagedResponse; + +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.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.gaming.v1.CreateGameServerClusterRequest; +import com.google.cloud.gaming.v1.DeleteGameServerClusterRequest; +import com.google.cloud.gaming.v1.GameServerCluster; +import com.google.cloud.gaming.v1.GetGameServerClusterRequest; +import com.google.cloud.gaming.v1.ListGameServerClustersRequest; +import com.google.cloud.gaming.v1.ListGameServerClustersResponse; +import com.google.cloud.gaming.v1.OperationMetadata; +import com.google.cloud.gaming.v1.PreviewCreateGameServerClusterRequest; +import com.google.cloud.gaming.v1.PreviewCreateGameServerClusterResponse; +import com.google.cloud.gaming.v1.PreviewDeleteGameServerClusterRequest; +import com.google.cloud.gaming.v1.PreviewDeleteGameServerClusterResponse; +import com.google.cloud.gaming.v1.PreviewUpdateGameServerClusterRequest; +import com.google.cloud.gaming.v1.PreviewUpdateGameServerClusterResponse; +import com.google.cloud.gaming.v1.UpdateGameServerClusterRequest; +import com.google.longrunning.Operation; +import com.google.protobuf.Empty; +import com.google.protobuf.TypeRegistry; +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 GameServerClustersService service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonGameServerClustersServiceStub extends GameServerClustersServiceStub { + private static final TypeRegistry typeRegistry = + TypeRegistry.newBuilder() + .add(GameServerCluster.getDescriptor()) + .add(OperationMetadata.getDescriptor()) + .add(Empty.getDescriptor()) + .build(); + + private static final ApiMethodDescriptor< + ListGameServerClustersRequest, ListGameServerClustersResponse> + listGameServerClustersMethodDescriptor = + ApiMethodDescriptor + .newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1.GameServerClustersService/ListGameServerClusters") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*/realms/*}/gameServerClusters", + 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, "filter", request.getFilter()); + serializer.putQueryParam(fields, "orderBy", request.getOrderBy()); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + serializer.putQueryParam(fields, "view", request.getView()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListGameServerClustersResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getGameServerClusterMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1.GameServerClustersService/GetGameServerCluster") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/realms/*/gameServerClusters/*}", + 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, "view", request.getView()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(GameServerCluster.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + createGameServerClusterMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1.GameServerClustersService/CreateGameServerCluster") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*/realms/*}/gameServerClusters", + 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, "gameServerClusterId", request.getGameServerClusterId()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("gameServerCluster", request.getGameServerCluster())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (CreateGameServerClusterRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor< + PreviewCreateGameServerClusterRequest, PreviewCreateGameServerClusterResponse> + previewCreateGameServerClusterMethodDescriptor = + ApiMethodDescriptor + . + newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1.GameServerClustersService/PreviewCreateGameServerCluster") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*/realms/*}/gameServerClusters:previewCreate", + 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, "gameServerClusterId", request.getGameServerClusterId()); + serializer.putQueryParam( + fields, "previewTime", request.getPreviewTime()); + serializer.putQueryParam(fields, "view", request.getView()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("gameServerCluster", request.getGameServerCluster())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance( + PreviewCreateGameServerClusterResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + deleteGameServerClusterMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1.GameServerClustersService/DeleteGameServerCluster") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/realms/*/gameServerClusters/*}", + 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(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (DeleteGameServerClusterRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor< + PreviewDeleteGameServerClusterRequest, PreviewDeleteGameServerClusterResponse> + previewDeleteGameServerClusterMethodDescriptor = + ApiMethodDescriptor + . + newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1.GameServerClustersService/PreviewDeleteGameServerCluster") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/realms/*/gameServerClusters/*}:previewDelete", + 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, "previewTime", request.getPreviewTime()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance( + PreviewDeleteGameServerClusterResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + updateGameServerClusterMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1.GameServerClustersService/UpdateGameServerCluster") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{gameServerCluster.name=projects/*/locations/*/realms/*/gameServerClusters/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam( + fields, + "gameServerCluster.name", + request.getGameServerCluster().getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("gameServerCluster", request.getGameServerCluster())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (UpdateGameServerClusterRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor< + PreviewUpdateGameServerClusterRequest, PreviewUpdateGameServerClusterResponse> + previewUpdateGameServerClusterMethodDescriptor = + ApiMethodDescriptor + . + newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1.GameServerClustersService/PreviewUpdateGameServerCluster") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{gameServerCluster.name=projects/*/locations/*/realms/*/gameServerClusters/*}:previewUpdate", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam( + fields, + "gameServerCluster.name", + request.getGameServerCluster().getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam( + fields, "previewTime", request.getPreviewTime()); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("gameServerCluster", request.getGameServerCluster())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance( + PreviewUpdateGameServerClusterResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private final UnaryCallable + listGameServerClustersCallable; + private final UnaryCallable + listGameServerClustersPagedCallable; + private final UnaryCallable + getGameServerClusterCallable; + private final UnaryCallable + createGameServerClusterCallable; + private final OperationCallable< + CreateGameServerClusterRequest, GameServerCluster, OperationMetadata> + createGameServerClusterOperationCallable; + private final UnaryCallable< + PreviewCreateGameServerClusterRequest, PreviewCreateGameServerClusterResponse> + previewCreateGameServerClusterCallable; + private final UnaryCallable + deleteGameServerClusterCallable; + private final OperationCallable + deleteGameServerClusterOperationCallable; + private final UnaryCallable< + PreviewDeleteGameServerClusterRequest, PreviewDeleteGameServerClusterResponse> + previewDeleteGameServerClusterCallable; + private final UnaryCallable + updateGameServerClusterCallable; + private final OperationCallable< + UpdateGameServerClusterRequest, GameServerCluster, OperationMetadata> + updateGameServerClusterOperationCallable; + private final UnaryCallable< + PreviewUpdateGameServerClusterRequest, PreviewUpdateGameServerClusterResponse> + previewUpdateGameServerClusterCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonOperationsStub httpJsonOperationsStub; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonGameServerClustersServiceStub create( + GameServerClustersServiceStubSettings settings) throws IOException { + return new HttpJsonGameServerClustersServiceStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonGameServerClustersServiceStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonGameServerClustersServiceStub( + GameServerClustersServiceStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonGameServerClustersServiceStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonGameServerClustersServiceStub( + GameServerClustersServiceStubSettings.newHttpJsonBuilder().build(), + clientContext, + callableFactory); + } + + /** + * Constructs an instance of HttpJsonGameServerClustersServiceStub, 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 HttpJsonGameServerClustersServiceStub( + GameServerClustersServiceStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new HttpJsonGameServerClustersServiceCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonGameServerClustersServiceStub, 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 HttpJsonGameServerClustersServiceStub( + GameServerClustersServiceStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.httpJsonOperationsStub = + HttpJsonOperationsStub.create(clientContext, callableFactory, typeRegistry); + + HttpJsonCallSettings + listGameServerClustersTransportSettings = + HttpJsonCallSettings + .newBuilder() + .setMethodDescriptor(listGameServerClustersMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + getGameServerClusterTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getGameServerClusterMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + createGameServerClusterTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createGameServerClusterMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings< + PreviewCreateGameServerClusterRequest, PreviewCreateGameServerClusterResponse> + previewCreateGameServerClusterTransportSettings = + HttpJsonCallSettings + . + newBuilder() + .setMethodDescriptor(previewCreateGameServerClusterMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + deleteGameServerClusterTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteGameServerClusterMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings< + PreviewDeleteGameServerClusterRequest, PreviewDeleteGameServerClusterResponse> + previewDeleteGameServerClusterTransportSettings = + HttpJsonCallSettings + . + newBuilder() + .setMethodDescriptor(previewDeleteGameServerClusterMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + updateGameServerClusterTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateGameServerClusterMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings< + PreviewUpdateGameServerClusterRequest, PreviewUpdateGameServerClusterResponse> + previewUpdateGameServerClusterTransportSettings = + HttpJsonCallSettings + . + newBuilder() + .setMethodDescriptor(previewUpdateGameServerClusterMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.listGameServerClustersCallable = + callableFactory.createUnaryCallable( + listGameServerClustersTransportSettings, + settings.listGameServerClustersSettings(), + clientContext); + this.listGameServerClustersPagedCallable = + callableFactory.createPagedCallable( + listGameServerClustersTransportSettings, + settings.listGameServerClustersSettings(), + clientContext); + this.getGameServerClusterCallable = + callableFactory.createUnaryCallable( + getGameServerClusterTransportSettings, + settings.getGameServerClusterSettings(), + clientContext); + this.createGameServerClusterCallable = + callableFactory.createUnaryCallable( + createGameServerClusterTransportSettings, + settings.createGameServerClusterSettings(), + clientContext); + this.createGameServerClusterOperationCallable = + callableFactory.createOperationCallable( + createGameServerClusterTransportSettings, + settings.createGameServerClusterOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.previewCreateGameServerClusterCallable = + callableFactory.createUnaryCallable( + previewCreateGameServerClusterTransportSettings, + settings.previewCreateGameServerClusterSettings(), + clientContext); + this.deleteGameServerClusterCallable = + callableFactory.createUnaryCallable( + deleteGameServerClusterTransportSettings, + settings.deleteGameServerClusterSettings(), + clientContext); + this.deleteGameServerClusterOperationCallable = + callableFactory.createOperationCallable( + deleteGameServerClusterTransportSettings, + settings.deleteGameServerClusterOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.previewDeleteGameServerClusterCallable = + callableFactory.createUnaryCallable( + previewDeleteGameServerClusterTransportSettings, + settings.previewDeleteGameServerClusterSettings(), + clientContext); + this.updateGameServerClusterCallable = + callableFactory.createUnaryCallable( + updateGameServerClusterTransportSettings, + settings.updateGameServerClusterSettings(), + clientContext); + this.updateGameServerClusterOperationCallable = + callableFactory.createOperationCallable( + updateGameServerClusterTransportSettings, + settings.updateGameServerClusterOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.previewUpdateGameServerClusterCallable = + callableFactory.createUnaryCallable( + previewUpdateGameServerClusterTransportSettings, + settings.previewUpdateGameServerClusterSettings(), + clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(listGameServerClustersMethodDescriptor); + methodDescriptors.add(getGameServerClusterMethodDescriptor); + methodDescriptors.add(createGameServerClusterMethodDescriptor); + methodDescriptors.add(previewCreateGameServerClusterMethodDescriptor); + methodDescriptors.add(deleteGameServerClusterMethodDescriptor); + methodDescriptors.add(previewDeleteGameServerClusterMethodDescriptor); + methodDescriptors.add(updateGameServerClusterMethodDescriptor); + methodDescriptors.add(previewUpdateGameServerClusterMethodDescriptor); + return methodDescriptors; + } + + public HttpJsonOperationsStub getHttpJsonOperationsStub() { + return httpJsonOperationsStub; + } + + @Override + public UnaryCallable + listGameServerClustersCallable() { + return listGameServerClustersCallable; + } + + @Override + public UnaryCallable + listGameServerClustersPagedCallable() { + return listGameServerClustersPagedCallable; + } + + @Override + public UnaryCallable + getGameServerClusterCallable() { + return getGameServerClusterCallable; + } + + @Override + public UnaryCallable + createGameServerClusterCallable() { + return createGameServerClusterCallable; + } + + @Override + public OperationCallable + createGameServerClusterOperationCallable() { + return createGameServerClusterOperationCallable; + } + + @Override + public UnaryCallable< + PreviewCreateGameServerClusterRequest, PreviewCreateGameServerClusterResponse> + previewCreateGameServerClusterCallable() { + return previewCreateGameServerClusterCallable; + } + + @Override + public UnaryCallable + deleteGameServerClusterCallable() { + return deleteGameServerClusterCallable; + } + + @Override + public OperationCallable + deleteGameServerClusterOperationCallable() { + return deleteGameServerClusterOperationCallable; + } + + @Override + public UnaryCallable< + PreviewDeleteGameServerClusterRequest, PreviewDeleteGameServerClusterResponse> + previewDeleteGameServerClusterCallable() { + return previewDeleteGameServerClusterCallable; + } + + @Override + public UnaryCallable + updateGameServerClusterCallable() { + return updateGameServerClusterCallable; + } + + @Override + public OperationCallable + updateGameServerClusterOperationCallable() { + return updateGameServerClusterOperationCallable; + } + + @Override + public UnaryCallable< + PreviewUpdateGameServerClusterRequest, PreviewUpdateGameServerClusterResponse> + previewUpdateGameServerClusterCallable() { + return previewUpdateGameServerClusterCallable; + } + + @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/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/HttpJsonGameServerConfigsServiceCallableFactory.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/HttpJsonGameServerConfigsServiceCallableFactory.java new file mode 100644 index 000000000000..ca8d6c000ffd --- /dev/null +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/HttpJsonGameServerConfigsServiceCallableFactory.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.cloud.gaming.v1.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 GameServerConfigsService service API. + * + *

This class is for advanced usage. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonGameServerConfigsServiceCallableFactory + 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/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/HttpJsonGameServerConfigsServiceStub.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/HttpJsonGameServerConfigsServiceStub.java new file mode 100644 index 000000000000..ab2cdccbf167 --- /dev/null +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/HttpJsonGameServerConfigsServiceStub.java @@ -0,0 +1,442 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.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.cloud.gaming.v1.stub; + +import static com.google.cloud.gaming.v1.GameServerConfigsServiceClient.ListGameServerConfigsPagedResponse; + +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.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.gaming.v1.CreateGameServerConfigRequest; +import com.google.cloud.gaming.v1.DeleteGameServerConfigRequest; +import com.google.cloud.gaming.v1.GameServerConfig; +import com.google.cloud.gaming.v1.GetGameServerConfigRequest; +import com.google.cloud.gaming.v1.ListGameServerConfigsRequest; +import com.google.cloud.gaming.v1.ListGameServerConfigsResponse; +import com.google.cloud.gaming.v1.OperationMetadata; +import com.google.longrunning.Operation; +import com.google.protobuf.Empty; +import com.google.protobuf.TypeRegistry; +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 GameServerConfigsService service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonGameServerConfigsServiceStub extends GameServerConfigsServiceStub { + private static final TypeRegistry typeRegistry = + TypeRegistry.newBuilder() + .add(GameServerConfig.getDescriptor()) + .add(OperationMetadata.getDescriptor()) + .add(Empty.getDescriptor()) + .build(); + + private static final ApiMethodDescriptor< + ListGameServerConfigsRequest, ListGameServerConfigsResponse> + listGameServerConfigsMethodDescriptor = + ApiMethodDescriptor + .newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1.GameServerConfigsService/ListGameServerConfigs") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*/gameServerDeployments/*}/configs", + 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, "filter", request.getFilter()); + serializer.putQueryParam(fields, "orderBy", request.getOrderBy()); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListGameServerConfigsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getGameServerConfigMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1.GameServerConfigsService/GetGameServerConfig") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/gameServerDeployments/*/configs/*}", + 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(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(GameServerConfig.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + createGameServerConfigMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1.GameServerConfigsService/CreateGameServerConfig") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*/gameServerDeployments/*}/configs", + 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, "configId", request.getConfigId()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("gameServerConfig", request.getGameServerConfig())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (CreateGameServerConfigRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + deleteGameServerConfigMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1.GameServerConfigsService/DeleteGameServerConfig") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/gameServerDeployments/*/configs/*}", + 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(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (DeleteGameServerConfigRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private final UnaryCallable + listGameServerConfigsCallable; + private final UnaryCallable + listGameServerConfigsPagedCallable; + private final UnaryCallable + getGameServerConfigCallable; + private final UnaryCallable + createGameServerConfigCallable; + private final OperationCallable< + CreateGameServerConfigRequest, GameServerConfig, OperationMetadata> + createGameServerConfigOperationCallable; + private final UnaryCallable + deleteGameServerConfigCallable; + private final OperationCallable + deleteGameServerConfigOperationCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonOperationsStub httpJsonOperationsStub; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonGameServerConfigsServiceStub create( + GameServerConfigsServiceStubSettings settings) throws IOException { + return new HttpJsonGameServerConfigsServiceStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonGameServerConfigsServiceStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonGameServerConfigsServiceStub( + GameServerConfigsServiceStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonGameServerConfigsServiceStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonGameServerConfigsServiceStub( + GameServerConfigsServiceStubSettings.newHttpJsonBuilder().build(), + clientContext, + callableFactory); + } + + /** + * Constructs an instance of HttpJsonGameServerConfigsServiceStub, 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 HttpJsonGameServerConfigsServiceStub( + GameServerConfigsServiceStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new HttpJsonGameServerConfigsServiceCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonGameServerConfigsServiceStub, 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 HttpJsonGameServerConfigsServiceStub( + GameServerConfigsServiceStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.httpJsonOperationsStub = + HttpJsonOperationsStub.create(clientContext, callableFactory, typeRegistry); + + HttpJsonCallSettings + listGameServerConfigsTransportSettings = + HttpJsonCallSettings + .newBuilder() + .setMethodDescriptor(listGameServerConfigsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + getGameServerConfigTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getGameServerConfigMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + createGameServerConfigTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createGameServerConfigMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + deleteGameServerConfigTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteGameServerConfigMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.listGameServerConfigsCallable = + callableFactory.createUnaryCallable( + listGameServerConfigsTransportSettings, + settings.listGameServerConfigsSettings(), + clientContext); + this.listGameServerConfigsPagedCallable = + callableFactory.createPagedCallable( + listGameServerConfigsTransportSettings, + settings.listGameServerConfigsSettings(), + clientContext); + this.getGameServerConfigCallable = + callableFactory.createUnaryCallable( + getGameServerConfigTransportSettings, + settings.getGameServerConfigSettings(), + clientContext); + this.createGameServerConfigCallable = + callableFactory.createUnaryCallable( + createGameServerConfigTransportSettings, + settings.createGameServerConfigSettings(), + clientContext); + this.createGameServerConfigOperationCallable = + callableFactory.createOperationCallable( + createGameServerConfigTransportSettings, + settings.createGameServerConfigOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.deleteGameServerConfigCallable = + callableFactory.createUnaryCallable( + deleteGameServerConfigTransportSettings, + settings.deleteGameServerConfigSettings(), + clientContext); + this.deleteGameServerConfigOperationCallable = + callableFactory.createOperationCallable( + deleteGameServerConfigTransportSettings, + settings.deleteGameServerConfigOperationSettings(), + clientContext, + httpJsonOperationsStub); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(listGameServerConfigsMethodDescriptor); + methodDescriptors.add(getGameServerConfigMethodDescriptor); + methodDescriptors.add(createGameServerConfigMethodDescriptor); + methodDescriptors.add(deleteGameServerConfigMethodDescriptor); + return methodDescriptors; + } + + public HttpJsonOperationsStub getHttpJsonOperationsStub() { + return httpJsonOperationsStub; + } + + @Override + public UnaryCallable + listGameServerConfigsCallable() { + return listGameServerConfigsCallable; + } + + @Override + public UnaryCallable + listGameServerConfigsPagedCallable() { + return listGameServerConfigsPagedCallable; + } + + @Override + public UnaryCallable getGameServerConfigCallable() { + return getGameServerConfigCallable; + } + + @Override + public UnaryCallable createGameServerConfigCallable() { + return createGameServerConfigCallable; + } + + @Override + public OperationCallable + createGameServerConfigOperationCallable() { + return createGameServerConfigOperationCallable; + } + + @Override + public UnaryCallable deleteGameServerConfigCallable() { + return deleteGameServerConfigCallable; + } + + @Override + public OperationCallable + deleteGameServerConfigOperationCallable() { + return deleteGameServerConfigOperationCallable; + } + + @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/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/HttpJsonGameServerDeploymentsServiceCallableFactory.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/HttpJsonGameServerDeploymentsServiceCallableFactory.java new file mode 100644 index 000000000000..e70b50fdb704 --- /dev/null +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/HttpJsonGameServerDeploymentsServiceCallableFactory.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.cloud.gaming.v1.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 GameServerDeploymentsService service API. + * + *

This class is for advanced usage. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonGameServerDeploymentsServiceCallableFactory + 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/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/HttpJsonGameServerDeploymentsServiceStub.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/HttpJsonGameServerDeploymentsServiceStub.java new file mode 100644 index 000000000000..8fe0b74443fc --- /dev/null +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/HttpJsonGameServerDeploymentsServiceStub.java @@ -0,0 +1,806 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.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.cloud.gaming.v1.stub; + +import static com.google.cloud.gaming.v1.GameServerDeploymentsServiceClient.ListGameServerDeploymentsPagedResponse; + +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.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.gaming.v1.CreateGameServerDeploymentRequest; +import com.google.cloud.gaming.v1.DeleteGameServerDeploymentRequest; +import com.google.cloud.gaming.v1.FetchDeploymentStateRequest; +import com.google.cloud.gaming.v1.FetchDeploymentStateResponse; +import com.google.cloud.gaming.v1.GameServerDeployment; +import com.google.cloud.gaming.v1.GameServerDeploymentRollout; +import com.google.cloud.gaming.v1.GetGameServerDeploymentRequest; +import com.google.cloud.gaming.v1.GetGameServerDeploymentRolloutRequest; +import com.google.cloud.gaming.v1.ListGameServerDeploymentsRequest; +import com.google.cloud.gaming.v1.ListGameServerDeploymentsResponse; +import com.google.cloud.gaming.v1.OperationMetadata; +import com.google.cloud.gaming.v1.PreviewGameServerDeploymentRolloutRequest; +import com.google.cloud.gaming.v1.PreviewGameServerDeploymentRolloutResponse; +import com.google.cloud.gaming.v1.UpdateGameServerDeploymentRequest; +import com.google.cloud.gaming.v1.UpdateGameServerDeploymentRolloutRequest; +import com.google.longrunning.Operation; +import com.google.protobuf.Empty; +import com.google.protobuf.TypeRegistry; +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 GameServerDeploymentsService service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonGameServerDeploymentsServiceStub extends GameServerDeploymentsServiceStub { + private static final TypeRegistry typeRegistry = + TypeRegistry.newBuilder() + .add(OperationMetadata.getDescriptor()) + .add(Empty.getDescriptor()) + .add(GameServerDeployment.getDescriptor()) + .build(); + + private static final ApiMethodDescriptor< + ListGameServerDeploymentsRequest, ListGameServerDeploymentsResponse> + listGameServerDeploymentsMethodDescriptor = + ApiMethodDescriptor + .newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1.GameServerDeploymentsService/ListGameServerDeployments") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*}/gameServerDeployments", + 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, "filter", request.getFilter()); + serializer.putQueryParam(fields, "orderBy", request.getOrderBy()); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListGameServerDeploymentsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getGameServerDeploymentMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1.GameServerDeploymentsService/GetGameServerDeployment") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/gameServerDeployments/*}", + 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(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(GameServerDeployment.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + createGameServerDeploymentMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1.GameServerDeploymentsService/CreateGameServerDeployment") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*}/gameServerDeployments", + 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, "deploymentId", request.getDeploymentId()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody( + "gameServerDeployment", request.getGameServerDeployment())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (CreateGameServerDeploymentRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + deleteGameServerDeploymentMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1.GameServerDeploymentsService/DeleteGameServerDeployment") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/gameServerDeployments/*}", + 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(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (DeleteGameServerDeploymentRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + updateGameServerDeploymentMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1.GameServerDeploymentsService/UpdateGameServerDeployment") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{gameServerDeployment.name=projects/*/locations/*/gameServerDeployments/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam( + fields, + "gameServerDeployment.name", + request.getGameServerDeployment().getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody( + "gameServerDeployment", request.getGameServerDeployment())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (UpdateGameServerDeploymentRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor< + GetGameServerDeploymentRolloutRequest, GameServerDeploymentRollout> + getGameServerDeploymentRolloutMethodDescriptor = + ApiMethodDescriptor + .newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1.GameServerDeploymentsService/GetGameServerDeploymentRollout") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/gameServerDeployments/*}/rollout", + 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(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(GameServerDeploymentRollout.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + updateGameServerDeploymentRolloutMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1.GameServerDeploymentsService/UpdateGameServerDeploymentRollout") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter + .newBuilder() + .setPath( + "/v1/{rollout.name=projects/*/locations/*/gameServerDeployments/*}/rollout", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer + serializer = ProtoRestSerializer.create(); + serializer.putPathParam( + fields, "rollout.name", request.getRollout().getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer + serializer = ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create().toBody("rollout", request.getRollout())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (UpdateGameServerDeploymentRolloutRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor< + PreviewGameServerDeploymentRolloutRequest, PreviewGameServerDeploymentRolloutResponse> + previewGameServerDeploymentRolloutMethodDescriptor = + ApiMethodDescriptor + . + newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1.GameServerDeploymentsService/PreviewGameServerDeploymentRollout") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter + .newBuilder() + .setPath( + "/v1/{rollout.name=projects/*/locations/*/gameServerDeployments/*}/rollout:preview", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer + serializer = ProtoRestSerializer.create(); + serializer.putPathParam( + fields, "rollout.name", request.getRollout().getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer + serializer = ProtoRestSerializer.create(); + serializer.putQueryParam( + fields, "previewTime", request.getPreviewTime()); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create().toBody("rollout", request.getRollout())) + .build()) + .setResponseParser( + ProtoMessageResponseParser + .newBuilder() + .setDefaultInstance( + PreviewGameServerDeploymentRolloutResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor< + FetchDeploymentStateRequest, FetchDeploymentStateResponse> + fetchDeploymentStateMethodDescriptor = + ApiMethodDescriptor + .newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1.GameServerDeploymentsService/FetchDeploymentState") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/gameServerDeployments/*}:fetchDeploymentState", + 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(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearName().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(FetchDeploymentStateResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private final UnaryCallable + listGameServerDeploymentsCallable; + private final UnaryCallable< + ListGameServerDeploymentsRequest, ListGameServerDeploymentsPagedResponse> + listGameServerDeploymentsPagedCallable; + private final UnaryCallable + getGameServerDeploymentCallable; + private final UnaryCallable + createGameServerDeploymentCallable; + private final OperationCallable< + CreateGameServerDeploymentRequest, GameServerDeployment, OperationMetadata> + createGameServerDeploymentOperationCallable; + private final UnaryCallable + deleteGameServerDeploymentCallable; + private final OperationCallable + deleteGameServerDeploymentOperationCallable; + private final UnaryCallable + updateGameServerDeploymentCallable; + private final OperationCallable< + UpdateGameServerDeploymentRequest, GameServerDeployment, OperationMetadata> + updateGameServerDeploymentOperationCallable; + private final UnaryCallable + getGameServerDeploymentRolloutCallable; + private final UnaryCallable + updateGameServerDeploymentRolloutCallable; + private final OperationCallable< + UpdateGameServerDeploymentRolloutRequest, GameServerDeployment, OperationMetadata> + updateGameServerDeploymentRolloutOperationCallable; + private final UnaryCallable< + PreviewGameServerDeploymentRolloutRequest, PreviewGameServerDeploymentRolloutResponse> + previewGameServerDeploymentRolloutCallable; + private final UnaryCallable + fetchDeploymentStateCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonOperationsStub httpJsonOperationsStub; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonGameServerDeploymentsServiceStub create( + GameServerDeploymentsServiceStubSettings settings) throws IOException { + return new HttpJsonGameServerDeploymentsServiceStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonGameServerDeploymentsServiceStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonGameServerDeploymentsServiceStub( + GameServerDeploymentsServiceStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonGameServerDeploymentsServiceStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonGameServerDeploymentsServiceStub( + GameServerDeploymentsServiceStubSettings.newHttpJsonBuilder().build(), + clientContext, + callableFactory); + } + + /** + * Constructs an instance of HttpJsonGameServerDeploymentsServiceStub, 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 HttpJsonGameServerDeploymentsServiceStub( + GameServerDeploymentsServiceStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new HttpJsonGameServerDeploymentsServiceCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonGameServerDeploymentsServiceStub, 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 HttpJsonGameServerDeploymentsServiceStub( + GameServerDeploymentsServiceStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.httpJsonOperationsStub = + HttpJsonOperationsStub.create(clientContext, callableFactory, typeRegistry); + + HttpJsonCallSettings + listGameServerDeploymentsTransportSettings = + HttpJsonCallSettings + .newBuilder() + .setMethodDescriptor(listGameServerDeploymentsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + getGameServerDeploymentTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getGameServerDeploymentMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + createGameServerDeploymentTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createGameServerDeploymentMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + deleteGameServerDeploymentTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteGameServerDeploymentMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + updateGameServerDeploymentTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateGameServerDeploymentMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + getGameServerDeploymentRolloutTransportSettings = + HttpJsonCallSettings + .newBuilder() + .setMethodDescriptor(getGameServerDeploymentRolloutMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + updateGameServerDeploymentRolloutTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateGameServerDeploymentRolloutMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings< + PreviewGameServerDeploymentRolloutRequest, PreviewGameServerDeploymentRolloutResponse> + previewGameServerDeploymentRolloutTransportSettings = + HttpJsonCallSettings + . + newBuilder() + .setMethodDescriptor(previewGameServerDeploymentRolloutMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + fetchDeploymentStateTransportSettings = + HttpJsonCallSettings + .newBuilder() + .setMethodDescriptor(fetchDeploymentStateMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.listGameServerDeploymentsCallable = + callableFactory.createUnaryCallable( + listGameServerDeploymentsTransportSettings, + settings.listGameServerDeploymentsSettings(), + clientContext); + this.listGameServerDeploymentsPagedCallable = + callableFactory.createPagedCallable( + listGameServerDeploymentsTransportSettings, + settings.listGameServerDeploymentsSettings(), + clientContext); + this.getGameServerDeploymentCallable = + callableFactory.createUnaryCallable( + getGameServerDeploymentTransportSettings, + settings.getGameServerDeploymentSettings(), + clientContext); + this.createGameServerDeploymentCallable = + callableFactory.createUnaryCallable( + createGameServerDeploymentTransportSettings, + settings.createGameServerDeploymentSettings(), + clientContext); + this.createGameServerDeploymentOperationCallable = + callableFactory.createOperationCallable( + createGameServerDeploymentTransportSettings, + settings.createGameServerDeploymentOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.deleteGameServerDeploymentCallable = + callableFactory.createUnaryCallable( + deleteGameServerDeploymentTransportSettings, + settings.deleteGameServerDeploymentSettings(), + clientContext); + this.deleteGameServerDeploymentOperationCallable = + callableFactory.createOperationCallable( + deleteGameServerDeploymentTransportSettings, + settings.deleteGameServerDeploymentOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.updateGameServerDeploymentCallable = + callableFactory.createUnaryCallable( + updateGameServerDeploymentTransportSettings, + settings.updateGameServerDeploymentSettings(), + clientContext); + this.updateGameServerDeploymentOperationCallable = + callableFactory.createOperationCallable( + updateGameServerDeploymentTransportSettings, + settings.updateGameServerDeploymentOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.getGameServerDeploymentRolloutCallable = + callableFactory.createUnaryCallable( + getGameServerDeploymentRolloutTransportSettings, + settings.getGameServerDeploymentRolloutSettings(), + clientContext); + this.updateGameServerDeploymentRolloutCallable = + callableFactory.createUnaryCallable( + updateGameServerDeploymentRolloutTransportSettings, + settings.updateGameServerDeploymentRolloutSettings(), + clientContext); + this.updateGameServerDeploymentRolloutOperationCallable = + callableFactory.createOperationCallable( + updateGameServerDeploymentRolloutTransportSettings, + settings.updateGameServerDeploymentRolloutOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.previewGameServerDeploymentRolloutCallable = + callableFactory.createUnaryCallable( + previewGameServerDeploymentRolloutTransportSettings, + settings.previewGameServerDeploymentRolloutSettings(), + clientContext); + this.fetchDeploymentStateCallable = + callableFactory.createUnaryCallable( + fetchDeploymentStateTransportSettings, + settings.fetchDeploymentStateSettings(), + clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(listGameServerDeploymentsMethodDescriptor); + methodDescriptors.add(getGameServerDeploymentMethodDescriptor); + methodDescriptors.add(createGameServerDeploymentMethodDescriptor); + methodDescriptors.add(deleteGameServerDeploymentMethodDescriptor); + methodDescriptors.add(updateGameServerDeploymentMethodDescriptor); + methodDescriptors.add(getGameServerDeploymentRolloutMethodDescriptor); + methodDescriptors.add(updateGameServerDeploymentRolloutMethodDescriptor); + methodDescriptors.add(previewGameServerDeploymentRolloutMethodDescriptor); + methodDescriptors.add(fetchDeploymentStateMethodDescriptor); + return methodDescriptors; + } + + public HttpJsonOperationsStub getHttpJsonOperationsStub() { + return httpJsonOperationsStub; + } + + @Override + public UnaryCallable + listGameServerDeploymentsCallable() { + return listGameServerDeploymentsCallable; + } + + @Override + public UnaryCallable + listGameServerDeploymentsPagedCallable() { + return listGameServerDeploymentsPagedCallable; + } + + @Override + public UnaryCallable + getGameServerDeploymentCallable() { + return getGameServerDeploymentCallable; + } + + @Override + public UnaryCallable + createGameServerDeploymentCallable() { + return createGameServerDeploymentCallable; + } + + @Override + public OperationCallable< + CreateGameServerDeploymentRequest, GameServerDeployment, OperationMetadata> + createGameServerDeploymentOperationCallable() { + return createGameServerDeploymentOperationCallable; + } + + @Override + public UnaryCallable + deleteGameServerDeploymentCallable() { + return deleteGameServerDeploymentCallable; + } + + @Override + public OperationCallable + deleteGameServerDeploymentOperationCallable() { + return deleteGameServerDeploymentOperationCallable; + } + + @Override + public UnaryCallable + updateGameServerDeploymentCallable() { + return updateGameServerDeploymentCallable; + } + + @Override + public OperationCallable< + UpdateGameServerDeploymentRequest, GameServerDeployment, OperationMetadata> + updateGameServerDeploymentOperationCallable() { + return updateGameServerDeploymentOperationCallable; + } + + @Override + public UnaryCallable + getGameServerDeploymentRolloutCallable() { + return getGameServerDeploymentRolloutCallable; + } + + @Override + public UnaryCallable + updateGameServerDeploymentRolloutCallable() { + return updateGameServerDeploymentRolloutCallable; + } + + @Override + public OperationCallable< + UpdateGameServerDeploymentRolloutRequest, GameServerDeployment, OperationMetadata> + updateGameServerDeploymentRolloutOperationCallable() { + return updateGameServerDeploymentRolloutOperationCallable; + } + + @Override + public UnaryCallable< + PreviewGameServerDeploymentRolloutRequest, PreviewGameServerDeploymentRolloutResponse> + previewGameServerDeploymentRolloutCallable() { + return previewGameServerDeploymentRolloutCallable; + } + + @Override + public UnaryCallable + fetchDeploymentStateCallable() { + return fetchDeploymentStateCallable; + } + + @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/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/HttpJsonRealmsServiceCallableFactory.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/HttpJsonRealmsServiceCallableFactory.java new file mode 100644 index 000000000000..9681c3cccc11 --- /dev/null +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/HttpJsonRealmsServiceCallableFactory.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.cloud.gaming.v1.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 RealmsService service API. + * + *

This class is for advanced usage. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonRealmsServiceCallableFactory + 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/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/HttpJsonRealmsServiceStub.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/HttpJsonRealmsServiceStub.java new file mode 100644 index 000000000000..325121f1c0f5 --- /dev/null +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/HttpJsonRealmsServiceStub.java @@ -0,0 +1,539 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.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.cloud.gaming.v1.stub; + +import static com.google.cloud.gaming.v1.RealmsServiceClient.ListRealmsPagedResponse; + +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.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.gaming.v1.CreateRealmRequest; +import com.google.cloud.gaming.v1.DeleteRealmRequest; +import com.google.cloud.gaming.v1.GetRealmRequest; +import com.google.cloud.gaming.v1.ListRealmsRequest; +import com.google.cloud.gaming.v1.ListRealmsResponse; +import com.google.cloud.gaming.v1.OperationMetadata; +import com.google.cloud.gaming.v1.PreviewRealmUpdateRequest; +import com.google.cloud.gaming.v1.PreviewRealmUpdateResponse; +import com.google.cloud.gaming.v1.Realm; +import com.google.cloud.gaming.v1.UpdateRealmRequest; +import com.google.longrunning.Operation; +import com.google.protobuf.Empty; +import com.google.protobuf.TypeRegistry; +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 RealmsService service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonRealmsServiceStub extends RealmsServiceStub { + private static final TypeRegistry typeRegistry = + TypeRegistry.newBuilder() + .add(OperationMetadata.getDescriptor()) + .add(Empty.getDescriptor()) + .add(Realm.getDescriptor()) + .build(); + + private static final ApiMethodDescriptor + listRealmsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.gaming.v1.RealmsService/ListRealms") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*}/realms", + 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, "filter", request.getFilter()); + serializer.putQueryParam(fields, "orderBy", request.getOrderBy()); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListRealmsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor getRealmMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.gaming.v1.RealmsService/GetRealm") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/realms/*}", + 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(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Realm.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + createRealmMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.gaming.v1.RealmsService/CreateRealm") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*}/realms", + 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, "realmId", request.getRealmId()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create().toBody("realm", request.getRealm())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (CreateRealmRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + deleteRealmMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.gaming.v1.RealmsService/DeleteRealm") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/realms/*}", + 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(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (DeleteRealmRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + updateRealmMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.gaming.v1.RealmsService/UpdateRealm") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{realm.name=projects/*/locations/*/realms/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam( + fields, "realm.name", request.getRealm().getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create().toBody("realm", request.getRealm())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (UpdateRealmRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + previewRealmUpdateMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.gaming.v1.RealmsService/PreviewRealmUpdate") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{realm.name=projects/*/locations/*/realms/*}:previewUpdate", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam( + fields, "realm.name", request.getRealm().getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam( + fields, "previewTime", request.getPreviewTime()); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create().toBody("realm", request.getRealm())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(PreviewRealmUpdateResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private final UnaryCallable listRealmsCallable; + private final UnaryCallable listRealmsPagedCallable; + private final UnaryCallable getRealmCallable; + private final UnaryCallable createRealmCallable; + private final OperationCallable + createRealmOperationCallable; + private final UnaryCallable deleteRealmCallable; + private final OperationCallable + deleteRealmOperationCallable; + private final UnaryCallable updateRealmCallable; + private final OperationCallable + updateRealmOperationCallable; + private final UnaryCallable + previewRealmUpdateCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonOperationsStub httpJsonOperationsStub; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonRealmsServiceStub create(RealmsServiceStubSettings settings) + throws IOException { + return new HttpJsonRealmsServiceStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonRealmsServiceStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonRealmsServiceStub( + RealmsServiceStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonRealmsServiceStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonRealmsServiceStub( + RealmsServiceStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonRealmsServiceStub, 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 HttpJsonRealmsServiceStub( + RealmsServiceStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new HttpJsonRealmsServiceCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonRealmsServiceStub, 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 HttpJsonRealmsServiceStub( + RealmsServiceStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.httpJsonOperationsStub = + HttpJsonOperationsStub.create(clientContext, callableFactory, typeRegistry); + + HttpJsonCallSettings listRealmsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listRealmsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getRealmTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getRealmMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings createRealmTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createRealmMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deleteRealmTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteRealmMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings updateRealmTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateRealmMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + previewRealmUpdateTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(previewRealmUpdateMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.listRealmsCallable = + callableFactory.createUnaryCallable( + listRealmsTransportSettings, settings.listRealmsSettings(), clientContext); + this.listRealmsPagedCallable = + callableFactory.createPagedCallable( + listRealmsTransportSettings, settings.listRealmsSettings(), clientContext); + this.getRealmCallable = + callableFactory.createUnaryCallable( + getRealmTransportSettings, settings.getRealmSettings(), clientContext); + this.createRealmCallable = + callableFactory.createUnaryCallable( + createRealmTransportSettings, settings.createRealmSettings(), clientContext); + this.createRealmOperationCallable = + callableFactory.createOperationCallable( + createRealmTransportSettings, + settings.createRealmOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.deleteRealmCallable = + callableFactory.createUnaryCallable( + deleteRealmTransportSettings, settings.deleteRealmSettings(), clientContext); + this.deleteRealmOperationCallable = + callableFactory.createOperationCallable( + deleteRealmTransportSettings, + settings.deleteRealmOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.updateRealmCallable = + callableFactory.createUnaryCallable( + updateRealmTransportSettings, settings.updateRealmSettings(), clientContext); + this.updateRealmOperationCallable = + callableFactory.createOperationCallable( + updateRealmTransportSettings, + settings.updateRealmOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.previewRealmUpdateCallable = + callableFactory.createUnaryCallable( + previewRealmUpdateTransportSettings, + settings.previewRealmUpdateSettings(), + clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(listRealmsMethodDescriptor); + methodDescriptors.add(getRealmMethodDescriptor); + methodDescriptors.add(createRealmMethodDescriptor); + methodDescriptors.add(deleteRealmMethodDescriptor); + methodDescriptors.add(updateRealmMethodDescriptor); + methodDescriptors.add(previewRealmUpdateMethodDescriptor); + return methodDescriptors; + } + + public HttpJsonOperationsStub getHttpJsonOperationsStub() { + return httpJsonOperationsStub; + } + + @Override + public UnaryCallable listRealmsCallable() { + return listRealmsCallable; + } + + @Override + public UnaryCallable listRealmsPagedCallable() { + return listRealmsPagedCallable; + } + + @Override + public UnaryCallable getRealmCallable() { + return getRealmCallable; + } + + @Override + public UnaryCallable createRealmCallable() { + return createRealmCallable; + } + + @Override + public OperationCallable + createRealmOperationCallable() { + return createRealmOperationCallable; + } + + @Override + public UnaryCallable deleteRealmCallable() { + return deleteRealmCallable; + } + + @Override + public OperationCallable + deleteRealmOperationCallable() { + return deleteRealmOperationCallable; + } + + @Override + public UnaryCallable updateRealmCallable() { + return updateRealmCallable; + } + + @Override + public OperationCallable + updateRealmOperationCallable() { + return updateRealmOperationCallable; + } + + @Override + public UnaryCallable + previewRealmUpdateCallable() { + return previewRealmUpdateCallable; + } + + @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/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/RealmsServiceStub.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/RealmsServiceStub.java index d8fa3f53ea93..eb677393fd00 100644 --- a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/RealmsServiceStub.java +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/RealmsServiceStub.java @@ -46,7 +46,11 @@ public abstract class RealmsServiceStub implements BackgroundResource { public OperationsStub getOperationsStub() { - throw new UnsupportedOperationException("Not implemented: getOperationsStub()"); + return null; + } + + public com.google.api.gax.httpjson.longrunning.stub.OperationsStub getHttpJsonOperationsStub() { + return null; } public UnaryCallable listRealmsPagedCallable() { diff --git a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/RealmsServiceStubSettings.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/RealmsServiceStubSettings.java index 55652cb2b818..b0e5817ae6e3 100644 --- a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/RealmsServiceStubSettings.java +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1/stub/RealmsServiceStubSettings.java @@ -28,6 +28,9 @@ 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; @@ -229,6 +232,11 @@ public RealmsServiceStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcRealmsServiceStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonRealmsServiceStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -261,18 +269,25 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde .setUseJwtAccessWithScope(true); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** 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 defaultApiClientHeaderProviderBuilder() { + public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() { return ApiClientHeaderProvider.newBuilder() .setGeneratedLibToken( "gapic", GaxProperties.getLibraryVersion(RealmsServiceStubSettings.class)) @@ -280,11 +295,30 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); } - /** Returns a new builder for this class. */ + @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(RealmsServiceStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return RealmsServiceStubSettings.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); @@ -432,6 +466,19 @@ private static Builder createDefault() { 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 .listRealmsSettings() diff --git a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/GameServerClustersServiceClient.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/GameServerClustersServiceClient.java index 2c18bce494f6..27443a66ab26 100644 --- a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/GameServerClustersServiceClient.java +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/GameServerClustersServiceClient.java @@ -20,6 +20,7 @@ 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; @@ -31,7 +32,6 @@ import com.google.cloud.gaming.v1beta.stub.GameServerClustersServiceStubSettings; import com.google.common.util.concurrent.MoreExecutors; import com.google.longrunning.Operation; -import com.google.longrunning.OperationsClient; import com.google.protobuf.Empty; import com.google.protobuf.FieldMask; import java.io.IOException; @@ -109,6 +109,21 @@ * GameServerClustersServiceClient.create(gameServerClustersServiceSettings); * } * + *

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 for illustrative purposes only.
+ * // It may require modifications to work in your environment.
+ * GameServerClustersServiceSettings gameServerClustersServiceSettings =
+ *     GameServerClustersServiceSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             GameServerClustersServiceSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * GameServerClustersServiceClient gameServerClustersServiceClient =
+ *     GameServerClustersServiceClient.create(gameServerClustersServiceSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @BetaApi @@ -116,7 +131,8 @@ public class GameServerClustersServiceClient implements BackgroundResource { private final GameServerClustersServiceSettings settings; private final GameServerClustersServiceStub stub; - private final OperationsClient operationsClient; + private final OperationsClient httpJsonOperationsClient; + private final com.google.longrunning.OperationsClient operationsClient; /** Constructs an instance of GameServerClustersServiceClient with default settings. */ public static final GameServerClustersServiceClient create() throws IOException { @@ -150,13 +166,17 @@ protected GameServerClustersServiceClient(GameServerClustersServiceSettings sett throws IOException { this.settings = settings; this.stub = ((GameServerClustersServiceStubSettings) settings.getStubSettings()).createStub(); - this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + this.operationsClient = + com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); + this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); } protected GameServerClustersServiceClient(GameServerClustersServiceStub stub) { this.settings = null; this.stub = stub; - this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + this.operationsClient = + com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); + this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); } public final GameServerClustersServiceSettings getSettings() { @@ -171,10 +191,18 @@ public GameServerClustersServiceStub getStub() { * 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() { + 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. + */ + public final OperationsClient getHttpJsonOperationsClient() { + return httpJsonOperationsClient; + } + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Lists game server clusters in a given project and location. diff --git a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/GameServerClustersServiceSettings.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/GameServerClustersServiceSettings.java index 3d5e6818899c..ee4cce12d33c 100644 --- a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/GameServerClustersServiceSettings.java +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/GameServerClustersServiceSettings.java @@ -23,6 +23,7 @@ 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; @@ -185,11 +186,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return GameServerClustersServiceStubSettings.defaultCredentialsProviderBuilder(); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return GameServerClustersServiceStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return GameServerClustersServiceStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return GameServerClustersServiceStubSettings.defaultTransportChannelProvider(); } @@ -199,11 +207,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return GameServerClustersServiceStubSettings.defaultApiClientHeaderProviderBuilder(); } - /** Returns a new builder for this class. */ + /** 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); @@ -242,6 +256,11 @@ private static Builder createDefault() { return new Builder(GameServerClustersServiceStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(GameServerClustersServiceStubSettings.newHttpJsonBuilder()); + } + public GameServerClustersServiceStubSettings.Builder getStubSettingsBuilder() { return ((GameServerClustersServiceStubSettings.Builder) getStubSettings()); } diff --git a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/GameServerConfigsServiceClient.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/GameServerConfigsServiceClient.java index fad05488792a..d05af6ed3207 100644 --- a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/GameServerConfigsServiceClient.java +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/GameServerConfigsServiceClient.java @@ -20,6 +20,7 @@ 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; @@ -31,7 +32,6 @@ import com.google.cloud.gaming.v1beta.stub.GameServerConfigsServiceStubSettings; import com.google.common.util.concurrent.MoreExecutors; import com.google.longrunning.Operation; -import com.google.longrunning.OperationsClient; import com.google.protobuf.Empty; import java.io.IOException; import java.util.List; @@ -107,6 +107,21 @@ * GameServerConfigsServiceClient.create(gameServerConfigsServiceSettings); * } * + *

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 for illustrative purposes only.
+ * // It may require modifications to work in your environment.
+ * GameServerConfigsServiceSettings gameServerConfigsServiceSettings =
+ *     GameServerConfigsServiceSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             GameServerConfigsServiceSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * GameServerConfigsServiceClient gameServerConfigsServiceClient =
+ *     GameServerConfigsServiceClient.create(gameServerConfigsServiceSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @BetaApi @@ -114,7 +129,8 @@ public class GameServerConfigsServiceClient implements BackgroundResource { private final GameServerConfigsServiceSettings settings; private final GameServerConfigsServiceStub stub; - private final OperationsClient operationsClient; + private final OperationsClient httpJsonOperationsClient; + private final com.google.longrunning.OperationsClient operationsClient; /** Constructs an instance of GameServerConfigsServiceClient with default settings. */ public static final GameServerConfigsServiceClient create() throws IOException { @@ -148,13 +164,17 @@ protected GameServerConfigsServiceClient(GameServerConfigsServiceSettings settin throws IOException { this.settings = settings; this.stub = ((GameServerConfigsServiceStubSettings) settings.getStubSettings()).createStub(); - this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + this.operationsClient = + com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); + this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); } protected GameServerConfigsServiceClient(GameServerConfigsServiceStub stub) { this.settings = null; this.stub = stub; - this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + this.operationsClient = + com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); + this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); } public final GameServerConfigsServiceSettings getSettings() { @@ -169,10 +189,18 @@ public GameServerConfigsServiceStub getStub() { * 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() { + 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. + */ + public final OperationsClient getHttpJsonOperationsClient() { + return httpJsonOperationsClient; + } + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Lists game server configs in a given project, location, and game server deployment. diff --git a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/GameServerConfigsServiceSettings.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/GameServerConfigsServiceSettings.java index 41f45a27a72a..a685e4de7452 100644 --- a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/GameServerConfigsServiceSettings.java +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/GameServerConfigsServiceSettings.java @@ -23,6 +23,7 @@ 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; @@ -146,11 +147,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return GameServerConfigsServiceStubSettings.defaultCredentialsProviderBuilder(); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return GameServerConfigsServiceStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return GameServerConfigsServiceStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return GameServerConfigsServiceStubSettings.defaultTransportChannelProvider(); } @@ -160,11 +168,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return GameServerConfigsServiceStubSettings.defaultApiClientHeaderProviderBuilder(); } - /** Returns a new builder for this class. */ + /** 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); @@ -203,6 +217,11 @@ private static Builder createDefault() { return new Builder(GameServerConfigsServiceStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(GameServerConfigsServiceStubSettings.newHttpJsonBuilder()); + } + public GameServerConfigsServiceStubSettings.Builder getStubSettingsBuilder() { return ((GameServerConfigsServiceStubSettings.Builder) getStubSettings()); } diff --git a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/GameServerDeploymentsServiceClient.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/GameServerDeploymentsServiceClient.java index 3a685ce7c02c..670c1be21396 100644 --- a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/GameServerDeploymentsServiceClient.java +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/GameServerDeploymentsServiceClient.java @@ -20,6 +20,7 @@ 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; @@ -31,7 +32,6 @@ import com.google.cloud.gaming.v1beta.stub.GameServerDeploymentsServiceStubSettings; import com.google.common.util.concurrent.MoreExecutors; import com.google.longrunning.Operation; -import com.google.longrunning.OperationsClient; import com.google.protobuf.Empty; import com.google.protobuf.FieldMask; import java.io.IOException; @@ -110,6 +110,22 @@ * GameServerDeploymentsServiceClient.create(gameServerDeploymentsServiceSettings); * } * + *

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 for illustrative purposes only.
+ * // It may require modifications to work in your environment.
+ * GameServerDeploymentsServiceSettings gameServerDeploymentsServiceSettings =
+ *     GameServerDeploymentsServiceSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             GameServerDeploymentsServiceSettings.defaultHttpJsonTransportProviderBuilder()
+ *                 .build())
+ *         .build();
+ * GameServerDeploymentsServiceClient gameServerDeploymentsServiceClient =
+ *     GameServerDeploymentsServiceClient.create(gameServerDeploymentsServiceSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @BetaApi @@ -117,7 +133,8 @@ public class GameServerDeploymentsServiceClient implements BackgroundResource { private final GameServerDeploymentsServiceSettings settings; private final GameServerDeploymentsServiceStub stub; - private final OperationsClient operationsClient; + private final OperationsClient httpJsonOperationsClient; + private final com.google.longrunning.OperationsClient operationsClient; /** Constructs an instance of GameServerDeploymentsServiceClient with default settings. */ public static final GameServerDeploymentsServiceClient create() throws IOException { @@ -153,13 +170,17 @@ protected GameServerDeploymentsServiceClient(GameServerDeploymentsServiceSetting this.settings = settings; this.stub = ((GameServerDeploymentsServiceStubSettings) settings.getStubSettings()).createStub(); - this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + this.operationsClient = + com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); + this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); } protected GameServerDeploymentsServiceClient(GameServerDeploymentsServiceStub stub) { this.settings = null; this.stub = stub; - this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + this.operationsClient = + com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); + this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); } public final GameServerDeploymentsServiceSettings getSettings() { @@ -174,10 +195,18 @@ public GameServerDeploymentsServiceStub getStub() { * 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() { + 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. + */ + public final OperationsClient getHttpJsonOperationsClient() { + return httpJsonOperationsClient; + } + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Lists game server deployments in a given project and location. diff --git a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/GameServerDeploymentsServiceSettings.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/GameServerDeploymentsServiceSettings.java index fd46c091e8b3..9a6d68cee9ff 100644 --- a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/GameServerDeploymentsServiceSettings.java +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/GameServerDeploymentsServiceSettings.java @@ -23,6 +23,7 @@ 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; @@ -200,11 +201,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return GameServerDeploymentsServiceStubSettings.defaultCredentialsProviderBuilder(); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return GameServerDeploymentsServiceStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return GameServerDeploymentsServiceStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return GameServerDeploymentsServiceStubSettings.defaultTransportChannelProvider(); } @@ -214,11 +222,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return GameServerDeploymentsServiceStubSettings.defaultApiClientHeaderProviderBuilder(); } - /** Returns a new builder for this class. */ + /** 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); @@ -257,6 +271,11 @@ private static Builder createDefault() { return new Builder(GameServerDeploymentsServiceStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(GameServerDeploymentsServiceStubSettings.newHttpJsonBuilder()); + } + public GameServerDeploymentsServiceStubSettings.Builder getStubSettingsBuilder() { return ((GameServerDeploymentsServiceStubSettings.Builder) getStubSettings()); } diff --git a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/RealmsServiceClient.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/RealmsServiceClient.java index da9da8d81e11..4bc2e4900b0f 100644 --- a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/RealmsServiceClient.java +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/RealmsServiceClient.java @@ -20,6 +20,7 @@ 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; @@ -31,7 +32,6 @@ import com.google.cloud.gaming.v1beta.stub.RealmsServiceStubSettings; import com.google.common.util.concurrent.MoreExecutors; import com.google.longrunning.Operation; -import com.google.longrunning.OperationsClient; import com.google.protobuf.Empty; import com.google.protobuf.FieldMask; import java.io.IOException; @@ -104,6 +104,20 @@ * RealmsServiceClient realmsServiceClient = RealmsServiceClient.create(realmsServiceSettings); * } * + *

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 for illustrative purposes only.
+ * // It may require modifications to work in your environment.
+ * RealmsServiceSettings realmsServiceSettings =
+ *     RealmsServiceSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             RealmsServiceSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * RealmsServiceClient realmsServiceClient = RealmsServiceClient.create(realmsServiceSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @BetaApi @@ -111,7 +125,8 @@ public class RealmsServiceClient implements BackgroundResource { private final RealmsServiceSettings settings; private final RealmsServiceStub stub; - private final OperationsClient operationsClient; + private final OperationsClient httpJsonOperationsClient; + private final com.google.longrunning.OperationsClient operationsClient; /** Constructs an instance of RealmsServiceClient with default settings. */ public static final RealmsServiceClient create() throws IOException { @@ -143,13 +158,17 @@ public static final RealmsServiceClient create(RealmsServiceStub stub) { protected RealmsServiceClient(RealmsServiceSettings settings) throws IOException { this.settings = settings; this.stub = ((RealmsServiceStubSettings) settings.getStubSettings()).createStub(); - this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + this.operationsClient = + com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); + this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); } protected RealmsServiceClient(RealmsServiceStub stub) { this.settings = null; this.stub = stub; - this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + this.operationsClient = + com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); + this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); } public final RealmsServiceSettings getSettings() { @@ -164,10 +183,18 @@ public RealmsServiceStub getStub() { * 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() { + 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. + */ + public final OperationsClient getHttpJsonOperationsClient() { + return httpJsonOperationsClient; + } + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Lists realms in a given project and location. diff --git a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/RealmsServiceSettings.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/RealmsServiceSettings.java index bccdb9f37509..8e51490a71dc 100644 --- a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/RealmsServiceSettings.java +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/RealmsServiceSettings.java @@ -23,6 +23,7 @@ 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; @@ -149,11 +150,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return RealmsServiceStubSettings.defaultCredentialsProviderBuilder(); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return RealmsServiceStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return RealmsServiceStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return RealmsServiceStubSettings.defaultTransportChannelProvider(); } @@ -163,11 +171,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return RealmsServiceStubSettings.defaultApiClientHeaderProviderBuilder(); } - /** Returns a new builder for this class. */ + /** 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); @@ -205,6 +219,11 @@ private static Builder createDefault() { return new Builder(RealmsServiceStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(RealmsServiceStubSettings.newHttpJsonBuilder()); + } + public RealmsServiceStubSettings.Builder getStubSettingsBuilder() { return ((RealmsServiceStubSettings.Builder) getStubSettings()); } diff --git a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/GameServerClustersServiceStub.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/GameServerClustersServiceStub.java index c1c2395d3b55..e3fc88cb16f2 100644 --- a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/GameServerClustersServiceStub.java +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/GameServerClustersServiceStub.java @@ -52,7 +52,11 @@ public abstract class GameServerClustersServiceStub implements BackgroundResource { public OperationsStub getOperationsStub() { - throw new UnsupportedOperationException("Not implemented: getOperationsStub()"); + return null; + } + + public com.google.api.gax.httpjson.longrunning.stub.OperationsStub getHttpJsonOperationsStub() { + return null; } public UnaryCallable diff --git a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/GameServerClustersServiceStubSettings.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/GameServerClustersServiceStubSettings.java index 42c73c87c831..4182a0af9014 100644 --- a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/GameServerClustersServiceStubSettings.java +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/GameServerClustersServiceStubSettings.java @@ -28,6 +28,9 @@ 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; @@ -291,6 +294,11 @@ public GameServerClustersServiceStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcGameServerClustersServiceStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonGameServerClustersServiceStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -323,18 +331,25 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde .setUseJwtAccessWithScope(true); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** 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 defaultApiClientHeaderProviderBuilder() { + public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() { return ApiClientHeaderProvider.newBuilder() .setGeneratedLibToken( "gapic", GaxProperties.getLibraryVersion(GameServerClustersServiceStubSettings.class)) @@ -342,11 +357,30 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); } - /** Returns a new builder for this class. */ + @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(GameServerClustersServiceStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return GameServerClustersServiceStubSettings.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); @@ -544,6 +578,19 @@ private static Builder createDefault() { 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 .listGameServerClustersSettings() diff --git a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/GameServerConfigsServiceStub.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/GameServerConfigsServiceStub.java index 8aa3d1d6cfec..9b60cf98a956 100644 --- a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/GameServerConfigsServiceStub.java +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/GameServerConfigsServiceStub.java @@ -45,7 +45,11 @@ public abstract class GameServerConfigsServiceStub implements BackgroundResource { public OperationsStub getOperationsStub() { - throw new UnsupportedOperationException("Not implemented: getOperationsStub()"); + return null; + } + + public com.google.api.gax.httpjson.longrunning.stub.OperationsStub getHttpJsonOperationsStub() { + return null; } public UnaryCallable diff --git a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/GameServerConfigsServiceStubSettings.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/GameServerConfigsServiceStubSettings.java index 6f15002a01f4..1be59707cbf1 100644 --- a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/GameServerConfigsServiceStubSettings.java +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/GameServerConfigsServiceStubSettings.java @@ -28,6 +28,9 @@ 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; @@ -232,6 +235,11 @@ public GameServerConfigsServiceStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcGameServerConfigsServiceStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonGameServerConfigsServiceStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -264,18 +272,25 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde .setUseJwtAccessWithScope(true); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** 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 defaultApiClientHeaderProviderBuilder() { + public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() { return ApiClientHeaderProvider.newBuilder() .setGeneratedLibToken( "gapic", GaxProperties.getLibraryVersion(GameServerConfigsServiceStubSettings.class)) @@ -283,11 +298,30 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); } - /** Returns a new builder for this class. */ + @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(GameServerConfigsServiceStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return GameServerConfigsServiceStubSettings.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); @@ -430,6 +464,19 @@ private static Builder createDefault() { 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 .listGameServerConfigsSettings() diff --git a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/GameServerDeploymentsServiceStub.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/GameServerDeploymentsServiceStub.java index 26ca40452e76..7fbba0f9e699 100644 --- a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/GameServerDeploymentsServiceStub.java +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/GameServerDeploymentsServiceStub.java @@ -53,7 +53,11 @@ public abstract class GameServerDeploymentsServiceStub implements BackgroundResource { public OperationsStub getOperationsStub() { - throw new UnsupportedOperationException("Not implemented: getOperationsStub()"); + return null; + } + + public com.google.api.gax.httpjson.longrunning.stub.OperationsStub getHttpJsonOperationsStub() { + return null; } public UnaryCallable diff --git a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/GameServerDeploymentsServiceStubSettings.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/GameServerDeploymentsServiceStubSettings.java index cee929bd9fbf..bac1a4359758 100644 --- a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/GameServerDeploymentsServiceStubSettings.java +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/GameServerDeploymentsServiceStubSettings.java @@ -28,6 +28,9 @@ 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; @@ -314,6 +317,11 @@ public GameServerDeploymentsServiceStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcGameServerDeploymentsServiceStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonGameServerDeploymentsServiceStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -346,18 +354,25 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde .setUseJwtAccessWithScope(true); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** 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 defaultApiClientHeaderProviderBuilder() { + public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() { return ApiClientHeaderProvider.newBuilder() .setGeneratedLibToken( "gapic", @@ -366,11 +381,31 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); } - /** Returns a new builder for this class. */ + @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(GameServerDeploymentsServiceStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return GameServerDeploymentsServiceStubSettings.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); @@ -576,6 +611,19 @@ private static Builder createDefault() { 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 .listGameServerDeploymentsSettings() diff --git a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/HttpJsonGameServerClustersServiceCallableFactory.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/HttpJsonGameServerClustersServiceCallableFactory.java new file mode 100644 index 000000000000..20c00b5c5587 --- /dev/null +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/HttpJsonGameServerClustersServiceCallableFactory.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.cloud.gaming.v1beta.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 GameServerClustersService service API. + * + *

This class is for advanced usage. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonGameServerClustersServiceCallableFactory + 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/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/HttpJsonGameServerClustersServiceStub.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/HttpJsonGameServerClustersServiceStub.java new file mode 100644 index 000000000000..5a724a159032 --- /dev/null +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/HttpJsonGameServerClustersServiceStub.java @@ -0,0 +1,739 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.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.cloud.gaming.v1beta.stub; + +import static com.google.cloud.gaming.v1beta.GameServerClustersServiceClient.ListGameServerClustersPagedResponse; + +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.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.gaming.v1beta.CreateGameServerClusterRequest; +import com.google.cloud.gaming.v1beta.DeleteGameServerClusterRequest; +import com.google.cloud.gaming.v1beta.GameServerCluster; +import com.google.cloud.gaming.v1beta.GetGameServerClusterRequest; +import com.google.cloud.gaming.v1beta.ListGameServerClustersRequest; +import com.google.cloud.gaming.v1beta.ListGameServerClustersResponse; +import com.google.cloud.gaming.v1beta.OperationMetadata; +import com.google.cloud.gaming.v1beta.PreviewCreateGameServerClusterRequest; +import com.google.cloud.gaming.v1beta.PreviewCreateGameServerClusterResponse; +import com.google.cloud.gaming.v1beta.PreviewDeleteGameServerClusterRequest; +import com.google.cloud.gaming.v1beta.PreviewDeleteGameServerClusterResponse; +import com.google.cloud.gaming.v1beta.PreviewUpdateGameServerClusterRequest; +import com.google.cloud.gaming.v1beta.PreviewUpdateGameServerClusterResponse; +import com.google.cloud.gaming.v1beta.UpdateGameServerClusterRequest; +import com.google.longrunning.Operation; +import com.google.protobuf.Empty; +import com.google.protobuf.TypeRegistry; +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 GameServerClustersService service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonGameServerClustersServiceStub extends GameServerClustersServiceStub { + private static final TypeRegistry typeRegistry = + TypeRegistry.newBuilder() + .add(Empty.getDescriptor()) + .add(GameServerCluster.getDescriptor()) + .add(OperationMetadata.getDescriptor()) + .build(); + + private static final ApiMethodDescriptor< + ListGameServerClustersRequest, ListGameServerClustersResponse> + listGameServerClustersMethodDescriptor = + ApiMethodDescriptor + .newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1beta.GameServerClustersService/ListGameServerClusters") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta/{parent=projects/*/locations/*/realms/*}/gameServerClusters", + 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, "filter", request.getFilter()); + serializer.putQueryParam(fields, "orderBy", request.getOrderBy()); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListGameServerClustersResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getGameServerClusterMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1beta.GameServerClustersService/GetGameServerCluster") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta/{name=projects/*/locations/*/realms/*/gameServerClusters/*}", + 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(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(GameServerCluster.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + createGameServerClusterMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1beta.GameServerClustersService/CreateGameServerCluster") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta/{parent=projects/*/locations/*/realms/*}/gameServerClusters", + 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, "gameServerClusterId", request.getGameServerClusterId()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("gameServerCluster", request.getGameServerCluster())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (CreateGameServerClusterRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor< + PreviewCreateGameServerClusterRequest, PreviewCreateGameServerClusterResponse> + previewCreateGameServerClusterMethodDescriptor = + ApiMethodDescriptor + . + newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1beta.GameServerClustersService/PreviewCreateGameServerCluster") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta/{parent=projects/*/locations/*/realms/*}/gameServerClusters:previewCreate", + 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, "gameServerClusterId", request.getGameServerClusterId()); + serializer.putQueryParam( + fields, "previewTime", request.getPreviewTime()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("gameServerCluster", request.getGameServerCluster())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance( + PreviewCreateGameServerClusterResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + deleteGameServerClusterMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1beta.GameServerClustersService/DeleteGameServerCluster") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta/{name=projects/*/locations/*/realms/*/gameServerClusters/*}", + 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(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (DeleteGameServerClusterRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor< + PreviewDeleteGameServerClusterRequest, PreviewDeleteGameServerClusterResponse> + previewDeleteGameServerClusterMethodDescriptor = + ApiMethodDescriptor + . + newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1beta.GameServerClustersService/PreviewDeleteGameServerCluster") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta/{name=projects/*/locations/*/realms/*/gameServerClusters/*}:previewDelete", + 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, "previewTime", request.getPreviewTime()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance( + PreviewDeleteGameServerClusterResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + updateGameServerClusterMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1beta.GameServerClustersService/UpdateGameServerCluster") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta/{gameServerCluster.name=projects/*/locations/*/realms/*/gameServerClusters/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam( + fields, + "gameServerCluster.name", + request.getGameServerCluster().getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("gameServerCluster", request.getGameServerCluster())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (UpdateGameServerClusterRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor< + PreviewUpdateGameServerClusterRequest, PreviewUpdateGameServerClusterResponse> + previewUpdateGameServerClusterMethodDescriptor = + ApiMethodDescriptor + . + newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1beta.GameServerClustersService/PreviewUpdateGameServerCluster") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta/{gameServerCluster.name=projects/*/locations/*/realms/*/gameServerClusters/*}:previewUpdate", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam( + fields, + "gameServerCluster.name", + request.getGameServerCluster().getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam( + fields, "previewTime", request.getPreviewTime()); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("gameServerCluster", request.getGameServerCluster())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance( + PreviewUpdateGameServerClusterResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private final UnaryCallable + listGameServerClustersCallable; + private final UnaryCallable + listGameServerClustersPagedCallable; + private final UnaryCallable + getGameServerClusterCallable; + private final UnaryCallable + createGameServerClusterCallable; + private final OperationCallable< + CreateGameServerClusterRequest, GameServerCluster, OperationMetadata> + createGameServerClusterOperationCallable; + private final UnaryCallable< + PreviewCreateGameServerClusterRequest, PreviewCreateGameServerClusterResponse> + previewCreateGameServerClusterCallable; + private final UnaryCallable + deleteGameServerClusterCallable; + private final OperationCallable + deleteGameServerClusterOperationCallable; + private final UnaryCallable< + PreviewDeleteGameServerClusterRequest, PreviewDeleteGameServerClusterResponse> + previewDeleteGameServerClusterCallable; + private final UnaryCallable + updateGameServerClusterCallable; + private final OperationCallable< + UpdateGameServerClusterRequest, GameServerCluster, OperationMetadata> + updateGameServerClusterOperationCallable; + private final UnaryCallable< + PreviewUpdateGameServerClusterRequest, PreviewUpdateGameServerClusterResponse> + previewUpdateGameServerClusterCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonOperationsStub httpJsonOperationsStub; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonGameServerClustersServiceStub create( + GameServerClustersServiceStubSettings settings) throws IOException { + return new HttpJsonGameServerClustersServiceStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonGameServerClustersServiceStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonGameServerClustersServiceStub( + GameServerClustersServiceStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonGameServerClustersServiceStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonGameServerClustersServiceStub( + GameServerClustersServiceStubSettings.newHttpJsonBuilder().build(), + clientContext, + callableFactory); + } + + /** + * Constructs an instance of HttpJsonGameServerClustersServiceStub, 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 HttpJsonGameServerClustersServiceStub( + GameServerClustersServiceStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new HttpJsonGameServerClustersServiceCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonGameServerClustersServiceStub, 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 HttpJsonGameServerClustersServiceStub( + GameServerClustersServiceStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.httpJsonOperationsStub = + HttpJsonOperationsStub.create(clientContext, callableFactory, typeRegistry); + + HttpJsonCallSettings + listGameServerClustersTransportSettings = + HttpJsonCallSettings + .newBuilder() + .setMethodDescriptor(listGameServerClustersMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + getGameServerClusterTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getGameServerClusterMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + createGameServerClusterTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createGameServerClusterMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings< + PreviewCreateGameServerClusterRequest, PreviewCreateGameServerClusterResponse> + previewCreateGameServerClusterTransportSettings = + HttpJsonCallSettings + . + newBuilder() + .setMethodDescriptor(previewCreateGameServerClusterMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + deleteGameServerClusterTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteGameServerClusterMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings< + PreviewDeleteGameServerClusterRequest, PreviewDeleteGameServerClusterResponse> + previewDeleteGameServerClusterTransportSettings = + HttpJsonCallSettings + . + newBuilder() + .setMethodDescriptor(previewDeleteGameServerClusterMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + updateGameServerClusterTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateGameServerClusterMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings< + PreviewUpdateGameServerClusterRequest, PreviewUpdateGameServerClusterResponse> + previewUpdateGameServerClusterTransportSettings = + HttpJsonCallSettings + . + newBuilder() + .setMethodDescriptor(previewUpdateGameServerClusterMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.listGameServerClustersCallable = + callableFactory.createUnaryCallable( + listGameServerClustersTransportSettings, + settings.listGameServerClustersSettings(), + clientContext); + this.listGameServerClustersPagedCallable = + callableFactory.createPagedCallable( + listGameServerClustersTransportSettings, + settings.listGameServerClustersSettings(), + clientContext); + this.getGameServerClusterCallable = + callableFactory.createUnaryCallable( + getGameServerClusterTransportSettings, + settings.getGameServerClusterSettings(), + clientContext); + this.createGameServerClusterCallable = + callableFactory.createUnaryCallable( + createGameServerClusterTransportSettings, + settings.createGameServerClusterSettings(), + clientContext); + this.createGameServerClusterOperationCallable = + callableFactory.createOperationCallable( + createGameServerClusterTransportSettings, + settings.createGameServerClusterOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.previewCreateGameServerClusterCallable = + callableFactory.createUnaryCallable( + previewCreateGameServerClusterTransportSettings, + settings.previewCreateGameServerClusterSettings(), + clientContext); + this.deleteGameServerClusterCallable = + callableFactory.createUnaryCallable( + deleteGameServerClusterTransportSettings, + settings.deleteGameServerClusterSettings(), + clientContext); + this.deleteGameServerClusterOperationCallable = + callableFactory.createOperationCallable( + deleteGameServerClusterTransportSettings, + settings.deleteGameServerClusterOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.previewDeleteGameServerClusterCallable = + callableFactory.createUnaryCallable( + previewDeleteGameServerClusterTransportSettings, + settings.previewDeleteGameServerClusterSettings(), + clientContext); + this.updateGameServerClusterCallable = + callableFactory.createUnaryCallable( + updateGameServerClusterTransportSettings, + settings.updateGameServerClusterSettings(), + clientContext); + this.updateGameServerClusterOperationCallable = + callableFactory.createOperationCallable( + updateGameServerClusterTransportSettings, + settings.updateGameServerClusterOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.previewUpdateGameServerClusterCallable = + callableFactory.createUnaryCallable( + previewUpdateGameServerClusterTransportSettings, + settings.previewUpdateGameServerClusterSettings(), + clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(listGameServerClustersMethodDescriptor); + methodDescriptors.add(getGameServerClusterMethodDescriptor); + methodDescriptors.add(createGameServerClusterMethodDescriptor); + methodDescriptors.add(previewCreateGameServerClusterMethodDescriptor); + methodDescriptors.add(deleteGameServerClusterMethodDescriptor); + methodDescriptors.add(previewDeleteGameServerClusterMethodDescriptor); + methodDescriptors.add(updateGameServerClusterMethodDescriptor); + methodDescriptors.add(previewUpdateGameServerClusterMethodDescriptor); + return methodDescriptors; + } + + public HttpJsonOperationsStub getHttpJsonOperationsStub() { + return httpJsonOperationsStub; + } + + @Override + public UnaryCallable + listGameServerClustersCallable() { + return listGameServerClustersCallable; + } + + @Override + public UnaryCallable + listGameServerClustersPagedCallable() { + return listGameServerClustersPagedCallable; + } + + @Override + public UnaryCallable + getGameServerClusterCallable() { + return getGameServerClusterCallable; + } + + @Override + public UnaryCallable + createGameServerClusterCallable() { + return createGameServerClusterCallable; + } + + @Override + public OperationCallable + createGameServerClusterOperationCallable() { + return createGameServerClusterOperationCallable; + } + + @Override + public UnaryCallable< + PreviewCreateGameServerClusterRequest, PreviewCreateGameServerClusterResponse> + previewCreateGameServerClusterCallable() { + return previewCreateGameServerClusterCallable; + } + + @Override + public UnaryCallable + deleteGameServerClusterCallable() { + return deleteGameServerClusterCallable; + } + + @Override + public OperationCallable + deleteGameServerClusterOperationCallable() { + return deleteGameServerClusterOperationCallable; + } + + @Override + public UnaryCallable< + PreviewDeleteGameServerClusterRequest, PreviewDeleteGameServerClusterResponse> + previewDeleteGameServerClusterCallable() { + return previewDeleteGameServerClusterCallable; + } + + @Override + public UnaryCallable + updateGameServerClusterCallable() { + return updateGameServerClusterCallable; + } + + @Override + public OperationCallable + updateGameServerClusterOperationCallable() { + return updateGameServerClusterOperationCallable; + } + + @Override + public UnaryCallable< + PreviewUpdateGameServerClusterRequest, PreviewUpdateGameServerClusterResponse> + previewUpdateGameServerClusterCallable() { + return previewUpdateGameServerClusterCallable; + } + + @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/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/HttpJsonGameServerConfigsServiceCallableFactory.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/HttpJsonGameServerConfigsServiceCallableFactory.java new file mode 100644 index 000000000000..404c44a756c9 --- /dev/null +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/HttpJsonGameServerConfigsServiceCallableFactory.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.cloud.gaming.v1beta.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 GameServerConfigsService service API. + * + *

This class is for advanced usage. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonGameServerConfigsServiceCallableFactory + 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/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/HttpJsonGameServerConfigsServiceStub.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/HttpJsonGameServerConfigsServiceStub.java new file mode 100644 index 000000000000..e25db4247234 --- /dev/null +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/HttpJsonGameServerConfigsServiceStub.java @@ -0,0 +1,442 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.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.cloud.gaming.v1beta.stub; + +import static com.google.cloud.gaming.v1beta.GameServerConfigsServiceClient.ListGameServerConfigsPagedResponse; + +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.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.gaming.v1beta.CreateGameServerConfigRequest; +import com.google.cloud.gaming.v1beta.DeleteGameServerConfigRequest; +import com.google.cloud.gaming.v1beta.GameServerConfig; +import com.google.cloud.gaming.v1beta.GetGameServerConfigRequest; +import com.google.cloud.gaming.v1beta.ListGameServerConfigsRequest; +import com.google.cloud.gaming.v1beta.ListGameServerConfigsResponse; +import com.google.cloud.gaming.v1beta.OperationMetadata; +import com.google.longrunning.Operation; +import com.google.protobuf.Empty; +import com.google.protobuf.TypeRegistry; +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 GameServerConfigsService service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonGameServerConfigsServiceStub extends GameServerConfigsServiceStub { + private static final TypeRegistry typeRegistry = + TypeRegistry.newBuilder() + .add(Empty.getDescriptor()) + .add(GameServerConfig.getDescriptor()) + .add(OperationMetadata.getDescriptor()) + .build(); + + private static final ApiMethodDescriptor< + ListGameServerConfigsRequest, ListGameServerConfigsResponse> + listGameServerConfigsMethodDescriptor = + ApiMethodDescriptor + .newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1beta.GameServerConfigsService/ListGameServerConfigs") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta/{parent=projects/*/locations/*/gameServerDeployments/*}/configs", + 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, "filter", request.getFilter()); + serializer.putQueryParam(fields, "orderBy", request.getOrderBy()); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListGameServerConfigsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getGameServerConfigMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1beta.GameServerConfigsService/GetGameServerConfig") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta/{name=projects/*/locations/*/gameServerDeployments/*/configs/*}", + 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(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(GameServerConfig.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + createGameServerConfigMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1beta.GameServerConfigsService/CreateGameServerConfig") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta/{parent=projects/*/locations/*/gameServerDeployments/*}/configs", + 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, "configId", request.getConfigId()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("gameServerConfig", request.getGameServerConfig())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (CreateGameServerConfigRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + deleteGameServerConfigMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1beta.GameServerConfigsService/DeleteGameServerConfig") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta/{name=projects/*/locations/*/gameServerDeployments/*/configs/*}", + 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(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (DeleteGameServerConfigRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private final UnaryCallable + listGameServerConfigsCallable; + private final UnaryCallable + listGameServerConfigsPagedCallable; + private final UnaryCallable + getGameServerConfigCallable; + private final UnaryCallable + createGameServerConfigCallable; + private final OperationCallable< + CreateGameServerConfigRequest, GameServerConfig, OperationMetadata> + createGameServerConfigOperationCallable; + private final UnaryCallable + deleteGameServerConfigCallable; + private final OperationCallable + deleteGameServerConfigOperationCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonOperationsStub httpJsonOperationsStub; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonGameServerConfigsServiceStub create( + GameServerConfigsServiceStubSettings settings) throws IOException { + return new HttpJsonGameServerConfigsServiceStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonGameServerConfigsServiceStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonGameServerConfigsServiceStub( + GameServerConfigsServiceStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonGameServerConfigsServiceStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonGameServerConfigsServiceStub( + GameServerConfigsServiceStubSettings.newHttpJsonBuilder().build(), + clientContext, + callableFactory); + } + + /** + * Constructs an instance of HttpJsonGameServerConfigsServiceStub, 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 HttpJsonGameServerConfigsServiceStub( + GameServerConfigsServiceStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new HttpJsonGameServerConfigsServiceCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonGameServerConfigsServiceStub, 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 HttpJsonGameServerConfigsServiceStub( + GameServerConfigsServiceStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.httpJsonOperationsStub = + HttpJsonOperationsStub.create(clientContext, callableFactory, typeRegistry); + + HttpJsonCallSettings + listGameServerConfigsTransportSettings = + HttpJsonCallSettings + .newBuilder() + .setMethodDescriptor(listGameServerConfigsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + getGameServerConfigTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getGameServerConfigMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + createGameServerConfigTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createGameServerConfigMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + deleteGameServerConfigTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteGameServerConfigMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.listGameServerConfigsCallable = + callableFactory.createUnaryCallable( + listGameServerConfigsTransportSettings, + settings.listGameServerConfigsSettings(), + clientContext); + this.listGameServerConfigsPagedCallable = + callableFactory.createPagedCallable( + listGameServerConfigsTransportSettings, + settings.listGameServerConfigsSettings(), + clientContext); + this.getGameServerConfigCallable = + callableFactory.createUnaryCallable( + getGameServerConfigTransportSettings, + settings.getGameServerConfigSettings(), + clientContext); + this.createGameServerConfigCallable = + callableFactory.createUnaryCallable( + createGameServerConfigTransportSettings, + settings.createGameServerConfigSettings(), + clientContext); + this.createGameServerConfigOperationCallable = + callableFactory.createOperationCallable( + createGameServerConfigTransportSettings, + settings.createGameServerConfigOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.deleteGameServerConfigCallable = + callableFactory.createUnaryCallable( + deleteGameServerConfigTransportSettings, + settings.deleteGameServerConfigSettings(), + clientContext); + this.deleteGameServerConfigOperationCallable = + callableFactory.createOperationCallable( + deleteGameServerConfigTransportSettings, + settings.deleteGameServerConfigOperationSettings(), + clientContext, + httpJsonOperationsStub); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(listGameServerConfigsMethodDescriptor); + methodDescriptors.add(getGameServerConfigMethodDescriptor); + methodDescriptors.add(createGameServerConfigMethodDescriptor); + methodDescriptors.add(deleteGameServerConfigMethodDescriptor); + return methodDescriptors; + } + + public HttpJsonOperationsStub getHttpJsonOperationsStub() { + return httpJsonOperationsStub; + } + + @Override + public UnaryCallable + listGameServerConfigsCallable() { + return listGameServerConfigsCallable; + } + + @Override + public UnaryCallable + listGameServerConfigsPagedCallable() { + return listGameServerConfigsPagedCallable; + } + + @Override + public UnaryCallable getGameServerConfigCallable() { + return getGameServerConfigCallable; + } + + @Override + public UnaryCallable createGameServerConfigCallable() { + return createGameServerConfigCallable; + } + + @Override + public OperationCallable + createGameServerConfigOperationCallable() { + return createGameServerConfigOperationCallable; + } + + @Override + public UnaryCallable deleteGameServerConfigCallable() { + return deleteGameServerConfigCallable; + } + + @Override + public OperationCallable + deleteGameServerConfigOperationCallable() { + return deleteGameServerConfigOperationCallable; + } + + @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/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/HttpJsonGameServerDeploymentsServiceCallableFactory.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/HttpJsonGameServerDeploymentsServiceCallableFactory.java new file mode 100644 index 000000000000..2a25b1aa79e8 --- /dev/null +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/HttpJsonGameServerDeploymentsServiceCallableFactory.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.cloud.gaming.v1beta.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 GameServerDeploymentsService service API. + * + *

This class is for advanced usage. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonGameServerDeploymentsServiceCallableFactory + 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/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/HttpJsonGameServerDeploymentsServiceStub.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/HttpJsonGameServerDeploymentsServiceStub.java new file mode 100644 index 000000000000..c4a18943c373 --- /dev/null +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/HttpJsonGameServerDeploymentsServiceStub.java @@ -0,0 +1,806 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.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.cloud.gaming.v1beta.stub; + +import static com.google.cloud.gaming.v1beta.GameServerDeploymentsServiceClient.ListGameServerDeploymentsPagedResponse; + +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.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.gaming.v1beta.CreateGameServerDeploymentRequest; +import com.google.cloud.gaming.v1beta.DeleteGameServerDeploymentRequest; +import com.google.cloud.gaming.v1beta.FetchDeploymentStateRequest; +import com.google.cloud.gaming.v1beta.FetchDeploymentStateResponse; +import com.google.cloud.gaming.v1beta.GameServerDeployment; +import com.google.cloud.gaming.v1beta.GameServerDeploymentRollout; +import com.google.cloud.gaming.v1beta.GetGameServerDeploymentRequest; +import com.google.cloud.gaming.v1beta.GetGameServerDeploymentRolloutRequest; +import com.google.cloud.gaming.v1beta.ListGameServerDeploymentsRequest; +import com.google.cloud.gaming.v1beta.ListGameServerDeploymentsResponse; +import com.google.cloud.gaming.v1beta.OperationMetadata; +import com.google.cloud.gaming.v1beta.PreviewGameServerDeploymentRolloutRequest; +import com.google.cloud.gaming.v1beta.PreviewGameServerDeploymentRolloutResponse; +import com.google.cloud.gaming.v1beta.UpdateGameServerDeploymentRequest; +import com.google.cloud.gaming.v1beta.UpdateGameServerDeploymentRolloutRequest; +import com.google.longrunning.Operation; +import com.google.protobuf.Empty; +import com.google.protobuf.TypeRegistry; +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 GameServerDeploymentsService service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonGameServerDeploymentsServiceStub extends GameServerDeploymentsServiceStub { + private static final TypeRegistry typeRegistry = + TypeRegistry.newBuilder() + .add(Empty.getDescriptor()) + .add(GameServerDeployment.getDescriptor()) + .add(OperationMetadata.getDescriptor()) + .build(); + + private static final ApiMethodDescriptor< + ListGameServerDeploymentsRequest, ListGameServerDeploymentsResponse> + listGameServerDeploymentsMethodDescriptor = + ApiMethodDescriptor + .newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1beta.GameServerDeploymentsService/ListGameServerDeployments") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta/{parent=projects/*/locations/*}/gameServerDeployments", + 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, "filter", request.getFilter()); + serializer.putQueryParam(fields, "orderBy", request.getOrderBy()); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListGameServerDeploymentsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getGameServerDeploymentMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1beta.GameServerDeploymentsService/GetGameServerDeployment") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta/{name=projects/*/locations/*/gameServerDeployments/*}", + 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(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(GameServerDeployment.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + createGameServerDeploymentMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1beta.GameServerDeploymentsService/CreateGameServerDeployment") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta/{parent=projects/*/locations/*}/gameServerDeployments", + 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, "deploymentId", request.getDeploymentId()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody( + "gameServerDeployment", request.getGameServerDeployment())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (CreateGameServerDeploymentRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + deleteGameServerDeploymentMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1beta.GameServerDeploymentsService/DeleteGameServerDeployment") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta/{name=projects/*/locations/*/gameServerDeployments/*}", + 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(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (DeleteGameServerDeploymentRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + updateGameServerDeploymentMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1beta.GameServerDeploymentsService/UpdateGameServerDeployment") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta/{gameServerDeployment.name=projects/*/locations/*/gameServerDeployments/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam( + fields, + "gameServerDeployment.name", + request.getGameServerDeployment().getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody( + "gameServerDeployment", request.getGameServerDeployment())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (UpdateGameServerDeploymentRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor< + GetGameServerDeploymentRolloutRequest, GameServerDeploymentRollout> + getGameServerDeploymentRolloutMethodDescriptor = + ApiMethodDescriptor + .newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1beta.GameServerDeploymentsService/GetGameServerDeploymentRollout") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta/{name=projects/*/locations/*/gameServerDeployments/*}/rollout", + 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(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(GameServerDeploymentRollout.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + updateGameServerDeploymentRolloutMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1beta.GameServerDeploymentsService/UpdateGameServerDeploymentRollout") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter + .newBuilder() + .setPath( + "/v1beta/{rollout.name=projects/*/locations/*/gameServerDeployments/*}/rollout", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer + serializer = ProtoRestSerializer.create(); + serializer.putPathParam( + fields, "rollout.name", request.getRollout().getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer + serializer = ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create().toBody("rollout", request.getRollout())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (UpdateGameServerDeploymentRolloutRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor< + PreviewGameServerDeploymentRolloutRequest, PreviewGameServerDeploymentRolloutResponse> + previewGameServerDeploymentRolloutMethodDescriptor = + ApiMethodDescriptor + . + newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1beta.GameServerDeploymentsService/PreviewGameServerDeploymentRollout") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter + .newBuilder() + .setPath( + "/v1beta/{rollout.name=projects/*/locations/*/gameServerDeployments/*}/rollout:preview", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer + serializer = ProtoRestSerializer.create(); + serializer.putPathParam( + fields, "rollout.name", request.getRollout().getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer + serializer = ProtoRestSerializer.create(); + serializer.putQueryParam( + fields, "previewTime", request.getPreviewTime()); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create().toBody("rollout", request.getRollout())) + .build()) + .setResponseParser( + ProtoMessageResponseParser + .newBuilder() + .setDefaultInstance( + PreviewGameServerDeploymentRolloutResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor< + FetchDeploymentStateRequest, FetchDeploymentStateResponse> + fetchDeploymentStateMethodDescriptor = + ApiMethodDescriptor + .newBuilder() + .setFullMethodName( + "google.cloud.gaming.v1beta.GameServerDeploymentsService/FetchDeploymentState") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta/{name=projects/*/locations/*/gameServerDeployments/*}:fetchDeploymentState", + 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(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearName().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(FetchDeploymentStateResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private final UnaryCallable + listGameServerDeploymentsCallable; + private final UnaryCallable< + ListGameServerDeploymentsRequest, ListGameServerDeploymentsPagedResponse> + listGameServerDeploymentsPagedCallable; + private final UnaryCallable + getGameServerDeploymentCallable; + private final UnaryCallable + createGameServerDeploymentCallable; + private final OperationCallable< + CreateGameServerDeploymentRequest, GameServerDeployment, OperationMetadata> + createGameServerDeploymentOperationCallable; + private final UnaryCallable + deleteGameServerDeploymentCallable; + private final OperationCallable + deleteGameServerDeploymentOperationCallable; + private final UnaryCallable + updateGameServerDeploymentCallable; + private final OperationCallable< + UpdateGameServerDeploymentRequest, GameServerDeployment, OperationMetadata> + updateGameServerDeploymentOperationCallable; + private final UnaryCallable + getGameServerDeploymentRolloutCallable; + private final UnaryCallable + updateGameServerDeploymentRolloutCallable; + private final OperationCallable< + UpdateGameServerDeploymentRolloutRequest, GameServerDeployment, OperationMetadata> + updateGameServerDeploymentRolloutOperationCallable; + private final UnaryCallable< + PreviewGameServerDeploymentRolloutRequest, PreviewGameServerDeploymentRolloutResponse> + previewGameServerDeploymentRolloutCallable; + private final UnaryCallable + fetchDeploymentStateCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonOperationsStub httpJsonOperationsStub; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonGameServerDeploymentsServiceStub create( + GameServerDeploymentsServiceStubSettings settings) throws IOException { + return new HttpJsonGameServerDeploymentsServiceStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonGameServerDeploymentsServiceStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonGameServerDeploymentsServiceStub( + GameServerDeploymentsServiceStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonGameServerDeploymentsServiceStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonGameServerDeploymentsServiceStub( + GameServerDeploymentsServiceStubSettings.newHttpJsonBuilder().build(), + clientContext, + callableFactory); + } + + /** + * Constructs an instance of HttpJsonGameServerDeploymentsServiceStub, 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 HttpJsonGameServerDeploymentsServiceStub( + GameServerDeploymentsServiceStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new HttpJsonGameServerDeploymentsServiceCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonGameServerDeploymentsServiceStub, 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 HttpJsonGameServerDeploymentsServiceStub( + GameServerDeploymentsServiceStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.httpJsonOperationsStub = + HttpJsonOperationsStub.create(clientContext, callableFactory, typeRegistry); + + HttpJsonCallSettings + listGameServerDeploymentsTransportSettings = + HttpJsonCallSettings + .newBuilder() + .setMethodDescriptor(listGameServerDeploymentsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + getGameServerDeploymentTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getGameServerDeploymentMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + createGameServerDeploymentTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createGameServerDeploymentMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + deleteGameServerDeploymentTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteGameServerDeploymentMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + updateGameServerDeploymentTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateGameServerDeploymentMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + getGameServerDeploymentRolloutTransportSettings = + HttpJsonCallSettings + .newBuilder() + .setMethodDescriptor(getGameServerDeploymentRolloutMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + updateGameServerDeploymentRolloutTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateGameServerDeploymentRolloutMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings< + PreviewGameServerDeploymentRolloutRequest, PreviewGameServerDeploymentRolloutResponse> + previewGameServerDeploymentRolloutTransportSettings = + HttpJsonCallSettings + . + newBuilder() + .setMethodDescriptor(previewGameServerDeploymentRolloutMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + fetchDeploymentStateTransportSettings = + HttpJsonCallSettings + .newBuilder() + .setMethodDescriptor(fetchDeploymentStateMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.listGameServerDeploymentsCallable = + callableFactory.createUnaryCallable( + listGameServerDeploymentsTransportSettings, + settings.listGameServerDeploymentsSettings(), + clientContext); + this.listGameServerDeploymentsPagedCallable = + callableFactory.createPagedCallable( + listGameServerDeploymentsTransportSettings, + settings.listGameServerDeploymentsSettings(), + clientContext); + this.getGameServerDeploymentCallable = + callableFactory.createUnaryCallable( + getGameServerDeploymentTransportSettings, + settings.getGameServerDeploymentSettings(), + clientContext); + this.createGameServerDeploymentCallable = + callableFactory.createUnaryCallable( + createGameServerDeploymentTransportSettings, + settings.createGameServerDeploymentSettings(), + clientContext); + this.createGameServerDeploymentOperationCallable = + callableFactory.createOperationCallable( + createGameServerDeploymentTransportSettings, + settings.createGameServerDeploymentOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.deleteGameServerDeploymentCallable = + callableFactory.createUnaryCallable( + deleteGameServerDeploymentTransportSettings, + settings.deleteGameServerDeploymentSettings(), + clientContext); + this.deleteGameServerDeploymentOperationCallable = + callableFactory.createOperationCallable( + deleteGameServerDeploymentTransportSettings, + settings.deleteGameServerDeploymentOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.updateGameServerDeploymentCallable = + callableFactory.createUnaryCallable( + updateGameServerDeploymentTransportSettings, + settings.updateGameServerDeploymentSettings(), + clientContext); + this.updateGameServerDeploymentOperationCallable = + callableFactory.createOperationCallable( + updateGameServerDeploymentTransportSettings, + settings.updateGameServerDeploymentOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.getGameServerDeploymentRolloutCallable = + callableFactory.createUnaryCallable( + getGameServerDeploymentRolloutTransportSettings, + settings.getGameServerDeploymentRolloutSettings(), + clientContext); + this.updateGameServerDeploymentRolloutCallable = + callableFactory.createUnaryCallable( + updateGameServerDeploymentRolloutTransportSettings, + settings.updateGameServerDeploymentRolloutSettings(), + clientContext); + this.updateGameServerDeploymentRolloutOperationCallable = + callableFactory.createOperationCallable( + updateGameServerDeploymentRolloutTransportSettings, + settings.updateGameServerDeploymentRolloutOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.previewGameServerDeploymentRolloutCallable = + callableFactory.createUnaryCallable( + previewGameServerDeploymentRolloutTransportSettings, + settings.previewGameServerDeploymentRolloutSettings(), + clientContext); + this.fetchDeploymentStateCallable = + callableFactory.createUnaryCallable( + fetchDeploymentStateTransportSettings, + settings.fetchDeploymentStateSettings(), + clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(listGameServerDeploymentsMethodDescriptor); + methodDescriptors.add(getGameServerDeploymentMethodDescriptor); + methodDescriptors.add(createGameServerDeploymentMethodDescriptor); + methodDescriptors.add(deleteGameServerDeploymentMethodDescriptor); + methodDescriptors.add(updateGameServerDeploymentMethodDescriptor); + methodDescriptors.add(getGameServerDeploymentRolloutMethodDescriptor); + methodDescriptors.add(updateGameServerDeploymentRolloutMethodDescriptor); + methodDescriptors.add(previewGameServerDeploymentRolloutMethodDescriptor); + methodDescriptors.add(fetchDeploymentStateMethodDescriptor); + return methodDescriptors; + } + + public HttpJsonOperationsStub getHttpJsonOperationsStub() { + return httpJsonOperationsStub; + } + + @Override + public UnaryCallable + listGameServerDeploymentsCallable() { + return listGameServerDeploymentsCallable; + } + + @Override + public UnaryCallable + listGameServerDeploymentsPagedCallable() { + return listGameServerDeploymentsPagedCallable; + } + + @Override + public UnaryCallable + getGameServerDeploymentCallable() { + return getGameServerDeploymentCallable; + } + + @Override + public UnaryCallable + createGameServerDeploymentCallable() { + return createGameServerDeploymentCallable; + } + + @Override + public OperationCallable< + CreateGameServerDeploymentRequest, GameServerDeployment, OperationMetadata> + createGameServerDeploymentOperationCallable() { + return createGameServerDeploymentOperationCallable; + } + + @Override + public UnaryCallable + deleteGameServerDeploymentCallable() { + return deleteGameServerDeploymentCallable; + } + + @Override + public OperationCallable + deleteGameServerDeploymentOperationCallable() { + return deleteGameServerDeploymentOperationCallable; + } + + @Override + public UnaryCallable + updateGameServerDeploymentCallable() { + return updateGameServerDeploymentCallable; + } + + @Override + public OperationCallable< + UpdateGameServerDeploymentRequest, GameServerDeployment, OperationMetadata> + updateGameServerDeploymentOperationCallable() { + return updateGameServerDeploymentOperationCallable; + } + + @Override + public UnaryCallable + getGameServerDeploymentRolloutCallable() { + return getGameServerDeploymentRolloutCallable; + } + + @Override + public UnaryCallable + updateGameServerDeploymentRolloutCallable() { + return updateGameServerDeploymentRolloutCallable; + } + + @Override + public OperationCallable< + UpdateGameServerDeploymentRolloutRequest, GameServerDeployment, OperationMetadata> + updateGameServerDeploymentRolloutOperationCallable() { + return updateGameServerDeploymentRolloutOperationCallable; + } + + @Override + public UnaryCallable< + PreviewGameServerDeploymentRolloutRequest, PreviewGameServerDeploymentRolloutResponse> + previewGameServerDeploymentRolloutCallable() { + return previewGameServerDeploymentRolloutCallable; + } + + @Override + public UnaryCallable + fetchDeploymentStateCallable() { + return fetchDeploymentStateCallable; + } + + @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/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/HttpJsonRealmsServiceCallableFactory.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/HttpJsonRealmsServiceCallableFactory.java new file mode 100644 index 000000000000..f21d70be339b --- /dev/null +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/HttpJsonRealmsServiceCallableFactory.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.cloud.gaming.v1beta.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 RealmsService service API. + * + *

This class is for advanced usage. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonRealmsServiceCallableFactory + 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/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/HttpJsonRealmsServiceStub.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/HttpJsonRealmsServiceStub.java new file mode 100644 index 000000000000..32047ecd8b18 --- /dev/null +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/HttpJsonRealmsServiceStub.java @@ -0,0 +1,539 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.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.cloud.gaming.v1beta.stub; + +import static com.google.cloud.gaming.v1beta.RealmsServiceClient.ListRealmsPagedResponse; + +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.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.gaming.v1beta.CreateRealmRequest; +import com.google.cloud.gaming.v1beta.DeleteRealmRequest; +import com.google.cloud.gaming.v1beta.GetRealmRequest; +import com.google.cloud.gaming.v1beta.ListRealmsRequest; +import com.google.cloud.gaming.v1beta.ListRealmsResponse; +import com.google.cloud.gaming.v1beta.OperationMetadata; +import com.google.cloud.gaming.v1beta.PreviewRealmUpdateRequest; +import com.google.cloud.gaming.v1beta.PreviewRealmUpdateResponse; +import com.google.cloud.gaming.v1beta.Realm; +import com.google.cloud.gaming.v1beta.UpdateRealmRequest; +import com.google.longrunning.Operation; +import com.google.protobuf.Empty; +import com.google.protobuf.TypeRegistry; +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 RealmsService service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonRealmsServiceStub extends RealmsServiceStub { + private static final TypeRegistry typeRegistry = + TypeRegistry.newBuilder() + .add(Empty.getDescriptor()) + .add(Realm.getDescriptor()) + .add(OperationMetadata.getDescriptor()) + .build(); + + private static final ApiMethodDescriptor + listRealmsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.gaming.v1beta.RealmsService/ListRealms") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta/{parent=projects/*/locations/*}/realms", + 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, "filter", request.getFilter()); + serializer.putQueryParam(fields, "orderBy", request.getOrderBy()); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListRealmsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor getRealmMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.gaming.v1beta.RealmsService/GetRealm") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta/{name=projects/*/locations/*/realms/*}", + 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(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Realm.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + createRealmMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.gaming.v1beta.RealmsService/CreateRealm") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta/{parent=projects/*/locations/*}/realms", + 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, "realmId", request.getRealmId()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create().toBody("realm", request.getRealm())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (CreateRealmRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + deleteRealmMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.gaming.v1beta.RealmsService/DeleteRealm") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta/{name=projects/*/locations/*/realms/*}", + 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(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (DeleteRealmRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + updateRealmMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.gaming.v1beta.RealmsService/UpdateRealm") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta/{realm.name=projects/*/locations/*/realms/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam( + fields, "realm.name", request.getRealm().getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create().toBody("realm", request.getRealm())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (UpdateRealmRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + previewRealmUpdateMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.gaming.v1beta.RealmsService/PreviewRealmUpdate") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta/{realm.name=projects/*/locations/*/realms/*}:previewUpdate", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam( + fields, "realm.name", request.getRealm().getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam( + fields, "previewTime", request.getPreviewTime()); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create().toBody("realm", request.getRealm())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(PreviewRealmUpdateResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private final UnaryCallable listRealmsCallable; + private final UnaryCallable listRealmsPagedCallable; + private final UnaryCallable getRealmCallable; + private final UnaryCallable createRealmCallable; + private final OperationCallable + createRealmOperationCallable; + private final UnaryCallable deleteRealmCallable; + private final OperationCallable + deleteRealmOperationCallable; + private final UnaryCallable updateRealmCallable; + private final OperationCallable + updateRealmOperationCallable; + private final UnaryCallable + previewRealmUpdateCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonOperationsStub httpJsonOperationsStub; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonRealmsServiceStub create(RealmsServiceStubSettings settings) + throws IOException { + return new HttpJsonRealmsServiceStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonRealmsServiceStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonRealmsServiceStub( + RealmsServiceStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonRealmsServiceStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonRealmsServiceStub( + RealmsServiceStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonRealmsServiceStub, 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 HttpJsonRealmsServiceStub( + RealmsServiceStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new HttpJsonRealmsServiceCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonRealmsServiceStub, 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 HttpJsonRealmsServiceStub( + RealmsServiceStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.httpJsonOperationsStub = + HttpJsonOperationsStub.create(clientContext, callableFactory, typeRegistry); + + HttpJsonCallSettings listRealmsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listRealmsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getRealmTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getRealmMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings createRealmTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createRealmMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deleteRealmTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteRealmMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings updateRealmTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateRealmMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + previewRealmUpdateTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(previewRealmUpdateMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.listRealmsCallable = + callableFactory.createUnaryCallable( + listRealmsTransportSettings, settings.listRealmsSettings(), clientContext); + this.listRealmsPagedCallable = + callableFactory.createPagedCallable( + listRealmsTransportSettings, settings.listRealmsSettings(), clientContext); + this.getRealmCallable = + callableFactory.createUnaryCallable( + getRealmTransportSettings, settings.getRealmSettings(), clientContext); + this.createRealmCallable = + callableFactory.createUnaryCallable( + createRealmTransportSettings, settings.createRealmSettings(), clientContext); + this.createRealmOperationCallable = + callableFactory.createOperationCallable( + createRealmTransportSettings, + settings.createRealmOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.deleteRealmCallable = + callableFactory.createUnaryCallable( + deleteRealmTransportSettings, settings.deleteRealmSettings(), clientContext); + this.deleteRealmOperationCallable = + callableFactory.createOperationCallable( + deleteRealmTransportSettings, + settings.deleteRealmOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.updateRealmCallable = + callableFactory.createUnaryCallable( + updateRealmTransportSettings, settings.updateRealmSettings(), clientContext); + this.updateRealmOperationCallable = + callableFactory.createOperationCallable( + updateRealmTransportSettings, + settings.updateRealmOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.previewRealmUpdateCallable = + callableFactory.createUnaryCallable( + previewRealmUpdateTransportSettings, + settings.previewRealmUpdateSettings(), + clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(listRealmsMethodDescriptor); + methodDescriptors.add(getRealmMethodDescriptor); + methodDescriptors.add(createRealmMethodDescriptor); + methodDescriptors.add(deleteRealmMethodDescriptor); + methodDescriptors.add(updateRealmMethodDescriptor); + methodDescriptors.add(previewRealmUpdateMethodDescriptor); + return methodDescriptors; + } + + public HttpJsonOperationsStub getHttpJsonOperationsStub() { + return httpJsonOperationsStub; + } + + @Override + public UnaryCallable listRealmsCallable() { + return listRealmsCallable; + } + + @Override + public UnaryCallable listRealmsPagedCallable() { + return listRealmsPagedCallable; + } + + @Override + public UnaryCallable getRealmCallable() { + return getRealmCallable; + } + + @Override + public UnaryCallable createRealmCallable() { + return createRealmCallable; + } + + @Override + public OperationCallable + createRealmOperationCallable() { + return createRealmOperationCallable; + } + + @Override + public UnaryCallable deleteRealmCallable() { + return deleteRealmCallable; + } + + @Override + public OperationCallable + deleteRealmOperationCallable() { + return deleteRealmOperationCallable; + } + + @Override + public UnaryCallable updateRealmCallable() { + return updateRealmCallable; + } + + @Override + public OperationCallable + updateRealmOperationCallable() { + return updateRealmOperationCallable; + } + + @Override + public UnaryCallable + previewRealmUpdateCallable() { + return previewRealmUpdateCallable; + } + + @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/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/RealmsServiceStub.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/RealmsServiceStub.java index 9018f2167e02..86233196d56b 100644 --- a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/RealmsServiceStub.java +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/RealmsServiceStub.java @@ -48,7 +48,11 @@ public abstract class RealmsServiceStub implements BackgroundResource { public OperationsStub getOperationsStub() { - throw new UnsupportedOperationException("Not implemented: getOperationsStub()"); + return null; + } + + public com.google.api.gax.httpjson.longrunning.stub.OperationsStub getHttpJsonOperationsStub() { + return null; } public UnaryCallable listRealmsPagedCallable() { diff --git a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/RealmsServiceStubSettings.java b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/RealmsServiceStubSettings.java index a5ab1e6c290e..7d514be27921 100644 --- a/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/RealmsServiceStubSettings.java +++ b/java-game-servers/google-cloud-game-servers/src/main/java/com/google/cloud/gaming/v1beta/stub/RealmsServiceStubSettings.java @@ -28,6 +28,9 @@ 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; @@ -230,6 +233,11 @@ public RealmsServiceStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcRealmsServiceStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonRealmsServiceStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -262,18 +270,25 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde .setUseJwtAccessWithScope(true); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** 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 defaultApiClientHeaderProviderBuilder() { + public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() { return ApiClientHeaderProvider.newBuilder() .setGeneratedLibToken( "gapic", GaxProperties.getLibraryVersion(RealmsServiceStubSettings.class)) @@ -281,11 +296,30 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); } - /** Returns a new builder for this class. */ + @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(RealmsServiceStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return RealmsServiceStubSettings.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); @@ -433,6 +467,19 @@ private static Builder createDefault() { 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 .listRealmsSettings() diff --git a/java-game-servers/google-cloud-game-servers/src/test/java/com/google/cloud/gaming/v1/GameServerClustersServiceClientHttpJsonTest.java b/java-game-servers/google-cloud-game-servers/src/test/java/com/google/cloud/gaming/v1/GameServerClustersServiceClientHttpJsonTest.java new file mode 100644 index 000000000000..5f8e3a86b55f --- /dev/null +++ b/java-game-servers/google-cloud-game-servers/src/test/java/com/google/cloud/gaming/v1/GameServerClustersServiceClientHttpJsonTest.java @@ -0,0 +1,799 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.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.cloud.gaming.v1; + +import static com.google.cloud.gaming.v1.GameServerClustersServiceClient.ListGameServerClustersPagedResponse; + +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.cloud.gaming.v1.stub.HttpJsonGameServerClustersServiceStub; +import com.google.common.collect.Lists; +import com.google.longrunning.Operation; +import com.google.protobuf.Any; +import com.google.protobuf.Empty; +import com.google.protobuf.FieldMask; +import com.google.protobuf.Timestamp; +import java.io.IOException; +import java.util.Arrays; +import java.util.HashMap; +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 GameServerClustersServiceClientHttpJsonTest { + private static MockHttpService mockService; + private static GameServerClustersServiceClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonGameServerClustersServiceStub.getMethodDescriptors(), + GameServerClustersServiceSettings.getDefaultEndpoint()); + GameServerClustersServiceSettings settings = + GameServerClustersServiceSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + GameServerClustersServiceSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = GameServerClustersServiceClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void listGameServerClustersTest() throws Exception { + GameServerCluster responsesElement = GameServerCluster.newBuilder().build(); + ListGameServerClustersResponse expectedResponse = + ListGameServerClustersResponse.newBuilder() + .setNextPageToken("") + .addAllGameServerClusters(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + RealmName parent = RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]"); + + ListGameServerClustersPagedResponse pagedListResponse = client.listGameServerClusters(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getGameServerClustersList().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 listGameServerClustersExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + RealmName parent = RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]"); + client.listGameServerClusters(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listGameServerClustersTest2() throws Exception { + GameServerCluster responsesElement = GameServerCluster.newBuilder().build(); + ListGameServerClustersResponse expectedResponse = + ListGameServerClustersResponse.newBuilder() + .setNextPageToken("") + .addAllGameServerClusters(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-3755/locations/location-3755/realms/realm-3755"; + + ListGameServerClustersPagedResponse pagedListResponse = client.listGameServerClusters(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getGameServerClustersList().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 listGameServerClustersExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-3755/locations/location-3755/realms/realm-3755"; + client.listGameServerClusters(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getGameServerClusterTest() throws Exception { + GameServerCluster expectedResponse = + GameServerCluster.newBuilder() + .setName( + GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]") + .toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setConnectionInfo(GameServerClusterConnectionInfo.newBuilder().build()) + .setEtag("etag3123477") + .setDescription("description-1724546052") + .setClusterState(KubernetesClusterState.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + GameServerClusterName name = + GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]"); + + GameServerCluster actualResponse = client.getGameServerCluster(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 getGameServerClusterExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GameServerClusterName name = + GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]"); + client.getGameServerCluster(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getGameServerClusterTest2() throws Exception { + GameServerCluster expectedResponse = + GameServerCluster.newBuilder() + .setName( + GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]") + .toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setConnectionInfo(GameServerClusterConnectionInfo.newBuilder().build()) + .setEtag("etag3123477") + .setDescription("description-1724546052") + .setClusterState(KubernetesClusterState.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-4532/locations/location-4532/realms/realm-4532/gameServerClusters/gameServerCluster-4532"; + + GameServerCluster actualResponse = client.getGameServerCluster(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 getGameServerClusterExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-4532/locations/location-4532/realms/realm-4532/gameServerClusters/gameServerCluster-4532"; + client.getGameServerCluster(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createGameServerClusterTest() throws Exception { + GameServerCluster expectedResponse = + GameServerCluster.newBuilder() + .setName( + GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]") + .toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setConnectionInfo(GameServerClusterConnectionInfo.newBuilder().build()) + .setEtag("etag3123477") + .setDescription("description-1724546052") + .setClusterState(KubernetesClusterState.newBuilder().build()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createGameServerClusterTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + RealmName parent = RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]"); + GameServerCluster gameServerCluster = GameServerCluster.newBuilder().build(); + String gameServerClusterId = "gameServerClusterId-1301104032"; + + GameServerCluster actualResponse = + client.createGameServerClusterAsync(parent, gameServerCluster, gameServerClusterId).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 createGameServerClusterExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + RealmName parent = RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]"); + GameServerCluster gameServerCluster = GameServerCluster.newBuilder().build(); + String gameServerClusterId = "gameServerClusterId-1301104032"; + client.createGameServerClusterAsync(parent, gameServerCluster, gameServerClusterId).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void createGameServerClusterTest2() throws Exception { + GameServerCluster expectedResponse = + GameServerCluster.newBuilder() + .setName( + GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]") + .toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setConnectionInfo(GameServerClusterConnectionInfo.newBuilder().build()) + .setEtag("etag3123477") + .setDescription("description-1724546052") + .setClusterState(KubernetesClusterState.newBuilder().build()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createGameServerClusterTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String parent = "projects/project-3755/locations/location-3755/realms/realm-3755"; + GameServerCluster gameServerCluster = GameServerCluster.newBuilder().build(); + String gameServerClusterId = "gameServerClusterId-1301104032"; + + GameServerCluster actualResponse = + client.createGameServerClusterAsync(parent, gameServerCluster, gameServerClusterId).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 createGameServerClusterExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-3755/locations/location-3755/realms/realm-3755"; + GameServerCluster gameServerCluster = GameServerCluster.newBuilder().build(); + String gameServerClusterId = "gameServerClusterId-1301104032"; + client.createGameServerClusterAsync(parent, gameServerCluster, gameServerClusterId).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void previewCreateGameServerClusterTest() throws Exception { + PreviewCreateGameServerClusterResponse expectedResponse = + PreviewCreateGameServerClusterResponse.newBuilder() + .setEtag("etag3123477") + .setTargetState(TargetState.newBuilder().build()) + .setClusterState(KubernetesClusterState.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + PreviewCreateGameServerClusterRequest request = + PreviewCreateGameServerClusterRequest.newBuilder() + .setParent(RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]").toString()) + .setGameServerClusterId("gameServerClusterId-1301104032") + .setGameServerCluster(GameServerCluster.newBuilder().build()) + .setPreviewTime(Timestamp.newBuilder().build()) + .setView(GameServerClusterView.forNumber(0)) + .build(); + + PreviewCreateGameServerClusterResponse actualResponse = + client.previewCreateGameServerCluster(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 previewCreateGameServerClusterExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + PreviewCreateGameServerClusterRequest request = + PreviewCreateGameServerClusterRequest.newBuilder() + .setParent(RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]").toString()) + .setGameServerClusterId("gameServerClusterId-1301104032") + .setGameServerCluster(GameServerCluster.newBuilder().build()) + .setPreviewTime(Timestamp.newBuilder().build()) + .setView(GameServerClusterView.forNumber(0)) + .build(); + client.previewCreateGameServerCluster(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteGameServerClusterTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteGameServerClusterTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + GameServerClusterName name = + GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]"); + + client.deleteGameServerClusterAsync(name).get(); + + 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 deleteGameServerClusterExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GameServerClusterName name = + GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]"); + client.deleteGameServerClusterAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void deleteGameServerClusterTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteGameServerClusterTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String name = + "projects/project-4532/locations/location-4532/realms/realm-4532/gameServerClusters/gameServerCluster-4532"; + + client.deleteGameServerClusterAsync(name).get(); + + 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 deleteGameServerClusterExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-4532/locations/location-4532/realms/realm-4532/gameServerClusters/gameServerCluster-4532"; + client.deleteGameServerClusterAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void previewDeleteGameServerClusterTest() throws Exception { + PreviewDeleteGameServerClusterResponse expectedResponse = + PreviewDeleteGameServerClusterResponse.newBuilder() + .setEtag("etag3123477") + .setTargetState(TargetState.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + PreviewDeleteGameServerClusterRequest request = + PreviewDeleteGameServerClusterRequest.newBuilder() + .setName( + GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]") + .toString()) + .setPreviewTime(Timestamp.newBuilder().build()) + .build(); + + PreviewDeleteGameServerClusterResponse actualResponse = + client.previewDeleteGameServerCluster(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 previewDeleteGameServerClusterExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + PreviewDeleteGameServerClusterRequest request = + PreviewDeleteGameServerClusterRequest.newBuilder() + .setName( + GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]") + .toString()) + .setPreviewTime(Timestamp.newBuilder().build()) + .build(); + client.previewDeleteGameServerCluster(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateGameServerClusterTest() throws Exception { + GameServerCluster expectedResponse = + GameServerCluster.newBuilder() + .setName( + GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]") + .toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setConnectionInfo(GameServerClusterConnectionInfo.newBuilder().build()) + .setEtag("etag3123477") + .setDescription("description-1724546052") + .setClusterState(KubernetesClusterState.newBuilder().build()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("updateGameServerClusterTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + GameServerCluster gameServerCluster = + GameServerCluster.newBuilder() + .setName( + GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]") + .toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setConnectionInfo(GameServerClusterConnectionInfo.newBuilder().build()) + .setEtag("etag3123477") + .setDescription("description-1724546052") + .setClusterState(KubernetesClusterState.newBuilder().build()) + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + + GameServerCluster actualResponse = + client.updateGameServerClusterAsync(gameServerCluster, updateMask).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 updateGameServerClusterExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GameServerCluster gameServerCluster = + GameServerCluster.newBuilder() + .setName( + GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]") + .toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setConnectionInfo(GameServerClusterConnectionInfo.newBuilder().build()) + .setEtag("etag3123477") + .setDescription("description-1724546052") + .setClusterState(KubernetesClusterState.newBuilder().build()) + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + client.updateGameServerClusterAsync(gameServerCluster, updateMask).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void previewUpdateGameServerClusterTest() throws Exception { + PreviewUpdateGameServerClusterResponse expectedResponse = + PreviewUpdateGameServerClusterResponse.newBuilder() + .setEtag("etag3123477") + .setTargetState(TargetState.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + PreviewUpdateGameServerClusterRequest request = + PreviewUpdateGameServerClusterRequest.newBuilder() + .setGameServerCluster( + GameServerCluster.newBuilder() + .setName( + GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]") + .toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setConnectionInfo(GameServerClusterConnectionInfo.newBuilder().build()) + .setEtag("etag3123477") + .setDescription("description-1724546052") + .setClusterState(KubernetesClusterState.newBuilder().build()) + .build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .setPreviewTime(Timestamp.newBuilder().build()) + .build(); + + PreviewUpdateGameServerClusterResponse actualResponse = + client.previewUpdateGameServerCluster(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 previewUpdateGameServerClusterExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + PreviewUpdateGameServerClusterRequest request = + PreviewUpdateGameServerClusterRequest.newBuilder() + .setGameServerCluster( + GameServerCluster.newBuilder() + .setName( + GameServerClusterName.of( + "[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]") + .toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setConnectionInfo(GameServerClusterConnectionInfo.newBuilder().build()) + .setEtag("etag3123477") + .setDescription("description-1724546052") + .setClusterState(KubernetesClusterState.newBuilder().build()) + .build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .setPreviewTime(Timestamp.newBuilder().build()) + .build(); + client.previewUpdateGameServerCluster(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/java-game-servers/google-cloud-game-servers/src/test/java/com/google/cloud/gaming/v1/GameServerConfigsServiceClientHttpJsonTest.java b/java-game-servers/google-cloud-game-servers/src/test/java/com/google/cloud/gaming/v1/GameServerConfigsServiceClientHttpJsonTest.java new file mode 100644 index 000000000000..bf348bd047ab --- /dev/null +++ b/java-game-servers/google-cloud-game-servers/src/test/java/com/google/cloud/gaming/v1/GameServerConfigsServiceClientHttpJsonTest.java @@ -0,0 +1,514 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.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.cloud.gaming.v1; + +import static com.google.cloud.gaming.v1.GameServerConfigsServiceClient.ListGameServerConfigsPagedResponse; + +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.cloud.gaming.v1.stub.HttpJsonGameServerConfigsServiceStub; +import com.google.common.collect.Lists; +import com.google.longrunning.Operation; +import com.google.protobuf.Any; +import com.google.protobuf.Empty; +import com.google.protobuf.Timestamp; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +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 GameServerConfigsServiceClientHttpJsonTest { + private static MockHttpService mockService; + private static GameServerConfigsServiceClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonGameServerConfigsServiceStub.getMethodDescriptors(), + GameServerConfigsServiceSettings.getDefaultEndpoint()); + GameServerConfigsServiceSettings settings = + GameServerConfigsServiceSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + GameServerConfigsServiceSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = GameServerConfigsServiceClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void listGameServerConfigsTest() throws Exception { + GameServerConfig responsesElement = GameServerConfig.newBuilder().build(); + ListGameServerConfigsResponse expectedResponse = + ListGameServerConfigsResponse.newBuilder() + .setNextPageToken("") + .addAllGameServerConfigs(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + GameServerDeploymentName parent = + GameServerDeploymentName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]"); + + ListGameServerConfigsPagedResponse pagedListResponse = client.listGameServerConfigs(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getGameServerConfigsList().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 listGameServerConfigsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GameServerDeploymentName parent = + GameServerDeploymentName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]"); + client.listGameServerConfigs(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listGameServerConfigsTest2() throws Exception { + GameServerConfig responsesElement = GameServerConfig.newBuilder().build(); + ListGameServerConfigsResponse expectedResponse = + ListGameServerConfigsResponse.newBuilder() + .setNextPageToken("") + .addAllGameServerConfigs(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = + "projects/project-6046/locations/location-6046/gameServerDeployments/gameServerDeployment-6046"; + + ListGameServerConfigsPagedResponse pagedListResponse = client.listGameServerConfigs(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getGameServerConfigsList().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 listGameServerConfigsExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = + "projects/project-6046/locations/location-6046/gameServerDeployments/gameServerDeployment-6046"; + client.listGameServerConfigs(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getGameServerConfigTest() throws Exception { + GameServerConfig expectedResponse = + GameServerConfig.newBuilder() + .setName( + GameServerConfigName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]", "[CONFIG]") + .toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .addAllFleetConfigs(new ArrayList()) + .addAllScalingConfigs(new ArrayList()) + .setDescription("description-1724546052") + .build(); + mockService.addResponse(expectedResponse); + + GameServerConfigName name = + GameServerConfigName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]", "[CONFIG]"); + + GameServerConfig actualResponse = client.getGameServerConfig(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 getGameServerConfigExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GameServerConfigName name = + GameServerConfigName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]", "[CONFIG]"); + client.getGameServerConfig(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getGameServerConfigTest2() throws Exception { + GameServerConfig expectedResponse = + GameServerConfig.newBuilder() + .setName( + GameServerConfigName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]", "[CONFIG]") + .toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .addAllFleetConfigs(new ArrayList()) + .addAllScalingConfigs(new ArrayList()) + .setDescription("description-1724546052") + .build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-2748/locations/location-2748/gameServerDeployments/gameServerDeployment-2748/configs/config-2748"; + + GameServerConfig actualResponse = client.getGameServerConfig(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 getGameServerConfigExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-2748/locations/location-2748/gameServerDeployments/gameServerDeployment-2748/configs/config-2748"; + client.getGameServerConfig(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createGameServerConfigTest() throws Exception { + GameServerConfig expectedResponse = + GameServerConfig.newBuilder() + .setName( + GameServerConfigName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]", "[CONFIG]") + .toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .addAllFleetConfigs(new ArrayList()) + .addAllScalingConfigs(new ArrayList()) + .setDescription("description-1724546052") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createGameServerConfigTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + GameServerDeploymentName parent = + GameServerDeploymentName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]"); + GameServerConfig gameServerConfig = GameServerConfig.newBuilder().build(); + + GameServerConfig actualResponse = + client.createGameServerConfigAsync(parent, gameServerConfig).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 createGameServerConfigExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GameServerDeploymentName parent = + GameServerDeploymentName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]"); + GameServerConfig gameServerConfig = GameServerConfig.newBuilder().build(); + client.createGameServerConfigAsync(parent, gameServerConfig).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void createGameServerConfigTest2() throws Exception { + GameServerConfig expectedResponse = + GameServerConfig.newBuilder() + .setName( + GameServerConfigName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]", "[CONFIG]") + .toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .addAllFleetConfigs(new ArrayList()) + .addAllScalingConfigs(new ArrayList()) + .setDescription("description-1724546052") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createGameServerConfigTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String parent = + "projects/project-6046/locations/location-6046/gameServerDeployments/gameServerDeployment-6046"; + GameServerConfig gameServerConfig = GameServerConfig.newBuilder().build(); + + GameServerConfig actualResponse = + client.createGameServerConfigAsync(parent, gameServerConfig).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 createGameServerConfigExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = + "projects/project-6046/locations/location-6046/gameServerDeployments/gameServerDeployment-6046"; + GameServerConfig gameServerConfig = GameServerConfig.newBuilder().build(); + client.createGameServerConfigAsync(parent, gameServerConfig).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void deleteGameServerConfigTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteGameServerConfigTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + GameServerConfigName name = + GameServerConfigName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]", "[CONFIG]"); + + client.deleteGameServerConfigAsync(name).get(); + + 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 deleteGameServerConfigExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GameServerConfigName name = + GameServerConfigName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]", "[CONFIG]"); + client.deleteGameServerConfigAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void deleteGameServerConfigTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteGameServerConfigTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String name = + "projects/project-2748/locations/location-2748/gameServerDeployments/gameServerDeployment-2748/configs/config-2748"; + + client.deleteGameServerConfigAsync(name).get(); + + 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 deleteGameServerConfigExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-2748/locations/location-2748/gameServerDeployments/gameServerDeployment-2748/configs/config-2748"; + client.deleteGameServerConfigAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } +} diff --git a/java-game-servers/google-cloud-game-servers/src/test/java/com/google/cloud/gaming/v1/GameServerDeploymentsServiceClientHttpJsonTest.java b/java-game-servers/google-cloud-game-servers/src/test/java/com/google/cloud/gaming/v1/GameServerDeploymentsServiceClientHttpJsonTest.java new file mode 100644 index 000000000000..842b9bca3137 --- /dev/null +++ b/java-game-servers/google-cloud-game-servers/src/test/java/com/google/cloud/gaming/v1/GameServerDeploymentsServiceClientHttpJsonTest.java @@ -0,0 +1,883 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.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.cloud.gaming.v1; + +import static com.google.cloud.gaming.v1.GameServerDeploymentsServiceClient.ListGameServerDeploymentsPagedResponse; + +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.cloud.gaming.v1.stub.HttpJsonGameServerDeploymentsServiceStub; +import com.google.common.collect.Lists; +import com.google.longrunning.Operation; +import com.google.protobuf.Any; +import com.google.protobuf.Empty; +import com.google.protobuf.FieldMask; +import com.google.protobuf.Timestamp; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +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 GameServerDeploymentsServiceClientHttpJsonTest { + private static MockHttpService mockService; + private static GameServerDeploymentsServiceClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonGameServerDeploymentsServiceStub.getMethodDescriptors(), + GameServerDeploymentsServiceSettings.getDefaultEndpoint()); + GameServerDeploymentsServiceSettings settings = + GameServerDeploymentsServiceSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + GameServerDeploymentsServiceSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = GameServerDeploymentsServiceClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void listGameServerDeploymentsTest() throws Exception { + GameServerDeployment responsesElement = GameServerDeployment.newBuilder().build(); + ListGameServerDeploymentsResponse expectedResponse = + ListGameServerDeploymentsResponse.newBuilder() + .setNextPageToken("") + .addAllGameServerDeployments(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + + ListGameServerDeploymentsPagedResponse pagedListResponse = + client.listGameServerDeployments(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getGameServerDeploymentsList().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 listGameServerDeploymentsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + client.listGameServerDeployments(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listGameServerDeploymentsTest2() throws Exception { + GameServerDeployment responsesElement = GameServerDeployment.newBuilder().build(); + ListGameServerDeploymentsResponse expectedResponse = + ListGameServerDeploymentsResponse.newBuilder() + .setNextPageToken("") + .addAllGameServerDeployments(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-5833/locations/location-5833"; + + ListGameServerDeploymentsPagedResponse pagedListResponse = + client.listGameServerDeployments(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getGameServerDeploymentsList().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 listGameServerDeploymentsExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + client.listGameServerDeployments(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getGameServerDeploymentTest() throws Exception { + GameServerDeployment expectedResponse = + GameServerDeployment.newBuilder() + .setName( + GameServerDeploymentName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build(); + mockService.addResponse(expectedResponse); + + GameServerDeploymentName name = + GameServerDeploymentName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]"); + + GameServerDeployment actualResponse = client.getGameServerDeployment(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 getGameServerDeploymentExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GameServerDeploymentName name = + GameServerDeploymentName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]"); + client.getGameServerDeployment(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getGameServerDeploymentTest2() throws Exception { + GameServerDeployment expectedResponse = + GameServerDeployment.newBuilder() + .setName( + GameServerDeploymentName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-8689/locations/location-8689/gameServerDeployments/gameServerDeployment-8689"; + + GameServerDeployment actualResponse = client.getGameServerDeployment(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 getGameServerDeploymentExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-8689/locations/location-8689/gameServerDeployments/gameServerDeployment-8689"; + client.getGameServerDeployment(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createGameServerDeploymentTest() throws Exception { + GameServerDeployment expectedResponse = + GameServerDeployment.newBuilder() + .setName( + GameServerDeploymentName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createGameServerDeploymentTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + GameServerDeployment gameServerDeployment = GameServerDeployment.newBuilder().build(); + + GameServerDeployment actualResponse = + client.createGameServerDeploymentAsync(parent, gameServerDeployment).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 createGameServerDeploymentExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + GameServerDeployment gameServerDeployment = GameServerDeployment.newBuilder().build(); + client.createGameServerDeploymentAsync(parent, gameServerDeployment).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void createGameServerDeploymentTest2() throws Exception { + GameServerDeployment expectedResponse = + GameServerDeployment.newBuilder() + .setName( + GameServerDeploymentName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createGameServerDeploymentTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String parent = "projects/project-5833/locations/location-5833"; + GameServerDeployment gameServerDeployment = GameServerDeployment.newBuilder().build(); + + GameServerDeployment actualResponse = + client.createGameServerDeploymentAsync(parent, gameServerDeployment).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 createGameServerDeploymentExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + GameServerDeployment gameServerDeployment = GameServerDeployment.newBuilder().build(); + client.createGameServerDeploymentAsync(parent, gameServerDeployment).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void deleteGameServerDeploymentTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteGameServerDeploymentTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + GameServerDeploymentName name = + GameServerDeploymentName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]"); + + client.deleteGameServerDeploymentAsync(name).get(); + + 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 deleteGameServerDeploymentExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GameServerDeploymentName name = + GameServerDeploymentName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]"); + client.deleteGameServerDeploymentAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void deleteGameServerDeploymentTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteGameServerDeploymentTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String name = + "projects/project-8689/locations/location-8689/gameServerDeployments/gameServerDeployment-8689"; + + client.deleteGameServerDeploymentAsync(name).get(); + + 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 deleteGameServerDeploymentExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-8689/locations/location-8689/gameServerDeployments/gameServerDeployment-8689"; + client.deleteGameServerDeploymentAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void updateGameServerDeploymentTest() throws Exception { + GameServerDeployment expectedResponse = + GameServerDeployment.newBuilder() + .setName( + GameServerDeploymentName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("updateGameServerDeploymentTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + GameServerDeployment gameServerDeployment = + GameServerDeployment.newBuilder() + .setName( + GameServerDeploymentName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + + GameServerDeployment actualResponse = + client.updateGameServerDeploymentAsync(gameServerDeployment, updateMask).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 updateGameServerDeploymentExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GameServerDeployment gameServerDeployment = + GameServerDeployment.newBuilder() + .setName( + GameServerDeploymentName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + client.updateGameServerDeploymentAsync(gameServerDeployment, updateMask).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void getGameServerDeploymentRolloutTest() throws Exception { + GameServerDeploymentRollout expectedResponse = + GameServerDeploymentRollout.newBuilder() + .setName("name3373707") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setDefaultGameServerConfig("defaultGameServerConfig-1852465704") + .addAllGameServerConfigOverrides(new ArrayList()) + .setEtag("etag3123477") + .build(); + mockService.addResponse(expectedResponse); + + GameServerDeploymentName name = + GameServerDeploymentName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]"); + + GameServerDeploymentRollout actualResponse = client.getGameServerDeploymentRollout(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 getGameServerDeploymentRolloutExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GameServerDeploymentName name = + GameServerDeploymentName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]"); + client.getGameServerDeploymentRollout(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getGameServerDeploymentRolloutTest2() throws Exception { + GameServerDeploymentRollout expectedResponse = + GameServerDeploymentRollout.newBuilder() + .setName("name3373707") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setDefaultGameServerConfig("defaultGameServerConfig-1852465704") + .addAllGameServerConfigOverrides(new ArrayList()) + .setEtag("etag3123477") + .build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-8689/locations/location-8689/gameServerDeployments/gameServerDeployment-8689"; + + GameServerDeploymentRollout actualResponse = client.getGameServerDeploymentRollout(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 getGameServerDeploymentRolloutExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-8689/locations/location-8689/gameServerDeployments/gameServerDeployment-8689"; + client.getGameServerDeploymentRollout(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateGameServerDeploymentRolloutTest() throws Exception { + GameServerDeployment expectedResponse = + GameServerDeployment.newBuilder() + .setName( + GameServerDeploymentName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("updateGameServerDeploymentRolloutTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + GameServerDeploymentRollout rollout = + GameServerDeploymentRollout.newBuilder() + .setName( + "projects/project-8689/locations/location-8689/gameServerDeployments/gameServerDeployment-8689") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setDefaultGameServerConfig("defaultGameServerConfig-1852465704") + .addAllGameServerConfigOverrides(new ArrayList()) + .setEtag("etag3123477") + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + + GameServerDeployment actualResponse = + client.updateGameServerDeploymentRolloutAsync(rollout, updateMask).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 updateGameServerDeploymentRolloutExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GameServerDeploymentRollout rollout = + GameServerDeploymentRollout.newBuilder() + .setName( + "projects/project-8689/locations/location-8689/gameServerDeployments/gameServerDeployment-8689") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setDefaultGameServerConfig("defaultGameServerConfig-1852465704") + .addAllGameServerConfigOverrides(new ArrayList()) + .setEtag("etag3123477") + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + client.updateGameServerDeploymentRolloutAsync(rollout, updateMask).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void previewGameServerDeploymentRolloutTest() throws Exception { + PreviewGameServerDeploymentRolloutResponse expectedResponse = + PreviewGameServerDeploymentRolloutResponse.newBuilder() + .addAllUnavailable(new ArrayList()) + .setEtag("etag3123477") + .setTargetState(TargetState.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + PreviewGameServerDeploymentRolloutRequest request = + PreviewGameServerDeploymentRolloutRequest.newBuilder() + .setRollout( + GameServerDeploymentRollout.newBuilder() + .setName( + "projects/project-8689/locations/location-8689/gameServerDeployments/gameServerDeployment-8689") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setDefaultGameServerConfig("defaultGameServerConfig-1852465704") + .addAllGameServerConfigOverrides(new ArrayList()) + .setEtag("etag3123477") + .build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .setPreviewTime(Timestamp.newBuilder().build()) + .build(); + + PreviewGameServerDeploymentRolloutResponse actualResponse = + client.previewGameServerDeploymentRollout(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 previewGameServerDeploymentRolloutExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + PreviewGameServerDeploymentRolloutRequest request = + PreviewGameServerDeploymentRolloutRequest.newBuilder() + .setRollout( + GameServerDeploymentRollout.newBuilder() + .setName( + "projects/project-8689/locations/location-8689/gameServerDeployments/gameServerDeployment-8689") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setDefaultGameServerConfig("defaultGameServerConfig-1852465704") + .addAllGameServerConfigOverrides(new ArrayList()) + .setEtag("etag3123477") + .build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .setPreviewTime(Timestamp.newBuilder().build()) + .build(); + client.previewGameServerDeploymentRollout(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void fetchDeploymentStateTest() throws Exception { + FetchDeploymentStateResponse expectedResponse = + FetchDeploymentStateResponse.newBuilder() + .addAllClusterState(new ArrayList()) + .addAllUnavailable(new ArrayList()) + .build(); + mockService.addResponse(expectedResponse); + + FetchDeploymentStateRequest request = + FetchDeploymentStateRequest.newBuilder() + .setName( + "projects/project-8689/locations/location-8689/gameServerDeployments/gameServerDeployment-8689") + .build(); + + FetchDeploymentStateResponse actualResponse = client.fetchDeploymentState(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 fetchDeploymentStateExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + FetchDeploymentStateRequest request = + FetchDeploymentStateRequest.newBuilder() + .setName( + "projects/project-8689/locations/location-8689/gameServerDeployments/gameServerDeployment-8689") + .build(); + client.fetchDeploymentState(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/java-game-servers/google-cloud-game-servers/src/test/java/com/google/cloud/gaming/v1/RealmsServiceClientHttpJsonTest.java b/java-game-servers/google-cloud-game-servers/src/test/java/com/google/cloud/gaming/v1/RealmsServiceClientHttpJsonTest.java new file mode 100644 index 000000000000..dfbaa2e5664f --- /dev/null +++ b/java-game-servers/google-cloud-game-servers/src/test/java/com/google/cloud/gaming/v1/RealmsServiceClientHttpJsonTest.java @@ -0,0 +1,640 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.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.cloud.gaming.v1; + +import static com.google.cloud.gaming.v1.RealmsServiceClient.ListRealmsPagedResponse; + +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.cloud.gaming.v1.stub.HttpJsonRealmsServiceStub; +import com.google.common.collect.Lists; +import com.google.longrunning.Operation; +import com.google.protobuf.Any; +import com.google.protobuf.Empty; +import com.google.protobuf.FieldMask; +import com.google.protobuf.Timestamp; +import java.io.IOException; +import java.util.Arrays; +import java.util.HashMap; +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 RealmsServiceClientHttpJsonTest { + private static MockHttpService mockService; + private static RealmsServiceClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonRealmsServiceStub.getMethodDescriptors(), + RealmsServiceSettings.getDefaultEndpoint()); + RealmsServiceSettings settings = + RealmsServiceSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + RealmsServiceSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = RealmsServiceClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void listRealmsTest() throws Exception { + Realm responsesElement = Realm.newBuilder().build(); + ListRealmsResponse expectedResponse = + ListRealmsResponse.newBuilder() + .setNextPageToken("") + .addAllRealms(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + + ListRealmsPagedResponse pagedListResponse = client.listRealms(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getRealmsList().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 listRealmsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + client.listRealms(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listRealmsTest2() throws Exception { + Realm responsesElement = Realm.newBuilder().build(); + ListRealmsResponse expectedResponse = + ListRealmsResponse.newBuilder() + .setNextPageToken("") + .addAllRealms(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-5833/locations/location-5833"; + + ListRealmsPagedResponse pagedListResponse = client.listRealms(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getRealmsList().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 listRealmsExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + client.listRealms(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getRealmTest() throws Exception { + Realm expectedResponse = + Realm.newBuilder() + .setName(RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setTimeZone("timeZone-2077180903") + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build(); + mockService.addResponse(expectedResponse); + + RealmName name = RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]"); + + Realm actualResponse = client.getRealm(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 getRealmExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + RealmName name = RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]"); + client.getRealm(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getRealmTest2() throws Exception { + Realm expectedResponse = + Realm.newBuilder() + .setName(RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setTimeZone("timeZone-2077180903") + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-9444/locations/location-9444/realms/realm-9444"; + + Realm actualResponse = client.getRealm(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 getRealmExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-9444/locations/location-9444/realms/realm-9444"; + client.getRealm(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createRealmTest() throws Exception { + Realm expectedResponse = + Realm.newBuilder() + .setName(RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setTimeZone("timeZone-2077180903") + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createRealmTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + Realm realm = Realm.newBuilder().build(); + String realmId = "realmId1080654858"; + + Realm actualResponse = client.createRealmAsync(parent, realm, realmId).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 createRealmExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + Realm realm = Realm.newBuilder().build(); + String realmId = "realmId1080654858"; + client.createRealmAsync(parent, realm, realmId).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void createRealmTest2() throws Exception { + Realm expectedResponse = + Realm.newBuilder() + .setName(RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setTimeZone("timeZone-2077180903") + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createRealmTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String parent = "projects/project-5833/locations/location-5833"; + Realm realm = Realm.newBuilder().build(); + String realmId = "realmId1080654858"; + + Realm actualResponse = client.createRealmAsync(parent, realm, realmId).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 createRealmExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + Realm realm = Realm.newBuilder().build(); + String realmId = "realmId1080654858"; + client.createRealmAsync(parent, realm, realmId).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void deleteRealmTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteRealmTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + RealmName name = RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]"); + + client.deleteRealmAsync(name).get(); + + 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 deleteRealmExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + RealmName name = RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]"); + client.deleteRealmAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void deleteRealmTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteRealmTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String name = "projects/project-9444/locations/location-9444/realms/realm-9444"; + + client.deleteRealmAsync(name).get(); + + 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 deleteRealmExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-9444/locations/location-9444/realms/realm-9444"; + client.deleteRealmAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void updateRealmTest() throws Exception { + Realm expectedResponse = + Realm.newBuilder() + .setName(RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setTimeZone("timeZone-2077180903") + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("updateRealmTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + Realm realm = + Realm.newBuilder() + .setName(RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setTimeZone("timeZone-2077180903") + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + + Realm actualResponse = client.updateRealmAsync(realm, updateMask).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 updateRealmExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + Realm realm = + Realm.newBuilder() + .setName(RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setTimeZone("timeZone-2077180903") + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + client.updateRealmAsync(realm, updateMask).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void previewRealmUpdateTest() throws Exception { + PreviewRealmUpdateResponse expectedResponse = + PreviewRealmUpdateResponse.newBuilder() + .setEtag("etag3123477") + .setTargetState(TargetState.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + PreviewRealmUpdateRequest request = + PreviewRealmUpdateRequest.newBuilder() + .setRealm( + Realm.newBuilder() + .setName(RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setTimeZone("timeZone-2077180903") + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .setPreviewTime(Timestamp.newBuilder().build()) + .build(); + + PreviewRealmUpdateResponse actualResponse = client.previewRealmUpdate(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 previewRealmUpdateExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + PreviewRealmUpdateRequest request = + PreviewRealmUpdateRequest.newBuilder() + .setRealm( + Realm.newBuilder() + .setName(RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setTimeZone("timeZone-2077180903") + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .setPreviewTime(Timestamp.newBuilder().build()) + .build(); + client.previewRealmUpdate(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/java-game-servers/google-cloud-game-servers/src/test/java/com/google/cloud/gaming/v1beta/GameServerClustersServiceClientHttpJsonTest.java b/java-game-servers/google-cloud-game-servers/src/test/java/com/google/cloud/gaming/v1beta/GameServerClustersServiceClientHttpJsonTest.java new file mode 100644 index 000000000000..1eff0ad7e1e9 --- /dev/null +++ b/java-game-servers/google-cloud-game-servers/src/test/java/com/google/cloud/gaming/v1beta/GameServerClustersServiceClientHttpJsonTest.java @@ -0,0 +1,787 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.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.cloud.gaming.v1beta; + +import static com.google.cloud.gaming.v1beta.GameServerClustersServiceClient.ListGameServerClustersPagedResponse; + +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.cloud.gaming.v1beta.stub.HttpJsonGameServerClustersServiceStub; +import com.google.common.collect.Lists; +import com.google.longrunning.Operation; +import com.google.protobuf.Any; +import com.google.protobuf.Empty; +import com.google.protobuf.FieldMask; +import com.google.protobuf.Timestamp; +import java.io.IOException; +import java.util.Arrays; +import java.util.HashMap; +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 GameServerClustersServiceClientHttpJsonTest { + private static MockHttpService mockService; + private static GameServerClustersServiceClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonGameServerClustersServiceStub.getMethodDescriptors(), + GameServerClustersServiceSettings.getDefaultEndpoint()); + GameServerClustersServiceSettings settings = + GameServerClustersServiceSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + GameServerClustersServiceSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = GameServerClustersServiceClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void listGameServerClustersTest() throws Exception { + GameServerCluster responsesElement = GameServerCluster.newBuilder().build(); + ListGameServerClustersResponse expectedResponse = + ListGameServerClustersResponse.newBuilder() + .setNextPageToken("") + .addAllGameServerClusters(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + RealmName parent = RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]"); + + ListGameServerClustersPagedResponse pagedListResponse = client.listGameServerClusters(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getGameServerClustersList().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 listGameServerClustersExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + RealmName parent = RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]"); + client.listGameServerClusters(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listGameServerClustersTest2() throws Exception { + GameServerCluster responsesElement = GameServerCluster.newBuilder().build(); + ListGameServerClustersResponse expectedResponse = + ListGameServerClustersResponse.newBuilder() + .setNextPageToken("") + .addAllGameServerClusters(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-3755/locations/location-3755/realms/realm-3755"; + + ListGameServerClustersPagedResponse pagedListResponse = client.listGameServerClusters(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getGameServerClustersList().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 listGameServerClustersExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-3755/locations/location-3755/realms/realm-3755"; + client.listGameServerClusters(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getGameServerClusterTest() throws Exception { + GameServerCluster expectedResponse = + GameServerCluster.newBuilder() + .setName( + GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]") + .toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setConnectionInfo(GameServerClusterConnectionInfo.newBuilder().build()) + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build(); + mockService.addResponse(expectedResponse); + + GameServerClusterName name = + GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]"); + + GameServerCluster actualResponse = client.getGameServerCluster(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 getGameServerClusterExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GameServerClusterName name = + GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]"); + client.getGameServerCluster(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getGameServerClusterTest2() throws Exception { + GameServerCluster expectedResponse = + GameServerCluster.newBuilder() + .setName( + GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]") + .toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setConnectionInfo(GameServerClusterConnectionInfo.newBuilder().build()) + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-4532/locations/location-4532/realms/realm-4532/gameServerClusters/gameServerCluster-4532"; + + GameServerCluster actualResponse = client.getGameServerCluster(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 getGameServerClusterExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-4532/locations/location-4532/realms/realm-4532/gameServerClusters/gameServerCluster-4532"; + client.getGameServerCluster(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createGameServerClusterTest() throws Exception { + GameServerCluster expectedResponse = + GameServerCluster.newBuilder() + .setName( + GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]") + .toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setConnectionInfo(GameServerClusterConnectionInfo.newBuilder().build()) + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createGameServerClusterTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + RealmName parent = RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]"); + GameServerCluster gameServerCluster = GameServerCluster.newBuilder().build(); + String gameServerClusterId = "gameServerClusterId-1301104032"; + + GameServerCluster actualResponse = + client.createGameServerClusterAsync(parent, gameServerCluster, gameServerClusterId).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 createGameServerClusterExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + RealmName parent = RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]"); + GameServerCluster gameServerCluster = GameServerCluster.newBuilder().build(); + String gameServerClusterId = "gameServerClusterId-1301104032"; + client.createGameServerClusterAsync(parent, gameServerCluster, gameServerClusterId).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void createGameServerClusterTest2() throws Exception { + GameServerCluster expectedResponse = + GameServerCluster.newBuilder() + .setName( + GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]") + .toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setConnectionInfo(GameServerClusterConnectionInfo.newBuilder().build()) + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createGameServerClusterTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String parent = "projects/project-3755/locations/location-3755/realms/realm-3755"; + GameServerCluster gameServerCluster = GameServerCluster.newBuilder().build(); + String gameServerClusterId = "gameServerClusterId-1301104032"; + + GameServerCluster actualResponse = + client.createGameServerClusterAsync(parent, gameServerCluster, gameServerClusterId).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 createGameServerClusterExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-3755/locations/location-3755/realms/realm-3755"; + GameServerCluster gameServerCluster = GameServerCluster.newBuilder().build(); + String gameServerClusterId = "gameServerClusterId-1301104032"; + client.createGameServerClusterAsync(parent, gameServerCluster, gameServerClusterId).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void previewCreateGameServerClusterTest() throws Exception { + PreviewCreateGameServerClusterResponse expectedResponse = + PreviewCreateGameServerClusterResponse.newBuilder() + .setEtag("etag3123477") + .setTargetState(TargetState.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + PreviewCreateGameServerClusterRequest request = + PreviewCreateGameServerClusterRequest.newBuilder() + .setParent(RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]").toString()) + .setGameServerClusterId("gameServerClusterId-1301104032") + .setGameServerCluster(GameServerCluster.newBuilder().build()) + .setPreviewTime(Timestamp.newBuilder().build()) + .build(); + + PreviewCreateGameServerClusterResponse actualResponse = + client.previewCreateGameServerCluster(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 previewCreateGameServerClusterExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + PreviewCreateGameServerClusterRequest request = + PreviewCreateGameServerClusterRequest.newBuilder() + .setParent(RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]").toString()) + .setGameServerClusterId("gameServerClusterId-1301104032") + .setGameServerCluster(GameServerCluster.newBuilder().build()) + .setPreviewTime(Timestamp.newBuilder().build()) + .build(); + client.previewCreateGameServerCluster(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteGameServerClusterTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteGameServerClusterTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + GameServerClusterName name = + GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]"); + + client.deleteGameServerClusterAsync(name).get(); + + 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 deleteGameServerClusterExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GameServerClusterName name = + GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]"); + client.deleteGameServerClusterAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void deleteGameServerClusterTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteGameServerClusterTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String name = + "projects/project-4532/locations/location-4532/realms/realm-4532/gameServerClusters/gameServerCluster-4532"; + + client.deleteGameServerClusterAsync(name).get(); + + 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 deleteGameServerClusterExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-4532/locations/location-4532/realms/realm-4532/gameServerClusters/gameServerCluster-4532"; + client.deleteGameServerClusterAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void previewDeleteGameServerClusterTest() throws Exception { + PreviewDeleteGameServerClusterResponse expectedResponse = + PreviewDeleteGameServerClusterResponse.newBuilder() + .setEtag("etag3123477") + .setTargetState(TargetState.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + PreviewDeleteGameServerClusterRequest request = + PreviewDeleteGameServerClusterRequest.newBuilder() + .setName( + GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]") + .toString()) + .setPreviewTime(Timestamp.newBuilder().build()) + .build(); + + PreviewDeleteGameServerClusterResponse actualResponse = + client.previewDeleteGameServerCluster(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 previewDeleteGameServerClusterExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + PreviewDeleteGameServerClusterRequest request = + PreviewDeleteGameServerClusterRequest.newBuilder() + .setName( + GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]") + .toString()) + .setPreviewTime(Timestamp.newBuilder().build()) + .build(); + client.previewDeleteGameServerCluster(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateGameServerClusterTest() throws Exception { + GameServerCluster expectedResponse = + GameServerCluster.newBuilder() + .setName( + GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]") + .toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setConnectionInfo(GameServerClusterConnectionInfo.newBuilder().build()) + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("updateGameServerClusterTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + GameServerCluster gameServerCluster = + GameServerCluster.newBuilder() + .setName( + GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]") + .toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setConnectionInfo(GameServerClusterConnectionInfo.newBuilder().build()) + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + + GameServerCluster actualResponse = + client.updateGameServerClusterAsync(gameServerCluster, updateMask).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 updateGameServerClusterExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GameServerCluster gameServerCluster = + GameServerCluster.newBuilder() + .setName( + GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]") + .toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setConnectionInfo(GameServerClusterConnectionInfo.newBuilder().build()) + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + client.updateGameServerClusterAsync(gameServerCluster, updateMask).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void previewUpdateGameServerClusterTest() throws Exception { + PreviewUpdateGameServerClusterResponse expectedResponse = + PreviewUpdateGameServerClusterResponse.newBuilder() + .setEtag("etag3123477") + .setTargetState(TargetState.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + PreviewUpdateGameServerClusterRequest request = + PreviewUpdateGameServerClusterRequest.newBuilder() + .setGameServerCluster( + GameServerCluster.newBuilder() + .setName( + GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]") + .toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setConnectionInfo(GameServerClusterConnectionInfo.newBuilder().build()) + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .setPreviewTime(Timestamp.newBuilder().build()) + .build(); + + PreviewUpdateGameServerClusterResponse actualResponse = + client.previewUpdateGameServerCluster(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 previewUpdateGameServerClusterExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + PreviewUpdateGameServerClusterRequest request = + PreviewUpdateGameServerClusterRequest.newBuilder() + .setGameServerCluster( + GameServerCluster.newBuilder() + .setName( + GameServerClusterName.of( + "[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]") + .toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setConnectionInfo(GameServerClusterConnectionInfo.newBuilder().build()) + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .setPreviewTime(Timestamp.newBuilder().build()) + .build(); + client.previewUpdateGameServerCluster(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/java-game-servers/google-cloud-game-servers/src/test/java/com/google/cloud/gaming/v1beta/GameServerConfigsServiceClientHttpJsonTest.java b/java-game-servers/google-cloud-game-servers/src/test/java/com/google/cloud/gaming/v1beta/GameServerConfigsServiceClientHttpJsonTest.java new file mode 100644 index 000000000000..22c0216564de --- /dev/null +++ b/java-game-servers/google-cloud-game-servers/src/test/java/com/google/cloud/gaming/v1beta/GameServerConfigsServiceClientHttpJsonTest.java @@ -0,0 +1,514 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.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.cloud.gaming.v1beta; + +import static com.google.cloud.gaming.v1beta.GameServerConfigsServiceClient.ListGameServerConfigsPagedResponse; + +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.cloud.gaming.v1beta.stub.HttpJsonGameServerConfigsServiceStub; +import com.google.common.collect.Lists; +import com.google.longrunning.Operation; +import com.google.protobuf.Any; +import com.google.protobuf.Empty; +import com.google.protobuf.Timestamp; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +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 GameServerConfigsServiceClientHttpJsonTest { + private static MockHttpService mockService; + private static GameServerConfigsServiceClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonGameServerConfigsServiceStub.getMethodDescriptors(), + GameServerConfigsServiceSettings.getDefaultEndpoint()); + GameServerConfigsServiceSettings settings = + GameServerConfigsServiceSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + GameServerConfigsServiceSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = GameServerConfigsServiceClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void listGameServerConfigsTest() throws Exception { + GameServerConfig responsesElement = GameServerConfig.newBuilder().build(); + ListGameServerConfigsResponse expectedResponse = + ListGameServerConfigsResponse.newBuilder() + .setNextPageToken("") + .addAllGameServerConfigs(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + GameServerDeploymentName parent = + GameServerDeploymentName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]"); + + ListGameServerConfigsPagedResponse pagedListResponse = client.listGameServerConfigs(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getGameServerConfigsList().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 listGameServerConfigsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GameServerDeploymentName parent = + GameServerDeploymentName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]"); + client.listGameServerConfigs(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listGameServerConfigsTest2() throws Exception { + GameServerConfig responsesElement = GameServerConfig.newBuilder().build(); + ListGameServerConfigsResponse expectedResponse = + ListGameServerConfigsResponse.newBuilder() + .setNextPageToken("") + .addAllGameServerConfigs(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = + "projects/project-6046/locations/location-6046/gameServerDeployments/gameServerDeployment-6046"; + + ListGameServerConfigsPagedResponse pagedListResponse = client.listGameServerConfigs(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getGameServerConfigsList().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 listGameServerConfigsExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = + "projects/project-6046/locations/location-6046/gameServerDeployments/gameServerDeployment-6046"; + client.listGameServerConfigs(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getGameServerConfigTest() throws Exception { + GameServerConfig expectedResponse = + GameServerConfig.newBuilder() + .setName( + GameServerConfigName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]", "[CONFIG]") + .toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .addAllFleetConfigs(new ArrayList()) + .addAllScalingConfigs(new ArrayList()) + .setDescription("description-1724546052") + .build(); + mockService.addResponse(expectedResponse); + + GameServerConfigName name = + GameServerConfigName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]", "[CONFIG]"); + + GameServerConfig actualResponse = client.getGameServerConfig(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 getGameServerConfigExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GameServerConfigName name = + GameServerConfigName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]", "[CONFIG]"); + client.getGameServerConfig(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getGameServerConfigTest2() throws Exception { + GameServerConfig expectedResponse = + GameServerConfig.newBuilder() + .setName( + GameServerConfigName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]", "[CONFIG]") + .toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .addAllFleetConfigs(new ArrayList()) + .addAllScalingConfigs(new ArrayList()) + .setDescription("description-1724546052") + .build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-2748/locations/location-2748/gameServerDeployments/gameServerDeployment-2748/configs/config-2748"; + + GameServerConfig actualResponse = client.getGameServerConfig(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 getGameServerConfigExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-2748/locations/location-2748/gameServerDeployments/gameServerDeployment-2748/configs/config-2748"; + client.getGameServerConfig(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createGameServerConfigTest() throws Exception { + GameServerConfig expectedResponse = + GameServerConfig.newBuilder() + .setName( + GameServerConfigName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]", "[CONFIG]") + .toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .addAllFleetConfigs(new ArrayList()) + .addAllScalingConfigs(new ArrayList()) + .setDescription("description-1724546052") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createGameServerConfigTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + GameServerDeploymentName parent = + GameServerDeploymentName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]"); + GameServerConfig gameServerConfig = GameServerConfig.newBuilder().build(); + + GameServerConfig actualResponse = + client.createGameServerConfigAsync(parent, gameServerConfig).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 createGameServerConfigExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GameServerDeploymentName parent = + GameServerDeploymentName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]"); + GameServerConfig gameServerConfig = GameServerConfig.newBuilder().build(); + client.createGameServerConfigAsync(parent, gameServerConfig).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void createGameServerConfigTest2() throws Exception { + GameServerConfig expectedResponse = + GameServerConfig.newBuilder() + .setName( + GameServerConfigName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]", "[CONFIG]") + .toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .addAllFleetConfigs(new ArrayList()) + .addAllScalingConfigs(new ArrayList()) + .setDescription("description-1724546052") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createGameServerConfigTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String parent = + "projects/project-6046/locations/location-6046/gameServerDeployments/gameServerDeployment-6046"; + GameServerConfig gameServerConfig = GameServerConfig.newBuilder().build(); + + GameServerConfig actualResponse = + client.createGameServerConfigAsync(parent, gameServerConfig).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 createGameServerConfigExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = + "projects/project-6046/locations/location-6046/gameServerDeployments/gameServerDeployment-6046"; + GameServerConfig gameServerConfig = GameServerConfig.newBuilder().build(); + client.createGameServerConfigAsync(parent, gameServerConfig).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void deleteGameServerConfigTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteGameServerConfigTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + GameServerConfigName name = + GameServerConfigName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]", "[CONFIG]"); + + client.deleteGameServerConfigAsync(name).get(); + + 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 deleteGameServerConfigExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GameServerConfigName name = + GameServerConfigName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]", "[CONFIG]"); + client.deleteGameServerConfigAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void deleteGameServerConfigTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteGameServerConfigTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String name = + "projects/project-2748/locations/location-2748/gameServerDeployments/gameServerDeployment-2748/configs/config-2748"; + + client.deleteGameServerConfigAsync(name).get(); + + 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 deleteGameServerConfigExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-2748/locations/location-2748/gameServerDeployments/gameServerDeployment-2748/configs/config-2748"; + client.deleteGameServerConfigAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } +} diff --git a/java-game-servers/google-cloud-game-servers/src/test/java/com/google/cloud/gaming/v1beta/GameServerDeploymentsServiceClientHttpJsonTest.java b/java-game-servers/google-cloud-game-servers/src/test/java/com/google/cloud/gaming/v1beta/GameServerDeploymentsServiceClientHttpJsonTest.java new file mode 100644 index 000000000000..7e1fe7a89251 --- /dev/null +++ b/java-game-servers/google-cloud-game-servers/src/test/java/com/google/cloud/gaming/v1beta/GameServerDeploymentsServiceClientHttpJsonTest.java @@ -0,0 +1,883 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.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.cloud.gaming.v1beta; + +import static com.google.cloud.gaming.v1beta.GameServerDeploymentsServiceClient.ListGameServerDeploymentsPagedResponse; + +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.cloud.gaming.v1beta.stub.HttpJsonGameServerDeploymentsServiceStub; +import com.google.common.collect.Lists; +import com.google.longrunning.Operation; +import com.google.protobuf.Any; +import com.google.protobuf.Empty; +import com.google.protobuf.FieldMask; +import com.google.protobuf.Timestamp; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +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 GameServerDeploymentsServiceClientHttpJsonTest { + private static MockHttpService mockService; + private static GameServerDeploymentsServiceClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonGameServerDeploymentsServiceStub.getMethodDescriptors(), + GameServerDeploymentsServiceSettings.getDefaultEndpoint()); + GameServerDeploymentsServiceSettings settings = + GameServerDeploymentsServiceSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + GameServerDeploymentsServiceSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = GameServerDeploymentsServiceClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void listGameServerDeploymentsTest() throws Exception { + GameServerDeployment responsesElement = GameServerDeployment.newBuilder().build(); + ListGameServerDeploymentsResponse expectedResponse = + ListGameServerDeploymentsResponse.newBuilder() + .setNextPageToken("") + .addAllGameServerDeployments(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + + ListGameServerDeploymentsPagedResponse pagedListResponse = + client.listGameServerDeployments(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getGameServerDeploymentsList().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 listGameServerDeploymentsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + client.listGameServerDeployments(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listGameServerDeploymentsTest2() throws Exception { + GameServerDeployment responsesElement = GameServerDeployment.newBuilder().build(); + ListGameServerDeploymentsResponse expectedResponse = + ListGameServerDeploymentsResponse.newBuilder() + .setNextPageToken("") + .addAllGameServerDeployments(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-5833/locations/location-5833"; + + ListGameServerDeploymentsPagedResponse pagedListResponse = + client.listGameServerDeployments(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getGameServerDeploymentsList().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 listGameServerDeploymentsExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + client.listGameServerDeployments(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getGameServerDeploymentTest() throws Exception { + GameServerDeployment expectedResponse = + GameServerDeployment.newBuilder() + .setName( + GameServerDeploymentName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build(); + mockService.addResponse(expectedResponse); + + GameServerDeploymentName name = + GameServerDeploymentName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]"); + + GameServerDeployment actualResponse = client.getGameServerDeployment(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 getGameServerDeploymentExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GameServerDeploymentName name = + GameServerDeploymentName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]"); + client.getGameServerDeployment(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getGameServerDeploymentTest2() throws Exception { + GameServerDeployment expectedResponse = + GameServerDeployment.newBuilder() + .setName( + GameServerDeploymentName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-8689/locations/location-8689/gameServerDeployments/gameServerDeployment-8689"; + + GameServerDeployment actualResponse = client.getGameServerDeployment(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 getGameServerDeploymentExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-8689/locations/location-8689/gameServerDeployments/gameServerDeployment-8689"; + client.getGameServerDeployment(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createGameServerDeploymentTest() throws Exception { + GameServerDeployment expectedResponse = + GameServerDeployment.newBuilder() + .setName( + GameServerDeploymentName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createGameServerDeploymentTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + GameServerDeployment gameServerDeployment = GameServerDeployment.newBuilder().build(); + + GameServerDeployment actualResponse = + client.createGameServerDeploymentAsync(parent, gameServerDeployment).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 createGameServerDeploymentExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + GameServerDeployment gameServerDeployment = GameServerDeployment.newBuilder().build(); + client.createGameServerDeploymentAsync(parent, gameServerDeployment).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void createGameServerDeploymentTest2() throws Exception { + GameServerDeployment expectedResponse = + GameServerDeployment.newBuilder() + .setName( + GameServerDeploymentName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createGameServerDeploymentTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String parent = "projects/project-5833/locations/location-5833"; + GameServerDeployment gameServerDeployment = GameServerDeployment.newBuilder().build(); + + GameServerDeployment actualResponse = + client.createGameServerDeploymentAsync(parent, gameServerDeployment).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 createGameServerDeploymentExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + GameServerDeployment gameServerDeployment = GameServerDeployment.newBuilder().build(); + client.createGameServerDeploymentAsync(parent, gameServerDeployment).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void deleteGameServerDeploymentTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteGameServerDeploymentTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + GameServerDeploymentName name = + GameServerDeploymentName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]"); + + client.deleteGameServerDeploymentAsync(name).get(); + + 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 deleteGameServerDeploymentExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GameServerDeploymentName name = + GameServerDeploymentName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]"); + client.deleteGameServerDeploymentAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void deleteGameServerDeploymentTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteGameServerDeploymentTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String name = + "projects/project-8689/locations/location-8689/gameServerDeployments/gameServerDeployment-8689"; + + client.deleteGameServerDeploymentAsync(name).get(); + + 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 deleteGameServerDeploymentExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-8689/locations/location-8689/gameServerDeployments/gameServerDeployment-8689"; + client.deleteGameServerDeploymentAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void updateGameServerDeploymentTest() throws Exception { + GameServerDeployment expectedResponse = + GameServerDeployment.newBuilder() + .setName( + GameServerDeploymentName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("updateGameServerDeploymentTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + GameServerDeployment gameServerDeployment = + GameServerDeployment.newBuilder() + .setName( + GameServerDeploymentName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + + GameServerDeployment actualResponse = + client.updateGameServerDeploymentAsync(gameServerDeployment, updateMask).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 updateGameServerDeploymentExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GameServerDeployment gameServerDeployment = + GameServerDeployment.newBuilder() + .setName( + GameServerDeploymentName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + client.updateGameServerDeploymentAsync(gameServerDeployment, updateMask).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void getGameServerDeploymentRolloutTest() throws Exception { + GameServerDeploymentRollout expectedResponse = + GameServerDeploymentRollout.newBuilder() + .setName("name3373707") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setDefaultGameServerConfig("defaultGameServerConfig-1852465704") + .addAllGameServerConfigOverrides(new ArrayList()) + .setEtag("etag3123477") + .build(); + mockService.addResponse(expectedResponse); + + GameServerDeploymentName name = + GameServerDeploymentName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]"); + + GameServerDeploymentRollout actualResponse = client.getGameServerDeploymentRollout(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 getGameServerDeploymentRolloutExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GameServerDeploymentName name = + GameServerDeploymentName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]"); + client.getGameServerDeploymentRollout(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getGameServerDeploymentRolloutTest2() throws Exception { + GameServerDeploymentRollout expectedResponse = + GameServerDeploymentRollout.newBuilder() + .setName("name3373707") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setDefaultGameServerConfig("defaultGameServerConfig-1852465704") + .addAllGameServerConfigOverrides(new ArrayList()) + .setEtag("etag3123477") + .build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-8689/locations/location-8689/gameServerDeployments/gameServerDeployment-8689"; + + GameServerDeploymentRollout actualResponse = client.getGameServerDeploymentRollout(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 getGameServerDeploymentRolloutExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-8689/locations/location-8689/gameServerDeployments/gameServerDeployment-8689"; + client.getGameServerDeploymentRollout(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateGameServerDeploymentRolloutTest() throws Exception { + GameServerDeployment expectedResponse = + GameServerDeployment.newBuilder() + .setName( + GameServerDeploymentName.of("[PROJECT]", "[LOCATION]", "[DEPLOYMENT]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("updateGameServerDeploymentRolloutTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + GameServerDeploymentRollout rollout = + GameServerDeploymentRollout.newBuilder() + .setName( + "projects/project-8689/locations/location-8689/gameServerDeployments/gameServerDeployment-8689") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setDefaultGameServerConfig("defaultGameServerConfig-1852465704") + .addAllGameServerConfigOverrides(new ArrayList()) + .setEtag("etag3123477") + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + + GameServerDeployment actualResponse = + client.updateGameServerDeploymentRolloutAsync(rollout, updateMask).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 updateGameServerDeploymentRolloutExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GameServerDeploymentRollout rollout = + GameServerDeploymentRollout.newBuilder() + .setName( + "projects/project-8689/locations/location-8689/gameServerDeployments/gameServerDeployment-8689") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setDefaultGameServerConfig("defaultGameServerConfig-1852465704") + .addAllGameServerConfigOverrides(new ArrayList()) + .setEtag("etag3123477") + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + client.updateGameServerDeploymentRolloutAsync(rollout, updateMask).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void previewGameServerDeploymentRolloutTest() throws Exception { + PreviewGameServerDeploymentRolloutResponse expectedResponse = + PreviewGameServerDeploymentRolloutResponse.newBuilder() + .addAllUnavailable(new ArrayList()) + .setEtag("etag3123477") + .setTargetState(TargetState.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + PreviewGameServerDeploymentRolloutRequest request = + PreviewGameServerDeploymentRolloutRequest.newBuilder() + .setRollout( + GameServerDeploymentRollout.newBuilder() + .setName( + "projects/project-8689/locations/location-8689/gameServerDeployments/gameServerDeployment-8689") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setDefaultGameServerConfig("defaultGameServerConfig-1852465704") + .addAllGameServerConfigOverrides(new ArrayList()) + .setEtag("etag3123477") + .build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .setPreviewTime(Timestamp.newBuilder().build()) + .build(); + + PreviewGameServerDeploymentRolloutResponse actualResponse = + client.previewGameServerDeploymentRollout(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 previewGameServerDeploymentRolloutExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + PreviewGameServerDeploymentRolloutRequest request = + PreviewGameServerDeploymentRolloutRequest.newBuilder() + .setRollout( + GameServerDeploymentRollout.newBuilder() + .setName( + "projects/project-8689/locations/location-8689/gameServerDeployments/gameServerDeployment-8689") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setDefaultGameServerConfig("defaultGameServerConfig-1852465704") + .addAllGameServerConfigOverrides(new ArrayList()) + .setEtag("etag3123477") + .build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .setPreviewTime(Timestamp.newBuilder().build()) + .build(); + client.previewGameServerDeploymentRollout(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void fetchDeploymentStateTest() throws Exception { + FetchDeploymentStateResponse expectedResponse = + FetchDeploymentStateResponse.newBuilder() + .addAllClusterState(new ArrayList()) + .addAllUnavailable(new ArrayList()) + .build(); + mockService.addResponse(expectedResponse); + + FetchDeploymentStateRequest request = + FetchDeploymentStateRequest.newBuilder() + .setName( + "projects/project-8689/locations/location-8689/gameServerDeployments/gameServerDeployment-8689") + .build(); + + FetchDeploymentStateResponse actualResponse = client.fetchDeploymentState(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 fetchDeploymentStateExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + FetchDeploymentStateRequest request = + FetchDeploymentStateRequest.newBuilder() + .setName( + "projects/project-8689/locations/location-8689/gameServerDeployments/gameServerDeployment-8689") + .build(); + client.fetchDeploymentState(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/java-game-servers/google-cloud-game-servers/src/test/java/com/google/cloud/gaming/v1beta/RealmsServiceClientHttpJsonTest.java b/java-game-servers/google-cloud-game-servers/src/test/java/com/google/cloud/gaming/v1beta/RealmsServiceClientHttpJsonTest.java new file mode 100644 index 000000000000..1cf5500bb5f4 --- /dev/null +++ b/java-game-servers/google-cloud-game-servers/src/test/java/com/google/cloud/gaming/v1beta/RealmsServiceClientHttpJsonTest.java @@ -0,0 +1,640 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.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.cloud.gaming.v1beta; + +import static com.google.cloud.gaming.v1beta.RealmsServiceClient.ListRealmsPagedResponse; + +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.cloud.gaming.v1beta.stub.HttpJsonRealmsServiceStub; +import com.google.common.collect.Lists; +import com.google.longrunning.Operation; +import com.google.protobuf.Any; +import com.google.protobuf.Empty; +import com.google.protobuf.FieldMask; +import com.google.protobuf.Timestamp; +import java.io.IOException; +import java.util.Arrays; +import java.util.HashMap; +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 RealmsServiceClientHttpJsonTest { + private static MockHttpService mockService; + private static RealmsServiceClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonRealmsServiceStub.getMethodDescriptors(), + RealmsServiceSettings.getDefaultEndpoint()); + RealmsServiceSettings settings = + RealmsServiceSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + RealmsServiceSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = RealmsServiceClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void listRealmsTest() throws Exception { + Realm responsesElement = Realm.newBuilder().build(); + ListRealmsResponse expectedResponse = + ListRealmsResponse.newBuilder() + .setNextPageToken("") + .addAllRealms(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + + ListRealmsPagedResponse pagedListResponse = client.listRealms(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getRealmsList().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 listRealmsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + client.listRealms(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listRealmsTest2() throws Exception { + Realm responsesElement = Realm.newBuilder().build(); + ListRealmsResponse expectedResponse = + ListRealmsResponse.newBuilder() + .setNextPageToken("") + .addAllRealms(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-5833/locations/location-5833"; + + ListRealmsPagedResponse pagedListResponse = client.listRealms(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getRealmsList().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 listRealmsExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + client.listRealms(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getRealmTest() throws Exception { + Realm expectedResponse = + Realm.newBuilder() + .setName(RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setTimeZone("timeZone-2077180903") + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build(); + mockService.addResponse(expectedResponse); + + RealmName name = RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]"); + + Realm actualResponse = client.getRealm(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 getRealmExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + RealmName name = RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]"); + client.getRealm(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getRealmTest2() throws Exception { + Realm expectedResponse = + Realm.newBuilder() + .setName(RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setTimeZone("timeZone-2077180903") + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-9444/locations/location-9444/realms/realm-9444"; + + Realm actualResponse = client.getRealm(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 getRealmExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-9444/locations/location-9444/realms/realm-9444"; + client.getRealm(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createRealmTest() throws Exception { + Realm expectedResponse = + Realm.newBuilder() + .setName(RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setTimeZone("timeZone-2077180903") + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createRealmTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + Realm realm = Realm.newBuilder().build(); + String realmId = "realmId1080654858"; + + Realm actualResponse = client.createRealmAsync(parent, realm, realmId).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 createRealmExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + Realm realm = Realm.newBuilder().build(); + String realmId = "realmId1080654858"; + client.createRealmAsync(parent, realm, realmId).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void createRealmTest2() throws Exception { + Realm expectedResponse = + Realm.newBuilder() + .setName(RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setTimeZone("timeZone-2077180903") + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createRealmTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String parent = "projects/project-5833/locations/location-5833"; + Realm realm = Realm.newBuilder().build(); + String realmId = "realmId1080654858"; + + Realm actualResponse = client.createRealmAsync(parent, realm, realmId).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 createRealmExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + Realm realm = Realm.newBuilder().build(); + String realmId = "realmId1080654858"; + client.createRealmAsync(parent, realm, realmId).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void deleteRealmTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteRealmTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + RealmName name = RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]"); + + client.deleteRealmAsync(name).get(); + + 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 deleteRealmExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + RealmName name = RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]"); + client.deleteRealmAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void deleteRealmTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteRealmTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String name = "projects/project-9444/locations/location-9444/realms/realm-9444"; + + client.deleteRealmAsync(name).get(); + + 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 deleteRealmExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-9444/locations/location-9444/realms/realm-9444"; + client.deleteRealmAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void updateRealmTest() throws Exception { + Realm expectedResponse = + Realm.newBuilder() + .setName(RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setTimeZone("timeZone-2077180903") + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("updateRealmTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + Realm realm = + Realm.newBuilder() + .setName(RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setTimeZone("timeZone-2077180903") + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + + Realm actualResponse = client.updateRealmAsync(realm, updateMask).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 updateRealmExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + Realm realm = + Realm.newBuilder() + .setName(RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setTimeZone("timeZone-2077180903") + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + client.updateRealmAsync(realm, updateMask).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void previewRealmUpdateTest() throws Exception { + PreviewRealmUpdateResponse expectedResponse = + PreviewRealmUpdateResponse.newBuilder() + .setEtag("etag3123477") + .setTargetState(TargetState.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + PreviewRealmUpdateRequest request = + PreviewRealmUpdateRequest.newBuilder() + .setRealm( + Realm.newBuilder() + .setName(RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setTimeZone("timeZone-2077180903") + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .setPreviewTime(Timestamp.newBuilder().build()) + .build(); + + PreviewRealmUpdateResponse actualResponse = client.previewRealmUpdate(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 previewRealmUpdateExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + PreviewRealmUpdateRequest request = + PreviewRealmUpdateRequest.newBuilder() + .setRealm( + Realm.newBuilder() + .setName(RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .putAllLabels(new HashMap()) + .setTimeZone("timeZone-2077180903") + .setEtag("etag3123477") + .setDescription("description-1724546052") + .build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .setPreviewTime(Timestamp.newBuilder().build()) + .build(); + client.previewRealmUpdate(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +}